use of org.openforis.idm.metamodel.CodeListItem in project collect by openforis.
the class CodeListManager method findCodeListItem.
private CodeListItem findCodeListItem(List<CodeListItem> siblings, String code, ModelVersion version) {
String adaptedCode = code.trim();
// remove initial zeros
adaptedCode = adaptedCode.replaceFirst("^0+", "");
adaptedCode = Pattern.quote(adaptedCode);
Pattern pattern = Pattern.compile("^[0]*" + adaptedCode + "$", Pattern.CASE_INSENSITIVE);
for (CodeListItem item : siblings) {
if (version == null || version.isApplicable(item)) {
String itemCode = item.getCode();
Matcher matcher = pattern.matcher(itemCode);
if (matcher.find()) {
return item;
}
}
}
return null;
}
use of org.openforis.idm.metamodel.CodeListItem in project collect by openforis.
the class CodeListImagesExportTask method execute.
@Override
protected void execute() throws Throwable {
List<CodeList> codeLists = survey.getCodeLists();
for (CodeList list : codeLists) {
if (!list.isExternal()) {
Deque<CodeListItem> stack = new LinkedList<CodeListItem>();
List<CodeListItem> rootItems = codeListManager.loadRootItems(list);
stack.addAll(rootItems);
while (!stack.isEmpty()) {
if (!isRunning()) {
break;
}
CodeListItem item = stack.pop();
if (item instanceof PersistedCodeListItem && item.hasUploadedImage()) {
FileWrapper imageFileWrapper = codeListManager.loadImageContent((PersistedCodeListItem) item);
ZipEntry entry = new ZipEntry(getEntryName(item));
zipOutputStream.putNextEntry(entry);
IOUtils.write(imageFileWrapper.getContent(), zipOutputStream);
zipOutputStream.closeEntry();
}
List<CodeListItem> childItems = codeListManager.loadChildItems(item);
for (CodeListItem childItem : childItems) {
stack.push(childItem);
}
}
}
}
}
use of org.openforis.idm.metamodel.CodeListItem in project collect by openforis.
the class CollectEarthGridTemplateGenerator method getFirstAvailableCodeItem.
private CodeListItem getFirstAvailableCodeItem(AttributeDefinition attrDef) {
CodeAttributeDefinition codeDefn = (CodeAttributeDefinition) attrDef;
CodeList list = codeDefn.getList();
CodeListService codeListService = attrDef.getSurvey().getContext().getCodeListService();
Integer levelIndex = codeDefn.getListLevelIndex();
int levelPosition = levelIndex == null ? 1 : levelIndex + 1;
List<CodeListItem> items;
if (levelPosition == 1) {
items = codeListService.loadRootItems(list);
} else {
items = codeListService.loadItems(list, levelPosition);
}
if (items.isEmpty()) {
return null;
} else {
return items.get(0);
}
}
use of org.openforis.idm.metamodel.CodeListItem in project collect by openforis.
the class CollectEarthGridTemplateGenerator method getDummyValue.
private String getDummyValue(AttributeDefinition attrDef, Integer ord) {
String attrName = attrDef.getName();
String value;
if (attrDef instanceof NumericAttributeDefinition || attrDef instanceof BooleanAttributeDefinition) {
value = "0";
if (ord != null) {
value = ord + "";
}
} else if (attrDef instanceof DateAttributeDefinition) {
value = "1/1/2000";
} else if (attrDef instanceof CodeAttributeDefinition) {
CodeListItem firstAvailableItem = getFirstAvailableCodeItem(attrDef);
value = firstAvailableItem == null ? "0" : firstAvailableItem.getCode();
} else {
value = attrName;
if (ord != null) {
value += "_" + ord;
}
}
return value;
}
use of org.openforis.idm.metamodel.CodeListItem in project collect by openforis.
the class CodeColumnProvider method extractValues.
@Override
public List<String> extractValues(Node<?> axis) {
List<String> values = super.extractValues(axis);
if (hasExpandedItems) {
List<Node<?>> attributes = extractNodes(axis);
for (CodeListItem item : expandedItems) {
CodeAttribute attr = findAttributeByCode(attributes, item.getCode());
values.add(Boolean.valueOf(attr != null).toString());
if (item.isQualifiable()) {
values.add(attr == null ? "" : attr.getValue().getQualifier());
}
}
}
return values;
}
Aggregations