Search in sources :

Example 11 with MetadataSyncServiceException

use of org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException in project dhis2-core by dhis2.

the class MetadataSyncImportHandler method importMetadata.

public MetadataSyncSummary importMetadata(MetadataSyncParams syncParams, String versionSnapShot) {
    MetadataVersion version = getMetadataVersion(syncParams);
    MetadataImportParams importParams = syncParams.getImportParams();
    MetadataSyncSummary metadataSyncSummary = new MetadataSyncSummary();
    if (importParams == null) {
        throw new MetadataSyncServiceException("MetadataImportParams for the Sync cant be null.");
    }
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> classListMap = parseClassListMap(versionSnapShot);
    if (classListMap == null) {
        throw new MetadataSyncServiceException("ClassListMap can't be null");
    }
    importParams.setObjects(classListMap);
    ImportReport importReport = null;
    try {
        importReport = metadataImportService.importMetadata(importParams);
    } catch (Exception e) {
        String message = "Exception occurred while trying to import the metadata. " + e.getMessage();
        log.error(message, e);
        throw new MetadataSyncImportException(message, e);
    }
    boolean addNewVersion = handleImportReport(importReport, version);
    if (addNewVersion) {
        try {
            metadataVersionDelegate.addNewMetadataVersion(version);
        } catch (MetadataVersionServiceException e) {
            throw new MetadataSyncServiceException(e.getMessage(), e);
        }
    }
    metadataSyncSummary.setImportReport(importReport);
    metadataSyncSummary.setMetadataVersion(version);
    return metadataSyncSummary;
}
Also used : MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) IOException(java.io.IOException) MetadataSyncImportException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncImportException) MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) MetadataSyncImportException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncImportException) List(java.util.List)

Example 12 with MetadataSyncServiceException

use of org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException in project dhis2-core by dhis2.

the class MetadataSyncPreProcessor method handleAggregateDataPush.

public ImportSummary handleAggregateDataPush(MetadataRetryContext context) {
    log.debug("Entering data push");
    ImportSummary importSummary = null;
    AvailabilityStatus remoteServerAvailable = synchronizationManager.isRemoteServerAvailable();
    if (!(remoteServerAvailable.isAvailable())) {
        String message = remoteServerAvailable.getMessage();
        log.error(message);
        context.updateRetryContext(MetadataSyncTask.DATA_PUSH_SUMMARY, remoteServerAvailable.getMessage(), null, null);
        throw new MetadataSyncServiceException(message);
    }
    try {
        importSummary = synchronizationManager.executeDataPush();
        handleAggregateImportSummary(importSummary, context);
    } catch (Exception ex) {
        log.error("Exception happened while trying to do data push " + ex.getMessage(), ex);
        if (ex instanceof MetadataSyncServiceException) {
            throw (MetadataSyncServiceException) ex;
        }
        context.updateRetryContext(MetadataSyncTask.DATA_PUSH_SUMMARY, ex.getMessage(), null, null);
        throw new MetadataSyncServiceException(ex.getMessage(), ex);
    }
    log.debug("Exiting data push");
    return importSummary;
}
Also used : MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)

Example 13 with MetadataSyncServiceException

use of org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException 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 14 with MetadataSyncServiceException

use of org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException in project dhis2-core by dhis2.

the class MetadataSyncPreProcessor method handleEventImportSummary.

private void handleEventImportSummary(ImportSummaries importSummary, MetadataRetryContext context) {
    if (importSummary != null) {
        boolean isImportError = false;
        StringBuilder summaryDescription = new StringBuilder();
        for (ImportSummary summary : importSummary.getImportSummaries()) {
            if (ImportStatus.ERROR.equals(summary.getStatus())) {
                isImportError = true;
                summaryDescription.append(summary.getDescription());
                summaryDescription.append("\n");
            }
        }
        if (isImportError) {
            log.error("Import Summary description: " + summaryDescription.toString());
            context.updateRetryContext(MetadataSyncTask.EVENT_PUSH_SUMMARY, summaryDescription.toString(), null, null);
            throw new MetadataSyncServiceException("The Event Data Push was not successful. ");
        }
    }
}
Also used : MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary)

Example 15 with MetadataSyncServiceException

use of org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException in project dhis2-core by dhis2.

the class MetadataSyncImportHandlerTest method testShouldThrowExceptionWhenImportServiceFails.

@Test
public void testShouldThrowExceptionWhenImportServiceFails() {
    syncParams.setImportParams(new MetadataImportParams());
    syncParams.setVersion(metadataVersion);
    when(metadataImportService.importMetadata(syncParams.getImportParams())).thenThrow(new MetadataSyncServiceException(""));
    expectedException.expect(MetadataSyncImportException.class);
    metadataSyncImportHandler.importMetadata(syncParams, expectedMetadataSnapshot);
    verify(metadataVersionDelegate, never()).addNewMetadataVersion(metadataVersion);
}
Also used : MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

MetadataSyncServiceException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)13 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)7 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)6 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)5 MetadataSyncParams (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams)4 DhisSpringTest (org.hisp.dhis.DhisSpringTest)3 IntegrationTest (org.hisp.dhis.IntegrationTest)3 MetadataSyncSummary (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)3 DhisVersionMismatchException (org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException)3 AvailabilityStatus (org.hisp.dhis.dxf2.synch.AvailabilityStatus)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)2 MetadataSyncImportException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncImportException)2 IOException (java.io.IOException)1 Date (java.util.Date)1 List (java.util.List)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 ImportStatus (org.hisp.dhis.dxf2.importsummary.ImportStatus)1 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)1