use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityServiceImpl method removeRelatedFields.
private void removeRelatedFields(List<Field> fields, List<String> modulesToRefresh) {
for (Field field : fields) {
Entity entity = allEntities.retrieveByClassName(field.getMetadataValue(RELATED_CLASS));
Field relatedField = entity.getField(field.getMetadataValue(RELATED_FIELD));
entity.removeField(relatedField.getId());
entity.incrementVersion();
addModuleToRefresh(entity, modulesToRefresh);
}
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityServiceImpl method addDisplayedFields.
@Override
@Transactional
public void addDisplayedFields(EntityDto entityDto, Map<String, Long> positions) {
Entity entity = allEntities.retrieveById(entityDto.getId());
assertEntityExists(entity, entityDto.getId());
List<Field> fields = entity.getFields();
if (MapUtils.isEmpty(positions)) {
for (long i = 0; i < fields.size(); ++i) {
Field field = fields.get((int) i);
// user fields and auto generated fields are ignored
if (isFieldFromDde(field)) {
field.setUIDisplayable(true);
field.setUIDisplayPosition(i);
}
}
} else {
for (Field field : fields) {
String fieldName = field.getName();
boolean isUIDisplayable = positions.containsKey(fieldName);
Long uiDisplayPosition = positions.get(fieldName);
field.setUIDisplayable(isUIDisplayable);
field.setUIDisplayPosition(uiDisplayPosition);
}
}
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityServiceImpl method addRelatedField.
private void addRelatedField(Field draftField, List<String> modulesToRefresh) {
Entity entity = allEntities.retrieveByClassName(draftField.getMetadataValue(RELATED_CLASS));
String fieldName = draftField.getMetadataValue(RELATED_FIELD);
String collectionType = draftField.getMetadataValue(RELATIONSHIP_COLLECTION_TYPE);
String relatedClass = draftField.getEntity().getClassName();
Set<Lookup> fieldLookups = new HashSet<>();
Field relatedField = new Field(entity, fieldName, fieldName, false, false, false, false, false, null, null, null, fieldLookups);
Type type = allTypes.retrieveByClassName(TypeDto.MANY_TO_MANY_RELATIONSHIP.getTypeClass());
relatedField.setType(type);
if (type.hasSettings()) {
for (TypeSetting setting : type.getSettings()) {
relatedField.addSetting(new FieldSetting(relatedField, setting));
}
}
relatedField.setUIDisplayable(true);
relatedField.setUIDisplayPosition((long) entity.getFields().size());
FieldHelper.createMetadataForManyToManyRelationship(relatedField, relatedClass, collectionType, draftField.getName(), false);
entity.addField(relatedField);
entity.incrementVersion();
addModuleToRefresh(entity, modulesToRefresh);
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityServiceImpl method toFieldDtos.
private List<FieldDto> toFieldDtos(Entity entity, List<Field> fields, boolean fetchComboboxOptions) {
List<FieldDto> fieldDtos = new ArrayList<>();
for (Field field : fields) {
FieldDto fieldDto = field.toDto();
if (fetchComboboxOptions && field.getType().isCombobox()) {
List<String> values = getAllComboboxValues(entity, field);
fieldDto.setSetting(Constants.Settings.COMBOBOX_VALUES, values);
}
fieldDtos.add(fieldDto);
}
return fieldDtos;
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class MdsBundleIT method verifyColumnNameChange.
private void verifyColumnNameChange() throws ClassNotFoundException, InterruptedException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
getLogger().info("Verifying column name change");
Long entityId = entityService.getEntityByClassName(FOO_CLASS).getId();
List<Field> fields = entityService.getEntityDraft(entityId).getFields();
Field fieldToUpdate = findFieldByName(fields, "someString");
entityService.saveDraftEntityChanges(entityId, DraftBuilder.forFieldEdit(fieldToUpdate.getId(), "basic.name", "newFieldName"));
entityService.commitChanges(entityId);
SchemaHolder schemaHolder = entityService.getSchema();
generator.regenerateMdsDataBundle(schemaHolder);
FieldDto fieldToUpdateDto = DtoHelper.findByName(entityService.getEntityFields(entityId), "newFieldName");
assertNotNull("Unable to find field named 'newFieldName'", fieldToUpdate);
assertEquals(String.class.getName(), fieldToUpdateDto.getType().getTypeClass());
service = (MotechDataService) ServiceRetriever.getService(bundleContext, ClassName.getInterfaceName(FOO_CLASS), true);
Object retrieved = service.retrieveAll(QueryParams.ascOrder("someDateTime")).get(0);
Object fieldValue = MethodUtils.invokeMethod(retrieved, "getNewFieldName", null);
assertNotNull(fieldValue);
entityId = entityService.getEntityByClassName(FOO_CLASS).getId();
fields = entityService.getEntityDraft(entityId).getFields();
fieldToUpdate = findFieldByName(fields, "newFieldName");
entityService.saveDraftEntityChanges(entityId, DraftBuilder.forFieldEdit(fieldToUpdate.getId(), "basic.name", "someString"));
entityService.commitChanges(entityId);
schemaHolder = entityService.getSchema();
generator.regenerateMdsDataBundle(schemaHolder);
service = (MotechDataService) ServiceRetriever.getService(bundleContext, ClassName.getInterfaceName(FOO_CLASS), true);
}
Aggregations