Search in sources :

Example 81 with CollectRecord

use of org.openforis.collect.model.CollectRecord in project collect by openforis.

the class NodeCommandHandler method findParentEntity.

protected Entity findParentEntity(NodeCommand command) {
    CollectRecord record = findRecord(command);
    Entity parentEntity = record.findNodeByPath(command.getParentEntityPath());
    return parentEntity;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity)

Example 82 with CollectRecord

use of org.openforis.collect.model.CollectRecord in project collect by openforis.

the class SpecifiedValidator method evaluate.

@Override
public ValidationResultFlag evaluate(Attribute<?, ?> attribute) {
    CollectRecord record = (CollectRecord) attribute.getRecord();
    Step step = record.getStep();
    if (Step.ENTRY == step) {
        if (attribute.isRelevant() && attribute.isEmpty() && !(attribute instanceof FileAttribute)) {
            if (isReasonBlankAlwaysSpecified(attribute)) {
                if (attribute.isRequired()) {
                    return WARNING;
                } else {
                    return OK;
                }
            } else {
                return ERROR;
            }
        } else {
            return OK;
        }
    }
    return OK;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Step(org.openforis.collect.model.CollectRecord.Step) FileAttribute(org.openforis.idm.model.FileAttribute)

Example 83 with CollectRecord

use of org.openforis.collect.model.CollectRecord in project collect by openforis.

the class RecordDao method fromQueryResult.

public CollectRecord fromQueryResult(CollectSurvey survey, Record r, boolean recordToBeUpdated) {
    int rootEntityId = r.getValue(OFC_RECORD.ROOT_ENTITY_DEFINITION_ID);
    String version = r.getValue(OFC_RECORD.MODEL_VERSION);
    Schema schema = survey.getSchema();
    EntityDefinition rootEntityDefn = schema.getDefinitionById(rootEntityId);
    CollectRecord c = new CollectRecord(survey, version, rootEntityDefn, recordToBeUpdated);
    c.setId(r.getValue(OFC_RECORD.ID));
    c.setStep(Step.valueOf(r.getValue(OFC_RECORD.STEP)));
    c.setWorkflowSequenceNumber(r.getValue(OFC_RECORD.DATA_SEQ_NUM));
    c.setCreationDate(r.getValue(OFC_RECORD.DATE_CREATED));
    c.setModifiedDate(r.getValue(OFC_RECORD.DATE_MODIFIED));
    c.setCreatedBy(createDetachedUser(r.getValue(OFC_RECORD.CREATED_BY_ID)));
    c.setModifiedBy(createDetachedUser(r.getValue(OFC_RECORD.MODIFIED_BY_ID)));
    c.setWarnings(r.getValue(OFC_RECORD.WARNINGS));
    c.setErrors(r.getValue(OFC_RECORD.ERRORS));
    c.setSkipped(r.getValue(OFC_RECORD.SKIPPED));
    c.setMissing(r.getValue(OFC_RECORD.MISSING));
    c.setOwner(createDetachedUser(r.getValue(OFC_RECORD.OWNER_ID)));
    c.setDataStep(Step.valueOf(r.getValue(OFC_RECORD_DATA.STEP)));
    c.setDataWorkflowSequenceNumber(r.getValue(OFC_RECORD_DATA.SEQ_NUM));
    c.setDataCreationDate(r.getValue(OFC_RECORD_DATA.DATE_CREATED));
    c.setDataModifiedDate(r.getValue(OFC_RECORD_DATA.DATE_MODIFIED));
    c.setDataCreatedBy(createDetachedUser(r.getValue(OFC_RECORD_DATA.CREATED_BY)));
    c.setDataModifiedBy(createDetachedUser(r.getValue(OFC_RECORD_DATA.MODIFIED_BY)));
    c.setDataRootEntityKeyValues(getFieldValues(r, rootEntityDefn.getKeyAttributeDefinitions(), RECORD_DATA_KEY_FIELDS, String.class));
    c.setDataEntityCounts(getFieldValues(r, schema.getCountableEntitiesInRecordList(rootEntityDefn), RECORD_DATA_COUNT_FIELDS, Integer.class));
    c.setDataQualifierValues(getFieldValues(r, schema.getQualifierAttributeDefinitions(rootEntityDefn), RECORD_DATA_QUALIFIER_FIELDS, String.class));
    c.setDataSummaryValues(getFieldValues(r, schema.getSummaryAttributeDefinitions(rootEntityDefn), RECORD_DATA_SUMMARY_FIELDS, String.class));
    String state = r.getValue(OFC_RECORD.STATE);
    c.setState(state == null ? null : State.fromCode(state));
    c.setApplicationVersion(new Version(r.getValue(OFC_RECORD_DATA.APP_VERSION)));
    byte[] data = r.getValue(OFC_RECORD_DATA.DATA);
    ModelSerializer modelSerializer = new ModelSerializer(SERIALIZATION_BUFFER_SIZE);
    Entity rootEntity = c.getRootEntity();
    modelSerializer.mergeFrom(data, rootEntity);
    c.setRootEntityKeyValues(getFieldValues(r, rootEntityDefn.getKeyAttributeDefinitions(), RECORD_KEY_FIELDS, String.class));
    c.setEntityCounts(getFieldValues(r, schema.getCountableEntitiesInRecordList(rootEntityDefn), RECORD_COUNT_FIELDS, Integer.class));
    c.setQualifierValues(getFieldValues(r, schema.getQualifierAttributeDefinitions(rootEntityDefn), RECORD_QUALIFIER_FIELDS, String.class));
    c.setSummaryValues(getFieldValues(r, schema.getSummaryAttributeDefinitions(rootEntityDefn), RECORD_SUMMARY_FIELDS, String.class));
    return c;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) Version(org.openforis.commons.versioning.Version) ModelVersion(org.openforis.idm.metamodel.ModelVersion) Schema(org.openforis.idm.metamodel.Schema) ModelSerializer(org.openforis.idm.model.ModelSerializer)

Example 84 with CollectRecord

use of org.openforis.collect.model.CollectRecord in project collect by openforis.

the class DataUnmarshaller method parse.

private ParseRecordResult parse(InputSource source) throws IOException {
    ParseRecordResult result = new ParseRecordResult();
    try {
        reader.parse(source);
        List<NodeUnmarshallingError> failures = dataHandler.getFailures();
        if (failures.isEmpty()) {
            CollectRecord record = dataHandler.getRecord();
            result.setRecord(record);
            List<NodeUnmarshallingError> warns = dataHandler.getWarnings();
            if (!warns.isEmpty()) {
                result.setMessage("Processed with errors: " + warns.toString());
                result.setWarnings(warns);
            }
            result.setSuccess(true);
        } else {
            result.setFailures(failures);
        }
    } catch (SAXException e) {
        NodeUnmarshallingError error = new NodeUnmarshallingError(e.toString());
        result.setFailures(Arrays.asList(error));
    }
    return result;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) SAXException(org.xml.sax.SAXException)

Example 85 with CollectRecord

use of org.openforis.collect.model.CollectRecord in project collect by openforis.

the class DataReportManager method loadItems.

public List<DataReportItem> loadItems(DataReport report, Integer offset, Integer limit) {
    CollectSurvey survey = report.getSurvey();
    Map<Integer, CollectRecord> recordCache = new HashMap<Integer, CollectRecord>();
    List<DataReportItem> items = dataReportItemDao.loadByReport(report, offset, limit);
    for (DataReportItem item : items) {
        int recordId = item.getRecordId();
        CollectRecord record = recordCache.get(recordId);
        if (record == null) {
            record = recordManager.load(survey, recordId, report.getRecordStep(), false);
            recordCache.put(recordId, record);
        }
        item.setRecord(record);
    }
    return items;
}
Also used : DataReportItem(org.openforis.collect.datacleansing.DataReportItem) CollectRecord(org.openforis.collect.model.CollectRecord) HashMap(java.util.HashMap) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Aggregations

CollectRecord (org.openforis.collect.model.CollectRecord)141 Entity (org.openforis.idm.model.Entity)36 Test (org.junit.Test)30 CollectSurvey (org.openforis.collect.model.CollectSurvey)29 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)29 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)27 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)24 Step (org.openforis.collect.model.CollectRecord.Step)23 User (org.openforis.collect.model.User)19 SessionState (org.openforis.collect.web.session.SessionState)15 RecordFilter (org.openforis.collect.model.RecordFilter)14 Transactional (org.springframework.transaction.annotation.Transactional)14 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)12 Secured (org.springframework.security.access.annotation.Secured)12 ArrayList (java.util.ArrayList)11 Date (org.openforis.idm.model.Date)10 GregorianCalendar (java.util.GregorianCalendar)9 Code (org.openforis.idm.model.Code)9 RealAttribute (org.openforis.idm.model.RealAttribute)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9