Search in sources :

Example 1 with Entity

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;
}
Also used : Field(org.jooq.Field) TableField(org.jooq.TableField) RecordSummarySortField(org.openforis.collect.model.RecordSummarySortField) Entity(org.openforis.idm.model.Entity) HashMap(java.util.HashMap) ModelSerializer(org.openforis.idm.model.ModelSerializer)

Example 2 with Entity

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;
}
Also used : Entity(org.openforis.idm.model.Entity) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) Record(org.openforis.idm.model.Record) CollectRecord(org.openforis.collect.model.CollectRecord)

Example 3 with Entity

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;
}
Also used : Entity(org.openforis.idm.model.Entity) Survey(org.openforis.idm.metamodel.Survey) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 4 with Entity

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;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) User(org.openforis.collect.model.User) UserInGroup(org.openforis.collect.model.UserInGroup) Node(org.openforis.idm.model.Node) ArrayList(java.util.ArrayList) UserGroup(org.openforis.collect.model.UserGroup) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey) CodeListItem(org.openforis.idm.metamodel.CodeListItem) CodeListItemProxy(org.openforis.collect.metamodel.proxy.CodeListItemProxy) Secured(org.springframework.security.access.annotation.Secured)

Example 5 with Entity

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;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) ArrayList(java.util.ArrayList) CodeListItem(org.openforis.idm.metamodel.CodeListItem) CodeListItemProxy(org.openforis.collect.metamodel.proxy.CodeListItemProxy) Secured(org.springframework.security.access.annotation.Secured)

Aggregations

Entity (org.openforis.idm.model.Entity)164 Test (org.junit.Test)88 CollectRecord (org.openforis.collect.model.CollectRecord)37 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)36 Code (org.openforis.idm.model.Code)35 RealAttribute (org.openforis.idm.model.RealAttribute)25 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)23 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)19 Node (org.openforis.idm.model.Node)19 AbstractTest (org.openforis.idm.AbstractTest)18 Date (org.openforis.idm.model.Date)16 ArrayList (java.util.ArrayList)14 CodeAttribute (org.openforis.idm.model.CodeAttribute)14 Time (org.openforis.idm.model.Time)12 GregorianCalendar (java.util.GregorianCalendar)9 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)9 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)9 TextAttribute (org.openforis.idm.model.TextAttribute)9 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)8 Attribute (org.openforis.idm.model.Attribute)8