use of nikita.model.noark5.v4.BasicRecord in project nikita-noark5-core by HiOA-ABI.
the class BasicRecordHateoasController method deleteRecordBySystemId.
// Delete a Record identified by systemID
// DELETE [contextPath][api]/arkivstruktur/registrering/{systemId}/
@ApiOperation(value = "Deletes a single Record entity identified by systemID", response = HateoasNoarkObject.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Parent entity (DocumentDescription or Record) 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> deleteRecordBySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the record to delete", required = true) @PathVariable("systemID") final String systemID) {
BasicRecord basicRecord = basicRecordService.findBySystemId(systemID);
NoarkEntity parentEntity = basicRecord.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());
}
basicRecordService.deleteEntity(systemID);
applicationEventPublisher.publishEvent(new AfterNoarkEntityDeletedEvent(this, basicRecord));
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(hateoasNoarkObject);
}
use of nikita.model.noark5.v4.BasicRecord in project nikita-noark5-core by HiOA-ABI.
the class BasicRecordHateoasController method findAllBasicRecord.
@ApiOperation(value = "Retrieves multiple BasicRecord entities limited by ownership rights", notes = "The field skip" + "tells how many BasicRecord 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 = BasicRecordHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "BasicRecord list found", response = BasicRecordHateoas.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(method = RequestMethod.GET)
public ResponseEntity<BasicRecordHateoas> findAllBasicRecord(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @RequestParam(name = "top", required = false) Integer top, @RequestParam(name = "skip", required = false) Integer skip) {
BasicRecordHateoas basicRecordHateoas = new BasicRecordHateoas((List<INikitaEntity>) (List) basicRecordService.findBasicRecordByOwnerPaginated(top, skip));
basicRecordHateoasHandler.addLinks(basicRecordHateoas, new Authorisation());
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(basicRecordHateoas);
}
use of nikita.model.noark5.v4.BasicRecord in project nikita-noark5-core by HiOA-ABI.
the class BasicRecordService method handleUpdate.
// All UPDATE operations
@Override
public BasicRecord handleUpdate(@NotNull String systemId, @NotNull Long version, @NotNull BasicRecord incomingBasicRecord) {
BasicRecord existingBasicRecord = getBasicRecordOrThrow(systemId);
// Here copy all the values you are allowed to copy ....
if (null != incomingBasicRecord.getDescription()) {
existingBasicRecord.setDescription(incomingBasicRecord.getDescription());
}
if (null != incomingBasicRecord.getTitle()) {
existingBasicRecord.setTitle(incomingBasicRecord.getTitle());
}
if (null != incomingBasicRecord.getDocumentMedium()) {
existingBasicRecord.setDocumentMedium(existingBasicRecord.getDocumentMedium());
}
existingBasicRecord.setVersion(version);
basicRecordRepository.save(existingBasicRecord);
return existingBasicRecord;
}
use of nikita.model.noark5.v4.BasicRecord in project nikita-noark5-core by HiOA-ABI.
the class BasicRecordService method getBasicRecordOrThrow.
// 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 BasicRecord back. If there is no valid
* BasicRecord, an exception is thrown
*
* @param basicRecordSystemId
* @return
*/
protected BasicRecord getBasicRecordOrThrow(@NotNull String basicRecordSystemId) {
BasicRecord basicRecord = basicRecordRepository.findBySystemId(basicRecordSystemId);
if (basicRecord == null) {
String info = INFO_CANNOT_FIND_OBJECT + " BasicRecord, using systemId " + basicRecordSystemId;
logger.info(info);
throw new NoarkEntityNotFoundException(info);
}
return basicRecord;
}
use of nikita.model.noark5.v4.BasicRecord in project nikita-noark5-core by HiOA-ABI.
the class BasicRecordService method findBasicRecordByOwnerPaginated.
// All READ operations
@Override
public List<BasicRecord> findBasicRecordByOwnerPaginated(Integer top, Integer skip) {
if (top == null || top > maxPageSize) {
top = maxPageSize;
}
if (skip == null) {
skip = 0;
}
String loggedInUser = SecurityContextHolder.getContext().getAuthentication().getName();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<BasicRecord> criteriaQuery = criteriaBuilder.createQuery(BasicRecord.class);
Root<BasicRecord> from = criteriaQuery.from(BasicRecord.class);
CriteriaQuery<BasicRecord> select = criteriaQuery.select(from);
criteriaQuery.where(criteriaBuilder.equal(from.get("ownedBy"), loggedInUser));
TypedQuery<BasicRecord> typedQuery = entityManager.createQuery(select);
typedQuery.setFirstResult(skip);
typedQuery.setMaxResults(top);
return typedQuery.getResultList();
}
Aggregations