Search in sources :

Example 51 with DataSet

use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.

the class VersionedObjectObjectBundleHook method postTypeImport.

@Override
public <T extends IdentifiableObject> void postTypeImport(Class<? extends IdentifiableObject> klass, List<T> objects, ObjectBundle bundle) {
    if (Section.class.isAssignableFrom(klass)) {
        Set<DataSet> dataSets = new HashSet<>();
        objects.forEach(o -> {
            DataSet dataSet = ((Section) o).getDataSet();
            if (dataSet.getId() > 0) {
                dataSets.add(dataSet);
            }
        });
        dataSets.forEach(ds -> {
            ds.increaseVersion();
            sessionFactory.getCurrentSession().save(ds);
        });
    } else if (Option.class.isAssignableFrom(klass)) {
        Set<OptionSet> optionSets = new HashSet<>();
        objects.forEach(o -> {
            Option option = (Option) o;
            if (option.getOptionSet() != null && option.getId() > 0) {
                optionSets.add(option.getOptionSet());
            }
        });
        optionSets.forEach(os -> {
            os.increaseVersion();
            sessionFactory.getCurrentSession().save(os);
        });
    }
}
Also used : HashSet(java.util.HashSet) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Option(org.hisp.dhis.option.Option) List(java.util.List) ObjectBundle(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle) OptionSet(org.hisp.dhis.option.OptionSet) VersionedObject(org.hisp.dhis.common.VersionedObject) DataSet(org.hisp.dhis.dataset.DataSet) Set(java.util.Set) Section(org.hisp.dhis.dataset.Section) HashSet(java.util.HashSet) OptionSet(org.hisp.dhis.option.OptionSet) DataSet(org.hisp.dhis.dataset.DataSet) Set(java.util.Set) DataSet(org.hisp.dhis.dataset.DataSet) Option(org.hisp.dhis.option.Option) Section(org.hisp.dhis.dataset.Section) HashSet(java.util.HashSet)

Example 52 with DataSet

use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.

the class ReportTableTest method setUpTest.

// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    dataElements = new ArrayList<>();
    categoryOptionCombos = new ArrayList<>();
    indicators = new ArrayList<>();
    reportingRates = new ArrayList<>();
    periods = new ArrayList<>();
    units = new ArrayList<>();
    relativeUnits = new ArrayList<>();
    groups = new ArrayList<>();
    montlyPeriodType = PeriodType.getPeriodTypeByName(MonthlyPeriodType.NAME);
    dataElementA = createDataElement('A');
    dataElementB = createDataElement('B');
    dataElementA.setId('A');
    dataElementB.setId('B');
    dataElements.add(dataElementA);
    dataElements.add(dataElementB);
    deGroupSetA = createDataElementGroupSet('A');
    deGroupA = createDataElementGroup('A');
    deGroupB = createDataElementGroup('B');
    deGroupA.getGroupSets().add(deGroupSetA);
    deGroupB.getGroupSets().add(deGroupSetA);
    deGroupSetA.getMembers().add(deGroupA);
    deGroupSetA.getMembers().add(deGroupB);
    categoryOptionComboA = createCategoryOptionCombo('A', 'A', 'B');
    categoryOptionComboB = createCategoryOptionCombo('B', 'C', 'D');
    categoryOptionComboA.setId('A');
    categoryOptionComboB.setId('B');
    categoryOptionCombos.add(categoryOptionComboA);
    categoryOptionCombos.add(categoryOptionComboB);
    categoryCombo = new DataElementCategoryCombo("CategoryComboA", DataDimensionType.DISAGGREGATION);
    categoryCombo.setId('A');
    categoryCombo.setOptionCombos(new HashSet<>(categoryOptionCombos));
    indicatorType = createIndicatorType('A');
    indicatorA = createIndicator('A', indicatorType);
    indicatorB = createIndicator('B', indicatorType);
    indicatorA.setId('A');
    indicatorB.setId('B');
    indicators.add(indicatorA);
    indicators.add(indicatorB);
    DataSet dataSetA = createDataSet('A', montlyPeriodType);
    DataSet dataSetB = createDataSet('B', montlyPeriodType);
    dataSetA.setId('A');
    dataSetB.setId('B');
    reportingRateA = new ReportingRate(dataSetA);
    reportingRateB = new ReportingRate(dataSetB);
    reportingRates.add(reportingRateA);
    reportingRates.add(reportingRateB);
    periodA = createPeriod(montlyPeriodType, getDate(2008, 1, 1), getDate(2008, 1, 31));
    periodB = createPeriod(montlyPeriodType, getDate(2008, 2, 1), getDate(2008, 2, 28));
    periodA.setId('A');
    periodB.setId('B');
    periods.add(periodA);
    periods.add(periodB);
    relatives = new RelativePeriods();
    relatives.setLastMonth(true);
    relatives.setThisYear(true);
    List<Period> rp = relatives.getRelativePeriods();
    periodC = rp.get(0);
    periodD = rp.get(1);
    unitA = createOrganisationUnit('A');
    unitB = createOrganisationUnit('B', unitA);
    unitC = createOrganisationUnit('C', unitA);
    unitA.setId('A');
    unitB.setId('B');
    unitC.setId('C');
    unitA.getChildren().add(unitB);
    unitA.getChildren().add(unitC);
    units.add(unitA);
    units.add(unitB);
    relativeUnits.add(unitA);
    ouGroupSetA = createOrganisationUnitGroupSet('A');
    ouGroupA = createOrganisationUnitGroup('A');
    ouGroupB = createOrganisationUnitGroup('B');
    ouGroupA.getGroupSets().add(ouGroupSetA);
    ouGroupB.getGroupSets().add(ouGroupSetA);
    ouGroupA.setId('A');
    ouGroupB.setId('B');
    ouGroupSetA.getOrganisationUnitGroups().add(ouGroupA);
    ouGroupSetA.getOrganisationUnitGroups().add(ouGroupB);
    groups.add(ouGroupA);
    groups.add(ouGroupB);
    i18nFormat = new MockI18nFormat();
}
Also used : MockI18nFormat(org.hisp.dhis.mock.MockI18nFormat) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) RelativePeriods(org.hisp.dhis.period.RelativePeriods) DataSet(org.hisp.dhis.dataset.DataSet) ReportingRate(org.hisp.dhis.common.ReportingRate) Period(org.hisp.dhis.period.Period)

