diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AbstractBusinessObject.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AbstractBusinessObject.java index 251b068223b63a1e893f4cea52a19eec3f4fc85c..cbe3dd1bbb2a1b403b3bb4f33779521641a6937c 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AbstractBusinessObject.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AbstractBusinessObject.java @@ -107,6 +107,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.IModifierBean; import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialPE; import ch.systemsx.cisd.openbis.generic.shared.dto.MetaprojectPE; import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectPE; import ch.systemsx.cisd.openbis.generic.shared.dto.RelationshipTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE; import ch.systemsx.cisd.openbis.generic.shared.dto.Session; @@ -835,6 +836,17 @@ abstract class AbstractBusinessObject implements IDAOFactory } assignmentManager.performAssignment(relationshipService, session); } + + protected void assignSampleToProject(SamplePE sample, ProjectPE project) + { + if (project != null) + { + relationshipService.assignSampleToProject(session, sample, project); + } else + { + relationshipService.unassignSampleFromProject(session, sample); + } + } protected void assignDataSetToSampleAndExperiment(DataPE data, SamplePE newSample, ExperimentPE experiment) { diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AbstractSampleBusinessObject.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AbstractSampleBusinessObject.java index da9762509b7a264904137c82c8e4bf30f3dba6fe..6b9ee97ee4e4d2a7ec0181e6084f78176b3f5103 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AbstractSampleBusinessObject.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AbstractSampleBusinessObject.java @@ -232,6 +232,37 @@ abstract class AbstractSampleBusinessObject extends AbstractSampleIdentifierBusi } return experimentPE; } + + private ProjectPE tryFindProject(Map<String, ProjectPE> projectCache, ProjectIdentifier projectIdentifier) + { + if (projectIdentifier == null) + { + return null; + } + return tryFindProject(projectCache, projectIdentifier.toString(), null); + } + + private ProjectPE tryFindProject(Map<String, ProjectPE> projectCache, String projectIdentifier, + String defaultSpace) + { + if (projectIdentifier == null) + { + return null; + } + ProjectIdentifier identifier = new ProjectIdentifierFactory(projectIdentifier).createIdentifier(defaultSpace); + fillSpaceIdentifier(identifier); + String key = identifier.toString(); + ProjectPE project = projectCache == null ? null : projectCache.get(key); + if (project == null) + { + project = findProject(identifier); + if (projectCache != null) + { + projectCache.put(key, project); + } + } + return project; + } protected void setContainer(final SampleIdentifier sampleIdentifier, final SamplePE samplePE, String containerIdentifier, final String defaultSpace) @@ -559,7 +590,32 @@ abstract class AbstractSampleBusinessObject extends AbstractSampleIdentifierBusi assignSampleAndRelatedDataSetsToExperiment(sample, newExperiment); } + + protected void updateProject(SamplePE sample, ProjectIdentifier projectIdentifierOrNull, + Map<String, ProjectPE> projectCache) + { + if (sample.getProject() == null && projectIdentifierOrNull == null) + { + return; + } + ProjectPE newProject = tryFindProject(projectCache, projectIdentifierOrNull); + if (EntityHelper.equalEntities(newProject, sample.getProject()) == false) + { + ensureSampleAttachableToProject(sample, newProject); + assignSampleToProject(sample, newProject); + } + } + private void ensureSampleAttachableToProject(SamplePE sample, ProjectPE project) + { + if (sample.getSpace() == null && project != null) + { + throw UserFailureException.fromTemplate( + "It is not allowed to connect a shared sample '%s' to a project.", + sample.getIdentifier()); + } + } + private void ensureSampleAttachableToExperiment(SamplePE sample, ExperimentPE newExperiment) { if (sample.getSpace() == null && newExperiment != null) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/SampleBO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/SampleBO.java index c008c9b0a644a3bc8910acd7e88836da45097e00..ffa01b3ee197b5f57994792d47d4fbe2895c10e4 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/SampleBO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/SampleBO.java @@ -303,6 +303,7 @@ public final class SampleBO extends AbstractSampleBusinessObject implements ISam { updateExperiment(sample, updates.getExperimentIdentifierOrNull(), null); } + updateProject(sample, updates.getProjectIdentifier(), null); setContainer(updates.getSampleIdentifier(), sample, updates.getContainerIdentifierOrNull(), null); addAttachments(sample, updates.getAttachments(), attachments); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/server/GenericClientService.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/server/GenericClientService.java index 8f334ca1377e98beeba2110d2d5768f830334df7..a84fdb999bdcc02c4933f6b3e62bd6b080e43fc1 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/server/GenericClientService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/server/GenericClientService.java @@ -1124,7 +1124,7 @@ public class GenericClientService extends AbstractClientService implements IGene private ProjectIdentifier getProjectIdentifier(SampleUpdates updates) { - String identifier = updates.getParentIdentifierOrNull(); + String identifier = updates.getProjectIdentifierOrNull(); if (identifier == null) { return null;