use of org.motechproject.mds.dto.LookupDto in project motech by motech.
the class EditableLookupsLoader method addEditableEntityLookups.
private void addEditableEntityLookups(MDSProcessorOutput output, EntityLookups entityLookups) {
String entityClassName = entityLookups.getEntityClassName();
List<LookupDto> lookupsToAdd = new ArrayList<>();
for (LookupDto lookup : entityLookups.getLookups()) {
if (!jsonLookupService.exists(entityClassName, lookup.getLookupName())) {
lookupsToAdd.add(lookup);
JsonLookupDto jsonLookup = new JsonLookupDto(entityClassName, lookup.getLookupName());
jsonLookupService.createJsonLookup(jsonLookup);
LOGGER.debug(LOOKUP_ADDED, lookup.getLookupName(), entityClassName);
}
}
List<LookupDto> lookups = getLookups(output, entityClassName);
if (lookupsToAdd.size() > 0) {
if (lookups == null) {
lookups = new ArrayList<>();
output.getLookupProcessorOutputs().put(entityClassName, lookups);
}
lookups.addAll(lookupsToAdd);
}
}
use of org.motechproject.mds.dto.LookupDto in project motech by motech.
the class Entity method addLookup.
public void addLookup(Lookup lookup) {
Lookup existing = getLookupByName(lookup.getLookupName());
if (existing == null) {
lookup.setEntity(this);
getLookups().add(lookup);
} else {
LookupDto lookupDto = lookup.toDto();
List<Field> lookupFields = new ArrayList<>();
for (LookupFieldDto lookupField : lookupDto.getLookupFields()) {
lookupFields.add(getField(lookupField.getId()));
}
existing.update(lookupDto, lookupFields);
}
}
use of org.motechproject.mds.dto.LookupDto in project motech by motech.
the class Entity method updateIndexes.
public void updateIndexes(List<LookupDto> indexes) {
// deletion
Iterator<Lookup> it = getLookups().iterator();
while (it.hasNext()) {
Lookup lookup = it.next();
boolean inNewList = false;
for (LookupDto lookupDto : indexes) {
if (Objects.equals(lookup.getId(), lookupDto.getId())) {
inNewList = true;
break;
}
}
if (!inNewList) {
it.remove();
}
}
for (LookupDto lookupDto : indexes) {
Lookup lookup = getLookupById(lookupDto.getId());
List<Field> lookupFields = new ArrayList<>();
List<String> lookupFieldsOrder = new ArrayList<>();
for (LookupFieldDto lookupField : lookupDto.getLookupFields()) {
Field field = getField(lookupField.getId());
if (!lookupFields.contains(field)) {
lookupFields.add(field);
}
String lookupFieldName = LookupName.buildLookupFieldName(field.getName(), lookupField.getRelatedName());
lookupFieldsOrder.add(lookupFieldName);
lookupField.setName(lookupFieldName);
}
lookupDto.setFieldsOrder(lookupFieldsOrder);
if (lookup == null) {
Lookup newLookup = new Lookup(lookupDto, lookupFields);
addLookup(newLookup);
} else {
lookup.update(lookupDto, lookupFields);
}
}
}
use of org.motechproject.mds.dto.LookupDto in project motech by motech.
the class EntityServiceImpl method removeLookup.
private void removeLookup(Entity entity, Collection<LookupDto> lookups) {
Iterator<Lookup> iterator = entity.getLookups().iterator();
while (iterator.hasNext()) {
Lookup lookup = iterator.next();
// don't remove user defined lookups
if (!lookup.isReadOnly()) {
continue;
}
boolean found = false;
for (LookupDto lookupDto : lookups) {
if (lookup.getLookupName().equalsIgnoreCase(lookupDto.getLookupName())) {
found = true;
break;
}
}
if (!found) {
iterator.remove();
}
}
}
use of org.motechproject.mds.dto.LookupDto in project motech by motech.
the class EntityServiceImpl method addNonPersistentFieldsData.
private List<FieldDto> addNonPersistentFieldsData(List<FieldDto> fieldDtos, Entity entity) {
List<LookupDto> lookupDtos = new ArrayList<>();
for (FieldDto fieldDto : fieldDtos) {
List<LookupDto> fieldLookups = fieldDto.getLookups();
if (fieldLookups != null) {
lookupDtos.addAll(fieldLookups);
}
}
addLookupsReferences(lookupDtos, entity.getClassName());
return fieldDtos;
}
Aggregations