Search in sources :

Example 1 with EntityDefinition

use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.

the class ValidationMessageBuilder method getMaxCountValidationMessage.

public String getMaxCountValidationMessage(Entity parentEntity, String childName, Locale locale) {
    EntityDefinition defn = parentEntity.getDefinition();
    NodeDefinition childDefn = defn.getChildDefinition(childName);
    Integer maxCount = parentEntity.getMaxCount(childDefn);
    Object[] args = new Integer[] { maxCount > 0 ? maxCount : 1 };
    String surveyDefaultLanguage = defn.getSurvey().getDefaultLanguage();
    String message = getMessage(surveyDefaultLanguage, locale, "validation.maxCount", args);
    return message;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 2 with EntityDefinition

use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.

the class ValidationMessageBuilder method getMessageArgs.

protected String[] getMessageArgs(Attribute<?, ?> attribute, ValidationResult validationResult, Locale locale) {
    ValidationRule<?> validator = validationResult.getValidator();
    if (validator instanceof ComparisonCheck) {
        ComparisonCheck check = (ComparisonCheck) validator;
        ArrayList<String> args = new ArrayList<String>();
        String labelText = getPrettyLabelText(attribute.getDefinition(), locale);
        args.add(labelText);
        Map<String, String> expressions = new HashMap<String, String>();
        expressions.put("lt", check.getLessThanExpression());
        expressions.put("lte", check.getLessThanOrEqualsExpression());
        expressions.put("gt", check.getGreaterThanExpression());
        expressions.put("gte", check.getGreaterThanOrEqualsExpression());
        for (String key : expressions.keySet()) {
            String expression = expressions.get(key);
            if (expression != null) {
                String argPart1 = key;
                String argPart2 = getComparisonCheckMessageArg(attribute, expression, locale);
                String arg = StringUtils.join(argPart1, MULTIPLE_MESSAGE_ARGS_SEPARATOR, argPart2);
                args.add(arg);
            }
        }
        return args.toArray(new String[args.size()]);
    } else if (validator instanceof EntityKeyValidator) {
        EntityDefinition parentDefn = attribute.getDefinition().getParentEntityDefinition();
        String parentLabel = getPrettyLabelText(parentDefn, locale.getLanguage());
        List<AttributeDefinition> keyDefns = parentDefn.getKeyAttributeDefinitions();
        List<String> keyDefnLabels = new ArrayList<String>(keyDefns.size());
        for (AttributeDefinition keyDefn : keyDefns) {
            keyDefnLabels.add(getPrettyLabelText(keyDefn, locale.getLanguage()));
        }
        // TODO localize separator
        return new String[] { parentLabel, StringUtils.join(keyDefnLabels, ", ") };
    } else {
        return null;
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) HashMap(java.util.HashMap) ComparisonCheck(org.openforis.idm.metamodel.validation.ComparisonCheck) ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) EntityKeyValidator(org.openforis.idm.metamodel.validation.EntityKeyValidator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with EntityDefinition

use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.

the class ValidationMessageBuilder method getKeyText.

public String getKeyText(Entity entity, Locale locale) {
    EntityDefinition defn = entity.getDefinition();
    List<AttributeDefinition> keyDefns = defn.getKeyAttributeDefinitions();
    if (!keyDefns.isEmpty()) {
        List<String> shortKeyParts = new ArrayList<String>();
        List<String> fullKeyParts = new ArrayList<String>();
        for (AttributeDefinition keyDefn : keyDefns) {
            Attribute<?, ?> keyAttr = (Attribute<?, ?>) entity.getChild(keyDefn, 0);
            if (keyAttr != null) {
                Object keyValue = getKeyLabelPart(keyAttr);
                if (keyValue != null && StringUtils.isNotBlank(keyValue.toString())) {
                    shortKeyParts.add(keyValue.toString());
                    String label = getPrettyLabelText(keyDefn, locale);
                    String fullKeyPart = label + " " + keyValue;
                    fullKeyParts.add(fullKeyPart);
                }
            }
        }
        return StringUtils.join(shortKeyParts, RECORD_KEYS_LABEL_SEPARATOR);
    } else if (entity.getParent() != null) {
        return "" + (entity.getIndex() + 1);
    } else {
        return null;
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Attribute(org.openforis.idm.model.Attribute) TaxonAttribute(org.openforis.idm.model.TaxonAttribute) ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

Example 4 with EntityDefinition

use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.

the class RecordDao method fromSummaryQueryRecord.

public CollectRecordSummary fromSummaryQueryRecord(CollectSurvey survey, Record r) {
    int rootEntityDefId = r.getValue(OFC_RECORD.ROOT_ENTITY_DEFINITION_ID);
    String versionName = r.getValue(OFC_RECORD.MODEL_VERSION);
    ModelVersion modelVersion = versionName == null ? null : survey.getVersion(versionName);
    CollectRecordSummary s = new CollectRecordSummary();
    s.setSurvey(survey);
    s.setVersion(modelVersion);
    s.setRootEntityDefinitionId(rootEntityDefId);
    s.setId(r.getValue(OFC_RECORD.ID));
    s.setOwner(createDetachedUser(r.getValue(OFC_RECORD.OWNER_ID)));
    Step step = Step.valueOf(r.getValue(OFC_RECORD.STEP));
    s.setStep(step);
    s.setWorkflowSequenceNumber(r.getValue(OFC_RECORD.DATA_SEQ_NUM));
    s.setCreationDate(r.getValue(OFC_RECORD.DATE_CREATED));
    s.setModifiedDate(r.getValue(OFC_RECORD.DATE_MODIFIED));
    s.setCreatedBy(createDetachedUser(r.getValue(OFC_RECORD.CREATED_BY_ID)));
    s.setModifiedBy(createDetachedUser(r.getValue(OFC_RECORD.MODIFIED_BY_ID)));
    StepSummary stepSummary = new StepSummary(step);
    stepSummary.setSequenceNumber(r.getValue(OFC_RECORD.DATA_SEQ_NUM));
    stepSummary.setErrors(r.getValue(OFC_RECORD.ERRORS));
    stepSummary.setWarnings(r.getValue(OFC_RECORD.WARNINGS));
    stepSummary.setSkipped(r.getValue(OFC_RECORD.SKIPPED));
    stepSummary.setMissing(r.getValue(OFC_RECORD.MISSING));
    int totalErrors = step == Step.ENTRY ? Numbers.sum(stepSummary.getErrors(), stepSummary.getSkipped()) : Numbers.sum(stepSummary.getErrors(), stepSummary.getMissingErrors());
    stepSummary.setTotalErrors(totalErrors);
    Schema schema = survey.getSchema();
    EntityDefinition rootEntityDef = schema.getRootEntityDefinition(rootEntityDefId);
    stepSummary.setRootEntityKeyValues(getFieldValues(r, rootEntityDef.getKeyAttributeDefinitions(), RECORD_KEY_FIELDS, String.class));
    stepSummary.setEntityCounts(getFieldValues(r, schema.getCountableEntitiesInRecordList(rootEntityDef), RECORD_COUNT_FIELDS, Integer.class));
    stepSummary.setQualifierValues(getFieldValues(r, schema.getQualifierAttributeDefinitions(rootEntityDef), RECORD_QUALIFIER_FIELDS, String.class));
    stepSummary.setSummaryValues(getFieldValues(r, schema.getSummaryAttributeDefinitions(rootEntityDef), RECORD_SUMMARY_FIELDS, String.class));
    String state = r.getValue(OFC_RECORD.STATE);
    stepSummary.setState(state == null ? null : State.fromCode(state));
    s.addStepSummary(stepSummary);
    return s;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) StepSummary(org.openforis.collect.model.CollectRecordSummary.StepSummary) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) Schema(org.openforis.idm.metamodel.Schema) ModelVersion(org.openforis.idm.metamodel.ModelVersion) Step(org.openforis.collect.model.CollectRecord.Step)

Example 5 with EntityDefinition

use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.

the class RecordDao method fromDataSummaryQueryRecord.

@SuppressWarnings("unchecked")
public StepSummary fromDataSummaryQueryRecord(Record r, CollectSurvey survey) {
    Step step = Step.valueOf(r.getValue(OFC_RECORD_DATA.STEP));
    StepSummary s = new StepSummary(step);
    s.setSequenceNumber(r.getValue(OFC_RECORD_DATA.SEQ_NUM));
    s.setCreationDate(r.getValue(OFC_RECORD_DATA.DATE_CREATED));
    s.setModifiedDate(r.getValue(OFC_RECORD_DATA.DATE_MODIFIED));
    s.setCreatedBy(createDetachedUser(r.getValue(OFC_RECORD_DATA.CREATED_BY)));
    s.setModifiedBy(createDetachedUser(r.getValue(OFC_RECORD_DATA.MODIFIED_BY)));
    s.setErrors(r.getValue(OFC_RECORD_DATA.ERRORS));
    s.setWarnings(r.getValue(OFC_RECORD_DATA.WARNINGS));
    s.setSkipped(r.getValue(OFC_RECORD_DATA.SKIPPED));
    s.setMissing(r.getValue(OFC_RECORD_DATA.MISSING));
    // create list of entity counts
    List<Integer> counts = new ArrayList<Integer>(RECORD_DATA_COUNT_FIELDS.length);
    for (TableField tableField : RECORD_DATA_COUNT_FIELDS) {
        counts.add((Integer) r.getValue(tableField));
    }
    s.setEntityCounts(counts);
    int rootEntityDefId = r.getValue(OFC_RECORD.ROOT_ENTITY_DEFINITION_ID);
    Schema schema = survey.getSchema();
    EntityDefinition rootEntityDef = schema.getRootEntityDefinition(rootEntityDefId);
    s.setRootEntityKeyValues(getFieldValues(r, rootEntityDef.getKeyAttributeDefinitions(), RECORD_DATA_KEY_FIELDS, String.class));
    s.setEntityCounts(getFieldValues(r, schema.getCountableEntitiesInRecordList(rootEntityDef), RECORD_DATA_COUNT_FIELDS, Integer.class));
    s.setQualifierValues(getFieldValues(r, schema.getQualifierAttributeDefinitions(rootEntityDef), RECORD_DATA_QUALIFIER_FIELDS, String.class));
    s.setSummaryValues(getFieldValues(r, schema.getSummaryAttributeDefinitions(rootEntityDef), RECORD_DATA_SUMMARY_FIELDS, String.class));
    String state = r.getValue(OFC_RECORD_DATA.STATE);
    s.setState(state == null ? null : State.fromCode(state));
    return s;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) StepSummary(org.openforis.collect.model.CollectRecordSummary.StepSummary) Schema(org.openforis.idm.metamodel.Schema) ArrayList(java.util.ArrayList) Step(org.openforis.collect.model.CollectRecord.Step) TableField(org.jooq.TableField)

Aggregations

EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)235 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)70 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)47 Schema (org.openforis.idm.metamodel.Schema)46 ArrayList (java.util.ArrayList)44 Test (org.junit.Test)38 Entity (org.openforis.idm.model.Entity)36 CollectRecord (org.openforis.collect.model.CollectRecord)30 CollectSurvey (org.openforis.collect.model.CollectSurvey)28 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)24 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)24 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)19 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)18 UITab (org.openforis.collect.metamodel.ui.UITab)16 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)14 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)13 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)12 RecordFilter (org.openforis.collect.model.RecordFilter)11 SurveyObject (org.openforis.idm.metamodel.SurveyObject)10 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)9