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;
}
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);
}
}
Aggregations