Search in sources :

Example 6 with RecordEvent

use of org.openforis.collect.event.RecordEvent in project collect by openforis.

the class RecordController method publishRecordPromotedEvents.

private void publishRecordPromotedEvents(CollectRecord record, String userName) {
    if (!eventQueue.isEnabled()) {
        return;
    }
    List<RecordEvent> events = new EventProducer().produceFor(record, userName);
    eventQueue.publish(new RecordTransaction(record.getSurvey().getName(), record.getId(), record.getStep().toRecordStep(), events));
}
Also used : EventProducer(org.openforis.collect.event.EventProducer) RecordEvent(org.openforis.collect.event.RecordEvent) RecordTransaction(org.openforis.collect.event.RecordTransaction)

Example 7 with RecordEvent

use of org.openforis.collect.event.RecordEvent in project collect by openforis.

the class CommandController method addOrUpdateAttributes.

@RequestMapping(value = "record/attributes", method = POST, consumes = APPLICATION_JSON_VALUE)
@Transactional
@ResponseBody
public List<RecordEventView> addOrUpdateAttributes(@RequestBody UpdateAttributesCommandWrapper commandsWrapper) {
    List<RecordEvent> events = new ArrayList<RecordEvent>();
    commandsWrapper.commands.forEach(c -> {
        UpdateAttributeCommand command = c.toCommand();
        events.addAll(commandDispatcher.submit(command));
    });
    return toView(events);
}
Also used : ArrayList(java.util.ArrayList) RecordEvent(org.openforis.collect.event.RecordEvent) UpdateAttributeCommand(org.openforis.collect.command.UpdateAttributeCommand) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Transactional(org.springframework.transaction.annotation.Transactional) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 8 with RecordEvent

use of org.openforis.collect.event.RecordEvent in project collect by openforis.

the class CommandController method updateAttribute.

@RequestMapping(value = "record/attribute", method = PATCH, consumes = APPLICATION_JSON_VALUE)
@Transactional
@ResponseBody
public List<RecordEventView> updateAttribute(@RequestBody UpdateAttributeCommandWrapper commandWrapper) {
    UpdateAttributeCommand command = commandWrapper.toCommand();
    List<RecordEvent> events = commandDispatcher.submit(command);
    return toView(events);
}
Also used : RecordEvent(org.openforis.collect.event.RecordEvent) UpdateAttributeCommand(org.openforis.collect.command.UpdateAttributeCommand) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Transactional(org.springframework.transaction.annotation.Transactional) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 9 with RecordEvent

use of org.openforis.collect.event.RecordEvent 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 10 with RecordEvent

use of org.openforis.collect.event.RecordEvent 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)

Aggregations

RecordEvent (org.openforis.collect.event.RecordEvent)11 EventProducer (org.openforis.collect.event.EventProducer)8 CollectRecord (org.openforis.collect.model.CollectRecord)6 NodeChangeSet (org.openforis.collect.model.NodeChangeSet)6 CollectSurvey (org.openforis.collect.model.CollectSurvey)3 Value (org.openforis.idm.model.Value)3 Transactional (org.springframework.transaction.annotation.Transactional)3 UpdateAttributeCommand (org.openforis.collect.command.UpdateAttributeCommand)2 RecordTransaction (org.openforis.collect.event.RecordTransaction)2 User (org.openforis.collect.model.User)2 MultipleEditException (org.openforis.collect.persistence.MultipleEditException)2 Secured (org.springframework.security.access.annotation.Secured)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 Connection (java.sql.Connection)1 ArrayList (java.util.ArrayList)1 RecordStep (org.openforis.collect.event.RecordStep)1 RecordIndexException (org.openforis.collect.manager.RecordIndexException)1 RecordPromoteException (org.openforis.collect.manager.RecordPromoteException)1 NodeChangeSetProxy (org.openforis.collect.model.proxy.NodeChangeSetProxy)1