From 5c6980a6400e1ab71bcfb242647b337f917dce6b Mon Sep 17 00:00:00 2001
From: brinn <brinn>
Date: Fri, 22 Feb 2013 15:57:37 +0000
Subject: [PATCH] [BIS-278/SP-417] Add tech id and perm id to API version of
 Project DTO.

SVN: 28414
---
 .../api/v1/GeneralInformationService.java     |   3 +-
 .../generic/shared/api/v1/Translator.java     |   3 +-
 .../generic/shared/api/v1/dto/Project.java    | 175 ++++++++++++++++--
 .../api/v1/ProteomicsDataApiFacade.java       |   9 +-
 .../api/v1/ProteomicsDataApiFacadeTest.java   |   4 +-
 5 files changed, 176 insertions(+), 18 deletions(-)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationService.java
index 7b6e495de7b..b559223231d 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationService.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationService.java
@@ -272,7 +272,8 @@ public class GeneralInformationService extends AbstractServer<IGeneralInformatio
         List<ProjectPE> projects = getDAOFactory().getProjectDAO().listProjects(space);
         for (ProjectPE project : projects)
         {
-            fullSpace.add(new Project(fullSpace.getCode(), project.getCode()));
+            fullSpace.add(new Project(project.getId(), project.getPermId(), fullSpace.getCode(),
+                    project.getCode()));
         }
     }
 
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/Translator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/Translator.java
index 6f0b80966f7..543c1736c9c 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/Translator.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/Translator.java
@@ -103,7 +103,8 @@ public class Translator
             ch.systemsx.cisd.openbis.generic.shared.basic.dto.Project project)
     {
         EntityRegistrationDetails registrationDetails = translateRegistrationDetails(project);
-        return new Project(project.getSpace().getCode(), project.getCode(), registrationDetails);
+        return new Project(project.getId(), project.getPermId(), project.getSpace().getCode(),
+                project.getCode(), registrationDetails);
     }
 
     public static List<Sample> translateSamples(
diff --git a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/Project.java b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/Project.java
index 43cf39e5806..7847b2737a6 100644
--- a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/Project.java
+++ b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/Project.java
@@ -35,12 +35,27 @@ public final class Project implements Serializable, IIdentifierHolder
 {
     private static final long serialVersionUID = 1L;
 
+    private Long id;
+
+    private String permId;
+
     private String spaceCode;
 
     private String code;
 
     private EntityRegistrationDetails registrationDetails;
 
+    /**
+     * Creates a new instance for the specified tech id, perm id, space code and project code.
+     * 
+     * @throws IllegalArgumentException if either the code or the space code is <code>null</code> or
+     *             an empty string.
+     */
+    public Project(Long id, String permId, String spaceCode, String code)
+    {
+        this(id, permId, spaceCode, code, null);
+    }
+
     /**
      * Creates a new instance for the specified space code and project code.
      * 
@@ -53,12 +68,41 @@ public final class Project implements Serializable, IIdentifierHolder
     }
 
     /**
-     * Creates a new instance for the specified space code and project code.
+     * Creates a new instance for the specified tech id, perm id, space code and project code.
      * 
      * @throws IllegalArgumentException if either the code or the space code is <code>null</code> or
      *             an empty string.
      */
     public Project(String spaceCode, String code, EntityRegistrationDetails registrationDetails)
+    {
+        checkAndSetCodes(spaceCode, code);
+        this.registrationDetails = registrationDetails;
+    }
+    
+    /**
+     * Creates a new instance for the specified space code and project code.
+     * 
+     * @throws IllegalArgumentException if either the code or the space code is <code>null</code> or
+     *             an empty string.
+     */
+    public Project(Long id, String permId, String spaceCode, String code, EntityRegistrationDetails registrationDetails)
+    {
+        if (id == null || id == 0)
+        {
+            throw new IllegalArgumentException("Unspecified tech id.");
+        }
+        this.id = id;
+        if (permId == null || permId.length() == 0)
+        {
+            throw new IllegalArgumentException("Unspecified permanent id.");
+        }
+        this.permId = permId;
+        checkAndSetCodes(spaceCode, code);
+        this.registrationDetails = registrationDetails;
+    }
+
+    @SuppressWarnings("hiding")
+    private void checkAndSetCodes(String spaceCode, String code)
     {
         if (spaceCode == null || spaceCode.length() == 0)
         {
@@ -70,7 +114,26 @@ public final class Project implements Serializable, IIdentifierHolder
             throw new IllegalArgumentException("Unspecified code.");
         }
         this.code = code;
-        this.registrationDetails = registrationDetails;
+    }
+
+    /**
+     * Returns the techical database id of the project.
+     * 
+     * @since 1.22
+     */
+    public Long getId()
+    {
+        return id;
+    }
+
+    /**
+     * Returns the permanent id of the project.
+     * 
+     * @since 1.22
+     */
+    public String getPermId()
+    {
+        return permId;
     }
 
     /**
@@ -106,30 +169,108 @@ public final class Project implements Serializable, IIdentifierHolder
         return registrationDetails;
     }
 
+    @Override
+    public int hashCode()
+    {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((code == null) ? 0 : code.hashCode());
+        result = prime * result + ((id == null) ? 0 : id.hashCode());
+        result = prime * result + ((permId == null) ? 0 : permId.hashCode());
+        result =
+                prime * result
+                        + ((registrationDetails == null) ? 0 : registrationDetails.hashCode());
+        result = prime * result + ((spaceCode == null) ? 0 : spaceCode.hashCode());
+        return result;
+    }
+
     @Override
     public boolean equals(Object obj)
     {
-        if (obj == this)
+        if (this == obj)
         {
             return true;
         }
-        if (obj instanceof Project == false)
+        if (obj == null)
         {
             return false;
         }
-        Project project = (Project) obj;
-        return project.spaceCode.equals(spaceCode) && project.code.equals(code);
-    }
-
-    @Override
-    public int hashCode()
-    {
-        return 37 * spaceCode.hashCode() + code.hashCode();
+        if (getClass() != obj.getClass())
+        {
+            return false;
+        }
+        Project other = (Project) obj;
+        if (code == null)
+        {
+            if (other.code != null)
+            {
+                return false;
+            }
+        } else if (code.equals(other.code) == false)
+        {
+            return false;
+        }
+        if (id == null)
+        {
+            if (other.id != null)
+            {
+                return false;
+            }
+        } else if (id.equals(other.id) == false)
+        {
+            return false;
+        }
+        if (permId == null)
+        {
+            if (other.permId != null)
+            {
+                return false;
+            }
+        } else if (permId.equals(other.permId) == false)
+        {
+            return false;
+        }
+        if (registrationDetails == null)
+        {
+            if (other.registrationDetails != null)
+            {
+                return false;
+            }
+        } else if (registrationDetails.equals(other.registrationDetails) == false)
+        {
+            return false;
+        }
+        if (spaceCode == null)
+        {
+            if (other.spaceCode != null)
+            {
+                return false;
+            }
+        } else if (spaceCode.equals(other.spaceCode) == false)
+        {
+            return false;
+        }
+        return true;
     }
 
     @Override
     public String toString()
     {
+        final StringBuilder buf = new StringBuilder();
+        buf.append(getIdentifier());
+        if (permId != null || id != null)
+        {
+            buf.append('[');
+            if (getPermId() != null)
+            {
+                buf.append(getPermId());
+            }
+            if (getId() != null)
+            {
+                buf.append("(" + getId() + ")");
+            }
+            buf.append(']');
+        }
         return getIdentifier();
     }
 
@@ -140,6 +281,16 @@ public final class Project implements Serializable, IIdentifierHolder
     {
     }
 
+    private void setId(Long id)
+    {
+        this.id = id;
+    }
+
+    private void setPermId(String permId)
+    {
+        this.permId = permId;
+    }
+
     private void setSpaceCode(String spaceCode)
     {
         this.spaceCode = spaceCode;
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/proteomics/client/api/v1/ProteomicsDataApiFacade.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/proteomics/client/api/v1/ProteomicsDataApiFacade.java
index be2482fcf58..5b94b11d167 100644
--- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/proteomics/client/api/v1/ProteomicsDataApiFacade.java
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/proteomics/client/api/v1/ProteomicsDataApiFacade.java
@@ -108,7 +108,8 @@ class ProteomicsDataApiFacade implements IProteomicsDataApiFacade
                 for (ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Project project : space
                         .getProjects())
                 {
-                    projects.add(new Project(space.getCode(), project.getCode()));
+                    projects.add(new Project(project.getId(), project.getPermId(), space.getCode(),
+                            project.getCode()));
                 }
             }
         }
@@ -123,7 +124,8 @@ class ProteomicsDataApiFacade implements IProteomicsDataApiFacade
     }
 
     @Override
-    public List<Experiment> listExperiments(@SuppressWarnings("hiding") String sessionToken,
+    public List<Experiment> listExperiments(@SuppressWarnings("hiding")
+    String sessionToken,
             String userID, String experimentTypeCode)
     {
         return service.listExperiments(sessionToken, userID, experimentTypeCode);
@@ -144,7 +146,8 @@ class ProteomicsDataApiFacade implements IProteomicsDataApiFacade
     }
 
     @Override
-    public void processProteinResultDataSets(@SuppressWarnings("hiding") String sessionToken,
+    public void processProteinResultDataSets(@SuppressWarnings("hiding")
+    String sessionToken,
             String userID, String dataSetProcessingKey, String experimentTypeCode,
             long[] experimentIDs)
     {
diff --git a/rtd_phosphonetx/sourceTest/java/ch/systemsx/cisd/openbis/plugin/proteomics/client/api/v1/ProteomicsDataApiFacadeTest.java b/rtd_phosphonetx/sourceTest/java/ch/systemsx/cisd/openbis/plugin/proteomics/client/api/v1/ProteomicsDataApiFacadeTest.java
index b057719966a..eb8265f2e7f 100644
--- a/rtd_phosphonetx/sourceTest/java/ch/systemsx/cisd/openbis/plugin/proteomics/client/api/v1/ProteomicsDataApiFacadeTest.java
+++ b/rtd_phosphonetx/sourceTest/java/ch/systemsx/cisd/openbis/plugin/proteomics/client/api/v1/ProteomicsDataApiFacadeTest.java
@@ -197,9 +197,11 @@ public class ProteomicsDataApiFacadeTest extends AssertJUnit
     private SpaceWithProjectsAndRoleAssignments createSpace(String spaceCode, String... projects)
     {
         SpaceWithProjectsAndRoleAssignments space = new SpaceWithProjectsAndRoleAssignments(spaceCode);
+        long id = 1;
         for (String project : projects)
         {
-            space.add(new Project(spaceCode, project));
+            space.add(new Project(id, Long.toString(id), spaceCode, project));
+            ++id;
         }
         return space;
     }
-- 
GitLab