use of nikita.model.noark5.v4.hateoas.FondsCreatorHateoas in project nikita-noark5-core by HiOA-ABI.
the class FondsService method findFondsByOwnerPaginated.
/**
* Retrieve a list of paginated Fonds objects associated from the database.
*
* @param top how many results you want to retrieve
* @param skip how many rows of results yo uwant to skip over
* @return the list of Fonds object wrapped as a FondsCreatorHateoas object
*/
@Override
public FondsHateoas findFondsByOwnerPaginated(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<Fonds> criteriaQuery = criteriaBuilder.createQuery(Fonds.class);
Root<Fonds> from = criteriaQuery.from(Fonds.class);
CriteriaQuery<Fonds> select = criteriaQuery.select(from);
criteriaQuery.where(criteriaBuilder.equal(from.get("ownedBy"), loggedInUser));
TypedQuery<Fonds> typedQuery = entityManager.createQuery(select);
typedQuery.setFirstResult(skip);
typedQuery.setMaxResults(top);
FondsHateoas fondsHateoas = new FondsHateoas((List<INikitaEntity>) (List) typedQuery.getResultList());
fondsHateoasHandler.addLinks(fondsHateoas, new Authorisation());
return fondsHateoas;
}
use of nikita.model.noark5.v4.hateoas.FondsCreatorHateoas in project nikita-noark5-core by HiOA-ABI.
the class FondsHateoasController method createFondsCreatorAssociatedWithFonds.
// Create a FondsCreator and associate it with the Fonds identified by systemId
// API - All GET Requests (CRUD - READ)
// POST [contextPath][api]/arkivstruktur/arkiv/{systemId}/ny-arkivskaper
@ApiOperation(value = "Persists a FondsCreator associated with the given Fonds " + "systemId", notes = "Returns the newly created FondsCreator after it was " + "associated with a Fonds and persisted to the database", response = FondsCreatorHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "FondsCreator " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = FondsCreatorHateoas.class), @ApiResponse(code = 201, message = "FondsCreator " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = FondsCreatorHateoas.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 " + "FondsCreator"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@RequestMapping(method = RequestMethod.POST, value = FONDS + SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_FONDS_CREATOR, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<FondsCreatorHateoas> createFondsCreatorAssociatedWithFonds(HttpServletRequest request, @ApiParam(name = "systemID", value = "systemId of fonds to associate the series with.", required = true) @PathVariable("systemID") String systemID, @ApiParam(name = "fondsCreator", value = "Incoming fondsCreator object", required = true) @RequestBody FondsCreator fondsCreator) throws NikitaException {
validateForCreate(fondsCreator);
FondsCreatorHateoas fondsCreatorHateoas = fondsService.createFondsCreatorAssociatedWithFonds(systemID, fondsCreator);
return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(fondsCreatorHateoas.getEntityVersion().toString()).body(fondsCreatorHateoas);
}
use of nikita.model.noark5.v4.hateoas.FondsCreatorHateoas in project nikita-noark5-core by HiOA-ABI.
the class FondsCreatorHateoasSerializer method serializeNoarkEntity.
@Override
public void serializeNoarkEntity(INikitaEntity noarkSystemIdEntity, HateoasNoarkObject fondsCreatorHateoas, JsonGenerator jgen) throws IOException {
FondsCreator fondsCreator = (FondsCreator) noarkSystemIdEntity;
jgen.writeStartObject();
CommonUtils.Hateoas.Serialize.printFondsCreator(jgen, fondsCreator);
CommonUtils.Hateoas.Serialize.printHateoasLinks(jgen, fondsCreatorHateoas.getLinks(fondsCreator));
jgen.writeEndObject();
}
use of nikita.model.noark5.v4.hateoas.FondsCreatorHateoas in project nikita-noark5-core by HiOA-ABI.
the class FondsCreatorHateoasController method findOne.
// API - All GET Requests (CRUD - READ)
// Get a FondsCreator identified by a systemId
// GET [contextPath][api]/arkivstruktur/arkivskaper/{systemId}
@ApiOperation(value = "Retrieves a single FondsCreator entity given a systemId", response = FondsCreator.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "FondsCreator returned", 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.GET)
public ResponseEntity<FondsCreatorHateoas> findOne(HttpServletRequest request, @ApiParam(name = "systemId", value = "systemId of FondsCreator to retrieve.", required = true) @PathVariable("systemID") final String fondsCreatorSystemId) {
FondsCreator fondsCreator = fondsCreatorService.findBySystemIdOrderBySystemId(fondsCreatorSystemId);
if (fondsCreator == null) {
throw new NoarkEntityNotFoundException("Could not find FondsCreator object with systemID " + fondsCreatorSystemId);
}
FondsCreatorHateoas fondsCreatorHateoas = new FondsCreatorHateoas(fondsCreator);
fondsCreatorHateoasHandler.addLinks(fondsCreatorHateoas, request, new Authorisation());
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(fondsCreator.getVersion().toString()).body(fondsCreatorHateoas);
}
use of nikita.model.noark5.v4.hateoas.FondsCreatorHateoas in project nikita-noark5-core by HiOA-ABI.
the class FondsCreatorHateoasController method createFondsCreator.
// API - All POST Requests (CRUD - CREATE)
// Create a new FondsCreator
// POST [contextPath][api]/arkivstruktur/ny-arkivskaper
@ApiOperation(value = "Persists a FondsCreator object", notes = "Returns the newly" + " created FondsCreator object after it is persisted to the database", response = FondsCreatorHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "FondsCreator " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = FondsCreatorHateoas.class), @ApiResponse(code = 201, message = "FondsCreator " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = FondsCreatorHateoas.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 FondsCreator"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(method = { RequestMethod.POST }, value = NEW_FONDS_CREATOR, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<FondsCreatorHateoas> createFondsCreator(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "FondsCreator", value = "Incoming FondsCreator object", required = true) @RequestBody FondsCreator fondsCreator) throws NikitaException {
fondsCreatorService.createNewFondsCreator(fondsCreator);
FondsCreatorHateoas fondsCreatorHateoas = new FondsCreatorHateoas(fondsCreator);
fondsCreatorHateoasHandler.addLinks(fondsCreatorHateoas, request, new Authorisation());
applicationEventPublisher.publishEvent(new AfterNoarkEntityCreatedEvent(this, fondsCreator));
return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(fondsCreator.getVersion().toString()).body(fondsCreatorHateoas);
}
Aggregations