diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/EntityPropertiesConverter.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/EntityPropertiesConverter.java index 36c8c90ff073f093429b19b2c8f99f0ec7ea3e18..950d60baf9937e4dd2964d0736fab9913031d64c 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/EntityPropertiesConverter.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/EntityPropertiesConverter.java @@ -17,6 +17,7 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -29,7 +30,6 @@ import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; import ch.systemsx.cisd.openbis.generic.server.util.KeyExtractorFactory; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityProperty; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityTypePropertyType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.EntityPropertyPE; @@ -183,11 +183,10 @@ public final class EntityPropertiesConverter implements IEntityPropertiesConvert return entityTypePropertyType; } - private final <T extends EntityPropertyPE, ET extends EntityType, ETPT extends EntityTypePropertyType<ET>> T tryConvertProperty( - final PersonPE registrator, final EntityTypePE entityTypePE, - final EntityProperty<ET, ETPT> property) + private final <T extends EntityPropertyPE> T tryConvertProperty(final PersonPE registrator, + final EntityTypePE entityTypePE, final EntityProperty<?, ?> property) { - final ETPT entityTypePropertyType = property.getEntityTypePropertyType(); + EntityTypePropertyType<?> entityTypePropertyType = property.getEntityTypePropertyType(); final String propertyCode = entityTypePropertyType.getPropertyType().getCode(); final PropertyTypePE propertyType = getPropertyType(propertyCode); final String valueOrNull = property.getValue(); @@ -225,8 +224,16 @@ public final class EntityPropertiesConverter implements IEntityPropertiesConvert // IEntityPropertiesConverter // - public final <T extends EntityPropertyPE, ET extends EntityType, ETPT extends EntityTypePropertyType<ET>> List<T> convertProperties( - final EntityProperty<ET, ETPT>[] properties, final String entityTypeCode, + private final <T extends EntityPropertyPE> List<T> convertProperties( + final List<? extends EntityProperty<?, ?>> properties, final String entityTypeCode, + final PersonPE registrator) + { + EntityProperty<?, ?>[] propsArray = properties.toArray(new EntityProperty<?, ?>[0]); + return convertProperties(propsArray, entityTypeCode, registrator); + } + + public final <T extends EntityPropertyPE> List<T> convertProperties( + final EntityProperty<?, ?>[] properties, final String entityTypeCode, final PersonPE registrator) { assert entityTypeCode != null : "Unspecified entity type code."; @@ -238,7 +245,7 @@ public final class EntityPropertiesConverter implements IEntityPropertiesConvert } final EntityTypePE entityTypePE = getEntityType(entityTypeCode); final List<T> list = new ArrayList<T>(); - for (final EntityProperty<ET, ETPT> property : properties) + for (final EntityProperty<?, ?> property : properties) { final T convertedPropertyOrNull = tryConvertProperty(registrator, entityTypePE, property); @@ -250,9 +257,8 @@ public final class EntityPropertiesConverter implements IEntityPropertiesConvert return list; } - public final <T extends EntityPropertyPE, ET extends EntityType, ETPT extends EntityTypePropertyType<ET>> T createProperty( - PropertyTypePE propertyType, EntityTypePropertyTypePE entityTypPropertyType, - final PersonPE registrator, String value) + public final <T extends EntityPropertyPE> T createProperty(PropertyTypePE propertyType, + EntityTypePropertyTypePE entityTypPropertyType, final PersonPE registrator, String value) { if (entityTypPropertyType.isMandatory() && value == null) { @@ -268,41 +274,40 @@ public final class EntityPropertiesConverter implements IEntityPropertiesConvert return null; } - public <T extends EntityPropertyPE, ET extends EntityType, ETPT extends EntityTypePropertyType<ET>, P extends EntityProperty<ET, ETPT>> Set<T> updateProperties( - List<T> oldProperties, String experiemntTypeCode, P[] newProperties, + public <T extends EntityPropertyPE, P extends EntityProperty<?, ?>> Set<T> updateProperties( + Collection<T> oldProperties, EntityTypePE entityType, List<P> newProperties, PersonPE registrator) { final List<T> convertedProperties = - convertProperties(newProperties, experiemntTypeCode, registrator); + convertProperties(newProperties, entityType.getCode(), registrator); final Set<T> set = new HashSet<T>(); - for (T p : convertedProperties) + for (T newProperty : convertedProperties) { - int index = find(oldProperties, p); - if (index > -1) + T existingProperty = tryFind(oldProperties, newProperty); + if (existingProperty != null) { - final T existingProperty = oldProperties.get(index); - existingProperty.setUntypedValue(p.getValue(), p.getVocabularyTerm(), p - .getMaterialValue()); + existingProperty.setUntypedValue(newProperty.getValue(), newProperty + .getVocabularyTerm(), newProperty.getMaterialValue()); set.add(existingProperty); } else { - set.add(p); + set.add(newProperty); } } return set; } - static private <T extends EntityPropertyPE> int find(List<T> oldProperties, T p) + private static <T extends EntityPropertyPE> T tryFind(Collection<T> oldProperties, T p) { - for (int i = 0; i < oldProperties.size(); i++) + for (T oldProperty : oldProperties) { - if (oldProperties.get(i).getEntityTypePropertyType().getPropertyType().equals( + if (oldProperty.getEntityTypePropertyType().getPropertyType().equals( p.getEntityTypePropertyType().getPropertyType())) { - return i; + return oldProperty; } } - return -1; + return null; } // diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ExperimentBO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ExperimentBO.java index 9d7c58a81581ada03a916465fe91b07aca76c164..09ccee395a0ada6c6077848216af193ca9f8a843 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ExperimentBO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ExperimentBO.java @@ -323,14 +323,11 @@ public final class ExperimentBO extends AbstractBusinessObject implements IExper private void updateProperties(List<ExperimentProperty> properties) { - final ArrayList<ExperimentPropertyPE> existingProperties = - new ArrayList<ExperimentPropertyPE>(experiment.getProperties()); - final String type = experiment.getExperimentType().getCode(); - final ExperimentProperty[] newProperties = - properties.toArray(ExperimentProperty.EMPTY_ARRAY); + final Set<ExperimentPropertyPE> existingProperties = experiment.getProperties(); + final ExperimentTypePE type = experiment.getExperimentType(); final PersonPE registrator = findRegistrator(); experiment.setProperties(propertiesConverter.updateProperties(existingProperties, type, - newProperties, registrator)); + properties, registrator)); } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IEntityPropertiesConverter.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IEntityPropertiesConverter.java index c1d4056a971d8b0c812d2a1b14bb183f80f62bcf..17df4aa9ddebd7144f22426d19deceacbcbfd5e7 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IEntityPropertiesConverter.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IEntityPropertiesConverter.java @@ -16,13 +16,13 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo; +import java.util.Collection; import java.util.List; import java.util.Set; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityProperty; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityType; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityTypePropertyType; import ch.systemsx.cisd.openbis.generic.shared.dto.EntityPropertyPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.EntityTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.EntityTypePropertyTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; import ch.systemsx.cisd.openbis.generic.shared.dto.PropertyTypePE; @@ -45,19 +45,19 @@ public interface IEntityPropertiesConverter * * @param registrator Will appear in the objects of the output. */ - public <T extends EntityPropertyPE, ET extends EntityType, ETPT extends EntityTypePropertyType<ET>> List<T> convertProperties( - final EntityProperty<ET, ETPT>[] properties, final String entityTypeCode, + public <T extends EntityPropertyPE> List<T> convertProperties( + final EntityProperty<?, ?>[] properties, final String entityTypeCode, final PersonPE registrator); /** * Creates {@link EntityPropertyPE}. */ - public <T extends EntityPropertyPE, ET extends EntityType, ETPT extends EntityTypePropertyType<ET>> T createProperty( - PropertyTypePE propertyType, EntityTypePropertyTypePE entityTypePropertyType, - final PersonPE registrator, String value); + public <T extends EntityPropertyPE> T createProperty(PropertyTypePE propertyType, + EntityTypePropertyTypePE entityTypePropertyType, final PersonPE registrator, + String value); /** Updates Set<T> of properties. */ - public <T extends EntityPropertyPE, ET extends EntityType, ETPT extends EntityTypePropertyType<ET>, P extends EntityProperty<ET, ETPT>> Set<T> updateProperties( - List<T> oldProperties, String experiemntTypeCode, P[] newProperties, + public <T extends EntityPropertyPE, P extends EntityProperty<?, ?>> Set<T> updateProperties( + Collection<T> oldProperties, EntityTypePE entityType, List<P> newProperties, PersonPE registrator); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/MaterialBO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/MaterialBO.java index 13af410ca16fb3cfb6faaa423c4a4537b6ad9514..1b9c437f844d1177a16e9b6d813428a16ecf1c69 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/MaterialBO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/MaterialBO.java @@ -19,6 +19,7 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Set; import org.springframework.dao.DataAccessException; @@ -27,6 +28,7 @@ import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialIdentifier; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialProperty; +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.MaterialPropertyPE; import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; @@ -113,13 +115,11 @@ public final class MaterialBO extends AbstractBusinessObject implements IMateria private void updateProperties(List<MaterialProperty> properties) { - final ArrayList<MaterialPropertyPE> existingProperties = - new ArrayList<MaterialPropertyPE>(material.getProperties()); - final String type = material.getMaterialType().getCode(); - final MaterialProperty[] newProperties = properties.toArray(MaterialProperty.EMPTY_ARRAY); + final Set<MaterialPropertyPE> existingProperties = material.getProperties(); + final EntityTypePE type = material.getMaterialType(); final PersonPE registrator = findRegistrator(); material.setProperties(propertiesConverter.updateProperties(existingProperties, type, - newProperties, registrator)); + properties, registrator)); } public MaterialPE getMaterial() 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 99bee89142260ef59f87c4daba32f0e780d2afed..024a621accbe9dff00b3b742275e84f31e5df573 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 @@ -16,9 +16,9 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo; -import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Set; import org.springframework.dao.DataAccessException; @@ -27,6 +27,7 @@ import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IExternalDataDAO; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleProperty; +import ch.systemsx.cisd.openbis.generic.shared.dto.EntityTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE; import ch.systemsx.cisd.openbis.generic.shared.dto.ExternalDataPE; import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; @@ -323,12 +324,10 @@ public final class SampleBO extends AbstractSampleBusinessObject implements ISam private void updateProperties(List<SampleProperty> properties) { - final ArrayList<SamplePropertyPE> existingProperties = - new ArrayList<SamplePropertyPE>(sample.getProperties()); - final String type = sample.getSampleType().getCode(); - final SampleProperty[] newProperties = properties.toArray(SampleProperty.EMPTY_ARRAY); + final Set<SamplePropertyPE> existingProperties = sample.getProperties(); + final EntityTypePE type = sample.getSampleType(); final PersonPE registrator = findRegistrator(); sample.setProperties(entityPropertiesConverter.updateProperties(existingProperties, type, - newProperties, registrator)); + properties, registrator)); } }