Search in sources :

Example 36 with Authorisation

use of nikita.webapp.security.Authorisation in project nikita-noark5-core by HiOA-ABI.

the class VariantFormatService method handleUpdate.

/**
 * Update a VariantFormat identified by its systemId
 * <p>
 * Copy the values you are allowed to change, code and description
 *
 * @param systemId      The systemId of the variantFormat object you wish to
 *                      update
 * @param variantFormat The updated variantFormat object. Note the values
 *                      you are allowed to change are copied from this
 *                      object. This object is not persisted.
 * @return the updated variantFormat
 */
@Override
public MetadataHateoas handleUpdate(String systemId, Long version, VariantFormat variantFormat) {
    VariantFormat existingVariantFormat = getVariantFormatOrThrow(systemId);
    // Copy all the values you are allowed to copy ....
    if (null != existingVariantFormat.getCode()) {
        existingVariantFormat.setCode(existingVariantFormat.getCode());
    }
    if (null != existingVariantFormat.getDescription()) {
        existingVariantFormat.setDescription(existingVariantFormat.getDescription());
    }
    // Note this can potentially result in a NoarkConcurrencyException
    // exception
    existingVariantFormat.setVersion(version);
    MetadataHateoas variantFormatHateoas = new MetadataHateoas(variantFormatRepository.save(existingVariantFormat));
    metadataHateoasHandler.addLinks(variantFormatHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, existingVariantFormat));
    return variantFormatHateoas;
}
Also used : Authorisation(nikita.webapp.security.Authorisation) VariantFormat(nikita.common.model.noark5.v4.metadata.VariantFormat) MetadataHateoas(nikita.common.model.noark5.v4.hateoas.metadata.MetadataHateoas) AfterNoarkEntityUpdatedEvent(nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)

Example 37 with Authorisation

use of nikita.webapp.security.Authorisation in project nikita-noark5-core by HiOA-ABI.

the class VariantFormatService method findByDescription.

/**
 * Retrieve all VariantFormat that have a given description.
 * <br>
 * Note, this will be replaced by OData search.
 *
 * @param description Description of object you wish to retrieve. The
 *                    whole text, this is an exact search.
 * @return A list of VariantFormat objects wrapped as a MetadataHateoas
 * object
 */
@Override
public MetadataHateoas findByDescription(String description) {
    MetadataHateoas metadataHateoas = new MetadataHateoas((List<INikitaEntity>) (List) variantFormatRepository.findByDescription(description), VARIANT_FORMAT);
    metadataHateoasHandler.addLinks(metadataHateoas, new Authorisation());
    return metadataHateoas;
}
Also used : INikitaEntity(nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity) Authorisation(nikita.webapp.security.Authorisation) List(java.util.List) MetadataHateoas(nikita.common.model.noark5.v4.hateoas.metadata.MetadataHateoas)

Example 38 with Authorisation

use of nikita.webapp.security.Authorisation in project nikita-noark5-core by HiOA-ABI.

the class BasicRecordHateoasController method updateBasicRecord.

