use of org.openforis.idm.model.Entity in project collect by openforis.
the class RecordDao method createRecordDataFieldValueMap.
private Map<Field<?>, Object> createRecordDataFieldValueMap(int recordId, Integer sequenceNumber, Step step, CollectRecord r) {
Map<Field<?>, Object> map = new HashMap<Field<?>, Object>();
map.put(OFC_RECORD_DATA.RECORD_ID, recordId);
if (sequenceNumber != null) {
map.put(OFC_RECORD_DATA.SEQ_NUM, sequenceNumber);
}
map.put(OFC_RECORD_DATA.DATE_CREATED, toTimestamp(defaultIfNull(r.getDataCreationDate(), r.getCreationDate())));
map.put(OFC_RECORD_DATA.CREATED_BY, getUserId(defaultIfNull(r.getDataCreatedBy(), r.getCreatedBy())));
map.put(OFC_RECORD_DATA.DATE_MODIFIED, toTimestamp(defaultIfNull(r.getDataModifiedDate(), r.getModifiedDate())));
map.put(OFC_RECORD_DATA.MODIFIED_BY, getUserId(defaultIfNull(r.getDataModifiedBy(), r.getModifiedBy())));
map.put(OFC_RECORD_DATA.STEP, step.getStepNumber());
map.put(OFC_RECORD_DATA.STATE, r.getState() != null ? r.getState().getCode() : null);
map.put(OFC_RECORD_DATA.SKIPPED, r.getSkipped());
map.put(OFC_RECORD_DATA.MISSING, r.getMissing());
map.put(OFC_RECORD_DATA.ERRORS, r.getErrors());
map.put(OFC_RECORD_DATA.WARNINGS, r.getWarnings());
map.put(OFC_RECORD_DATA.APP_VERSION, r.getApplicationVersion().toString());
addValuesToMap(map, RECORD_DATA_KEY_FIELDS, r.getRootEntityKeyValues());
addValuesToMap(map, RECORD_DATA_COUNT_FIELDS, r.getEntityCounts());
addValuesToMap(map, RECORD_DATA_QUALIFIER_FIELDS, r.getQualifierValues());
addValuesToMap(map, RECORD_DATA_SUMMARY_FIELDS, r.getDataSummaryValues());
Entity rootEntity = r.getRootEntity();
byte[] data = new ModelSerializer(SERIALIZATION_BUFFER_SIZE).toByteArray(rootEntity);
map.put(OFC_RECORD_DATA.DATA, data);
return map;
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class CollectValidator method isRootEntityKey.
private boolean isRootEntityKey(Attribute<?, ?> attribute) {
AttributeDefinition attrDef = attribute.getDefinition();
if (attrDef.isKey()) {
Record record = attribute.getRecord();
Entity rootEntity = record.getRootEntity();
EntityDefinition rootEntityDef = rootEntity.getDefinition();
List<AttributeDefinition> keyAttributeDefs = rootEntityDef.getKeyAttributeDefinitions();
for (AttributeDefinition keyDef : keyAttributeDefs) {
if (keyDef.getId() == attrDef.getId()) {
return true;
}
}
}
return false;
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class DataQueryResultItem method extractNodePath.
public String extractNodePath() {
Survey survey = record.getSurvey();
NodeDefinition attrDefn = survey.getSchema().getDefinitionById(query.getAttributeDefinitionId());
Entity parentEntity = (Entity) record.getNodeByInternalId(parentEntityId);
String path;
if (attrDefn.isMultiple()) {
path = String.format("%s/%s[%d]", parentEntity.getPath(), attrDefn.getName(), nodeIndex + 1);
} else {
path = String.format("%s/%s", parentEntity.getPath(), attrDefn.getName());
}
return path;
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class DataService method findAssignableCodeListItems.
/**
* Gets the code list items assignable to the specified attribute.
*
* @param parentEntityId
* @param attrName
* @return
*/
@Secured(USER)
public List<CodeListItemProxy> findAssignableCodeListItems(int parentEntityId, String attrName) {
CollectRecord record = getActiveRecord();
CollectSurvey survey = (CollectSurvey) record.getSurvey();
UserGroup surveyUserGroup = survey.getUserGroup();
User user = sessionManager.getLoggedUser();
final UserInGroup userInGroup = userGroupManager.findUserInGroupOrDescendants(surveyUserGroup, user);
if (userInGroup == null) {
throw new IllegalStateException(String.format("User %s not allowed to access survey %s", user.getUsername(), survey.getName()));
}
Entity parent = (Entity) record.getNodeByInternalId(parentEntityId);
CodeAttributeDefinition def = (CodeAttributeDefinition) parent.getDefinition().getChildDefinition(attrName);
List<CodeListItem> items = codeListManager.loadValidItems(parent, def);
List<CodeListItem> filteredItems = new ArrayList<CodeListItem>(items);
// filter by user group qualifier (if any)
UserGroup group = userGroupManager.loadById(userInGroup.getGroupId());
String qualifierName = group.getQualifier1Name();
String listHierarchicalLevelName = def.getList().isHierarchical() ? def.getHierarchicalLevel() : def.getListName();
if (qualifierName != null && qualifierName.equals(listHierarchicalLevelName)) {
CollectionUtils.filter(filteredItems, new Predicate<CodeListItem>() {
public boolean evaluate(CodeListItem item) {
return item.getCode().equals(group.getQualifier1Value());
}
});
}
List<CodeListItemProxy> result = CodeListItemProxy.fromList(filteredItems);
List<Node<?>> selectedCodes = parent.getChildren(attrName);
CodeListItemProxy.setSelectedItems(result, selectedCodes);
return result;
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class DataService method getCodeListItems.
/**
* Gets the code list items assignable to the specified attribute and matching the specified codes.
*
* @param parentEntityId
* @param attrName
* @param codes
* @return
*/
@Secured(USER)
public List<CodeListItemProxy> getCodeListItems(int parentEntityId, String attrName, String[] codes) {
CollectRecord record = getActiveRecord();
Entity parent = (Entity) record.getNodeByInternalId(parentEntityId);
CodeAttributeDefinition def = (CodeAttributeDefinition) parent.getDefinition().getChildDefinition(attrName);
List<CodeListItem> items = codeListManager.loadValidItems(parent, def);
List<CodeListItem> filteredItems = new ArrayList<CodeListItem>();
if (codes != null && codes.length > 0) {
// filter by specified codes
for (CodeListItem item : items) {
for (String code : codes) {
if (item.getCode().equals(code)) {
filteredItems.add(item);
}
}
}
}
List<CodeListItemProxy> result = CodeListItemProxy.fromList(filteredItems);
return result;
}
Aggregations