use of org.motechproject.mds.web.domain.BasicHistoryRecord in project motech by motech.
the class InstanceController method getHistory.
@RequestMapping(value = "/instances/{entityId}/{instanceId}/history", method = RequestMethod.GET)
@ResponseBody
public Records<BasicHistoryRecord> getHistory(@PathVariable Long entityId, @PathVariable Long instanceId, GridSettings settings) {
QueryParams queryParams = QueryParamsBuilder.buildQueryParams(settings);
List<BasicHistoryRecord> historyRecordsList = instanceService.getInstanceHistory(entityId, instanceId, queryParams);
long recordCount = instanceService.countHistoryRecords(entityId, instanceId);
int rowCount = (int) Math.ceil(recordCount / (double) queryParams.getPageSize());
Records<BasicHistoryRecord> records = new Records<>(queryParams.getPage(), rowCount, (int) recordCount, historyRecordsList);
processFieldsForUIinHistoryRecords(records);
return records;
}
use of org.motechproject.mds.web.domain.BasicHistoryRecord in project motech by motech.
the class InstanceServiceImpl method convertToBasicHistoryRecord.
private BasicHistoryRecord convertToBasicHistoryRecord(Object object, EntityDto entity, Long instanceId, MotechDataService service) {
Long entityId = entity.getId();
List<FieldDto> fields = getEntityFields(entityId);
Map<String, List<FieldDto>> relatedEntitiesFields = getRelatedEntitiesFields(fields);
BasicEntityRecord entityRecord = instanceToBasicRecord(object, entity, entityService.getEntityFields(entityId), service, EntityType.HISTORY, relatedEntitiesFields);
Long historyInstanceSchemaVersion = (Long) PropertyUtil.safeGetProperty(object, HistoryTrashClassHelper.historySchemaVersion(object.getClass()));
Long currentSchemaVersion = entityService.getCurrentSchemaVersion(entity.getClassName());
return new BasicHistoryRecord(entityRecord.getId(), instanceId, historyInstanceSchemaVersion.equals(currentSchemaVersion), entityRecord.getFields());
}
use of org.motechproject.mds.web.domain.BasicHistoryRecord in project motech by motech.
the class InstanceServiceImpl method getInstanceHistory.
@Override
public List<BasicHistoryRecord> getInstanceHistory(Long entityId, Long instanceId, QueryParams queryParams) {
EntityDto entity = getEntity(entityId);
validateCredentialsForReading(entity);
MotechDataService service = getServiceForEntity(entity);
Object instance = service.retrieve(ID_FIELD_NAME, instanceId);
List history = historyService.getHistoryForInstance(instance, queryParams);
updateGridSize(entityId, queryParams);
List<BasicHistoryRecord> result = new ArrayList<>();
for (Object o : history) {
result.add(convertToBasicHistoryRecord(o, entity, instanceId, service));
}
return result;
}
Aggregations