// API - All PUT Requests (CRUD - UPDATE)
// Update a BasicRecord
// PUT [contextPath][api]/arkivstruktur/basisregistrering/{systemID}
@ApiOperation(value = "Updates a BasicRecord object", notes = "Returns the newly" + " update BasicRecord object after it is persisted to the database", response = BasicRecordHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "BasicRecord " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = BasicRecordHateoas.class), @ApiResponse(code = 201, message = "BasicRecord " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = BasicRecordHateoas.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 BasicRecord"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@RequestMapping(method = RequestMethod.PUT, value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<BasicRecordHateoas> updateBasicRecord(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemId of basicRecord to update.", required = true) @PathVariable("systemID") String systemID, @ApiParam(name = "basicRecord", value = "Incoming basicRecord object", required = true) @RequestBody BasicRecord basicRecord) throws NikitaException {
    validateForUpdate(basicRecord);
    BasicRecord updatedBasicRecord = basicRecordService.handleUpdate(systemID, parseETAG(request.getHeader(ETAG)), basicRecord);
    BasicRecordHateoas basicRecordHateoas = new BasicRecordHateoas(updatedBasicRecord);
    basicRecordHateoasHandler.addLinks(basicRecordHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, updatedBasicRecord));
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(updatedBasicRecord.getVersion().toString()).body(basicRecordHateoas);
}
Also used : Authorisation(nikita.webapp.security.Authorisation) AfterNoarkEntityUpdatedEvent(nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 39 with Authorisation

use of nikita.webapp.security.Authorisation in project nikita-noark5-core by HiOA-ABI.

the class BasicRecordHateoasController method findOneBasicRecordBySystemId.

// API - All GET Requests (CRUD - READ)
@ApiOperation(value = "Retrieves a single BasicRecord entity given a systemId", response = BasicRecord.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "BasicRecord returned", response = BasicRecord.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<BasicRecordHateoas> findOneBasicRecordBySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the basicRecord to retrieve", required = true) @PathVariable("systemID") final String basicRecordSystemId) {
    BasicRecord createdBasicRecord = basicRecordService.findBySystemId(basicRecordSystemId);
    BasicRecordHateoas basicRecordHateoas = new BasicRecordHateoas(createdBasicRecord);
    basicRecordHateoasHandler.addLinks(basicRecordHateoas, new Authorisation());
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(createdBasicRecord.getVersion().toString()).body(basicRecordHateoas);
}
Also used : Authorisation(nikita.webapp.security.Authorisation) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 40 with Authorisation

use of nikita.webapp.security.Authorisation in project nikita-noark5-core by HiOA-ABI.

the class ClassificationSystemHateoasController method createClassAssociatedWithClassificationSystem.

@ApiOperation(value = "Persists a Class object associated with the given ClassificationSystem systemId", notes = "Returns the newly created class object after it was associated with a classificationSystem " + "object and persisted to the database", response = ClassHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Class " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = Class.class), @ApiResponse(code = 201, message = "Class " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = Class.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 Class"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@RequestMapping(method = RequestMethod.POST, value = CLASSIFICATION_SYSTEM + SLASH + LEFT_PARENTHESIS + "classificationSystemSystemId" + RIGHT_PARENTHESIS + SLASH + NEW_RECORD, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<ClassHateoas> createClassAssociatedWithClassificationSystem(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "classificationSystemSystemId", value = "systemId of classificationSystem to associate the klass with.", required = true) @PathVariable String classificationSystemSystemId, @ApiParam(name = "klass", value = "Incoming class object", required = true) @RequestBody Class klass) throws NikitaException {
    Class createdClass = classificationSystemService.createClassAssociatedWithClassificationSystem(classificationSystemSystemId, klass);
    ClassHateoas classHateoas = new ClassHateoas(createdClass);
    classHateoasHandler.addLinks(classHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityCreatedEvent(this, createdClass));
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(createdClass.getVersion().toString()).body(classHateoas);
}
Also used : ClassHateoas(nikita.common.model.noark5.v4.hateoas.ClassHateoas) AfterNoarkEntityCreatedEvent(nikita.webapp.web.events.AfterNoarkEntityCreatedEvent) Authorisation(nikita.webapp.security.Authorisation) Class(nikita.common.model.noark5.v4.Class) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Authorisation (nikita.webapp.security.Authorisation)212 MetadataHateoas (nikita.common.model.noark5.v4.hateoas.metadata.MetadataHateoas)121 Counted (com.codahale.metrics.annotation.Counted)98 ApiOperation (io.swagger.annotations.ApiOperation)87 ApiResponses (io.swagger.annotations.ApiResponses)87 List (java.util.List)76 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)75 AfterNoarkEntityUpdatedEvent (nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)34 CaseFileHateoas (nikita.common.model.noark5.v4.hateoas.casehandling.CaseFileHateoas)13 NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)13 AfterNoarkEntityCreatedEvent (nikita.webapp.web.events.AfterNoarkEntityCreatedEvent)13 Class (nikita.common.model.noark5.v4.Class)8 Fonds (nikita.common.model.noark5.v4.Fonds)8 CaseFile (nikita.common.model.noark5.v4.casehandling.CaseFile)8 NikitaException (nikita.common.util.exceptions.NikitaException)8 DocumentDescription (nikita.common.model.noark5.v4.DocumentDescription)7 DocumentObject (nikita.common.model.noark5.v4.DocumentObject)7 ClassHateoas (nikita.common.model.noark5.v4.hateoas.ClassHateoas)7 DocumentObjectHateoas (nikita.common.model.noark5.v4.hateoas.DocumentObjectHateoas)7 FondsCreatorHateoas (nikita.common.model.noark5.v4.hateoas.FondsCreatorHateoas)7