use of org.hisp.dhis.dxf2.common.TranslateParams in project dhis2-core by dhis2.
the class DataSetController method getDvs.
@RequestMapping(value = "/{uid}/dataValueSet", method = RequestMethod.GET)
@ResponseBody
public RootNode getDvs(@PathVariable("uid") String uid, @RequestParam(value = "orgUnitIdScheme", defaultValue = "ID", required = false) String orgUnitIdScheme, @RequestParam(value = "dataElementIdScheme", defaultValue = "ID", required = false) String dataElementIdScheme, @RequestParam(value = "period", defaultValue = "", required = false) String period, @RequestParam(value = "orgUnit", defaultValue = "", required = false) List<String> orgUnits, @RequestParam(value = "comment", defaultValue = "true", required = false) boolean comment, TranslateParams translateParams, HttpServletResponse response) throws IOException, WebMessageException {
setUserContext(translateParams);
List<DataSet> dataSets = getEntity(uid, NO_WEB_OPTIONS);
if (dataSets.isEmpty()) {
throw new WebMessageException(WebMessageUtils.notFound("DataSet not found for uid: " + uid));
}
Period pe = periodService.getPeriod(period);
return dataValueSetService.getDataValueSetTemplate(dataSets.get(0), pe, orgUnits, comment, orgUnitIdScheme, dataElementIdScheme);
}
use of org.hisp.dhis.dxf2.common.TranslateParams in project dhis2-core by dhis2.
the class DataSetController method getFormXml.
@RequestMapping(value = "/{uid}/form", method = RequestMethod.GET, produces = { "application/xml", "text/xml" })
public void getFormXml(@PathVariable("uid") String uid, @RequestParam(value = "ou", required = false) String orgUnit, @RequestParam(value = "pe", required = false) String period, @RequestParam(value = "catOpts", required = false) String categoryOptions, @RequestParam(required = false) boolean metaData, TranslateParams translateParams, HttpServletResponse response) throws IOException, WebMessageException {
setUserContext(translateParams);
List<DataSet> dataSets = getEntity(uid, NO_WEB_OPTIONS);
if (dataSets.isEmpty()) {
throw new WebMessageException(WebMessageUtils.notFound("DataSet not found for uid: " + uid));
}
OrganisationUnit ou = manager.get(OrganisationUnit.class, orgUnit);
if (ou == null) {
throw new WebMessageException(WebMessageUtils.notFound("Organisation unit does not exist: " + orgUnit));
}
Period pe = PeriodType.getPeriodFromIsoString(period);
Form form = getForm(dataSets, ou, pe, categoryOptions, metaData);
renderService.toXml(response.getOutputStream(), form);
}
use of org.hisp.dhis.dxf2.common.TranslateParams in project dhis2-core by dhis2.
the class DataSetController method getFormJson.
@RequestMapping(value = "/{uid}/form", method = RequestMethod.GET, produces = "application/json")
public void getFormJson(@PathVariable("uid") String uid, @RequestParam(value = "ou", required = false) String orgUnit, @RequestParam(value = "pe", required = false) String period, @RequestParam(value = "categoryOptions", required = false) String categoryOptions, @RequestParam(required = false) boolean metaData, TranslateParams translateParams, HttpServletResponse response) throws IOException, WebMessageException {
setUserContext(translateParams);
List<DataSet> dataSets = getEntity(uid, NO_WEB_OPTIONS);
if (dataSets.isEmpty()) {
throw new WebMessageException(WebMessageUtils.notFound("DataSet not found for uid: " + uid));
}
OrganisationUnit ou = manager.get(OrganisationUnit.class, orgUnit);
if (ou == null) {
throw new WebMessageException(WebMessageUtils.notFound("Organisation unit does not exist: " + orgUnit));
}
Period pe = PeriodType.getPeriodFromIsoString(period);
Form form = getForm(dataSets, ou, pe, categoryOptions, metaData);
renderService.toJson(response.getOutputStream(), form);
}
use of org.hisp.dhis.dxf2.common.TranslateParams in project dhis2-core by dhis2.
the class AbstractCrudController method getCollectionItem.
//--------------------------------------------------------------------------
// Identifiable object collections add, delete
//--------------------------------------------------------------------------
@RequestMapping(value = "/{uid}/{property}/{itemId}", method = RequestMethod.GET)
@ResponseBody
public RootNode getCollectionItem(@PathVariable("uid") String pvUid, @PathVariable("property") String pvProperty, @PathVariable("itemId") String pvItemId, @RequestParam Map<String, String> parameters, TranslateParams translateParams, HttpServletRequest request, HttpServletResponse response) throws Exception {
User user = currentUserService.getCurrentUser();
setUserContext(user, translateParams);
if (!aclService.canRead(user, getEntityClass())) {
throw new ReadAccessDeniedException("You don't have the proper permissions to read objects of this type.");
}
RootNode rootNode = getObjectInternal(pvUid, parameters, Lists.newArrayList(), Lists.newArrayList(pvProperty + "[:all]"), user);
// TODO optimize this using field filter (collection filtering)
if (!rootNode.getChildren().isEmpty() && rootNode.getChildren().get(0).isCollection()) {
rootNode.getChildren().get(0).getChildren().stream().filter(Node::isComplex).forEach(node -> {
node.getChildren().stream().filter(child -> child.isSimple() && child.getName().equals("id") && !((SimpleNode) child).getValue().equals(pvItemId)).forEach(child -> rootNode.getChildren().get(0).removeChild(node));
});
}
if (rootNode.getChildren().isEmpty() || rootNode.getChildren().get(0).getChildren().isEmpty()) {
throw new WebMessageException(WebMessageUtils.notFound(pvProperty + " with ID " + pvItemId + " could not be found."));
}
return rootNode;
}
use of org.hisp.dhis.dxf2.common.TranslateParams in project dhis2-core by dhis2.
the class MetadataExportController method getMetadata.
@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseBody
public RootNode getMetadata(@RequestParam(required = false, defaultValue = "false") boolean translate, @RequestParam(required = false) String locale) {
if (translate) {
TranslateParams translateParams = new TranslateParams(true, locale);
setUserContext(currentUserService.getCurrentUser(), translateParams);
}
MetadataExportParams params = metadataExportService.getParamsFromMap(contextService.getParameterValuesMap());
metadataExportService.validate(params);
return metadataExportService.getMetadataAsNode(params);
}
Aggregations