Search in sources :

Example 11 with RegistryEntryHateoas

use of nikita.common.model.noark5.v4.hateoas.casehandling.RegistryEntryHateoas in project nikita-noark5-core by HiOA-ABI.

the class CaseFileHateoasController method createDefaultRegistryEntry.

// API - All GET Requests (CRUD - READ)
// Create a RegistryEntry object with default values
// GET [contextPath][api]/casehandling/mappe/SYSTEM_ID/ny-journalpost
@ApiOperation(value = "Create a RegistryEntry with default values", response = RegistryEntry.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "RegistryEntry returned", response = RegistryEntry.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
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_REGISTRY_ENTRY, method = RequestMethod.GET)
public ResponseEntity<RegistryEntryHateoas> createDefaultRegistryEntry(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response) {
    RegistryEntry defaultRegistryEntry = new RegistryEntry();
    // TODO consider using Calendar date = new GregorianCalendar()
    Date now = new Date();
    // TODO figure out good defaults to return
    defaultRegistryEntry.setRecordDate(now);
    defaultRegistryEntry.setDocumentDate(now);
    defaultRegistryEntry.setRecordStatus(TEST_RECORD_STATUS);
    defaultRegistryEntry.setRegistryEntryType(TEST_REGISTRY_ENTRY_TYPE);
    defaultRegistryEntry.setRecordYear(Calendar.getInstance().get(Calendar.YEAR));
    // TODO generate these
    // defaultRegistryEntry.setRecordSequenceNumber(201701011);
    // defaultRegistryEntry.setRegistryEntryNumber(201701);
    RegistryEntryHateoas registryEntryHateoas = new RegistryEntryHateoas(defaultRegistryEntry);
    registryEntryHateoasHandler.addLinksOnNew(registryEntryHateoas, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(registryEntryHateoas);
}
Also used : RegistryEntryHateoas(nikita.common.model.noark5.v4.hateoas.casehandling.RegistryEntryHateoas) Authorisation(nikita.webapp.security.Authorisation) RegistryEntry(nikita.common.model.noark5.v4.casehandling.RegistryEntry) Date(java.util.Date) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 12 with RegistryEntryHateoas

use of nikita.common.model.noark5.v4.hateoas.casehandling.RegistryEntryHateoas in project nikita-noark5-core by HiOA-ABI.

the class CaseFileHateoasController method createRegistryEntryAssociatedWithFile.

// API - All POST Requests (CRUD - CREATE)
// Create a RegistryEntry entity
// POST [contextPath][api]/casehandling/{systemId}/ny-journalpost
@ApiOperation(value = "Persists a RegistryEntry object associated with the given Series systemId", notes = "Returns the newly created record object after it was associated with a File object and " + "persisted to the database", response = RegistryEntryHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "RegistryEntry " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = RegistryEntryHateoas.class), @ApiResponse(code = 201, message = "RegistryEntry " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = RegistryEntryHateoas.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 RegistryEntry"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@RequestMapping(method = RequestMethod.POST, value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_REGISTRY_ENTRY, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<RegistryEntryHateoas> createRegistryEntryAssociatedWithFile(HttpServletRequest request, @ApiParam(name = "systemID", value = "systemId of file to associate the record with", required = true) @PathVariable("systemID") final String systemID, @ApiParam(name = "RegistryEntry", value = "Incoming registryEntry object", required = true) @RequestBody RegistryEntry registryEntry) throws NikitaException {
    RegistryEntry createdRegistryEntry = caseFileService.createRegistryEntryAssociatedWithCaseFile(systemID, registryEntry);
    RegistryEntryHateoas registryEntryHateoas = new RegistryEntryHateoas(createdRegistryEntry);
    registryEntryHateoasHandler.addLinks(registryEntryHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityCreatedEvent(this, createdRegistryEntry));
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(createdRegistryEntry.getVersion().toString()).body(registryEntryHateoas);
}
Also used : RegistryEntryHateoas(nikita.common.model.noark5.v4.hateoas.casehandling.RegistryEntryHateoas) AfterNoarkEntityCreatedEvent(nikita.webapp.web.events.AfterNoarkEntityCreatedEvent) Authorisation(nikita.webapp.security.Authorisation) RegistryEntry(nikita.common.model.noark5.v4.casehandling.RegistryEntry) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 13 with RegistryEntryHateoas

use of nikita.common.model.noark5.v4.hateoas.casehandling.RegistryEntryHateoas in project nikita-noark5-core by HiOA-ABI.

the class RegistryEntryHateoasController method findOneRegistryEntrybySystemId.

// Retrieve a single registryEntry identified by systemId
// GET [contextPath][api]/casehandling/journalpost/{systemID}
@ApiOperation(value = "Retrieves a single RegistryEntry entity given a systemId", response = RegistryEntry.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "RegistryEntry returned", response = RegistryEntry.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
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.GET)
public ResponseEntity<RegistryEntryHateoas> findOneRegistryEntrybySystemId(HttpServletRequest request, @ApiParam(name = "systemID", value = "systemID of the registryEntry to retrieve", required = true) @PathVariable("systemID") final String registryEntrySystemId) {
    RegistryEntry registryEntry = registryEntryService.findBySystemId(registryEntrySystemId);
    RegistryEntryHateoas registryEntryHateoas = new RegistryEntryHateoas(registryEntry);
    registryEntryHateoasHandler.addLinks(registryEntryHateoas, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(registryEntry.getVersion().toString()).body(registryEntryHateoas);
}
Also used : Authorisation(nikita.webapp.security.Authorisation) RegistryEntry(nikita.common.model.noark5.v4.casehandling.RegistryEntry) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 14 with RegistryEntryHateoas

use of nikita.common.model.noark5.v4.hateoas.casehandling.RegistryEntryHateoas in project nikita-noark5-core by HiOA-ABI.

the class RegistryEntryHateoasController method updateRegistryEntry.

// Update a RegistryEntry with given values
// PUT [contextPath][api]/casehandling/journalpost/{systemId}
@ApiOperation(value = "Updates a RegistryEntry identified by a given systemId", notes = "Returns the newly updated registryEntry", response = RegistryEntryHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "RegistryEntry " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = RegistryEntryHateoas.class), @ApiResponse(code = 201, message = "RegistryEntry " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = RegistryEntryHateoas.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 RegistryEntry"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.PUT, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<RegistryEntryHateoas> updateRegistryEntry(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemId of registryEntry to update", required = true) @PathVariable("systemID") final String systemID, @ApiParam(name = "RegistryEntry", value = "Incoming registryEntry object", required = true) @RequestBody RegistryEntry registryEntry) throws NikitaException {
    validateForUpdate(registryEntry);
    RegistryEntry updatedRegistryEntry = registryEntryService.handleUpdate(systemID, parseETAG(request.getHeader(ETAG)), registryEntry);
    RegistryEntryHateoas registryEntryHateoas = new RegistryEntryHateoas(updatedRegistryEntry);
    registryEntryHateoasHandler.addLinks(registryEntryHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, updatedRegistryEntry));
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(updatedRegistryEntry.getVersion().toString()).body(registryEntryHateoas);
}
Also used : Authorisation(nikita.webapp.security.Authorisation) RegistryEntry(nikita.common.model.noark5.v4.casehandling.RegistryEntry) AfterNoarkEntityUpdatedEvent(nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)12 ApiOperation (io.swagger.annotations.ApiOperation)12 ApiResponses (io.swagger.annotations.ApiResponses)12 Timed (com.codahale.metrics.annotation.Timed)6 Authorisation (nikita.webapp.security.Authorisation)6 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)6 RegistryEntry (nikita.common.model.noark5.v4.casehandling.RegistryEntry)5 RegistryEntry (nikita.model.noark5.v4.casehandling.RegistryEntry)5 RegistryEntryHateoas (nikita.common.model.noark5.v4.hateoas.casehandling.RegistryEntryHateoas)3 RegistryEntryHateoas (nikita.model.noark5.v4.hateoas.casehandling.RegistryEntryHateoas)3 Date (java.util.Date)2 List (java.util.List)2 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)2 ArrayList (java.util.ArrayList)1 CaseFile (nikita.common.model.noark5.v4.casehandling.CaseFile)1 NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)1 CaseFile (nikita.model.noark5.v4.casehandling.CaseFile)1 INikitaEntity (nikita.model.noark5.v4.interfaces.entities.INikitaEntity)1 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)1 AfterNoarkEntityCreatedEvent (nikita.webapp.web.events.AfterNoarkEntityCreatedEvent)1