use of org.openforis.idm.metamodel.CodeListItem in project collect by openforis.
the class CollectRecordIntegrationTest method createMultipleLevelCodeListTestSurvey.
private CollectSurvey createMultipleLevelCodeListTestSurvey() {
CollectSurvey survey = surveyManager.createTemporarySurvey("test", "en");
CodeList codeList = survey.createCodeList();
{
CodeListLevel codeListLevel = new CodeListLevel();
codeListLevel.setName("level1");
codeList.addLevel(codeListLevel);
}
{
CodeListLevel codeListLevel = new CodeListLevel();
codeListLevel.setName("level2");
codeList.addLevel(codeListLevel);
}
{
CodeListLevel codeListLevel = new CodeListLevel();
codeListLevel.setName("level3");
codeList.addLevel(codeListLevel);
}
{
CodeListItem item = codeList.createItem(1);
item.setCode("A");
codeList.addItem(item);
{
CodeListItem child = codeList.createItem(2);
child.setCode("1");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
{
CodeListItem child = codeList.createItem(2);
child.setCode("2");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
{
CodeListItem child = codeList.createItem(2);
child.setCode("3");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
}
{
CodeListItem item = codeList.createItem(1);
item.setCode("B");
codeList.addItem(item);
{
CodeListItem child = codeList.createItem(2);
child.setCode("1");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
{
CodeListItem child = codeList.createItem(2);
child.setCode("2");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
{
CodeListItem child = codeList.createItem(2);
child.setCode("3");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
}
survey.addCodeList(codeList);
Schema schema = survey.getSchema();
EntityDefinition root = schema.createEntityDefinition();
root.setName("root");
schema.addRootEntityDefinition(root);
{
CodeAttributeDefinition codeAttrDefn = schema.createCodeAttributeDefinition();
codeAttrDefn.setList(codeList);
codeAttrDefn.setName("code1");
root.addChildDefinition(codeAttrDefn);
}
{
CodeAttributeDefinition codeAttrDefn = schema.createCodeAttributeDefinition();
codeAttrDefn.setList(codeList);
codeAttrDefn.setName("code2");
codeAttrDefn.setParentExpression("code1");
root.addChildDefinition(codeAttrDefn);
}
{
CodeAttributeDefinition codeAttrDefn = schema.createCodeAttributeDefinition();
codeAttrDefn.setList(codeList);
codeAttrDefn.setName("code3");
codeAttrDefn.setParentExpression("code2");
root.addChildDefinition(codeAttrDefn);
}
survey.init();
return survey;
}
use of org.openforis.idm.metamodel.CodeListItem in project collect by openforis.
the class MinCountValidator method isAvailableCodeListItems.
private boolean isAvailableCodeListItems(Entity parentEntity) {
CodeAttributeDefinition codeAttrDef = (CodeAttributeDefinition) nodeDefinition;
SurveyContext context = codeAttrDef.getSurvey().getContext();
CodeListService codeListService = context.getCodeListService();
if (codeListService == null) {
// test context does not have a CodeListService
return true;
}
List<CodeListItem> validItems = codeListService.loadValidItems(parentEntity, codeAttrDef);
return !validItems.isEmpty();
}
use of org.openforis.idm.metamodel.CodeListItem in project collect by openforis.
the class CodeListImportTask method hasDifferentLabel.
protected boolean hasDifferentLabel(String code, LanguageSpecificText item, CodeListItem parentItem) {
CodeListItem existingItem = getChildItem(parentItem, code);
if (existingItem == null) {
return false;
} else {
String lang = item.getLanguage();
String label = item.getText();
String existingItemLabel = existingItem.getLabel(lang);
return !existingItemLabel.equals(label);
}
}
use of org.openforis.idm.metamodel.CodeListItem in project collect by openforis.
the class CodeListImportTask method processLevel.
protected CodeListItem processLevel(CodeListItem parent, CodeListLine line, int levelIdx, boolean lastLevel) {
CodeListItem result;
// validate code
List<String> codes = line.getLevelCodes();
if (codes.isEmpty()) {
addEmptyCodeColumnError(line, levelIdx);
}
String code = codes.get(levelIdx);
if (lastLevel && isDuplicate(code, parent)) {
addDuplicateCodeError(line, levelIdx);
}
// validate labels
List<LanguageSpecificText> labels = line.getLabelItems(levelIdx);
for (LanguageSpecificText label : labels) {
if (hasDifferentLabel(code, label, parent)) {
addDifferentLabelError(line, levelIdx, label.getLanguage());
}
}
result = getChildItem(parent, code);
if (result == null) {
result = codeList.createItem(levelIdx + 1);
List<LanguageSpecificText> descriptions = line.getDescriptionItems(levelIdx);
fillItem(result, code, labels, descriptions);
if (parent == null) {
codeToRootItem.put(code, result);
} else {
parent.addChildItem(result);
}
}
return result;
}
use of org.openforis.idm.metamodel.CodeListItem in project collect by openforis.
the class CEComponentHTMLFormatter method buildCodeSelect.
private void buildCodeSelect(XMLBuilder builder, CECodeField comp) {
String elId = comp.getHtmlParameterName();
// build select
XMLBuilder selectBuilder = // $NON-NLS-1$
builder.e("select").a("id", // $NON-NLS-1$
elId).a("name", // $NON-NLS-1$
elId).a("data-field-type", // $NON-NLS-1$
comp.getType().name()).a("class", // $NON-NLS-1$ //$NON-NLS-2$
"form-control selectboxit show-menu-arrow show-tick").a("data-width", // $NON-NLS-1$ //$NON-NLS-2$
"75px");
if (comp.getParentName() != null) {
// $NON-NLS-1$
selectBuilder.a("data-parent-id-field-id", comp.getParentName());
}
// add root items, if any
Map<Integer, List<CodeListItem>> itemsByParentCode = ((CECodeField) comp).getCodeItemsByParentId();
List<CodeListItem> rootItems = itemsByParentCode.get(0);
if (rootItems != null) {
boolean hasNAoption = false;
for (CodeListItem item : rootItems) {
if (// $NON-NLS-1$
item.getCode().equalsIgnoreCase("na") || // $NON-NLS-1$
item.getCode().equalsIgnoreCase("n/a")) {
hasNAoption = true;
}
}
if (!hasNAoption) {
// $NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
selectBuilder.e("option").a("value", "").t(HtmlUnicodeEscaperUtil.escapeForBalloon(Messages.getString("CEComponentHTMLFormatter.119", language)));
}
for (CodeListItem item : rootItems) {
String itemLabel = getItemLabel(item);
// $NON-NLS-1$
selectBuilder.e("option").a("value", // $NON-NLS-1$
item.getCode()).t(itemLabel);
}
}
}
Aggregations