Search in sources :

Example 1 with FondsCreatorHateoas

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

the class FondsCreatorHateoasController method getFondsCreatorTemplate.

// Create a suggested FondsCreator (like a template) object with default values (nothing persisted)
// GET [contextPath][api]/arkivstruktur/arkiv/{systemID}/ny-arkivskaper
// GET [contextPath][api]/arkivstruktur/ny-arkivskaper
@ApiOperation(value = "Suggests the contents of a new FondsCreator", notes = "Returns a pre-filled FondsCreator" + " with values relevant for the logged-in user", response = FondsCreatorHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "FondsCreator " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, 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 = { NEW_FONDS_CREATOR, FONDS + SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_FONDS_CREATOR })
public ResponseEntity<FondsCreatorHateoas> getFondsCreatorTemplate(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response) throws NikitaException {
    FondsCreator suggestedFondsCreator = new FondsCreator();
    // TODO: This should be replaced with configurable data based on whoever is logged in
    //       Currently just returns the test values
    suggestedFondsCreator.setFondsCreatorId("123456789");
    suggestedFondsCreator.setFondsCreatorName("Eksempel kommune");
    suggestedFondsCreator.setDescription("Eksempel kommune ligger i eksempel fylke nord for nord");
    FondsCreatorHateoas fondsCreatorHateoas = new FondsCreatorHateoas(suggestedFondsCreator);
    fondsHateoasHandler.addLinksOnNew(fondsCreatorHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).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) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with FondsCreatorHateoas

use of nikita.common.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
// 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)
@SuppressWarnings("unchecked")
@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), @ApiResponse(code = 501, message = API_MESSAGE_NOT_IMPLEMENTED) })
@Counted
@Timed
@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(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @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);
    fondsService.createFondsCreatorAssociatedWithFonds(systemID, fondsCreator);
    FondsCreatorHateoas fondsCreatorHateoas = new FondsCreatorHateoas(fondsCreator);
    fondsCreatorHateoasHandler.addLinks(fondsCreatorHateoas, request, new Authorisation());
    response.setHeader(ETAG, fondsCreator.getVersion().toString());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityCreatedEvent(this, fondsCreator));
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(fondsCreator.getVersion().toString()).body(fondsCreatorHateoas);
}
Also used : AfterNoarkEntityCreatedEvent(no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityCreatedEvent) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) 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 3 with FondsCreatorHateoas

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

the class FondsService method findFondsCreatorAssociatedWithFonds.

// All READ operations
/**
 * Retrieve a list of FondsCreator objects associated with a given Fonds
 * 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.
 * <p>
 * If any FondsCreator objects exist, they are wrapped in a
 * FondsCreatorHateoas object and returned to the caller.
 *
 * @param fondsSystemId The systemId of the Fonds object that you want to
 *                      retrieve associated FondsCreator objects
 * @return the fondsCreator objects wrapped as a FondsCreatorHateoas object
 */
@Override
public FondsCreatorHateoas findFondsCreatorAssociatedWithFonds(@NotNull String fondsSystemId) {
    Fonds fonds = getFondsOrThrow(fondsSystemId);
    FondsCreatorHateoas fondsCreatorHateoas = new FondsCreatorHateoas((List<INikitaEntity>) (List) fonds.getReferenceFondsCreator());
    fondsCreatorHateoasHandler.addLinks(fondsCreatorHateoas, new Authorisation());
    return fondsCreatorHateoas;
}
Also used : INikitaEntity(nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity) Authorisation(nikita.webapp.security.Authorisation) Fonds(nikita.common.model.noark5.v4.Fonds) FondsCreatorHateoas(nikita.common.model.noark5.v4.hateoas.FondsCreatorHateoas) List(java.util.List)

Example 4 with FondsCreatorHateoas

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

the class FondsService method createFondsCreatorAssociatedWithFonds.

/**
 * Persists a new FondsCreator object to the database. Some values are set
 * in the incoming payload (e.g. fonds_creator_name) and some are set by
 * the core. owner,createdBy, createdDate are automatically set by the core.
 * <p>
 * First we try to locate the fonds to associate the FondsCreator with. If
 * the fonds does not exist a NoarkEntityNotFoundException exception is
 * thrown. After that we check that the Fonds object is not already closed.
 *
 * @param fondsSystemId The systemId of the fonds object you wish to
 *                      associate the fondsCreator object with
 * @param fondsCreator  incoming fondsCreator object with some values set
 * @return the newly persisted fondsCreator object wrapped as a
 * FondsCreatorHateoas object
 */
@Override
public FondsCreatorHateoas createFondsCreatorAssociatedWithFonds(@NotNull String fondsSystemId, @NotNull FondsCreator fondsCreator) {
    Fonds fonds = getFondsOrThrow(fondsSystemId);
    checkFondsNotClosed(fonds);
    fondsCreatorService.createNewFondsCreator(fondsCreator);
    // add references to objects in both directions
    fondsCreator.addFonds(fonds);
    fonds.getReferenceFondsCreator().add(fondsCreator);
    // create the hateoas object with links
    FondsCreatorHateoas fondsCreatorHateoas = new FondsCreatorHateoas(fondsCreator);
    fondsCreatorHateoasHandler.addLinks(fondsCreatorHateoas, new Authorisation());
    return fondsCreatorHateoas;
}
Also used : Authorisation(nikita.webapp.security.Authorisation) Fonds(nikita.common.model.noark5.v4.Fonds) FondsCreatorHateoas(nikita.common.model.noark5.v4.hateoas.FondsCreatorHateoas)

Example 5 with FondsCreatorHateoas

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

Aggregations

Counted (com.codahale.metrics.annotation.Counted)12 ApiOperation (io.swagger.annotations.ApiOperation)12 ApiResponses (io.swagger.annotations.ApiResponses)12 FondsCreatorHateoas (nikita.common.model.noark5.v4.hateoas.FondsCreatorHateoas)8 Authorisation (nikita.webapp.security.Authorisation)8 Timed (com.codahale.metrics.annotation.Timed)6 FondsCreatorHateoas (nikita.model.noark5.v4.hateoas.FondsCreatorHateoas)6 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)6 FondsCreator (nikita.common.model.noark5.v4.FondsCreator)4 FondsCreator (nikita.model.noark5.v4.FondsCreator)4 List (java.util.List)3 Fonds (nikita.common.model.noark5.v4.Fonds)3 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)3 AfterNoarkEntityCreatedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityCreatedEvent)2 ArrayList (java.util.ArrayList)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 FondsHateoas (nikita.common.model.noark5.v4.hateoas.FondsHateoas)1 NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)1 INikitaEntity (nikita.model.noark5.v4.interfaces.entities.INikitaEntity)1 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)1