Search in sources :

Example 41 with Metadata

use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.

the class MetadataImportController method postXmlMetadata.

@RequestMapping(value = "", method = RequestMethod.POST, consumes = MediaType.APPLICATION_XML_VALUE)
public void postXmlMetadata(HttpServletRequest request, HttpServletResponse response) throws IOException {
    MetadataImportParams params = metadataImportService.getParamsFromMap(contextService.getParameterValuesMap());
    Metadata metadata = renderService.fromXml(StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream()), Metadata.class);
    params.addMetadata(schemaService.getMetadataSchemas(), metadata);
    if (params.hasTaskId()) {
        startAsync(params);
        response.setStatus(HttpServletResponse.SC_NO_CONTENT);
    } else {
        ImportReport importReport = metadataImportService.importMetadata(params);
        renderService.toXml(response.getOutputStream(), importReport);
    }
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) Metadata(org.hisp.dhis.dxf2.metadata.Metadata) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 42 with Metadata

use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.

the class MetadataSyncController method metadataSync.

@PreAuthorize("hasRole('ALL') or hasRole('F_METADATA_MANAGE')")
@GetMapping
public ResponseEntity<? extends WebMessageResponse> metadataSync(HttpServletRequest request, HttpServletResponse response) throws MetadataSyncException, BadRequestException, MetadataImportConflictException, OperationNotAllowedException {
    MetadataSyncParams syncParams;
    MetadataSyncSummary metadataSyncSummary = null;
    synchronized (metadataSyncService) {
        try {
            syncParams = metadataSyncService.getParamsFromMap(contextService.getParameterValuesMap());
        } catch (RemoteServerUnavailableException exception) {
            throw new MetadataSyncException(exception.getMessage(), exception);
        } catch (MetadataSyncServiceException serviceException) {
            throw new BadRequestException("Error in parsing inputParams " + serviceException.getMessage(), serviceException);
        }
        try {
            boolean isSyncRequired = metadataSyncService.isSyncRequired(syncParams);
            if (isSyncRequired) {
                metadataSyncSummary = metadataSyncService.doMetadataSync(syncParams);
                validateSyncSummaryResponse(metadataSyncSummary);
            } else {
                throw new MetadataImportConflictException("Version already exists in system and hence not starting the sync.");
            }
        } catch (MetadataSyncImportException importerException) {
            throw new MetadataSyncException("Runtime exception occurred while doing import: " + importerException.getMessage());
        } catch (MetadataSyncServiceException serviceException) {
            throw new MetadataSyncException("Exception occurred while doing metadata sync: " + serviceException.getMessage());
        } catch (DhisVersionMismatchException versionMismatchException) {
            throw new OperationNotAllowedException("Exception occurred while doing metadata sync: " + versionMismatchException.getMessage());
        }
    }
    return new ResponseEntity<MetadataSyncSummary>(metadataSyncSummary, HttpStatus.OK);
}
Also used : MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataSyncParams(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams) ResponseEntity(org.springframework.http.ResponseEntity) RemoteServerUnavailableException(org.hisp.dhis.exception.RemoteServerUnavailableException) BadRequestException(org.hisp.dhis.webapi.controller.exception.BadRequestException) MetadataSyncImportException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncImportException) DhisVersionMismatchException(org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException) MetadataSyncSummary(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary) OperationNotAllowedException(org.hisp.dhis.webapi.controller.exception.OperationNotAllowedException) MetadataSyncException(org.hisp.dhis.webapi.controller.exception.MetadataSyncException) MetadataImportConflictException(org.hisp.dhis.webapi.controller.exception.MetadataImportConflictException) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 43 with Metadata

use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.

the class MetadataVersionController method getMetaDataVersionHistory.

