use of nikita.model.noark5.v4.Record in project nikita-noark5-core by HiOA-ABI.
the class FileService method createRecordAssociatedWithFile.
@Override
public Record createRecordAssociatedWithFile(String fileSystemId, Record record) {
Record persistedRecord;
File file = fileRepository.findBySystemId(fileSystemId);
if (file == null) {
String info = INFO_CANNOT_FIND_OBJECT + " File, using fileSystemId " + fileSystemId;
logger.info(info);
throw new NoarkEntityNotFoundException(info);
} else {
record.setReferenceFile(file);
persistedRecord = recordService.save(record);
}
return persistedRecord;
}
use of nikita.model.noark5.v4.Record in project nikita-noark5-core by HiOA-ABI.
the class RecordService method getRecordOrThrow.
// All HELPER operations
/**
* Internal helper method. Rather than having a find and try catch in multiple methods, we have it here once.
* If you call this, be aware that you will only ever get a valid Record back. If there is no valid
* Record, an exception is thrown
*
* @param systemID
* @return
*/
protected Record getRecordOrThrow(@NotNull String systemID) {
Record record = recordRepository.findBySystemId(systemID);
if (record == null) {
String info = INFO_CANNOT_FIND_OBJECT + " Record, using systemId " + systemID;
logger.info(info);
throw new NoarkEntityNotFoundException(info);
}
return record;
}
use of nikita.model.noark5.v4.Record in project nikita-noark5-core by HiOA-ABI.
the class RecordService method handleUpdate.
// All UPDATE operations
@Override
public Record handleUpdate(@NotNull String systemId, @NotNull Long version, @NotNull Record incomingRecord) {
Record existingRecord = getRecordOrThrow(systemId);
// Here copy all the values you are allowed to copy ....
// TODO: FIND ALL VALUES
// This might be a class that can only have values set via parameter values rather than request bodies
existingRecord.setVersion(version);
recordRepository.save(existingRecord);
return existingRecord;
}
use of nikita.model.noark5.v4.Record in project nikita-noark5-core by HiOA-ABI.
the class RecordService method createDocumentDescriptionAssociatedWithRecord.
@Override
public DocumentDescription createDocumentDescriptionAssociatedWithRecord(String systemID, DocumentDescription documentDescription) {
DocumentDescription persistedDocumentDescription = null;
Record record = recordRepository.findBySystemId(systemID);
if (record == null) {
String info = INFO_CANNOT_FIND_OBJECT + " Record, using systemID " + systemID;
logger.info(info);
throw new NoarkEntityNotFoundException(info);
} else {
ArrayList<Record> records = (ArrayList<Record>) documentDescription.getReferenceRecord();
if (records == null) {
records = new ArrayList<>();
documentDescription.setReferenceRecord(records);
}
records.add(record);
List<DocumentDescription> documentDescriptions = record.getReferenceDocumentDescription();
documentDescriptions.add(documentDescription);
persistedDocumentDescription = documentDescriptionService.save(documentDescription);
}
return persistedDocumentDescription;
}
use of nikita.model.noark5.v4.Record in project nikita-noark5-core by HiOA-ABI.
the class DocumentDescriptionHateoasController method findAllDocumentDescriptionAssociatedWithRecord.
// Retrieve all DocumentObjects associated with a DocumentDescription identified by systemId
// GET [contextPath][api]/arkivstruktur/dokumentbeskrivelse/{systemId}/dokumentobjekt
@ApiOperation(value = "Retrieves a list of DocumentObjects associated with a DocumentDescription", response = DocumentObjectHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "DocumentObject returned", response = DocumentObjectHateoas.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 + SLASH + DOCUMENT_OBJECT, method = RequestMethod.GET)
public ResponseEntity<DocumentObjectHateoas> 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) {
DocumentDescription documentDescription = documentDescriptionService.findBySystemId(systemID);
if (documentDescription == null) {
throw new NoarkEntityNotFoundException("Could not find DocumentDescription object with systemID " + systemID);
}
DocumentObjectHateoas documentObjectHateoas = new DocumentObjectHateoas((List<INikitaEntity>) (List) documentDescription.getReferenceDocumentObject());
documentObjectHateoasHandler.addLinks(documentObjectHateoas, new Authorisation());
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(documentObjectHateoas);
}
Aggregations