Search in sources :

Example 46 with RecordFilter

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

the class RecordController method createRecordFilter.

private static RecordFilter createRecordFilter(CollectSurvey survey, User user, UserGroupManager userGroupManager, Integer rootEntityId, boolean onlyOwnedRecords) {
    if (rootEntityId == null) {
        rootEntityId = survey.getSchema().getFirstRootEntityDefinition().getId();
    }
    RecordFilter recordFilter = new RecordFilter(survey);
    recordFilter.setRootEntityId(rootEntityId);
    if (onlyOwnedRecords || user.getRole() == UserRole.ENTRY_LIMITED) {
        recordFilter.setOwnerId(user.getId());
    }
    if (user.getRole() != UserRole.ADMIN) {
        Map<String, String> qualifiers = userGroupManager.getQualifiers(survey.getUserGroup(), user);
        if (!qualifiers.isEmpty()) {
            recordFilter.setQualifiersByName(qualifiers);
        }
    }
    return recordFilter;
}
Also used : RecordFilter(org.openforis.collect.model.RecordFilter)

Example 47 with RecordFilter

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

the class RecordController method getCount.

@RequestMapping(value = "survey/{surveyId}/data/records/count.json", method = GET)
@ResponseBody
public int getCount(@PathVariable("surveyId") int surveyId, @RequestParam(value = "rootEntityDefinitionId", required = false) Integer rootEntityDefinitionId, @RequestParam(value = "step", required = false) Integer stepNumber) throws Exception {
    CollectSurvey survey = surveyManager.getById(surveyId);
    RecordFilter filter = createRecordFilter(survey, sessionManager.getLoggedUser(), userGroupManager, rootEntityDefinitionId, false);
    if (stepNumber != null) {
        filter.setStepGreaterOrEqual(Step.valueOf(stepNumber));
    }
    int count = recordManager.countRecords(filter);
    return count;
}
Also used : CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 48 with RecordFilter

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

the class ValidationController method validationReport.

@RequestMapping(value = "/validationReport", method = RequestMethod.GET)
public void validationReport(HttpServletRequest request, HttpServletResponse response, @RequestParam(required = false) String surveyName, @RequestParam(required = false) Integer rootEntityId, @RequestParam(required = false, defaultValue = "en_US") String locale, String[] recordKeys, @RequestParam(required = false) Date modifiedSince) throws IOException {
    ServletOutputStream outputStream = response.getOutputStream();
    try {
        if (surveyName == null || rootEntityId == null || locale == null) {
            outputStream.println("Wrong parameters: please specify 'surveyName' (name of the survey), 'rootEntityId' (root entity id) and 'locale' string rappresentation of locale");
            return;
        }
        CollectSurvey survey = surveyManager.get(surveyName);
        if (survey == null) {
            print(outputStream, "Survey not found");
            return;
        }
        response.setContentType("text/csv");
        String outputFileName = String.format("%s_validation_report_%s.csv", surveyName, Dates.formatDateTime(new Date()));
        response.setHeader("Content-Disposition", "attachment; fileName=" + outputFileName);
        SessionState sessionState = getSessionState(request);
        User user = sessionState.getUser();
        String sessionId = sessionState.getSessionId();
        RecordFilter recordFilter = new RecordFilter(survey, rootEntityId);
        recordFilter.setKeyValues(recordKeys);
        recordFilter.setModifiedSince(modifiedSince);
        if (user.getRole() == UserRole.ENTRY_LIMITED) {
            recordFilter.setOwnerId(user.getId());
        }
        ValidationReportProcess process = new ValidationReportProcess(outputStream, recordManager, messageContextHolder, ReportType.CSV, user, sessionId, recordFilter, true, LocaleUtils.toLocale(locale));
        process.init();
        process.call();
    } catch (Exception e) {
        // outputStream.println("ERROR - Validation of records not completed: " + e.getMessage());
        LOG.error("ERROR - Validation of records not completed: " + e.getMessage(), e);
        throw new RuntimeException(e);
    }
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) User(org.openforis.collect.model.User) ServletOutputStream(javax.servlet.ServletOutputStream) ValidationReportProcess(org.openforis.collect.manager.ValidationReportProcess) CollectSurvey(org.openforis.collect.model.CollectSurvey) Date(java.util.Date) RecordFilter(org.openforis.collect.model.RecordFilter) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 49 with RecordFilter

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

the class RecordManager method loadUniqueRecordSummary.

public CollectRecordSummary loadUniqueRecordSummary(CollectSurvey survey, int recordId) {
    RecordFilter filter = new RecordFilter(survey);
    filter.setRecordId(recordId);
    List<CollectRecordSummary> summaries = loadSummaries(filter);
    return summaries.isEmpty() ? null : summaries.get(0);
}
Also used : CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 50 with RecordFilter

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

the class RecordManager method countRecords.

public int countRecords(CollectSurvey survey, String rootEntity, String... keyValues) {
    RecordFilter filter = new RecordFilter(survey, rootEntity);
    filter.setKeyValues(keyValues);
    return countRecords(filter);
}
Also used : RecordFilter(org.openforis.collect.model.RecordFilter)

Aggregations

RecordFilter (org.openforis.collect.model.RecordFilter)66 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)33 CollectSurvey (org.openforis.collect.model.CollectSurvey)27 CollectRecord (org.openforis.collect.model.CollectRecord)14 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 Date (java.util.Date)10 User (org.openforis.collect.model.User)10 SessionState (org.openforis.collect.web.session.SessionState)7 Transactional (org.springframework.transaction.annotation.Transactional)7 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 File (java.io.File)5 HashMap (java.util.HashMap)5 CSVDataExportParameters (org.openforis.collect.io.data.csv.CSVDataExportParameters)5 Step (org.openforis.collect.model.CollectRecord.Step)5 IOException (java.io.IOException)4 SurveyBackupJob (org.openforis.collect.io.SurveyBackupJob)4 CSVDataExportJob (org.openforis.collect.io.data.CSVDataExportJob)4 Schema (org.openforis.idm.metamodel.Schema)4 Test (org.junit.Test)3