use of org.motechproject.mds.domain.Lookup in project motech by motech.
the class LookupReader method readLookup.
public void readLookup() throws IOException {
Lookup lookup = new Lookup();
lookup.setEntity(entity);
jsonReader.beginObject();
lookup.setLookupName(objectReader.readString("name"));
lookup.setSingleObjectReturn(objectReader.readBoolean("singleObjectReturn"));
lookup.setMethodName(objectReader.readString("methodName"));
lookup.setFields(readFields());
lookup.setRangeLookupFields(objectReader.readStringArray("rangeFields"));
lookup.setCustomOperators(objectReader.readStringMap("customOperators"));
lookup.setUseGenericParams(objectReader.readBooleanMap("useGenericParams"));
lookup.setFieldsOrder(objectReader.readStringArray("fieldsOrder"));
jsonReader.endObject();
Lookup existingLookup = entity.getLookupByName(lookup.getLookupName());
if (null == existingLookup) {
entity.addLookup(lookup);
} else if (!existingLookup.isReadOnly()) {
entity.removeLookup(existingLookup.getId());
entity.addLookup(lookup);
} else {
throw new LookupReadOnlyException("Cannot import lookup " + lookup.getLookupName());
}
}
use of org.motechproject.mds.domain.Lookup in project motech by motech.
the class AllEntityAudits method createAudit.
public EntityAudit createAudit(Entity entity, String username) {
EntityAudit audit = new EntityAudit();
audit.setOwnerUsername(username);
audit.setModificationDate(DateUtil.nowUTC());
audit.setVersion(entity.getEntityVersion());
audit.setName(entity.getName());
audit.setClassName(entity.getClassName());
audit.setNamespace(entity.getNamespace());
audit.setTableName(entity.getTableName());
audit.setModule(entity.getModule());
for (Field field : entity.getFields()) {
Field tmp = field.copy();
tmp.setId(null);
audit.addField(tmp);
}
for (Lookup lookup : entity.getLookups()) {
audit.addLookup(lookup.copy(entity.getFields()));
}
if (entity.getRestOptions() != null) {
RestOptions restOptions = entity.getRestOptions().copy();
restOptions.setEntity(audit);
audit.setRestOptions(restOptions);
}
if (entity.getTracking() != null) {
Tracking tracking = entity.getTracking().copy();
tracking.setEntity(audit);
audit.setTracking(tracking);
}
return create(audit);
}
use of org.motechproject.mds.domain.Lookup in project motech by motech.
the class EntitySchemaBuilder method build.
public Entity build() {
Entity entity = new Entity(clazz, module, namespace, null);
entity.setRestOptions(rest.build());
entity.getRestOptions().setEntity(entity);
entity.setTracking(auditing.build());
entity.getTracking().setEntity(entity);
Map<String, Field> fieldsMap = new HashMap<>();
for (FieldSchemaBuilder fieldBuilder : fields) {
Field field = fieldBuilder.build();
field.setEntity(entity);
field.setExposedViaRest(rest.fields.contains(field.getName()));
field.setUIDisplayable(browsing.fields.contains(field.getName()));
field.setUIDisplayPosition(Integer.valueOf(browsing.fields.indexOf(field.getName())).longValue());
field.setUIFilterable(browsing.filters.contains(field.getName()));
fieldsMap.put(field.getName(), field);
entity.addField(field);
}
for (LookupSchemaBuilder lookupBuilder : lookups) {
Lookup lookup = lookupBuilder.build();
lookup.setEntity(entity);
lookup.setExposedViaRest(rest.lookups.contains(lookup.getLookupName()));
setLookupFields(lookup, lookupBuilder, fieldsMap);
entity.addLookup(lookup);
}
return entity;
}
use of org.motechproject.mds.domain.Lookup 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.Lookup 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();
}
}
}
Aggregations