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);
});
}
}
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();
}
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;
}
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;
}
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;
}
Aggregations