Example 53 with DataSet

use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.

the class CreateSMSCommandForm method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    SMSCommand command = new SMSCommand();
    command.setName(name);
    command.setParserType(parserType);
    if (parserType.equals(ParserType.KEY_VALUE_PARSER) || parserType.equals(ParserType.J2ME_PARSER)) {
        DataSet dataset = dataSetService.getDataSet(selectedDataSetID);
        command.setDataset(dataset);
    } else if (parserType.equals(ParserType.ALERT_PARSER) || parserType.equals(ParserType.UNREGISTERED_PARSER)) {
        UserGroup userGroup = new UserGroup();
        userGroup = userGroupService.getUserGroup(userGroupID);
        command.setUserGroup(userGroup);
    } else if (parserType.equals(ParserType.TRACKED_ENTITY_REGISTRATION_PARSER)) {
        Program program = programService.getProgram(selectedProgramId);
        command.setProgram(program);
    } else if (parserType.equals(ParserType.EVENT_REGISTRATION_PARSER)) {
        Program program = programService.getProgram(selectedProgramIdWithoutRegistration);
        command.setProgram(program);
        command.setProgramStage(program.getProgramStages().iterator().next());
    }
    smsCommandService.save(command);
    return SUCCESS;
}
Also used : Program(org.hisp.dhis.program.Program) DataSet(org.hisp.dhis.dataset.DataSet) SMSCommand(org.hisp.dhis.sms.command.SMSCommand) UserGroup(org.hisp.dhis.user.UserGroup)

Example 54 with DataSet

use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.

the class DefaultAdxDataService method saveDataValueSetInternal.

