Search in sources :

Example 1 with MetadataVersion

use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.

the class DefaultMetadataVersionService method getMetadataVersionsAsNode.

@Override
public RootNode getMetadataVersionsAsNode(List<MetadataVersion> versions) {
    RootNode rootNode = NodeUtils.createRootNode("metadataversions");
    CollectionNode collectionNode = new CollectionNode("metadataversions", true);
    rootNode.addChild(collectionNode);
    for (MetadataVersion version : versions) {
        ComplexNode complexNode = new ComplexNode("");
        complexNode.addChild(new SimpleNode("name", version.getName()));
        complexNode.addChild(new SimpleNode("type", version.getType()));
        complexNode.addChild(new SimpleNode("created", version.getCreated()));
        complexNode.addChild(new SimpleNode("id", version.getUid()));
        complexNode.addChild(new SimpleNode("importdate", version.getImportDate()));
        complexNode.addChild(new SimpleNode("hashCode", version.getHashCode()));
        collectionNode.addChild(complexNode);
    }
    return rootNode;
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) RootNode(org.hisp.dhis.node.types.RootNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode)

Example 2 with MetadataVersion

use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.

the class DefaultMetadataVersionService method updateVersionName.

@Override
public void updateVersionName(int id, String name) {
    MetadataVersion version = getVersionById(id);
    if (version != null) {
        version.setName(name);
        updateVersion(version);
    }
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion)

Example 3 with MetadataVersion

use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.

the class MetadataSyncTask method runSyncTask.

public synchronized void runSyncTask(MetadataRetryContext context) throws MetadataSyncServiceException, DhisVersionMismatchException {
    metadataSyncPreProcessor.setUp(context);
    metadataSyncPreProcessor.handleAggregateDataPush(context);
    metadataSyncPreProcessor.handleEventDataPush(context);
    MetadataVersion metadataVersion = metadataSyncPreProcessor.handleCurrentMetadataVersion(context);
    List<MetadataVersion> metadataVersionList = metadataSyncPreProcessor.handleMetadataVersionsList(context, metadataVersion);
    if (metadataVersionList != null) {
        for (MetadataVersion dataVersion : metadataVersionList) {
            MetadataSyncParams syncParams = new MetadataSyncParams(new MetadataImportParams(), dataVersion);
            boolean isSyncRequired = metadataSyncService.isSyncRequired(syncParams);
            MetadataSyncSummary metadataSyncSummary = null;
            if (isSyncRequired) {
                metadataSyncSummary = handleMetadataSync(context, dataVersion);
            } else {
                metadataSyncPostProcessor.handleVersionAlreadyExists(context, dataVersion);
                break;
            }
            boolean abortStatus = metadataSyncPostProcessor.handleSyncNotificationsAndAbortStatus(metadataSyncSummary, context, dataVersion);
            if (abortStatus) {
                break;
            }
            systemSettingManager.saveSystemSetting(SettingKey.LAST_SUCCESSFUL_METADATA_SYNC, dataVersion.getImportDate());
            clearFailedVersionSettings();
        }
    }
    log.info("Metadata sync cron job ended ");
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataSyncParams(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) MetadataSyncSummary(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)

Example 4 with MetadataVersion

use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.

the class MetadataVersionDelegate method getMetaDataDifference.

public List<MetadataVersion> getMetaDataDifference(MetadataVersion metadataVersion) {
    String url;
    List<MetadataVersion> metadataVersions = new ArrayList<>();
    if (metadataVersion == null) {
        url = metadataSystemSettingService.getEntireVersionHistory();
    } else {
        url = metadataSystemSettingService.getMetaDataDifferenceURL(metadataVersion.getName());
    }
    DhisHttpResponse dhisHttpResponse = getDhisHttpResponse(url, VERSION_TIMEOUT);
    if (isValidDhisHttpResponse(dhisHttpResponse)) {
        try {
            metadataVersions = renderService.fromMetadataVersion(new ByteArrayInputStream(dhisHttpResponse.getResponse().getBytes()), RenderFormat.JSON);
            return metadataVersions;
        } catch (IOException io) {
            String message = "Exception occurred while trying to do JSON conversion. Caused by:  " + io.getMessage();
            log.error(message, io);
            throw new MetadataVersionServiceException(message, io);
        }
    }
    log.warn("Returning empty for the metadata versions difference");
    return metadataVersions;
}
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) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 5 with MetadataVersion

use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.

the class DefaultMetadataSyncService method getParamsFromMap.

@Override
public MetadataSyncParams getParamsFromMap(Map<String, List<String>> parameters) {
    List<String> versionName = getVersionsFromParams(parameters);
    MetadataImportParams importParams = new MetadataImportParams();
    importParams.setMetadataSyncImport(true);
    MetadataSyncParams syncParams = new MetadataSyncParams();
    syncParams.setImportParams(importParams);
    String versionNameStr = versionName.get(0);
    if (StringUtils.isNotEmpty(versionNameStr)) {
        MetadataVersion version;
        try {
            version = metadataVersionDelegate.getRemoteMetadataVersion(versionNameStr);
        } catch (MetadataVersionServiceException e) {
            throw new MetadataSyncServiceException(e.getMessage(), e);
        }
        if (version == null) {
            throw new MetadataSyncServiceException("The MetadataVersion could not be fetched from the remote server for the versionName: " + versionNameStr);
        }
        syncParams.setVersion(version);
    }
    syncParams.setParameters(parameters);
    return syncParams;
}
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) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams)

Aggregations

MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)60 Test (org.junit.jupiter.api.Test)31 Date (java.util.Date)15 AvailabilityStatus (org.hisp.dhis.dxf2.synch.AvailabilityStatus)14 ArrayList (java.util.ArrayList)11 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)10 DhisHttpResponse (org.hisp.dhis.system.util.DhisHttpResponse)10 HttpUtils (org.hisp.dhis.system.util.HttpUtils)10 DhisSpringTest (org.hisp.dhis.DhisSpringTest)8 IOException (java.io.IOException)7 MetadataRetryContext (org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext)6 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)5 MetadataSyncServiceException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 HttpResponse (org.apache.http.HttpResponse)4 ComplexNode (org.hisp.dhis.node.types.ComplexNode)4 RootNode (org.hisp.dhis.node.types.RootNode)4 BadRequestException (org.hisp.dhis.webapi.controller.exception.BadRequestException)3 MetadataVersionException (org.hisp.dhis.webapi.controller.exception.MetadataVersionException)3 Test (org.junit.Test)3