use of nikita.common.model.noark5.v4.DocumentDescription in project nikita-noark5-core by HiOA-ABI.
the class RecordHateoasController method createDefaultDocumentDescription.
// Create a DocumentDescription with default values
// GET [contextPath][api]/arkivstruktur/resgistrering/{systemId}/ny-dokumentbeskrivelse
@ApiOperation(value = "Create a DocumentDescription with default values", response = DocumentDescriptionHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "DocumentDescription returned", response = DocumentDescriptionHateoas.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_DOCUMENT_DESCRIPTION, method = RequestMethod.GET)
public ResponseEntity<DocumentDescriptionHateoas> createDefaultDocumentDescription(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response) {
DocumentDescription defaultDocumentDescription = new DocumentDescription();
defaultDocumentDescription.setAssociatedWithRecordAs(MAIN_DOCUMENT);
defaultDocumentDescription.setTitle(TEST_TITLE);
defaultDocumentDescription.setDocumentType(LETTER);
defaultDocumentDescription.setDocumentStatus(DOCUMENT_STATUS_FINALISED);
defaultDocumentDescription.setDescription(TEST_DESCRIPTION);
DocumentDescriptionHateoas documentDescriptionHateoas = new DocumentDescriptionHateoas(defaultDocumentDescription);
documentDescriptionHateoasHandler.addLinksOnNew(documentDescriptionHateoas, request, new Authorisation());
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(documentDescriptionHateoas);
}
use of nikita.common.model.noark5.v4.DocumentDescription in project nikita-noark5-core by HiOA-ABI.
the class RecordHateoasController method findAllDocumentDescriptionAssociatedWithRecord.
// Retrieve all DocumentDescriptions associated with a Record identified by systemId
// GET [contextPath][api]/arkivstruktur/resgistrering/{systemId}/dokumentbeskrivelse
@ApiOperation(value = "Retrieves a lit of DocumentDescriptions associated with a Record", response = DocumentDescriptionHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "DocumentDescription returned", response = DocumentDescriptionHateoas.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + DOCUMENT_DESCRIPTION, method = RequestMethod.GET)
public ResponseEntity<DocumentDescriptionHateoas> findAllDocumentDescriptionAssociatedWithRecord(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the file to retrieve associated Record", required = true) @PathVariable("systemID") final String systemID) {
Record record = recordService.findBySystemIdOrderBySystemId(systemID);
if (record == null) {
throw new NoarkEntityNotFoundException("Could not find File object with systemID " + systemID);
}
DocumentDescriptionHateoas documentDescriptionHateoas = new DocumentDescriptionHateoas(new ArrayList<>(record.getReferenceDocumentDescription()));
documentDescriptionHateoasHandler.addLinks(documentDescriptionHateoas, request, new Authorisation());
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(documentDescriptionHateoas);
}
use of nikita.common.model.noark5.v4.DocumentDescription in project nikita-noark5-core by HiOA-ABI.
the class DocumentDescriptionDeserializer method deserialize.
@Override
public DocumentDescription deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
DocumentDescription documentDescription = new DocumentDescription();
ObjectNode objectNode = mapper.readTree(jsonParser);
// Deserialise general record properties
CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(documentDescription, objectNode);
CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(documentDescription, objectNode);
CommonUtils.Hateoas.Deserialize.deserialiseNoarkTitleDescriptionEntity(documentDescription, objectNode);
// Deserialize documentType
JsonNode currentNode = objectNode.get(DOCUMENT_DESCRIPTION_DOCUMENT_TYPE);
if (null != currentNode) {
documentDescription.setDocumentType(currentNode.textValue());
objectNode.remove(DOCUMENT_DESCRIPTION_DOCUMENT_TYPE);
}
// Deserialize documentStatus
currentNode = objectNode.get(DOCUMENT_DESCRIPTION_STATUS);
if (null != currentNode) {
documentDescription.setDocumentStatus(currentNode.textValue());
objectNode.remove(DOCUMENT_DESCRIPTION_STATUS);
}
// Deserialize associatedWithRecordAs
currentNode = objectNode.get(DOCUMENT_DESCRIPTION_ASSOCIATED_WITH_RECORD_AS);
if (null != currentNode) {
documentDescription.setAssociatedWithRecordAs(currentNode.textValue());
objectNode.remove(DOCUMENT_DESCRIPTION_ASSOCIATED_WITH_RECORD_AS);
}
// Deserialize documentNumber
currentNode = objectNode.get(DOCUMENT_DESCRIPTION_DOCUMENT_NUMBER);
if (null != currentNode) {
documentDescription.setDocumentNumber(Integer.valueOf(currentNode.intValue()));
objectNode.remove(DOCUMENT_DESCRIPTION_DOCUMENT_NUMBER);
}
// Deserialize associationDate
currentNode = objectNode.get(DOCUMENT_DESCRIPTION_ASSOCIATION_DATE);
if (null != currentNode) {
try {
Date parsedDate = Deserialize.parseDateTimeFormat(currentNode.textValue());
documentDescription.setAssociationDate(parsedDate);
} catch (ParseException e) {
throw new NikitaMalformedInputDataException("The dokumentbeskrivelse you tried to create " + "has a malformed tilknyttetDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
}
objectNode.remove(DOCUMENT_DESCRIPTION_ASSOCIATION_DATE);
}
// Deserialize associatedBy
currentNode = objectNode.get(DOCUMENT_DESCRIPTION_ASSOCIATED_BY);
if (null != currentNode) {
documentDescription.setAssociatedBy(currentNode.textValue());
objectNode.remove(DOCUMENT_DESCRIPTION_ASSOCIATED_BY);
}
// Deserialize storageLocation
currentNode = objectNode.get(STORAGE_LOCATION);
if (null != currentNode) {
documentDescription.setStorageLocation(currentNode.textValue());
objectNode.remove(STORAGE_LOCATION);
}
// Deserialize general documentDescription properties
CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(documentDescription, objectNode);
// If there are additional throw a malformed input exception
if (objectNode.size() != 0) {
throw new NikitaMalformedInputDataException("The dokumentbeskrivelse you tried to create is malformed. The " + "following fields are not recognised as dokumentbeskrivelse fields[" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
}
return documentDescription;
}
use of nikita.common.model.noark5.v4.DocumentDescription in project nikita-noark5-core by HiOA-ABI.
the class DocumentDescriptionHateoasSerializer method serializeNoarkEntity.
@Override
public void serializeNoarkEntity(INikitaEntity noarkEntity, HateoasNoarkObject documentDescriptionHateoas, JsonGenerator jgen) throws IOException {
DocumentDescription documentDescription = (DocumentDescription) noarkEntity;
jgen.writeStartObject();
// handle DocumentDescription properties
CommonUtils.Hateoas.Serialize.printSystemIdEntity(jgen, documentDescription);
if (documentDescription.getDocumentType() != null) {
jgen.writeStringField(DOCUMENT_DESCRIPTION_DOCUMENT_TYPE, documentDescription.getDocumentType());
}
if (documentDescription.getDocumentStatus() != null) {
jgen.writeStringField(DOCUMENT_DESCRIPTION_STATUS, documentDescription.getDocumentStatus());
}
CommonUtils.Hateoas.Serialize.printTitleAndDescription(jgen, documentDescription);
if (documentDescription.getDocumentNumber() != null) {
jgen.writeNumberField(DOCUMENT_DESCRIPTION_DOCUMENT_NUMBER, documentDescription.getDocumentNumber().intValue());
}
CommonUtils.Hateoas.Serialize.printCreateEntity(jgen, documentDescription);
if (documentDescription.getAssociationDate() != null) {
jgen.writeStringField(DOCUMENT_DESCRIPTION_ASSOCIATION_DATE, Serialize.formatDate(documentDescription.getAssociationDate()));
}
if (documentDescription.getAssociatedWithRecordAs() != null) {
jgen.writeStringField(DOCUMENT_DESCRIPTION_ASSOCIATED_WITH_RECORD_AS, documentDescription.getAssociatedWithRecordAs());
}
CommonUtils.Hateoas.Serialize.printComment(jgen, documentDescription);
CommonUtils.Hateoas.Serialize.printDisposal(jgen, documentDescription);
CommonUtils.Hateoas.Serialize.printDisposalUndertaken(jgen, documentDescription);
CommonUtils.Hateoas.Serialize.printDeletion(jgen, documentDescription);
CommonUtils.Hateoas.Serialize.printScreening(jgen, documentDescription);
CommonUtils.Hateoas.Serialize.printClassified(jgen, documentDescription);
if (documentDescription.getStorageLocation() != null) {
jgen.writeStringField(STORAGE_LOCATION, documentDescription.getStorageLocation());
}
CommonUtils.Hateoas.Serialize.printElectronicSignature(jgen, documentDescription);
CommonUtils.Hateoas.Serialize.printHateoasLinks(jgen, documentDescriptionHateoas.getLinks(documentDescription));
jgen.writeEndObject();
}
use of nikita.common.model.noark5.v4.DocumentDescription in project nikita-noark5-core by HiOA-ABI.
the class DocumentDescriptionService method handleUpdate.
// All UPDATE operations
@Override
public DocumentDescription handleUpdate(@NotNull String systemId, @NotNull Long version, @NotNull DocumentDescription incomingDocumentDescription) {
DocumentDescription existingDocumentDescription = getDocumentDescriptionOrThrow(systemId);
// Copy all the values you are allowed to copy ....
if (null != incomingDocumentDescription.getDescription()) {
existingDocumentDescription.setDescription(incomingDocumentDescription.getDescription());
}
if (null != incomingDocumentDescription.getTitle()) {
existingDocumentDescription.setTitle(incomingDocumentDescription.getTitle());
}
if (null != incomingDocumentDescription.getDocumentMedium()) {
existingDocumentDescription.setDocumentMedium(existingDocumentDescription.getDocumentMedium());
}
if (null != incomingDocumentDescription.getAssociatedWithRecordAs()) {
existingDocumentDescription.setAssociatedWithRecordAs(incomingDocumentDescription.getAssociatedWithRecordAs());
}
if (null != incomingDocumentDescription.getDocumentNumber()) {
existingDocumentDescription.setDocumentNumber(incomingDocumentDescription.getDocumentNumber());
}
existingDocumentDescription.setVersion(version);
documentDescriptionRepository.save(existingDocumentDescription);
return existingDocumentDescription;
}
Aggregations