Search in sources :

Example 16 with User

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

the class SurveyController method unpublishSurvey.

@RequestMapping(value = "unpublish/{id}", method = POST)
@ResponseBody
public SurveyView unpublishSurvey(@PathVariable int id) throws SurveyStoreException {
    User activeUser = sessionManager.getLoggedUser();
    CollectSurvey survey = surveyManager.unpublish(id, activeUser);
    return generateView(survey, false);
}
Also used : User(org.openforis.collect.model.User) CollectSurvey(org.openforis.collect.model.CollectSurvey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 17 with User

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

the class SurveyController method cloneIntoTemporarySurvey.

@Transactional
@RequestMapping(value = "cloneintotemporary/{surveyId}", method = POST)
@ResponseBody
public Response cloneIntoTemporarySurvey(@PathVariable int surveyId) throws Exception {
    Response response = new Response();
    User loggedUser = sessionManager.getLoggedUser();
    CollectSurvey survey = surveyManager.getOrLoadSurveyById(surveyId);
    if (survey.isPublished()) {
        String surveyUri = survey.getUri();
        CollectSurvey temporarySurvey = surveyManager.createTemporarySurveyFromPublished(surveyUri, loggedUser);
        response.setObject(temporarySurvey.getId());
    } else {
        response.setErrorStatus();
        response.setErrorMessage(String.format("Survey with id %d is not published as expected", surveyId));
    }
    return response;
}
Also used : Response(org.openforis.commons.web.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) User(org.openforis.collect.model.User) CollectSurvey(org.openforis.collect.model.CollectSurvey) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 18 with User

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

the class ValidationController method validateAllRecords.

@RequestMapping(value = "/validateAllRecords.htm", method = RequestMethod.GET)
public void validateAllRecords(HttpServletRequest request, HttpServletResponse response, @RequestParam String s, @RequestParam String r) throws IOException {
    final ServletOutputStream outputStream = response.getOutputStream();
    try {
        if (s == null || r == null) {
            outputStream.println("Wrong parameters: please specify 's' (survey) and 'r' (root entity name).");
            return;
        }
        SessionState sessionState = getSessionState(request);
        final User user = sessionState.getUser();
        final String sessionId = sessionState.getSessionId();
        print(outputStream, "Starting validation of all records: ");
        final CollectSurvey survey = surveyManager.get(s);
        if (survey == null) {
            print(outputStream, "Survey not found");
            return;
        }
        RecordFilter filter = new RecordFilter(survey);
        filter.setRootEntityId(survey.getSchema().getRootEntityDefinition(r).getId());
        final ValidationMessageBuilder validationMessageHelper = ValidationMessageBuilder.createInstance(messageContextHolder);
        recordManager.visitSummaries(filter, null, new Visitor<CollectRecordSummary>() {

            public void visit(CollectRecordSummary summary) {
                try {
                    String recordKey = validationMessageHelper.getRecordKey(summary);
                    long start = System.currentTimeMillis();
                    print(outputStream, "Start validating record: " + recordKey);
                    Integer id = summary.getId();
                    Step step = summary.getStep();
                    recordManager.validateAndSave(survey, user, sessionId, id, step);
                    long elapsedMillis = System.currentTimeMillis() - start;
                    print(outputStream, "Validation of record " + recordKey + " completed in " + elapsedMillis + " millis");
                } catch (Exception e) {
                    try {
                        String message = "ERROR validating record " + summary.getId();
                        outputStream.println(message);
                        LOG.error(message);
                    } catch (IOException e1) {
                    }
                }
            }
        });
        print(outputStream, "End of validation of all records.");
    } catch (Exception e) {
        outputStream.println("ERROR - Validation of records not completed: " + e.getMessage());
        LOG.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}
Also used : ValidationMessageBuilder(org.openforis.collect.model.validation.ValidationMessageBuilder) SessionState(org.openforis.collect.web.session.SessionState) User(org.openforis.collect.model.User) ServletOutputStream(javax.servlet.ServletOutputStream) Step(org.openforis.collect.model.CollectRecord.Step) IOException(java.io.IOException) IOException(java.io.IOException) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with User

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

the class RecordController method newRecord.

@Transactional
@RequestMapping(value = "survey/{surveyId}/data/records", method = POST, consumes = APPLICATION_JSON_VALUE)
@ResponseBody
public RecordProxy newRecord(@PathVariable("surveyId") int surveyId, @RequestBody NewRecordParameters params) throws RecordPersistenceException {
    User user = sessionManager.getLoggedUser();
    if (user == null) {
        user = loadUser(params.getUserId(), params.getUsername());
    }
    CollectSurvey survey = surveyManager.getById(surveyId);
    params.setRootEntityName(ObjectUtils.defaultIfNull(params.getRootEntityName(), survey.getSchema().getFirstRootEntityDefinition().getName()));
    params.setVersionName(ObjectUtils.defaultIfNull(params.getVersionName(), survey.getLatestVersion() != null ? survey.getLatestVersion().getName() : null));
    params.setUserId(user.getId());
    CollectRecord record = recordGenerator.generate(surveyId, params, params.getRecordKey());
    return toProxy(record);
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) CollectSurvey(org.openforis.collect.model.CollectSurvey) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 20 with User

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

the class RecordManagerIntegrationTest method testNewRecordInsert.

@Test
public void testNewRecordInsert() {
    CollectRecord record = (CollectRecord) record(attribute("id", "10_117"), attribute("region", "002"), attribute("district", "003")).build(survey, "cluster", "2.0");
    new RecordUpdater().initializeNewRecord(record);
    User user = userManager.loadAdminUser();
    record.setCreatedBy(user);
    record.setCreationDate(new Date());
    record.setModifiedBy(user);
    record.setModifiedDate(new Date());
    recordManager.save(record);
    CollectRecord reloaded = recordManager.load(survey, record.getId());
    assertEquals(record, reloaded);
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) RecordUpdater(org.openforis.collect.model.RecordUpdater) Date(java.util.Date) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Aggregations

User (org.openforis.collect.model.User)71 CollectRecord (org.openforis.collect.model.CollectRecord)19 CollectSurvey (org.openforis.collect.model.CollectSurvey)19 SessionState (org.openforis.collect.web.session.SessionState)16 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)12 Transactional (org.springframework.transaction.annotation.Transactional)11 RecordFilter (org.openforis.collect.model.RecordFilter)10 Test (org.junit.Test)8 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)6 RecordUpdater (org.openforis.collect.model.RecordUpdater)6 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)5 Date (java.util.Date)4 UserGroup (org.openforis.collect.model.UserGroup)4 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)4 Secured (org.springframework.security.access.annotation.Secured)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 RecordStep (org.openforis.collect.event.RecordStep)3 Step (org.openforis.collect.model.CollectRecord.Step)3