Search in sources :

Example 1 with NodeChangeSet

use of org.openforis.collect.model.NodeChangeSet 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 NodeChangeSet

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

the class DataService method updateActiveRecord.

@Transactional
@Secured(ENTRY_LIMITED)
public NodeChangeSetProxy updateActiveRecord(NodeUpdateRequestSetProxy requestSet) throws RecordPersistenceException, RecordIndexException {
    sessionManager.checkIsActiveRecordLocked();
    CollectRecord activeRecord = getActiveRecord();
    NodeUpdateRequestSet reqSet = requestSet.toNodeUpdateRequestSet(codeListManager, sessionManager, activeRecord);
    NodeChangeSet changeSet = updateRecord(activeRecord, reqSet);
    if (!changeSet.isEmpty() && isCurrentRecordIndexable()) {
        recordIndexService.temporaryIndex(activeRecord);
    }
    String userName = sessionManager.getSessionState().getUser().getUsername();
    List<RecordEvent> events = new EventProducer().produceFor(changeSet, userName);
    sessionManager.onEvents(events);
    NodeChangeSetProxy result = new NodeChangeSetProxy(activeRecord, changeSet, getProxyContext());
    if (requestSet.isAutoSave()) {
        try {
            saveActiveRecord();
            result.setRecordSaved(true);
        } catch (Exception e) {
            result.setRecordSaved(false);
        }
    }
    return result;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) NodeChangeSet(org.openforis.collect.model.NodeChangeSet) EventProducer(org.openforis.collect.event.EventProducer) RecordEvent(org.openforis.collect.event.RecordEvent) NodeChangeSetProxy(org.openforis.collect.model.proxy.NodeChangeSetProxy) RecordPromoteException(org.openforis.collect.manager.RecordPromoteException) RecordUnlockedException(org.openforis.collect.persistence.RecordUnlockedException) RecordIndexException(org.openforis.collect.manager.RecordIndexException) RecordLockedException(org.openforis.collect.persistence.RecordLockedException) MultipleEditException(org.openforis.collect.persistence.MultipleEditException) RecordPersistenceException(org.openforis.collect.persistence.RecordPersistenceException) Secured(org.springframework.security.access.annotation.Secured) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with NodeChangeSet

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

the class CSVDataImportProcess method setSRSIdField.

private void setSRSIdField(Attribute<?, ?> attr, String value, long row, String colName) {
    boolean valid = true;
    if (StringUtils.isNotBlank(value)) {
        // check SRS id validity
        Survey survey = attr.getSurvey();
        SpatialReferenceSystem srs = survey.getSpatialReferenceSystem(value);
        if (srs == null) {
            ParsingError parsingError = new ParsingError(ErrorType.INVALID_VALUE, row, colName, SRS_NOT_FOUND_MESSAGE_KEY);
            parsingError.setMessageArgs(new String[] { value });
            status.addParsingError(parsingError);
            valid = false;
        }
    }
    if (valid) {
        Field<String> field = ((CoordinateAttribute) attr).getSrsIdField();
        NodeChangeSet changes = recordUpdater.updateField(field, value);
        if (nodeChangeBatchProcessor != null) {
            nodeChangeBatchProcessor.add(changes, adminUser.getUsername());
        }
    }
}
Also used : NodeChangeSet(org.openforis.collect.model.NodeChangeSet) CollectSurvey(org.openforis.collect.model.CollectSurvey) Survey(org.openforis.idm.metamodel.Survey) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) CoordinateAttribute(org.openforis.idm.model.CoordinateAttribute) SpatialReferenceSystem(org.openforis.idm.metamodel.SpatialReferenceSystem)

Example 4 with NodeChangeSet

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

the class AddNodeCommandHandler method execute.

@Override
public List<RecordEvent> execute(C command) {
    CollectRecord record = findRecord(command);
    Entity parentEntity = record.findNodeByPath(command.getParentEntityPath());
    NodeDefinition nodeDef = parentEntity.getDefinition().getChildDefinition(command.getNodeDefId());
    NodeChangeSet changeSet = recordUpdater.addNode(parentEntity, nodeDef);
    recordManager.save(record);
    List<RecordEvent> events = new EventProducer().produceFor(changeSet, command.getUsername());
    return events;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) NodeChangeSet(org.openforis.collect.model.NodeChangeSet) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) EventProducer(org.openforis.collect.event.EventProducer) RecordEvent(org.openforis.collect.event.RecordEvent)

Example 5 with NodeChangeSet

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

the class UpdateAttributeCommandHandler method execute.

@Override
public List<RecordEvent> execute(UpdateAttributeCommand command) {
    CollectRecord record = findRecord(command);
    Attribute<?, Value> attribute = findAttribute(command, record);
    Value value = extractValue(command);
    NodeChangeSet changeSet = recordUpdater.updateAttribute(attribute, value);
    recordManager.save(record);
    List<RecordEvent> events = new EventProducer().produceFor(changeSet, command.getUsername());
    return events;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) NodeChangeSet(org.openforis.collect.model.NodeChangeSet) BooleanValue(org.openforis.idm.model.BooleanValue) Value(org.openforis.idm.model.Value) EventProducer(org.openforis.collect.event.EventProducer) RecordEvent(org.openforis.collect.event.RecordEvent)

Aggregations

NodeChangeSet (org.openforis.collect.model.NodeChangeSet)14 CollectRecord (org.openforis.collect.model.CollectRecord)7 EventProducer (org.openforis.collect.event.EventProducer)6 RecordEvent (org.openforis.collect.event.RecordEvent)6 CollectSurvey (org.openforis.collect.model.CollectSurvey)6 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)4 Entity (org.openforis.idm.model.Entity)4 Value (org.openforis.idm.model.Value)4 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)3 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)3 NodeChangeMap (org.openforis.collect.model.NodeChangeMap)2 User (org.openforis.collect.model.User)2 MultipleEditException (org.openforis.collect.persistence.MultipleEditException)2 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)2 Survey (org.openforis.idm.metamodel.Survey)2 Secured (org.springframework.security.access.annotation.Secured)2 Entry (java.util.Map.Entry)1 FieldValueKey (org.openforis.collect.io.data.DataLine.FieldValueKey)1 RecordIndexException (org.openforis.collect.manager.RecordIndexException)1 RecordPromoteException (org.openforis.collect.manager.RecordPromoteException)1