Search in sources :

Example 16 with Fonds

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

the class FondsHateoasController method createFondsCreatorAssociatedWithFonds.

// Create a FondsCreator and associate it with the Fonds identified by systemId
// POST [contextPath][api]/arkivstruktur/arkiv/{systemId}/ny-arkivskaper
@ApiOperation(value = "Persists a FondsCreator associated with the given Fonds systemId", notes = "Returns" + " the newly created FondsCreator after it was associated with a Fonds and persisted to the " + "database", response = FondsCreatorHateoas.class)
@SuppressWarnings("unchecked")
@ApiResponses(value = { @ApiResponse(code = 200, message = "FondsCreator " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = FondsCreatorHateoas.class), @ApiResponse(code = 201, message = "FondsCreator " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = FondsCreatorHateoas.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 FondsCreator"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR), @ApiResponse(code = 501, message = API_MESSAGE_NOT_IMPLEMENTED) })
@Counted
@Timed
@RequestMapping(method = { RequestMethod.POST }, value = FONDS + SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_FONDS_CREATOR, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<FondsCreatorHateoas> createFondsCreatorAssociatedWithFonds(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemId of fonds to associate the series with.", required = true) @PathVariable("systemID") String systemID, @ApiParam(name = "fondsCreator", value = "Incoming fondsCreator object", required = true) @RequestBody FondsCreator fondsCreator) throws NikitaException {
    validateForCreate(fondsCreator);
    fondsService.createFondsCreatorAssociatedWithFonds(systemID, fondsCreator);
    FondsCreatorHateoas fondsCreatorHateoas = new FondsCreatorHateoas(fondsCreator);
    fondsCreatorHateoasHandler.addLinks(fondsCreatorHateoas, request, new Authorisation());
    response.setHeader(ETAG, fondsCreator.getVersion().toString());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityCreatedEvent(this, fondsCreator));
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(fondsCreator.getVersion().toString()).body(fondsCreatorHateoas);
}
Also used : AfterNoarkEntityCreatedEvent(no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityCreatedEvent) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) FondsCreatorHateoas(nikita.model.noark5.v4.hateoas.FondsCreatorHateoas) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 17 with Fonds

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

the class FondsHateoasController method findAllFonds.

// Find all fonds using elasticsearch ... This is experimental and not part of the standard
// No swagger documentation on this. If we decide to drop db for es, then all re
// GET [contextPath][api]/arkivstruktur/arkiv/all/
@RequestMapping(method = RequestMethod.GET, value = FONDS + SLASH + "all" + SLASH)
public ResponseEntity<FondsHateoas> findAllFonds(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @RequestParam(name = "filter", required = false) String filter) {
    Session session = entityManager.unwrap(Session.class);
    FullTextSession fullTextSession = Search.getFullTextSession(session);
    QueryDescriptor query = ElasticsearchQueries.fromQueryString("title:test fonds");
    List<Fonds> result = fullTextSession.createFullTextQuery(query, Fonds.class).list();
    FondsHateoas fondsHateoas = new FondsHateoas((ArrayList<INikitaEntity>) (ArrayList) result);
    fondsHateoasHandler.addLinks(fondsHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(fondsHateoas);
}
Also used : QueryDescriptor(org.hibernate.search.query.engine.spi.QueryDescriptor) FullTextSession(org.hibernate.search.FullTextSession) FondsHateoas(nikita.model.noark5.v4.hateoas.FondsHateoas) INikitaEntity(nikita.model.noark5.v4.interfaces.entities.INikitaEntity) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) ArrayList(java.util.ArrayList) Fonds(nikita.model.noark5.v4.Fonds) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

Example 18 with Fonds

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

the class ArchiveStructureTests method testCorrectArchiveStructureFull.

//    @Test
public void testCorrectArchiveStructureFull() throws Exception {
    String fondsTitle = "Test fonds title";
    String fondsDescription = "Test fonds description. This fonds should be automatically deleted after tests are undertaken";
    Fonds fonds = new Fonds();
    fonds.setTitle(fondsTitle);
    fonds.setDescription(fondsDescription);
    fonds.setDocumentMedium(DOCUMENT_MEDIUM_ELECTRONIC);
    MvcResult result = mockMvc.perform(post("/" + FONDS).contentType(MediaType.APPLICATION_JSON_VALUE).content(objectMapper.writeValueAsString(fonds))).andExpect(status().isOk()).andReturn();
    String responseObject = result.getResponse().getContentAsString();
    // How do I check this is actually a fonds, a try catch?
    fonds = objectMapper.readValue(responseObject, Fonds.class);
    System.out.println(fonds);
}
Also used : Fonds(nikita.model.noark5.v4.Fonds) MvcResult(org.springframework.test.web.servlet.MvcResult)

Example 19 with Fonds

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

the class FondsDeserializer method deserialize.

@Override
public Fonds deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    Fonds fonds = new Fonds();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // TODO : Are we deserialising parent? No, it's not done here or is it????
    // Deserialise general properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkEntity(fonds, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(fonds, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseStorageLocation(fonds, objectNode);
    // Deserialize seriesStatus
    JsonNode currentNode = objectNode.get(FONDS_STATUS);
    if (currentNode != null) {
        fonds.setFondsStatus(currentNode.textValue());
        objectNode.remove(FONDS_STATUS);
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        throw new NikitaMalformedInputDataException("The arkiv you tried to create is malformed. The " + "following fields are not recognised as arkiv fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
    }
    return fonds;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Fonds(nikita.model.noark5.v4.Fonds) JsonNode(com.fasterxml.jackson.databind.JsonNode) NikitaMalformedInputDataException(nikita.util.exceptions.NikitaMalformedInputDataException)

Example 20 with Fonds

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

the class UserDeserializer method deserialize.

@Override
public Fonds deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    Fonds fonds = new Fonds();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // TODO : Are we deserialising parent? No, it's not done here or is it????
    // Deserialise general properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkEntity(fonds, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(fonds, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseStorageLocation(fonds, objectNode);
    // Deserialize seriesStatus
    JsonNode currentNode = objectNode.get(FONDS_STATUS);
    if (currentNode != null) {
        fonds.setFondsStatus(currentNode.textValue());
        objectNode.remove(FONDS_STATUS);
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        throw new NikitaMalformedInputDataException("The arkiv you tried to create is malformed. The " + "following fields are not recognised as arkiv fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
    }
    return fonds;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Fonds(nikita.model.noark5.v4.Fonds) JsonNode(com.fasterxml.jackson.databind.JsonNode) NikitaMalformedInputDataException(nikita.util.exceptions.NikitaMalformedInputDataException)

Aggregations

Fonds (nikita.model.noark5.v4.Fonds)28 Counted (com.codahale.metrics.annotation.Counted)27 ApiOperation (io.swagger.annotations.ApiOperation)27 ApiResponses (io.swagger.annotations.ApiResponses)27 Timed (com.codahale.metrics.annotation.Timed)18 Fonds (nikita.common.model.noark5.v4.Fonds)15 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)14 Authorisation (nikita.webapp.security.Authorisation)13 FondsHateoas (nikita.model.noark5.v4.hateoas.FondsHateoas)10 FondsHateoas (nikita.common.model.noark5.v4.hateoas.FondsHateoas)9 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)8 ArrayList (java.util.ArrayList)5 Series (nikita.model.noark5.v4.Series)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 List (java.util.List)4 FondsCreatorHateoas (nikita.common.model.noark5.v4.hateoas.FondsCreatorHateoas)4 SeriesHateoas (nikita.common.model.noark5.v4.hateoas.SeriesHateoas)4 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)4 FondsCreator (nikita.common.model.noark5.v4.FondsCreator)3