use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.
the class RecordGenerator method addSecondLevelEntities.
private void addSecondLevelEntities(CollectRecord record, RecordKey recordKey) {
CollectSurvey survey = (CollectSurvey) record.getSurvey();
List<AttributeDefinition> nonMeasurementKeyDefs = getNonMeasurementKeyDefs(survey);
List<String> keyValues = recordKey.getValues(nonMeasurementKeyDefs);
List<SamplingDesignItem> secondLevelSamplingPointItems = samplingDesignManager.loadChildItems(survey.getId(), keyValues);
List<CodeAttributeDefinition> samplingPointDataCodeAttributeDefs = findSamplingPointCodeAttributes(survey);
if (!secondLevelSamplingPointItems.isEmpty() && samplingPointDataCodeAttributeDefs.size() > 1) {
int levelIndex = 1;
for (SamplingDesignItem samplingDesignItem : secondLevelSamplingPointItems) {
CodeAttributeDefinition levelKeyDef = samplingPointDataCodeAttributeDefs.get(levelIndex);
EntityDefinition levelEntityDef = levelKeyDef.getParentEntityDefinition();
Entity parentLevelEntity = record.getRootEntity();
NodeChangeSet addEntityChangeSet = recordUpdater.addEntity(parentLevelEntity, levelEntityDef);
Entity entity = getAddedEntity(addEntityChangeSet);
CodeAttribute keyAttr = entity.getChild(levelKeyDef);
recordUpdater.updateAttribute(keyAttr, new Code(samplingDesignItem.getLevelCode(levelIndex + 1)));
}
}
}
use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.
the class CodeListManager method isInUse.
public boolean isInUse(final CodeList list) {
Survey survey = list.getSurvey();
Schema schema = survey.getSchema();
NodeDefinition attrDefnUsingCodeList = schema.findNodeDefinition(new NodeDefinitionVerifier() {
@Override
public boolean verify(NodeDefinition definition) {
return definition instanceof CodeAttributeDefinition && ((CodeAttributeDefinition) definition).getList() == list;
}
});
return attrDefnUsingCodeList != null;
}
use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.
the class CollectEarthGridTemplateGenerator method getFirstAvailableCodeItem.
private CodeListItem getFirstAvailableCodeItem(AttributeDefinition attrDef) {
CodeAttributeDefinition codeDefn = (CodeAttributeDefinition) attrDef;
CodeList list = codeDefn.getList();
CodeListService codeListService = attrDef.getSurvey().getContext().getCodeListService();
Integer levelIndex = codeDefn.getListLevelIndex();
int levelPosition = levelIndex == null ? 1 : levelIndex + 1;
List<CodeListItem> items;
if (levelPosition == 1) {
items = codeListService.loadRootItems(list);
} else {
items = codeListService.loadItems(list, levelPosition);
}
if (items.isEmpty()) {
return null;
} else {
return items.get(0);
}
}
use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.
the class CollectEarthGridTemplateGenerator method getDummyValue.
private String getDummyValue(AttributeDefinition attrDef, Integer ord) {
String attrName = attrDef.getName();
String value;
if (attrDef instanceof NumericAttributeDefinition || attrDef instanceof BooleanAttributeDefinition) {
value = "0";
if (ord != null) {
value = ord + "";
}
} else if (attrDef instanceof DateAttributeDefinition) {
value = "1/1/2000";
} else if (attrDef instanceof CodeAttributeDefinition) {
CodeListItem firstAvailableItem = getFirstAvailableCodeItem(attrDef);
value = firstAvailableItem == null ? "0" : firstAvailableItem.getCode();
} else {
value = attrName;
if (ord != null) {
value += "_" + ord;
}
}
return value;
}
use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.
the class RecordUpdater method addEmptyEnumeratedEntities.
private void addEmptyEnumeratedEntities(Entity parentEntity, EntityDefinition enumerableEntityDefn) {
Record record = parentEntity.getRecord();
ModelVersion version = record.getVersion();
CodeAttributeDefinition enumeratingCodeDefn = enumerableEntityDefn.getEnumeratingKeyCodeAttribute(version);
if (enumeratingCodeDefn != null) {
CodeList list = enumeratingCodeDefn.getList();
Survey survey = record.getSurvey();
CodeListService codeListService = survey.getContext().getCodeListService();
List<CodeListItem> items = codeListService.loadRootItems(list);
int i = 0;
for (CodeListItem item : items) {
if (version == null || version.isApplicable(item)) {
String code = item.getCode();
Entity enumeratedEntity = parentEntity.getEnumeratedEntity(enumerableEntityDefn, enumeratingCodeDefn, code);
if (enumeratedEntity == null) {
Entity addedEntity = performEntityAdd(parentEntity, enumerableEntityDefn, i);
addEmptyNodes(addedEntity);
// set the value of the key CodeAttribute
CodeAttribute addedCode = (CodeAttribute) addedEntity.getChild(enumeratingCodeDefn, 0);
addedCode.setValue(new Code(code));
addedCode.updateSummaryInfo();
} else if (enumeratedEntity.getIndex() != i) {
parentEntity.move(enumerableEntityDefn, enumeratedEntity.getIndex(), i);
}
i++;
}
}
}
}
Aggregations