Search in sources :

Example 31 with Timed

use of com.codahale.metrics.annotation.Timed in project nikita-noark5-core by HiOA-ABI.

the class DocumentObjectHateoasController method findOneDocumentObjectBySystemId.

// API - All GET Requests (CRUD - READ)
// Get a documentObject identified by systemID
// GET [contextPath][api]/arkivstruktur/dokumentobjekt/{systemID}
@ApiOperation(value = "Retrieves a single DocumentObject entity given a systemId", response = DocumentObject.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "DocumentObject returned", response = DocumentObject.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, produces = { NOARK5_V4_CONTENT_TYPE_JSON, NOARK5_V4_CONTENT_TYPE_JSON_XML })
public ResponseEntity<DocumentObjectHateoas> findOneDocumentObjectBySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the documentObject to retrieve", required = true) @PathVariable("systemID") final String documentObjectSystemId) {
    DocumentObject createdDocumentObject = documentObjectService.findBySystemIdOrderBySystemId(documentObjectSystemId);
    if (createdDocumentObject == null) {
        throw new NoarkEntityNotFoundException(documentObjectSystemId);
    }
    DocumentObjectHateoas documentObjectHateoas = new DocumentObjectHateoas(createdDocumentObject);
    documentObjectHateoasHandler.addLinks(documentObjectHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(createdDocumentObject.getVersion().toString()).body(documentObjectHateoas);
}
Also used : DocumentObjectHateoas(nikita.model.noark5.v4.hateoas.DocumentObjectHateoas) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) DocumentObject(nikita.model.noark5.v4.DocumentObject) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 32 with Timed

use of com.codahale.metrics.annotation.Timed in project nikita-noark5-core by HiOA-ABI.

the class DocumentObjectHateoasController method findAllDocumentObject.

