use of nikita.util.exceptions.NoarkEntityNotFoundException in project nikita-noark5-core by HiOA-ABI.
the class DocumentDescriptionHateoasController method findAllDocumentDescriptionAssociatedWithRecord.
// Retrieve all DocumentObjects associated with a DocumentDescription identified by systemId
// GET [contextPath][api]/arkivstruktur/dokumentbeskrivelse/{systemId}/dokumentobjekt
@ApiOperation(value = "Retrieves a list of DocumentObjects associated with a DocumentDescription", response = DocumentObjectHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "DocumentObject returned", response = DocumentObjectHateoas.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + DOCUMENT_OBJECT, method = RequestMethod.GET)
public ResponseEntity<DocumentObjectHateoas> findAllDocumentDescriptionAssociatedWithRecord(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the file to retrieve associated Record", required = true) @PathVariable("systemID") final String systemID) {
DocumentDescription documentDescription = documentDescriptionService.findBySystemIdOrderBySystemId(systemID);
if (documentDescription == null) {
throw new NoarkEntityNotFoundException("Could not find DocumentDescription object with systemID " + systemID);
}
DocumentObjectHateoas documentObjectHateoas = new DocumentObjectHateoas(new ArrayList<>(documentDescription.getReferenceDocumentObject()));
documentObjectHateoasHandler.addLinks(documentObjectHateoas, request, new Authorisation());
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(documentObjectHateoas);
}
use of nikita.util.exceptions.NoarkEntityNotFoundException in project nikita-noark5-core by HiOA-ABI.
the class DocumentObjectHateoasController method handleFileDownload.
// Get a file identified by systemID retrievable with referanseFile
// GET [contextPath][api]/arkivstruktur/dokumentobjekt/{systemID}/referanseFil
@ApiOperation(value = "Downloads a file associated with the documentObject identified by a systemId", response = DocumentObjectHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "File uploaded successfully", response = DocumentObjectHateoas.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + REFERENCE_FILE, method = RequestMethod.GET)
public void handleFileDownload(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the documentObject that has a file associated with it", required = true) @PathVariable("systemID") final String documentObjectSystemId) throws IOException {
DocumentObject documentObject = documentObjectService.findBySystemIdOrderBySystemId(documentObjectSystemId);
if (documentObject == null) {
throw new NoarkEntityNotFoundException(documentObjectSystemId);
}
Resource fileResource = documentObjectService.loadAsResource(documentObject);
String acceptType = request.getHeader(HttpHeaders.ACCEPT);
if (acceptType != null && !acceptType.equalsIgnoreCase(documentObject.getMimeType())) {
if (!acceptType.equals("*/*")) {
throw new NoarkNotAcceptableException("The request [" + request.getRequestURI() + "] is not acceptable. " + "You have issued an Accept: " + acceptType + ", while the mimeType you are trying to retrieve " + "is [" + documentObject.getMimeType() + "].");
}
}
response.setContentType(documentObject.getMimeType());
response.setContentLength(documentObject.getFileSize().intValue());
response.addHeader("Content-disposition", "inline; filename=" + documentObject.getOriginalFilename());
response.addHeader("Content-Type", documentObject.getMimeType());
InputStream filestream = fileResource.getInputStream();
try {
long bytesTotal = IOUtils.copyLarge(filestream, response.getOutputStream());
filestream.close();
} finally {
try {
// Try close without exceptions if copy() threw an
// exception. If close() is called twice, the second
// close() should be ignored.
filestream.close();
} catch (IOException e) {
// swallow any error to expose exceptions from
// IOUtil.copy() if the second close() failed.
}
}
response.flushBuffer();
}
use of nikita.util.exceptions.NoarkEntityNotFoundException in project nikita-noark5-core by HiOA-ABI.
the class FondsCreatorHateoasController method findOne.
// API - All GET Requests (CRUD - READ)
// Get a FondsCreator identified by a systemId
// GET [contextPath][api]/arkivstruktur/arkivskaper/{systemId}
@ApiOperation(value = "Retrieves a single FondsCreator entity given a systemId", response = FondsCreator.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "FondsCreator returned", response = FondsCreator.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(value = FONDS_CREATOR + SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.GET)
public ResponseEntity<FondsCreatorHateoas> findOne(HttpServletRequest request, @ApiParam(name = "systemId", value = "systemId of FondsCreator to retrieve.", required = true) @PathVariable("systemID") final String fondsCreatorSystemId) {
FondsCreator fondsCreator = fondsCreatorService.findBySystemIdOrderBySystemId(fondsCreatorSystemId);
if (fondsCreator == null) {
throw new NoarkEntityNotFoundException("Could not find FondsCreator object with systemID " + fondsCreatorSystemId);
}
FondsCreatorHateoas fondsCreatorHateoas = new FondsCreatorHateoas(fondsCreator);
fondsCreatorHateoasHandler.addLinks(fondsCreatorHateoas, request, new Authorisation());
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(fondsCreator.getVersion().toString()).body(fondsCreatorHateoas);
}
use of nikita.util.exceptions.NoarkEntityNotFoundException in project nikita-noark5-core by HiOA-ABI.
the class FondsHateoasController method findOne.
// API - All GET Requests (CRUD - READ)
// Get single fonds identified by systemId
// GET [contextPath][api]/arkivstruktur/arkiv/{systemId}/
@ApiOperation(value = "Retrieves a single fonds entity given a systemId", response = Fonds.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Fonds returned", response = Fonds.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(value = FONDS + SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.GET)
@SuppressWarnings("unchecked")
public ResponseEntity<FondsHateoas> findOne(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemId of fonds to retrieve.", required = true) @PathVariable("systemID") final String systemID) {
Fonds fonds = fondsService.findBySystemIdOrderBySystemId(systemID);
if (fonds == null) {
throw new NoarkEntityNotFoundException("Could not find fonds object with systemID " + systemID);
}
FondsHateoas fondsHateoas = new FondsHateoas(fonds);
fondsHateoasHandler.addLinks(fondsHateoas, request, new Authorisation());
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(fonds.getVersion().toString()).body(fondsHateoas);
}
use of nikita.util.exceptions.NoarkEntityNotFoundException in project nikita-noark5-core by HiOA-ABI.
the class SeriesHateoasController method findOneSeriesbySystemId.
// API - All GET Requests (CRUD - READ)
// Retrieve a Series given a systemId
// GET [contextPath][api]/arkivstruktur/arkivdel/{systemId}/
@ApiOperation(value = "Retrieves a single Series entity given a systemId", response = Series.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Series returned", response = Series.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.GET)
public ResponseEntity<SeriesHateoas> findOneSeriesbySystemId(HttpServletRequest request, @ApiParam(name = "systemID", value = "systemID of the series to retrieve", required = true) @PathVariable("systemID") final String systemID) {
Series series = seriesService.findBySystemIdOrderBySystemId(systemID);
if (series == null) {
throw new NoarkEntityNotFoundException("Could not find series object with systemID " + systemID);
}
SeriesHateoas seriesHateoas = new SeriesHateoas(series);
seriesHateoasHandler.addLinks(seriesHateoas, request, new Authorisation());
return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(series.getVersion().toString()).body(seriesHateoas);
}
Aggregations