Search in sources :

Example 61 with Fonds

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

the class FondsService method createSeriesAssociatedWithFonds.

/**
 * Persists a new Series object to the database. Some values are set in
 * the incoming payload (e.g. title) 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 Series with. If the
 * fonds does not exist a NoarkEntityNotFoundException exception is
 * thrown. Then we check that the fonds does not have children fonds. If it
 * does an NoarkInvalidStructureException exception is thrown. After that
 * we check that the Fonds object is not already closed.
 *
 * @param fondsSystemId The systemId of the fonds object to associate a
 *                      Series with
 * @param series        The incoming Series object
 * @return the newly persisted series object wrapped as a SeriesHateoas
 * object
 */
@Override
public SeriesHateoas createSeriesAssociatedWithFonds(@NotNull String fondsSystemId, @NotNull Series series) {
    Fonds fonds = getFondsOrThrow(fondsSystemId);
    checkFondsNotClosed(fonds);
    checkFondsDoesNotContainSubFonds(fonds);
    series.setReferenceFonds(fonds);
    SeriesHateoas seriesHateoas = new SeriesHateoas(seriesService.save(series));
    seriesHateoasHandler.addLinks(seriesHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityCreatedEvent(this, fonds));
    return seriesHateoas;
}
Also used : AfterNoarkEntityCreatedEvent(nikita.webapp.web.events.AfterNoarkEntityCreatedEvent) Authorisation(nikita.webapp.security.Authorisation) SeriesHateoas(nikita.common.model.noark5.v4.hateoas.SeriesHateoas) Fonds(nikita.common.model.noark5.v4.Fonds)

Example 62 with Fonds

use of nikita.common.model.noark5.v4.Fonds 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 63 with Fonds

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

the class FondsService method findSeriesAssociatedWithFonds.

/**
 * Retrieve a list of Series 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 Series objects exist, they are wrapped in a SeriesHateoas
 * object and returned to the caller.
 *
 * @param fondsSystemId The systemId of the Fonds object that you want to
 *                      retrieve associated Series objects
 * @return the list of Series objects wrapped as a SeriesHateoas object
 */
@Override
public SeriesHateoas findSeriesAssociatedWithFonds(@NotNull String fondsSystemId) {
    Fonds fonds = getFondsOrThrow(fondsSystemId);
    SeriesHateoas seriesHateoas = new SeriesHateoas((List<INikitaEntity>) (List) fonds.getReferenceSeries());
    seriesHateoasHandler.addLinks(seriesHateoas, new Authorisation());
    return seriesHateoas;
}
Also used : INikitaEntity(nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity) Authorisation(nikita.webapp.security.Authorisation) SeriesHateoas(nikita.common.model.noark5.v4.hateoas.SeriesHateoas) Fonds(nikita.common.model.noark5.v4.Fonds) List(java.util.List)

Example 64 with Fonds

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

the class FondsDeserializer method deserialize.

@Override
public Fonds deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    StringBuilder errors = new StringBuilder();
    Fonds fonds = new Fonds();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // TODO : Are we deserialising parent? No, it's not done here or is it????
    // Deserialise general properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkEntity(fonds, objectNode, errors);
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(fonds, objectNode, errors);
    CommonUtils.Hateoas.Deserialize.deserialiseStorageLocation(fonds, objectNode, errors);
    // Deserialize seriesStatus
    JsonNode currentNode = objectNode.get(N5ResourceMappings.FONDS_STATUS);
    if (currentNode != null) {
        fonds.setFondsStatus(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.FONDS_STATUS);
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        errors.append("The arkiv you tried to create is malformed. The " + "following fields are not recognised as arkiv fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]. ");
    }
    if (0 < errors.length())
        throw new NikitaMalformedInputDataException(errors.toString());
    return fonds;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Fonds(nikita.common.model.noark5.v4.Fonds) JsonNode(com.fasterxml.jackson.databind.JsonNode) NikitaMalformedInputDataException(nikita.common.util.exceptions.NikitaMalformedInputDataException)

Example 65 with Fonds

use of nikita.common.model.noark5.v4.Fonds 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

Fonds (nikita.model.noark5.v4.Fonds)28 Counted (com.codahale.metrics.annotation.Counted)27 ApiOperation (io.swagger.annotations.ApiOperation)27 ApiResponses (io.swagger.annotations.ApiResponses)27 Timed (com.codahale.metrics.annotation.Timed)18 Fonds (nikita.common.model.noark5.v4.Fonds)15 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)14 Authorisation (nikita.webapp.security.Authorisation)13 FondsHateoas (nikita.model.noark5.v4.hateoas.FondsHateoas)10 FondsHateoas (nikita.common.model.noark5.v4.hateoas.FondsHateoas)9 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)8 ArrayList (java.util.ArrayList)5 Series (nikita.model.noark5.v4.Series)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 List (java.util.List)4 FondsCreatorHateoas (nikita.common.model.noark5.v4.hateoas.FondsCreatorHateoas)4 SeriesHateoas (nikita.common.model.noark5.v4.hateoas.SeriesHateoas)4 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)4 FondsCreator (nikita.common.model.noark5.v4.FondsCreator)3