use of org.hisp.dhis.webapi.mvc.annotation.ApiVersion in project dhis2-core by dhis2.
the class CompleteDataSetRegistrationController method postCompleteRegistrationsXml.
// -------------------------------------------------------------------------
// POST
// -------------------------------------------------------------------------
@ApiVersion({ DhisApiVersion.DEFAULT, DhisApiVersion.V26, DhisApiVersion.V27 })
@RequestMapping(method = RequestMethod.POST, consumes = CONTENT_TYPE_XML)
public void postCompleteRegistrationsXml(ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
if (importOptions.isAsync()) {
asyncImport(importOptions, ImportCompleteDataSetRegistrationsTask.FORMAT_XML, request, response);
} else {
response.setContentType(CONTENT_TYPE_XML);
ImportSummary summary = registrationExchangeService.saveCompleteDataSetRegistrationsXml(request.getInputStream(), importOptions);
summary.setImportOptions(importOptions);
renderService.toXml(response.getOutputStream(), summary);
}
}
use of org.hisp.dhis.webapi.mvc.annotation.ApiVersion 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);
}
use of org.hisp.dhis.webapi.mvc.annotation.ApiVersion in project dhis2-core by dhis2.
the class CompleteDataSetRegistrationController method getCompleteDataSetRegistrationsJson.
// Legacy (>= V25)
@ApiVersion({ DhisApiVersion.V23, DhisApiVersion.V24, DhisApiVersion.V25 })
@RequestMapping(method = RequestMethod.GET, produces = CONTENT_TYPE_JSON)
@ResponseBody
public RootNode getCompleteDataSetRegistrationsJson(@RequestParam Set<String> dataSet, @RequestParam(required = false) String period, @RequestParam Date startDate, @RequestParam Date endDate, @RequestParam Set<String> orgUnit, @RequestParam(required = false) boolean children, HttpServletResponse response) throws IOException {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
List<String> defaults = new ArrayList<>();
defaults.add("period[id,name,code],organisationUnit[id,name,created,lastUpdated],dataSet[code,name,created,lastUpdated,id],attributeOptionCombo[code,name,created,lastUpdated,id]");
fields.addAll(defaults);
}
response.setContentType(CONTENT_TYPE_JSON);
CompleteDataSetRegistrations completeDataSetRegistrations = getCompleteDataSetRegistrations(dataSet, period, startDate, endDate, orgUnit, children);
RootNode rootNode = NodeUtils.createMetadata();
rootNode.addChild(fieldFilterService.filter(CompleteDataSetRegistration.class, completeDataSetRegistrations.getCompleteDataSetRegistrations(), fields));
return rootNode;
}
use of org.hisp.dhis.webapi.mvc.annotation.ApiVersion in project dhis2-core by dhis2.
the class CompleteDataSetRegistrationController method postCompleteRegistrationsJson.
@ApiVersion({ DhisApiVersion.DEFAULT, DhisApiVersion.V26, DhisApiVersion.V27 })
@RequestMapping(method = RequestMethod.POST, consumes = CONTENT_TYPE_JSON)
public void postCompleteRegistrationsJson(ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
if (importOptions.isAsync()) {
asyncImport(importOptions, ImportCompleteDataSetRegistrationsTask.FORMAT_JSON, request, response);
} else {
response.setContentType(CONTENT_TYPE_JSON);
ImportSummary summary = registrationExchangeService.saveCompleteDataSetRegistrationsJson(request.getInputStream(), importOptions);
summary.setImportOptions(importOptions);
renderService.toJson(response.getOutputStream(), summary);
}
}
use of org.hisp.dhis.webapi.mvc.annotation.ApiVersion in project dhis2-core by dhis2.
the class DataSetController method updateCustomDataEntryFormJson.
@PostMapping(value = "/{uid}/form", consumes = APPLICATION_JSON_VALUE)
@ApiVersion(value = DhisApiVersion.ALL)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void updateCustomDataEntryFormJson(@PathVariable("uid") String uid, HttpServletRequest request) throws WebMessageException {
DataSet dataSet = dataSetService.getDataSet(uid);
if (dataSet == null) {
throw new WebMessageException(notFound("DataSet not found for uid: " + uid));
}
DataEntryForm form = dataSet.getDataEntryForm();
DataEntryForm newForm;
try {
newForm = renderService.fromJson(request.getInputStream(), DataEntryForm.class);
} catch (IOException e) {
throw new WebMessageException(badRequest("Failed to parse request", e.getMessage()));
}
if (form == null) {
if (!newForm.hasForm()) {
throw new WebMessageException(badRequest("Missing required parameter 'htmlCode'"));
}
newForm.setName(dataSet.getName());
dataEntryFormService.addDataEntryForm(newForm);
dataSet.setDataEntryForm(newForm);
} else {
if (newForm.getHtmlCode() != null) {
form.setHtmlCode(dataEntryFormService.prepareDataEntryFormForSave(newForm.getHtmlCode()));
}
if (newForm.getStyle() != null) {
form.setStyle(newForm.getStyle());
}
dataEntryFormService.updateDataEntryForm(form);
}
dataSet.increaseVersion();
dataSetService.updateDataSet(dataSet);
}
Aggregations