Search in sources :

Example 11 with NodeChangeSet

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

the class CSVDataImportProcess method setUnitField.

private void setUnitField(Attribute<?, ?> attr, String value, long row, String colName) {
    if (StringUtils.isBlank(value)) {
        ((NumberAttribute<?, ?>) attr).setUnit(null);
    } else {
        Survey survey = attr.getSurvey();
        Unit unit = survey.getUnit(value);
        NumericAttributeDefinition defn = (NumericAttributeDefinition) attr.getDefinition();
        if (unit == null || !defn.getUnits().contains(unit)) {
            ParsingError parsingError = new ParsingError(ErrorType.INVALID_VALUE, row, colName, UNIT_NOT_FOUND_MESSAGE_KEY);
            parsingError.setMessageArgs(new String[] { value });
            status.addParsingError(parsingError);
        } else {
            Field<Integer> field = ((NumberAttribute<?, ?>) attr).getUnitField();
            NodeChangeSet changes = recordUpdater.updateField(field, unit.getId());
            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) NumberAttribute(org.openforis.idm.model.NumberAttribute) Unit(org.openforis.idm.metamodel.Unit) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition)

Example 12 with NodeChangeSet

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

the class CreateRecordHandler method execute.

@Override
public List<RecordEvent> execute(CreateRecordCommand command) {
    String username = command.getUsername();
    User user = userManager.loadByUserName(username);
    CollectSurvey survey = surveyManager.getById(command.getSurveyId());
    List<EntityDefinition> rootDefs = survey.getSchema().getRootEntityDefinitions();
    EntityDefinition firstRootEntity = rootDefs.get(0);
    String firstRootEntityName = firstRootEntity.getName();
    CollectRecord record = recordManager.instantiateRecord(survey, firstRootEntityName, user, command.getFormVersion(), Step.ENTRY);
    NodeChangeSet changeSet = recordManager.initializeRecord(record);
    List<String> keyValues = command.getKeyValues();
    Iterator<String> keyValuesIt = keyValues.iterator();
    List<AttributeDefinition> keyAttributeDefinitions = firstRootEntity.getKeyAttributeDefinitions();
    Iterator<AttributeDefinition> keyDefsIt = keyAttributeDefinitions.iterator();
    while (keyDefsIt.hasNext()) {
        AttributeDefinition keyDef = keyDefsIt.next();
        String keyVal = keyValuesIt.next();
        Value keyValue = keyDef.createValue(keyVal);
        Attribute<?, Value> keyAttr = record.findNodeByPath(keyDef.getPath());
        recordUpdater.updateAttribute(keyAttr, keyValue);
    }
    recordManager.save(record);
    List<RecordEvent> events = new EventProducer().produceFor(changeSet, user.getUsername());
    for (RecordEvent recordEvent : events) {
        recordEvent.initializeRecordId(record.getId());
    }
    return events;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) NodeChangeSet(org.openforis.collect.model.NodeChangeSet) User(org.openforis.collect.model.User) EventProducer(org.openforis.collect.event.EventProducer) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) RecordEvent(org.openforis.collect.event.RecordEvent) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Value(org.openforis.idm.model.Value) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 13 with NodeChangeSet

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

the class DeleteNodeCommandHandler method execute.

@Override
public List<RecordEvent> execute(C command) {
    CollectRecord record = findRecord(command);
    Attribute<?, Value> attribute = findAttribute(command, record);
    NodeChangeSet changeSet = recordUpdater.deleteNode(attribute);
    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) Value(org.openforis.idm.model.Value) EventProducer(org.openforis.collect.event.EventProducer) RecordEvent(org.openforis.collect.event.RecordEvent)

Example 14 with NodeChangeSet

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

the class DataService method createRecord.

@Secured(ENTRY)
public RecordProxy createRecord(String rootEntityName, String versionName, Step recordStep) throws RecordPersistenceException, RecordIndexException {
    SessionState sessionState = sessionManager.getSessionState();
    if (sessionState.isActiveRecordBeingEdited()) {
        throw new MultipleEditException();
    }
    CollectSurvey activeSurvey = sessionState.getActiveSurvey();
    User user = sessionState.getUser();
    CollectRecord record = recordManager.instantiateRecord(activeSurvey, rootEntityName, user, versionName, recordStep);
    NodeChangeSet changeSet = recordManager.initializeRecord(record);
    List<RecordEvent> events = new EventProducer().produceFor(changeSet, user.getUsername());
    sessionManager.onEvents(events);
    sessionManager.setActiveRecord(record);
    prepareRecordIndexing();
    RecordProxy recordProxy = new RecordProxy(record, getProxyContext(), true);
    return recordProxy;
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectRecord(org.openforis.collect.model.CollectRecord) NodeChangeSet(org.openforis.collect.model.NodeChangeSet) RecordProxy(org.openforis.collect.model.proxy.RecordProxy) User(org.openforis.collect.model.User) EventProducer(org.openforis.collect.event.EventProducer) MultipleEditException(org.openforis.collect.persistence.MultipleEditException) RecordEvent(org.openforis.collect.event.RecordEvent) CollectSurvey(org.openforis.collect.model.CollectSurvey) Secured(org.springframework.security.access.annotation.Secured)

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