Search in sources :

Example 6 with Class

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

the class ClassService method updateClassSetFinalized.

public Class updateClassSetFinalized(Long id) {
    Class klass = classRepository.findById(id);
    if (klass == null) {
    // TODO throw Object not find
    }
    String username = SecurityContextHolder.getContext().getAuthentication().getName();
    klass.setFinalisedDate(new Date());
    klass.setFinalisedBy(username);
    return classRepository.save(klass);
}
Also used : Class(nikita.model.noark5.v4.Class) Date(java.util.Date)

Example 7 with Class

use of nikita.common.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(maxPageSize);
    return typedQuery.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Class(nikita.model.noark5.v4.Class)

Example 8 with Class

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

Example 9 with Class

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

the class ClassService method deleteEntity.

// All DELETE operations
@Override
public void deleteEntity(@NotNull String classSystemId) {
    Class klass = getClassOrThrow(classSystemId);
    classRepository.delete(klass);
}
Also used : Class(nikita.model.noark5.v4.Class)

Example 10 with Class

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

the class ClassificationSystemHateoasController method createClassAssociatedWithClassificationSystem.

@ApiOperation(value = "Persists a Class object associated with the given ClassificationSystem systemId", notes = "Returns the newly created class object after it was associated with a classificationSystem " + "object and persisted to the database", response = ClassHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Class " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = Class.class), @ApiResponse(code = 201, message = "Class " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = Class.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 404, message = API_MESSAGE_PARENT_DOES_NOT_EXIST + " of type Class"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@RequestMapping(method = RequestMethod.POST, value = CLASSIFICATION_SYSTEM + SLASH + LEFT_PARENTHESIS + "classificationSystemSystemId" + RIGHT_PARENTHESIS + SLASH + NEW_RECORD, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<ClassHateoas> createClassAssociatedWithClassificationSystem(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "classificationSystemSystemId", value = "systemId of classificationSystem to associate the klass with.", required = true) @PathVariable String classificationSystemSystemId, @ApiParam(name = "klass", value = "Incoming class object", required = true) @RequestBody Class klass) throws NikitaException {
    Class createdClass = classificationSystemService.createClassAssociatedWithClassificationSystem(classificationSystemSystemId, klass);
    ClassHateoas classHateoas = new ClassHateoas(createdClass);
    classHateoasHandler.addLinks(classHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityCreatedEvent(this, createdClass));
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(createdClass.getVersion().toString()).body(classHateoas);
}
Also used : ClassHateoas(nikita.common.model.noark5.v4.hateoas.ClassHateoas) AfterNoarkEntityCreatedEvent(nikita.webapp.web.events.AfterNoarkEntityCreatedEvent) Authorisation(nikita.webapp.security.Authorisation) Class(nikita.common.model.noark5.v4.Class) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

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