use of org.openforis.collect.event.EventProducer 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;
}
use of org.openforis.collect.event.EventProducer 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;
}
use of org.openforis.collect.event.EventProducer 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;
}
Aggregations