use of org.openforis.idm.metamodel.ModelVersion 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.ModelVersion in project collect by openforis.
the class CodeValueFKColumnValueExtractor method extractValue.
private Object extractValue(CodeAttribute valNode) {
CodeListItem item = findCodeListItem(valNode);
if (item == null) {
String defaultCodeValue = column.getDefaultCodeValue();
String codeValue = getCodeValue(valNode);
if (defaultCodeValue == null || (codeValue != null && !codeValue.equals(defaultCodeValue))) {
// no default code value specified or code list item not found (invalid code?)
return null;
} else {
CodeAttributeDefinition definition = valNode.getDefinition();
CodeList list = definition.getList();
Record record = valNode.getRecord();
ModelVersion version = record.getVersion();
return getDefaultCodeItemId(list, version);
}
} else {
return item.getId();
}
}
use of org.openforis.idm.metamodel.ModelVersion in project collect by openforis.
the class CodeAttribute method getCodeListItem.
/**
* @deprecated Access code list items using manager class.
*
* @return
*/
@Deprecated
public CodeListItem getCodeListItem() {
Code code = getValue();
if (code != null) {
String codeValue = code.getCode();
if (StringUtils.isNotBlank(codeValue)) {
ModelVersion currentVersion = getRecord().getVersion();
CodeAttributeDefinition definition = getDefinition();
String parentExpression = definition.getParentExpression();
if (StringUtils.isBlank(parentExpression)) {
return findCodeListItem(definition.getList().getItems(), codeValue, currentVersion);
} else {
CodeAttribute codeParent = getCodeParent();
if (codeParent != null) {
CodeListItem codeListItemParent = codeParent.getCodeListItem();
if (codeListItemParent != null) {
return findCodeListItem(codeListItemParent.getChildItems(), codeValue, currentVersion);
}
}
}
}
}
return null;
}
use of org.openforis.idm.metamodel.ModelVersion in project collect by openforis.
the class ModelVersionUtil method isInVersion.
public static boolean isInVersion(Versionable versionable, ModelVersion currentVersion) {
boolean result;
ModelVersion since = versionable.getSinceVersion();
ModelVersion deprecated = versionable.getDeprecatedVersion();
String currentDate = currentVersion.getDate();
int compareToSince;
if (since == null) {
compareToSince = 1;
} else {
compareToSince = currentDate.compareTo(since.getDate());
}
int compareToDeprecated;
if (deprecated == null) {
compareToDeprecated = -1;
} else {
compareToDeprecated = currentDate.compareTo(deprecated.getDate());
}
result = compareToSince >= 0 && compareToDeprecated <= 0;
return result;
}
use of org.openforis.idm.metamodel.ModelVersion in project collect by openforis.
the class DataHandler method startChildNode.
public void startChildNode(String localName, Attributes attributes) {
Entity entity = (Entity) node;
NodeDefinition childDefn = getNodeDefinition(entity, localName, attributes);
if (childDefn == null) {
warn(localName, "Undefined node");
pushIgnore();
} else {
ModelVersion version = record.getVersion();
if (version == null || version.isApplicable(childDefn)) {
Node<?> newNode = childDefn.createNode();
entity.add(newNode);
Integer stateValue = getNodeState();
if (stateValue != null) {
entity.setChildState(localName, stateValue);
}
this.node = newNode;
} else {
warn(localName, "Node definition is not applicable to the record version");
pushIgnore();
}
}
}
Aggregations