Search in sources :

Example 11 with MetadataVersionServiceException

use of org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException in project dhis2-core by dhis2.

the class MetadataSyncPreProcessor method handleMetadataVersionsList.

public List<MetadataVersion> handleMetadataVersionsList(MetadataRetryContext context, MetadataVersion metadataVersion) {
    log.debug("Fetching the list of remote versions");
    List<MetadataVersion> metadataVersionList = new ArrayList<>();
    try {
        metadataVersionList = metadataVersionDelegate.getMetaDataDifference(metadataVersion);
        if (metadataVersion == null) {
            log.info("There is no initial version in the system");
        }
        if (isRemoteVersionEmpty(metadataVersion, metadataVersionList)) {
            log.info("There are no metadata versions created in the remote instance.");
            return metadataVersionList;
        }
        if (isUsingLatestVersion(metadataVersion, metadataVersionList)) {
            log.info("Your instance is already using the latest version:" + metadataVersion);
            return metadataVersionList;
        }
        MetadataVersion latestVersion = getLatestVersion(metadataVersionList);
        assert latestVersion != null;
        systemSettingManager.saveSystemSetting(SettingKey.REMOTE_METADATA_VERSION, latestVersion.getName());
        log.info("Remote system is at version: " + latestVersion.getName());
    } catch (MetadataVersionServiceException e) {
        String message = setVersionListErrorInfoInContext(context, metadataVersion, e);
        throw new MetadataSyncServiceException(message, e);
    } catch (Exception ex) {
        if (ex instanceof MetadataSyncServiceException) {
            log.error(ex.getMessage(), ex);
            throw ex;
        }
        String message = setVersionListErrorInfoInContext(context, metadataVersion, ex);
        log.error(message, ex);
        throw new MetadataSyncServiceException(message, ex);
    }
    return metadataVersionList;
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) ArrayList(java.util.ArrayList) MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)

Example 12 with MetadataVersionServiceException

use of org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException in project dhis2-core by dhis2.

the class MetadataVersionNameGenerator method getNextVersionName.

public static String getNextVersionName(MetadataVersion version) {
    if (version == null) {
        return MetadataVersionService.METADATAVERSION_NAME_PREFIX + 1;
    } else {
        String[] versionNameSplit = version.getName().split("_");
        String versionNameSuffix = versionNameSplit[1];
        int n;
        try {
            n = Integer.parseInt(versionNameSuffix);
        } catch (NumberFormatException nfe) {
            String message = "Invalid version name found: " + versionNameSuffix;
            log.error(message, nfe);
            throw new MetadataVersionServiceException(message, nfe);
        }
        return MetadataVersionService.METADATAVERSION_NAME_PREFIX + (n + 1);
    }
}
Also used : MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)

Example 13 with MetadataVersionServiceException

use of org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException in project dhis2-core by dhis2.

the class DefaultMetadataVersionService method createMetadataVersionInDataStore.

@Override
public void createMetadataVersionInDataStore(String versionName, String versionSnapshot) {
    if (StringUtils.isEmpty(versionSnapshot)) {
        throw new MetadataVersionServiceException("The Metadata Snapshot is null while trying to create a Metadata Version entry in DataStore.");
    }
    KeyJsonValue keyJsonValue = new KeyJsonValue();
    keyJsonValue.setKey(versionName);
    keyJsonValue.setNamespace(MetadataVersionService.METADATASTORE);
    keyJsonValue.setValue(versionSnapshot);
    try {
        keyJsonValueService.addKeyJsonValue(keyJsonValue);
    } catch (Exception ex) {
        String message = "Exception occurred while saving the Metadata snapshot in Data Store" + ex.getMessage();
        log.error(message, ex);
        throw new MetadataVersionServiceException(message, ex);
    }
}
Also used : MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) KeyJsonValue(org.hisp.dhis.keyjsonvalue.KeyJsonValue) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 14 with MetadataVersionServiceException

use of org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException in project dhis2-core by dhis2.

the class MetadataVersionDelegate method getRemoteMetadataVersion.

public MetadataVersion getRemoteMetadataVersion(String versionName) {
    String versionDetailsUrl = metadataSystemSettingService.getVersionDetailsUrl(versionName);
    DhisHttpResponse dhisHttpResponse = getDhisHttpResponse(versionDetailsUrl, VERSION_TIMEOUT);
    MetadataVersion dataVersion = null;
    if (isValidDhisHttpResponse(dhisHttpResponse)) {
        try {
            dataVersion = renderService.fromJson(dhisHttpResponse.getResponse(), MetadataVersion.class);
        } catch (Exception e) {
            String message = "Exception occurred while trying to do JSON conversion for metadata version";
            log.error(message, e);
            throw new MetadataVersionServiceException(message, e);
        }
    }
    return dataVersion;
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) DhisHttpResponse(org.hisp.dhis.system.util.DhisHttpResponse) IOException(java.io.IOException) RemoteServerUnavailableException(org.hisp.dhis.exception.RemoteServerUnavailableException) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)

Example 15 with MetadataVersionServiceException

use of org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException in project dhis2-core by dhis2.

the class MetadataVersionController method getMetaDataVersion.

//Gets the version by versionName or latest system version
@RequestMapping(value = MetadataVersionSchemaDescriptor.API_ENDPOINT, method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public MetadataVersion getMetaDataVersion(@RequestParam(value = "versionName", required = false) String versionName) throws MetadataVersionException, BadRequestException {
    MetadataVersion versionToReturn = null;
    boolean enabled = isMetadataVersioningEnabled();
    try {
        if (!enabled) {
            throw new BadRequestException("Metadata versioning is not enabled for this instance.");
        }
        if (StringUtils.isNotEmpty(versionName)) {
            versionToReturn = versionService.getVersionByName(versionName);
            if (versionToReturn == null) {
                throw new MetadataVersionException("No metadata version with name " + versionName + " exists. Please check again later.");
            }
        } else {
            versionToReturn = versionService.getCurrentVersion();
            if (versionToReturn == null) {
                throw new MetadataVersionException("No metadata versions exist. Please check again later.");
            }
        }
        return versionToReturn;
    } catch (MetadataVersionServiceException ex) {
        throw new MetadataVersionException("Exception occurred while getting metadata version." + (StringUtils.isNotEmpty(versionName) ? versionName : " ") + ex.getMessage(), ex);
    }
}
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) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)16 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)10 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 MetadataSyncServiceException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)4 DhisHttpResponse (org.hisp.dhis.system.util.DhisHttpResponse)4 BadRequestException (org.hisp.dhis.webapi.controller.exception.BadRequestException)4 MetadataVersionException (org.hisp.dhis.webapi.controller.exception.MetadataVersionException)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Date (java.util.Date)2 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)2 AvailabilityStatus (org.hisp.dhis.dxf2.synch.AvailabilityStatus)2 RemoteServerUnavailableException (org.hisp.dhis.exception.RemoteServerUnavailableException)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 List (java.util.List)1