private ImportSummary saveDataValueSetInternal(InputStream in, ImportOptions importOptions, TaskId id) {
    notifier.clear(id).notify(id, "ADX parsing process started");
    ImportOptions adxImportOptions = ObjectUtils.firstNonNull(importOptions, ImportOptions.getDefaultImportOptions()).instance().setNotificationLevel(NotificationLevel.OFF);
    // Get import options
    IdScheme dataSetIdScheme = importOptions.getIdSchemes().getDataSetIdScheme();
    IdScheme dataElementIdScheme = importOptions.getIdSchemes().getDataElementIdScheme();
    // Create meta-data maps
    CachingMap<String, DataSet> dataSetMap = new CachingMap<>();
    CachingMap<String, DataElement> dataElementMap = new CachingMap<>();
    // Get meta-data maps
    IdentifiableObjectCallable<DataSet> dataSetCallable = new IdentifiableObjectCallable<>(identifiableObjectManager, DataSet.class, dataSetIdScheme, null);
    IdentifiableObjectCallable<DataElement> dataElementCallable = new IdentifiableObjectCallable<>(identifiableObjectManager, DataElement.class, dataElementIdScheme, null);
    // Heat cache
    if (importOptions.isPreheatCacheDefaultFalse()) {
        dataSetMap.load(identifiableObjectManager.getAll(DataSet.class), o -> o.getPropertyValue(dataSetIdScheme));
        dataElementMap.load(identifiableObjectManager.getAll(DataElement.class), o -> o.getPropertyValue(dataElementIdScheme));
    }
    XMLReader adxReader = XMLFactory.getXMLReader(in);
    ImportSummary importSummary;
    adxReader.moveToStartElement(AdxDataService.ROOT, AdxDataService.NAMESPACE);
    ExecutorService executor = Executors.newSingleThreadExecutor();
    // Give the DXF import a different notification task ID so it doesn't conflict with notifications from this level.
    TaskId dxfTaskId = new TaskId(TaskCategory.DATAVALUE_IMPORT_INTERNAL, id.getUser());
    int groupCount = 0;
    try (PipedOutputStream pipeOut = new PipedOutputStream()) {
        Future<ImportSummary> futureImportSummary = executor.submit(new AdxPipedImporter(dataValueSetService, adxImportOptions, dxfTaskId, pipeOut, sessionFactory));
        XMLOutputFactory factory = XMLOutputFactory.newInstance();
        XMLStreamWriter dxfWriter = factory.createXMLStreamWriter(pipeOut);
        List<ImportConflict> adxConflicts = new LinkedList<>();
        dxfWriter.writeStartDocument("1.0");
        dxfWriter.writeStartElement("dataValueSet");
        dxfWriter.writeDefaultNamespace("http://dhis2.org/schema/dxf/2.0");
        notifier.notify(id, "Starting to import ADX data groups.");
        while (adxReader.moveToStartElement(AdxDataService.GROUP, AdxDataService.NAMESPACE)) {
            notifier.update(id, "Importing ADX data group: " + groupCount);
            // note this returns conflicts which are detected at ADX level
            adxConflicts.addAll(parseAdxGroupToDxf(adxReader, dxfWriter, adxImportOptions, dataSetMap, dataSetCallable, dataElementMap, dataElementCallable));
            groupCount++;
        }
        // end dataValueSet
        dxfWriter.writeEndElement();
        dxfWriter.writeEndDocument();
        pipeOut.flush();
        importSummary = futureImportSummary.get(TOTAL_MINUTES_TO_WAIT, TimeUnit.MINUTES);
        importSummary.getConflicts().addAll(adxConflicts);
        importSummary.getImportCount().incrementIgnored(adxConflicts.size());
    } catch (AdxException ex) {
        importSummary = new ImportSummary();
        importSummary.setStatus(ImportStatus.ERROR);
        importSummary.setDescription("Data set import failed within group number: " + groupCount);
        importSummary.getConflicts().add(ex.getImportConflict());
        notifier.update(id, NotificationLevel.ERROR, "ADX data import done", true);
        log.warn("Import failed: " + DebugUtils.getStackTrace(ex));
    } catch (IOException | XMLStreamException | InterruptedException | ExecutionException | TimeoutException ex) {
        importSummary = new ImportSummary();
        importSummary.setStatus(ImportStatus.ERROR);
        importSummary.setDescription("Data set import failed within group number: " + groupCount);
        notifier.update(id, NotificationLevel.ERROR, "ADX data import done", true);
        log.warn("Import failed: " + DebugUtils.getStackTrace(ex));
    }
    executor.shutdown();
    notifier.update(id, INFO, "ADX data import done", true).addTaskSummary(id, importSummary);
    ImportCount c = importSummary.getImportCount();
    log.info("ADX data import done, imported: " + c.getImported() + ", updated: " + c.getUpdated() + ", deleted: " + c.getDeleted() + ", ignored: " + c.getIgnored());
    return importSummary;
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) TaskId(org.hisp.dhis.scheduling.TaskId) DataSet(org.hisp.dhis.dataset.DataSet) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PipedOutputStream(java.io.PipedOutputStream) DataElement(org.hisp.dhis.dataelement.DataElement) CachingMap(org.hisp.dhis.commons.collection.CachingMap) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) ExecutionException(java.util.concurrent.ExecutionException) XMLReader(org.hisp.staxwax.reader.XMLReader) ImportConflict(org.hisp.dhis.dxf2.importsummary.ImportConflict) TimeoutException(java.util.concurrent.TimeoutException) ImportCount(org.hisp.dhis.dxf2.importsummary.ImportCount) IdScheme(org.hisp.dhis.common.IdScheme) IOException(java.io.IOException) IdentifiableObjectCallable(org.hisp.dhis.system.callable.IdentifiableObjectCallable) LinkedList(java.util.LinkedList) XMLStreamException(javax.xml.stream.XMLStreamException) ExecutorService(java.util.concurrent.ExecutorService) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions)

