use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeListsVM method isCodeListInPublishedSurvey.
protected boolean isCodeListInPublishedSurvey() {
SessionStatus sessionStatus = getSessionStatus();
Integer publishedSurveyId = sessionStatus.getPublishedSurveyId();
if (publishedSurveyId != null) {
CollectSurvey publishedSurvey = surveyManager.getById(publishedSurveyId);
CodeList oldPublishedCodeList = publishedSurvey.getCodeListById(editedItem.getId());
return oldPublishedCodeList != null;
} else {
return false;
}
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class SurveyMigrator method fixCodeListHierarchyLevelNames.
protected void fixCodeListHierarchyLevelNames(CollectSurvey survey) {
List<CodeList> codeLists = survey.getCodeLists();
for (CodeList list : codeLists) {
List<CodeListLevel> hierarchy = list.getHierarchy();
for (CodeListLevel level : hierarchy) {
String name = level.getName();
Pattern pattern = Pattern.compile(INTERNAL_NAME_REGEX);
Matcher matcher = pattern.matcher(name);
if (!matcher.matches()) {
String fixedName = fixInternalName(name);
level.setName(fixedName);
}
}
}
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeListManager method loadPersistedItem.
protected PersistedCodeListItem loadPersistedItem(CodeAttribute attribute) {
Code code = attribute.getValue();
if (code == null || StringUtils.isBlank(code.getCode())) {
return null;
} else {
String codeVal = code.getCode();
CodeAttributeDefinition defn = attribute.getDefinition();
CodeList list = defn.getList();
Record record = attribute.getRecord();
ModelVersion version = record.getVersion();
if (StringUtils.isBlank(defn.getParentExpression())) {
CodeListItem item = codeListItemDao.loadRootItem(list, codeVal, version);
return (PersistedCodeListItem) item;
} else {
PersistedCodeListItem parentItem = (PersistedCodeListItem) loadParentItem(attribute);
if (parentItem == null) {
return null;
} else {
CodeListItem item = codeListItemDao.loadItem(list, parentItem.getSystemId(), codeVal, version);
return (PersistedCodeListItem) item;
}
}
}
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeListManager method loadValidItems.
public <T extends CodeListItem> List<T> loadValidItems(Entity parent, CodeAttributeDefinition def) {
List<T> items = null;
CodeList list = def.getList();
if (StringUtils.isEmpty(def.getParentExpression())) {
items = loadRootItems(list);
} else {
CodeAttribute parentCodeAttribute = getCodeParent(parent, def);
if (parentCodeAttribute != null) {
CodeListItem parentCodeListItem = loadItemByAttribute(parentCodeAttribute);
if (parentCodeListItem != null) {
items = loadChildItems(parentCodeListItem);
}
}
}
Record record = parent.getRecord();
ModelVersion version = record.getVersion();
return filterApplicableItems(items, version);
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeListManager method getUnusedCodeLists.
protected Set<CodeList> getUnusedCodeLists(CollectSurvey survey) {
Set<CodeList> result = new HashSet<CodeList>();
List<CodeList> codeLists = survey.getCodeLists();
for (CodeList list : codeLists) {
if (!isInUse(list)) {
result.add(list);
}
}
return result;
}
Aggregations