use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict in project dhis2-core by dhis2.
the class DataApprovalController method getDataApprovalList.
private List<DataApproval> getDataApprovalList(Approvals approvals) throws WebMessageException {
List<DataSet> dataSets = objectManager.getByUid(DataSet.class, approvals.getDs());
List<Period> periods = PeriodType.getPeriodsFromIsoStrings(approvals.getPe());
periods = periodService.reloadPeriods(periods);
User user = currentUserService.getCurrentUser();
DataElementCategoryOptionCombo defaultOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
Date date = new Date();
// Avoid duplicates when different data sets have the same work flow
Set<DataApproval> set = new HashSet<>();
for (DataSet dataSet : dataSets) {
if (dataSet.getWorkflow() == null) {
throw new WebMessageException(WebMessageUtils.conflict("DataSet has no approval workflow: " + dataSet.getName()));
}
Set<DataElementCategoryOptionCombo> dataSetOptionCombos = dataSet.getCategoryCombo() != null ? dataSet.getCategoryCombo().getOptionCombos() : null;
for (Approval approval : approvals.getApprovals()) {
OrganisationUnit unit = organisationUnitService.getOrganisationUnit(approval.getOu());
DataElementCategoryOptionCombo optionCombo = categoryService.getDataElementCategoryOptionCombo(approval.getAoc());
optionCombo = ObjectUtils.firstNonNull(optionCombo, defaultOptionCombo);
for (Period period : periods) {
if (dataSetOptionCombos != null && dataSetOptionCombos.contains(optionCombo)) {
DataApproval dataApproval = new DataApproval(null, dataSet.getWorkflow(), period, unit, optionCombo, false, date, user);
set.add(dataApproval);
}
}
}
}
return new ArrayList<>(set);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict in project dhis2-core by dhis2.
the class DataSetController method getVersion.
@RequestMapping(value = "/{uid}/version", method = RequestMethod.GET)
public void getVersion(@PathVariable("uid") String uid, @RequestParam Map<String, String> parameters, HttpServletResponse response) throws Exception {
DataSet dataSet = manager.get(DataSet.class, uid);
if (dataSet == null) {
throw new WebMessageException(WebMessageUtils.conflict("Data set does not exist: " + uid));
}
Map<String, Integer> versionMap = new HashMap<>();
versionMap.put("version", dataSet.getVersion());
renderService.toJson(response.getOutputStream(), versionMap);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict in project dhis2-core by dhis2.
the class DataApprovalController method removeApproval.
// -------------------------------------------------------------------------
// Delete
// -------------------------------------------------------------------------
@PreAuthorize("hasRole('ALL') or hasRole('F_APPROVE_DATA') or hasRole('F_APPROVE_DATA_LOWER_LEVELS')")
@RequestMapping(value = APPROVALS_PATH, method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void removeApproval(@RequestParam Set<String> ds, @RequestParam String pe, @RequestParam String ou, HttpServletResponse response) throws WebMessageException {
Set<DataSet> dataSets = parseDataSetsWithWorkflow(ds);
if (dataSets.size() != ds.size()) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal data set identifier in this list: " + ds));
}
Period period = getAndValidatePeriod(pe);
OrganisationUnit organisationUnit = getAndValidateOrgUnit(ou);
DataApprovalLevel dataApprovalLevel = getAndValidateApprovalLevel(organisationUnit);
User user = currentUserService.getCurrentUser();
List<DataApproval> dataApprovalList = newArrayList();
for (DataSet dataSet : dataSets) {
dataApprovalList.addAll(getApprovalsAsList(dataApprovalLevel, dataSet.getWorkflow(), period, organisationUnit, false, new Date(), user));
}
dataApprovalService.unapproveData(dataApprovalList);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict in project dhis2-core by dhis2.
the class CompleteDataSetRegistrationController method registerCompleteDataSet.
private CompleteDataSetRegistration registerCompleteDataSet(DataSet dataSet, Period period, OrganisationUnit orgUnit, DataElementCategoryOptionCombo attributeOptionCombo, String storedBy, Date completionDate) throws WebMessageException {
I18nFormat format = i18nManager.getI18nFormat();
if (dataSet == null) {
throw new WebMessageException(WebMessageUtils.conflict("dataSet can not be null."));
}
if (period == null) {
throw new WebMessageException(WebMessageUtils.conflict("period can not be null"));
}
if (orgUnit == null) {
throw new WebMessageException(WebMessageUtils.conflict("organisationUnit can not be null"));
}
if (attributeOptionCombo == null) {
throw new WebMessageException(WebMessageUtils.conflict("attributeOptionCombo can not be null"));
}
CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, orgUnit, attributeOptionCombo);
if (registration == null) {
registration = new CompleteDataSetRegistration();
registration.setDataSet(dataSet);
registration.setPeriod(period);
registration.setSource(orgUnit);
registration.setAttributeOptionCombo(attributeOptionCombo);
registration.setDate(completionDate != null ? completionDate : new Date());
registration.setStoredBy(storedBy != null ? storedBy : currentUserService.getCurrentUsername());
registration.setPeriodName(format.formatPeriod(registration.getPeriod()));
registrationService.saveCompleteDataSetRegistration(registration);
} else {
registration.setDate(completionDate != null ? completionDate : new Date());
registration.setStoredBy(storedBy != null ? storedBy : currentUserService.getCurrentUsername());
registration.setPeriodName(format.formatPeriod(registration.getPeriod()));
registrationService.updateCompleteDataSetRegistration(registration);
}
return registration;
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict in project dhis2-core by dhis2.
the class CompleteDataSetRegistrationController method saveCompleteDataSetRegistration.
// Legacy (<= V25)
@ApiVersion({ DhisApiVersion.V23, DhisApiVersion.V24, DhisApiVersion.V25 })
@RequestMapping(method = RequestMethod.POST, produces = "text/plain")
public void saveCompleteDataSetRegistration(@RequestParam String ds, @RequestParam String pe, @RequestParam String ou, @RequestParam(required = false) String cc, @RequestParam(required = false) String cp, @RequestParam(required = false) Date cd, @RequestParam(required = false) String sb, @RequestParam(required = false) boolean multiOu, HttpServletResponse response) throws WebMessageException {
DataSet dataSet = dataSetService.getDataSet(ds);
if (dataSet == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal data set identifier: " + ds));
}
Period period = PeriodType.getPeriodFromIsoString(pe);
if (period == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal period identifier: " + pe));
}
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(ou);
if (organisationUnit == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal organisation unit identifier: " + ou));
}
DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
if (attributeOptionCombo == null) {
return;
}
if (dataSetService.isLocked(dataSet, period, organisationUnit, attributeOptionCombo, null, multiOu)) {
throw new WebMessageException(WebMessageUtils.conflict("Data set is locked: " + ds));
}
// ---------------------------------------------------------------------
// Register as completed data set
// ---------------------------------------------------------------------
Set<OrganisationUnit> children = organisationUnit.getChildren();
String storedBy = (sb == null) ? currentUserService.getCurrentUsername() : sb;
Date completionDate = (cd == null) ? new Date() : cd;
List<CompleteDataSetRegistration> registrations = new ArrayList<>();
if (!multiOu) {
CompleteDataSetRegistration completeDataSetRegistration = registerCompleteDataSet(dataSet, period, organisationUnit, attributeOptionCombo, storedBy, completionDate);
if (completeDataSetRegistration != null) {
registrations.add(completeDataSetRegistration);
}
} else {
addRegistrationsForOrgUnits(registrations, Sets.union(children, Sets.newHashSet(organisationUnit)), dataSet, period, attributeOptionCombo, storedBy, completionDate);
}
registrationService.saveCompleteDataSetRegistrations(registrations, true);
}
Aggregations