Skip to content
Snippets Groups Projects
Commit 4ab4824d authored by buczekp's avatar buczekp
Browse files

[LMS-1508] improved speed of creating validated values for properties

SVN: 15702
parent ffb85332
No related branches found
No related tags found
No related merge requests found
...@@ -313,8 +313,8 @@ public final class EntityPropertiesConverter implements IEntityPropertiesConvert ...@@ -313,8 +313,8 @@ public final class EntityPropertiesConverter implements IEntityPropertiesConvert
} }
} }
public final <T extends EntityPropertyPE> T createProperty(PropertyTypePE propertyType, public final String tryCreateValidatedPropertyValue(PropertyTypePE propertyType,
EntityTypePropertyTypePE entityTypPropertyType, final PersonPE registrator, String value) EntityTypePropertyTypePE entityTypPropertyType, String value)
{ {
if (entityTypPropertyType.isMandatory() && value == null) if (entityTypPropertyType.isMandatory() && value == null)
{ {
...@@ -325,11 +325,20 @@ public final class EntityPropertiesConverter implements IEntityPropertiesConvert ...@@ -325,11 +325,20 @@ public final class EntityPropertiesConverter implements IEntityPropertiesConvert
{ {
final String validated = final String validated =
propertyValueValidator.validatePropertyValue(propertyType, value); propertyValueValidator.validatePropertyValue(propertyType, value);
return createEntityProperty(registrator, propertyType, entityTypPropertyType, validated); return validated;
} }
return null; return null;
} }
public final <T extends EntityPropertyPE> T createValidatedProperty(PropertyTypePE propertyType,
EntityTypePropertyTypePE entityTypPropertyType, final PersonPE registrator,
String validatedValue)
{
assert validatedValue != null;
return createEntityProperty(registrator, propertyType, entityTypPropertyType,
validatedValue);
}
public <T extends EntityPropertyPE, P extends IEntityProperty> Set<T> updateProperties( public <T extends EntityPropertyPE, P extends IEntityProperty> Set<T> updateProperties(
Collection<T> oldProperties, EntityTypePE entityType, List<P> newProperties, Collection<T> oldProperties, EntityTypePE entityType, List<P> newProperties,
PersonPE registrator) PersonPE registrator)
......
...@@ -30,6 +30,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.EntityPropertyPE; ...@@ -30,6 +30,7 @@ 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.EntityTypePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.EntityTypePropertyTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.EntityTypePropertyTypePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.IEntityPropertiesHolder; import ch.systemsx.cisd.openbis.generic.shared.dto.IEntityPropertiesHolder;
import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.PropertyTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.PropertyTypePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.Session; 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.dto.properties.EntityKind;
...@@ -141,11 +142,15 @@ public class EntityTypePropertyTypeBO extends AbstractBusinessObject implements ...@@ -141,11 +142,15 @@ public class EntityTypePropertyTypeBO extends AbstractBusinessObject implements
.getLabel(), createPlural(size), entityType.getCode())); .getLabel(), createPlural(size), entityType.getCode()));
} }
} }
PersonPE registrator = findRegistrator();
String validatedValue =
propertiesConverter.tryCreateValidatedPropertyValue(propertyType, assignment,
defaultValue);
for (IEntityPropertiesHolder entity : entities) for (IEntityPropertiesHolder entity : entities)
{ {
final EntityPropertyPE property = final EntityPropertyPE property =
propertiesConverter.createProperty(propertyType, assignment, findRegistrator(), propertiesConverter.createValidatedProperty(propertyType, assignment,
defaultValue); registrator, validatedValue);
if (property != null) if (property != null)
{ {
entity.addProperty(property); entity.addProperty(property);
......
...@@ -46,12 +46,19 @@ public interface IEntityPropertiesConverter ...@@ -46,12 +46,19 @@ public interface IEntityPropertiesConverter
final IEntityProperty[] properties, final String entityTypeCode, final IEntityProperty[] properties, final String entityTypeCode,
final PersonPE registrator); final PersonPE registrator);
/**
* Returns given value validated and converted for given property type and entity type.
* Result may be null if given value is null.
*/
public String tryCreateValidatedPropertyValue(PropertyTypePE propertyType,
EntityTypePropertyTypePE entityTypPropertyType, String value);
/** /**
* Creates {@link EntityPropertyPE}. * Creates {@link EntityPropertyPE}.
*/ */
public <T extends EntityPropertyPE> T createProperty(PropertyTypePE propertyType, public <T extends EntityPropertyPE> T createValidatedProperty(PropertyTypePE propertyType,
EntityTypePropertyTypePE entityTypePropertyType, final PersonPE registrator, EntityTypePropertyTypePE entityTypePropertyType, final PersonPE registrator,
String value); String validatedValue);
/** Updates Set<T> of properties. */ /** Updates Set<T> of properties. */
public <T extends EntityPropertyPE, P extends IEntityProperty> Set<T> updateProperties( public <T extends EntityPropertyPE, P extends IEntityProperty> Set<T> updateProperties(
......
...@@ -246,13 +246,15 @@ public final class EntityPropertiesConverterTest extends AbstractBOTest ...@@ -246,13 +246,15 @@ public final class EntityPropertiesConverterTest extends AbstractBOTest
one(propertyValueValidator).validatePropertyValue(propertyType, defaultValue); one(propertyValueValidator).validatePropertyValue(propertyType, defaultValue);
} }
}); });
assertEquals(registrator, entityPropertiesConverter.createProperty(propertyType, entityPropertiesConverter.tryCreateValidatedPropertyValue(propertyType, assignment,
defaultValue);
assertEquals(registrator, entityPropertiesConverter.createValidatedProperty(propertyType,
assignment, registrator, defaultValue).getRegistrator()); assignment, registrator, defaultValue).getRegistrator());
context.assertIsSatisfied(); context.assertIsSatisfied();
} }
@Test(expectedExceptions = UserFailureException.class) @Test(expectedExceptions = UserFailureException.class)
public void testCreatePropertyMandatoryWithNullGlobal() throws Exception public void testCreateValidatedPropertyValueMandatoryWithNullGlobal() throws Exception
{ {
final IEntityPropertiesConverter entityPropertiesConverter = final IEntityPropertiesConverter entityPropertiesConverter =
createEntityPropertiesConverter(EntityKind.SAMPLE); createEntityPropertiesConverter(EntityKind.SAMPLE);
...@@ -261,15 +263,15 @@ public final class EntityPropertiesConverterTest extends AbstractBOTest ...@@ -261,15 +263,15 @@ public final class EntityPropertiesConverterTest extends AbstractBOTest
EntityTypePropertyTypePE assignment = EntityTypePropertyTypePE assignment =
EntityTypePropertyTypePE.createEntityTypePropertyType(entityKind); EntityTypePropertyTypePE.createEntityTypePropertyType(entityKind);
assignment.setMandatory(true); assignment.setMandatory(true);
PersonPE registrator = new PersonPE();
final String defaultValue = null; final String defaultValue = null;
entityPropertiesConverter.createProperty(propertyType, assignment, registrator,
entityPropertiesConverter.tryCreateValidatedPropertyValue(propertyType, assignment,
defaultValue); defaultValue);
context.assertIsSatisfied(); context.assertIsSatisfied();
} }
@Test @Test
public void testCreatePropertyNotMandatoryWithNullGlobal() throws Exception public void testCreateValidatedPropertyValueNotMandatoryWithNullGlobal() throws Exception
{ {
final IEntityPropertiesConverter entityPropertiesConverter = final IEntityPropertiesConverter entityPropertiesConverter =
createEntityPropertiesConverter(EntityKind.EXPERIMENT); createEntityPropertiesConverter(EntityKind.EXPERIMENT);
...@@ -278,10 +280,9 @@ public final class EntityPropertiesConverterTest extends AbstractBOTest ...@@ -278,10 +280,9 @@ public final class EntityPropertiesConverterTest extends AbstractBOTest
EntityTypePropertyTypePE assignment = EntityTypePropertyTypePE assignment =
EntityTypePropertyTypePE.createEntityTypePropertyType(entityKind); EntityTypePropertyTypePE.createEntityTypePropertyType(entityKind);
assignment.setMandatory(false); assignment.setMandatory(false);
PersonPE registrator = new PersonPE();
final String defaultValue = null; final String defaultValue = null;
assertNull(entityPropertiesConverter.createProperty(propertyType, assignment, registrator, assertNull(entityPropertiesConverter.tryCreateValidatedPropertyValue(propertyType,
defaultValue)); assignment, defaultValue));
context.assertIsSatisfied(); context.assertIsSatisfied();
} }
} }
...@@ -104,7 +104,8 @@ public final class EntityTypePropertyTypeBOTest extends AbstractBOTest ...@@ -104,7 +104,8 @@ public final class EntityTypePropertyTypeBOTest extends AbstractBOTest
final EntityKind entityKind = EntityKind.EXPERIMENT; final EntityKind entityKind = EntityKind.EXPERIMENT;
boolean mandatory = true; boolean mandatory = true;
final String defaultValue = "50"; final String defaultValue = "50.00";
final String validatedValue = "50.0";
final String section = "section 1"; final String section = "section 1";
final ExperimentPE experiment = new ExperimentPE(); final ExperimentPE experiment = new ExperimentPE();
...@@ -132,9 +133,12 @@ public final class EntityTypePropertyTypeBOTest extends AbstractBOTest ...@@ -132,9 +133,12 @@ public final class EntityTypePropertyTypeBOTest extends AbstractBOTest
experimets.add(experiment); experimets.add(experiment);
will(returnValue(experimets)); will(returnValue(experimets));
one(propertiesConverter).createProperty(with(propertyType), one(propertiesConverter).tryCreateValidatedPropertyValue(with(propertyType),
with(any(ExperimentTypePropertyTypePE.class)), with(defaultValue));
will(returnValue(validatedValue));
one(propertiesConverter).createValidatedProperty(with(propertyType),
with(any(ExperimentTypePropertyTypePE.class)), with(any(ExperimentTypePropertyTypePE.class)),
with(any(PersonPE.class)), with(defaultValue)); with(any(PersonPE.class)), with(validatedValue));
will(returnValue(property)); will(returnValue(property));
} }
}); });
......
...@@ -629,17 +629,6 @@ public final class ExternalDataTableTest extends AbstractBOTest ...@@ -629,17 +629,6 @@ public final class ExternalDataTableTest extends AbstractBOTest
}); });
} }
private void prepareFlush()
{
context.checking(new Expectations()
{
{
one(externalDataDAO).flush();
}
});
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void prepareArchiving(final IDataStoreService service, final DataStorePE store, private void prepareArchiving(final IDataStoreService service, final DataStorePE store,
final ExternalDataPE... dataSets) final ExternalDataPE... dataSets)
......
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