Search in sources :

Example 1 with NodeChangeMap

use of org.openforis.collect.model.NodeChangeMap in project collect by openforis.

the class DataService method updateRecord.

private NodeChangeSet updateRecord(CollectRecord record, NodeUpdateRequestSet nodeUpdateRequestSet) throws RecordPersistenceException, RecordIndexException {
    List<NodeUpdateRequest> opts = nodeUpdateRequestSet.getRequests();
    NodeChangeMap result = new NodeChangeMap();
    for (NodeUpdateRequest req : opts) {
        NodeChangeSet partialChangeSet = updateRecord(record, req);
        result.addMergeChanges(partialChangeSet);
    }
    return result;
}
Also used : NodeChangeSet(org.openforis.collect.model.NodeChangeSet) NodeChangeMap(org.openforis.collect.model.NodeChangeMap)

Example 2 with NodeChangeMap

use of org.openforis.collect.model.NodeChangeMap in project collect by openforis.

the class RecordManager method addQualifierValues.

private void addQualifierValues(CollectRecord record, User user) {
    if (userGroupManager == null) {
        return;
    }
    NodeChangeMap changeSet = new NodeChangeMap();
    CollectSurvey survey = (CollectSurvey) record.getSurvey();
    UserGroup surveyUserGrup = survey.getUserGroup();
    UserInGroup userInGroup = userGroupManager.findUserInGroupOrDescendants(surveyUserGrup, user);
    if (userInGroup == null) {
        throw new IllegalArgumentException(String.format("User %s is not allowed to create records for survey %s", user.getUsername(), survey.getName()));
    }
    UserGroup group = userGroupManager.loadById(userInGroup.getGroupId());
    Map<String, String> qualifiersByName = group.getQualifiersByName();
    for (Entry<String, String> qualifier : qualifiersByName.entrySet()) {
        String attributePath = record.getRootEntity().getName() + "/" + qualifier.getKey();
        Attribute<?, Value> attribute = record.findNodeByPath(attributePath);
        Value qualifierValue = attribute.getDefinition().createValue(qualifier.getValue());
        NodeChangeSet changes = updater.updateAttribute(attribute, qualifierValue);
        changeSet.addMergeChanges(changes);
    }
}
Also used : NodeChangeSet(org.openforis.collect.model.NodeChangeSet) UserInGroup(org.openforis.collect.model.UserInGroup) Value(org.openforis.idm.model.Value) NodeChangeMap(org.openforis.collect.model.NodeChangeMap) CollectSurvey(org.openforis.collect.model.CollectSurvey) UserGroup(org.openforis.collect.model.UserGroup)

Aggregations

NodeChangeMap (org.openforis.collect.model.NodeChangeMap)2 NodeChangeSet (org.openforis.collect.model.NodeChangeSet)2 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 UserGroup (org.openforis.collect.model.UserGroup)1 UserInGroup (org.openforis.collect.model.UserInGroup)1 Value (org.openforis.idm.model.Value)1