Search in sources :

Example 21 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class InstanceServiceImpl method buildRelatedInstances.

private Object buildRelatedInstances(MotechDataService service, Class<?> parameterType, Class<?> argumentType, Object fieldValue, Object relatedObject) throws IllegalAccessException, InstantiationException, ClassNotFoundException, NoSuchMethodException, CannotCompileException, NoSuchFieldException {
    Object parsedValue;
    RelationshipsUpdate relationshipsUpdate = mapper.convertValue(fieldValue, RelationshipsUpdate.class);
    EntityDto relatedEntity = getEntity(argumentType.getName());
    List<FieldDto> entityFields = getEntityFields(relatedEntity.getId());
    if (Collection.class.isAssignableFrom(parameterType)) {
        parsedValue = parseRelationshipCollection(service, (Class<? extends Collection>) parameterType, argumentType, (Collection) relatedObject, relationshipsUpdate, entityFields);
    } else {
        parsedValue = parseRelationshipValue(service, argumentType, relationshipsUpdate, entityFields);
    }
    return parsedValue;
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) RelationshipsUpdate(org.motechproject.mds.web.domain.RelationshipsUpdate) Collection(java.util.Collection) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 22 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class InstanceServiceImpl method getInstanceField.

@Override
public Object getInstanceField(Long entityId, Long instanceId, String fieldName) throws InstanceNotFoundException {
    EntityDto entity = getEntity(entityId);
    MotechDataService service = getServiceForEntity(entity);
    validateCredentialsForReading(entity);
    Object instance = service.findById(instanceId);
    if (instance == null) {
        throw new InstanceNotFoundException(String.format("Cannot find instance with id: %d", instanceId));
    }
    return service.getDetachedField(instance, fieldName);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) InstanceNotFoundException(javax.management.InstanceNotFoundException) MotechDataService(org.motechproject.mds.service.MotechDataService)

Example 23 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class InstanceServiceImpl method countRecordsWithFilters.

@Override
public long countRecordsWithFilters(Long entityId, Filters filters) {
    EntityDto entity = getEntity(entityId);
    validateCredentialsForReading(entity);
    MotechDataService service = getServiceForEntity(entity);
    return service.countForFilters(filters);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) MotechDataService(org.motechproject.mds.service.MotechDataService)

Example 24 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class InstanceServiceImpl method deleteAllInstances.

@Override
public void deleteAllInstances(Long entityId) {
    EntityDto entity = getEntity(entityId);
    validateCredentials(entity);
    validateNonEditableProperty(entity);
    MotechDataService service = getServiceForEntity(entity);
    service.deleteAll();
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) MotechDataService(org.motechproject.mds.service.MotechDataService)

Example 25 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class InstanceServiceImpl method revertInstanceFromTrash.

@Override
public void revertInstanceFromTrash(Long entityId, Long instanceId) {
    EntityDto entity = getEntity(entityId);
    validateCredentials(entity);
    validateNonEditableProperty(entity);
    MotechDataService service = getServiceForEntity(entity);
    service.revertFromTrash(instanceId);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) MotechDataService(org.motechproject.mds.service.MotechDataService)

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