Search in sources :

Example 1 with HistoryRecord

use of org.motechproject.mds.web.domain.HistoryRecord in project motech by motech.

the class InstanceController method getPreviousInstance.

@RequestMapping(value = "/instances/{entityId}/{instanceId}/previousVersion/{historyId}", method = RequestMethod.GET)
@ResponseBody
public HistoryRecord getPreviousInstance(@PathVariable Long entityId, @PathVariable Long instanceId, @PathVariable Long historyId) {
    HistoryRecord historyRecord = instanceService.getHistoryRecord(entityId, instanceId, historyId);
    if (historyRecord == null) {
        throw new EntityNotFoundException(entityId);
    }
    processFieldsForUIInHistoryRecord(historyRecord.getFields());
    return historyRecord;
}
Also used : EntityNotFoundException(org.motechproject.mds.exception.entity.EntityNotFoundException) BasicHistoryRecord(org.motechproject.mds.web.domain.BasicHistoryRecord) HistoryRecord(org.motechproject.mds.web.domain.HistoryRecord) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with HistoryRecord

use of org.motechproject.mds.web.domain.HistoryRecord in project motech by motech.

the class InstanceServiceImpl method convertToHistoryRecord.

private HistoryRecord convertToHistoryRecord(Object object, EntityDto entity, Long instanceId, MotechDataService service) {
    Long entityId = entity.getId();
    List<FieldDto> fields = getEntityFields(entityId);
    Map<String, List<FieldDto>> relatedEntitiesFields = getRelatedEntitiesFields(fields);
    EntityRecord entityRecord = instanceToRecord(object, entity, entityService.getEntityFieldsForUI(entityId), service, EntityType.HISTORY, relatedEntitiesFields);
    Long historyInstanceSchemaVersion = (Long) PropertyUtil.safeGetProperty(object, HistoryTrashClassHelper.historySchemaVersion(object.getClass()));
    Long currentSchemaVersion = entityService.getCurrentSchemaVersion(entity.getClassName());
    return new HistoryRecord(entityRecord.getId(), instanceId, historyInstanceSchemaVersion.equals(currentSchemaVersion), entityRecord.getFields());
}
Also used : EntityRecord(org.motechproject.mds.web.domain.EntityRecord) BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) ArrayList(java.util.ArrayList) List(java.util.List) BasicHistoryRecord(org.motechproject.mds.web.domain.BasicHistoryRecord) HistoryRecord(org.motechproject.mds.web.domain.HistoryRecord) FieldDto(org.motechproject.mds.dto.FieldDto)

Aggregations

BasicHistoryRecord (org.motechproject.mds.web.domain.BasicHistoryRecord)2 HistoryRecord (org.motechproject.mds.web.domain.HistoryRecord)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 FieldDto (org.motechproject.mds.dto.FieldDto)1 EntityNotFoundException (org.motechproject.mds.exception.entity.EntityNotFoundException)1 BasicEntityRecord (org.motechproject.mds.web.domain.BasicEntityRecord)1 EntityRecord (org.motechproject.mds.web.domain.EntityRecord)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1