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;
}
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;
}
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;
}
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();
}
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());
}
Aggregations