Search in sources :

Example 1 with Fonds

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

the class FondsCreatorService method createFondsAssociatedWithFondsCreator.

@Override
public Fonds createFondsAssociatedWithFondsCreator(String fondsCreatorSystemId, Fonds fonds) {
    FondsCreator fondsCreator = getFondsCreatorOrThrow(fondsCreatorSystemId);
    NoarkUtils.NoarkEntity.Create.checkDocumentMediumValid(fonds);
    NoarkUtils.NoarkEntity.Create.setNoarkEntityValues(fonds);
    fonds.setFondsStatus(STATUS_OPEN);
    NoarkUtils.NoarkEntity.Create.setFinaliseEntityValues(fonds);
    fonds.getReferenceFondsCreator().add(fondsCreator);
    fondsCreator.getReferenceFonds().add(fonds);
    fondsRepository.save(fonds);
    return fonds;
}
Also used : FondsCreator(nikita.model.noark5.v4.FondsCreator)

Example 2 with Fonds

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

the class FondsService method createFondsAssociatedWithFonds.

/**
     *
     ** Persists a new fonds object to the database, that is associated with a parent fonds object. 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.
     *
     * First we try to locate the parent. If the parent does not exist a NoarkEntityNotFoundException exception is
     * thrown
     *
     * @param childFonds incoming fonds object with some values set
     * @param parentFondsSystemId The systemId of the parent fonds
     * @return the newly persisted fonds object
     */
@Override
public Fonds createFondsAssociatedWithFonds(String parentFondsSystemId, Fonds childFonds) {
    Fonds persistedChildFonds = null;
    Fonds parentFonds = fondsRepository.findBySystemIdOrderBySystemId(parentFondsSystemId);
    if (parentFonds == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " Fonds, using fondsSystemId " + parentFondsSystemId + " when " + "trying to associate a child fonds with a parent fonds";
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    } else if (parentFonds.getReferenceSeries() != null) {
        String info = INFO_INVALID_STRUCTURE + " Cannot associate a new child fonds with a fonds that has " + "one or more series " + parentFondsSystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    } else {
        childFonds.setReferenceParentFonds(parentFonds);
        persistedChildFonds = this.createNewFonds(childFonds);
    }
    return persistedChildFonds;
}
Also used : Fonds(nikita.model.noark5.v4.Fonds) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException)

Example 3 with Fonds

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

the class FondsService method findFondsByOwnerPaginated.

// All READ operations
public List<Fonds> 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(maxPageSize);
    return typedQuery.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Fonds(nikita.model.noark5.v4.Fonds)

Example 4 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.
     *
     * First we try to locate the parent fonds. If the parent fonds does not exist a NoarkEntityNotFoundException
     * exception is thrown. Next  we check that the fonds does not have children fonds. If it does an
     * exception is thrown.
     *
     * @param fondsSystemId
     * @param series
     * @return the newly persisted series object
     */
@Override
public Series createSeriesAssociatedWithFonds(String fondsSystemId, Series series) {
    Series persistedSeries = null;
    Fonds fonds = fondsRepository.findBySystemIdOrderBySystemId(fondsSystemId);
    if (fonds == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " Fonds, using fondsSystemId " + fondsSystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    } else if (fonds.getReferenceChildFonds() != null && fonds.getReferenceChildFonds().size() > 0) {
        String info = INFO_INVALID_STRUCTURE + " Cannot associate series with a fonds that has" + "children fonds " + fondsSystemId;
        logger.info(info);
        throw new NoarkInvalidStructureException(info, "Fonds", "Series");
    } else if (fonds.getFondsStatus() != null && fonds.getFondsStatus().equals(STATUS_CLOSED)) {
        String info = INFO_CANNOT_ASSOCIATE_WITH_CLOSED_OBJECT + ". Fonds with fondsSystemId " + fondsSystemId + "has status " + STATUS_CLOSED;
        logger.info(info);
        throw new NoarkEntityEditWhenClosedException(info);
    } else {
        series.setReferenceFonds(fonds);
        persistedSeries = seriesService.save(series);
    }
    return persistedSeries;
}
Also used : Series(nikita.model.noark5.v4.Series) NoarkInvalidStructureException(nikita.util.exceptions.NoarkInvalidStructureException) Fonds(nikita.model.noark5.v4.Fonds) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException) NoarkEntityEditWhenClosedException(nikita.util.exceptions.NoarkEntityEditWhenClosedException)

Example 5 with Fonds

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

the class FondsService method deleteEntity.

// All DELETE operations
@Override
public void deleteEntity(@NotNull String fondsSystemId) {
    Fonds fonds = getFondsOrThrow(fondsSystemId);
    // Disassociate the link between Fonds and FondsCreator
    // https://github.com/HiOA-ABI/nikita-noark5-core/issues/82
    Query q = entityManager.createNativeQuery("DELETE FROM fonds_fonds_creator WHERE f_pk_fonds_id  = :id ;");
    q.setParameter("id", fonds.getId());
    q.executeUpdate();
    entityManager.remove(fonds);
    entityManager.flush();
    entityManager.clear();
//fondsRepository.delete(fonds);
}
Also used : TypedQuery(javax.persistence.TypedQuery) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) Fonds(nikita.model.noark5.v4.Fonds)

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