use of nikita.common.model.noark5.v4.FondsCreator in project nikita-noark5-core by HiOA-ABI.
the class FondsCreatorHateoasController method updateFondsCreator.
// API - All PUT Requests (CRUD - UPDATE)
// Updates a FondsCreator identified by a systemId
// PUT [contextPath][api]/arkivstruktur/arkivskaper/{systemId}
@ApiOperation(value = "Updates a FondsCreator identified by a systemId with new values", response = FondsCreator.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "FondsCreator updated", response = FondsCreator.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 = FONDS_CREATOR + SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.PUT, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<FondsCreatorHateoas> updateFondsCreator(HttpServletRequest request, @ApiParam(name = "fondsCreator", value = "Incoming fondsCreator object", required = true) @RequestBody FondsCreator fondsCreator, @ApiParam(name = "systemId", value = "systemId of FondsCreator to retrieve.", required = true) @PathVariable("systemID") final String systemID) {
FondsCreator createdFonds = fondsCreatorService.handleUpdate(systemID, parseETAG(request.getHeader(ETAG)), fondsCreator);
applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, createdFonds));
FondsCreatorHateoas fondsCreatorHateoas = new FondsCreatorHateoas(createdFonds);
fondsCreatorHateoasHandler.addLinks(fondsCreatorHateoas, request, new Authorisation());
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(createdFonds.getVersion().toString()).body(fondsCreatorHateoas);
}
use of nikita.common.model.noark5.v4.FondsCreator in project nikita-noark5-core by HiOA-ABI.
the class FondsCreatorHateoasController method findAllFondsCreator.
// Get all FondsCreator
// GET [contextPath][api]/arkivstruktur/arkivskaper/
@ApiOperation(value = "Retrieves multiple FondsCreator entities limited by ownership rights", notes = "The field skip" + "tells how many FondsCreator 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 = FondsCreatorHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "FondsCreator found", response = FondsCreatorHateoas.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(method = RequestMethod.GET, value = FONDS_CREATOR)
public ResponseEntity<FondsCreatorHateoas> findAllFondsCreator(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @RequestParam(name = "top", required = false) Integer top, @RequestParam(name = "skip", required = false) Integer skip) {
FondsCreatorHateoas fondsCreatorHateoas = new FondsCreatorHateoas((ArrayList<INikitaEntity>) (ArrayList) fondsCreatorService.findFondsCreatorByOwnerPaginated(top, skip));
fondsCreatorHateoasHandler.addLinks(fondsCreatorHateoas, request, new Authorisation());
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(fondsCreatorHateoas);
}
use of nikita.common.model.noark5.v4.FondsCreator in project nikita-noark5-core by HiOA-ABI.
the class FondsCreatorService method deleteEntity.
// All DELETE operations
@Override
public void deleteEntity(@NotNull String fondsCreatorSystemId) {
FondsCreator fondsCreator = getFondsCreatorOrThrow(fondsCreatorSystemId);
// See issue for a description of why this code was written this way
// https://github.com/HiOA-ABI/nikita-noark5-core/issues/82
Query q = entityManager.createNativeQuery("DELETE FROM fonds_fonds_creator WHERE f_pk_fonds_creator_id = :id ;");
q.setParameter("id", fondsCreator.getId());
q.executeUpdate();
entityManager.remove(fondsCreator);
entityManager.flush();
entityManager.clear();
}
use of nikita.common.model.noark5.v4.FondsCreator in project nikita-noark5-core by HiOA-ABI.
the class FondsService method deleteEntity.
// All DELETE operations
/**
* Deletes a Fonds object from the database. First we try to locate the
* Fonds object. If the Fonds object does not exist a
* NoarkEntityNotFoundException exception is thrown that the caller has
* to deal with. Note that as there is a @ManyToMany relationship between
* Fonds and FondsCreator with a join table, we first have to
* disassociate the link between Fonds and FondsCreator or we hit a
* foreign key constraint issue. The same applies for Fonds and
* StorageLocation.
* <p>
* In order to minimise problems that could be caused with table and
* column names changing, constants are used to define relevant column
* and table names.
* <p>
* The approach is is discussed in a nikita github issue
* https://github.com/HiOA-ABI/nikita-noark5-core/issues/82
*
* @param fondsSystemId The systemId of the fonds object to retrieve
*/
@Override
public void deleteEntity(@NotNull String fondsSystemId) {
Fonds fonds = getFondsOrThrow(fondsSystemId);
// Disassociate any links between Fonds and FondsCreator
Query q = entityManager.createNativeQuery("DELETE FROM " + TABLE_FONDS_FONDS_CREATOR + " WHERE " + FOREIGN_KEY_FONDS_PK + " = :id ;");
q.setParameter("id", fonds.getId());
q.executeUpdate();
// Disassociate any links between Fonds and StorageLocation
q = entityManager.createNativeQuery("DELETE FROM " + TABLE_STORAGE_LOCATION + " WHERE " + FOREIGN_KEY_FONDS_PK + " = :id ;");
q.setParameter("id", fonds.getId());
q.executeUpdate();
// Next get hibernate to delete the Fonds object
entityManager.remove(fonds);
entityManager.flush();
entityManager.clear();
}
use of nikita.common.model.noark5.v4.FondsCreator in project nikita-noark5-core by HiOA-ABI.
the class FondsCreatorHateoasController method createFondsAssociatedWithFondsCreator.
// Create a new fonds
// POST [contextPath][api]/arkivstruktur/arkivskaper/{systemID}/ny-arkiv
@ApiOperation(value = "Persists a new Fonds associated with a FondsCreator", notes = "Returns the newly" + " created Fonds after it is associated with the Fonds and persisted to the database", response = FondsCreatorHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Fonds " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = FondsHateoas.class), @ApiResponse(code = 201, message = "Fonds " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = FondsHateoas.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@RequestMapping(method = RequestMethod.POST, value = FONDS_CREATOR + SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_FONDS, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<FondsHateoas> createFondsAssociatedWithFondsCreator(HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemId", value = "systemId of FondsCreator to associate the Fonds with.", required = true) @PathVariable("systemID") String systemID, @ApiParam(name = "fonds", value = "Incoming fonds object", required = true) @RequestBody Fonds fonds) throws NikitaException {
fondsCreatorService.createFondsAssociatedWithFondsCreator(systemID, fonds);
FondsHateoas fondsHateoas = new FondsHateoas(fonds);
fondsHateoasHandler.addLinks(fondsHateoas, new Authorisation());
applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, fonds));
return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(fonds.getVersion().toString()).body(fondsHateoas);
}
Aggregations