Search in sources :

Example 31 with Fonds

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

the class FondsService method handleUpdate.

// All UPDATE operations
/**
 * Updates a Fonds object in the database. First we try to locate the
 * Fonds object. If the Fonds object does not exist a
 * NoarkEntityNotFoundException exception is thrown that the caller has
 * to deal with.
 * <br>
 * After this the values you are allowed to update are copied from the
 * incomingFonds object to the existingFonds object and the existingFonds
 * object will be persisted to the database when the transaction boundary
 * is over.
 * <p>
 * Note, the version corresponds to the version number, when the object
 * was initially retrieved from the database. If this number is not the
 * same as the version number when re-retrieving the Fonds object from
 * the database a NoarkConcurrencyException is thrown. Note. This happens
 * when the call to Fonds.setVersion() occurs.
 *
 * @param fondsSystemId The systemId of the fonds object to retrieve
 * @param version       The last known version number (derived from an ETAG)
 * @param incomingFonds The incoming fonds object
 */
@Override
public FondsHateoas handleUpdate(@NotNull String fondsSystemId, @NotNull Long version, @NotNull Fonds incomingFonds) {
    Fonds existingFonds = getFondsOrThrow(fondsSystemId);
    // Copy all the values you are allowed to copy ....
    if (null != incomingFonds.getDescription()) {
        existingFonds.setDescription(incomingFonds.getDescription());
    }
    if (null != incomingFonds.getTitle()) {
        existingFonds.setTitle(incomingFonds.getTitle());
    }
    if (null != incomingFonds.getDocumentMedium()) {
        existingFonds.setDocumentMedium(existingFonds.getDocumentMedium());
    }
    // Note this can potentially result in a NoarkConcurrencyException
    // exception
    existingFonds.setVersion(version);
    FondsHateoas fondsHateoas = new FondsHateoas(fondsRepository.save(existingFonds));
    fondsHateoasHandler.addLinks(fondsHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, existingFonds));
    return fondsHateoas;
}
Also used : FondsHateoas(nikita.common.model.noark5.v4.hateoas.FondsHateoas) Authorisation(nikita.webapp.security.Authorisation) Fonds(nikita.common.model.noark5.v4.Fonds) AfterNoarkEntityUpdatedEvent(nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)

Example 32 with Fonds

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

the class FondsService method createNewFonds.

// All CREATE operations
/**
 * Persists a new fonds object to the database. Some values are set in the
 * incoming payload (e.g. title) and some are set by the core.
 * owner, createdBy, createdDate are automatically set by the core.
 *
 * @param fonds fonds object with some values set
 * @return the newly persisted fonds object wrapped as a fondsHateaos object
 */
@Override
public FondsHateoas createNewFonds(@NotNull Fonds fonds) {
    NoarkUtils.NoarkEntity.Create.checkDocumentMediumValid(fonds);
    NoarkUtils.NoarkEntity.Create.setNoarkEntityValues(fonds);
    fonds.setFondsStatus(STATUS_OPEN);
    NoarkUtils.NoarkEntity.Create.setFinaliseEntityValues(fonds);
    FondsHateoas fondsHateoas = new FondsHateoas(fondsRepository.save(fonds));
    fondsHateoasHandler.addLinks(fondsHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityCreatedEvent(this, fonds));
    return fondsHateoas;
}
Also used : AfterNoarkEntityCreatedEvent(nikita.webapp.web.events.AfterNoarkEntityCreatedEvent) FondsHateoas(nikita.common.model.noark5.v4.hateoas.FondsHateoas) Authorisation(nikita.webapp.security.Authorisation)

Example 33 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 {
    StringBuilder errors = new StringBuilder();
    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, errors);
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(fonds, objectNode, errors);
    CommonUtils.Hateoas.Deserialize.deserialiseStorageLocation(fonds, objectNode, errors);
    // Deserialize seriesStatus
    JsonNode currentNode = objectNode.get(N5ResourceMappings.FONDS_STATUS);
    if (currentNode != null) {
        fonds.setFondsStatus(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.FONDS_STATUS);
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        errors.append("The arkiv you tried to create is malformed. The " + "following fields are not recognised as arkiv fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]. ");
    }
    if (0 < errors.length())
        throw new NikitaMalformedInputDataException(errors.toString());
    return fonds;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Fonds(nikita.common.model.noark5.v4.Fonds) JsonNode(com.fasterxml.jackson.databind.JsonNode) NikitaMalformedInputDataException(nikita.common.util.exceptions.NikitaMalformedInputDataException)

Example 34 with Fonds

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

the class FondsHateoasSerializer method serializeNoarkEntity.

@Override
public void serializeNoarkEntity(INikitaEntity noarkSystemIdEntity, HateoasNoarkObject fondsHateoas, JsonGenerator jgen) throws IOException {
    Fonds fonds = (Fonds) noarkSystemIdEntity;
    jgen.writeStartObject();
    CommonUtils.Hateoas.Serialize.printSystemIdEntity(jgen, fonds);
    CommonUtils.Hateoas.Serialize.printTitleAndDescription(jgen, fonds);
    if (fonds.getFondsStatus() != null) {
        jgen.writeStringField(FONDS_STATUS, fonds.getFondsStatus());
    }
    CommonUtils.Hateoas.Serialize.printDocumentMedium(jgen, fonds);
    CommonUtils.Hateoas.Serialize.printStorageLocation(jgen, fonds);
    CommonUtils.Hateoas.Serialize.printCreateEntity(jgen, fonds);
    CommonUtils.Hateoas.Serialize.printFinaliseEntity(jgen, fonds);
    CommonUtils.Hateoas.Serialize.printHateoasLinks(jgen, fondsHateoas.getLinks(fonds));
    jgen.writeEndObject();
}
Also used : Fonds(nikita.common.model.noark5.v4.Fonds)

Example 35 with Fonds

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

the class FondsIT method test_2_createFonds.

@Test
public void test_2_createFonds() throws JsonProcessingException {
    assertTrue(checkLoggedIn());
    assertNotNull(headers);
    assertNotNull(headers.get("Authorization"));
    Fonds fonds = new Fonds();
    fonds.setDescription("description");
    fonds.setTitle("title");
    String serializedFonds = mapper.writeValueAsString(fonds);
    HttpEntity<String> request = new HttpEntity<>(serializedFonds, headers);
    ResponseEntity<HateoasNoarkObject> responseEntity = restTemplate.exchange("/hateoas-api/arkivstruktur/ny-arkiv", HttpMethod.POST, request, HateoasNoarkObject.class);
    assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
    HateoasNoarkObject result = responseEntity.getBody();
    ArrayList<INikitaEntity> entities = (ArrayList<INikitaEntity>) result.getList();
    assertNotNull(entities);
    assertEquals(entities.size(), 1);
    INoarkGeneralEntity returnedFonds = (INoarkGeneralEntity) entities.get(0);
    assertEquals("description", returnedFonds.getDescription());
    assertEquals("title", returnedFonds.getTitle());
}
Also used : INoarkGeneralEntity(nikita.common.model.noark5.v4.interfaces.entities.INoarkGeneralEntity) HateoasNoarkObject(nikita.common.model.noark5.v4.hateoas.HateoasNoarkObject) INikitaEntity(nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity) ArrayList(java.util.ArrayList) Fonds(nikita.common.model.noark5.v4.Fonds) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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