Search in sources :

Example 1 with BasicHistoryRecord

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;
}
Also used : QueryParams(org.motechproject.mds.query.QueryParams) BasicHistoryRecord(org.motechproject.mds.web.domain.BasicHistoryRecord) Records(org.motechproject.mds.web.domain.Records) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with BasicHistoryRecord

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());
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) BasicHistoryRecord(org.motechproject.mds.web.domain.BasicHistoryRecord) BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 3 with BasicHistoryRecord

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;
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BasicHistoryRecord(org.motechproject.mds.web.domain.BasicHistoryRecord) MotechDataService(org.motechproject.mds.service.MotechDataService)

Aggregations

BasicHistoryRecord (org.motechproject.mds.web.domain.BasicHistoryRecord)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 EntityDto (org.motechproject.mds.dto.EntityDto)1 FieldDto (org.motechproject.mds.dto.FieldDto)1 QueryParams (org.motechproject.mds.query.QueryParams)1 MotechDataService (org.motechproject.mds.service.MotechDataService)1 BasicEntityRecord (org.motechproject.mds.web.domain.BasicEntityRecord)1 Records (org.motechproject.mds.web.domain.Records)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1