use of org.openforis.idm.metamodel.CodeAttributeDefinition 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.CodeAttributeDefinition 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.CodeAttributeDefinition in project collect by openforis.
the class MondrianCubeGenerator method generateLevel.
private List<Level> generateLevel(NodeDefinition nodeDef) {
List<Level> levels = new ArrayList<Level>();
String attrLabel = extractFailsafeLabel(nodeDef);
Level level = new Level(attrLabel);
levels.add(level);
if (nodeDef instanceof NumericAttributeDefinition) {
level.type = ((NumericAttributeDefinition) nodeDef).getType() == Type.INTEGER ? INTEGER_DATATYPE : NUMERIC_DATATYPE;
} else if (nodeDef instanceof CodeAttributeDefinition) {
level.type = ((CodeAttributeDefinition) nodeDef).getList().isExternal() ? STRING_DATATYPE : INTEGER_DATATYPE;
} else {
level.type = STRING_DATATYPE;
}
level.levelType = "Regular";
if (nodeDef instanceof CodeAttributeDefinition) {
CodeAttributeDefinition codeDef = (CodeAttributeDefinition) nodeDef;
String codeTableName = extractCodeListTableName(codeDef);
level.table = codeTableName;
level.column = codeTableName + rdbConfig.getIdColumnSuffix();
level.nameColumn = codeTableName.substring(0, codeTableName.length() - rdbConfig.getCodeListTableSuffix().length()) + "_label_" + language;
Level levelId = new Level(attrLabel + " - ID");
levelId.type = "String";
levelId.table = codeTableName;
levelId.column = codeTableName + rdbConfig.getIdColumnSuffix();
levelId.nameColumn = extractCodeListName(codeDef);
levels.add(levelId);
} else {
level.column = nodeDef.getName();
}
return levels;
}
use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.
the class NewMondrianSchemaGenerator method generateLevel.
private Level generateLevel(AttributeDefinition nodeDef) {
DataTable dataTable = rdbSchema.getDataTable(nodeDef.getParentDefinition());
Level level = new Level(determineDimensionName(nodeDef), determineLevelCaption(nodeDef));
level.levelType = "Regular";
if (nodeDef instanceof NumericAttributeDefinition) {
level.type = ((NumericAttributeDefinition) nodeDef).getType() == Type.INTEGER ? INTEGER_DATATYPE : NUMERIC_DATATYPE;
} else if (nodeDef instanceof BooleanAttributeDefinition) {
level.type = BOOLEAN_DATATYPE;
} else if (nodeDef instanceof CodeAttributeDefinition) {
level.type = ((CodeAttributeDefinition) nodeDef).getList().isExternal() ? STRING_DATATYPE : INTEGER_DATATYPE;
} else {
level.type = STRING_DATATYPE;
}
if (nodeDef instanceof CodeAttributeDefinition && !((CodeAttributeDefinition) nodeDef).getList().isExternal()) {
CodeAttributeDefinition codeDef = (CodeAttributeDefinition) nodeDef;
CodeTable codeListTable = rdbSchema.getCodeListTable(codeDef);
level.table = codeListTable.getName();
level.column = codeListTable.getPrimaryKeyConstraint().getPrimaryKeyColumn().getName();
level.nameColumn = CodeListTables.getLabelColumnName(rdbConfig, codeDef.getList(), codeDef.getLevelIndex(), language);
} else if (nodeDef instanceof TaxonAttributeDefinition) {
DataColumn dataColumn = dataTable.getDataColumn(((TaxonAttributeDefinition) nodeDef).getCodeFieldDefinition());
level.column = dataColumn.getName();
} else if (nodeDef.isMultiple()) {
// TODO skip multiple attributes?
level.column = nodeDef.getName();
} else {
DataColumn dataColumn = dataTable.getDataColumn(nodeDef.getMainFieldDefinition());
level.column = dataColumn.getName();
}
return level;
}
use of org.openforis.idm.metamodel.CodeAttributeDefinition in project collect by openforis.
the class CollectEarthBalloonGenerator method createComponent.
private CEComponent createComponent(NodeDefinition def, int entityPosition) {
String label = def.getLabel(Type.INSTANCE, language);
if (label == null && !isDefaultLanguage()) {
label = def.getLabel(Type.INSTANCE);
}
if (label == null) {
label = def.getName();
}
boolean multiple = def.isMultiple();
UIOptions uiOptions = survey.getUIOptions();
boolean hideWhenNotRelevant = uiOptions.isHideWhenNotRelevant(def);
CEComponent comp;
if (def instanceof EntityDefinition) {
if (def.isMultiple() && ((EntityDefinition) def).isEnumerable()) {
comp = createEnumeratedEntityComponent((EntityDefinition) def);
} else {
String tooltip = def.getDescription(language);
CEFieldSet fieldSet = new CEFieldSet(def.getName(), label, tooltip);
for (NodeDefinition child : ((EntityDefinition) def).getChildDefinitions()) {
if (!uiOptions.isHidden(child)) {
fieldSet.addChild(createComponent(child));
}
}
comp = fieldSet;
}
} else {
AttributeDefinition attrDef = (AttributeDefinition) def;
String htmlParameterName;
boolean insideEnumeratedEntity = def.getParentEntityDefinition().isEnumerable();
if (insideEnumeratedEntity) {
htmlParameterName = getEnumeratedEntityComponentHtmlParameterName(def.getParentEntityDefinition(), entityPosition, def);
} else {
htmlParameterName = getHtmlParameterName(def);
}
String tooltip = attrDef.getDescription(language);
CEFieldType type = getFieldType(def);
boolean key = def instanceof KeyAttributeDefinition ? ((KeyAttributeDefinition) def).isKey() : false;
if (insideEnumeratedEntity && key) {
comp = new CEEnumeratingCodeField(htmlParameterName, def.getName(), label, tooltip, multiple, type, key);
} else if (def instanceof CodeAttributeDefinition) {
CodeAttributeDefinition codeAttrDef = (CodeAttributeDefinition) def;
CodeList list = codeAttrDef.getList();
Integer listLevelIndex = codeAttrDef.getListLevelIndex();
Map<Integer, List<CodeListItem>> codeItemsByParentCodeItemId = getCodeListItemsByParentId(list, listLevelIndex);
CodeAttributeDefinition parentCodeAttributeDef = codeAttrDef.getParentCodeAttributeDefinition();
String parentName = parentCodeAttributeDef == null ? null : getHtmlParameterName(parentCodeAttributeDef);
comp = new CECodeField(htmlParameterName, def.getName(), label, tooltip, type, multiple, key, codeItemsByParentCodeItemId, parentName);
} else {
comp = new CEField(htmlParameterName, def.getName(), label, tooltip, multiple, type, key);
}
CollectAnnotations annotations = survey.getAnnotations();
if (attrDef.isCalculated() || (annotations.isFromCollectEarthCSV(attrDef) && annotations.isShowReadOnlyFieldInCollectEarth(attrDef))) {
((CEField) comp).setReadOnly(true);
}
}
comp.hideWhenNotRelevant = hideWhenNotRelevant;
componentByName.put(comp.getName(), comp);
return comp;
}
Aggregations