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;
}
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);
}
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);
}
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();
}
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);
}
Aggregations