use of org.motechproject.mds.dto.EntityDto in project motech by motech.
the class InstanceServiceImpl method verifyEntityAccess.
@Override
public void verifyEntityAccess(Long entityId) {
EntityDto entity = getEntity(entityId);
validateCredentialsForReading(entity);
}
use of org.motechproject.mds.dto.EntityDto in project motech by motech.
the class InstanceServiceImpl method saveInstance.
@Override
@Transactional
public Object saveInstance(EntityRecord entityRecord, Long deleteValueFieldId) {
EntityDto entity = getEntity(entityRecord.getEntitySchemaId());
validateCredentials(entity);
validateNonEditableProperty(entity);
List<FieldDto> entityFields = getEntityFields(entityRecord.getEntitySchemaId());
try {
MotechDataService service = getServiceForEntity(entity);
Class<?> entityClass = getEntityClass(entity);
boolean newObject = entityRecord.getId() == null;
Object instance;
if (newObject) {
instance = newInstanceFromEntityRecord(entityClass, entityFields, entityRecord.getFields(), service);
return service.create(instance);
} else {
instance = service.retrieve(ID_FIELD_NAME, entityRecord.getId());
if (instance == null) {
throw new ObjectNotFoundException(entity.getName(), entityRecord.getId());
}
updateFields(instance, entityRecord.getFields(), service, deleteValueFieldId, true);
return service.update(instance);
}
} catch (Exception e) {
if (entityRecord.getId() == null) {
throw new ObjectCreateException(entity.getName(), e);
} else {
throw new ObjectUpdateException(entity.getName(), entityRecord.getId(), e);
}
}
}
use of org.motechproject.mds.dto.EntityDto in project motech by motech.
the class InstanceServiceImpl method revertPreviousVersion.
@Override
public void revertPreviousVersion(Long entityId, Long instanceId, Long historyId) {
validateNonEditableProperty(entityId);
EntityDto entity = getEntity(entityId);
MotechDataService service = getServiceForEntity(entity);
service.revertToHistoricalRevision(instanceId, historyId);
}
use of org.motechproject.mds.dto.EntityDto in project motech by motech.
the class InstanceServiceImpl method getInstanceFields.
@Override
public List<FieldInstanceDto> getInstanceFields(Long entityId, Long instanceId) {
EntityDto entity = entityService.getEntity(entityId);
validateCredentialsForReading(entity);
List<FieldDto> fields = entityService.getEntityFieldsForUI(entityId);
List<FieldInstanceDto> result = new ArrayList<>();
for (FieldDto field : fields) {
FieldInstanceDto fieldInstanceDto = new FieldInstanceDto(field.getId(), instanceId, field.getBasic());
result.add(fieldInstanceDto);
}
return result;
}
use of org.motechproject.mds.dto.EntityDto in project motech by motech.
the class InstanceServiceImpl method getHistoryRecord.
@Override
public HistoryRecord getHistoryRecord(Long entityId, Long instanceId, Long historyId) {
EntityDto entity = getEntity(entityId);
validateCredentialsForReading(entity);
MotechDataService service = getServiceForEntity(entity);
Object instance = service.retrieve(ID_FIELD_NAME, instanceId);
Object historyInstance = historyService.getSingleHistoryInstance(instance, historyId);
return convertToHistoryRecord(historyInstance, entity, instanceId, service);
}
Aggregations