Search in sources :

Example 11 with Class

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

the class ClassService method createClassAssociatedWithClass.

public Class createClassAssociatedWithClass(String classSystemId, Class klass) {
    Class persistedClass = null;
    Class parentKlass = classRepository.findBySystemId(classSystemId);
    if (parentKlass == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " Class, using classSystemId " + classSystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    } else if (parentKlass.getFinalisedDate() != null) {
        String info = INFO_CANNOT_ASSOCIATE_WITH_CLOSED_OBJECT + ". Class with classSystemId " + classSystemId + "has been finalised. Cannot associate a new class object with a finalised class object";
        logger.info(info);
        throw new NoarkEntityEditWhenClosedException(info);
    } else {
        klass.setReferenceParentClass(parentKlass);
        persistedClass = this.save(klass);
    }
    return persistedClass;
}
Also used : Class(nikita.common.model.noark5.v4.Class) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException) NoarkEntityEditWhenClosedException(nikita.common.util.exceptions.NoarkEntityEditWhenClosedException)

Example 12 with Class

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

the class ClassService method findClassByOwnerPaginated.

// All READ operations
@Override
public List<Class> findClassByOwnerPaginated(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<Class> criteriaQuery = criteriaBuilder.createQuery(Class.class);
    Root<Class> from = criteriaQuery.from(Class.class);
    CriteriaQuery<Class> select = criteriaQuery.select(from);
    criteriaQuery.where(criteriaBuilder.equal(from.get("ownedBy"), loggedInUser));
    TypedQuery<Class> typedQuery = entityManager.createQuery(select);
    typedQuery.setFirstResult(skip);
    typedQuery.setMaxResults(top);
    return typedQuery.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Class(nikita.common.model.noark5.v4.Class)

Example 13 with Class

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

the class ClassService method getClassOrThrow.

// All HELPER operations
/**
 * Internal helper method. Rather than having a find and try catch in multiple methods, we have it here once.
 * If you call this, be aware that you will only ever get a valid Class back. If there is no valid
 * Class, an exception is thrown
 *
 * @param classSystemId systemId of the class object you are looking for
 * @return the newly found class object or null if it does not exist
 */
protected Class getClassOrThrow(@NotNull String classSystemId) {
    Class klass = classRepository.findBySystemId(classSystemId);
    if (null == klass) {
        String info = INFO_CANNOT_FIND_OBJECT + " Class, using systemId " + classSystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    }
    return klass;
}
Also used : Class(nikita.common.model.noark5.v4.Class) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException)

Example 14 with Class

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

the class ClassificationSystemService method createClassAssociatedWithClassificationSystem.

@Override
public Class createClassAssociatedWithClassificationSystem(String classificationSystemSystemId, Class klass) {
    Class persistedClass = null;
    ClassificationSystem classificationSystem = classificationSystemRepository.findBySystemId(classificationSystemSystemId);
    if (classificationSystem == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " ClassificationSystem, using classificationSystemSystemId " + classificationSystemSystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    } else {
        klass.setReferenceClassificationSystem(classificationSystem);
        persistedClass = classService.save(klass);
    }
    return persistedClass;
}
Also used : ClassificationSystem(nikita.common.model.noark5.v4.ClassificationSystem) Class(nikita.common.model.noark5.v4.Class) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException)

Example 15 with Class

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

the class RecordService method handleUpdate.

// All UPDATE operations
@Override
public Record handleUpdate(@NotNull String systemId, @NotNull Long version, @NotNull Record incomingRecord) {
    Record existingRecord = getRecordOrThrow(systemId);
    // Here copy all the values you are allowed to copy ....
    // TODO: FIND ALL VALUES
    // This might be a class that can only have values set via parameter values rather than request bodies
    existingRecord.setVersion(version);
    recordRepository.save(existingRecord);
    return existingRecord;
}
Also used : Record(nikita.common.model.noark5.v4.Record)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)18 ApiOperation (io.swagger.annotations.ApiOperation)18 ApiResponses (io.swagger.annotations.ApiResponses)18 Class (nikita.model.noark5.v4.Class)17 Class (nikita.common.model.noark5.v4.Class)16 Timed (com.codahale.metrics.annotation.Timed)9 Authorisation (nikita.webapp.security.Authorisation)9 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)9 ClassHateoas (nikita.common.model.noark5.v4.hateoas.ClassHateoas)7 ClassHateoas (nikita.model.noark5.v4.hateoas.ClassHateoas)7 AfterNoarkEntityDeletedEvent (nikita.webapp.web.events.AfterNoarkEntityDeletedEvent)5 AfterNoarkEntityDeletedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityDeletedEvent)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 NikitaException (nikita.common.util.exceptions.NikitaException)4 NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)4 NikitaException (nikita.util.exceptions.NikitaException)4 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)4 Date (java.util.Date)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2