Search in sources :

Example 76 with EntityDto

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);
    }
}
Also used : LookupDto(org.motechproject.mds.dto.LookupDto) LookupExecutor(org.motechproject.mds.lookup.LookupExecutor) BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) MotechDataService(org.motechproject.mds.service.MotechDataService) EntityDto(org.motechproject.mds.dto.EntityDto) ArrayList(java.util.ArrayList) List(java.util.List) LookupExecutionException(org.motechproject.mds.exception.lookup.LookupExecutionException) FieldDto(org.motechproject.mds.dto.FieldDto) LookupExecutorException(org.motechproject.mds.exception.lookup.LookupExecutorException)

Example 77 with EntityDto

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());
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto)

Example 78 with EntityDto

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);
    }
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) MotechDataService(org.motechproject.mds.service.MotechDataService)

Example 79 with EntityDto

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();
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) MotechDataService(org.motechproject.mds.service.MotechDataService)

Example 80 with EntityDto

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());
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) Entry(org.motechproject.mds.test.domain.editablelookups.Entry) HashMap(java.util.HashMap) LookupDto(org.motechproject.mds.dto.LookupDto) Test(org.junit.Test)

Aggregations

EntityDto (org.motechproject.mds.dto.EntityDto)136 Test (org.junit.Test)61 FieldDto (org.motechproject.mds.dto.FieldDto)53 ArrayList (java.util.ArrayList)34 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)32 MotechDataService (org.motechproject.mds.service.MotechDataService)26 LookupDto (org.motechproject.mds.dto.LookupDto)24 List (java.util.List)19 BasicEntityRecord (org.motechproject.mds.web.domain.BasicEntityRecord)12 Method (java.lang.reflect.Method)11 FieldTestHelper.lookupFieldDto (org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto)11 Arrays.asList (java.util.Arrays.asList)9 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)9 EntityRecord (org.motechproject.mds.web.domain.EntityRecord)9 AdvancedSettingsDto (org.motechproject.mds.dto.AdvancedSettingsDto)7 TypeDto (org.motechproject.mds.dto.TypeDto)7 HashMap (java.util.HashMap)6 SchemaHolder (org.motechproject.mds.dto.SchemaHolder)6 BasicFieldRecord (org.motechproject.mds.web.domain.BasicFieldRecord)6 FieldRecord (org.motechproject.mds.web.domain.FieldRecord)6