use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityHelper method removeAdditionalFieldsAndLookups.
/**
* In case of DDE, removes all fields and lookups that are not part of the original schema (was added later).
* In case of EUDE, removes all fields and lookups.
* @param entity entity to remove fields and lookups from
*/
public static void removeAdditionalFieldsAndLookups(Entity entity) {
Iterator<Field> fieldIterator = entity.getFields().iterator();
while (fieldIterator.hasNext()) {
Field field = fieldIterator.next();
if (!field.isAutoGenerated() && !field.isReadOnly()) {
fieldIterator.remove();
}
}
Iterator<Lookup> lookupIterator = entity.getLookups().iterator();
while (lookupIterator.hasNext()) {
Lookup lookup = lookupIterator.next();
if (!lookup.isReadOnly()) {
lookupIterator.remove();
}
}
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityWriter method writeFields.
private void writeFields() throws IOException {
jsonWriter.name("fields");
jsonWriter.beginArray();
for (Field field : entity.getFields()) {
if (!field.isReadOnly()) {
fieldWriter.writeField(field);
}
}
jsonWriter.endArray();
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityServiceImpl method addFilterableFields.
@Override
@Transactional
public void addFilterableFields(EntityDto entityDto, Collection<String> fieldNames) {
Entity entity = allEntities.retrieveById(entityDto.getId());
assertEntityExists(entity, entityDto.getId());
for (Field field : entity.getFields()) {
if (!field.isUiChanged()) {
field.setUIFilterable(fieldNames.contains(field.getName()));
}
}
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityServiceImpl method findEntityFieldByName.
@Override
@Transactional
public FieldDto findEntityFieldByName(Long entityId, String name) {
Entity entity = allEntities.retrieveById(entityId);
Field field = entity.getField(name);
if (field == null) {
throw new FieldNotFoundException(entity.getClassName(), name);
}
return field.toDto();
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityServiceImpl method addFields.
@Override
@Transactional
public void addFields(Long entityId, Collection<FieldDto> fields) {
Entity entity = allEntities.retrieveById(entityId);
assertEntityExists(entity, entityId);
removeFields(entity, fields);
for (FieldDto fieldDto : fields) {
Field existing = entity.getField(fieldDto.getBasic().getName());
if (null != existing) {
existing.update(fieldDto);
} else {
addField(entity, fieldDto);
}
}
}
Aggregations