Search in sources :

Example 1 with MetadataSyncServiceException

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

the class MetadataSyncPreProcessor method handleAggregateImportSummary.

//----------------------------------------------------------------------------------------
// Private Methods
//----------------------------------------------------------------------------------------
private void handleAggregateImportSummary(ImportSummary importSummary, MetadataRetryContext context) {
    if (importSummary != null) {
        ImportStatus status = importSummary.getStatus();
        if (ImportStatus.ERROR.equals(status) || ImportStatus.WARNING.equals(status)) {
            log.error("Import Summary description: " + importSummary.getDescription());
            context.updateRetryContext(MetadataSyncTask.DATA_PUSH_SUMMARY, importSummary.getDescription(), null, null);
            throw new MetadataSyncServiceException("The Data Push was not successful. ");
        }
    }
}
Also used : MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus)

Example 2 with MetadataSyncServiceException

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

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

the class MetadataSyncPreProcessor method handleEventDataPush.

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

Example 4 with MetadataSyncServiceException

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

use of org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException 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);
    MetadataSyncParams syncParams = new MetadataSyncParams();
    syncParams.setImportParams(new MetadataImportParams());
    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

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