Search in sources :

Example 31 with FondsCreator

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);
}
Also used : Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) FondsCreatorHateoas(nikita.model.noark5.v4.hateoas.FondsCreatorHateoas) FondsCreator(nikita.model.noark5.v4.FondsCreator) AfterNoarkEntityUpdatedEvent(no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 32 with FondsCreator

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);
}
Also used : INikitaEntity(nikita.model.noark5.v4.interfaces.entities.INikitaEntity) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) ArrayList(java.util.ArrayList) FondsCreatorHateoas(nikita.model.noark5.v4.hateoas.FondsCreatorHateoas) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 33 with FondsCreator

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();
}
Also used : Query(javax.persistence.Query) FondsCreator(nikita.common.model.noark5.v4.FondsCreator)

Example 34 with FondsCreator

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();
}
Also used : TypedQuery(javax.persistence.TypedQuery) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) Fonds(nikita.common.model.noark5.v4.Fonds)

Example 35 with FondsCreator

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);
}
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)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)16 ApiOperation (io.swagger.annotations.ApiOperation)16 ApiResponses (io.swagger.annotations.ApiResponses)16 FondsCreator (nikita.model.noark5.v4.FondsCreator)11 FondsCreator (nikita.common.model.noark5.v4.FondsCreator)10 Authorisation (nikita.webapp.security.Authorisation)9 Timed (com.codahale.metrics.annotation.Timed)8 FondsCreatorHateoas (nikita.common.model.noark5.v4.hateoas.FondsCreatorHateoas)8 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)7 FondsCreatorHateoas (nikita.model.noark5.v4.hateoas.FondsCreatorHateoas)6 Query (javax.persistence.Query)4 Fonds (nikita.common.model.noark5.v4.Fonds)4 TypedQuery (javax.persistence.TypedQuery)3 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)3 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)3 AfterNoarkEntityUpdatedEvent (nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 List (java.util.List)2 FondsHateoas (nikita.common.model.noark5.v4.hateoas.FondsHateoas)2 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)2