diff --git a/server-application-server/source/java/ch/systemsx/cisd/openbis/generic/server/hotfix/ELNFixes.java b/server-application-server/source/java/ch/systemsx/cisd/openbis/generic/server/hotfix/ELNFixes.java index 72a91ed2c67d614268c3b872dc0d94de7fcf4bb9..b9ba0f449a62d17ba5bb5ea2eb12128c9a5f2f5a 100644 --- a/server-application-server/source/java/ch/systemsx/cisd/openbis/generic/server/hotfix/ELNFixes.java +++ b/server-application-server/source/java/ch/systemsx/cisd/openbis/generic/server/hotfix/ELNFixes.java @@ -18,8 +18,25 @@ package ch.systemsx.cisd.openbis.generic.server.hotfix; import static ch.systemsx.cisd.common.spring.ExposablePropertyPlaceholderConfigurer.PROPERTY_CONFIGURER_BEAN_NAME; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; import java.util.List; +import java.util.Map; +import java.util.Set; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.EntityKind; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.id.EntityTypePermId; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.Experiment; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.create.ExperimentCreation; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.fetchoptions.ExperimentFetchOptions; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.id.ExperimentIdentifier; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.id.IExperimentId; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.project.Project; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.project.create.ProjectCreation; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.project.fetchoptions.ProjectFetchOptions; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.project.id.IProjectId; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.project.id.ProjectIdentifier; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.space.Space; import org.apache.log4j.Logger; import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.search.SearchResult; @@ -43,6 +60,7 @@ public class ELNFixes { public static void beforeUpgrade(String sessionToken) throws Exception { operationLog.info("ELNFixes beforeUpgrade START"); IApplicationServerInternalApi api = CommonServiceProvider.getApplicationServerApi(); + storageCollectionIntroduction(sessionToken, api); storageValidationLevelFix(sessionToken, api); nameNoRTFFix(sessionToken, api); // TODO(alaskowski): SSDM-13831: Do migration here!!! @@ -155,4 +173,126 @@ public class ELNFixes { operationLog.info(String.format("ELNFixes fixProperties for propertiesTable %s", propertiesTable)); } + private static void storageCollectionIntroduction(String sessionToken, + IApplicationServerInternalApi api) + { + SampleSearchCriteria criteria = new SampleSearchCriteria(); + criteria.withType().withCode().thatEquals("STORAGE_POSITION"); + + SampleFetchOptions options = new SampleFetchOptions(); + options.withSpace(); + options.withExperiment(); + options.withProject(); + + SearchResult<Sample> storagePositionResults = api.searchSamples(sessionToken, criteria, options); + + Set<ProjectIdentifier> createdProjects = new HashSet<>(); + Set<ExperimentIdentifier> createdExperiments = new HashSet<>(); + + List<SampleUpdate> storagePositionUpdates = new ArrayList<>(); + + for (Sample storagePosition:storagePositionResults.getObjects()) { + Space space = storagePosition.getSpace(); + String spaceCode = space.getCode(); + String postFix = ""; + + if (spaceCode.startsWith("STORAGE") && spaceCode.length() > "STORAGE".length()) + { + int start = spaceCode.indexOf("_"); + postFix = spaceCode.substring(start + 1); + } + + ProjectIdentifier projectIdentifier = null; + + if (storagePosition.getProject() == null) + { + String projectCode = "STORAGE_POSITIONS"; + if (!postFix.isBlank()) { + projectCode += "_" + postFix; + } + projectIdentifier = new ProjectIdentifier(spaceCode, projectCode); + + if (createdProjects.contains(projectIdentifier) == false) + { + Map<IProjectId, Project> projects = + api.getProjects(sessionToken, Arrays.asList(projectIdentifier), + new ProjectFetchOptions()); + + System.out.println("PROJECT [FETCH]: " + projectIdentifier + " " + projects.size() + " " + Thread.currentThread().getName()); + + if (projects.size() == 1) { + createdProjects.add(projectIdentifier); + } + } + + if (createdProjects.contains(projectIdentifier) == false) + { + ProjectCreation creation = new ProjectCreation(); + creation.setSpaceId(space.getPermId()); + creation.setCode(projectCode); + System.out.println("PROJECT [CREATION]: " + creation.getSpaceId() + " " + projectCode + " " + Thread.currentThread().getName()); + api.createProjects(sessionToken, Arrays.asList(creation)); + createdProjects.add(projectIdentifier); + } + } else { + projectIdentifier = storagePosition.getProject().getIdentifier(); + } + + ExperimentIdentifier experimentIdentifier; + + if (storagePosition.getExperiment() == null) + { + String experimentCode = "STORAGE_POSITIONS_COLLECTION"; + if (!postFix.isBlank()) { + experimentCode += "_" + postFix; + } + String experimentType = "COLLECTION"; + + experimentIdentifier = new ExperimentIdentifier(spaceCode, projectIdentifier.getIdentifier().substring(projectIdentifier.getIdentifier().lastIndexOf('/') + 1), experimentCode); + + if (createdExperiments.contains(experimentIdentifier) == false) + { + Map<IExperimentId, Experiment> experiments = + api.getExperiments(sessionToken, Arrays.asList(experimentIdentifier), + new ExperimentFetchOptions()); + + System.out.println("EXPERIMENT [FETCH]: " + experimentIdentifier + " " + experiments.size() + " " + Thread.currentThread().getName()); + + if (experiments.size() == 1) { + createdExperiments.add(experimentIdentifier); + } + } + + if (createdExperiments.contains(experimentIdentifier) == false) + { + ExperimentCreation creation = new ExperimentCreation(); + creation.setProjectId(projectIdentifier); + creation.setCode(experimentCode); + creation.setTypeId(new EntityTypePermId(experimentType, EntityKind.EXPERIMENT)); + System.out.println("EXPERIMENT [CREATION]: " + creation.getProjectId() + " " + experimentCode + " " + Thread.currentThread().getName()); + api.createExperiments(sessionToken, Arrays.asList(creation)); + createdExperiments.add(experimentIdentifier); + } + } else { + experimentIdentifier = storagePosition.getExperiment().getIdentifier(); + } + + SampleUpdate sampleUpdate = new SampleUpdate(); + sampleUpdate.setSampleId(storagePosition.getPermId()); + sampleUpdate.setExperimentId(experimentIdentifier); + + storagePositionUpdates.add(sampleUpdate); + + if (storagePositionUpdates.size() > 1000) { + api.updateSamples(sessionToken, storagePositionUpdates); + storagePositionUpdates.clear(); + } + } + + if (storagePositionUpdates.isEmpty() == false) { + api.updateSamples(sessionToken, storagePositionUpdates); + storagePositionUpdates.clear(); + } + } + } diff --git a/ui-eln-lims/src/core-plugins/eln-lims/1/as/master-data/common-data-model.xls b/ui-eln-lims/src/core-plugins/eln-lims/1/as/master-data/common-data-model.xls index 86a4612971080b10dfbf33ebaa8b30de2430e281..d00993ab3e5d6e2edf97a7eb5d7f79cab09d8828 100644 Binary files a/ui-eln-lims/src/core-plugins/eln-lims/1/as/master-data/common-data-model.xls and b/ui-eln-lims/src/core-plugins/eln-lims/1/as/master-data/common-data-model.xls differ diff --git a/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/StorageListView.js b/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/StorageListView.js index d11005288329bdefd4c7b5963ced051a0debbfec..820132f2e9038a6894c0803b807aee868c5cb5ae 100644 --- a/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/StorageListView.js +++ b/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/StorageListView.js @@ -166,6 +166,7 @@ function StorageListView(storageListController, storageListModel) { code : uuid, identifier : null, sampleTypeCode : "STORAGE_POSITION", + experimentIdentifier: null, properties : {} }; _this._storageListModel.sample.children.push(newChildSample); @@ -244,6 +245,11 @@ function StorageListView(storageListController, storageListModel) { if(sampleChild.newSampleJustCreated) { sampleChild.identifier = IdentifierUtil.getSampleIdentifier(storageSpaceCode, null, sampleChild.code); delete sampleChild.newSampleJustCreated; + var postFix = ""; + if(storageSpaceCode.length > "STORAGE".length) { + postFix = storageSpaceCode.substring("STORAGE".length + 1); + } + sampleChild.experimentIdentifier = "/" + storageSpaceCode + "/STORAGE_POSITIONS" + postFix + "/STORAGE_POSITIONS_COLLECTION" + postFix; } else { // On update the identifier should be set, fail if not }