use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class VersioningVM method getReferencesInCodeLists.
protected List<VersionableSurveyObject> getReferencesInCodeLists(ModelVersion version) {
List<VersionableSurveyObject> references = new ArrayList<VersionableSurveyObject>();
List<CodeList> codeLists = survey.getCodeLists();
for (CodeList codeList : codeLists) {
if (isVersionInUse(version, codeList)) {
references.add(codeList);
}
if (!codeList.isExternal()) {
List<CodeListItem> items = codeList.getItems();
Stack<CodeListItem> itemsStack = new Stack<CodeListItem>();
itemsStack.addAll(items);
while (!itemsStack.isEmpty()) {
CodeListItem item = itemsStack.pop();
if (isVersionInUse(version, item)) {
references.add(item);
}
itemsStack.addAll(item.getChildItems());
}
}
}
return references;
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class SurveyCreator method createTemporarySimpleSurvey.
private CollectSurvey createTemporarySimpleSurvey(String name, List<SimpleCodeList> simpleCodeLists) {
CollectSurvey survey = surveyManager.createTemporarySurvey(name, languageCode);
for (int codeListIdx = 0; codeListIdx < simpleCodeLists.size(); codeListIdx++) {
SimpleCodeList simpleCodeList = simpleCodeLists.get(codeListIdx);
CodeList codeList = survey.createCodeList();
codeList.setName("values_" + (codeListIdx + 1));
codeList.setLabel(CodeListLabel.Type.ITEM, survey.getDefaultLanguage(), simpleCodeList.getName());
List<ListItem> items = simpleCodeList.getItems();
for (int itemIdx = 0; itemIdx < items.size(); itemIdx++) {
ListItem paramItem = items.get(itemIdx);
CodeListItem item = codeList.createItem(1);
// specified code or item index
item.setCode(ObjectUtils.defaultIfNull(paramItem.getCode(), String.valueOf(itemIdx + 1)));
item.setLabel(languageCode, paramItem.getLabel());
item.setColor(paramItem.getColor());
codeList.addItem(item);
}
survey.addCodeList(codeList);
}
Schema schema = survey.getSchema();
EntityDefinition rootEntityDef = schema.createEntityDefinition();
rootEntityDef.setName(singleAttributeSurveyRootEntityName);
schema.addRootEntityDefinition(rootEntityDef);
CodeAttributeDefinition idAttrDef = schema.createCodeAttributeDefinition();
idAttrDef.setName(singleAttributeSurveyKeyAttributeName);
idAttrDef.setKey(true);
idAttrDef.setList(survey.getSamplingDesignCodeList());
rootEntityDef.addChildDefinition(idAttrDef);
TextAttributeDefinition operatorAttrDef = schema.createTextAttributeDefinition();
operatorAttrDef.setName(singleAttributeSurveyOperatorAttributeName);
operatorAttrDef.setKey(true);
operatorAttrDef.setLabel(Type.INSTANCE, languageCode, singleAttributeSurveyOperatorAttributeLabel);
survey.getAnnotations().setMeasurementAttribute(operatorAttrDef, true);
rootEntityDef.addChildDefinition(operatorAttrDef);
EntityDefinition secondLevelEntityDef = schema.createEntityDefinition();
secondLevelEntityDef.setName(singleAttributeSurveySecondLevelEntityName);
secondLevelEntityDef.setMultiple(true);
rootEntityDef.addChildDefinition(secondLevelEntityDef);
CodeAttributeDefinition secondLevelIdAttrDef = schema.createCodeAttributeDefinition();
secondLevelIdAttrDef.setName(singleAttributeSurveySecondLevelIdAttributeName);
secondLevelIdAttrDef.setKey(true);
secondLevelIdAttrDef.setList(survey.getSamplingDesignCodeList());
secondLevelIdAttrDef.setParentCodeAttributeDefinition(idAttrDef);
secondLevelEntityDef.addChildDefinition(secondLevelIdAttrDef);
for (int i = 0; i < simpleCodeLists.size(); i++) {
String codeListName = "values_" + (i + 1);
CodeList codeList = survey.getCodeList(codeListName);
CodeAttributeDefinition valueAttrDef = schema.createCodeAttributeDefinition();
valueAttrDef.setName(codeListName);
valueAttrDef.setList(codeList);
secondLevelEntityDef.addChildDefinition(valueAttrDef);
}
// create root tab set
UIOptions uiOptions = survey.getUIOptions();
UITabSet rootTabSet = uiOptions.createRootTabSet((EntityDefinition) rootEntityDef);
UITab mainTab = uiOptions.getMainTab(rootTabSet);
mainTab.setLabel(languageCode, singleAttributeSurveyTabLabel);
UIConfiguration uiConfiguration = new UIOptionsMigrator().migrateToUIConfiguration(uiOptions);
survey.setUIConfiguration(uiConfiguration);
SurveyObjectsGenerator surveyObjectsGenerator = new SurveyObjectsGenerator();
surveyObjectsGenerator.addPredefinedObjects(survey);
if (survey.getSamplingDesignCodeList() == null) {
survey.addSamplingDesignCodeList();
}
return survey;
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeListBatchImportJob method addCodeListImportTask.
private void addCodeListImportTask(String codeListName) {
CodeList codeList = getOrCreateCodeList(codeListName);
CodeListImportTask task = new CodeListImportTask();
task.setCodeListManager(codeListManager);
task.setCodeList(codeList);
task.setOverwriteData(overwriteData);
addTask(task);
}
Aggregations