From c5cae848c56640481e609bf2f4e0623583f5871d Mon Sep 17 00:00:00 2001
From: gakin <gakin>
Date: Mon, 5 Sep 2016 11:36:09 +0000
Subject: [PATCH] SSDM-4079 - Changes to IProjectBO to make it possible to set
 perm id when creating a new project from dropboxes.

SVN: 37029
---
 .../openbis/generic/server/CommonServer.java    |  4 +++-
 .../server/ServiceForDataStoreServer.java       |  5 +----
 .../generic/server/business/bo/IProjectBO.java  |  3 ++-
 .../generic/server/business/bo/ProjectBO.java   | 17 +++++++++++------
 .../generic/shared/basic/dto/NewProject.java    | 11 ++---------
 .../server/business/bo/ProjectBOTest.java       |  7 ++++---
 6 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java
index ca5888ecdc2..4ffff4fc634 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java
@@ -1581,7 +1581,9 @@ public final class CommonServer extends AbstractCommonServer<ICommonServerForInt
     {
         final Session session = getSession(sessionToken);
         final IProjectBO projectBO = businessObjectFactory.createProjectBO(session);
-        projectBO.define(projectIdentifier, description, null, leaderId);
+
+        NewProject project = new NewProject(projectIdentifier.toString(), description);
+        projectBO.define(project, null, leaderId);
         projectBO.save();
         for (NewAttachment attachment : attachments)
         {
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ServiceForDataStoreServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ServiceForDataStoreServer.java
index 61e8f1abf38..e14f2dedb14 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ServiceForDataStoreServer.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ServiceForDataStoreServer.java
@@ -2268,10 +2268,7 @@ public class ServiceForDataStoreServer extends AbstractCommonServer<IServiceForD
             String registratorUserIdOrNull)
     {
         IProjectBO projectBO = businessObjectFactory.createProjectBO(session);
-        ProjectIdentifier identifier =
-                new ProjectIdentifierFactory(newProject.getIdentifier()).createIdentifier();
-        projectBO
-                .define(identifier, newProject.getDescription(), newProject.getAttachments(), null);
+        projectBO.define(newProject, newProject.getAttachments(), null);
         if (registratorUserIdOrNull != null)
         {
             projectBO.getProject().setRegistrator(
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IProjectBO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IProjectBO.java
index f8f0926a7b7..badf037b90d 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IProjectBO.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IProjectBO.java
@@ -22,6 +22,7 @@ import ch.systemsx.cisd.common.exceptions.UserFailureException;
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.id.project.IProjectId;
 import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewAttachment;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewProject;
 import ch.systemsx.cisd.openbis.generic.shared.dto.AttachmentPE;
 import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectPE;
 import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectUpdatesDTO;
@@ -41,7 +42,7 @@ public interface IProjectBO extends IEntityBusinessObject
      * 
      * @throws UserFailureException if <code>projectIdentifier</code> does already exist or project group is unspecified and home group is undefined.
      */
-    public void define(final ProjectIdentifier projectIdentifier, String description,
+    public void define(final NewProject newProject,
             List<NewAttachment> attachmentsOrNull, String leaderIdOrNull)
             throws UserFailureException;
 
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ProjectBO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ProjectBO.java
index 765d1a88ff0..e0405584e95 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ProjectBO.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ProjectBO.java
@@ -39,6 +39,7 @@ import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.id.project.ProjectPerm
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.id.project.ProjectTechIdId;
 import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewAttachment;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewProject;
 import ch.systemsx.cisd.openbis.generic.shared.dto.AttachmentPE;
 import ch.systemsx.cisd.openbis.generic.shared.dto.DeletedExperimentPE;
 import ch.systemsx.cisd.openbis.generic.shared.dto.DeletionPE;
@@ -88,17 +89,19 @@ public final class ProjectBO extends AbstractBusinessObject implements IProjectB
         this.historyCreator = historyCreator;
     }
 
-    private ProjectPE createProject(final ProjectIdentifier projectIdentifier, String description,
+    private ProjectPE createProject(final NewProject newProject,
             List<NewAttachment> attachmentsOrNull, String leaderIdOrNull)
     {
         final ProjectPE result = new ProjectPE();
+        ProjectIdentifier projectIdentifier =
+                new ProjectIdentifierFactory(newProject.getIdentifier()).createIdentifier();
         final SpacePE group =
                 SpaceIdentifierHelper.tryGetSpace(projectIdentifier, session.tryGetPerson(), this);
         result.setSpace(group);
         result.setRegistrator(findPerson());
-        result.setPermId(getPermIdDAO().createPermId());
+        result.setPermId(getOrCreatePermID(newProject));
         result.setCode(projectIdentifier.getProjectCode());
-        result.setDescription(description);
+        result.setDescription(newProject.getDescription());
         if (leaderIdOrNull != null)
         {
             PersonPE leader = getPersonDAO().tryFindPersonByUserId(leaderIdOrNull);
@@ -170,11 +173,13 @@ public final class ProjectBO extends AbstractBusinessObject implements IProjectB
     }
 
     @Override
-    public void define(ProjectIdentifier projectIdentifier, String description,
+    public void define(final NewProject newProject,
             List<NewAttachment> attachmentsOrNull, String creatorId) throws UserFailureException
     {
-        assert projectIdentifier != null : "Unspecified project identifier.";
-        this.project = createProject(projectIdentifier, description, attachmentsOrNull, creatorId);
+        assert newProject != null : "Unspecified new project.";
+        assert newProject.getIdentifier() != null : "Unspecified project identifier.";
+
+        this.project = createProject(newProject, attachmentsOrNull, creatorId);
         dataChanged = true;
     }
 
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/NewProject.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/NewProject.java
index d6141d4e910..d2547ed2858 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/NewProject.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/NewProject.java
@@ -22,28 +22,21 @@ import java.util.List;
 /**
  * @author Kaloyan Enimanev
  */
-public class NewProject implements Serializable
+public class NewProject extends Identifier<NewProject> implements Serializable
 {
 
     private static final long serialVersionUID = 1L;
 
-    private final String identifier;
-
     private final String description;
 
     private List<NewAttachment> attachments;
 
     public NewProject(String identifier, String description)
     {
-        this.identifier = identifier;
+        setIdentifier(identifier);
         this.description = description;
     }
 
-    public String getIdentifier()
-    {
-        return identifier;
-    }
-
     public String getDescription()
     {
         return description;
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ProjectBOTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ProjectBOTest.java
index 767d707786e..1ff2d4fc88a 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ProjectBOTest.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ProjectBOTest.java
@@ -33,6 +33,7 @@ import ch.systemsx.cisd.common.test.RecordingMatcher;
 import ch.systemsx.cisd.openbis.generic.server.business.ManagerTestTool;
 import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.deletion.EntityHistoryCreator;
 import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewProject;
 import ch.systemsx.cisd.openbis.generic.shared.dto.DeletedExperimentPE;
 import ch.systemsx.cisd.openbis.generic.shared.dto.DeletionPE;
 import ch.systemsx.cisd.openbis.generic.shared.dto.EventPE;
@@ -264,7 +265,7 @@ public final class ProjectBOTest extends AbstractBOTest
         boolean fail = true;
         try
         {
-            projectBO.define(null, null, null, null);
+            projectBO.define(new NewProject(null, null), null, null);
         } catch (final AssertionError ex)
         {
             fail = false;
@@ -285,7 +286,7 @@ public final class ProjectBOTest extends AbstractBOTest
                 }
             });
 
-        projectBO.define(createProjectIdent(), null, null, null);
+        projectBO.define(new NewProject(createProjectIdent().toString(), null), null, null);
 
         context.checking(new Expectations()
             {
@@ -324,7 +325,7 @@ public final class ProjectBOTest extends AbstractBOTest
                 }
             });
 
-        projectBO.define(projIdent, null, null, null);
+        projectBO.define(new NewProject(projIdent.toString(), null), null, null);
 
         context.checking(new Expectations()
             {
-- 
GitLab