Search in sources :

Example 36 with NoarkEntityNotFoundException

use of nikita.common.util.exceptions.NoarkEntityNotFoundException in project nikita-noark5-core by HiOA-ABI.

the class VariantFormatService method getVariantFormatOrThrow.

/**
 * Internal helper method. Rather than having a find and try catch in
 * multiple methods, we have it here once. If you call this, be aware
 * that you will only ever get a valid VariantFormat object back. If there
 * is no VariantFormat object, a NoarkEntityNotFoundException exception
 * is thrown
 *
 * @param systemId The systemId of the VariantFormat object to retrieve
 * @return the VariantFormat object
 */
private VariantFormat getVariantFormatOrThrow(@NotNull String systemId) {
    VariantFormat variantFormat = variantFormatRepository.findBySystemId(systemId);
    if (variantFormat == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " VariantFormat, using " + "systemId " + systemId;
        logger.error(info);
        throw new NoarkEntityNotFoundException(info);
    }
    return variantFormat;
}
Also used : NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException) VariantFormat(nikita.common.model.noark5.v4.metadata.VariantFormat)

Example 37 with NoarkEntityNotFoundException

use of nikita.common.util.exceptions.NoarkEntityNotFoundException in project nikita-noark5-core by HiOA-ABI.

the class PrecedenceService method getPrecedenceOrThrow.

/**
 * Internal helper method. Rather than having a find and try catch in multiple methods, we have it here once.
 * If you call this, be aware that you will only ever get a valid Precedence back. If there is no valid
 * Precedence, an exception is thrown
 *
 * @param precedenceSystemId
 * @return
 */
protected Precedence getPrecedenceOrThrow(@NotNull String precedenceSystemId) {
    Precedence precedence = precedenceRepository.findBySystemId(precedenceSystemId);
    if (precedence == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " Precedence, using systemId " + precedenceSystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    }
    return precedence;
}
Also used : NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException) Precedence(nikita.common.model.noark5.v4.casehandling.Precedence)

Example 38 with NoarkEntityNotFoundException

use of nikita.common.util.exceptions.NoarkEntityNotFoundException in project nikita-noark5-core by HiOA-ABI.

the class ClassHateoasController method findOne.

// API - All GET Requests (CRUD - READ)
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.GET)
public ResponseEntity<ClassHateoas> findOne(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemId", value = "systemId of class to retrieve.", required = true) @PathVariable("systemID") final String classSystemId) {
    Class klass = classService.findBySystemId(classSystemId);
    if (klass == null) {
        throw new NoarkEntityNotFoundException(classSystemId);
    }
    ClassHateoas classHateoas = new ClassHateoas(klass);
    classHateoasHandler.addLinks(classHateoas, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).eTag(klass.getVersion().toString()).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(classHateoas);
}
Also used : ClassHateoas(nikita.common.model.noark5.v4.hateoas.ClassHateoas) Authorisation(nikita.webapp.security.Authorisation) Class(nikita.common.model.noark5.v4.Class) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException)

Example 39 with NoarkEntityNotFoundException

use of nikita.common.util.exceptions.NoarkEntityNotFoundException in project nikita-noark5-core by HiOA-ABI.

the class ClassificationSystemHateoasController method findOne.

// API - All GET Requests (CRUD - READ)
@RequestMapping(value = CLASSIFICATION_SYSTEM + SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.GET)
public ResponseEntity<ClassificationSystemHateoas> findOne(HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemId", value = "systemId of classificationSystem to retrieve.", required = true) @PathVariable("systemID") final String classificationSystemId) {
    ClassificationSystem classificationSystem = classificationSystemService.findBySystemId(classificationSystemId);
    if (classificationSystem == null) {
        throw new NoarkEntityNotFoundException(classificationSystemId);
    }
    ClassificationSystemHateoas classificationSystemHateoas = new ClassificationSystemHateoas(classificationSystem);
    classificationSystemHateoasHandler.addLinks(classificationSystemHateoas, new Authorisation());
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(classificationSystem.getVersion().toString()).body(classificationSystemHateoas);
}
Also used : ClassificationSystem(nikita.common.model.noark5.v4.ClassificationSystem) ClassificationSystemHateoas(nikita.common.model.noark5.v4.hateoas.ClassificationSystemHateoas) Authorisation(nikita.webapp.security.Authorisation) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException)

Example 40 with NoarkEntityNotFoundException

use of nikita.common.util.exceptions.NoarkEntityNotFoundException in project nikita-noark5-core by HiOA-ABI.

the class DocumentDescriptionHateoasController method findOneDocumentDescriptionBySystemId.

// API - All GET Requests (CRUD - READ)
@ApiOperation(value = "Retrieves a single DocumentDescription entity given a systemId", response = DocumentDescription.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "DocumentDescription returned", response = DocumentDescription.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<DocumentDescriptionHateoas> findOneDocumentDescriptionBySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the documentDescription to retrieve", required = true) @PathVariable("systemID") final String systemID) {
    DocumentDescription documentDescription = documentDescriptionService.findBySystemId(systemID);
    if (documentDescription == null) {
        throw new NoarkEntityNotFoundException(systemID);
    }
    DocumentDescriptionHateoas documentDescriptionHateoas = new DocumentDescriptionHateoas(documentDescription);
    documentDescriptionHateoasHandler.addLinks(documentDescriptionHateoas, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(documentDescription.getVersion().toString()).body(documentDescriptionHateoas);
}
Also used : DocumentDescription(nikita.common.model.noark5.v4.DocumentDescription) Authorisation(nikita.webapp.security.Authorisation) DocumentDescriptionHateoas(nikita.common.model.noark5.v4.hateoas.DocumentDescriptionHateoas) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)55 Authorisation (nikita.webapp.security.Authorisation)13 Counted (com.codahale.metrics.annotation.Counted)12 ApiOperation (io.swagger.annotations.ApiOperation)10 ApiResponses (io.swagger.annotations.ApiResponses)10 List (java.util.List)5 DocumentDescription (nikita.common.model.noark5.v4.DocumentDescription)5 DocumentObject (nikita.common.model.noark5.v4.DocumentObject)5 CaseFile (nikita.common.model.noark5.v4.casehandling.CaseFile)5 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)5 Class (nikita.common.model.noark5.v4.Class)4 File (nikita.common.model.noark5.v4.File)4 Record (nikita.common.model.noark5.v4.Record)4 BasicRecord (nikita.common.model.noark5.v4.BasicRecord)3 ClassificationSystem (nikita.common.model.noark5.v4.ClassificationSystem)3 Series (nikita.common.model.noark5.v4.Series)3 DocumentObjectHateoas (nikita.common.model.noark5.v4.hateoas.DocumentObjectHateoas)3 NoarkEntityEditWhenClosedException (nikita.common.util.exceptions.NoarkEntityEditWhenClosedException)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2