From abcbf3b5842516aff255e0729128680c1ea647a5 Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Wed, 9 Sep 2009 06:55:11 +0000
Subject: [PATCH] SE-137 bugs in protein viewer fixed

SVN: 12526
---
 .../client/application/ProteinSamplesSection.java    |  8 +++++---
 .../client/web/client/application/ProteinViewer.java | 12 +++++++-----
 .../application/SampleAbundanceBrowserGrid.java      |  3 ++-
 .../dto/ListSampleAbundanceByProteinCriteria.java    | 11 +++++++++++
 .../web/server/ListSampleAbundanceDataProvider.java  |  7 +++++--
 .../client/web/server/PhosphoNetXClientService.java  |  2 +-
 .../plugin/phosphonetx/server/PhosphoNetXServer.java |  5 +++--
 .../phosphonetx/server/PhosphoNetXServerLogger.java  |  7 ++++---
 .../phosphonetx/server/business/ISampleTable.java    |  2 +-
 .../phosphonetx/server/business/SampleTable.java     |  8 +++++---
 .../server/dataaccess/IProteinQueryDAO.java          |  9 ++++++---
 .../phosphonetx/shared/IPhosphoNetXServer.java       |  3 ++-
 12 files changed, 52 insertions(+), 25 deletions(-)

diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/ProteinSamplesSection.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/ProteinSamplesSection.java
index 6330f85a981..a18c1ec9ae9 100644
--- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/ProteinSamplesSection.java
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/ProteinSamplesSection.java
@@ -22,6 +22,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.SingleSect
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.IDatabaseModificationObserver;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.IDisposableComponent;
 import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment;
 import ch.systemsx.cisd.openbis.plugin.phosphonetx.client.web.client.IPhosphoNetXClientServiceAsync;
 
 /**
@@ -38,12 +39,13 @@ public class ProteinSamplesSection extends SingleSectionPanel
     private IDisposableComponent sampleDisposableGrid;
 
     public ProteinSamplesSection(final IViewContext<IPhosphoNetXClientServiceAsync> viewContext,
-            final TechId proteinReferenceID)
+            final TechId proteinReferenceID, Experiment experimentOrNull)
     {
         super("Samples");
+        Long experimentID = experimentOrNull == null ? null : experimentOrNull.getId();
         sampleDisposableGrid =
-                SampleAbundanceBrowserGrid.createGridForProteinSamples(viewContext, proteinReferenceID,
-                        createGridId(proteinReferenceID));
+                SampleAbundanceBrowserGrid.createGridForProteinSamples(viewContext,
+                        proteinReferenceID, experimentID, createGridId(proteinReferenceID));
         add(sampleDisposableGrid.getComponent());
     }
 
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/ProteinViewer.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/ProteinViewer.java
index c0d92e92e88..77d8904cde8 100644
--- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/ProteinViewer.java
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/ProteinViewer.java
@@ -77,7 +77,7 @@ public class ProteinViewer extends
             {
                 public String getId()
                 {
-                    return createWidgetID(proteinInfo.getId());
+                    return createWidgetID(experimentOrNull, proteinInfo.getId());
                 }
 
                 public ITabItem create()
@@ -106,9 +106,10 @@ public class ProteinViewer extends
         return StringUtils.abbreviate(info, 30);
     }
 
-    static String createWidgetID(TechId proteinReferenceID)
+    static String createWidgetID(Experiment experimentOrNull, TechId proteinReferenceID)
     {
-        return ID_PREFIX + proteinReferenceID.getId();
+        Long experimentID = experimentOrNull == null ? null : experimentOrNull.getId();
+        return ID_PREFIX + experimentID + "_" + proteinReferenceID.getId();
     }
 
     private final IViewContext<IPhosphoNetXClientServiceAsync> viewContext;
@@ -122,7 +123,7 @@ public class ProteinViewer extends
     private ProteinViewer(IViewContext<IPhosphoNetXClientServiceAsync> viewContext,
             Experiment experimentOrNull, TechId proteinReferenceID)
     {
-        super(viewContext, "", createWidgetID(proteinReferenceID), false);
+        super(viewContext, "", createWidgetID(experimentOrNull, proteinReferenceID), false);
         this.viewContext = viewContext;
         this.experimentOrNull = experimentOrNull;
         this.proteinReferenceID = proteinReferenceID;
@@ -151,7 +152,8 @@ public class ProteinViewer extends
         } else
         {
             add(propertyPanel, createBorderLayoutData(LayoutRegion.CENTER));
-            proteinSamplesSection = new ProteinSamplesSection(viewContext, proteinReferenceID);
+            proteinSamplesSection =
+                    new ProteinSamplesSection(viewContext, proteinReferenceID, experimentOrNull);
             add(proteinSamplesSection, createBorderLayoutData(LayoutRegion.SOUTH));
             layout();
         }
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/SampleAbundanceBrowserGrid.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/SampleAbundanceBrowserGrid.java
index 053d69249d7..83a9df3cd3f 100644
--- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/SampleAbundanceBrowserGrid.java
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/SampleAbundanceBrowserGrid.java
@@ -87,11 +87,12 @@ public class SampleAbundanceBrowserGrid
 
     public static IDisposableComponent createGridForProteinSamples(
             final IViewContext<IPhosphoNetXClientServiceAsync> viewContext,
-            final TechId proteinReferenceID, final String gridId)
+            final TechId proteinReferenceID, Long experimentIDOrNull, final String gridId)
     {
         final ListSampleAbundanceByProteinCriteria criteria =
                 new ListSampleAbundanceByProteinCriteria();
         criteria.setProteinReferenceID(proteinReferenceID);
+        criteria.setExperimentID(experimentIDOrNull);
 
         ISampleAbundanceCriteriaProvider criteriaProvider =
                 new SampleAbundanceCriteriaProvider(viewContext, criteria);
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/dto/ListSampleAbundanceByProteinCriteria.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/dto/ListSampleAbundanceByProteinCriteria.java
index 6eefaa1677b..9cf36395a4a 100644
--- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/dto/ListSampleAbundanceByProteinCriteria.java
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/dto/ListSampleAbundanceByProteinCriteria.java
@@ -30,8 +30,19 @@ import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.basic.dto.SampleWithPr
 public class ListSampleAbundanceByProteinCriteria extends
         DefaultResultSetConfig<String, SampleWithPropertiesAndAbundance> implements IsSerializable
 {
+    private TechId experimentID;
     private TechId proteinReferenceID;
 
+    public final TechId getExperimentID()
+    {
+        return experimentID;
+    }
+
+    public final void setExperimentID(Long experimentID)
+    {
+        this.experimentID = experimentID == null ? null : new TechId(experimentID);
+    }
+
     public final TechId getProteinReferenceID()
     {
         return proteinReferenceID;
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/server/ListSampleAbundanceDataProvider.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/server/ListSampleAbundanceDataProvider.java
index 13350d8a519..c7ce947019b 100644
--- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/server/ListSampleAbundanceDataProvider.java
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/server/ListSampleAbundanceDataProvider.java
@@ -35,20 +35,23 @@ class ListSampleAbundanceDataProvider implements IOriginalDataProvider<SampleWit
 
     private final String sessionToken;
 
+    private final TechId experimentID;
+    
     private final TechId proteinReferenceID;
 
     ListSampleAbundanceDataProvider(IPhosphoNetXServer server, String sessionToken,
-            TechId proteinReferenceID)
+            TechId experimentID, TechId proteinReferenceID)
     {
         this.server = server;
         this.sessionToken = sessionToken;
+        this.experimentID = experimentID;
         this.proteinReferenceID = proteinReferenceID;
     }
 
 
     public List<SampleWithPropertiesAndAbundance> getOriginalData() throws UserFailureException
     {
-        return server.listSamplesWithAbundanceByProtein(sessionToken, proteinReferenceID);
+        return server.listSamplesWithAbundanceByProtein(sessionToken, experimentID, proteinReferenceID);
     }
 
 }
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/server/PhosphoNetXClientService.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/server/PhosphoNetXClientService.java
index cbc836978be..96a748d55f2 100644
--- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/server/PhosphoNetXClientService.java
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/server/PhosphoNetXClientService.java
@@ -154,7 +154,7 @@ public class PhosphoNetXClientService extends AbstractClientService implements
     {
         final String sessionToken = getSessionToken();
         return listEntities(criteria, new ListSampleAbundanceDataProvider(server, sessionToken,
-                criteria.getProteinReferenceID()));
+                criteria.getExperimentID(), criteria.getProteinReferenceID()));
     }
 
     public String prepareExportSamplesWithAbundance(
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/PhosphoNetXServer.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/PhosphoNetXServer.java
index e12e5502dc6..dd798d11f4b 100644
--- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/PhosphoNetXServer.java
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/PhosphoNetXServer.java
@@ -182,11 +182,12 @@ public class PhosphoNetXServer extends AbstractServer<IPhosphoNetXServer> implem
     }
 
     public List<SampleWithPropertiesAndAbundance> listSamplesWithAbundanceByProtein(
-            String sessionToken, TechId proteinReferenceID) throws UserFailureException
+            String sessionToken, TechId experimentID, TechId proteinReferenceID)
+            throws UserFailureException
     {
         final Session session = getSessionManager().getSession(sessionToken);
         ISampleTable sampleTable = specificBOFactory.createSampleTable(session);
-        sampleTable.loadSamplesWithAbundance(proteinReferenceID);
+        sampleTable.loadSamplesWithAbundance(experimentID, proteinReferenceID);
         return sampleTable.getSamples();
     }
 
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/PhosphoNetXServerLogger.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/PhosphoNetXServerLogger.java
index a4bc062abe4..4222fd2b29f 100644
--- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/PhosphoNetXServerLogger.java
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/PhosphoNetXServerLogger.java
@@ -96,10 +96,11 @@ public class PhosphoNetXServerLogger extends AbstractServerLogger implements IPh
     }
 
     public List<SampleWithPropertiesAndAbundance> listSamplesWithAbundanceByProtein(
-            String sessionToken, TechId proteinReferenceID) throws UserFailureException
+            String sessionToken, TechId experimentID, TechId proteinReferenceID)
+            throws UserFailureException
     {
-        logAccess(sessionToken, "list_samples_with_abundance_by_protein", "PROTEIN_REFERENCE_ID(%s)",
-                proteinReferenceID);
+        logAccess(sessionToken, "list_samples_with_abundance_by_protein",
+                "EXPERIMENT_ID(%s) PROTEIN_REFERENCE_ID(%s)", experimentID, proteinReferenceID);
         return null;
     }
 
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/business/ISampleTable.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/business/ISampleTable.java
index 63e7d88cf96..f7006ad7ec9 100644
--- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/business/ISampleTable.java
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/business/ISampleTable.java
@@ -29,7 +29,7 @@ import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.basic.dto.SampleWithPr
 public interface ISampleTable
 {
 
-    public void loadSamplesWithAbundance(TechId proteinReferenceID);
+    public void loadSamplesWithAbundance(TechId experimentID, TechId proteinReferenceID);
 
     public List<SampleWithPropertiesAndAbundance> getSamples();
 
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/business/SampleTable.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/business/SampleTable.java
index 85e07e332e3..898e5efbda3 100644
--- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/business/SampleTable.java
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/business/SampleTable.java
@@ -59,15 +59,17 @@ class SampleTable extends AbstractBusinessObject implements ISampleTable
         return samples;
     }
 
-    public void loadSamplesWithAbundance(TechId proteinReferenceID)
+    public void loadSamplesWithAbundance(TechId experimentID, TechId proteinReferenceID)
     {
         samples = new ArrayList<SampleWithPropertiesAndAbundance>();
         IProteinQueryDAO proteinQueryDAO = getSpecificDAOFactory().getProteinQueryDAO();
-        ISampleDAO sampleDAO = getDaoFactory().getSampleDAO();
+        IDAOFactory daoFactory = getDaoFactory();
+        String experimentPermID = daoFactory.getExperimentDAO().getByTechId(experimentID).getPermId();
         DataSet<SampleAbundance> sampleAbundances =
-                proteinQueryDAO.listSampleAbundanceByProtein(proteinReferenceID.getId());
+                proteinQueryDAO.listSampleAbundanceByProtein(experimentPermID, proteinReferenceID.getId());
         try
         {
+            ISampleDAO sampleDAO = daoFactory.getSampleDAO();
             for (SampleAbundance sampleAbundance : sampleAbundances)
             {
                 SampleWithPropertiesAndAbundance sample = new SampleWithPropertiesAndAbundance();
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/dataaccess/IProteinQueryDAO.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/dataaccess/IProteinQueryDAO.java
index 6061c44940e..39bd86b6d41 100644
--- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/dataaccess/IProteinQueryDAO.java
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/dataaccess/IProteinQueryDAO.java
@@ -83,12 +83,15 @@ public interface IProteinQueryDAO extends BaseQuery
     @Select("select * from peptides where prot_id = ?{1}")
     public DataSet<IdentifiedPeptide> listIdentifiedPeptidesByProtein(long proteinID);
     
-    @Select("select distinct a.id, perm_id, value " 
+    @Select("select distinct a.id, samples.perm_id, value "
             + "from abundances as a left join proteins as p on a.prot_id = p.id "
+            + "                     left join data_sets as d on p.dase_id = d.id "
+            + "                     left join experiments as e on d.expe_id = e.id "
             + "                     left join identified_proteins as i on i.prot_id = p.id "
             + "                     left join sequences as s on i.sequ_id = s.id "
             + "                     left join samples on a.samp_id = samples.id "
-            + "where s.prre_id = ?{1}")
-    public DataSet<SampleAbundance> listSampleAbundanceByProtein(long proteinReferenceID);
+            + "where e.perm_id = ?{1} and s.prre_id = ?{2}")
+    public DataSet<SampleAbundance> listSampleAbundanceByProtein(String experimentPermID,
+            long proteinReferenceID);
     
 }
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/shared/IPhosphoNetXServer.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/shared/IPhosphoNetXServer.java
index ab481b78388..ce73f84b4ce 100644
--- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/shared/IPhosphoNetXServer.java
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/shared/IPhosphoNetXServer.java
@@ -81,6 +81,7 @@ public interface IPhosphoNetXServer extends IServer
     @Transactional
     @RolesAllowed(RoleSet.OBSERVER)
     public List<SampleWithPropertiesAndAbundance> listSamplesWithAbundanceByProtein(
-            String sessionToken, TechId proteinReferenceID) throws UserFailureException;
+            String sessionToken, TechId experimentID, TechId proteinReferenceID)
+            throws UserFailureException;
 
 }
-- 
GitLab