Search in sources :

Example 6 with ClassificationSystem

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

the class ClassificationSystemService method findClassificationSystemByOwnerPaginated.

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

Example 7 with ClassificationSystem

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

the class ClassificationSystemService method getClassificationSystemOrThrow.

// 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 ClassificationSystem back. If there is no valid
     * ClassificationSystem, an exception is thrown
     *
     * @param classificationSystemSystemId
     * @return
     */
protected ClassificationSystem getClassificationSystemOrThrow(@NotNull String classificationSystemSystemId) {
    ClassificationSystem classificationSystem = classificationSystemRepository.findBySystemIdOrderBySystemId(classificationSystemSystemId);
    if (classificationSystem == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " ClassificationSystem, using systemId " + classificationSystemSystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    }
    return classificationSystem;
}
Also used : ClassificationSystem(nikita.model.noark5.v4.ClassificationSystem) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException)

Example 8 with ClassificationSystem

use of nikita.model.noark5.v4.ClassificationSystem 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.findBySystemIdOrderBySystemId(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.model.noark5.v4.ClassificationSystem) Class(nikita.model.noark5.v4.Class) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException)

Example 9 with ClassificationSystem

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

the class ClassificationSystemService method handleUpdate.

// All UPDATE operations
@Override
public ClassificationSystem handleUpdate(@NotNull String systemId, @NotNull Long version, @NotNull ClassificationSystem incomingClassificationSystem) {
    ClassificationSystem existingClassificationSystem = getClassificationSystemOrThrow(systemId);
    // Copy all the values you are allowed to copy ....
    if (null != incomingClassificationSystem.getDescription()) {
        existingClassificationSystem.setDescription(incomingClassificationSystem.getDescription());
    }
    if (null != incomingClassificationSystem.getTitle()) {
        existingClassificationSystem.setTitle(incomingClassificationSystem.getTitle());
    }
    existingClassificationSystem.setVersion(version);
    classificationSystemRepository.save(existingClassificationSystem);
    return existingClassificationSystem;
}
Also used : ClassificationSystem(nikita.model.noark5.v4.ClassificationSystem)

Example 10 with ClassificationSystem

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

the class ClassHateoasController method deleteClassBySystemId.

// Delete a Class identified by systemID
// DELETE [contextPath][api]/arkivstruktur/dokumentobjekt/{systemId}/
@ApiOperation(value = "Deletes a single Class entity identified by systemID", response = HateoasNoarkObject.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Parent entity (DocumentDescription or Record) returned", response = HateoasNoarkObject.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.DELETE)
public ResponseEntity<HateoasNoarkObject> deleteClassBySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the class to delete", required = true) @PathVariable("systemID") final String systemID) {
    Class klass = classService.findBySystemIdOrderBySystemId(systemID);
    NoarkEntity parentEntity = klass.chooseParent();
    classService.deleteEntity(systemID);
    HateoasNoarkObject hateoasNoarkObject;
    if (parentEntity instanceof Class) {
        hateoasNoarkObject = new ClassHateoas(parentEntity);
        classHateoasHandler.addLinks(hateoasNoarkObject, request, new Authorisation());
    } else if (parentEntity instanceof ClassificationSystem) {
        hateoasNoarkObject = new ClassificationSystemHateoas(parentEntity);
        classificationSystemHateoasHandler.addLinks(hateoasNoarkObject, request, new Authorisation());
    } else {
        throw new NikitaException("Internal error. Could process" + request.getRequestURI());
    }
    applicationEventPublisher.publishEvent(new AfterNoarkEntityDeletedEvent(this, klass));
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(hateoasNoarkObject);
}
Also used : NikitaException(nikita.util.exceptions.NikitaException) ClassificationSystem(nikita.model.noark5.v4.ClassificationSystem) ClassificationSystemHateoas(nikita.model.noark5.v4.hateoas.ClassificationSystemHateoas) NoarkEntity(nikita.model.noark5.v4.NoarkEntity) ClassHateoas(nikita.model.noark5.v4.hateoas.ClassHateoas) HateoasNoarkObject(nikita.model.noark5.v4.hateoas.HateoasNoarkObject) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) Class(nikita.model.noark5.v4.Class) AfterNoarkEntityDeletedEvent(no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityDeletedEvent) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ClassificationSystem (nikita.model.noark5.v4.ClassificationSystem)11 Counted (com.codahale.metrics.annotation.Counted)7 Timed (com.codahale.metrics.annotation.Timed)7 ApiOperation (io.swagger.annotations.ApiOperation)7 ApiResponses (io.swagger.annotations.ApiResponses)7 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)7 ClassificationSystemHateoas (nikita.model.noark5.v4.hateoas.ClassificationSystemHateoas)5 Class (nikita.model.noark5.v4.Class)4 ClassHateoas (nikita.model.noark5.v4.hateoas.ClassHateoas)3 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)3 AfterNoarkEntityCreatedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityCreatedEvent)3 AfterNoarkEntityDeletedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityDeletedEvent)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ArrayList (java.util.ArrayList)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 NoarkEntity (nikita.model.noark5.v4.NoarkEntity)1 HateoasNoarkObject (nikita.model.noark5.v4.hateoas.HateoasNoarkObject)1 INikitaEntity (nikita.model.noark5.v4.interfaces.entities.INikitaEntity)1 NikitaException (nikita.util.exceptions.NikitaException)1 NikitaMalformedInputDataException (nikita.util.exceptions.NikitaMalformedInputDataException)1