Search in sources :

Example 1 with DataReportItem

use of org.openforis.collect.datacleansing.DataReportItem in project collect by openforis.

the class DataReportController method loadItems.

@RequestMapping(value = "{reportId}/items.json", method = GET)
@ResponseBody
public PaginatedResponse loadItems(@PathVariable int reportId, @RequestParam int offset, @RequestParam int limit) {
    CollectSurvey survey = sessionManager.getActiveSurvey();
    DataReport report = itemManager.loadById(survey, reportId);
    int total = itemManager.countItems(report);
    List<DataReportItem> items = itemManager.loadItems(report, offset, limit);
    List<DataReportItemForm> rows = new ArrayList<DataReportItemForm>(items.size());
    for (DataReportItem item : items) {
        rows.add(new DataReportItemForm(item));
    }
    return new PaginatedResponse(total, rows);
}
Also used : DataReportItem(org.openforis.collect.datacleansing.DataReportItem) PaginatedResponse(org.openforis.collect.web.controller.PaginatedResponse) DataReportItemForm(org.openforis.collect.datacleansing.form.DataReportItemForm) DataReport(org.openforis.collect.datacleansing.DataReport) ArrayList(java.util.ArrayList) CollectSurvey(org.openforis.collect.model.CollectSurvey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with DataReportItem

use of org.openforis.collect.datacleansing.DataReportItem in project collect by openforis.

the class DataReportItemDao method insert.

public void insert(DataReport report, List<DataReportItem> items) {
    JooqDSLContext dsl = dsl(report);
    int nextId = dsl.nextId();
    int maxId = nextId;
    Insert<OfcDataReportItemRecord> insert = dsl.createInsertStatement();
    BatchBindStep batch = dsl.batch(insert);
    for (DataReportItem item : items) {
        Integer id = item.getId();
        if (id == null) {
            id = nextId++;
            item.setId(id);
        }
        Object[] values = dsl.extractValues(item);
        batch.bind(values);
        maxId = Math.max(maxId, id);
    }
    batch.execute();
    dsl.restartSequence(maxId + 1);
}
Also used : DataReportItem(org.openforis.collect.datacleansing.DataReportItem) OfcDataReportItemRecord(org.openforis.collect.persistence.jooq.tables.records.OfcDataReportItemRecord) BatchBindStep(org.jooq.BatchBindStep)

Example 3 with DataReportItem

use of org.openforis.collect.datacleansing.DataReportItem in project collect by openforis.

the class DataReportManager method loadItems.

public List<DataReportItem> loadItems(DataReport report, Integer offset, Integer limit) {
    CollectSurvey survey = report.getSurvey();
    Map<Integer, CollectRecord> recordCache = new HashMap<Integer, CollectRecord>();
    List<DataReportItem> items = dataReportItemDao.loadByReport(report, offset, limit);
    for (DataReportItem item : items) {
        int recordId = item.getRecordId();
        CollectRecord record = recordCache.get(recordId);
        if (record == null) {
            record = recordManager.load(survey, recordId, report.getRecordStep(), false);
            recordCache.put(recordId, record);
        }
        item.setRecord(record);
    }
    return items;
}
Also used : DataReportItem(org.openforis.collect.datacleansing.DataReportItem) CollectRecord(org.openforis.collect.model.CollectRecord) HashMap(java.util.HashMap) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Aggregations

DataReportItem (org.openforis.collect.datacleansing.DataReportItem)3 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 BatchBindStep (org.jooq.BatchBindStep)1 DataReport (org.openforis.collect.datacleansing.DataReport)1 DataReportItemForm (org.openforis.collect.datacleansing.form.DataReportItemForm)1 CollectRecord (org.openforis.collect.model.CollectRecord)1 OfcDataReportItemRecord (org.openforis.collect.persistence.jooq.tables.records.OfcDataReportItemRecord)1 PaginatedResponse (org.openforis.collect.web.controller.PaginatedResponse)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1