Search in sources :

Example 41 with Fonds

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

the class FondsService method handleUpdate.

// All UPDATE operations
@Override
public Fonds handleUpdate(@NotNull String systemId, @NotNull Long version, @NotNull Fonds incomingFonds) {
    Fonds existingFonds = getFondsOrThrow(systemId);
    // Copy all the values you are allowed to copy ....
    if (null != incomingFonds.getDescription()) {
        existingFonds.setDescription(incomingFonds.getDescription());
    }
    if (null != incomingFonds.getTitle()) {
        existingFonds.setTitle(incomingFonds.getTitle());
    }
    if (null != incomingFonds.getDocumentMedium()) {
        existingFonds.setDocumentMedium(existingFonds.getDocumentMedium());
    }
    existingFonds.setVersion(version);
    fondsRepository.save(existingFonds);
    return existingFonds;
}
Also used : Fonds(nikita.model.noark5.v4.Fonds)

Example 42 with Fonds

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

the class FondsService method updateFondsSetTitle.

public Fonds updateFondsSetTitle(Long id, String newTitle) {
    Fonds fonds = fondsRepository.findById(id);
    if (fonds == null) {
    // TODO throw Object not find
    } else if (fonds.getFondsStatus().equals(STATUS_CLOSED)) {
    // TODO throw Object finalises, cannot be edited
    }
    fonds.setTitle(newTitle);
    return fondsRepository.save(fonds);
}
Also used : Fonds(nikita.model.noark5.v4.Fonds)

Example 43 with Fonds

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

the class FondsImportService method createFondsAssociatedWithFonds.

/**
     *
     * Persists a new fonds object to the database, that is associated with a parent fonds object. It's assumed the
     * caller has a valid fonds object. Minimal error checking occurs here.
     *
     * 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 44 with Fonds

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

the class NoarkImportService method checkAndSetDefaultValues.

/**
     *
     * Check a Noark entity (fonds, series, file, etc) for valid properties and set any values that have not been set
     * that should be set with default values.
     *
     * @param entity
     * @throws Exception
     */
public void checkAndSetDefaultValues(INoarkGeneralEntity entity) throws Exception {
    String username = SecurityContextHolder.getContext().getAuthentication().getName();
    // Not all Noark objects, i.e DocumentDescription and DocumentObject have a documentMedium property
    if (entity instanceof IDocumentMedium) {
        if (!NoarkUtils.NoarkEntity.Create.checkDocumentMediumValid(((IDocumentMedium) entity))) {
            logger.error("Document medium not a valid document medium. Assigned value is " + ((IDocumentMedium) entity).getDocumentMedium());
        // An exception will be thrown  by checkDocumentMediumValid if not valid
        //TODO: Look at the logic here, as a change checkDocumentMediumValid kinda makes
        // the if redundant
        }
    }
    // uniqueness via systemId
    if (entity.getSystemId() == null) {
        entity.setSystemId(UUID.randomUUID().toString());
    } else if (entity.getSystemId().length() != Constants.UUIDLength) {
        String randomUUID = UUID.randomUUID().toString();
        logger.info("Noark object of type [ " + entity.getClass().getName() + "] does not have a valid UUID. Original value [" + entity.getSystemId() + entity.toString() + "] is being changed and assigned with [" + randomUUID + "]");
        entity.setSystemId(randomUUID);
    }
    if (entity.getCreatedDate() == null) {
        logger.info("Noark object of type [ " + entity.getClass().getName() + "] does not have a createdDate value. createdDate is being set to [" + new Date().toString() + "]");
        entity.setCreatedDate(new Date());
    }
    if (entity.getCreatedBy() == null) {
        logger.info("Noark object of type [ " + entity.getClass().getName() + "] does not have a createdBy value. createdBy is being set to [" + username + "]");
        entity.setCreatedBy(username);
    }
    if (entity.getOwnedBy() == null) {
        logger.info("Noark object of type [ " + entity.getClass().getName() + "] does not have a createdBy value. createdBy is being set to [" + username + "]");
        entity.setOwnedBy(username);
    }
    entity.setDeleted(false);
}
Also used : IDocumentMedium(nikita.model.noark5.v4.interfaces.IDocumentMedium) Date(java.util.Date)

Example 45 with Fonds

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

the class CorrespondencePartService method deleteCorrespondencePartInternal.

@Override
public void deleteCorrespondencePartInternal(@NotNull String code) {
    CorrespondencePartInternal correspondencePartInternal = (CorrespondencePartInternal) getCorrespondencePartOrThrow(code);
    /*
        // 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();*/
    correspondencePartRepository.delete(correspondencePartInternal);
}
Also used : CorrespondencePartInternal(nikita.model.noark5.v4.casehandling.secondary.CorrespondencePartInternal)

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