use of org.openforis.idm.metamodel.Survey in project collect by openforis.
the class CodeListManager method delete.
@Transactional
public void delete(CodeList codeList) {
Survey survey = codeList.getSurvey();
deleteAllItems(codeList);
survey.removeCodeList(codeList);
}
use of org.openforis.idm.metamodel.Survey 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.Survey in project collect by openforis.
the class RecordFileManager method getRepositoryRelativePath.
public static String getRepositoryRelativePath(FileAttributeDefinition defn, String directorySeparator, boolean surveyRelative) {
Survey survey = defn.getSurvey();
StringBuilder sb = new StringBuilder();
if (surveyRelative) {
sb.append(survey.getId());
sb.append(directorySeparator);
}
sb.append(defn.getId());
return sb.toString();
}
use of org.openforis.idm.metamodel.Survey 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++;
}
}
}
}
use of org.openforis.idm.metamodel.Survey in project collect by openforis.
the class CSVDataImportProcess method getOrCreateParentEntity.
// @SuppressWarnings("unchecked")
// private <T extends Value> void setValueInAttribute(Attribute<?, T> attr, String strVal) {
// T val;
// if ( attr instanceof DateAttribute ) {
// val = (T) Date.parseDate(strVal);
// } else if ( attr instanceof CodeAttribute ) {
// val = (T) new Code(strVal);
// } else if ( attr instanceof CoordinateAttribute ) {
// val = (T) Coordinate.parseCoordinate(strVal);
// } else if ( attr instanceof TextAttribute ) {
// val = (T) new TextValue(strVal);
// } else {
// throw new UnsupportedOperationException("Attribute type not supported: " + attr.getClass().getName());
// }
// attr.setValue(val);
// }
private Entity getOrCreateParentEntity(CollectRecord record, DataLine line) {
Survey survey = record.getSurvey();
Schema schema = survey.getSchema();
EntityDefinition parentEntityDefn = (EntityDefinition) schema.getDefinitionById(parentEntityDefinitionId);
Entity rootEntity = record.getRootEntity();
Entity currentParent = rootEntity;
List<EntityDefinition> ancestorEntityDefns = parentEntityDefn.getAncestorEntityDefinitionsInReverseOrder();
ancestorEntityDefns.add(parentEntityDefn);
// skip the root entity
for (int i = 1; i < ancestorEntityDefns.size(); i++) {
EntityDefinition ancestorDefn = ancestorEntityDefns.get(i);
String ancestorName = ancestorDefn.getName();
EntityIdentifier<?> identifier = line.getAncestorIdentifier(ancestorDefn.getId());
Entity childEntity;
if (ancestorDefn.isMultiple()) {
List<Entity> childEntities = findChildEntities(currentParent, ancestorName, identifier);
switch(childEntities.size()) {
case 0:
if (settings.isCreateAncestorEntities() || ancestorDefn == parentEntityDefn) {
childEntity = createChildEntity(currentParent, ancestorName, identifier, line.getColumnNamesByField(), line.getLineNumber());
} else {
status.addParsingError(createParentEntitySearchError(record, line, identifier, PARENT_ENTITY_NOT_FOUND_MESSAGE_KEY));
return null;
}
break;
case 1:
childEntity = childEntities.get(0);
break;
default:
status.addParsingError(createParentEntitySearchError(record, line, identifier, MULTIPLE_PARENT_ENTITY_FOUND_MESSAGE_KEY));
return null;
}
} else {
if (currentParent.getCount(ancestorDefn) == 0) {
Node<?> newNode = ancestorDefn.createNode();
currentParent.add(newNode);
}
childEntity = (Entity) currentParent.getChild(ancestorDefn);
}
currentParent = childEntity;
}
return currentParent;
}
Aggregations