use of nikita.model.noark5.v4.metadata.DocumentMedium in project nikita-noark5-core by HiOA-ABI.
the class DocumentMediumController method updateDocumentMedium.
// API - All PUT Requests (CRUD - UPDATE)
// Update a documentmedium
// PUT [contextPath][api]/metatdata/dokumentmedium/
@ApiOperation(value = "Updates a DocumentMedium object", notes = "Returns the newly" + " updated DocumentMedium object after it is persisted to the database", response = DocumentMedium.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "DocumentMedium " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = DocumentMedium.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 404, message = API_MESSAGE_MALFORMED_PAYLOAD), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(method = RequestMethod.PUT, value = DOCUMENT_MEDIUM + SLASH + DOCUMENT_MEDIUM)
public ResponseEntity<MetadataHateoas> updateDocumentMedium(@RequestBody DocumentMedium documentMedium, HttpServletRequest request) throws NikitaException {
DocumentMedium newDocumentMedium = documentMediumService.update(documentMedium);
MetadataHateoas metadataHateoas = new MetadataHateoas(documentMedium);
metadataHateoasHandler.addLinks(metadataHateoas, request, new Authorisation());
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(metadataHateoas);
}
use of nikita.model.noark5.v4.metadata.DocumentMedium in project nikita-noark5-core by HiOA-ABI.
the class DocumentMediumController method createDocumentMedium.
// API - All POST Requests (CRUD - CREATE)
// Creates a new documentmedium
// POST [contextPath][api]/metadata/dokumentmedium/ny-dokumentmedium
@ApiOperation(value = "Persists a new DocumentMedium object", notes = "Returns the newly" + " created DocumentMedium object after it is persisted to the database", response = DocumentMedium.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "DocumentMedium " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = DocumentMedium.class), @ApiResponse(code = 201, message = "DocumentMedium " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = DocumentMedium.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 404, message = API_MESSAGE_MALFORMED_PAYLOAD), @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 = DOCUMENT_MEDIUM + SLASH + NEW_DOCUMENT_MEDIUM)
public ResponseEntity<MetadataHateoas> createDocumentMedium(HttpServletRequest request, @RequestBody DocumentMedium documentMedium) throws NikitaException {
DocumentMedium newDocumentMedium = documentMediumService.createNewDocumentMedium(documentMedium);
MetadataHateoas metadataHateoas = new MetadataHateoas(newDocumentMedium);
metadataHateoasHandler.addLinks(metadataHateoas, request, new Authorisation());
return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(newDocumentMedium.getVersion().toString()).body(metadataHateoas);
}
use of nikita.model.noark5.v4.metadata.DocumentMedium in project nikita-noark5-core by HiOA-ABI.
the class DocumentMediumController method findBySystemIdOrderBySystemId.
// Retrieves a given documentMedium identified by a systemId
// GET [contextPath][api]/metadata/dokumentmedium/{systemId}/
@ApiOperation(value = "Gets documentMedium identified by its systemId", notes = "Returns the requested " + " documentMedium object", response = DocumentMedium.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "DocumentMedium " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = DocumentMedium.class), @ApiResponse(code = 201, message = "DocumentMedium " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = DocumentMedium.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 404, message = API_MESSAGE_MALFORMED_PAYLOAD), @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(value = DOCUMENT_MEDIUM + SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH, method = RequestMethod.GET)
public ResponseEntity<MetadataHateoas> findBySystemIdOrderBySystemId(@PathVariable("systemID") final String systemId, HttpServletRequest request) {
DocumentMedium documentMedium = documentMediumService.findBySystemIdOrderBySystemId(systemId);
MetadataHateoas metadataHateoas = new MetadataHateoas(documentMedium);
metadataHateoasHandler.addLinks(metadataHateoas, request, new Authorisation());
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(documentMedium.getVersion().toString()).body(metadataHateoas);
}
use of nikita.model.noark5.v4.metadata.DocumentMedium in project nikita-noark5-core by HiOA-ABI.
the class NoarkImportService method checkAndSetDefaultValues.
/**
*
* Check a Noark entity (fonds, series, file, etc) for valid properties and set any values that have not been set
* that should be set with default values.
*
* @param entity
* @throws Exception
*/
public void checkAndSetDefaultValues(INoarkGeneralEntity entity) throws Exception {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
// Not all Noark objects, i.e DocumentDescription and DocumentObject have a documentMedium property
if (entity instanceof IDocumentMedium) {
if (!NoarkUtils.NoarkEntity.Create.checkDocumentMediumValid(((IDocumentMedium) entity))) {
logger.error("Document medium not a valid document medium. Assigned value is " + ((IDocumentMedium) entity).getDocumentMedium());
// An exception will be thrown by checkDocumentMediumValid if not valid
//TODO: Look at the logic here, as a change checkDocumentMediumValid kinda makes
// the if redundant
}
}
// uniqueness via systemId
if (entity.getSystemId() == null) {
entity.setSystemId(UUID.randomUUID().toString());
} else if (entity.getSystemId().length() != Constants.UUIDLength) {
String randomUUID = UUID.randomUUID().toString();
logger.info("Noark object of type [ " + entity.getClass().getName() + "] does not have a valid UUID. Original value [" + entity.getSystemId() + entity.toString() + "] is being changed and assigned with [" + randomUUID + "]");
entity.setSystemId(randomUUID);
}
if (entity.getCreatedDate() == null) {
logger.info("Noark object of type [ " + entity.getClass().getName() + "] does not have a createdDate value. createdDate is being set to [" + new Date().toString() + "]");
entity.setCreatedDate(new Date());
}
if (entity.getCreatedBy() == null) {
logger.info("Noark object of type [ " + entity.getClass().getName() + "] does not have a createdBy value. createdBy is being set to [" + username + "]");
entity.setCreatedBy(username);
}
if (entity.getOwnedBy() == null) {
logger.info("Noark object of type [ " + entity.getClass().getName() + "] does not have a createdBy value. createdBy is being set to [" + username + "]");
entity.setOwnedBy(username);
}
entity.setDeleted(false);
}
use of nikita.model.noark5.v4.metadata.DocumentMedium in project nikita-noark5-core by HiOA-ABI.
the class DocumentMediumController method getDocumentMediumTemplate.
// Create a suggested documentMedium(like a template) with default values (nothing persisted)
// GET [contextPath][api]/metadata/ny-dokumentmedium
@ApiOperation(value = "Creates a suggested DocumentMedium", response = DocumentMedium.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "DocumentMedium codes found", response = DocumentMedium.class), @ApiResponse(code = 404, message = "No DocumentMedium found"), @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(method = RequestMethod.GET, value = NEW_DOCUMENT_MEDIUM)
public ResponseEntity<MetadataHateoas> getDocumentMediumTemplate(HttpServletRequest request) {
DocumentMedium documentMedium = new DocumentMedium();
documentMedium.setCode(TEMPLATE_DOCUMENT_MEDIUM_CODE);
documentMedium.setDescription(TEMPLATE_DOCUMENT_MEDIUM_DESCRIPTION);
MetadataHateoas metadataHateoas = new MetadataHateoas(documentMedium);
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(metadataHateoas);
}
Aggregations