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;
}
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;
}
}
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;
}
}
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;
}
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;
}
Aggregations