Search in sources :

Example 1 with RemoteServerUnavailableException

use of org.hisp.dhis.exception.RemoteServerUnavailableException in project dhis2-core by dhis2.

the class MetadataVersionDelegate method getDhisHttpResponse.

//----------------------------------------------------------------------------------------
// Private Methods
//----------------------------------------------------------------------------------------
private DhisHttpResponse getDhisHttpResponse(String url, int timeout) {
    AvailabilityStatus remoteServerAvailable = synchronizationManager.isRemoteServerAvailable();
    if (!(remoteServerAvailable.isAvailable())) {
        String message = remoteServerAvailable.getMessage();
        log.error(message);
        throw new RemoteServerUnavailableException(message);
    }
    String username = metadataSystemSettingService.getRemoteInstanceUserName();
    String password = metadataSystemSettingService.getRemoteInstancePassword();
    log.info("Remote server metadata version  URL: " + url + ", username: " + username);
    DhisHttpResponse dhisHttpResponse = null;
    try {
        dhisHttpResponse = HttpUtils.httpGET(url, true, username, password, null, timeout, true);
    } catch (Exception e) {
        String message = "Exception occurred while trying to make the GET call to URL: " + url;
        log.error(message, e);
        throw new MetadataVersionServiceException(message, e);
    }
    return dhisHttpResponse;
}
Also used : MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) DhisHttpResponse(org.hisp.dhis.system.util.DhisHttpResponse) AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) RemoteServerUnavailableException(org.hisp.dhis.exception.RemoteServerUnavailableException) IOException(java.io.IOException) RemoteServerUnavailableException(org.hisp.dhis.exception.RemoteServerUnavailableException) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)

Example 2 with RemoteServerUnavailableException

use of org.hisp.dhis.exception.RemoteServerUnavailableException 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)

Aggregations

RemoteServerUnavailableException (org.hisp.dhis.exception.RemoteServerUnavailableException)2 IOException (java.io.IOException)1 MetadataSyncParams (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams)1 MetadataSyncSummary (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)1 DhisVersionMismatchException (org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException)1 MetadataSyncImportException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncImportException)1 MetadataSyncServiceException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)1 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)1 AvailabilityStatus (org.hisp.dhis.dxf2.synch.AvailabilityStatus)1 DhisHttpResponse (org.hisp.dhis.system.util.DhisHttpResponse)1 BadRequestException (org.hisp.dhis.webapi.controller.exception.BadRequestException)1 MetadataImportConflictException (org.hisp.dhis.webapi.controller.exception.MetadataImportConflictException)1 MetadataSyncException (org.hisp.dhis.webapi.controller.exception.MetadataSyncException)1 OperationNotAllowedException (org.hisp.dhis.webapi.controller.exception.OperationNotAllowedException)1 ResponseEntity (org.springframework.http.ResponseEntity)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1