Skip to content

Commit

Permalink
Fix dcm4che#310 dcm4che/dcm4chee-arc-light : Improve Exception Handli…
Browse files Browse the repository at this point in the history
…ng on server and client side
  • Loading branch information
vrindanayak committed Aug 29, 2016
1 parent 5cd0ad9 commit 5dcf6f7
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ public void deletePatient(@PathParam("PatientID") IDWithIssuer patientID) throws
logRequest();
Patient patient = patientService.findPatient(patientID);
if (patient == null)
throw new WebApplicationException(
"Patient having patient ID : " + patientID + " not found.", Response.Status.NOT_FOUND);
throw new WebApplicationException(getResponse(
"Patient having patient ID : " + patientID + " not found.", Response.Status.NOT_FOUND));
if (patient.getNumberOfStudies() > 0)
throw new WebApplicationException(
"Patient having patient ID : " + patientID + " has non empty studies.", Response.Status.FORBIDDEN);
throw new WebApplicationException(getResponse(
"Patient having patient ID : " + patientID + " has non empty studies.", Response.Status.FORBIDDEN));
PatientMgtContext ctx = patientService.createPatientMgtContextWEB(request, getApplicationEntity());
ctx.setPatientID(patientID);
ctx.setAttributes(patient.getAttributes());
Expand All @@ -206,10 +206,10 @@ public void deleteStudy(@PathParam("StudyUID") String studyUID) throws Exception
try {
deletionService.deleteStudy(studyUID, request, getApplicationEntity());
} catch (StudyNotFoundException e) {
throw new WebApplicationException("Study having study instance UID " + studyUID + " not found.",
Response.Status.NOT_FOUND);
throw new WebApplicationException(getResponse("Study having study instance UID " + studyUID + " not found.",
Response.Status.NOT_FOUND));
} catch (StudyNotEmptyException e) {
throw new WebApplicationException(e.getMessage() + studyUID, Response.Status.FORBIDDEN);
throw new WebApplicationException(getResponse(e.getMessage() + studyUID, Response.Status.FORBIDDEN));
}
}

