use of org.openforis.idm.model.Entity in project collect by openforis.
the class CompositeAttributeColumnProvider method findNodesParentEntity.
private Entity findNodesParentEntity(Entity axis) {
List<EntityDefinition> ancestorEntityDefs = attributeDefinition.getAncestorEntityDefinitionsUpTo(axis.getDefinition());
Entity currentParentEntity = axis;
if (!ancestorEntityDefs.isEmpty()) {
for (int i = ancestorEntityDefs.size() - 1; i >= 0; i--) {
EntityDefinition ancestorEntityDef = ancestorEntityDefs.get(i);
if (ancestorEntityDef.isMultiple()) {
throw new IllegalStateException(String.format("Error extracting values for composite attribute %s in survey %s: single entity expected but multiple found: %s", attributeDefinition.getPath(), attributeDefinition.getSurvey().getName(), ancestorEntityDef.getPath()));
} else {
currentParentEntity = currentParentEntity.getChild(ancestorEntityDef);
}
}
}
return currentParentEntity;
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class MultipleAttributeColumnProvider method extractValues.
public List<String> extractValues(Node<?> axis) {
if (axis instanceof Entity) {
Entity entity = (Entity) axis;
int cnt = entity.getCount(defn.getName());
StringBuffer sb = new StringBuffer();
for (int i = 0; i < cnt; i++) {
if (i > 0) {
sb.append(delimiter);
}
String mainFieldName = null;
if (defn.hasMainField()) {
mainFieldName = defn.getMainFieldName();
}
String val = extractValue(entity, mainFieldName, i);
sb.append(val);
}
return Arrays.asList(sb.toString());
} else {
throw new UnsupportedOperationException();
}
}
use of org.openforis.idm.model.Entity 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;
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class ValidationMessageBuilder method getComparisonCheckMessageArg.
protected String getComparisonCheckMessageArg(Attribute<?, ?> attribute, String expression, Locale locale) {
if (StringUtils.isNotBlank(expression)) {
String result = expression;
Survey survey = attribute.getSurvey();
Schema schema = survey.getSchema();
SurveyContext surveyContext = survey.getContext();
ExpressionEvaluator expressionEvaluator = surveyContext.getExpressionEvaluator();
try {
Entity parentEntity = attribute.getParent();
EntityDefinition parentDefinition = parentEntity.getDefinition();
Set<String> referencedPaths = expressionEvaluator.determineReferencedPaths(expression);
for (String path : referencedPaths) {
String absolutePath = parentDefinition.getPath() + PATH_SEPARATOR + path;
NodeDefinition nodeDefinition = schema.getDefinitionByPath(absolutePath);
String label = getPrettyLabelText(nodeDefinition, locale);
result = result.replaceAll(nodeDefinition.getName(), label);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return result;
} else {
return expression;
}
}
use of org.openforis.idm.model.Entity 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;
}
Aggregations