use of org.motechproject.mds.dto.EntityDto 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);
}
}
use of org.motechproject.mds.dto.EntityDto in project motech by motech.
the class InstanceServiceImpl method countTrashRecords.
@Override
public long countTrashRecords(Long entityId) {
EntityDto entity = getEntity(entityId);
validateCredentialsForReading(entity);
return trashService.countTrashRecords(entity.getClassName());
}
use of org.motechproject.mds.dto.EntityDto in project motech by motech.
the class InstanceServiceImpl method deleteSelectedInstances.
@Override
public void deleteSelectedInstances(Long entityId, List<Long> instanceIds) {
EntityDto entity = getEntity(entityId);
validateCredentials(entity);
validateNonEditableProperty(entity);
MotechDataService service = getServiceForEntity(entity);
for (Long instanceId : instanceIds) {
service.delete(ID_FIELD_NAME, instanceId);
}
}
use of org.motechproject.mds.dto.EntityDto in project motech by motech.
the class InstanceServiceImpl method countRecords.
@Override
public long countRecords(Long entityId) {
EntityDto entity = getEntity(entityId);
validateCredentialsForReading(entity);
MotechDataService service = getServiceForEntity(entity);
return service.count();
}
use of org.motechproject.mds.dto.EntityDto in project motech by motech.
the class MdsDdeBundleIT method shouldLoadLookupsFromFile.
@Test
public void shouldLoadLookupsFromFile() {
Entry entryOne = new Entry();
entryOne.setValue("someValue");
entryDataService.create(entryOne);
Entry entryTwo = new Entry();
entryTwo.setValue("someValueTwo");
entryDataService.create(entryTwo);
EntityDto entity = entityService.getEntityByClassName("org.motechproject.mds.test.domain.editablelookups.Entry");
List<LookupDto> lookups = entityService.getEntityLookups(entity.getId());
assertEquals(1, lookups.size());
assertEquals("Find by Value", lookups.get(0).getLookupName());
Map<String, String> params = new HashMap<>();
params.put("value", entryOne.getValue());
List<Entry> lookupResult = lookupService.findMany(entity.getClassName(), lookups.get(0).getLookupName(), params);
assertEquals(1, lookupResult.size());
assertEquals(entryOne.getValue(), lookupResult.get(0).getValue());
}
Aggregations