use of nikita.common.model.noark5.v4.hateoas.FondsHateoas in project nikita-noark5-core by HiOA-ABI.
the class FondsHateoasSerializer method serializeNoarkEntity.
@Override
public void serializeNoarkEntity(INikitaEntity noarkSystemIdEntity, HateoasNoarkObject fondsHateoas, JsonGenerator jgen) throws IOException {
Fonds fonds = (Fonds) noarkSystemIdEntity;
jgen.writeStartObject();
CommonUtils.Hateoas.Serialize.printSystemIdEntity(jgen, fonds);
CommonUtils.Hateoas.Serialize.printTitleAndDescription(jgen, fonds);
if (fonds.getFondsStatus() != null) {
jgen.writeStringField(FONDS_STATUS, fonds.getFondsStatus());
}
CommonUtils.Hateoas.Serialize.printDocumentMedium(jgen, fonds);
CommonUtils.Hateoas.Serialize.printStorageLocation(jgen, fonds);
CommonUtils.Hateoas.Serialize.printCreateEntity(jgen, fonds);
CommonUtils.Hateoas.Serialize.printFinaliseEntity(jgen, fonds);
CommonUtils.Hateoas.Serialize.printHateoasLinks(jgen, fondsHateoas.getLinks(fonds));
jgen.writeEndObject();
}
use of nikita.common.model.noark5.v4.hateoas.FondsHateoas in project nikita-noark5-core by HiOA-ABI.
the class FondsHateoasController method createFonds.
// API - All POST Requests (CRUD - CREATE)
// Create a Fonds
// POST [contextPath][api]/arkivstruktur/arkiv
@ApiOperation(value = "Persists a Fonds object", notes = "Returns the newly created Fonds object after it is " + "persisted to the database", response = FondsHateoas.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 = 404, message = API_MESSAGE_PARENT_DOES_NOT_EXIST + " of type " + "Fonds"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@RequestMapping(method = RequestMethod.POST, value = NEW_FONDS, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<FondsHateoas> createFonds(HttpServletRequest request, @ApiParam(name = "fonds", value = "Incoming fonds object", required = true) @RequestBody Fonds fonds) throws NikitaException {
validateForCreate(fonds);
FondsHateoas fondsHateoas = fondsService.createNewFonds(fonds);
return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(fonds.getVersion().toString()).body(fondsHateoas);
}
use of nikita.common.model.noark5.v4.hateoas.FondsHateoas in project nikita-noark5-core by HiOA-ABI.
the class FondsHateoasController method updateFonds.
// API - All PUT Requests (CRUD - UPDATE)
// Update a Fonds
// PUT [contextPath][api]/arkivstruktur/arkiv
@ApiOperation(value = "Updates a Fonds object", notes = "Returns the newly updated Fonds object after it is " + "persisted to the database", response = FondsHateoas.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 = 404, message = API_MESSAGE_PARENT_DOES_NOT_EXIST + " of type Fonds"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@RequestMapping(method = RequestMethod.PUT, value = FONDS + SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<FondsHateoas> updateFonds(HttpServletRequest request, @ApiParam(name = "systemID", value = "systemId of fonds to update.", required = true) @PathVariable("systemID") String systemID, @ApiParam(name = "fonds", value = "Incoming fonds object", required = true) @RequestBody Fonds fonds) throws NikitaException {
validateForUpdate(fonds);
FondsHateoas fondsHateoas = fondsService.handleUpdate(systemID, parseETAG(request.getHeader(ETAG)), fonds);
return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(fondsHateoas.getEntityVersion().toString()).body(fondsHateoas);
}
use of nikita.common.model.noark5.v4.hateoas.FondsHateoas 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.common.model.noark5.v4.hateoas.FondsHateoas 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