use of org.motechproject.mds.lookup.LookupExecutor in project motech by motech.
the class MdsLookupServiceImpl method findMany.
@Override
public <T> List<T> findMany(String entityClassName, String lookupName, Map<String, ?> lookupParams, QueryParams queryParams) {
LookupExecutor lookupExecutor = buildLookupExecutor(entityClassName, lookupName);
Object result = lookupExecutor.execute(lookupParams, queryParams);
return returnListResult(result);
}
use of org.motechproject.mds.lookup.LookupExecutor in project motech by motech.
the class MDSDataProvider method findUsingLookup.
private Object findUsingLookup(String type, String lookupName, Map<String, String> lookupMap) {
Object obj = null;
LookupDto lookup = null;
EntityDto entity = entityService.getEntityByClassName(type);
if (entity != null) {
lookup = entityService.getLookupByName(entity.getId(), lookupName);
}
if (entity != null && lookup != null) {
String serviceName = MotechClassPool.getInterfaceName(type);
MotechDataService service = OSGiServiceUtils.findService(bundleContext, serviceName);
if (service != null) {
Map<String, FieldDto> fieldsByName = entityService.getLookupFieldsMapping(entity.getId(), lookupName);
LookupExecutor executor = new LookupExecutor(service, lookup, fieldsByName);
obj = executor.execute(lookupMap);
} else {
getLogger().error("Service %s not found", serviceName);
}
}
// we allow executing lookups that return multiple objects
// if such a lookup returns more then 1 object we throw an exception
Object result = null;
if (obj instanceof Collection) {
Collection collection = (Collection) obj;
if (collection.size() == 1) {
result = collection.iterator().next();
} else if (collection.size() > 1) {
throw new IllegalArgumentException(String.format("Data provided lookup for %s returned more then 1 object, number of objects found: %d", type, collection.size()));
}
} else {
result = obj;
}
return result;
}
use of org.motechproject.mds.lookup.LookupExecutor in project motech by motech.
the class MdsRestFacadeImpl method readLookups.
private void readLookups(EntityInfo entity) {
for (LookupDto lookup : entity.getLookups()) {
Map<String, FieldDto> fieldMap = getLookupFieldsMapping(entity, lookup);
String lookuMethodpName = lookup.getMethodName();
if (lookup.isExposedViaRest()) {
// we create executors for exposed lookups
LookupExecutor executor = new LookupExecutor(dataService, lookup, fieldMap);
lookupExecutors.put(lookuMethodpName, executor);
} else {
// we keep a list of forbidden lookups in order to print the appropriate error
forbiddenLookupMethodNames.add(lookuMethodpName);
}
}
}
Aggregations