Search in sources :

Example 1 with Class

use of nikita.common.model.noark5.v4.Class in project nikita-noark5-core by HiOA-ABI.

the class ClassHateoasController method createClassAssociatedWithClassificationSystem.

// API - All POST Requests (CRUD - CREATE)
// POST [contextPath][api]/arkivstruktur/klassifikasjonsystem/{systemID}/ny-underklass
@ApiOperation(value = "Persists a Class object associated with the (other) given Class systemId", notes = "Returns the newly created class object after it was associated with a class" + "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
@Timed
@RequestMapping(method = RequestMethod.POST, value = SLASH + LEFT_PARENTHESIS + "classificationSystemSystemId" + RIGHT_PARENTHESIS + SLASH + NEW_SUB_CLASS, 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 classSystemId, @ApiParam(name = "klass", value = "Incoming class object", required = true) @RequestBody Class klass) throws NikitaException {
    Class createdClass = classService.createClassAssociatedWithClass(classSystemId, klass);
    ClassHateoas classHateoas = new ClassHateoas(createdClass);
    classHateoasHandler.addLinks(classHateoas, request, 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.model.noark5.v4.hateoas.ClassHateoas) AfterNoarkEntityCreatedEvent(no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityCreatedEvent) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) Class(nikita.model.noark5.v4.Class) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with Class

use of nikita.common.model.noark5.v4.Class 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.findBySystemIdOrderBySystemId(classSystemId);
    if (klass == null) {
        throw new NoarkEntityNotFoundException(classSystemId);
    }
    ClassHateoas classHateoas = new ClassHateoas(klass);
    classHateoasHandler.addLinks(classHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).eTag(klass.getVersion().toString()).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(classHateoas);
}
Also used : ClassHateoas(nikita.model.noark5.v4.hateoas.ClassHateoas) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) Class(nikita.model.noark5.v4.Class) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException)

Example 3 with Class

use of nikita.common.model.noark5.v4.Class in project nikita-noark5-core by HiOA-ABI.

the class ClassDeserializer method deserialize.

@Override
public Class deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    Class klass = new Class();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkEntity(klass, objectNode);
    // Deserialize classId
    JsonNode currentNode = objectNode.get(CLASS_ID);
    if (null != currentNode) {
        klass.setClassId(currentNode.textValue());
        objectNode.remove(CLASS_ID);
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        throw new NikitaMalformedInputDataException("The klasse you tried to create is malformed. The " + "following fields are not recognised as klasse fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
    }
    return klass;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Class(nikita.model.noark5.v4.Class) JsonNode(com.fasterxml.jackson.databind.JsonNode) NikitaMalformedInputDataException(nikita.util.exceptions.NikitaMalformedInputDataException)

Example 4 with Class

use of nikita.common.model.noark5.v4.Class in project nikita-noark5-core by HiOA-ABI.

the class ClassHateoasSerializer method serializeNoarkEntity.

@Override
public void serializeNoarkEntity(INikitaEntity noarkSystemIdEntity, HateoasNoarkObject classHateoas, JsonGenerator jgen) throws IOException {
    Class klass = (Class) noarkSystemIdEntity;
    jgen.writeStartObject();
    CommonUtils.Hateoas.Serialize.printSystemIdEntity(jgen, klass);
    CommonUtils.Hateoas.Serialize.printTitleAndDescription(jgen, klass);
    CommonUtils.Hateoas.Serialize.printCreateEntity(jgen, klass);
    CommonUtils.Hateoas.Serialize.printFinaliseEntity(jgen, klass);
    // TODO: Fix this ! CommonCommonUtils.Hateoas.Serialize.printCrossReference(jgen, klass);
    CommonUtils.Hateoas.Serialize.printDisposal(jgen, klass);
    CommonUtils.Hateoas.Serialize.printScreening(jgen, klass);
    CommonUtils.Hateoas.Serialize.printClassified(jgen, klass);
    CommonUtils.Hateoas.Serialize.printHateoasLinks(jgen, classHateoas.getLinks(klass));
    jgen.writeEndObject();
}
Also used : Class(nikita.model.noark5.v4.Class)

Example 5 with Class

use of nikita.common.model.noark5.v4.Class in project nikita-noark5-core by HiOA-ABI.

the class ClassService method getClassOrThrow.

// All HELPER operations
/**
     * 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 Class back. If there is no valid
     * Class, an exception is thrown
     *
     * @param classSystemId
     * @return
     */
protected Class getClassOrThrow(@NotNull String classSystemId) {
    Class klass = classRepository.findBySystemIdOrderBySystemId(classSystemId);
    if (null == klass) {
        String info = INFO_CANNOT_FIND_OBJECT + " Class, using systemId " + classSystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    }
    return klass;
}
Also used : Class(nikita.model.noark5.v4.Class) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)18 ApiOperation (io.swagger.annotations.ApiOperation)18 ApiResponses (io.swagger.annotations.ApiResponses)18 Class (nikita.model.noark5.v4.Class)17 Class (nikita.common.model.noark5.v4.Class)16 Timed (com.codahale.metrics.annotation.Timed)9 Authorisation (nikita.webapp.security.Authorisation)9 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)9 ClassHateoas (nikita.common.model.noark5.v4.hateoas.ClassHateoas)7 ClassHateoas (nikita.model.noark5.v4.hateoas.ClassHateoas)7 AfterNoarkEntityDeletedEvent (nikita.webapp.web.events.AfterNoarkEntityDeletedEvent)5 AfterNoarkEntityDeletedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityDeletedEvent)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 NikitaException (nikita.common.util.exceptions.NikitaException)4 NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)4 NikitaException (nikita.util.exceptions.NikitaException)4 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)4 Date (java.util.Date)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2