use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityServiceImpl method removeFields.
private void removeFields(Entity entity, Collection<FieldDto> fields) {
Iterator<Field> iterator = entity.getFields().iterator();
while (iterator.hasNext()) {
Field field = iterator.next();
// don't remove user defined fields
if (!field.isReadOnly() || field.getMetadata(AUTO_GENERATED) != null || field.getMetadata(AUTO_GENERATED_EDITABLE) != null) {
continue;
}
boolean found = false;
for (FieldDto fieldDto : fields) {
if (field.getName().equalsIgnoreCase(fieldDto.getBasic().getName())) {
found = true;
break;
}
}
if (!found) {
iterator.remove();
}
}
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityServiceImpl method getFieldsForPreferences.
private Set<Field> getFieldsForPreferences(Entity parent, EntityDraft draft, Set<String> oldFields) {
Set<Field> newFields = new HashSet<>();
for (String field : oldFields) {
String name = field;
if (draft.getFieldNameChanges().containsKey(name)) {
name = draft.getFieldNameChanges().get(name);
}
Field newfield = parent.getField(name);
if (newfield != null) {
newFields.add(newfield);
}
}
return newFields;
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityServiceImpl method addNonPersistentDataForLookupFields.
private void addNonPersistentDataForLookupFields(Collection<LookupDto> lookupDtos, Entity entity) {
for (LookupDto lookup : lookupDtos) {
for (LookupFieldDto lookupField : lookup.getLookupFields()) {
Field field = entity.getField(lookupField.getName());
if (StringUtils.isNotBlank(lookupField.getRelatedName())) {
Entity relatedEntity = allEntities.retrieveByClassName(field.getMetadata(Constants.MetadataKeys.RELATED_CLASS).getValue());
Field relatedField = relatedEntity.getField(lookupField.getRelatedName());
addNonPersistentDataForLookupField(relatedField, lookupField, field.getDisplayName(), relatedField.getDisplayName());
} else {
addNonPersistentDataForLookupField(field, lookupField, field.getDisplayName(), null);
}
}
}
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityServiceImpl method getEntityFieldsByClassName.
private List<FieldDto> getEntityFieldsByClassName(String className, boolean forUI) {
Entity entity = allEntities.retrieveByClassName(className);
assertEntityExists(entity, className);
List<Field> fields = new ArrayList<>(entity.getFields());
Collections.sort(fields, new UIDisplayFieldComparator());
return toFieldDtos(entity, fields, forUI);
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityServiceImpl method updateRelatedField.
private void updateRelatedField(Field oldField, Field draftField, List<String> modulesToRefresh) {
Entity relatedEntity = allEntities.retrieveByClassName(oldField.getMetadataValue(RELATED_CLASS));
Field relatedField = relatedEntity.getField(oldField.getMetadataValue(RELATED_FIELD));
boolean fieldChanged = false;
boolean relatedEntityChanged = false;
if (!StringUtils.equals(draftField.getMetadataValue(RELATED_CLASS), oldField.getMetadataValue(RELATED_CLASS))) {
addRelatedField(draftField, modulesToRefresh);
relatedEntity.removeField(relatedField.getId());
relatedEntityChanged = true;
}
if (!relatedEntityChanged && !StringUtils.equals(draftField.getMetadataValue(RELATIONSHIP_COLLECTION_TYPE), oldField.getMetadataValue(RELATIONSHIP_COLLECTION_TYPE))) {
relatedField.setMetadataValue(RELATIONSHIP_COLLECTION_TYPE, draftField.getMetadataValue(RELATIONSHIP_COLLECTION_TYPE));
fieldChanged = true;
}
if (!relatedEntityChanged && !StringUtils.equals(draftField.getMetadataValue(RELATED_FIELD), oldField.getMetadataValue(RELATED_FIELD))) {
relatedField.setName(draftField.getMetadataValue(RELATED_FIELD));
fieldChanged = true;
}
if (!relatedEntityChanged && !oldField.getName().equals(draftField.getName())) {
relatedField.setMetadataValue(RELATED_FIELD, draftField.getName());
fieldChanged = true;
}
if (fieldChanged || relatedEntityChanged) {
relatedEntity.incrementVersion();
}
addModuleToRefresh(relatedEntity, modulesToRefresh);
}
Aggregations