use of org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncImportException 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.exception.MetadataSyncImportException 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");
}
// Job configurations should not be imported from any source
// (neither by normal metadata import nor by sync).
classListMap.remove(JobConfiguration.class);
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;
}
Aggregations