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