Search in sources :

Example 21 with FondsHateoas

use of nikita.model.noark5.v4.hateoas.FondsHateoas in project nikita-noark5-core by HiOA-ABI.

the class FondsImportController method createFondsAssociatedWithFonds.

// TODO: Doublecheck this logic
@ApiOperation(value = "Persists a child Fonds object", notes = "Returns the newly" + " created child 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), @ApiResponse(code = 501, message = API_MESSAGE_NOT_IMPLEMENTED) })
@Counted
@Timed
@RequestMapping(method = RequestMethod.POST, value = FONDS + SLASH + LEFT_PARENTHESIS + "fondsSystemId" + RIGHT_PARENTHESIS + SLASH + NEW_FONDS)
public ResponseEntity<FondsHateoas> createFondsAssociatedWithFonds(@ApiParam(name = "parentFondsSystemId", value = "systemId of parent fonds to associate the fonds with.", required = true) @PathVariable String parentFondsSystemId, @ApiParam(name = "fonds", value = "Incoming fonds object", required = true) @RequestBody Fonds fonds) throws NikitaException {
    Fonds createdFonds = fondsImportService.createFondsAssociatedWithFonds(parentFondsSystemId, fonds);
    FondsHateoas fondsHateoas = new FondsHateoas(createdFonds);
    return new ResponseEntity<>(fondsHateoas, HttpStatus.CREATED);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) FondsHateoas(nikita.model.noark5.v4.hateoas.FondsHateoas) Fonds(nikita.model.noark5.v4.Fonds) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 22 with FondsHateoas

use of nikita.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;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) FondsHateoas(nikita.common.model.noark5.v4.hateoas.FondsHateoas) INikitaEntity(nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity) Authorisation(nikita.webapp.security.Authorisation) Fonds(nikita.common.model.noark5.v4.Fonds) List(java.util.List)

Example 23 with FondsHateoas

use of nikita.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);
}
Also used : FondsHateoas(nikita.common.model.noark5.v4.hateoas.FondsHateoas) Authorisation(nikita.webapp.security.Authorisation) AfterNoarkEntityUpdatedEvent(nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 24 with FondsHateoas

use of nikita.model.noark5.v4.hateoas.FondsHateoas in project nikita-noark5-core by HiOA-ABI.

the class FondsCreatorHateoasController method deleteSeriesBySystemId.

// Delete a FondsCreator identified by systemID
// DELETE [contextPath][api]/arkivstruktur/arkivskaper/{systemId}/
@ApiOperation(value = "Deletes a single FondsCreator entity identified by systemID", response = FondsHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Parent Fonds returned", response = FondsHateoas.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 + FONDS_CREATOR + SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.DELETE)
public ResponseEntity<String> deleteSeriesBySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the fondsCreator to delete", required = true) @PathVariable("systemID") final String seriesSystemId) {
    FondsCreator fondsCreator = fondsCreatorService.findBySystemId(seriesSystemId);
    fondsCreatorService.deleteEntity(seriesSystemId);
    applicationEventPublisher.publishEvent(new AfterNoarkEntityDeletedEvent(this, fondsCreator));
    /*        List<Fonds> fonds = new List<>();
        fonds.addAll(fondsCreator.getReferenceFonds());
        FondsHateoas fondsHateoas = new FondsHateoas((List<INikitaEntity>) (List)fonds);
        fondsHateoasHandler.addLinks(fondsHateoas, new Authorisation());
  */
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body("{\"status\" : \"Success\"}");
}
Also used : FondsCreator(nikita.common.model.noark5.v4.FondsCreator) AfterNoarkEntityDeletedEvent(nikita.webapp.web.events.AfterNoarkEntityDeletedEvent) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 25 with FondsHateoas

use of nikita.model.noark5.v4.hateoas.FondsHateoas in project nikita-noark5-core by HiOA-ABI.

the class FondsHateoasController method createFondsAssociatedWithFonds.

// Create a sub-fonds and associate it with the Fonds identified by systemId
// POST [contextPath][api]/arkivstruktur/arkiv/{systemId}/ny-underarkiv
@ApiOperation(value = "Persists a child Fonds object", notes = "Returns the newly created child 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), @ApiResponse(code = 501, message = API_MESSAGE_NOT_IMPLEMENTED) })
@Counted
@RequestMapping(method = RequestMethod.POST, value = FONDS + SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_SUB_FONDS, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<FondsHateoas> createFondsAssociatedWithFonds(HttpServletRequest request, @ApiParam(name = "systemID", value = "systemId of parent fonds 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 {
    validateForCreate(fonds);
    FondsHateoas fondsHateoas = fondsService.createFondsAssociatedWithFonds(systemID, fonds);
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(fonds.getVersion().toString()).body(fondsHateoas);
}
Also used : FondsHateoas(nikita.common.model.noark5.v4.hateoas.FondsHateoas) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)15 ApiOperation (io.swagger.annotations.ApiOperation)15 ApiResponses (io.swagger.annotations.ApiResponses)15 Timed (com.codahale.metrics.annotation.Timed)10 Fonds (nikita.model.noark5.v4.Fonds)10 FondsHateoas (nikita.model.noark5.v4.hateoas.FondsHateoas)10 FondsHateoas (nikita.common.model.noark5.v4.hateoas.FondsHateoas)9 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)8 Fonds (nikita.common.model.noark5.v4.Fonds)6 Authorisation (nikita.webapp.security.Authorisation)6 AfterNoarkEntityUpdatedEvent (nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)3 ArrayList (java.util.ArrayList)2 INikitaEntity (nikita.model.noark5.v4.interfaces.entities.INikitaEntity)2 AfterNoarkEntityCreatedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityCreatedEvent)2 AfterNoarkEntityUpdatedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)2 ResponseEntity (org.springframework.http.ResponseEntity)2 List (java.util.List)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 FondsCreator (nikita.common.model.noark5.v4.FondsCreator)1 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)1