Search in sources :

Example 6 with TranslateParams

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);
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Period(org.hisp.dhis.period.Period) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with TranslateParams

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);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) DataEntryForm(org.hisp.dhis.dataentryform.DataEntryForm) Form(org.hisp.dhis.webapi.webdomain.form.Form) Period(org.hisp.dhis.period.Period) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with TranslateParams

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);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) DataEntryForm(org.hisp.dhis.dataentryform.DataEntryForm) Form(org.hisp.dhis.webapi.webdomain.form.Form) Period(org.hisp.dhis.period.Period) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with TranslateParams

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;
}
Also used : ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) PathVariable(org.springframework.web.bind.annotation.PathVariable) Order(org.hisp.dhis.query.Order) RequestParam(org.springframework.web.bind.annotation.RequestParam) ErrorReport(org.hisp.dhis.feedback.ErrorReport) UserContext(org.hisp.dhis.common.UserContext) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) MergeService(org.hisp.dhis.schema.MergeService) RenderService(org.hisp.dhis.render.RenderService) InclusionStrategy(org.hisp.dhis.node.config.InclusionStrategy) UserSettingKey(org.hisp.dhis.user.UserSettingKey) Autowired(org.springframework.beans.factory.annotation.Autowired) WebMessageService(org.hisp.dhis.webapi.service.WebMessageService) NodeUtils(org.hisp.dhis.node.NodeUtils) UserSettingService(org.hisp.dhis.user.UserSettingService) Optional(com.google.common.base.Optional) MetadataImportService(org.hisp.dhis.dxf2.metadata.MetadataImportService) Locale(java.util.Locale) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) Preset(org.hisp.dhis.node.Preset) PagerUtils(org.hisp.dhis.common.PagerUtils) Status(org.hisp.dhis.feedback.Status) Query(org.hisp.dhis.query.Query) ContextService(org.hisp.dhis.webapi.service.ContextService) DefaultRenderService(org.hisp.dhis.render.DefaultRenderService) LinkService(org.hisp.dhis.webapi.service.LinkService) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) FieldFilterService(org.hisp.dhis.fieldfilter.FieldFilterService) MediaType(org.springframework.http.MediaType) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) SchemaService(org.hisp.dhis.schema.SchemaService) QueryService(org.hisp.dhis.query.QueryService) Property(org.hisp.dhis.schema.Property) Collectors(java.util.stream.Collectors) ImportReportMode(org.hisp.dhis.dxf2.metadata.feedback.ImportReportMode) MetadataExportService(org.hisp.dhis.dxf2.metadata.MetadataExportService) SimpleNode(org.hisp.dhis.node.types.SimpleNode) ObjectTranslation(org.hisp.dhis.translation.ObjectTranslation) List(java.util.List) ComplexNode(org.hisp.dhis.node.types.ComplexNode) Type(java.lang.reflect.Type) AclService(org.hisp.dhis.security.acl.AclService) Schema(org.hisp.dhis.schema.Schema) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) RootNode(org.hisp.dhis.node.types.RootNode) Joiner(com.google.common.base.Joiner) HibernateCacheManager(org.hisp.dhis.cache.HibernateCacheManager) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) CollectionNode(org.hisp.dhis.node.types.CollectionNode) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) CreateAccessDeniedException(org.hisp.dhis.hibernate.exception.CreateAccessDeniedException) HashMap(java.util.HashMap) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) Enums(com.google.common.base.Enums) TypeReport(org.hisp.dhis.feedback.TypeReport) ArrayList(java.util.ArrayList) HttpServletRequest(javax.servlet.http.HttpServletRequest) Lists(com.google.common.collect.Lists) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) Charset(java.nio.charset.Charset) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) User(org.hisp.dhis.user.User) ErrorCode(org.hisp.dhis.feedback.ErrorCode) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) WebMessageUtils(org.hisp.dhis.dxf2.webmessage.WebMessageUtils) ObjectReport(org.hisp.dhis.feedback.ObjectReport) QueryParserException(org.hisp.dhis.query.QueryParserException) IdentifiableObjects(org.hisp.dhis.common.IdentifiableObjects) ReadAccessDeniedException(org.hisp.dhis.hibernate.exception.ReadAccessDeniedException) StreamUtils(org.springframework.util.StreamUtils) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) ContextUtils(org.hisp.dhis.webapi.utils.ContextUtils) Node(org.hisp.dhis.node.Node) DeleteAccessDeniedException(org.hisp.dhis.hibernate.exception.DeleteAccessDeniedException) Pager(org.hisp.dhis.common.Pager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) CollectionService(org.hisp.dhis.dxf2.metadata.collection.CollectionService) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) HttpStatus(org.springframework.http.HttpStatus) OrderParams(org.hisp.dhis.dxf2.common.OrderParams) ParameterizedType(java.lang.reflect.ParameterizedType) CurrentUserService(org.hisp.dhis.user.CurrentUserService) TranslateParams(org.hisp.dhis.dxf2.common.TranslateParams) StringUtils(org.springframework.util.StringUtils) RootNode(org.hisp.dhis.node.types.RootNode) User(org.hisp.dhis.user.User) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ReadAccessDeniedException(org.hisp.dhis.hibernate.exception.ReadAccessDeniedException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 10 with TranslateParams

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);
}
Also used : TranslateParams(org.hisp.dhis.dxf2.common.TranslateParams) MetadataExportParams(org.hisp.dhis.dxf2.metadata.MetadataExportParams) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)7 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 DataSet (org.hisp.dhis.dataset.DataSet)4 TranslateParams (org.hisp.dhis.dxf2.common.TranslateParams)4 Pager (org.hisp.dhis.common.Pager)3 Period (org.hisp.dhis.period.Period)3 WebMetadata (org.hisp.dhis.webapi.webdomain.WebMetadata)3 WebOptions (org.hisp.dhis.webapi.webdomain.WebOptions)3 DataEntryForm (org.hisp.dhis.dataentryform.DataEntryForm)2 RootNode (org.hisp.dhis.node.types.RootNode)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 User (org.hisp.dhis.user.User)2 Form (org.hisp.dhis.webapi.webdomain.form.Form)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)1 Enums (com.google.common.base.Enums)1 Joiner (com.google.common.base.Joiner)1 Optional (com.google.common.base.Optional)1