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);
}
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();
}
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;
}
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);
}
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);
}
Aggregations