use of org.hisp.dhis.dataset.CompleteDataSetRegistration in project dhis2-core by dhis2.
the class GetDataValuesForDataSetAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
// ---------------------------------------------------------------------
// Validation
// ---------------------------------------------------------------------
DataSet dataSet = dataSetService.getDataSet(dataSetId);
Period period = PeriodType.getPeriodFromIsoString(periodId);
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
if (organisationUnit == null || period == null || dataSet == null) {
log.warn("Illegal input, org unit: " + organisationUnit + ", period: " + period + ", data set: " + dataSet);
return SUCCESS;
}
Set<OrganisationUnit> children = organisationUnit.getChildren();
// ---------------------------------------------------------------------
// Attributes
// ---------------------------------------------------------------------
DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
// ---------------------------------------------------------------------
// Data values & Min-max data elements
// ---------------------------------------------------------------------
minMaxDataElements.addAll(minMaxDataElementService.getMinMaxDataElements(organisationUnit, dataSet.getDataElements()));
if (!multiOrganisationUnit) {
dataValues.addAll(dataValueService.getDataValues(organisationUnit, period, dataSet.getDataElements(), attributeOptionCombo));
} else {
for (OrganisationUnit ou : children) {
if (ou.getDataSets().contains(dataSet)) {
dataValues.addAll(dataValueService.getDataValues(ou, period, dataSet.getDataElements(), attributeOptionCombo));
minMaxDataElements.addAll(minMaxDataElementService.getMinMaxDataElements(ou, dataSet.getDataElements()));
}
}
}
// ---------------------------------------------------------------------
// File resource meta-data
// ---------------------------------------------------------------------
List<String> fileResourceUids = dataValues.stream().filter(dv -> dv.getDataElement().isFileType()).map(DataValue::getValue).collect(Collectors.toList());
dataValueFileResourceMap.putAll(fileResourceService.getFileResources(fileResourceUids).stream().collect(Collectors.toMap(BaseIdentifiableObject::getUid, f -> f)));
if (!multiOrganisationUnit) {
CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, organisationUnit, attributeOptionCombo);
if (registration != null) {
complete = true;
date = registration.getDate();
storedBy = registration.getStoredBy();
}
locked = dataSetService.isLocked(dataSet, period, organisationUnit, attributeOptionCombo, null);
} else {
complete = true;
for (OrganisationUnit ou : children) {
if (ou.getDataSets().contains(dataSet)) {
locked = dataSetService.isLocked(dataSet, period, organisationUnit, attributeOptionCombo, null);
if (locked) {
break;
}
CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, ou, attributeOptionCombo);
if (complete && registration == null) {
complete = false;
}
}
}
}
return SUCCESS;
}
use of org.hisp.dhis.dataset.CompleteDataSetRegistration in project dhis2-core by dhis2.
the class MarkComplete method execute.
// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
Validate.notNull(organisationUnitId);
Validate.notNull(isoPeriod);
Validate.notNull(dataSetId);
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
Period period = periodService.getPeriod(isoPeriod);
DataSet dataSet = dataSetService.getDataSet(dataSetId);
//TODO
DataElementCategoryOptionCombo optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, organisationUnit, optionCombo);
if (registration == null) {
registration = new CompleteDataSetRegistration();
registration.setDataSet(dataSet);
registration.setPeriod(period);
registration.setSource(organisationUnit);
registration.setDate(new Date());
registration.setStoredBy(currentUserService.getCurrentUsername());
registrationService.saveCompleteDataSetRegistration(registration);
}
return SUCCESS;
}
use of org.hisp.dhis.dataset.CompleteDataSetRegistration in project dhis2-core by dhis2.
the class DefaultDataValueSetService method getCompleteDate.
private Date getCompleteDate(DataExportParams params) {
if (params.isSingleDataValueSet()) {
//TODO
DataElementCategoryOptionCombo optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(params.getFirstDataSet(), params.getFirstPeriod(), params.getFirstOrganisationUnit(), optionCombo);
return registration != null ? registration.getDate() : null;
}
return null;
}
use of org.hisp.dhis.dataset.CompleteDataSetRegistration in project dhis2-core by dhis2.
the class DefaultDataValueSetService method handleComplete.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private void handleComplete(DataSet dataSet, Date completeDate, Period period, OrganisationUnit orgUnit, DataElementCategoryOptionCombo attributeOptionCombo, ImportSummary summary) {
if (orgUnit == null) {
summary.getConflicts().add(new ImportConflict(OrganisationUnit.class.getSimpleName(), ERROR_OBJECT_NEEDED_TO_COMPLETE));
return;
}
if (period == null) {
summary.getConflicts().add(new ImportConflict(Period.class.getSimpleName(), ERROR_OBJECT_NEEDED_TO_COMPLETE));
return;
}
period = periodService.reloadPeriod(period);
CompleteDataSetRegistration completeAlready = registrationService.getCompleteDataSetRegistration(dataSet, period, orgUnit, attributeOptionCombo);
String username = currentUserService.getCurrentUsername();
if (completeAlready != null) {
completeAlready.setStoredBy(username);
completeAlready.setDate(completeDate);
registrationService.updateCompleteDataSetRegistration(completeAlready);
} else {
CompleteDataSetRegistration registration = new CompleteDataSetRegistration(dataSet, period, orgUnit, attributeOptionCombo, completeDate, username);
registrationService.saveCompleteDataSetRegistration(registration);
}
summary.setDataSetComplete(DateUtils.getMediumDateString(completeDate));
}
use of org.hisp.dhis.dataset.CompleteDataSetRegistration in project dhis2-core by dhis2.
the class DefaultCompleteDataSetRegistrationExchangeService method batchImport.
/**
* @return total number of processed CompleteDataSetRegistration objects
*/
private int batchImport(CompleteDataSetRegistrations completeRegistrations, ImportConfig config, ImportSummary summary, MetaDataCallables mdCallables, MetaDataCaches mdCaches) {
final String currentUser = currentUserService.getCurrentUsername();
final Set<OrganisationUnit> userOrgUnits = currentUserService.getCurrentUserOrganisationUnits();
final I18n i18n = i18nManager.getI18n();
BatchHandler<CompleteDataSetRegistration> batchHandler = batchHandlerFactory.createBatchHandler(CompleteDataSetRegistrationBatchHandler.class).init();
int importCount = 0, updateCount = 0, deleteCount = 0, totalCount = 0;
Date now = new Date();
while (completeRegistrations.hasNextCompleteDataSetRegistration()) {
org.hisp.dhis.dxf2.dataset.CompleteDataSetRegistration cdsr = completeRegistrations.getNextCompleteDataSetRegistration();
totalCount++;
// ---------------------------------------------------------------------
// Init meta-data properties against meta-data cache
// ---------------------------------------------------------------------
MetaDataProperties mdProps = initMetaDataProperties(cdsr, mdCallables, mdCaches);
heatCaches(mdCaches, config);
// ---------------------------------------------------------------------
// Meta-data validation
// ---------------------------------------------------------------------
String storedBy;
try {
// Validate CDSR meta-data properties
mdProps.validate(cdsr, config);
validateOrgUnitInUserHierarchy(mdCaches, mdProps, userOrgUnits, currentUser);
if (config.strictAttrOptionCombos) {
validateAocMatchesDataSetCc(mdProps);
}
validateAttrOptCombo(mdProps, mdCaches, config);
if (config.strictPeriods) {
validateHasMatchingPeriodTypes(mdProps);
}
if (config.strictOrgUnits) {
validateDataSetIsAssignedToOrgUnit(mdProps);
}
storedBy = cdsr.getStoredBy();
validateStoredBy(storedBy, i18n);
storedBy = StringUtils.isBlank(storedBy) ? currentUser : storedBy;
// TODO Check if Period is within range of data set?
} catch (ImportConflictException ic) {
summary.getConflicts().add(ic.getImportConflict());
continue;
}
// -----------------------------------------------------------------
// Create complete data set registration
// -----------------------------------------------------------------
CompleteDataSetRegistration internalCdsr = createCompleteDataSetRegistration(cdsr, mdProps, now, storedBy);
CompleteDataSetRegistration existingCdsr = config.skipExistingCheck ? null : batchHandler.findObject(internalCdsr);
ImportStrategy strategy = config.strategy;
boolean isDryRun = config.dryRun;
if (!config.skipExistingCheck && existingCdsr != null) {
if (strategy.isCreateAndUpdate() || strategy.isUpdate()) {
// Update existing CDSR
updateCount++;
if (!isDryRun) {
batchHandler.updateObject(internalCdsr);
}
} else if (strategy.isDelete()) {
// TODO Does 'delete' even make sense for CDSR?
// Replace existing CDSR
deleteCount++;
if (!isDryRun) {
batchHandler.deleteObject(internalCdsr);
}
}
} else {
if (strategy.isCreateAndUpdate() || strategy.isCreate()) {
if (existingCdsr != null) {
// Already exists -> update
importCount++;
if (!isDryRun) {
batchHandler.updateObject(internalCdsr);
}
} else {
// Does not exist -> add new CDSR
boolean added = false;
if (!isDryRun) {
added = batchHandler.addObject(internalCdsr);
}
if (isDryRun || added) {
importCount++;
}
}
}
}
}
batchHandler.flush();
finalizeSummary(summary, totalCount, importCount, updateCount, deleteCount);
return totalCount;
}
Aggregations