use of org.openforis.idm.model.Record in project collect by openforis.
the class RecordFileManager method generateNewRepositoryFilename.
private String generateNewRepositoryFilename(FileAttribute fileAttribute, String tempFileName) {
Record record = fileAttribute.getRecord();
String extension = FilenameUtils.getExtension(tempFileName);
return String.format("%d_%d.%s", record.getId(), System.currentTimeMillis(), extension);
}
use of org.openforis.idm.model.Record 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.model.Record in project collect by openforis.
the class CodeListManager method loadValidItems.
public <T extends CodeListItem> List<T> loadValidItems(Entity parent, CodeAttributeDefinition def) {
List<T> items = null;
CodeList list = def.getList();
if (StringUtils.isEmpty(def.getParentExpression())) {
items = loadRootItems(list);
} else {
CodeAttribute parentCodeAttribute = getCodeParent(parent, def);
if (parentCodeAttribute != null) {
CodeListItem parentCodeListItem = loadItemByAttribute(parentCodeAttribute);
if (parentCodeListItem != null) {
items = loadChildItems(parentCodeListItem);
}
}
}
Record record = parent.getRecord();
ModelVersion version = record.getVersion();
return filterApplicableItems(items, version);
}
use of org.openforis.idm.model.Record in project collect by openforis.
the class CodeListManager method findValidItems.
public List<CodeListItem> findValidItems(Entity parent, CodeAttributeDefinition defn, String... codes) {
List<CodeListItem> result = new ArrayList<CodeListItem>();
List<CodeListItem> assignableItems = loadValidItems(parent, defn);
if (!assignableItems.isEmpty()) {
Record record = parent.getRecord();
ModelVersion version = record.getVersion();
for (String code : codes) {
CodeListItem item = findCodeListItem(assignableItems, code, version);
if (item != null) {
result.add(item);
}
}
}
return result;
}
use of org.openforis.idm.model.Record in project collect by openforis.
the class RecordUpdater method addEmptyEnumeratedEntities.
private void addEmptyEnumeratedEntities(Entity parentEntity) {
Record record = parentEntity.getRecord();
ModelVersion version = record.getVersion();
EntityDefinition parentEntityDefn = parentEntity.getDefinition();
List<NodeDefinition> childDefinitions = parentEntityDefn.getChildDefinitionsInVersion(version);
for (NodeDefinition childDefn : childDefinitions) {
if (childDefn instanceof EntityDefinition) {
EntityDefinition childEntityDefn = (EntityDefinition) childDefn;
if (childEntityDefn.isMultiple() && childEntityDefn.isEnumerable() && childEntityDefn.isEnumerate()) {
addEmptyEnumeratedEntities(parentEntity, childEntityDefn);
}
}
}
}
Aggregations