Example 55 with DataSet

use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.

the class DataElementOperandController method getObjectList.

@GetMapping
@SuppressWarnings("unchecked")
@ResponseBody
public RootNode getObjectList(@RequestParam Map<String, String> rpParameters, OrderParams orderParams) throws QueryParserException {
    Schema schema = schemaService.getDynamicSchema(DataElementOperand.class);
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
    List<Order> orders = orderParams.getOrders(schema);
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    WebOptions options = new WebOptions(rpParameters);
    WebMetadata metadata = new WebMetadata();
    List<DataElementOperand> dataElementOperands;
    if (options.isTrue("persisted")) {
        dataElementOperands = Lists.newArrayList(manager.getAll(DataElementOperand.class));
    } else {
        boolean totals = options.isTrue("totals");
        String deg = CollectionUtils.popStartsWith(filters, "dataElement.dataElementGroups.id:eq:");
        deg = deg != null ? deg.substring("dataElement.dataElementGroups.id:eq:".length()) : null;
        String ds = options.get("dataSet");
        if (deg != null) {
            DataElementGroup dataElementGroup = manager.get(DataElementGroup.class, deg);
            dataElementOperands = dataElementCategoryService.getOperands(dataElementGroup.getMembers(), totals);
        } else if (ds != null) {
            DataSet dataSet = manager.get(DataSet.class, ds);
            dataElementOperands = dataElementCategoryService.getOperands(dataSet, totals);
        } else {
            List<DataElement> dataElements = new ArrayList<>(manager.getAllSorted(DataElement.class));
            dataElementOperands = dataElementCategoryService.getOperands(dataElements, totals);
        }
    }
    Query query = queryService.getQueryFromUrl(DataElementOperand.class, filters, orders, options.getRootJunction());
    query.setDefaultOrder();
    query.setObjects(dataElementOperands);
    dataElementOperands = (List<DataElementOperand>) queryService.query(query);
    Pager pager = metadata.getPager();
    if (options.hasPaging() && pager == null) {
        pager = new Pager(options.getPage(), dataElementOperands.size(), options.getPageSize());
        linkService.generatePagerLinks(pager, DataElementOperand.class);
        dataElementOperands = PagerUtils.pageCollection(dataElementOperands, pager);
    }
    RootNode rootNode = NodeUtils.createMetadata();
    if (pager != null) {
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    rootNode.addChild(fieldFilterService.filter(DataElementOperand.class, dataElementOperands, fields));
    return rootNode;
}
Also used : Order(org.hisp.dhis.query.Order) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) RootNode(org.hisp.dhis.node.types.RootNode) Query(org.hisp.dhis.query.Query) DataSet(org.hisp.dhis.dataset.DataSet) Schema(org.hisp.dhis.schema.Schema) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) Pager(org.hisp.dhis.common.Pager) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) ArrayList(java.util.ArrayList) List(java.util.List) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

DataSet (org.hisp.dhis.dataset.DataSet)118 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)52 Period (org.hisp.dhis.period.Period)40 Test (org.junit.Test)39 DataElement (org.hisp.dhis.dataelement.DataElement)34 ArrayList (java.util.ArrayList)29 DhisSpringTest (org.hisp.dhis.DhisSpringTest)21 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)21 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)21 List (java.util.List)20 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)17 User (org.hisp.dhis.user.User)17 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)16 HashSet (java.util.HashSet)14 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)14 ClassPathResource (org.springframework.core.io.ClassPathResource)14 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)13 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)11 PeriodType (org.hisp.dhis.period.PeriodType)11 Date (java.util.Date)9