use of org.motechproject.mds.exception.lookup.LookupExecutionException in project motech by motech.
the class InstanceServiceImpl method countRecordsByLookup.
@Override
public long countRecordsByLookup(Long entityId, String lookupName, Map<String, Object> lookupMap) {
EntityDto entity = getEntity(entityId);
validateCredentialsForReading(entity);
LookupDto lookup = getLookupByName(entityId, lookupName);
Map<String, FieldDto> fieldMap = entityService.getLookupFieldsMapping(entityId, lookupName);
MotechDataService service = getServiceForEntity(entity);
try {
LookupExecutor lookupExecutor = new LookupExecutor(service, lookup, fieldMap);
return lookupExecutor.executeCount(lookupMap);
} catch (RuntimeException e) {
throw new LookupExecutionException(e, LOOKUP_EXCEPTION_MESSAGE_KEY);
}
}
use of org.motechproject.mds.exception.lookup.LookupExecutionException in project motech by motech.
the class InstanceServiceImpl method getEntityRecordsFromLookup.
@Override
public List<BasicEntityRecord> getEntityRecordsFromLookup(Long entityId, String lookupName, Map<String, Object> lookupMap, QueryParams queryParams) {
EntityDto entity = getEntity(entityId);
validateCredentialsForReading(entity);
LookupDto lookup = getLookupByName(entityId, lookupName);
List<FieldDto> fields = entityService.getEntityFieldsForUI(entityId);
Map<String, FieldDto> fieldMap = entityService.getLookupFieldsMapping(entityId, lookupName);
MotechDataService service = getServiceForEntity(entity);
try {
LookupExecutor lookupExecutor = new LookupExecutor(service, lookup, fieldMap);
Object result = lookupExecutor.execute(lookupMap, queryParams);
if (lookup.isSingleObjectReturn()) {
BasicEntityRecord record = instanceToBasicRecord(result, entity, fields, service, EntityType.STANDARD, getRelatedEntitiesFields(fields));
return (record == null) ? new ArrayList<BasicEntityRecord>() : Collections.singletonList(record);
} else {
List instances = (List) result;
return instancesToBasicRecords(instances, entity, fields, service, EntityType.STANDARD);
}
} catch (LookupExecutorException e) {
if (e.getMessageKey() != null) {
throw new LookupExecutionException(e, e.getMessageKey());
} else {
throw new LookupExecutionException(e, LOOKUP_EXCEPTION_MESSAGE_KEY);
}
} catch (RuntimeException e) {
throw new LookupExecutionException(e, LOOKUP_EXCEPTION_MESSAGE_KEY);
}
}
Aggregations