use of org.openforis.idm.metamodel.PersistedCodeListItem 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.PersistedCodeListItem in project collect by openforis.
the class CodeListManager method createPersistedItems.
protected List<PersistedCodeListItem> createPersistedItems(Collection<CodeListItem> items, int nextId, Integer parentItemId) {
List<PersistedCodeListItem> result = new ArrayList<PersistedCodeListItem>();
int sortOrder = 1;
for (CodeListItem item : items) {
PersistedCodeListItem persistedChildItem = PersistedCodeListItem.fromItem(item);
persistedChildItem.setParentId(parentItemId);
int id = nextId++;
persistedChildItem.setSystemId(id);
persistedChildItem.setSortOrder(sortOrder++);
result.add(persistedChildItem);
List<PersistedCodeListItem> temp = createPersistedItems(item.getChildItems(), nextId, id);
nextId += temp.size();
result.addAll(temp);
}
return result;
}
use of org.openforis.idm.metamodel.PersistedCodeListItem in project collect by openforis.
the class CodeListImagesImportTask method execute.
@Override
protected void execute() throws Throwable {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
String entryName = entry.getName();
if (CodeListImageEntry.isValidEntry(entryName)) {
CodeListImageEntry codeListImageEntry = CodeListImageEntry.parseEntryName(entryName);
CodeList codeList = survey.getCodeListById(codeListImageEntry.getListId());
if (codeList != null) {
CodeListItem item = codeListManager.loadItem(codeList, codeListImageEntry.getItemId());
if (item != null && item instanceof PersistedCodeListItem) {
byte[] content = IOUtils.toByteArray(zipFile.getInputStream(entry));
codeListManager.saveImageContent((PersistedCodeListItem) item, new FileWrapper(content, codeListImageEntry.getFileName()));
} else {
log().warn("Error restoring code list image file : " + entry.getName());
}
}
}
}
}
Aggregations