Skip to content
Snippets Groups Projects
Commit be9fe9c2 authored by kaloyane's avatar kaloyane
Browse files

[LMS-2347] Jython Dropbox API extension: add the possibility to create/fetch...

[LMS-2347] Jython Dropbox API extension: add the possibility to create/fetch materials within transactions

SVN: 21840
parent 23e7e0ac
No related branches found
No related tags found
No related merge requests found
Showing
with 724 additions and 25 deletions
......@@ -18,6 +18,7 @@ package ch.systemsx.cisd.etlserver.registrator;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import ch.systemsx.cisd.etlserver.ITopLevelDataSetRegistratorDelegate;
import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService;
......@@ -25,6 +26,7 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.dto.AtomicEntityOperationDeta
import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetRegistrationInformation;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewMaterial;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewProject;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSpace;
......@@ -78,6 +80,7 @@ public class DefaultEntityOperationService<T extends DataSetInformation> impleme
List<NewExperiment> experimentRegistrations = details.getExperimentRegistrations();
List<SampleUpdatesDTO> sampleUpdates = details.getSampleUpdates();
List<NewSample> sampleRegistrations = details.getSampleRegistrations();
Map<String, List<NewMaterial>> materialRegistrations = details.getMaterialRegistrations();
List<DataSetUpdatesDTO> dataSetUpdates = details.getDataSetUpdates();
List<NewExternalData> dataSetRegistrations = new ArrayList<NewExternalData>();
......@@ -89,8 +92,8 @@ public class DefaultEntityOperationService<T extends DataSetInformation> impleme
return new ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails(
details.tryUserIdOrNull(), spaceRegistrations, projectRegistrations,
experimentRegistrations, sampleUpdates, sampleRegistrations, dataSetRegistrations,
dataSetUpdates);
experimentRegistrations, sampleUpdates, sampleRegistrations, materialRegistrations,
dataSetRegistrations, dataSetUpdates);
}
}
\ No newline at end of file
......@@ -129,6 +129,21 @@ public interface IDataSetRegistrationTransaction
*/
ISpaceImmutable getSpace(String spaceCode);
/**
* Get a material from the openBIS AS. Returns null if the space does not exist.
*
* @return A material or null
*/
IMaterialImmutable getMaterial(String materialCode, String materialType);
/**
* Create a new space to register with the openBIS AS.
*
* @param materialCode the code of the material
* @param materialType the type of the material
*/
IMaterial createNewMaterial(String materialCode, String materialType);
// File operations -- The source and destination paths are local to the incoming data set folder
// or incoming directory if the data set is just one file
......
/*
* Copyright 2011 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.etlserver.registrator.api.v1;
/**
* @author Kaloyan Enimanev
*/
public interface IMaterial extends IMaterialImmutable
{
/**
* Set the value for a property.
*/
void setPropertyValue(String propertyCode, String propertyValue);
}
/*
* Copyright 2011 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.etlserver.registrator.api.v1;
/**
* @author Kaloyan Enimanev
*/
public interface IMaterialImmutable
{
/**
* Return the code for this material.
*/
String getCode();
/**
* Return the type for this material. May be null.
*/
String getMaterialType();
/**
* Return true if the material exists in the database.
*/
boolean isExistingMaterial();
/**
* Return the value of a property specified by a code. May return null of no such property with
* code <code>propertyCode</code> is found.
*/
String getPropertyValue(String propertyCode);
}
......@@ -18,7 +18,9 @@ package ch.systemsx.cisd.etlserver.registrator.api.v1.impl;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import ch.systemsx.cisd.common.exceptions.NotImplementedException;
import ch.systemsx.cisd.common.filesystem.FileUtilities;
......@@ -32,6 +34,7 @@ import ch.systemsx.cisd.etlserver.registrator.api.v1.IDataSetImmutable;
import ch.systemsx.cisd.etlserver.registrator.api.v1.IDataSetUpdatable;
import ch.systemsx.cisd.etlserver.registrator.api.v1.IExperiment;
import ch.systemsx.cisd.etlserver.registrator.api.v1.IExperimentImmutable;
import ch.systemsx.cisd.etlserver.registrator.api.v1.IMaterial;
import ch.systemsx.cisd.etlserver.registrator.api.v1.IProject;
import ch.systemsx.cisd.etlserver.registrator.api.v1.ISample;
import ch.systemsx.cisd.etlserver.registrator.api.v1.ISampleImmutable;
......@@ -42,6 +45,7 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetRegistrationInformation;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewMaterial;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewProject;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSpace;
......@@ -112,6 +116,8 @@ abstract class AbstractTransactionState<T extends DataSetInformation>
private final List<Sample> samplesToBeUpdated = new ArrayList<Sample>();
private final List<Material> materialsToBeRegistered = new ArrayList<Material>();
private String userIdOrNull = null;
public LiveTransactionState(DataSetRegistrationTransaction<T> parent,
......@@ -301,6 +307,13 @@ abstract class AbstractTransactionState<T extends DataSetInformation>
return project;
}
public IMaterial createNewMaterial(String materialCode, String materialType)
{
Material material = new Material(materialCode, materialType);
materialsToBeRegistered.add(material);
return material;
}
public String moveFile(String src, IDataSet dst)
{
File srcFile = new File(src);
......@@ -436,6 +449,7 @@ abstract class AbstractTransactionState<T extends DataSetInformation>
List<NewExperiment> experimentRegistrations = convertExperimentsToBeRegistered();
List<SampleUpdatesDTO> sampleUpdates = convertSamplesToBeUpdated();
List<NewSample> sampleRegistrations = convertSamplesToBeRegistered();
Map<String, List<NewMaterial>> materialRegistrations = convertMaterialsToBeRegistered();
List<DataSetUpdatesDTO> dataSetUpdates = convertDataSetsToBeUpdated();
// experiment updates not yet supported
......@@ -444,8 +458,8 @@ abstract class AbstractTransactionState<T extends DataSetInformation>
AtomicEntityOperationDetails<T> registrationDetails =
new AtomicEntityOperationDetails<T>(getUserId(), spaceRegistrations,
projectRegistrations, experimentUpdates, experimentRegistrations,
sampleUpdates, sampleRegistrations, dataSetRegistrations,
dataSetUpdates);
sampleUpdates, sampleRegistrations, materialRegistrations,
dataSetRegistrations, dataSetUpdates);
return registrationDetails;
}
......@@ -509,6 +523,24 @@ abstract class AbstractTransactionState<T extends DataSetInformation>
return result;
}
private Map<String, List<NewMaterial>> convertMaterialsToBeRegistered()
{
Map<String, List<NewMaterial>> result = new HashMap<String, List<NewMaterial>>();
for (Material material : materialsToBeRegistered)
{
NewMaterial converted = ConversionUtils.convertToNewMaterial(material);
String materialType = material.getMaterialType();
List<NewMaterial> materialsOfSameType = result.get(materialType);
if (materialsOfSameType == null)
{
materialsOfSameType = new ArrayList<NewMaterial>();
result.put(materialType, materialsOfSameType);
}
materialsOfSameType.add(converted);
}
return result;
}
@Override
public boolean isCommitted()
{
......
......@@ -29,6 +29,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewAttachment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewMaterial;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewProject;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSpace;
......@@ -222,4 +223,13 @@ public class ConversionUtils
return dataSetUpdate;
}
public static NewMaterial convertToNewMaterial(Material material)
{
NewMaterial newMaterial = new NewMaterial(material.getCode());
IEntityProperty[] properties =
material.getMaterial().getProperties().toArray(new IEntityProperty[0]);
newMaterial.setProperties(properties);
return newMaterial;
}
}
......@@ -39,6 +39,8 @@ import ch.systemsx.cisd.etlserver.registrator.api.v1.IDataSetRegistrationTransac
import ch.systemsx.cisd.etlserver.registrator.api.v1.IDataSetUpdatable;
import ch.systemsx.cisd.etlserver.registrator.api.v1.IExperiment;
import ch.systemsx.cisd.etlserver.registrator.api.v1.IExperimentImmutable;
import ch.systemsx.cisd.etlserver.registrator.api.v1.IMaterial;
import ch.systemsx.cisd.etlserver.registrator.api.v1.IMaterialImmutable;
import ch.systemsx.cisd.etlserver.registrator.api.v1.IProject;
import ch.systemsx.cisd.etlserver.registrator.api.v1.IProjectImmutable;
import ch.systemsx.cisd.etlserver.registrator.api.v1.ISample;
......@@ -53,6 +55,7 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService;
import ch.systemsx.cisd.openbis.dss.generic.shared.dto.AtomicEntityOperationDetails;
import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetRegistrationInformation;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifierFactory;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ProjectIdentifier;
......@@ -277,6 +280,19 @@ public class DataSetRegistrationTransaction<T extends DataSetInformation> implem
return (null == spaceOrNull) ? null : new SpaceImmutable(spaceOrNull);
}
public IMaterialImmutable getMaterial(String materialCode, String materialType)
{
MaterialIdentifier materialIdentifier = new MaterialIdentifier(materialCode, materialType);
ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material materialOrNull =
openBisService.tryGetMaterial(materialIdentifier);
return (null == materialOrNull) ? null : new MaterialImmutable(materialOrNull);
}
public IMaterial createNewMaterial(String materialCode, String materialType)
{
return getStateAsLiveState().createNewMaterial(materialCode, materialType);
}
public String moveFile(String src, IDataSet dst)
{
return getStateAsLiveState().moveFile(src, dst);
......
/*
* Copyright 2011 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.etlserver.registrator.api.v1.impl;
import java.util.ArrayList;
import ch.systemsx.cisd.etlserver.registrator.api.v1.IMaterial;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialType;
import ch.systemsx.cisd.openbis.generic.shared.util.EntityHelper;
/**
* @author Kaloyan Enimanev
*/
public class Material extends MaterialImmutable implements IMaterial
{
private static ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material buildMaterialWithCodeAndType(
String code, String type)
{
ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material material =
new ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material();
material.setCode(code);
MaterialType materialType = new MaterialType();
materialType.setCode(type);
material.setMaterialType(materialType);
material.setProperties(new ArrayList<IEntityProperty>());
return material;
}
public Material(ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material material)
{
super(material);
}
public Material(String code, String type)
{
super(buildMaterialWithCodeAndType(code, type), false);
}
public void setPropertyValue(String propertyCode, String propertyValue)
{
EntityHelper.createOrUpdateProperty(getMaterial(), propertyCode, propertyValue);
}
}
/*
* Copyright 2011 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.etlserver.registrator.api.v1.impl;
import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.etlserver.registrator.api.v1.IMaterialImmutable;
import ch.systemsx.cisd.openbis.generic.shared.util.EntityHelper;
/**
* @author Kaloyan Enimanev
*/
public class MaterialImmutable implements IMaterialImmutable
{
private final ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material material;
private final boolean existingMaterial;
public MaterialImmutable(ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material material)
{
this(material, true);
}
public MaterialImmutable(ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material material,
boolean existingMaterial)
{
this.material = material;
this.existingMaterial = existingMaterial;
}
public String getCode()
{
return material.getCode();
}
public String getMaterialType()
{
if (material.getMaterialType() != null)
{
return material.getMaterialType().getCode();
}
return null;
}
public boolean isExistingMaterial()
{
return existingMaterial;
}
public ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material getMaterial()
{
return material;
}
/**
* Throw an exception if the sample does not exist
*/
protected void checkExists()
{
if (false == isExistingMaterial())
{
throw new UserFailureException("Material does not exist.");
}
}
public String getPropertyValue(String propertyCode)
{
return EntityHelper.tryFindPropertyValue(material, propertyCode);
}
}
......@@ -47,6 +47,8 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExperimentType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListSampleCriteria;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSamplesWithTypes;
......@@ -558,4 +560,9 @@ public final class EncapsulatedOpenBISService implements IEncapsulatedOpenBISSer
return service.listExperiments(session.getToken(), projectIdentifier);
}
public Material tryGetMaterial(MaterialIdentifier materialIdentifier)
{
return service.tryGetMaterial(session.getToken(), materialIdentifier);
}
}
\ No newline at end of file
......@@ -34,6 +34,8 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExperimentType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListSampleCriteria;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSamplesWithTypes;
......@@ -153,6 +155,12 @@ public interface IEncapsulatedOpenBISService
public SampleIdentifier tryToGetSampleIdentifier(String samplePermID)
throws UserFailureException;
/**
* For given {@link MaterialIdentifier} returns the corresponding {@link Material}.
*/
@ManagedAuthentication
public Material tryGetMaterial(MaterialIdentifier materialIdentifier);
/**
* Lists vocabulary terms.
*/
......
......@@ -18,9 +18,12 @@ package ch.systemsx.cisd.openbis.dss.generic.shared.dto;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewMaterial;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewProject;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSpace;
......@@ -53,6 +56,8 @@ public class AtomicEntityOperationDetails<T extends DataSetInformation> implemen
private final List<NewSample> sampleRegistrations;
private final Map<String /* material type */, List<NewMaterial>> materialRegistrations;
private final List<DataSetRegistrationInformation<T>> dataSetRegistrations;
private final List<DataSetUpdatesDTO> dataSetUpdates;
......@@ -62,6 +67,7 @@ public class AtomicEntityOperationDetails<T extends DataSetInformation> implemen
List<ExperimentUpdatesDTO> experimentUpdates,
List<NewExperiment> experimentRegistrations, List<SampleUpdatesDTO> sampleUpdates,
List<NewSample> sampleRegistrations,
Map<String, List<NewMaterial>> materialRegistrations,
List<DataSetRegistrationInformation<T>> dataSetRegistrations,
List<DataSetUpdatesDTO> dataSetUpdates)
{
......@@ -72,6 +78,7 @@ public class AtomicEntityOperationDetails<T extends DataSetInformation> implemen
this.experimentRegistrations = new ArrayList<NewExperiment>(experimentRegistrations);
this.sampleUpdates = new ArrayList<SampleUpdatesDTO>(sampleUpdates);
this.sampleRegistrations = new ArrayList<NewSample>(sampleRegistrations);
this.materialRegistrations = new HashMap<String, List<NewMaterial>>(materialRegistrations);
this.dataSetRegistrations =
new ArrayList<DataSetRegistrationInformation<T>>(dataSetRegistrations);
this.dataSetUpdates = new ArrayList<DataSetUpdatesDTO>(dataSetUpdates);
......@@ -122,4 +129,9 @@ public class AtomicEntityOperationDetails<T extends DataSetInformation> implemen
return projectRegistrations;
}
public Map<String, List<NewMaterial>> getMaterialRegistrations()
{
return materialRegistrations;
}
}
......@@ -17,7 +17,9 @@
package ch.systemsx.cisd.openbis.dss.generic.server;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import org.jmock.Expectations;
import org.jmock.Mockery;
......@@ -33,6 +35,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewAttachment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewMaterial;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewProject;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSpace;
......@@ -161,6 +164,7 @@ public class EncapsulatedOpenBISServiceTest
new AtomicEntityOperationDetails(null, Arrays.<NewSpace> asList(),
Arrays.<NewProject> asList(), Arrays.<NewExperiment> asList(),
Arrays.<SampleUpdatesDTO> asList(), Arrays.<NewSample> asList(),
Collections.<String, List<NewMaterial>> emptyMap(),
Arrays.asList(data), Arrays.<DataSetUpdatesDTO> asList());
context.checking(new Expectations()
{
......
......@@ -23,6 +23,8 @@ import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import ch.systemsx.cisd.authentication.IAuthenticationService;
......@@ -39,6 +41,7 @@ import ch.systemsx.cisd.openbis.generic.server.business.bo.IDataBO;
import ch.systemsx.cisd.openbis.generic.server.business.bo.IExperimentBO;
import ch.systemsx.cisd.openbis.generic.server.business.bo.IExperimentTable;
import ch.systemsx.cisd.openbis.generic.server.business.bo.IGroupBO;
import ch.systemsx.cisd.openbis.generic.server.business.bo.IMaterialBO;
import ch.systemsx.cisd.openbis.generic.server.business.bo.IProjectBO;
import ch.systemsx.cisd.openbis.generic.server.business.bo.IRoleAssignmentTable;
import ch.systemsx.cisd.openbis.generic.server.business.bo.ISampleBO;
......@@ -76,7 +79,10 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Grantee;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListOrSearchSampleCriteria;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListSampleCriteria;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewMaterial;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewProject;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSamplesWithTypes;
......@@ -143,6 +149,7 @@ import ch.systemsx.cisd.openbis.generic.shared.translator.ExperimentTranslator;
import ch.systemsx.cisd.openbis.generic.shared.translator.ExperimentTranslator.LoadableFields;
import ch.systemsx.cisd.openbis.generic.shared.translator.ExperimentTypeTranslator;
import ch.systemsx.cisd.openbis.generic.shared.translator.GroupTranslator;
import ch.systemsx.cisd.openbis.generic.shared.translator.MaterialTranslator;
import ch.systemsx.cisd.openbis.generic.shared.translator.PersonTranslator;
import ch.systemsx.cisd.openbis.generic.shared.translator.ProjectTranslator;
import ch.systemsx.cisd.openbis.generic.shared.translator.SampleTranslator;
......@@ -1070,7 +1077,6 @@ public class ETLService extends AbstractCommonServer<IETLService> implements IET
// space does not exist
return null;
}
}
public Project tryGetProject(String sessionToken, ProjectIdentifier projectIdentifier)
......@@ -1089,6 +1095,21 @@ public class ETLService extends AbstractCommonServer<IETLService> implements IET
}
}
public Material tryGetMaterial(String sessionToken, MaterialIdentifier materialIdentifier)
{
final Session session = getSession(sessionToken);
final IMaterialBO bo = businessObjectFactory.createMaterialBO(session);
try
{
bo.loadByMaterialIdentifier(materialIdentifier);
return MaterialTranslator.translate(bo.getMaterial());
} catch (UserFailureException ufe)
{
// material does not exist
return null;
}
}
public AtomicEntityOperationResult performEntityOperations(String sessionToken,
AtomicEntityOperationDetails operationDetails)
{
......@@ -1096,6 +1117,8 @@ public class ETLService extends AbstractCommonServer<IETLService> implements IET
List<Space> spacesCreated = createSpaces(session, operationDetails);
List<Material> materialsCreated = createMaterials(session, operationDetails);
List<Project> projectsCreated = createProjects(session, operationDetails);
List<Experiment> experimentsCreated = createExperiments(session, operationDetails);
......@@ -1109,7 +1132,7 @@ public class ETLService extends AbstractCommonServer<IETLService> implements IET
List<ExternalData> dataSetsUpdated = updateDataSets(session, operationDetails);
return new AtomicEntityOperationResult(spacesCreated, projectsCreated, experimentsCreated,
samplesUpdated, samplesCreated, dataSetsCreated, dataSetsUpdated);
samplesUpdated, samplesCreated, materialsCreated, dataSetsCreated, dataSetsUpdated);
}
private List<Space> createSpaces(Session session, AtomicEntityOperationDetails operationDetails)
......@@ -1125,6 +1148,24 @@ public class ETLService extends AbstractCommonServer<IETLService> implements IET
return GroupTranslator.translate(spacePEsCreated);
}
private List<Material> createMaterials(Session session,
AtomicEntityOperationDetails operationDetails)
{
MaterialHelper materialHelper =
new MaterialHelper(session, businessObjectFactory, getDAOFactory(),
getPropertiesBatchManager());
Map<String, List<NewMaterial>> materialRegs = operationDetails.getMaterialRegistrations();
List<Material> registeredMaterials = new ArrayList<Material>();
for (Entry<String, List<NewMaterial>> newMaterialsEntry : materialRegs.entrySet())
{
String materialType = newMaterialsEntry.getKey();
List<NewMaterial> newMaterials = newMaterialsEntry.getValue();
List<Material> materials = materialHelper.registerMaterials(materialType, newMaterials);
registeredMaterials.addAll(materials);
}
return registeredMaterials;
}
private SpacePE registerSpaceInternal(Session session, NewSpace newSpace,
String registratorUserIdOrNull)
{
......
......@@ -36,6 +36,8 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExperimentType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListSampleCriteria;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSamplesWithTypes;
......@@ -487,4 +489,10 @@ public class ETLServiceLogger extends AbstractServerLogger implements IETLServic
logAccess(sessionToken, "searchForDataSets", "%s", searchCriteria);
return null;
}
public Material tryGetMaterial(String sessionToken, MaterialIdentifier materialIdentifier)
{
logAccess(sessionToken, "tryGetMaterial", "%s", materialIdentifier);
return null;
}
}
/*
* Copyright 2011 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.generic.server;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.log4j.Logger;
import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.common.logging.LogCategory;
import ch.systemsx.cisd.common.logging.LogFactory;
import ch.systemsx.cisd.openbis.generic.server.batch.BatchOperationExecutor;
import ch.systemsx.cisd.openbis.generic.server.batch.IBatchOperation;
import ch.systemsx.cisd.openbis.generic.server.business.IPropertiesBatchManager;
import ch.systemsx.cisd.openbis.generic.server.business.bo.IAbstractBussinessObjectFactory;
import ch.systemsx.cisd.openbis.generic.server.business.bo.IMaterialTable;
import ch.systemsx.cisd.openbis.generic.server.business.bo.MaterialUpdateDTO;
import ch.systemsx.cisd.openbis.generic.server.business.bo.materiallister.IMaterialLister;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory;
import ch.systemsx.cisd.openbis.generic.shared.basic.CodeConverter;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListMaterialCriteria;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewMaterial;
import ch.systemsx.cisd.openbis.generic.shared.dto.EntityTypePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialTypePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.Session;
import ch.systemsx.cisd.openbis.generic.shared.dto.properties.EntityKind;
import ch.systemsx.cisd.openbis.generic.shared.translator.MaterialTranslator;
import ch.systemsx.cisd.openbis.generic.shared.translator.MaterialTypeTranslator;
import ch.systemsx.cisd.openbis.generic.shared.util.ServerUtils;
/**
* @author Kaloyan Enimanev
*/
public class MaterialHelper
{
private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION,
MaterialHelper.class);
private final Session session;
private final IAbstractBussinessObjectFactory businessObjectFactory;
private final IDAOFactory daoFactory;
private final IPropertiesBatchManager propertiesBatchManager;
public MaterialHelper(Session session,
IAbstractBussinessObjectFactory businessObjectFactory, IDAOFactory daoFactory,
IPropertiesBatchManager propertiesBatchManager)
{
this.session = session;
this.businessObjectFactory = businessObjectFactory;
this.daoFactory = daoFactory;
this.propertiesBatchManager = propertiesBatchManager;
}
public List<Material> registerMaterials(String materialTypeCode,
final List<NewMaterial> newMaterials)
{
assert materialTypeCode != null : "Unspecified material type.";
assert newMaterials != null : "Unspecified new materials.";
// Does nothing if material list is empty.
if (newMaterials.size() == 0)
{
return Collections.emptyList();
}
ServerUtils.prevalidate(newMaterials, "material");
final MaterialTypePE materialTypePE = findMaterialType(materialTypeCode);
final List<MaterialPE> registeredMaterials = new ArrayList<MaterialPE>();
propertiesBatchManager.manageProperties(materialTypePE, newMaterials,
session.tryGetPerson());
IBatchOperation<NewMaterial> strategy = new IBatchOperation<NewMaterial>()
{
public void execute(List<NewMaterial> entities)
{
final IMaterialTable materialTable =
businessObjectFactory.createMaterialTable(session);
materialTable.add(entities, materialTypePE);
materialTable.save();
registeredMaterials.addAll(materialTable.getMaterials());
}
public List<NewMaterial> getAllEntities()
{
return newMaterials;
}
public String getEntityName()
{
return "material";
}
public String getOperationName()
{
return "register";
}
};
BatchOperationExecutor.executeInBatches(strategy);
return MaterialTranslator.translate(registeredMaterials);
}
public int updateMaterials(String materialTypeCode,
final List<NewMaterial> newMaterials, final boolean ignoreUnregisteredMaterials)
throws UserFailureException
{
assert materialTypeCode != null : "Unspecified material type.";
assert newMaterials != null : "Unspecified new materials.";
// Does nothing if material list is empty.
if (newMaterials.size() == 0)
{
return 0;
}
ServerUtils.prevalidate(newMaterials, "material");
final AtomicInteger count = new AtomicInteger(0);
final Map<String/* code */, Material> existingMaterials = listMaterials(materialTypeCode);
final MaterialTypePE materialTypePE = findMaterialType(materialTypeCode);
propertiesBatchManager.manageProperties(materialTypePE, newMaterials,
session.tryGetPerson());
IBatchOperation<NewMaterial> strategy = new IBatchOperation<NewMaterial>()
{
public void execute(List<NewMaterial> entities)
{
List<MaterialUpdateDTO> materialUpdates = new ArrayList<MaterialUpdateDTO>();
for (NewMaterial material : entities)
{
Material existingMaterial =
existingMaterials.get(CodeConverter.tryToDatabase(material
.getCode()));
if (existingMaterial != null)
{
materialUpdates.add(createMaterialUpdate(existingMaterial, material));
count.incrementAndGet();
} else if (ignoreUnregisteredMaterials == false)
{
throw new UserFailureException("Can not update unregistered material '"
+ material.getCode()
+ "'. Please use checkbox for ignoring unregistered materials.");
}
}
updateMaterials(materialUpdates);
}
public List<NewMaterial> getAllEntities()
{
return newMaterials;
}
public String getEntityName()
{
return "material";
}
public String getOperationName()
{
return "update";
}
};
BatchOperationExecutor.executeInBatches(strategy);
return count.get();
}
public void registerOrUpdateMaterials(String materialTypeCode, List<NewMaterial> materials)
{
Map<String/* code */, Material> existingMaterials = listMaterials(materialTypeCode);
List<NewMaterial> materialsToRegister = new ArrayList<NewMaterial>();
List<MaterialUpdateDTO> materialUpdates = new ArrayList<MaterialUpdateDTO>();
for (NewMaterial material : materials)
{
Material existingMaterial =
existingMaterials.get(CodeConverter.tryToDatabase(material.getCode()));
if (existingMaterial != null)
{
materialUpdates.add(createMaterialUpdate(existingMaterial, material));
} else
{
materialsToRegister.add(material);
}
}
registerMaterials(materialTypeCode, materialsToRegister);
updateMaterials(materialUpdates);
operationLog.info(String.format("Number of newly registered materials: %d, "
+ "number of existing materials which have been updated: %d",
materialsToRegister.size(), materialUpdates.size()));
}
private static MaterialUpdateDTO createMaterialUpdate(Material existingMaterial,
NewMaterial material)
{
return new MaterialUpdateDTO(new TechId(existingMaterial.getId()), Arrays.asList(material
.getProperties()), existingMaterial.getModificationDate());
}
private void updateMaterials(List<MaterialUpdateDTO> updates)
{
if (updates.isEmpty())
{
return;
}
IMaterialTable materialTable = businessObjectFactory.createMaterialTable(session);
materialTable.update(updates);
materialTable.save();
}
private Map<String/* code */, Material> listMaterials(String materialTypeCode)
{
EntityTypePE entityTypePE =
daoFactory.getEntityTypeDAO(EntityKind.MATERIAL).tryToFindEntityTypeByCode(
materialTypeCode);
MaterialType materialType = MaterialTypeTranslator.translateSimple(entityTypePE);
IMaterialLister materialLister = businessObjectFactory.createMaterialLister(session);
ListMaterialCriteria listByTypeCriteria = new ListMaterialCriteria(materialType);
List<Material> materials = materialLister.list(listByTypeCriteria, false);
return asCodeToMaterialMap(materials);
}
private static Map<String, Material> asCodeToMaterialMap(List<Material> materials)
{
Map<String, Material> map = new HashMap<String, Material>();
for (Material material : materials)
{
map.put(material.getCode(), material);
}
return map;
}
private MaterialTypePE findMaterialType(String materialTypeCode)
{
final MaterialTypePE materialTypePE =
(MaterialTypePE) daoFactory.getEntityTypeDAO(EntityKind.MATERIAL)
.tryToFindEntityTypeByCode(materialTypeCode);
if (materialTypePE == null)
{
throw UserFailureException.fromTemplate("Material type with code '%s' does not exist.",
materialTypeCode);
}
return materialTypePE;
}
}
/*
* Copyright 2011 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.generic.server.business.bo;
import ch.systemsx.cisd.openbis.generic.server.business.bo.materiallister.IMaterialLister;
import ch.systemsx.cisd.openbis.generic.shared.dto.Session;
/**
* An abstract bussiness object factory.
*
* @author Kaloyan Enimanev
*/
public interface IAbstractBussinessObjectFactory
{
public IMaterialTable createMaterialTable(Session session);
public IMaterialBO createMaterialBO(Session session);
public IMaterialLister createMaterialLister(Session session);
}
......@@ -17,7 +17,6 @@
package ch.systemsx.cisd.openbis.generic.server.business.bo;
import ch.systemsx.cisd.openbis.generic.server.business.bo.datasetlister.IDatasetLister;
import ch.systemsx.cisd.openbis.generic.server.business.bo.materiallister.IMaterialLister;
import ch.systemsx.cisd.openbis.generic.server.business.bo.samplelister.ISampleLister;
import ch.systemsx.cisd.openbis.generic.shared.dto.Session;
import ch.systemsx.cisd.openbis.generic.shared.dto.properties.EntityKind;
......@@ -28,7 +27,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.properties.EntityKind;
*
* @author Tomasz Pylak
*/
public interface ICommonBusinessObjectFactory
public interface ICommonBusinessObjectFactory extends IAbstractBussinessObjectFactory
{
public IAttachmentBO createAttachmentBO(final Session session);
......@@ -63,12 +62,8 @@ public interface ICommonBusinessObjectFactory
public IProjectBO createProjectBO(final Session session);
public IMaterialTable createMaterialTable(Session session);
public IEntityTypeBO createEntityTypeBO(Session session);
public IMaterialBO createMaterialBO(Session session);
public IAuthorizationGroupBO createAuthorizationGroupBO(Session session);
public IGridCustomFilterOrColumnBO createGridCustomFilterBO(final Session session);
......@@ -78,10 +73,8 @@ public interface ICommonBusinessObjectFactory
public IInvalidationBO createInvalidationBO(final Session session);
// Fast listing operations
public ISampleLister createSampleLister(Session session);
public IDatasetLister createDatasetLister(Session session);
public IMaterialLister createMaterialLister(Session session);
}
......@@ -57,6 +57,8 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExperimentType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListSampleCriteria;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSamplesWithTypes;
......@@ -120,20 +122,11 @@ public interface IETLLIMSService extends IServer, ISessionProvider
throws UserFailureException;
/**
* Gets a sample with the specified identifier. Sample is enriched with properties and the
* experiment with properties.
*
* @param sessionToken the user authentication token. Must not be <code>null</code>.
* @param sampleIdentifier an identifier which uniquely identifies the sample.
* @return <code>null</code> if no sample attached to an experiment could be found for given
* <var>sampleIdentifier</var>.
* For given {@link MaterialIdentifier} returns the corresponding {@link Material}.
*/
@Transactional(readOnly = true)
@RolesAllowed(RoleWithHierarchy.SPACE_ETL_SERVER)
public Sample tryGetSampleWithExperiment(
final String sessionToken,
@AuthorizationGuard(guardClass = ExistingSampleOwnerIdentifierPredicate.class) final SampleIdentifier sampleIdentifier)
throws UserFailureException;
public Material tryGetMaterial(String sessionToken, MaterialIdentifier materialIdentifier);
/**
* Tries to get the identifier of sample with specified permanent ID.
......@@ -154,6 +147,22 @@ public interface IETLLIMSService extends IServer, ISessionProvider
public ExperimentType getExperimentType(String sessionToken, String experimentTypeCode)
throws UserFailureException;
/**
* Gets a sample with the specified identifier. Sample is enriched with properties and the
* experiment with properties.
*
* @param sessionToken the user authentication token. Must not be <code>null</code>.
* @param sampleIdentifier an identifier which uniquely identifies the sample.
* @return <code>null</code> if no sample attached to an experiment could be found for given
* <var>sampleIdentifier</var>.
*/
@Transactional(readOnly = true)
@RolesAllowed(RoleWithHierarchy.SPACE_ETL_SERVER)
public Sample tryGetSampleWithExperiment(
final String sessionToken,
@AuthorizationGuard(guardClass = ExistingSampleOwnerIdentifierPredicate.class) final SampleIdentifier sampleIdentifier)
throws UserFailureException;
/**
* Returns a list of terms belonging to given vocabulary.
*/
......
......@@ -19,11 +19,14 @@ package ch.systemsx.cisd.openbis.generic.shared.dto;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewMaterial;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewProject;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSpace;
......@@ -55,6 +58,8 @@ public class AtomicEntityOperationDetails implements Serializable
private final List<NewSample> sampleRegistrations;
private final Map<String /* material type */, List<NewMaterial>> materialRegistrations;
private final List<? extends NewExternalData> dataSetRegistrations;
private final List<DataSetUpdatesDTO> dataSetUpdates;
......@@ -62,6 +67,7 @@ public class AtomicEntityOperationDetails implements Serializable
public AtomicEntityOperationDetails(String userIdOrNull, List<NewSpace> spaceRegistrations,
List<NewProject> projectRegistrations, List<NewExperiment> experimentRegistrations,
List<SampleUpdatesDTO> sampleUpdates, List<NewSample> sampleRegistrations,
Map<String, List<NewMaterial>> materialRegistrations,
List<? extends NewExternalData> dataSetRegistrations,
List<DataSetUpdatesDTO> dataSetUpdates)
{
......@@ -72,6 +78,7 @@ public class AtomicEntityOperationDetails implements Serializable
this.experimentRegistrations = new ArrayList<NewExperiment>(experimentRegistrations);
this.sampleUpdates = new ArrayList<SampleUpdatesDTO>(sampleUpdates);
this.sampleRegistrations = new ArrayList<NewSample>(sampleRegistrations);
this.materialRegistrations = new TreeMap<String, List<NewMaterial>>(materialRegistrations);
this.dataSetRegistrations = new ArrayList<NewExternalData>(dataSetRegistrations);
this.dataSetUpdates = new ArrayList<DataSetUpdatesDTO>(dataSetUpdates);
}
......@@ -121,6 +128,11 @@ public class AtomicEntityOperationDetails implements Serializable
return projectRegistrations;
}
public Map<String, List<NewMaterial>> getMaterialRegistrations()
{
return materialRegistrations;
}
@Override
public String toString()
{
......@@ -132,8 +144,10 @@ public class AtomicEntityOperationDetails implements Serializable
sb.append("experimentRegistrations", experimentRegistrations);
sb.append("sampleUpdates", sampleUpdates);
sb.append("sampleRegistrations", sampleRegistrations);
sb.append("materialRegistrations", materialRegistrations);
sb.append("dataSetRegistrations", dataSetRegistrations);
sb.append("dataSetUpdates", dataSetUpdates);
return sb.toString();
}
}
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