Expand Down Expand Up @@ -264,8 +264,8 @@ public StreamingOutput updateStudy(InputStream in) throws Exception {

Patient patient = patientService.findPatient(patientID);
if (patient == null)
throw new WebApplicationException("Patient[id=" + patientID + "] does not exists",
Response.Status.NOT_FOUND);
throw new WebApplicationException(getResponse("Patient[id=" + patientID + "] does not exists",
Response.Status.NOT_FOUND));

if (!attrs.containsValue(Tag.StudyInstanceUID))
attrs.setString(Tag.StudyInstanceUID, VR.UI, UIDUtils.createUID());
Expand Down Expand Up @@ -294,12 +294,12 @@ public String updateStudy(@PathParam("PatientID") IDWithIssuer patientID,
Attributes attrs = reader.readDataset(null);
String studyIUID = attrs.getString(Tag.StudyInstanceUID);
if (studyIUID != null)
throw new WebApplicationException("Study Instance UID in message body", Response.Status.BAD_REQUEST);
throw new WebApplicationException(getResponse("Study Instance UID in message body", Response.Status.BAD_REQUEST));

Patient patient = patientService.findPatient(patientID);
if (patient == null)
throw new WebApplicationException("Patient[id=" + patientID + "] does not exists",
Response.Status.NOT_FOUND);
throw new WebApplicationException(getResponse("Patient[id=" + patientID + "] does not exists",
Response.Status.NOT_FOUND));

attrs.setString(Tag.StudyInstanceUID, VR.UI, UIDUtils.createUID());

Expand All @@ -323,16 +323,16 @@ public void updateStudy(@PathParam("PatientID") IDWithIssuer patientID,
ctx.setAttributes(reader.readDataset(null));
String studyIUIDBody = ctx.getStudyInstanceUID();
if (studyIUIDBody == null)
throw new WebApplicationException("missing Study Instance UID in message body", Response.Status.BAD_REQUEST);
throw new WebApplicationException(getResponse("missing Study Instance UID in message body", Response.Status.BAD_REQUEST));
if (!studyIUIDBody.equals(studyUID))
throw new WebApplicationException("Study Instance UID[" + studyIUIDBody +
throw new WebApplicationException(getResponse("Study Instance UID[" + studyIUIDBody +
"] in message body does not match Study Instance UID[" + studyUID + "] in path",
Response.Status.BAD_REQUEST);
Response.Status.BAD_REQUEST));

Patient patient = patientService.findPatient(patientID);
if (patient == null)
throw new WebApplicationException("Patient[id=" + patientID + "] does not exists",
Response.Status.NOT_FOUND);
throw new WebApplicationException(getResponse("Patient[id=" + patientID + "] does not exists",
Response.Status.NOT_FOUND));

ctx.setPatient(patient);

Expand Down Expand Up @@ -374,7 +374,7 @@ private void updateExpirationDate(String studyUID, String seriesUID, String expi
message = "Series not found. " + seriesUID;
else
message = "Study not found. " + studyUID;
throw new WebApplicationException(message, Response.Status.NOT_FOUND);
throw new WebApplicationException(getResponse(message, Response.Status.NOT_FOUND));
}
}

Expand All @@ -392,13 +392,13 @@ private void logRequest() {
private ApplicationEntity getApplicationEntity() {
ApplicationEntity ae = device.getApplicationEntity(aet, true);
if (ae == null || !ae.isInstalled())
throw new WebApplicationException(
throw new WebApplicationException(getResponse(
"No such Application Entity: " + aet,
Response.Status.SERVICE_UNAVAILABLE);
Response.Status.SERVICE_UNAVAILABLE));
ArchiveAEExtension arcAE = ae.getAEExtension(ArchiveAEExtension.class);
if (request.getAttribute(keycloakClassName) != null)
if(!authenticatedUser(request, arcAE.getAcceptedUserRoles()))
throw new WebApplicationException("User not allowed to perform this service.", Response.Status.FORBIDDEN);
throw new WebApplicationException(getResponse("User not allowed to perform this service.", Response.Status.FORBIDDEN));
return ae;
}

Expand All @@ -421,11 +421,11 @@ private void reject(String method, String studyUID, String seriesUID, String obj
Code code = new Code(codeValue, designator, null, "?");
RejectionNote rjNote = arcDev.getRejectionNote(code);
if (rjNote == null)
throw new WebApplicationException("Unknown Rejection Note Code: " + code, Response.Status.NOT_FOUND);
throw new WebApplicationException(getResponse("Unknown Rejection Note Code: " + code, Response.Status.NOT_FOUND));

Attributes attrs = queryService.createRejectionNote(ae, studyUID, seriesUID, objectUID, rjNote);
if (attrs == null)
throw new WebApplicationException("No Study with UID: " + studyUID, Response.Status.NOT_FOUND);
throw new WebApplicationException(getResponse("No Study with UID: " + studyUID, Response.Status.NOT_FOUND));

StoreSession session = storeService.newStoreSession(request, ae);
StoreContext ctx = storeService.newStoreContext(session);
Expand All @@ -448,7 +448,7 @@ private StreamingOutput copyOrMoveInstances(String studyUID, InputStream in, Cod
StoreSession session = storeService.newStoreSession(request, ae);
Collection<InstanceLocations> instances = storeService.queryInstances(session, instanceRefs, studyUID, uidMap);
if (instances.isEmpty())
throw new WebApplicationException(Response.Status.NOT_FOUND);
throw new WebApplicationException(getResponse("No Instances found. ", Response.Status.NOT_FOUND));
Attributes sopInstanceRefs = getSOPInstanceRefs(instanceRefs, instances, ae, false);
moveSequence(sopInstanceRefs, Tag.ReferencedSeriesSequence, instanceRefs);
rejectInstanceRefs(code, instanceRefs, session, arcDev);
Expand Down Expand Up @@ -507,7 +507,7 @@ private void rejectInstanceRefs(Code code, Attributes instanceRefs, StoreSession
if (code != null) {
rjNote = arcDev.getRejectionNote(code);
if (rjNote == null)
throw new WebApplicationException("Unknown Rejection Note Code: " + code, Response.Status.NOT_FOUND);
throw new WebApplicationException(getResponse("Unknown Rejection Note Code: " + code, Response.Status.NOT_FOUND));
}
if (rjNote != null) {
Attributes ko = queryService.createRejectionNote(instanceRefs, rjNote);
Expand All @@ -522,7 +522,7 @@ private void rejectInstanceRefs(Code code, Attributes instanceRefs, StoreSession
private void expect(JsonParser parser, JsonParser.Event expected) {
JsonParser.Event next = parser.next();
if (next != expected)
throw new WebApplicationException("Unexpected " + next, Response.Status.BAD_REQUEST);
throw new WebApplicationException(getResponse("Unexpected " + next, Response.Status.BAD_REQUEST));
}

private Attributes parseSOPInstanceReferences(InputStream in) throws IOException {
Expand All @@ -540,11 +540,11 @@ private Attributes parseSOPInstanceReferences(InputStream in) throws IOException
attrs.newSequence(Tag.ReferencedSeriesSequence, 10));
break;
default:
throw new WebApplicationException("Unexpected Key name", Response.Status.BAD_REQUEST);
throw new WebApplicationException(getResponse("Unexpected Key name", Response.Status.BAD_REQUEST));
}
}
if (!attrs.contains(Tag.StudyInstanceUID))
throw new WebApplicationException("Missing StudyInstanceUID", Response.Status.BAD_REQUEST);
throw new WebApplicationException(getResponse("Missing StudyInstanceUID", Response.Status.BAD_REQUEST));

return attrs;
}
Expand All @@ -568,11 +568,11 @@ private Attributes parseReferencedSeries(JsonParser parser) {
attrs.newSequence(Tag.ReferencedSOPSequence, 10));
break;
default:
throw new WebApplicationException("Unexpected Key name", Response.Status.BAD_REQUEST);
throw new WebApplicationException(getResponse("Unexpected Key name", Response.Status.BAD_REQUEST));
}
}
if (!attrs.contains(Tag.SeriesInstanceUID))
throw new WebApplicationException("Missing SeriesInstanceUID", Response.Status.BAD_REQUEST);
throw new WebApplicationException(getResponse("Missing SeriesInstanceUID", Response.Status.BAD_REQUEST));

return attrs;
}
Expand All @@ -596,14 +596,14 @@ private Attributes parseReferencedSOP(JsonParser parser) {
attrs.setString(Tag.ReferencedSOPInstanceUID, VR.UI, parser.getString());
break;
default:
throw new WebApplicationException("Unexpected Key name", Response.Status.BAD_REQUEST);
throw new WebApplicationException(getResponse("Unexpected Key name", Response.Status.BAD_REQUEST));
}
}
if (!attrs.contains(Tag.ReferencedSOPClassUID))
throw new WebApplicationException("Missing ReferencedSOPClassUID", Response.Status.BAD_REQUEST);
throw new WebApplicationException(getResponse("Missing ReferencedSOPClassUID", Response.Status.BAD_REQUEST));

if (!attrs.contains(Tag.ReferencedSOPInstanceUID))
throw new WebApplicationException("Missing ReferencedSOPInstanceUID", Response.Status.BAD_REQUEST);
throw new WebApplicationException(getResponse("Missing ReferencedSOPInstanceUID", Response.Status.BAD_REQUEST));

return attrs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ private ApplicationEntity getApplicationEntity() {
if (ae == null) {
ae = device.getApplicationEntity(aet, true);
if (ae == null || !ae.isInstalled())
throw new WebApplicationException(
throw new WebApplicationException(getResponse(
"No such Application Entity: " + aet,
Response.Status.SERVICE_UNAVAILABLE);
Response.Status.SERVICE_UNAVAILABLE));
this.ae = ae;
}
return ae;
Expand Down
49 changes: 35 additions & 14 deletions dcm4chee-arc-ui/src/main/webapp/js/controllers/study_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -1073,8 +1073,11 @@ myApp.controller('StudyListCtrl', function ($scope, $window, $http, QidoService,
$scope.callBackFree = true;
}, function errorCallback(response) {
DeviceService.msg($scope, {
"title": "Error",
"text": "Error saving mwl!",
// "title": "Error",
// "text": "Error saving mwl!",
// "status": "error"
"title": "Error "+response.status,
"text": response.data.errorMessage,
"status": "error"
});
$scope.callBackFree = true;
Expand Down Expand Up @@ -2220,8 +2223,11 @@ myApp.controller('StudyListCtrl', function ($scope, $window, $http, QidoService,
},
function errorCallback(response) {
DeviceService.msg($scope, {
"title": "Error",
"text": "Error deleting study!",
// "title": "Error",
// "text": "Error deleting study!",
// "status": "error"
"title": "Error "+response.status,
"text": response.data.errorMessage,
"status": "error"
});
cfpLoadingBar.complete();
Expand Down Expand Up @@ -2272,8 +2278,11 @@ myApp.controller('StudyListCtrl', function ($scope, $window, $http, QidoService,
},
function errorCallback(response) {
DeviceService.msg($scope, {
"title": "Error",
"text": "Error deleting patient!",
// "title": "Error",
// "text": "Error deleting patient!",
// "status": "error"
"title": "Error "+response.status,
"text": response.data.errorMessage,
"status": "error"
});
// angular.element("#querypatients").trigger('click');
Expand Down Expand Up @@ -2411,8 +2420,11 @@ myApp.controller('StudyListCtrl', function ($scope, $window, $http, QidoService,
$scope.callBackFree = true;
}, function errorCallback(response) {
DeviceService.msg($scope, {
"title": "Error",
"text": "Error copying object "+m.StudyInstanceUID,
// "title": "Error",
// "text": "Error copying object "+m.StudyInstanceUID,
// "status": "error"
"title": "Error "+response.status,
"text": response.data.errorMessage,
"status": "error"
});
$scope.callBackFree = true;
Expand Down Expand Up @@ -2446,8 +2458,11 @@ myApp.controller('StudyListCtrl', function ($scope, $window, $http, QidoService,
$scope.callBackFree = true;
}, function errorCallback(response) {
DeviceService.msg($scope, {
"title": "Error",
"text": "Error copying object "+$scope.target.attrs['0020000D'].Value[0],
// "title": "Error",
// "text": "Error copying object "+$scope.target.attrs['0020000D'].Value[0],
// "status": "error"
"title": "Error "+response.status,
"text": response.data.errorMessage,
"status": "error"
});
$scope.callBackFree = true;
Expand Down Expand Up @@ -2485,8 +2500,11 @@ myApp.controller('StudyListCtrl', function ($scope, $window, $http, QidoService,
$scope.callBackFree = true;
}, function errorCallback(response) {
DeviceService.msg($scope, {
"title": "Error",
"text": "Error moving object "+m.StudyInstanceUID,
// "title": "Error",
// "text": "Error moving object "+m.StudyInstanceUID,
// "status": "error"
"title": "Error "+response.status,
"text": response.data.errorMessage,
"status": "error"
});
$scope.callBackFree = true;
Expand Down Expand Up @@ -2519,8 +2537,11 @@ myApp.controller('StudyListCtrl', function ($scope, $window, $http, QidoService,
$scope.callBackFree = true;
}, function errorCallback(response) {
DeviceService.msg($scope, {
"title": "Error",
"text": "Error moving object "+$scope.target.attrs['0020000D'].Value[0],
// "title": "Error",
// "text": "Error moving object "+$scope.target.attrs['0020000D'].Value[0],
// "status": "error"
"title": "Error "+response.status,
"text": response.data.errorMessage,
"status": "error"
});
$scope.callBackFree = true;
Expand Down

0 comments on commit 5dcf6f7

Please sign in to comment.