use of org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams 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 ");
}
use of org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams 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;
}
use of org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams 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);
}
use of org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams in project dhis2-core by dhis2.
the class MetadataSyncTask method handleMetadataSync.
//----------------------------------------------------------------------------------------
// Private Methods
//----------------------------------------------------------------------------------------
private MetadataSyncSummary handleMetadataSync(MetadataRetryContext context, MetadataVersion dataVersion) throws DhisVersionMismatchException {
MetadataSyncParams syncParams = new MetadataSyncParams(new MetadataImportParams(), dataVersion);
MetadataSyncSummary metadataSyncSummary = null;
try {
metadataSyncSummary = metadataSyncService.doMetadataSync(syncParams);
} catch (MetadataSyncServiceException e) {
log.error("Exception happened while trying to do metadata sync " + e.getMessage(), e);
context.updateRetryContext(METADATA_SYNC, e.getMessage(), dataVersion);
throw e;
} catch (DhisVersionMismatchException e) {
context.updateRetryContext(METADATA_SYNC, e.getMessage(), dataVersion);
throw e;
}
return metadataSyncSummary;
}
use of org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams in project dhis2-core by dhis2.
the class MetadataSyncJob method handleMetadataSync.
// ----------------------------------------------------------------------------------------
// Private Methods
// ----------------------------------------------------------------------------------------
private MetadataSyncSummary handleMetadataSync(MetadataRetryContext context, MetadataVersion dataVersion) throws DhisVersionMismatchException {
MetadataSyncParams syncParams = new MetadataSyncParams(new MetadataImportParams(), dataVersion);
MetadataSyncSummary metadataSyncSummary = null;
try {
metadataSyncSummary = metadataSyncService.doMetadataSync(syncParams);
} catch (MetadataSyncServiceException e) {
log.error("Exception happened while trying to do metadata sync " + e.getMessage(), e);
context.updateRetryContext(METADATA_SYNC, e.getMessage(), dataVersion);
throw e;
} catch (DhisVersionMismatchException e) {
context.updateRetryContext(METADATA_SYNC, e.getMessage(), dataVersion);
throw e;
}
return metadataSyncSummary;
}
Aggregations