diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/DynamicProperiesPlaceholderCreator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/DynamicProperiesPlaceholderCreator.java deleted file mode 100644 index 45f217dbd7ce23973455f28bb2540116a8df73a4..0000000000000000000000000000000000000000 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/DynamicProperiesPlaceholderCreator.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2010 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 java.util.List; -import java.util.Set; - -import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityProperty; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; - -class DynamicProperiesPlaceholderCreator implements IDynamicProperiesPlaceholderCreator -{ - /** - * Adds "dynamic properties" to "properties to update" and appropriate "placeholder" values - * to "new properties". - */ - public void addDynamicPropertiesPlaceholders(List<IEntityProperty> newProperties, - Set<String> propertiesToUpdate, Set<String> dynamicProperties) - { - propertiesToUpdate.addAll(dynamicProperties); - for (String dp : dynamicProperties) - { - final IEntityProperty entityProperty = new EntityProperty(); - entityProperty.setValue(BasicConstant.PLACEHOLDER_PROPERTY_VALUE); - PropertyType propertyType = new PropertyType(); - propertyType.setCode(dp); - entityProperty.setPropertyType(propertyType); - newProperties.add(entityProperty); - } - } -} \ No newline at end of file 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 289e1f0d0cb0b76b016c07f51e14be9c2998071a..1c2297ccec7fcafdc2ac15d22a4be1b61e1b81b6 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 @@ -21,6 +21,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -74,6 +75,9 @@ public final class EntityPropertiesConverter implements IEntityPropertiesConvert private Map<String, Set<String>> dynamicPropertiesByEntityTypeCode = new HashMap<String, Set<String>>(); + private Map<String, Set<String>> managedPropertiesByEntityTypeCode = + new HashMap<String, Set<String>>(); + private final TableMap<String, PropertyTypePE> propertyTypesByCode = new TableMap<String, PropertyTypePE>( KeyExtractorFactory.getPropertyTypeByCodeKeyExtractor()); @@ -86,19 +90,19 @@ public final class EntityPropertiesConverter implements IEntityPropertiesConvert private final IDynamicPropertiesUpdateChecker dynamicPropertiesUpdateChecker; - private final IDynamicProperiesPlaceholderCreator placeholderCreator; + private final IPropertyPlaceholderCreator placeholderCreator; public EntityPropertiesConverter(final EntityKind entityKind, final IDAOFactory daoFactory) { this(entityKind, daoFactory, new PropertyValidator(), new DynamicPropertiesUpdateChecker(), - new DynamicProperiesPlaceholderCreator()); + new PlaceholderPropertyCreator()); } @Private EntityPropertiesConverter(final EntityKind entityKind, final IDAOFactory daoFactory, final IPropertyValueValidator propertyValueValidator, IDynamicPropertiesUpdateChecker dynamicPropertiesUpdateChecker, - IDynamicProperiesPlaceholderCreator placeholderCreator) + IPropertyPlaceholderCreator placeholderCreator) { assert entityKind != null : "Unspecified entity kind."; assert daoFactory != null : "Unspecified DAO factory."; @@ -134,6 +138,27 @@ public final class EntityPropertiesConverter implements IEntityPropertiesConvert return dynamicPropertiesByEntityTypeCode.get(code); } + private final Set<String> getManagedProperties(final EntityTypePE entityTypePE) + { + String code = entityTypePE.getCode(); + if (managedPropertiesByEntityTypeCode.containsKey(code) == false) + { + HashSet<String> set = new HashSet<String>(); + List<EntityTypePropertyTypePE> list = + daoFactory.getEntityPropertyTypeDAO(entityKind).listEntityPropertyTypes( + entityTypePE); + for (EntityTypePropertyTypePE etpt : list) + { + if (etpt.isManaged()) + { + set.add(etpt.getPropertyType().getCode()); + } + } + managedPropertiesByEntityTypeCode.put(code, set); + } + return managedPropertiesByEntityTypeCode.get(code); + } + private final EntityTypePE getEntityType(final String entityTypeCode) { if (entityTypesByCode == null) @@ -227,32 +252,36 @@ public final class EntityPropertiesConverter implements IEntityPropertiesConvert // IEntityPropertiesConverter // - private final <T extends EntityPropertyPE> List<T> convertProperties( - final List<? extends IEntityProperty> properties, final String entityTypeCode, + public final <T extends EntityPropertyPE> List<T> convertProperties( + final IEntityProperty[] properties, final String entityTypeCode, final PersonPE registrator) { - IEntityProperty[] propsArray = properties.toArray(new IEntityProperty[0]); - return convertProperties(propsArray, entityTypeCode, registrator); + return convertProperties(properties, entityTypeCode, registrator, true); } - public final <T extends EntityPropertyPE> List<T> convertProperties( + private final <T extends EntityPropertyPE> List<T> convertProperties( final IEntityProperty[] properties, final String entityTypeCode, - final PersonPE registrator) + final PersonPE registrator, final boolean createManagedPropertiesPlaceholders) { assert entityTypeCode != null : "Unspecified entity type code."; assert registrator != null : "Unspecified registrator"; assert properties != null : "Unspecified entity properties"; final EntityTypePE entityTypePE = getEntityType(entityTypeCode); Set<String> dynamicProperties = getDynamicProperties(entityTypePE); + Set<String> managedProperties = getManagedProperties(entityTypePE); + Set<IEntityProperty> definedProperties = + new LinkedHashSet<IEntityProperty>(Arrays.asList(properties)); Set<String> propertiesToUpdate = extractPropertiesToUpdate(properties); dynamicPropertiesUpdateChecker.checkDynamicPropertiesNotManuallyUpdated(propertiesToUpdate, dynamicProperties); - List<IEntityProperty> newProperties = - new ArrayList<IEntityProperty>(Arrays.asList(properties)); - placeholderCreator.addDynamicPropertiesPlaceholders(newProperties, propertiesToUpdate, - dynamicProperties); + placeholderCreator.addDynamicPropertiesPlaceholders(definedProperties, dynamicProperties); + if (createManagedPropertiesPlaceholders) + { + placeholderCreator.addManagedPropertiesPlaceholders(definedProperties, + managedProperties); + } final List<T> list = new ArrayList<T>(); - for (final IEntityProperty property : newProperties) + for (final IEntityProperty property : definedProperties) { final T convertedPropertyOrNull = tryConvertProperty(registrator, entityTypePE, property); @@ -379,7 +408,7 @@ public final class EntityPropertiesConverter implements IEntityPropertiesConvert EntityTypePE entityType, List<IEntityProperty> newProperties, PersonPE registrator) { final List<T> convertedProperties = - convertProperties(newProperties, entityType.getCode(), registrator); + convertPropertiesForUpdate(newProperties, entityType.getCode(), registrator); final Set<T> set = new HashSet<T>(); for (T newProperty : convertedProperties) { @@ -397,6 +426,15 @@ public final class EntityPropertiesConverter implements IEntityPropertiesConvert return set; } + private final <T extends EntityPropertyPE> List<T> convertPropertiesForUpdate( + final List<? extends IEntityProperty> properties, final String entityTypeCode, + final PersonPE registrator) + { + IEntityProperty[] propsArray = properties.toArray(new IEntityProperty[0]); + return convertProperties(propsArray, entityTypeCode, registrator, false); + } + + // TODO 2010-01-12, Piotr Buczek: refactor - propertiesToUpdate are not used at all public <T extends EntityPropertyPE> Set<T> updateProperties(Collection<T> oldProperties, EntityTypePE entityType, List<IEntityProperty> newProperties, PersonPE registrator, Set<String> propertiesToUpdate) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/EntityTypePropertyTypeBO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/EntityTypePropertyTypeBO.java index 4ed70285b6e7942edcdea50e5b86143bc08d68f1..4ed2699a2dccb8c65f2ed9521fbec303d14493c6 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/EntityTypePropertyTypeBO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/EntityTypePropertyTypeBO.java @@ -119,7 +119,12 @@ public class EntityTypePropertyTypeBO extends AbstractBusinessObject implements { List<Long> entityIds = getAllEntityIds(entityType); addPropertyWithDefaultValue(entityType, propertyType, - BasicConstant.PLACEHOLDER_PROPERTY_VALUE, entityIds, null); + BasicConstant.DYNAMIC_PROPERTY_PLACEHOLDER_VALUE, entityIds, null); + } else if (newAssignment.isManaged()) + { + List<Long> entityIds = getAllEntityIds(entityType); + addPropertyWithDefaultValue(entityType, propertyType, + BasicConstant.MANAGED_PROPERTY_PLACEHOLDER_VALUE, entityIds, null); } else if (newAssignment.isMandatory()) // fill default property values { diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IDynamicProperiesPlaceholderCreator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IPropertyPlaceholderCreator.java similarity index 72% rename from openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IDynamicProperiesPlaceholderCreator.java rename to openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IPropertyPlaceholderCreator.java index 47b5a0719fe72706a83a81e01143fac7dd0d45c6..7d30a7dab91caf49daa5a91b0b970a79093898c0 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IDynamicProperiesPlaceholderCreator.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IPropertyPlaceholderCreator.java @@ -16,13 +16,15 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo; -import java.util.List; import java.util.Set; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty; -interface IDynamicProperiesPlaceholderCreator +interface IPropertyPlaceholderCreator { - void addDynamicPropertiesPlaceholders(List<IEntityProperty> newProperties, - Set<String> propertiesToUpdate, Set<String> dynamicProperties); + void addDynamicPropertiesPlaceholders(Set<IEntityProperty> definedProperties, + Set<String> dynamicProperties); + + void addManagedPropertiesPlaceholders(Set<IEntityProperty> definedProperties, + Set<String> managedProperties); } \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/PlaceholderPropertyCreator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/PlaceholderPropertyCreator.java new file mode 100644 index 0000000000000000000000000000000000000000..f5d56d2fb0eb928dc9de123ef1e88a52880a399d --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/PlaceholderPropertyCreator.java @@ -0,0 +1,71 @@ +/* + * Copyright 2010 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 java.util.Set; + +import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityProperty; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; + +class PlaceholderPropertyCreator implements IPropertyPlaceholderCreator +{ + /** + * Adds placeholders for <var>dynamicProperties</var> to <var>definedProperties</var> if they + * don't exist yet. + */ + public void addDynamicPropertiesPlaceholders(Set<IEntityProperty> definedProperties, + Set<String> dynamicProperties) + { + addPlaceholders(definedProperties, dynamicProperties, + BasicConstant.DYNAMIC_PROPERTY_PLACEHOLDER_VALUE); + } + + /** + * Adds placeholders for <var>managedProperties</var> to <var>definedProperties</var> if they + * don't exist yet. + */ + public void addManagedPropertiesPlaceholders(Set<IEntityProperty> definedProperties, + Set<String> managedProperties) + { + addPlaceholders(definedProperties, managedProperties, + BasicConstant.MANAGED_PROPERTY_PLACEHOLDER_VALUE); + } + + /** + * Adds <var>placeholderProperties</var> with specified <var>placeholderValue</var>to + * <var>definedProperties</var> if they don't exist yet. + */ + private void addPlaceholders(Set<IEntityProperty> definedProperties, + Set<String> placeholderProperties, String placeholderValue) + { + for (String p : placeholderProperties) + { + if (definedProperties.contains(p) == false) + { + final IEntityProperty entityProperty = new EntityProperty(); + entityProperty.setValue(placeholderValue); + PropertyType propertyType = new PropertyType(); + propertyType.setCode(p); + entityProperty.setPropertyType(propertyType); + definedProperties.add(entityProperty); + } + } + } + +} \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/BasicConstant.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/BasicConstant.java index ac26dc4a7bf15576330e04d48b049f4d0c0164e0..cbc8e53621827c4171b2effcde86f527b0a82b71 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/BasicConstant.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/BasicConstant.java @@ -43,11 +43,14 @@ public class BasicConstant /** Prefix of property value that contains error message. */ public static final String ERROR_PROPERTY_PREFIX = "" + UNI_REPLACEMENT_CHAR; - // placeholder - /** Prefix of property value that contains error message. */ - public static final String PLACEHOLDER_PROPERTY_VALUE = ERROR_PROPERTY_PREFIX + /** Value of dynamic property before it is evaluated. */ + public static final String DYNAMIC_PROPERTY_PLACEHOLDER_VALUE = ERROR_PROPERTY_PREFIX + "(pending evaluation)"; + /** Value of managed property before it is defined by user. */ + public static final String MANAGED_PROPERTY_PLACEHOLDER_VALUE = ERROR_PROPERTY_PREFIX + + "(undefined)"; + /** Template part of Vocabulary URL that that is replaced with vocabulary term code. */ public static final String VOCABULARY_URL_TEMPLATE_TERM_PART = "$term$"; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/EntityTypePropertyTypePE.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/EntityTypePropertyTypePE.java index 90beedd059c167e8721d019998b8b39026ae918e..e768984d66feee2576cbc6d50f1bbc57c1d31c14 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/EntityTypePropertyTypePE.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/EntityTypePropertyTypePE.java @@ -216,6 +216,7 @@ public abstract class EntityTypePropertyTypePE extends HibernateAbstractRegistra builder.append("ordinal", getOrdinal()); builder.append("section", getSection()); builder.append("dynamic", isDynamic()); + builder.append("managed", isManaged()); return builder.toString(); } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/EntityPropertiesConverterTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/EntityPropertiesConverterTest.java index d009c2b9438a35230e9fecca7c6cb6b7c117b9d5..322927142710bdc969a89ad212e537b900719b16 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/EntityPropertiesConverterTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/EntityPropertiesConverterTest.java @@ -61,7 +61,7 @@ public final class EntityPropertiesConverterTest extends AbstractBOTest private IDynamicPropertiesUpdateChecker dynamicPropertiesChecker; - private IDynamicProperiesPlaceholderCreator placeholderCreator; + private IPropertyPlaceholderCreator placeholderCreator; @Override @BeforeMethod @@ -70,7 +70,7 @@ public final class EntityPropertiesConverterTest extends AbstractBOTest super.beforeMethod(); propertyValueValidator = context.mock(IPropertyValueValidator.class); dynamicPropertiesChecker = context.mock(IDynamicPropertiesUpdateChecker.class); - placeholderCreator = context.mock(IDynamicProperiesPlaceholderCreator.class); + placeholderCreator = context.mock(IPropertyPlaceholderCreator.class); } @@ -180,12 +180,11 @@ public final class EntityPropertiesConverterTest extends AbstractBOTest one(dynamicPropertiesChecker).checkDynamicPropertiesNotManuallyUpdated( with(propertiesToUpdateMatcher), with(dynamicPropertiesMatcher)); - CollectionMatcher<List<IEntityProperty>> newPropertiesMatcher = - new CollectionMatcher<List<IEntityProperty>>( - new ArrayList<IEntityProperty>()); + CollectionMatcher<Set<IEntityProperty>> definedPropertiesMatcher = + new CollectionMatcher<Set<IEntityProperty>>( + new HashSet<IEntityProperty>()); one(placeholderCreator).addDynamicPropertiesPlaceholders( - with(newPropertiesMatcher), with(propertiesToUpdateMatcher), - with(dynamicPropertiesMatcher)); + with(definedPropertiesMatcher), with(dynamicPropertiesMatcher)); } }); final List<EntityPropertyPE> properties = @@ -245,11 +244,11 @@ public final class EntityPropertiesConverterTest extends AbstractBOTest { listOfProperties.add(p); } - CollectionMatcher<List<IEntityProperty>> newPropertiesMatcher = - new CollectionMatcher<List<IEntityProperty>>(listOfProperties); + CollectionMatcher<Set<IEntityProperty>> definedPropertiesMatcher = + new CollectionMatcher<Set<IEntityProperty>>( + new HashSet<IEntityProperty>()); one(placeholderCreator).addDynamicPropertiesPlaceholders( - with(newPropertiesMatcher), with(propertiesToUpdateMatcher), - with(dynamicPropertiesMatcher)); + with(definedPropertiesMatcher), with(dynamicPropertiesMatcher)); } }); @@ -303,11 +302,11 @@ public final class EntityPropertiesConverterTest extends AbstractBOTest { listOfProperties.add(p); } - CollectionMatcher<List<IEntityProperty>> newPropertiesMatcher = - new CollectionMatcher<List<IEntityProperty>>(listOfProperties); + CollectionMatcher<Set<IEntityProperty>> definedPropertiesMatcher = + new CollectionMatcher<Set<IEntityProperty>>( + new HashSet<IEntityProperty>()); one(placeholderCreator).addDynamicPropertiesPlaceholders( - with(newPropertiesMatcher), with(propertiesToUpdateMatcher), - with(dynamicPropertiesMatcher)); + with(definedPropertiesMatcher), with(dynamicPropertiesMatcher)); } }); final List<EntityPropertyPE> convertedProperties =