Skip to content
Snippets Groups Projects
Commit 39dc72e1 authored by juanf's avatar juanf
Browse files

SSDM-7235 : Continuous sample codes, project samples support

parent ccb751d2
No related branches found
No related tags found
No related merge requests found
...@@ -25,6 +25,8 @@ import java.util.Map; ...@@ -25,6 +25,8 @@ import java.util.Map;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.project.id.ProjectIdentifier;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.id.SampleIdentifier;
import ch.systemsx.cisd.common.io.DelegatedReader; import ch.systemsx.cisd.common.io.DelegatedReader;
import ch.systemsx.cisd.common.parser.ExcelFileLoader; import ch.systemsx.cisd.common.parser.ExcelFileLoader;
import ch.systemsx.cisd.common.parser.IParserObjectFactory; import ch.systemsx.cisd.common.parser.IParserObjectFactory;
...@@ -85,7 +87,9 @@ public class SampleUploadSectionsParser ...@@ -85,7 +87,9 @@ public class SampleUploadSectionsParser
List<String> generateCodes(int size); List<String> generateCodes(int size);
} }
public static BatchSamplesOperation prepareSamples(final SampleType sampleType, public static BatchSamplesOperation prepareSamples(
final boolean projectSamplesEnabled,
final SampleType sampleType,
final String spaceIdentifierSilentOverrideOrNull, final String spaceIdentifierSilentOverrideOrNull,
final String experimentIdentifierSilentOverrideOrNull, final String experimentIdentifierSilentOverrideOrNull,
final Collection<NamedInputStream> files, String defaultGroupIdentifier, final Collection<NamedInputStream> files, String defaultGroupIdentifier,
...@@ -107,7 +111,7 @@ public class SampleUploadSectionsParser ...@@ -107,7 +111,7 @@ public class SampleUploadSectionsParser
case REGISTRATION: case REGISTRATION:
if (isAutoGenerateCodes) if (isAutoGenerateCodes)
{ {
generateIdentifiers(defaultGroupIdentifier, sampleCodeGeneratorOrNull, generateIdentifiers(projectSamplesEnabled, defaultGroupIdentifier, sampleCodeGeneratorOrNull,
isAutoGenerateCodes, newSamples); isAutoGenerateCodes, newSamples);
} }
break; break;
...@@ -332,7 +336,8 @@ public class SampleUploadSectionsParser ...@@ -332,7 +336,8 @@ public class SampleUploadSectionsParser
return results; return results;
} }
private static void generateIdentifiers(String defaultGroupIdentifier, private static void generateIdentifiers(boolean projectSamplesEnabled,
String defaultGroupIdentifier,
SampleCodeGenerator sampleCodeGenerator, boolean isAutoGenerateCodes, SampleCodeGenerator sampleCodeGenerator, boolean isAutoGenerateCodes,
List<NewSamplesWithTypes> newSamplesWithTypes) List<NewSamplesWithTypes> newSamplesWithTypes)
{ {
...@@ -344,14 +349,22 @@ public class SampleUploadSectionsParser ...@@ -344,14 +349,22 @@ public class SampleUploadSectionsParser
List<String> codes = sampleCodeGenerator.generateCodes(newSamples.size()); List<String> codes = sampleCodeGenerator.generateCodes(newSamples.size());
for (int i = 0; i < newSamples.size(); i++) for (int i = 0; i < newSamples.size(); i++)
{ {
if (newSamples.get(i).getDefaultSpaceIdentifier() == null || newSamples.get(i).getDefaultSpaceIdentifier().isEmpty()) String spaceCodeOrNull = null;
if (newSamples.get(i).getDefaultSpaceIdentifier() == null || newSamples.get(i).getDefaultSpaceIdentifier().isEmpty())
{ {
newSamples.get(i).setIdentifier(defaultGroupIdentifier + "/" + codes.get(i)); spaceCodeOrNull = defaultGroupIdentifier;
} else } else
{ {
newSamples.get(i).setIdentifier( spaceCodeOrNull = newSamples.get(i).getDefaultSpaceIdentifier();
newSamples.get(i).getDefaultSpaceIdentifier() + "/" + codes.get(i));
} }
spaceCodeOrNull = spaceCodeOrNull.substring(1);
String projectCodeOrNull = null;
if(projectSamplesEnabled && newSamples.get(i).getExperimentIdentifier() != null && !newSamples.get(i).getExperimentIdentifier().isEmpty()) {
String[] experimentIdentifierParts = newSamples.get(i).getExperimentIdentifier().split("/");
projectCodeOrNull = experimentIdentifierParts[experimentIdentifierParts.length - 2];
}
SampleIdentifier identifier = new SampleIdentifier(spaceCodeOrNull, projectCodeOrNull, null, codes.get(i));
newSamples.get(i).setIdentifier(identifier.getIdentifier());
} }
} }
} }
......
...@@ -26,6 +26,7 @@ import java.util.HashMap; ...@@ -26,6 +26,7 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import java.util.Set; import java.util.Set;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -39,6 +40,7 @@ import ch.systemsx.cisd.base.exceptions.CheckedExceptionTunnel; ...@@ -39,6 +40,7 @@ import ch.systemsx.cisd.base.exceptions.CheckedExceptionTunnel;
import ch.systemsx.cisd.common.exceptions.ExceptionUtils; import ch.systemsx.cisd.common.exceptions.ExceptionUtils;
import ch.systemsx.cisd.common.properties.PropertyUtils; import ch.systemsx.cisd.common.properties.PropertyUtils;
import ch.systemsx.cisd.common.servlet.IRequestContextProvider; import ch.systemsx.cisd.common.servlet.IRequestContextProvider;
import ch.systemsx.cisd.common.spring.ExposablePropertyPlaceholderConfigurer;
import ch.systemsx.cisd.openbis.common.spring.IUncheckedMultipartFile; import ch.systemsx.cisd.openbis.common.spring.IUncheckedMultipartFile;
import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DataSetUpdates; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DataSetUpdates;
import ch.systemsx.cisd.openbis.generic.client.web.client.dto.SampleUpdates; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.SampleUpdates;
...@@ -114,6 +116,9 @@ import ch.systemsx.cisd.openbis.plugin.generic.shared.ResourceNames; ...@@ -114,6 +116,9 @@ import ch.systemsx.cisd.openbis.plugin.generic.shared.ResourceNames;
public class GenericClientService extends AbstractClientService implements IGenericClientService, IEntityImportService public class GenericClientService extends AbstractClientService implements IGenericClientService, IEntityImportService
{ {
@Resource(name = ExposablePropertyPlaceholderConfigurer.PROPERTY_CONFIGURER_BEAN_NAME)
private ExposablePropertyPlaceholderConfigurer configurer;
@Resource(name = ResourceNames.GENERIC_PLUGIN_SERVER) @Resource(name = ResourceNames.GENERIC_PLUGIN_SERVER)
private IGenericServerInternal genericServer; private IGenericServerInternal genericServer;
...@@ -592,9 +597,11 @@ public class GenericClientService extends AbstractClientService implements IGene ...@@ -592,9 +597,11 @@ public class GenericClientService extends AbstractClientService implements IGene
{ {
files.add(new NamedInputStream(f.getInputStream(), f.getOriginalFilename())); files.add(new NamedInputStream(f.getInputStream(), f.getOriginalFilename()));
} }
boolean projectSamplesEnabled = PropertyUtils.getBoolean(configurer.getResolvedProps(), Constants.PROJECT_SAMPLES_ENABLED_KEY, false);
BatchSamplesOperation batchSamplesOperation = BatchSamplesOperation batchSamplesOperation =
SampleUploadSectionsParser.prepareSamples(sampleType, spaceIdentifierSilentOverrideOrNull, experimentIdentifierSilentOverrideOrNull, SampleUploadSectionsParser.prepareSamples(projectSamplesEnabled, sampleType, spaceIdentifierSilentOverrideOrNull, experimentIdentifierSilentOverrideOrNull,
files, files,
defaultGroupIdentifier, sampleCodeGeneratorOrNull, allowExperiments, defaultGroupIdentifier, sampleCodeGeneratorOrNull, allowExperiments,
excelSheetName, operationKind); excelSheetName, operationKind);
...@@ -1372,7 +1379,10 @@ public class GenericClientService extends AbstractClientService implements IGene ...@@ -1372,7 +1379,10 @@ public class GenericClientService extends AbstractClientService implements IGene
Map<String, Object> info = new HashMap<String, Object>(); Map<String, Object> info = new HashMap<String, Object>();
try try
{ {
boolean projectSamplesEnabled = PropertyUtils.getBoolean(configurer.getResolvedProps(), Constants.PROJECT_SAMPLES_ENABLED_KEY, false);
BatchSamplesOperation batchSamplesOperation = SampleUploadSectionsParser.prepareSamples( BatchSamplesOperation batchSamplesOperation = SampleUploadSectionsParser.prepareSamples(
projectSamplesEnabled,
sampleType, sampleType,
null, null,
null, null,
......
...@@ -68,6 +68,7 @@ import ch.systemsx.cisd.openbis.generic.server.business.bo.SampleCodeGeneratorBy ...@@ -68,6 +68,7 @@ import ch.systemsx.cisd.openbis.generic.server.business.bo.SampleCodeGeneratorBy
import ch.systemsx.cisd.openbis.generic.server.business.bo.SampleCodeGeneratorForTempCodes; import ch.systemsx.cisd.openbis.generic.server.business.bo.SampleCodeGeneratorForTempCodes;
import ch.systemsx.cisd.openbis.generic.server.business.bo.samplelister.ISampleLister; import ch.systemsx.cisd.openbis.generic.server.business.bo.samplelister.ISampleLister;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.IProjectDAO;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.ISampleDAO; import ch.systemsx.cisd.openbis.generic.server.dataaccess.ISampleDAO;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.ISpaceDAO; import ch.systemsx.cisd.openbis.generic.server.dataaccess.ISpaceDAO;
import ch.systemsx.cisd.openbis.generic.server.plugin.IDataSetTypeSlaveServerPlugin; import ch.systemsx.cisd.openbis.generic.server.plugin.IDataSetTypeSlaveServerPlugin;
...@@ -111,6 +112,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE; ...@@ -111,6 +112,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentTypePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentUpdatesDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentUpdatesDTO;
import ch.systemsx.cisd.openbis.generic.shared.dto.MetaprojectPE; import ch.systemsx.cisd.openbis.generic.shared.dto.MetaprojectPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.SampleBatchUpdatesDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleBatchUpdatesDTO;
import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE; import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.SampleTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleTypePE;
...@@ -1041,9 +1043,12 @@ public final class GenericServer extends AbstractServer<IGenericServerInternal> ...@@ -1041,9 +1043,12 @@ public final class GenericServer extends AbstractServer<IGenericServerInternal>
public void updateTemporaryCodes(String sessionToken, Map<String, List<String>> sampleTypeCodeToTemporaryIdentifiers) public void updateTemporaryCodes(String sessionToken, Map<String, List<String>> sampleTypeCodeToTemporaryIdentifiers)
{ {
ISpaceDAO spaceDAO = getDAOFactory().getSpaceDAO(); ISpaceDAO spaceDAO = getDAOFactory().getSpaceDAO();
IProjectDAO projectDAO = getDAOFactory().getProjectDAO();
ISampleDAO sampleDAO = getDAOFactory().getSampleDAO(); ISampleDAO sampleDAO = getDAOFactory().getSampleDAO();
Map<String, SpacePE> spaceCache = new HashMap<String, SpacePE>(); Map<String, SpacePE> spaceCache = new HashMap<String, SpacePE>();
Map<String, ProjectPE> projectCache = new HashMap<String, ProjectPE>();
Map<String, List<String>> spaceToOldSampleCodes = new HashMap<String, List<String>>(); Map<String, List<String>> spaceToOldSampleCodes = new HashMap<String, List<String>>();
Map<String, List<String>> projectToOldSampleCodes = new HashMap<String, List<String>>();
Map<String, String> identifiersToNewSampleCodes = new HashMap<String, String>(); Map<String, String> identifiersToNewSampleCodes = new HashMap<String, String>();
// Generate Updates for each space and build helper maps // Generate Updates for each space and build helper maps
...@@ -1060,23 +1065,48 @@ public final class GenericServer extends AbstractServer<IGenericServerInternal> ...@@ -1060,23 +1065,48 @@ public final class GenericServer extends AbstractServer<IGenericServerInternal>
String tempIdentifier = temporaryIdentifiers.get(tIdx); String tempIdentifier = temporaryIdentifiers.get(tIdx);
String spaceCode = tempIdentifier.split("/")[1]; String spaceCode = tempIdentifier.split("/")[1];
String tempSampleCode = tempIdentifier.substring(tempIdentifier.lastIndexOf('/') + 1, tempIdentifier.length()); String tempSampleCode = tempIdentifier.substring(tempIdentifier.lastIndexOf('/') + 1, tempIdentifier.length());
SpacePE spacePE = spaceCache.get(spaceCode); String[] tempIdentifierParts = tempIdentifier.split("/");
if (spacePE == null) String projectIdentifier = null;
{ String projectCode = null;
spacePE = spaceDAO.tryFindSpaceByCode(spaceCode); if(tempIdentifierParts.length == 4) {
spaceCache.put(spaceCode, spacePE); projectCode = tempIdentifierParts[2];
projectIdentifier = "/" + spaceCode + "/" + projectCode;
} }
List<String> oldSampleCodes = spaceToOldSampleCodes.get(spaceCode);
if (oldSampleCodes == null) List<String> oldSampleCodes = null;
{ if(projectIdentifier != null) {
oldSampleCodes = new ArrayList<String>(); ProjectPE projectPE = projectCache.get(projectIdentifier);
spaceToOldSampleCodes.put(spaceCode, oldSampleCodes); if(projectPE == null) {
projectPE = projectDAO.tryFindProject(spaceCode, projectCode);
projectCache.put(projectIdentifier, projectPE);
}
oldSampleCodes = projectToOldSampleCodes.get(projectIdentifier);
if (oldSampleCodes == null)
{
oldSampleCodes = new ArrayList<String>();
projectToOldSampleCodes.put(projectIdentifier, oldSampleCodes);
}
} else {
SpacePE spacePE = spaceCache.get(spaceCode);
if (spacePE == null)
{
spacePE = spaceDAO.tryFindSpaceByCode(spaceCode);
spaceCache.put(spaceCode, spacePE);
}
oldSampleCodes = spaceToOldSampleCodes.get(spaceCode);
if (oldSampleCodes == null)
{
oldSampleCodes = new ArrayList<String>();
spaceToOldSampleCodes.put(spaceCode, oldSampleCodes);
}
} }
oldSampleCodes.add(tempSampleCode); oldSampleCodes.add(tempSampleCode);
identifiersToNewSampleCodes.put(tempIdentifier, newCodes.get(tIdx)); identifiersToNewSampleCodes.put(tempIdentifier, newCodes.get(tIdx));
} }
} }
// Retrieve all sample PE objects // Retrieve all sample PE objects
List<SamplePE> allSamplesPE = new ArrayList<SamplePE>(); List<SamplePE> allSamplesPE = new ArrayList<SamplePE>();
for (String spaceCode : spaceToOldSampleCodes.keySet()) for (String spaceCode : spaceToOldSampleCodes.keySet())
...@@ -1084,6 +1114,11 @@ public final class GenericServer extends AbstractServer<IGenericServerInternal> ...@@ -1084,6 +1114,11 @@ public final class GenericServer extends AbstractServer<IGenericServerInternal>
List<SamplePE> samples = sampleDAO.listByCodesAndSpace(spaceToOldSampleCodes.get(spaceCode), null, spaceCache.get(spaceCode)); List<SamplePE> samples = sampleDAO.listByCodesAndSpace(spaceToOldSampleCodes.get(spaceCode), null, spaceCache.get(spaceCode));
allSamplesPE.addAll(samples); allSamplesPE.addAll(samples);
} }
for (String projectIdentifier : projectToOldSampleCodes.keySet())
{
List<SamplePE> samples = sampleDAO.listByCodesAndProject(projectToOldSampleCodes.get(projectIdentifier), null, projectCache.get(projectIdentifier));
allSamplesPE.addAll(samples);
}
// Update all codes in sample PE objects // Update all codes in sample PE objects
for (SamplePE samplePE : allSamplesPE) for (SamplePE samplePE : allSamplesPE)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment