Search in sources :

Example 1 with NoarkInvalidStructureException

use of nikita.util.exceptions.NoarkInvalidStructureException 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 2 with NoarkInvalidStructureException

use of nikita.util.exceptions.NoarkInvalidStructureException in project nikita-noark5-core by HiOA-ABI.

the class FondsImportService 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 = seriesImportService.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)

Aggregations

Fonds (nikita.model.noark5.v4.Fonds)2 Series (nikita.model.noark5.v4.Series)2 NoarkEntityEditWhenClosedException (nikita.util.exceptions.NoarkEntityEditWhenClosedException)2 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)2 NoarkInvalidStructureException (nikita.util.exceptions.NoarkInvalidStructureException)2