//Gets the list of all versions in between the passed version name and latest system version
@RequestMapping(value = MetadataVersionSchemaDescriptor.API_ENDPOINT + "/history", method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public RootNode getMetaDataVersionHistory(@RequestParam(value = "baseline", required = false) String versionName) throws MetadataVersionException, BadRequestException {
    List<MetadataVersion> allVersionsInBetween = new ArrayList<>();
    boolean enabled = isMetadataVersioningEnabled();
    try {
        if (!enabled) {
            throw new BadRequestException("Metadata versioning is not enabled for this instance.");
        }
        Date startDate;
        if (versionName == null || versionName.isEmpty()) {
            MetadataVersion initialVersion = versionService.getInitialVersion();
            if (initialVersion == null) {
                return versionService.getMetadataVersionsAsNode(allVersionsInBetween);
            }
            startDate = initialVersion.getCreated();
        } else {
            startDate = versionService.getCreatedDate(versionName);
        }
        if (startDate == null) {
            throw new MetadataVersionException("There is no such metadata version. The latest version is Version " + versionService.getCurrentVersion().getName());
        }
        Date endDate = new Date();
        allVersionsInBetween = versionService.getAllVersionsInBetween(startDate, endDate);
        if (allVersionsInBetween != null) {
            //now remove the baseline version details
            for (Iterator<MetadataVersion> iterator = allVersionsInBetween.iterator(); iterator.hasNext(); ) {
                MetadataVersion m = iterator.next();
                if (m.getName().equals(versionName)) {
                    iterator.remove();
                    break;
                }
            }
            if (!allVersionsInBetween.isEmpty()) {
                return versionService.getMetadataVersionsAsNode(allVersionsInBetween);
            }
        }
    } catch (MetadataVersionServiceException ex) {
        throw new MetadataVersionException(ex.getMessage(), ex);
    }
    return null;
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) ArrayList(java.util.ArrayList) BadRequestException(org.hisp.dhis.webapi.controller.exception.BadRequestException) MetadataVersionException(org.hisp.dhis.webapi.controller.exception.MetadataVersionException) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 44 with Metadata

use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.

the class MetadataVersionController method createSystemVersion.

//Creates version in versioning table, exports the metadata and saves the snapshot in datastore
@PreAuthorize("hasRole('ALL') or hasRole('F_METADATA_MANAGE')")
@RequestMapping(value = MetadataVersionSchemaDescriptor.API_ENDPOINT + "/create", method = RequestMethod.POST, produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public MetadataVersion createSystemVersion(@RequestParam(value = "type") VersionType versionType) throws MetadataVersionException, BadRequestException {
    MetadataVersion versionToReturn = null;
    boolean enabled = isMetadataVersioningEnabled();
    try {
        if (!enabled) {
            throw new BadRequestException("Metadata versioning is not enabled for this instance.");
        }
        synchronized (versionService) {
            versionService.saveVersion(versionType);
            versionToReturn = versionService.getCurrentVersion();
            return versionToReturn;
        }
    } catch (MetadataVersionServiceException ex) {
        throw new MetadataVersionException("Unable to create version in system. " + ex.getMessage());
    }
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) BadRequestException(org.hisp.dhis.webapi.controller.exception.BadRequestException) MetadataVersionException(org.hisp.dhis.webapi.controller.exception.MetadataVersionException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 45 with Metadata

use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.

the class FilledOrganisationUnitLevelController method setList.

@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public void setList(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Metadata metadata = DefaultRenderService.getJsonMapper().readValue(request.getInputStream(), Metadata.class);
    List<OrganisationUnitLevel> levels = metadata.getOrganisationUnitLevels();
    for (OrganisationUnitLevel level : levels) {
        if (level.getLevel() <= 0) {
            throw new WebMessageException(WebMessageUtils.conflict("Level must be greater than zero"));
        }
        if (StringUtils.isBlank(level.getName())) {
            throw new WebMessageException(WebMessageUtils.conflict("Name must be specified"));
        }
        organisationUnitService.addOrUpdateOrganisationUnitLevel(new OrganisationUnitLevel(level.getLevel(), level.getName(), level.getOfflineLevels()));
    }
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) Metadata(org.hisp.dhis.dxf2.metadata.Metadata) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DhisSpringTest (org.hisp.dhis.DhisSpringTest)55 Test (org.junit.Test)55 List (java.util.List)46 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)46 ClassPathResource (org.springframework.core.io.ClassPathResource)42 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)37 DataElement (org.hisp.dhis.dataelement.DataElement)25 User (org.hisp.dhis.user.User)20 Metadata (com.google.android.exoplayer2.metadata.Metadata)19 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)19 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)19 DataSet (org.hisp.dhis.dataset.DataSet)15 ArrayList (java.util.ArrayList)14 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 IOException (java.io.IOException)10 Metadata (org.hisp.dhis.dxf2.metadata.Metadata)10 DhisHttpResponse (org.hisp.dhis.system.util.DhisHttpResponse)10 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)10 IntegrationTest (org.hisp.dhis.IntegrationTest)9