use of nikita.common.model.noark5.v4.File in project nikita-noark5-core by HiOA-ABI.
the class SeriesHateoasController method findAllFileAssociatedWithSeries.
// Retrieve all Files associated with a Series (paginated)
// GET [contextPath][api]/arkivstruktur/arkivdel/{systemId}/mappe/
// GET [contextPath][api]/arkivstruktur/arkivdel/{systemId}/mappe/?top=5&skip=1
@ApiOperation(value = "Retrieves a list of Files associated with a Series", notes = "The field skip" + "tells how many File rows of the result set to ignore (starting at 0), while top tells how many rows" + " after skip to return. Note if the value of top is greater than system value " + " nikita-noark5-core.pagination.maxPageSize, then nikita-noark5-core.pagination.maxPageSize is used. ", response = FileHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "File list found", response = FileHateoas.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 + FILE, method = RequestMethod.GET)
public ResponseEntity<FileHateoas> findAllFileAssociatedWithSeries(HttpServletRequest request, @RequestParam(name = "top", required = false) Integer top, @RequestParam(name = "skip", required = false) Integer skip, @ApiParam(name = "systemID", value = "systemID of the series to retrieve", required = true) @PathVariable("systemID") final String systemID) {
Series series = seriesService.findBySystemIdOrderBySystemId(systemID);
if (series == null) {
throw new NoarkEntityNotFoundException("Could not find series object with systemID " + systemID);
}
FileHateoas fileHateoas = new FileHateoas(new ArrayList<>(series.getReferenceFile()));
fileHateoasHandler.addLinks(fileHateoas, request, new Authorisation());
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(fileHateoas);
}
use of nikita.common.model.noark5.v4.File in project nikita-noark5-core by HiOA-ABI.
the class SeriesHateoasController method createFileAssociatedWithSeries.
// API - All POST Requests (CRUD - CREATE)
// Create a new file
// POST [contextPath][api]/arkivstruktur/arkivdel/ny-mappe/
@ApiOperation(value = "Persists a File object associated with the given Series systemId", notes = "Returns the " + "newly created file object after it was associated with a Series object and persisted to the database", response = FileHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "File " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = FileHateoas.class), @ApiResponse(code = 201, message = "File " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = FileHateoas.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 File"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(method = RequestMethod.POST, value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_FILE, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<FileHateoas> createFileAssociatedWithSeries(HttpServletRequest request, @ApiParam(name = "systemID", value = "systemId of series to associate the caseFile with", required = true) @PathVariable String systemID, @ApiParam(name = "File", value = "Incoming file object", required = true) @RequestBody File file) throws NikitaException {
validateForCreate(file);
File createdFile = seriesService.createFileAssociatedWithSeries(systemID, file);
FileHateoas fileHateoas = new FileHateoas(createdFile);
fileHateoasHandler.addLinks(fileHateoas, request, new Authorisation());
applicationEventPublisher.publishEvent(new AfterNoarkEntityCreatedEvent(this, createdFile));
return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(createdFile.getVersion().toString()).body(fileHateoas);
}
use of nikita.common.model.noark5.v4.File in project nikita-noark5-core by HiOA-ABI.
the class CaseFileHateoasController method createRegistryEntryAssociatedWithFile.
// API - All POST Requests (CRUD - CREATE)
// Create a RegistryEntry entity
// POST [contextPath][api]/casehandling/{systemId}/ny-journalpost
@ApiOperation(value = "Persists a RegistryEntry object associated with the given Series systemId", notes = "Returns the newly created record object after it was associated with a File object and " + "persisted to the database", response = RegistryEntryHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "RegistryEntry " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = RegistryEntryHateoas.class), @ApiResponse(code = 201, message = "RegistryEntry " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = RegistryEntryHateoas.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 RegistryEntry"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(method = RequestMethod.POST, value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_REGISTRY_ENTRY, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<RegistryEntryHateoas> createRegistryEntryAssociatedWithFile(HttpServletRequest request, @ApiParam(name = "systemID", value = "systemId of file to associate the record with", required = true) @PathVariable("systemID") final String systemID, @ApiParam(name = "RegistryEntry", value = "Incoming registryEntry object", required = true) @RequestBody RegistryEntry registryEntry) throws NikitaException {
RegistryEntry createdRegistryEntry = caseFileService.createRegistryEntryAssociatedWithCaseFile(systemID, registryEntry);
RegistryEntryHateoas registryEntryHateoas = new RegistryEntryHateoas(createdRegistryEntry);
registryEntryHateoasHandler.addLinks(registryEntryHateoas, request, new Authorisation());
applicationEventPublisher.publishEvent(new AfterNoarkEntityCreatedEvent(this, createdRegistryEntry));
return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(createdRegistryEntry.getVersion().toString()).body(registryEntryHateoas);
}
use of nikita.common.model.noark5.v4.File in project nikita-noark5-core by HiOA-ABI.
the class CaseFileDeserializer method deserialize.
@Override
public CaseFile deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
CaseFile caseFile = new CaseFile();
ObjectNode objectNode = mapper.readTree(jsonParser);
// Deserialise properties for File
CommonUtils.Hateoas.Deserialize.deserialiseNoarkEntity(caseFile, objectNode);
CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(caseFile, objectNode);
CommonUtils.Hateoas.Deserialize.deserialiseStorageLocation(caseFile, objectNode);
CommonUtils.Hateoas.Deserialize.deserialiseKeyword(caseFile, objectNode);
// Deserialize fileId
JsonNode currentNode = objectNode.get(FILE_ID);
if (null != currentNode) {
caseFile.setFileId(currentNode.textValue());
objectNode.remove(FILE_ID);
}
// Deserialize officialTitle
currentNode = objectNode.get(FILE_PUBLIC_TITLE);
if (null != currentNode) {
caseFile.setOfficialTitle(currentNode.textValue());
objectNode.remove(FILE_PUBLIC_TITLE);
}
caseFile.setReferenceCrossReference(CommonUtils.Hateoas.Deserialize.deserialiseCrossReferences(objectNode));
CommonUtils.Hateoas.Deserialize.deserialiseComments(caseFile, objectNode);
caseFile.setReferenceDisposal(CommonUtils.Hateoas.Deserialize.deserialiseDisposal(objectNode));
caseFile.setReferenceScreening(CommonUtils.Hateoas.Deserialize.deserialiseScreening(objectNode));
caseFile.setReferenceClassified(CommonUtils.Hateoas.Deserialize.deserialiseClassified(objectNode));
// Deserialise general properties for CaseFile
// Deserialize caseYear
currentNode = objectNode.get(CASE_YEAR);
if (null != currentNode) {
caseFile.setCaseYear(Integer.valueOf(currentNode.intValue()));
objectNode.remove(CASE_YEAR);
}
// Deserialize caseSequenceNumber
currentNode = objectNode.get(CASE_SEQUENCE_NUMBER);
if (null != currentNode) {
caseFile.setCaseSequenceNumber(Integer.valueOf(currentNode.intValue()));
objectNode.remove(CASE_SEQUENCE_NUMBER);
}
// Deserialize caseDate
currentNode = objectNode.get(CASE_DATE);
if (null != currentNode) {
try {
Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
caseFile.setCaseDate(parsedDate);
objectNode.remove(CASE_DATE);
} catch (ParseException e) {
throw new NikitaMalformedInputDataException("The saksmappe you tried to create " + "has a malformed saksDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
}
}
// Deserialize administrativeUnit
currentNode = objectNode.get(ADMINISTRATIVE_UNIT);
if (null != currentNode) {
caseFile.setAdministrativeUnit(currentNode.textValue());
objectNode.remove(ADMINISTRATIVE_UNIT);
}
// Deserialize caseResponsible
currentNode = objectNode.get(CASE_RESPONSIBLE);
if (null != currentNode) {
caseFile.setCaseResponsible(currentNode.textValue());
objectNode.remove(CASE_RESPONSIBLE);
}
// Deserialize recordsManagementUnit
currentNode = objectNode.get(CASE_RECORDS_MANAGEMENT_UNIT);
if (null != currentNode) {
caseFile.setRecordsManagementUnit(currentNode.textValue());
objectNode.remove(CASE_RECORDS_MANAGEMENT_UNIT);
}
// Deserialize caseStatus
currentNode = objectNode.get(CASE_STATUS);
if (null != currentNode) {
caseFile.setCaseStatus(currentNode.textValue());
objectNode.remove(CASE_STATUS);
}
// Deserialize loanedDate
currentNode = objectNode.get(CASE_LOANED_DATE);
if (null != currentNode) {
try {
Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
caseFile.setLoanedDate(parsedDate);
objectNode.remove(CASE_LOANED_DATE);
} catch (ParseException e) {
throw new NikitaMalformedInputDataException("The saksmappe you tried to create " + "has a malformed utlaantDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
}
}
// Deserialize loanedTo
currentNode = objectNode.get(CASE_LOANED_TO);
if (null != currentNode) {
caseFile.setLoanedTo(currentNode.textValue());
objectNode.remove(CASE_LOANED_TO);
}
// Deserialize referenceSeries
currentNode = objectNode.get(REFERENCE_SERIES);
if (null != currentNode) {
Series series = new Series();
String systemID = currentNode.textValue();
if (systemID != null) {
series.setSystemId(systemID);
}
caseFile.setReferenceSeries(series);
objectNode.remove(REFERENCE_SERIES);
}
// If there are additional throw a malformed input exception
if (objectNode.size() != 0) {
throw new NikitaMalformedInputDataException("The saksmappe object you tried to create is malformed. The " + "following fields are not recognised as saksmappe fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
}
caseFile.setReferenceCaseParty(CommonUtils.Hateoas.Deserialize.deserialiseCaseParties(objectNode));
caseFile.setReferencePrecedence(CommonUtils.Hateoas.Deserialize.deserialisePrecedences(objectNode));
return caseFile;
}
use of nikita.common.model.noark5.v4.File in project nikita-noark5-core by HiOA-ABI.
the class FileHateoasSerializer method serializeNoarkEntity.
@Override
public void serializeNoarkEntity(INikitaEntity noarkSystemIdEntity, HateoasNoarkObject fileHateoas, JsonGenerator jgen) throws IOException {
File file = (File) noarkSystemIdEntity;
jgen.writeStartObject();
CommonUtils.Hateoas.Serialize.printSystemIdEntity(jgen, file);
CommonUtils.Hateoas.Serialize.printStorageLocation(jgen, file);
if (file.getFileId() != null) {
jgen.writeStringField(FILE_ID, file.getFileId());
if (file.getTitle() != null) {
jgen.writeStringField(TITLE, file.getTitle());
}
if (file.getOfficialTitle() != null) {
jgen.writeStringField(FILE_PUBLIC_TITLE, file.getOfficialTitle());
}
if (file.getDescription() != null) {
jgen.writeStringField(DESCRIPTION, file.getDescription());
}
}
CommonUtils.Hateoas.Serialize.printDocumentMedium(jgen, file);
CommonUtils.Hateoas.Serialize.printKeyword(jgen, file);
CommonUtils.Hateoas.Serialize.printCreateEntity(jgen, file);
CommonUtils.Hateoas.Serialize.printFinaliseEntity(jgen, file);
if (file.getReferenceSeries() != null && file.getReferenceSeries().getSystemId() != null) {
jgen.writeStringField(REFERENCE_SERIES, file.getReferenceSeries().getSystemId());
}
//TODO: CommonCommonUtils.Hateoas.Serialize.printCrossReference(jgen, file.getReferenceCrossReference());
CommonUtils.Hateoas.Serialize.printComment(jgen, file);
CommonUtils.Hateoas.Serialize.printDisposal(jgen, file);
CommonUtils.Hateoas.Serialize.printScreening(jgen, file);
CommonUtils.Hateoas.Serialize.printClassified(jgen, file);
CommonUtils.Hateoas.Serialize.printHateoasLinks(jgen, fileHateoas.getLinks(file));
jgen.writeEndObject();
}
Aggregations