@Test public void shouldAddAndUpdateComboboxMetadata() { Entity entity = new Entity("SampleEntity"); entity.setClassName("org.motechproject.samplemodule.domain.SampleEntity"); Field field = FieldTestHelper.fieldWithComboboxSettings(entity, "sampleField", "Display Name", String.class, false, false, asList("Item_1", "Item_2")); FieldHelper.addOrUpdateMetadataForCombobox(field); assertEquals("org.motechproject.samplemodule.domain.mdsenum.SampleEntitySampleField", field.getMetadata(Constants.MetadataKeys.ENUM_CLASS_NAME).getValue()); Entity otherEntity = new Entity("OtherEntity"); otherEntity.setClassName("org.motechproject.samplemodule.domain.OtherEntity"); field.setEntity(otherEntity); FieldHelper.addOrUpdateMetadataForCombobox(field); assertEquals("org.motechproject.samplemodule.domain.mdsenum.OtherEntitySampleField", field.getMetadata(Constants.MetadataKeys.ENUM_CLASS_NAME).getValue()); }
public static void addOrUpdateMetadataForCombobox(Field field) { if (field.getType().isCombobox()) { FieldMetadata metadata = field.getMetadata(ENUM_CLASS_NAME); if (metadata == null) { metadata = new FieldMetadata(field, ENUM_CLASS_NAME); metadata.setValue(MemberUtil.getDefaultEnumName(field.getEntity().getClassName(), field.getName())); field.addMetadata(metadata); } else { field.setMetadataValue(ENUM_CLASS_NAME, MemberUtil.getDefaultEnumName(field.getEntity().getClassName(), field.getName())); } } }
FieldHelper { public static void addOrUpdateMetadataForCombobox(Field field) { if (field.getType().isCombobox()) { FieldMetadata metadata = field.getMetadata(ENUM_CLASS_NAME); if (metadata == null) { metadata = new FieldMetadata(field, ENUM_CLASS_NAME); metadata.setValue(MemberUtil.getDefaultEnumName(field.getEntity().getClassName(), field.getName())); field.addMetadata(metadata); } else { field.setMetadataValue(ENUM_CLASS_NAME, MemberUtil.getDefaultEnumName(field.getEntity().getClassName(), field.getName())); } } } }
FieldHelper { public static void addOrUpdateMetadataForCombobox(Field field) { if (field.getType().isCombobox()) { FieldMetadata metadata = field.getMetadata(ENUM_CLASS_NAME); if (metadata == null) { metadata = new FieldMetadata(field, ENUM_CLASS_NAME); metadata.setValue(MemberUtil.getDefaultEnumName(field.getEntity().getClassName(), field.getName())); field.addMetadata(metadata); } else { field.setMetadataValue(ENUM_CLASS_NAME, MemberUtil.getDefaultEnumName(field.getEntity().getClassName(), field.getName())); } } } private  FieldHelper(); }
FieldHelper { public static void addOrUpdateMetadataForCombobox(Field field) { if (field.getType().isCombobox()) { FieldMetadata metadata = field.getMetadata(ENUM_CLASS_NAME); if (metadata == null) { metadata = new FieldMetadata(field, ENUM_CLASS_NAME); metadata.setValue(MemberUtil.getDefaultEnumName(field.getEntity().getClassName(), field.getName())); field.addMetadata(metadata); } else { field.setMetadataValue(ENUM_CLASS_NAME, MemberUtil.getDefaultEnumName(field.getEntity().getClassName(), field.getName())); } } } private  FieldHelper(); static void setField(Object current, String path, List value); static Map<String, Field> fieldMapByName(Collection<Field> fields); static void addOrUpdateMetadataForCombobox(Field field); static void addMetadataForRelationship(String typeClass, Field field); static void createMetadataForManyToManyRelationship(Field field, String relatedClass, String collectionType,
                                                               String relatedField, boolean isOwningSide); static void setMetadataForManyToManyRelationship(Field field, boolean isOwningSide); }
FieldHelper { public static void addOrUpdateMetadataForCombobox(Field field) { if (field.getType().isCombobox()) { FieldMetadata metadata = field.getMetadata(ENUM_CLASS_NAME); if (metadata == null) { metadata = new FieldMetadata(field, ENUM_CLASS_NAME); metadata.setValue(MemberUtil.getDefaultEnumName(field.getEntity().getClassName(), field.getName())); field.addMetadata(metadata); } else { field.setMetadataValue(ENUM_CLASS_NAME, MemberUtil.getDefaultEnumName(field.getEntity().getClassName(), field.getName())); } } } private  FieldHelper(); static void setField(Object current, String path, List value); static Map<String, Field> fieldMapByName(Collection<Field> fields); static void addOrUpdateMetadataForCombobox(Field field); static void addMetadataForRelationship(String typeClass, Field field); static void createMetadataForManyToManyRelationship(Field field, String relatedClass, String collectionType,
                                                               String relatedField, boolean isOwningSide); static void setMetadataForManyToManyRelationship(Field field, boolean isOwningSide);  }