use of nikita.common.model.noark5.v4.Class in project nikita-noark5-core by HiOA-ABI.
the class SeriesDeserializer method deserialize.
@Override
public Series deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
StringBuilder errors = new StringBuilder();
Series series = new Series();
ObjectNode objectNode = mapper.readTree(jsonParser);
// Deserialise general properties
CommonUtils.Hateoas.Deserialize.deserialiseNoarkEntity(series, objectNode, errors);
CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(series, objectNode, errors);
CommonUtils.Hateoas.Deserialize.deserialiseStorageLocation(series, objectNode, errors);
// Deserialize seriesStatus
JsonNode currentNode = objectNode.get(N5ResourceMappings.SERIES_STATUS);
if (null != currentNode) {
series.setSeriesStatus(currentNode.textValue());
objectNode.remove(N5ResourceMappings.SERIES_STATUS);
}
// Deserialize seriesStartDate
series.setSeriesStartDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.SERIES_START_DATE, objectNode, errors));
// Deserialize seriesEndDate
series.setSeriesEndDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.SERIES_END_DATE, objectNode, errors));
// Deserialize referencePrecursor
currentNode = objectNode.get(N5ResourceMappings.SERIES_PRECURSOR);
if (null != currentNode) {
Series seriesPrecursor = new Series();
seriesPrecursor.setSystemId(currentNode.textValue());
series.setReferencePrecursor(seriesPrecursor);
// TODO: Does this imply that the current arkivdel is the successor?
// I would not set it here, as the service class has to check that
// the seriesPrecursor object actually exists
objectNode.remove(N5ResourceMappings.SERIES_PRECURSOR);
}
// Deserialize referenceSuccessor
currentNode = objectNode.get(N5ResourceMappings.SERIES_SUCCESSOR);
if (null != currentNode) {
Series seriesSuccessor = new Series();
seriesSuccessor.setSystemId(currentNode.textValue());
series.setReferenceSuccessor(seriesSuccessor);
// TODO: Does this imply that the current arkivdel is the precursor?
// I would not set it here, as the service class should do this
objectNode.remove(N5ResourceMappings.SERIES_SUCCESSOR);
}
series.setReferenceDisposal(CommonUtils.Hateoas.Deserialize.deserialiseDisposal(objectNode, errors));
series.setReferenceDisposalUndertaken(CommonUtils.Hateoas.Deserialize.deserialiseDisposalUndertaken(objectNode, errors));
series.setReferenceDeletion(CommonUtils.Hateoas.Deserialize.deserialiseDeletion(objectNode, errors));
series.setReferenceScreening(CommonUtils.Hateoas.Deserialize.deserialiseScreening(objectNode, errors));
series.setReferenceClassified(CommonUtils.Hateoas.Deserialize.deserialiseClassified(objectNode, errors));
// If there are additional throw a malformed input exception
if (objectNode.size() != 0) {
errors.append("The arkivdel you tried to create is malformed. The " + "following fields are not recognised as arkivdel fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]. ");
}
if (0 < errors.length())
throw new NikitaMalformedInputDataException(errors.toString());
return series;
}
use of nikita.common.model.noark5.v4.Class in project nikita-noark5-core by HiOA-ABI.
the class ClassHateoasSerializer method serializeNoarkEntity.
@Override
public void serializeNoarkEntity(INikitaEntity noarkSystemIdEntity, HateoasNoarkObject classHateoas, JsonGenerator jgen) throws IOException {
Class klass = (Class) noarkSystemIdEntity;
jgen.writeStartObject();
CommonUtils.Hateoas.Serialize.printSystemIdEntity(jgen, klass);
CommonUtils.Hateoas.Serialize.printTitleAndDescription(jgen, klass);
CommonUtils.Hateoas.Serialize.printCreateEntity(jgen, klass);
CommonUtils.Hateoas.Serialize.printFinaliseEntity(jgen, klass);
// TODO: Fix this ! CommonCommonUtils.Hateoas.Serialize.printCrossReference(jgen, klass);
CommonUtils.Hateoas.Serialize.printDisposal(jgen, klass);
CommonUtils.Hateoas.Serialize.printScreening(jgen, klass);
CommonUtils.Hateoas.Serialize.printClassified(jgen, klass);
CommonUtils.Hateoas.Serialize.printHateoasLinks(jgen, classHateoas.getLinks(klass));
jgen.writeEndObject();
}
use of nikita.common.model.noark5.v4.Class in project nikita-noark5-core by HiOA-ABI.
the class FileHateoasController method deleteFileBySystemId.
// Delete a File identified by systemID
// DELETE [contextPath][api]/arkivstruktur/mappe/{systemId}/
@ApiOperation(value = "Deletes a single File entity identified by systemID", response = HateoasNoarkObject.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Parent entity (DocumentDescription or File) returned", response = HateoasNoarkObject.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
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.DELETE)
public ResponseEntity<HateoasNoarkObject> deleteFileBySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the file to delete", required = true) @PathVariable("systemID") final String systemID) {
File file = fileService.findBySystemId(systemID);
NoarkEntity parentEntity = file.chooseParent();
HateoasNoarkObject hateoasNoarkObject;
if (parentEntity instanceof Series) {
hateoasNoarkObject = new SeriesHateoas(parentEntity);
seriesHateoasHandler.addLinks(hateoasNoarkObject, new Authorisation());
} else if (parentEntity instanceof File) {
hateoasNoarkObject = new FileHateoas(parentEntity);
fileHateoasHandler.addLinks(hateoasNoarkObject, new Authorisation());
} else if (parentEntity instanceof Class) {
hateoasNoarkObject = new ClassHateoas(parentEntity);
classHateoasHandler.addLinks(hateoasNoarkObject, new Authorisation());
} else {
throw new NikitaException("Internal error. Could not process" + request.getRequestURI());
}
fileService.deleteEntity(systemID);
applicationEventPublisher.publishEvent(new AfterNoarkEntityDeletedEvent(this, file));
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(hateoasNoarkObject);
}
use of nikita.common.model.noark5.v4.Class in project nikita-noark5-core by HiOA-ABI.
the class CaseFileHateoasController method deleteCaseFileBySystemId.
// Delete a CaseFile identified by systemID
// DELETE [contextPath][api]/casehandling/saksmappe/{systemId}/
@ApiOperation(value = "Deletes a single CaseFile entity identified by systemID", response = HateoasNoarkObject.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Parent entity (DocumentDescription or CaseFile) returned", response = HateoasNoarkObject.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
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.DELETE)
public ResponseEntity<HateoasNoarkObject> deleteCaseFileBySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the caseFile to delete", required = true) @PathVariable("systemID") final String systemID) {
CaseFile caseFile = caseFileService.findBySystemId(systemID);
NoarkEntity parentEntity = caseFile.chooseParent();
HateoasNoarkObject hateoasNoarkObject;
if (parentEntity instanceof Series) {
hateoasNoarkObject = new SeriesHateoas(parentEntity);
seriesHateoasHandler.addLinks(hateoasNoarkObject, new Authorisation());
} else // TODO: Can a casefile have a Class as parent???
if (parentEntity instanceof Class) {
hateoasNoarkObject = new ClassHateoas(parentEntity);
classHateoasHandler.addLinks(hateoasNoarkObject, new Authorisation());
} else {
throw new NikitaException("Internal error. Could not process " + request.getRequestURI());
}
caseFileService.deleteEntity(systemID);
applicationEventPublisher.publishEvent(new AfterNoarkEntityDeletedEvent(this, caseFile));
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(hateoasNoarkObject);
}
use of nikita.common.model.noark5.v4.Class in project nikita-noark5-core by HiOA-ABI.
the class SeriesDeserializer method deserialize.
@Override
public Series deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
Series series = new Series();
ObjectNode objectNode = mapper.readTree(jsonParser);
// Deserialise general properties
CommonUtils.Hateoas.Deserialize.deserialiseNoarkEntity(series, objectNode);
CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(series, objectNode);
CommonUtils.Hateoas.Deserialize.deserialiseStorageLocation(series, objectNode);
// Deserialize seriesStatus
JsonNode currentNode = objectNode.get(SERIES_STATUS);
if (null != currentNode) {
series.setSeriesStatus(currentNode.textValue());
objectNode.remove(SERIES_STATUS);
}
// Deserialize seriesStartDate
currentNode = objectNode.get(SERIES_START_DATE);
if (null != currentNode) {
try {
Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
series.setSeriesStartDate(parsedDate);
objectNode.remove(SERIES_START_DATE);
} catch (ParseException e) {
throw new NikitaMalformedInputDataException("The arkivdel you tried to create " + "has a malformed arkivperiodeStartDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
}
}
// Deserialize seriesEndDate
currentNode = objectNode.get(SERIES_END_DATE);
if (null != currentNode) {
try {
Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
series.setSeriesEndDate(parsedDate);
objectNode.remove(SERIES_END_DATE);
} catch (ParseException e) {
throw new NikitaMalformedInputDataException("The arkivdel you tried to create " + "has a malformed arkivperiodeSluttDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
}
}
// Deserialize referencePrecursor
currentNode = objectNode.get(SERIES_PRECURSOR);
if (null != currentNode) {
Series seriesPrecursor = new Series();
seriesPrecursor.setSystemId(currentNode.textValue());
series.setReferencePrecursor(seriesPrecursor);
// TODO: Does this imply that the current arkivdel is the successor?
// I would not set it here, as the service class has to check that
// the seriesPrecursor object actually exists
objectNode.remove(SERIES_PRECURSOR);
}
// Deserialize referenceSuccessor
currentNode = objectNode.get(SERIES_SUCCESSOR);
if (null != currentNode) {
Series seriesSuccessor = new Series();
seriesSuccessor.setSystemId(currentNode.textValue());
series.setReferenceSuccessor(seriesSuccessor);
// TODO: Does this imply that the current arkivdel is the precursor?
// I would not set it here, as the service class should do this
objectNode.remove(SERIES_SUCCESSOR);
}
series.setReferenceDisposal(CommonUtils.Hateoas.Deserialize.deserialiseDisposal(objectNode));
series.setReferenceDisposalUndertaken(CommonUtils.Hateoas.Deserialize.deserialiseDisposalUndertaken(objectNode));
series.setReferenceDeletion(CommonUtils.Hateoas.Deserialize.deserialiseDeletion(objectNode));
series.setReferenceScreening(CommonUtils.Hateoas.Deserialize.deserialiseScreening(objectNode));
series.setReferenceClassified(CommonUtils.Hateoas.Deserialize.deserialiseClassified(objectNode));
// If there are additional throw a malformed input exception
if (objectNode.size() != 0) {
throw new NikitaMalformedInputDataException("The arkivdel you tried to create is malformed. The " + "following fields are not recognised as arkivdel fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
}
return series;
}
Aggregations