use of org.hisp.dhis.webapi.controller.exception.BadRequestException in project dhis2-core by dhis2.
the class DeduplicationControllerMvcTest method shouldThrowUpdatePotentialDuplicateToMergedStatus.
@Test
void shouldThrowUpdatePotentialDuplicateToMergedStatus() throws Exception {
String uid = "uid";
PotentialDuplicate potentialDuplicate = new PotentialDuplicate(teiA, teiB);
when(deduplicationService.getPotentialDuplicateByUid(uid)).thenReturn(potentialDuplicate);
mockMvc.perform(put(ENDPOINT + "/" + uid).param("status", DeduplicationStatus.MERGED.name()).content(objectMapper.writeValueAsString(potentialDuplicate)).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)).andExpect(result -> assertTrue(result.getResolvedException() instanceof BadRequestException));
verify(deduplicationService).getPotentialDuplicateByUid(uid);
}
use of org.hisp.dhis.webapi.controller.exception.BadRequestException in project dhis2-core by dhis2.
the class MetadataVersionController method createSystemVersion.
// Creates version in versioning table, exports the metadata and saves the
// snapshot in datastore
@PreAuthorize("hasRole('ALL') or hasRole('F_METADATA_MANAGE')")
@PostMapping(value = MetadataVersionSchemaDescriptor.API_ENDPOINT + "/create", produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public MetadataVersion createSystemVersion(@RequestParam(value = "type") VersionType versionType) throws MetadataVersionException, BadRequestException {
MetadataVersion versionToReturn = null;
boolean enabled = isMetadataVersioningEnabled();
try {
if (!enabled) {
throw new BadRequestException("Metadata versioning is not enabled for this instance.");
}
synchronized (versionService) {
versionService.saveVersion(versionType);
versionToReturn = versionService.getCurrentVersion();
return versionToReturn;
}
} catch (MetadataVersionServiceException ex) {
throw new MetadataVersionException("Unable to create version in system. " + ex.getMessage());
}
}
use of org.hisp.dhis.webapi.controller.exception.BadRequestException in project dhis2-core by dhis2.
the class MetadataVersionController method getMetaDataVersionHistory.
// Gets the list of all versions in between the passed version name and
// latest system version
@GetMapping(value = MetadataVersionSchemaDescriptor.API_ENDPOINT + "/history", produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public RootNode getMetaDataVersionHistory(@RequestParam(value = "baseline", required = false) String versionName) throws MetadataVersionException, BadRequestException {
List<MetadataVersion> allVersionsInBetween = new ArrayList<>();
boolean enabled = isMetadataVersioningEnabled();
try {
if (!enabled) {
throw new BadRequestException("Metadata versioning is not enabled for this instance.");
}
Date startDate;
if (versionName == null || versionName.isEmpty()) {
MetadataVersion initialVersion = versionService.getInitialVersion();
if (initialVersion == null) {
return getMetadataVersionsAsNode(allVersionsInBetween);
}
startDate = initialVersion.getCreated();
} else {
startDate = versionService.getCreatedDate(versionName);
}
if (startDate == null) {
throw new MetadataVersionException("There is no such metadata version. The latest version is Version " + versionService.getCurrentVersion().getName());
}
Date endDate = new Date();
allVersionsInBetween = versionService.getAllVersionsInBetween(startDate, endDate);
if (allVersionsInBetween != null) {
// now remove the baseline version details
for (Iterator<MetadataVersion> iterator = allVersionsInBetween.iterator(); iterator.hasNext(); ) {
MetadataVersion m = iterator.next();
if (m.getName().equals(versionName)) {
iterator.remove();
break;
}
}
if (!allVersionsInBetween.isEmpty()) {
return getMetadataVersionsAsNode(allVersionsInBetween);
}
}
} catch (MetadataVersionServiceException ex) {
throw new MetadataVersionException(ex.getMessage(), ex);
}
return null;
}
use of org.hisp.dhis.webapi.controller.exception.BadRequestException 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.webapi.controller.exception.BadRequestException in project dhis2-core by dhis2.
the class AbstractGistReadOnlyController method getObjectPropertyGistAsCsv.
@GetMapping(value = "/{uid}/{property}/gist", produces = "text/csv")
public void getObjectPropertyGistAsCsv(@PathVariable("uid") String uid, @PathVariable("property") String property, HttpServletRequest request, HttpServletResponse response) throws Exception {
Property objProperty = getSchema().getProperty(property);
if (objProperty == null) {
throw new BadRequestException("No such property: " + property);
}
gistToCsvResponse(response, createPropertyQuery(uid, property, request, objProperty));
}
Aggregations