Search in sources :

Example 1 with BulkRecordMoveJob

use of org.openforis.collect.io.data.BulkRecordMoveJob in project collect by openforis.

the class RecordController method moveRecords.

@RequestMapping(value = "survey/{surveyId}/data/move/records", method = POST, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public JobProxy moveRecords(@PathVariable("surveyId") int surveyId, @RequestParam String fromStep, @RequestParam boolean promote) {
    BulkRecordMoveJob job = jobManager.createJob(BulkRecordMoveJob.class);
    SessionState sessionState = sessionManager.getSessionState();
    User loggedUser = sessionState.getUser();
    CollectSurvey survey = surveyManager.getById(surveyId);
    EntityDefinition rootEntityDef = survey.getSchema().getFirstRootEntityDefinition();
    job.setSurvey(survey);
    job.setRootEntity(rootEntityDef.getName());
    job.setPromote(promote);
    job.setFromStep(Step.valueOf(fromStep));
    job.setUser(loggedUser);
    job.setRecordMovedCallback(new BulkRecordMoveJob.Callback() {

        @Override
        public void recordMoved(CollectRecord record) {
            if (promote) {
                publishRecordPromotedEvents(record, loggedUser.getUsername());
            } else {
                publishRecordDeletedEvent(record, RecordStep.valueOf(fromStep), loggedUser.getUsername());
            }
        }
    });
    jobManager.startSurveyJob(job);
    return new JobProxy(job);
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) JobProxy(org.openforis.concurrency.proxy.JobProxy) CollectSurvey(org.openforis.collect.model.CollectSurvey) BulkRecordMoveJob(org.openforis.collect.io.data.BulkRecordMoveJob) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with BulkRecordMoveJob

use of org.openforis.collect.io.data.BulkRecordMoveJob in project collect by openforis.

the class DataService method moveRecords.

@Secured(CLEANSING)
public SurveyLockingJobProxy moveRecords(String rootEntity, int fromStepNumber, final boolean promote) {
    BulkRecordMoveJob job = collectJobManager.createJob(BulkRecordMoveJob.class);
    SessionState sessionState = getSessionState();
    final String userName = sessionState.getUser().getUsername();
    job.setSurvey(sessionState.getActiveSurvey());
    job.setRootEntity(rootEntity);
    job.setPromote(promote);
    final Step fromStep = Step.valueOf(fromStepNumber);
    job.setFromStep(fromStep);
    job.setUser(sessionState.getUser());
    job.setRecordMovedCallback(new BulkRecordMoveJob.Callback() {

        @Override
        public void recordMoved(CollectRecord record) {
            if (promote) {
                publishRecordPromotedEvents(record, userName);
            } else {
                publishRecordDeletedEvent(record, fromStep.toRecordStep(), userName);
            }
        }
    });
    collectJobManager.startSurveyJob(job);
    return new SurveyLockingJobProxy(job);
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectRecord(org.openforis.collect.model.CollectRecord) RecordStep(org.openforis.collect.event.RecordStep) Step(org.openforis.collect.model.CollectRecord.Step) SurveyLockingJobProxy(org.openforis.collect.remoting.service.concurrency.proxy.SurveyLockingJobProxy) BulkRecordMoveJob(org.openforis.collect.io.data.BulkRecordMoveJob) Secured(org.springframework.security.access.annotation.Secured)

Aggregations

BulkRecordMoveJob (org.openforis.collect.io.data.BulkRecordMoveJob)2 CollectRecord (org.openforis.collect.model.CollectRecord)2 SessionState (org.openforis.collect.web.session.SessionState)2 RecordStep (org.openforis.collect.event.RecordStep)1 Step (org.openforis.collect.model.CollectRecord.Step)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 User (org.openforis.collect.model.User)1 SurveyLockingJobProxy (org.openforis.collect.remoting.service.concurrency.proxy.SurveyLockingJobProxy)1 JobProxy (org.openforis.concurrency.proxy.JobProxy)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 Secured (org.springframework.security.access.annotation.Secured)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1