diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java index eefb7dc6036dda922e6f2030e329d33e96ae96f2..208a238cd76306b29c087fa7d6aff40f6af34027 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java @@ -215,7 +215,6 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewETPTAssignment; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewVocabulary; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PersonAdapter; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Project; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyUpdates; @@ -2968,7 +2967,8 @@ public final class CommonServer extends AbstractCommonServer<ICommonServerForInt ManagedPropertyEvaluator evaluator = tryManagedPropertyEvaluator(managedProperty, properties); extendWithPerson(updateAction, session.tryGetPerson()); - evaluator.updateFromUI(managedProperty, updateAction); + evaluator.updateFromUI(managedProperty, + PersonTranslator.translateToIPerson(session.tryGetPerson()), updateAction); experimentBO.updateManagedProperty(managedProperty); experimentBO.save(); @@ -2989,7 +2989,8 @@ public final class CommonServer extends AbstractCommonServer<ICommonServerForInt ManagedPropertyEvaluator evaluator = tryManagedPropertyEvaluator(managedProperty, properties); extendWithPerson(updateAction, session.tryGetPerson()); - evaluator.updateFromUI(managedProperty, updateAction); + evaluator.updateFromUI(managedProperty, + PersonTranslator.translateToIPerson(session.tryGetPerson()), updateAction); sampleBO.updateManagedProperty(managedProperty); sampleBO.save(); @@ -3010,7 +3011,8 @@ public final class CommonServer extends AbstractCommonServer<ICommonServerForInt ManagedPropertyEvaluator evaluator = tryManagedPropertyEvaluator(managedProperty, properties); extendWithPerson(updateAction, session.tryGetPerson()); - evaluator.updateFromUI(managedProperty, updateAction); + evaluator.updateFromUI(managedProperty, + PersonTranslator.translateToIPerson(session.tryGetPerson()), updateAction); dataSetBO.updateManagedProperty(managedProperty); dataSetBO.save(); @@ -3031,7 +3033,8 @@ public final class CommonServer extends AbstractCommonServer<ICommonServerForInt ManagedPropertyEvaluator evaluator = tryManagedPropertyEvaluator(managedProperty, properties); extendWithPerson(updateAction, session.tryGetPerson()); - evaluator.updateFromUI(managedProperty, updateAction); + evaluator.updateFromUI(managedProperty, + PersonTranslator.translateToIPerson(session.tryGetPerson()), updateAction); materialBO.updateManagedProperty(managedProperty); materialBO.save(); @@ -3041,13 +3044,7 @@ public final class CommonServer extends AbstractCommonServer<ICommonServerForInt { if (personOrNull != null && updateAction instanceof ManagedUiActionDescription) { - final String userId = personOrNull.getUserId(); - String userName = userId; - if (personOrNull.getFirstName() != null && personOrNull.getLastName() != null) - { - userName = personOrNull.getFirstName() + " " + personOrNull.getLastName(); - } - final IPerson person = new PersonAdapter(userId, userName); + final IPerson person = PersonTranslator.translateToIPerson(personOrNull); final ManagedUiActionDescription action = (ManagedUiActionDescription) updateAction; action.setPerson(person); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/PropertiesBatchManager.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/PropertiesBatchManager.java index 71ea78616e310dfdc92b135f7b0b6a2e765f1636..b3af8e28d354154bab177d7f4e2c442cb8ed7a9a 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/PropertiesBatchManager.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/PropertiesBatchManager.java @@ -40,6 +40,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewDataSet; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewMaterial; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IPerson; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.ValidationException; import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.EntityTypePropertyTypePE; @@ -51,6 +52,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.ScriptPE; import ch.systemsx.cisd.openbis.generic.shared.managed_property.ManagedPropertyEvaluator; import ch.systemsx.cisd.openbis.generic.shared.managed_property.ManagedPropertyEvaluatorFactory; import ch.systemsx.cisd.openbis.generic.shared.managed_property.ManagedPropertyFunctions; +import ch.systemsx.cisd.openbis.generic.shared.translator.PersonTranslator; /** * Handles Managed Properties of batch uploads/updates. @@ -113,13 +115,14 @@ public class PropertiesBatchManager implements IPropertiesBatchManager Map<String, EvaluationContext> contexts = createEvaluationContexts(entityTypePropertyTypes); PropertiesBatchEvaluationErrors errors = new PropertiesBatchEvaluationErrors(registrator, propertiesBeans.size()); + IPerson person = PersonTranslator.translateToIPerson(registrator); int rowNumber = 0; for (IPropertiesBean propertiesBean : propertiesBeans) { rowNumber++; List<IEntityProperty> newProperties = - accumulateNewProperties(propertiesBean, rowNumber, contexts, errors); + accumulateNewProperties(propertiesBean, person, rowNumber, contexts, errors); IEntityProperty[] newPropArray = newProperties.toArray(new IEntityProperty[newProperties.size()]); propertiesBean.setProperties(newPropArray); @@ -135,7 +138,7 @@ public class PropertiesBatchManager implements IPropertiesBatchManager } private List<IEntityProperty> accumulateNewProperties(IPropertiesBean propertiesBean, - int rowNumber, Map<String, EvaluationContext> contexts, + IPerson person, int rowNumber, Map<String, EvaluationContext> contexts, PropertiesBatchEvaluationErrors errors) { List<IEntityProperty> newProperties = new ArrayList<IEntityProperty>(); @@ -149,7 +152,7 @@ public class PropertiesBatchManager implements IPropertiesBatchManager try { EntityProperty entityProperty = - evaluateManagedProperty(code, entry.getValue(), evalContext); + evaluateManagedProperty(code, person, entry.getValue(), evalContext); if (false == ManagedProperty.isSpecialValue(entityProperty.getValue())) { newProperties.add(entityProperty); @@ -169,8 +172,8 @@ public class PropertiesBatchManager implements IPropertiesBatchManager return newProperties; } - private EntityProperty evaluateManagedProperty(String code, Map<String, String> bindings, - EvaluationContext evalContext) + private EntityProperty evaluateManagedProperty(String code, IPerson person, + Map<String, String> bindings, EvaluationContext evalContext) { EntityProperty entityProperty = createNewEntityProperty(code); if (evalContext == null) @@ -181,7 +184,7 @@ public class PropertiesBatchManager implements IPropertiesBatchManager ManagedPropertyEvaluator evaluator = evalContext.evaluator; ManagedProperty managedProperty = new ManagedProperty(); managedProperty.setPropertyTypeCode(code); - evaluator.updateFromBatchInput(managedProperty, bindings); + evaluator.updateFromBatchInput(managedProperty, person, bindings); entityProperty.setValue(managedProperty.getValue()); } return entityProperty; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/EntityPropertiesConverter.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/EntityPropertiesConverter.java index 5a1af7bb5d5af2bdb701b3b594dcde4eca257fb3..8c5f193c5d31064e09d6420f1fed68d900e388b6 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/EntityPropertiesConverter.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/EntityPropertiesConverter.java @@ -46,6 +46,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ManagedProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialIdentifier; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedInputWidgetDescription; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedProperty; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IPerson; 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; @@ -58,6 +59,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyTermPE; import ch.systemsx.cisd.openbis.generic.shared.dto.properties.EntityKind; import ch.systemsx.cisd.openbis.generic.shared.managed_property.ManagedPropertyEvaluator; import ch.systemsx.cisd.openbis.generic.shared.managed_property.ManagedPropertyEvaluatorFactory; +import ch.systemsx.cisd.openbis.generic.shared.translator.PersonTranslator; /** * The unique {@link IEntityPropertiesConverter} implementation. @@ -270,7 +272,7 @@ public final class EntityPropertiesConverter implements IEntityPropertiesConvert propertyValueValidator.validatePropertyValue(propertyType, valueOrNull); return createEntityProperty(registrator, propertyType, entityTypePropertyTypePE, - extendedETPT.translate(validated)); + extendedETPT.translate(registrator, validated)); } return null; } @@ -579,7 +581,7 @@ public final class EntityPropertiesConverter implements IEntityPropertiesConvert } @SuppressWarnings("unchecked") - String translate(String propertyValue) + String translate(PersonPE personPE, String propertyValue) { if (inputWidgetDescriptions.isEmpty() || propertyValue == null @@ -601,7 +603,10 @@ public final class EntityPropertiesConverter implements IEntityPropertiesConvert { continue; } - evaluator.updateFromBatchInput(managedProperty, (Map<String, String>) row); + + IPerson person = PersonTranslator.translateToIPerson(personPE); + evaluator.updateFromBatchInput(managedProperty, person, + (Map<String, String>) row); } return managedProperty.getValue(); } catch (Exception ex) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/PersonAdapter.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/PersonAdapter.java index f11e469ed6e58a04a5889b30ad304d171dc4a40e..04586ecb3c0814488c5657011e0e62482679810d 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/PersonAdapter.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/PersonAdapter.java @@ -29,10 +29,15 @@ public class PersonAdapter implements IPerson private String userName; - public PersonAdapter(String userId, String userName) + public PersonAdapter(String userId, String firstName, String lastName) { this.userId = userId; - this.userName = userName; + this.userName = userId; + + if (firstName != null && lastName != null) + { + userName = firstName + " " + lastName; + } } @Override diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluator.java index ddaa313beb9002a503318a194ca1b6689b792ef2..2425e63e66a48d6c411059f5e1564c7dec398af7 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluator.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluator.java @@ -32,6 +32,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ManagedUiActionDescript import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedInputWidgetDescription; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedUiAction; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IPerson; import ch.systemsx.cisd.openbis.generic.shared.dto.EntityPropertyPE; /** @@ -97,6 +98,8 @@ public class ManagedPropertyEvaluator private static final String PROPERTY_PE_VARIABLE_NAME = "propertyPE"; + private static final String PERSON_VARIABLE_NAME = "person"; + private final Evaluator evaluator; private final List<String> columnNames; @@ -213,7 +216,8 @@ public class ManagedPropertyEvaluator evaluator.evalFunction(CONFIGURE_UI_FUNCTION); } - public void updateFromUI(IManagedProperty managedProperty, IManagedUiAction action) + public void updateFromUI(IManagedProperty managedProperty, IPerson person, + IManagedUiAction action) { if (operationLog.isDebugEnabled()) { @@ -222,6 +226,7 @@ public class ManagedPropertyEvaluator } evaluator.set(PROPERTY_VARIABLE_NAME, managedProperty); + evaluator.set(PERSON_VARIABLE_NAME, person); evaluator.evalFunction(UPDATE_FROM_UI_FUNCTION, action); } @@ -235,7 +240,8 @@ public class ManagedPropertyEvaluator return inputWidgetDescriptions; } - public void updateFromBatchInput(IManagedProperty managedProperty, Map<String, String> bindings) + public void updateFromBatchInput(IManagedProperty managedProperty, IPerson person, + Map<String, String> bindings) { if (updateFromBatchFunctionDefined == false) { @@ -246,6 +252,7 @@ public class ManagedPropertyEvaluator } else { evaluator.set(PROPERTY_VARIABLE_NAME, managedProperty); + evaluator.set(PERSON_VARIABLE_NAME, person); evaluator.evalFunction(UPDATE_FROM_BATCH_INPUT_FUNCTION, bindings); } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/PersonTranslator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/PersonTranslator.java index aea5351a7cdc30fdfa798e59c13544632f7eee15..3af9b866b1cbe008ccc3d51c505ca6f288505303 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/PersonTranslator.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/PersonTranslator.java @@ -21,6 +21,8 @@ import java.util.Collection; import java.util.List; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PersonAdapter; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IPerson; import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; /** @@ -72,4 +74,16 @@ public class PersonTranslator return result; } + + public final static IPerson translateToIPerson(final PersonPE personPE) + { + if (personPE == null) + { + return null; + } + + return new PersonAdapter(personPE.getUserId(), personPE.getFirstName(), + personPE.getLastName()); + } + } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluatorTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluatorTest.java index 8db850c8c7ff5085dd6c52fecc62a814b3ac5668..92eb390811117679e8c19b998716eaaf4b7cb6b7 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluatorTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluatorTest.java @@ -29,6 +29,8 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ManagedComboBoxInputWid import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ManagedHtmlWidgetDescription; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ManagedProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ManagedTableWidgetDescription; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ManagedUiActionDescription; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PersonAdapter; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModel; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedInputWidgetDescription; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedInputWidgetDescriptionFactory; @@ -36,6 +38,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedOutputWidge import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedUiAction; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedUiDescription; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IPerson; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.ManagedInputFieldType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.ManagedOutputWidgetType; import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePropertyPE; @@ -217,6 +220,8 @@ public class ManagedPropertyEvaluatorTest extends AssertJUnit IManagedInputWidgetDescriptionFactory widgetFactory = ManagedPropertyFunctions.inputWidgetFactory(); + IPerson person = new PersonAdapter("test", null, null); + IManagedUiAction action1 = uiDescription.addAction("a1"); IManagedInputWidgetDescription action1w1 = widgetFactory.createTextInputField("t1"); IManagedInputWidgetDescription action1w2 = @@ -246,7 +251,7 @@ public class ManagedPropertyEvaluatorTest extends AssertJUnit String script = CommonTestUtils.getResourceAsString(SCRIPT_FOLDER, UPDATE_FROM_UI_TEST_PY); ManagedPropertyEvaluator evaluator = new ManagedPropertyEvaluator(script); - evaluator.updateFromUI(managedProperty, action1); + evaluator.updateFromUI(managedProperty, person, action1); assertNotNull(managedProperty.getValue()); String[] inputTokens1 = managedProperty.getValue().split("\\|"); assertEquals("a1", inputTokens1[0]); @@ -255,7 +260,7 @@ public class ManagedPropertyEvaluatorTest extends AssertJUnit assertEquals("multi=multi\nline\ninput", inputTokens1[3]); assertEquals("combo=cv1", inputTokens1[4]); - evaluator.updateFromUI(managedProperty, action2); + evaluator.updateFromUI(managedProperty, person, action2); assertNotNull(managedProperty.getValue()); String[] inputTokens2 = managedProperty.getValue().split("\\!"); assertEquals("a2", inputTokens2[0]); @@ -264,7 +269,7 @@ public class ManagedPropertyEvaluatorTest extends AssertJUnit try { - evaluator.updateFromUI(managedProperty, action3); + evaluator.updateFromUI(managedProperty, person, action3); fail("expected EvaluatorException"); } catch (EvaluatorException e) { @@ -272,6 +277,22 @@ public class ManagedPropertyEvaluatorTest extends AssertJUnit } } + @Test + public void testUpdateFromUIAccessToPerson() + { + ManagedPropertyEvaluator evaluator = + new ManagedPropertyEvaluator("def updateFromUI(action):\n" + + " property.setValue(person.getUserId() + ';' + person.getUserName())"); + ManagedProperty property = new ManagedProperty(); + property.setPropertyTypeCode("p"); + IPerson person = new PersonAdapter("jbravo", "Johny", "Bravo"); + IManagedUiAction action = new ManagedUiActionDescription(); + + evaluator.updateFromUI(property, person, action); + + assertEquals("jbravo;Johny Bravo", property.getValue()); + } + private void checkInputFieldWidget(IManagedInputWidgetDescription widget, ManagedInputFieldType expectedType, String expectedLabel, String expectedDefaultValue, String expectedDescription, boolean expectedMandatory) @@ -408,10 +429,11 @@ public class ManagedPropertyEvaluatorTest extends AssertJUnit ManagedPropertyEvaluator evaluator = new ManagedPropertyEvaluator(""); ManagedProperty property = new ManagedProperty(); property.setPropertyTypeCode("p"); + IPerson person = new PersonAdapter("test", null, null); Map<String, String> bindings = new HashMap<String, String>(); bindings.put("", "42"); - evaluator.updateFromBatchInput(property, bindings); + evaluator.updateFromBatchInput(property, person, bindings); assertEquals("42", property.getValue()); } @@ -424,10 +446,11 @@ public class ManagedPropertyEvaluatorTest extends AssertJUnit + " property.setValue(bindings.get(''))"); ManagedProperty property = new ManagedProperty(); property.setPropertyTypeCode("p"); + IPerson person = new PersonAdapter("test", null, null); Map<String, String> bindings = new HashMap<String, String>(); bindings.put("", "42"); - evaluator.updateFromBatchInput(property, bindings); + evaluator.updateFromBatchInput(property, person, bindings); assertEquals("42", property.getValue()); } @@ -441,11 +464,12 @@ public class ManagedPropertyEvaluatorTest extends AssertJUnit + " property.setValue(bindings.get('A') + bindings.get('B'))"); ManagedProperty property = new ManagedProperty(); property.setPropertyTypeCode("p"); + IPerson person = new PersonAdapter("test", null, null); Map<String, String> bindings = new HashMap<String, String>(); bindings.put("A", "4"); bindings.put("B", "2"); - evaluator.updateFromBatchInput(property, bindings); + evaluator.updateFromBatchInput(property, person, bindings); assertEquals("42", property.getValue()); } @@ -461,14 +485,61 @@ public class ManagedPropertyEvaluatorTest extends AssertJUnit + "bindings.get(originalColumnNameBindingKey('OC')))"); ManagedProperty property = new ManagedProperty(); property.setPropertyTypeCode("p"); + IPerson person = new PersonAdapter("test", null, null); Map<String, String> bindings = new HashMap<String, String>(); bindings.put("BC1", "b1"); bindings.put("BC2", "b2"); bindings.put(ManagedPropertyFunctions.originalColumnNameBindingKey("OC"), "original"); - evaluator.updateFromBatchInput(property, bindings); + evaluator.updateFromBatchInput(property, person, bindings); assertEquals("b1 b2 original", property.getValue()); } + @Test + public void testUpdateFromBatchInputAccessToPersonWithAllFieldsFilled() + { + ManagedPropertyEvaluator evaluator = + new ManagedPropertyEvaluator("def updateFromBatchInput(bindings):\n" + + " property.setValue(person.getUserId() + ';' + person.getUserName())"); + ManagedProperty property = new ManagedProperty(); + property.setPropertyTypeCode("p"); + IPerson person = new PersonAdapter("jbravo", "Johny", "Bravo"); + Map<String, String> bindings = new HashMap<String, String>(); + + evaluator.updateFromBatchInput(property, person, bindings); + + assertEquals("jbravo;Johny Bravo", property.getValue()); + } + + @Test + public void testUpdateFromBatchInputAccessToPersonWithEmptyFirstNameAndLastName() + { + ManagedPropertyEvaluator evaluator = + new ManagedPropertyEvaluator("def updateFromBatchInput(bindings):\n" + + " property.setValue(person.getUserId() + ';' + person.getUserName())"); + ManagedProperty property = new ManagedProperty(); + property.setPropertyTypeCode("p"); + IPerson person = new PersonAdapter("jbravo", null, null); + Map<String, String> bindings = new HashMap<String, String>(); + + evaluator.updateFromBatchInput(property, person, bindings); + + assertEquals("jbravo;jbravo", property.getValue()); + } + + @Test + public void testUpdateFromBatchInputAccessToNullPerson() + { + ManagedPropertyEvaluator evaluator = + new ManagedPropertyEvaluator("def updateFromBatchInput(bindings):\n" + + " property.setValue(person)"); + ManagedProperty property = new ManagedProperty(); + property.setPropertyTypeCode("p"); + Map<String, String> bindings = new HashMap<String, String>(); + + evaluator.updateFromBatchInput(property, null, bindings); + + assertNull(property.getValue()); + } }