// Get all documentObject
// GET [contextPath][api]/arkivstruktur/dokumentobjekt/
@ApiOperation(value = "Retrieves multiple DocumentObject entities limited by ownership rights", notes = "The field skip" + "tells how many DocumentObject rows of the result set to ignore (starting at 0), while  top tells how many rows" + " after skip to return. Note if the value of top is greater than system value " + " nikita-noark5-core.pagination.maxPageSize, then nikita-noark5-core.pagination.maxPageSize is used. ", response = DocumentObjectHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "DocumentObject list found", 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(method = RequestMethod.GET, produces = { NOARK5_V4_CONTENT_TYPE_JSON, NOARK5_V4_CONTENT_TYPE_JSON_XML })
public ResponseEntity<DocumentObjectHateoas> findAllDocumentObject(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @RequestParam(name = "top", required = false) Integer top, @RequestParam(name = "skip", required = false) Integer skip, @RequestParam(name = "filter", required = false) String filter) {
    String reg = " ";
    String[] pieces;
    DocumentObjectHateoas documentObjectHateoas = null;
    if (filter != null) {
        pieces = filter.split(reg);
        if (pieces.length == 3 && pieces[1].equalsIgnoreCase("eq")) {
            pieces[2] = pieces[2].replace("\'", "");
            documentObjectHateoas = new DocumentObjectHateoas((ArrayList<INikitaEntity>) (ArrayList) documentObjectService.findDocumentObjectByAnyColumn(pieces[0], pieces[2]));
        }
    }
    if (null == documentObjectHateoas) {
        documentObjectHateoas = new DocumentObjectHateoas((ArrayList<INikitaEntity>) (ArrayList) documentObjectService.findDocumentObjectByOwnerPaginated(top, skip));
    }
    documentObjectHateoasHandler.addLinks(documentObjectHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(documentObjectHateoas);
}
Also used : DocumentObjectHateoas(nikita.model.noark5.v4.hateoas.DocumentObjectHateoas) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) ArrayList(java.util.ArrayList) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 33 with Timed

use of com.codahale.metrics.annotation.Timed in project nikita-noark5-core by HiOA-ABI.

the class FileHateoasController method createDefaultRecord.

// Create a Record with default values
// GET [contextPath][api]/arkivstruktur/mappe/{systemId}/ny-registrering
@ApiOperation(value = "Create a Record with default values", response = Record.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Record returned", response = Record.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 + NEW_RECORD, method = RequestMethod.GET)
public ResponseEntity<RecordHateoas> createDefaultRecord(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response) {
    Record defaultRecord = new Record();
    defaultRecord.setArchivedBy(TEST_USER_CASE_HANDLER_2);
    defaultRecord.setArchivedDate(new Date());
    RecordHateoas recordHateoas = new RecordHateoas(defaultRecord);
    recordHateoasHandler.addLinksOnNew(recordHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(recordHateoas);
}
Also used : Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) Date(java.util.Date) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 34 with Timed

use of com.codahale.metrics.annotation.Timed in project nikita-noark5-core by HiOA-ABI.

the class FileHateoasController method findAllRecordsAssociatedWithFile.

// API - All GET Requests (CRUD - READ)
// Retrieve all Records associated with File identified by systemId
// GET [contextPath][api]/arkivstruktur/mappe/{systemId}/registrering
// REL http://rel.kxml.no/noark5/v4/api/arkivstruktur/registrering/
@ApiOperation(value = "Retrieve all Record associated with a File identified by systemId", response = RecordHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Record returned", response = RecordHateoas.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 + REGISTRATION, method = RequestMethod.GET)
public ResponseEntity<RecordHateoas> findAllRecordsAssociatedWithFile(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) {
    File file = fileService.findBySystemIdOrderBySystemId(systemID);
    if (file == null) {
        throw new NoarkEntityNotFoundException("Could not find File object with systemID " + systemID);
    }
    RecordHateoas recordHateoas = new RecordHateoas(new ArrayList<>(file.getReferenceRecord()));
    recordHateoasHandler.addLinks(recordHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(recordHateoas);
}
Also used : Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 35 with Timed

use of com.codahale.metrics.annotation.Timed in project nikita-noark5-core by HiOA-ABI.

the class FileHateoasController method updateFile.

// API - All PUT Requests (CRUD - UPDATE)
// Update a File with given values
// PUT [contextPath][api]/arkivstruktur/mappe/{systemId}
@ApiOperation(value = "Updates a File identified by a given systemId", notes = "Returns the newly updated file", response = FileHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "File " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = FileHateoas.class), @ApiResponse(code = 201, message = "File " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = FileHateoas.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 404, message = API_MESSAGE_PARENT_DOES_NOT_EXIST + " of type File"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.PUT, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<FileHateoas> updateFile(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemId of file to update", required = true) @PathVariable("systemID") final String systemID, @ApiParam(name = "File", value = "Incoming file object", required = true) @RequestBody File file) throws NikitaException {
    validateForUpdate(file);
    File updatedFile = fileService.handleUpdate(systemID, parseETAG(request.getHeader(ETAG)), file);
    FileHateoas fileHateoas = new FileHateoas(updatedFile);
    fileHateoasHandler.addLinks(fileHateoas, request, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, updatedFile));
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(updatedFile.getVersion().toString()).body(fileHateoas);
}
Also used : Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) CaseFileHateoas(nikita.model.noark5.v4.hateoas.casehandling.CaseFileHateoas) AfterNoarkEntityUpdatedEvent(no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)1042 Path (javax.ws.rs.Path)386 ApiOperation (io.swagger.annotations.ApiOperation)316 ApiResponses (io.swagger.annotations.ApiResponses)218 GET (javax.ws.rs.GET)203 POST (javax.ws.rs.POST)167 URI (java.net.URI)157 Produces (javax.ws.rs.Produces)148 Counted (com.codahale.metrics.annotation.Counted)122 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)105 AuditEvent (org.graylog2.audit.jersey.AuditEvent)96 Consumes (javax.ws.rs.Consumes)91 PUT (javax.ws.rs.PUT)91 DELETE (javax.ws.rs.DELETE)78 Response (javax.ws.rs.core.Response)73 NotFoundException (javax.ws.rs.NotFoundException)68 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)66 ResponseEntity (org.springframework.http.ResponseEntity)66 HttpHeaders (org.springframework.http.HttpHeaders)54 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)53