From da1a068a3a774151f7f9cfcf9e98ba02e9dc2c78 Mon Sep 17 00:00:00 2001 From: dseurotech Date: Fri, 12 Apr 2024 09:26:23 +0200 Subject: [PATCH] :heavy_minus_sign: removing the checker framework as it was not activated anyway, and if activated it failed compilation without any debug information Signed-off-by: dseurotech --- commons/pom.xml | 4 - .../commons/jpa/KapuaEntityJpaRepository.java | 324 +++++------ .../commons/service/internal/ServiceDAO.java | 517 ++++++++++-------- pom.xml | 20 +- .../access/shiro/GroupQueryHelperImpl.java | 15 +- 5 files changed, 470 insertions(+), 410 deletions(-) diff --git a/commons/pom.xml b/commons/pom.xml index c230fca499d..a4fbe973a8e 100644 --- a/commons/pom.xml +++ b/commons/pom.xml @@ -149,10 +149,6 @@ org.reflections reflections - - org.checkerframework - checker-qual - org.hibernate hibernate-jpamodelgen diff --git a/commons/src/main/java/org/eclipse/kapua/commons/jpa/KapuaEntityJpaRepository.java b/commons/src/main/java/org/eclipse/kapua/commons/jpa/KapuaEntityJpaRepository.java index 67dda80e4e6..8ce113e4654 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/jpa/KapuaEntityJpaRepository.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/jpa/KapuaEntityJpaRepository.java @@ -12,9 +12,35 @@ *******************************************************************************/ package org.eclipse.kapua.commons.jpa; -import com.google.common.base.MoreObjects; +import java.sql.SQLException; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; + +import javax.persistence.Embedded; +import javax.persistence.EntityExistsException; +import javax.persistence.EntityManager; +import javax.persistence.LockModeType; +import javax.persistence.NonUniqueResultException; +import javax.persistence.PersistenceException; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Expression; +import javax.persistence.criteria.JoinType; +import javax.persistence.criteria.Order; +import javax.persistence.criteria.ParameterExpression; +import javax.persistence.criteria.Path; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; +import javax.persistence.metamodel.Attribute; +import javax.persistence.metamodel.EntityType; + import org.apache.commons.lang.ArrayUtils; -import org.checkerframework.checker.nullness.qual.NonNull; import org.eclipse.kapua.KapuaEntityExistsException; import org.eclipse.kapua.KapuaEntityNotFoundException; import org.eclipse.kapua.KapuaErrorCodes; @@ -39,34 +65,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.persistence.Embedded; -import javax.persistence.EntityExistsException; -import javax.persistence.EntityManager; -import javax.persistence.LockModeType; -import javax.persistence.NonUniqueResultException; -import javax.persistence.PersistenceException; -import javax.persistence.TypedQuery; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Expression; -import javax.persistence.criteria.JoinType; -import javax.persistence.criteria.Order; -import javax.persistence.criteria.ParameterExpression; -import javax.persistence.criteria.Path; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; -import javax.persistence.metamodel.Attribute; -import javax.persistence.metamodel.EntityType; -import java.sql.SQLException; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.function.Supplier; +import com.google.common.base.MoreObjects; public class KapuaEntityJpaRepository> implements KapuaEntityRepository { + protected final Class concreteClass; protected final String entityName; protected final Supplier listSupplier; @@ -78,10 +80,13 @@ public class KapuaEntityJpaRepository concreteClass, @@ -328,19 +333,25 @@ protected E doDelete(EntityManager em, E entityToDelete) { *

* It can be invoked recursively (i.e. to handle {@link AttributePredicate}s of the {@link AndPredicate}. * - * @param queryPredicate The {@link QueryPredicate} to handle. - * @param binds The {@link Map}≶{@link String}, {@link Object}> of the query values. - * @param cb The JPA {@link CriteriaBuilder} of the {@link javax.persistence.Query}. - * @param userPermissionRoot The JPA {@link Root} of the {@link javax.persistence.Query}. - * @param entityType The JPA {@link EntityType} of the {@link javax.persistence.Query}. + * @param queryPredicate + * The {@link QueryPredicate} to handle. + * @param binds + * The {@link Map}≶{@link String}, {@link Object}> of the query values. + * @param cb + * The JPA {@link CriteriaBuilder} of the {@link javax.persistence.Query}. + * @param userPermissionRoot + * The JPA {@link Root} of the {@link javax.persistence.Query}. + * @param entityType + * The JPA {@link EntityType} of the {@link javax.persistence.Query}. * @return The handled {@link Predicate} - * @throws KapuaException If any problem occurs. + * @throws KapuaException + * If any problem occurs. */ - private Predicate handleKapuaQueryPredicates(@NonNull QueryPredicate queryPredicate, - @NonNull Map binds, - @NonNull CriteriaBuilder cb, - @NonNull Root userPermissionRoot, - @NonNull EntityType entityType) + private Predicate handleKapuaQueryPredicates(QueryPredicate queryPredicate, + Map binds, + CriteriaBuilder cb, + Root userPermissionRoot, + EntityType entityType) throws KapuaException { Predicate predicate = null; if (queryPredicate instanceof AttributePredicate) { @@ -363,11 +374,11 @@ private Predicate handleKapuaQueryPredicates(@NonNull QueryPredicate queryPr return predicate; } - private Predicate handleAndPredicate(@NonNull AndPredicate andPredicate, - @NonNull Map binds, - @NonNull CriteriaBuilder cb, - @NonNull Root entityRoot, - @NonNull EntityType entityType) + private Predicate handleAndPredicate(AndPredicate andPredicate, + Map binds, + CriteriaBuilder cb, + Root entityRoot, + EntityType entityType) throws KapuaException { Predicate[] jpaAndPredicates = @@ -382,11 +393,11 @@ private Predicate handleAndPredicate(@NonNull AndPredicate andPredicate, } - private Predicate handleOrPredicate(@NonNull OrPredicate orPredicate, - @NonNull Map binds, - @NonNull CriteriaBuilder cb, - @NonNull Root entityRoot, - @NonNull EntityType entityType) + private Predicate handleOrPredicate(OrPredicate orPredicate, + Map binds, + CriteriaBuilder cb, + Root entityRoot, + EntityType entityType) throws KapuaException { Predicate[] jpaOrPredicates = @@ -400,11 +411,11 @@ private Predicate handleOrPredicate(@NonNull OrPredicate orPredicate, return cb.or(jpaOrPredicates); } - private Predicate[] handlePredicate(@NonNull List orPredicates, - @NonNull Map binds, - @NonNull CriteriaBuilder cb, - @NonNull Root entityRoot, - @NonNull EntityType entityType) throws KapuaException { + private Predicate[] handlePredicate(List orPredicates, + Map binds, + CriteriaBuilder cb, + Root entityRoot, + EntityType entityType) throws KapuaException { Predicate[] jpaOrPredicates = new Predicate[orPredicates.size()]; for (int i = 0; i < orPredicates.size(); i++) { @@ -414,11 +425,11 @@ private Predicate[] handlePredicate(@NonNull List orPredicat return jpaOrPredicates; } - private Predicate handleAttributePredicate(@NonNull AttributePredicate attrPred, - @NonNull Map binds, - @NonNull CriteriaBuilder cb, - @NonNull Root entityRoot, - @NonNull EntityType entityType) + private Predicate handleAttributePredicate(AttributePredicate attrPred, + Map binds, + CriteriaBuilder cb, + Root entityRoot, + EntityType entityType) throws KapuaException { Predicate expr; String attrName = attrPred.getAttributeName(); @@ -468,84 +479,84 @@ private Predicate handleAttributePredicate(@NonNull AttributePredicate at .replace(configuration.any, configuration.escape + configuration.any)) .orElse(null); switch (attrPred.getOperator()) { - case LIKE: - ParameterExpression pl = cb.parameter(String.class); - binds.put(pl, configuration.like + escapedAttributeValue + configuration.like); - expr = cb.like(extractAttribute(entityRoot, attrName), pl); - break; - - case LIKE_IGNORE_CASE: - ParameterExpression plci = cb.parameter(String.class); - binds.put(plci, configuration.like + escapedAttributeValue.toLowerCase() + configuration.like); - expr = cb.like(cb.lower(extractAttribute(entityRoot, attrName)), plci); - break; - - case STARTS_WITH: - ParameterExpression psw = cb.parameter(String.class); - binds.put(psw, escapedAttributeValue + configuration.like); - expr = cb.like(extractAttribute(entityRoot, attrName), psw); - break; - - case STARTS_WITH_IGNORE_CASE: - ParameterExpression pswci = cb.parameter(String.class); - binds.put(pswci, escapedAttributeValue.toLowerCase() + configuration.like); - expr = cb.like(cb.lower(extractAttribute(entityRoot, attrName)), pswci); - break; - - case IS_NULL: - expr = cb.isNull(extractAttribute(entityRoot, attrName)); - break; - - case NOT_NULL: - expr = cb.isNotNull(extractAttribute(entityRoot, attrName)); - break; - - case NOT_EQUAL: - expr = cb.notEqual(extractAttribute(entityRoot, attrName), attributeValue); - break; - - case GREATER_THAN: - if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { - Comparable comparableAttrValue = (Comparable) attributeValue; - Expression comparableExpression = extractAttribute(entityRoot, attrName); - expr = cb.greaterThan(comparableExpression, comparableAttrValue); - } else { - throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); - } - break; - - case GREATER_THAN_OR_EQUAL: - if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { - Expression comparableExpression = extractAttribute(entityRoot, attrName); - Comparable comparableAttrValue = (Comparable) attributeValue; - expr = cb.greaterThanOrEqualTo(comparableExpression, comparableAttrValue); - } else { - throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); - } - break; - - case LESS_THAN: - if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { - Expression comparableExpression = extractAttribute(entityRoot, attrName); - Comparable comparableAttrValue = (Comparable) attributeValue; - expr = cb.lessThan(comparableExpression, comparableAttrValue); - } else { - throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); - } - break; - case LESS_THAN_OR_EQUAL: - if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { - Expression comparableExpression = extractAttribute(entityRoot, attrName); - Comparable comparableAttrValue = (Comparable) attributeValue; - expr = cb.lessThanOrEqualTo(comparableExpression, comparableAttrValue); - } else { - throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); - } - break; - - case EQUAL: - default: - expr = cb.equal(extractAttribute(entityRoot, attrName), attributeValue); + case LIKE: + ParameterExpression pl = cb.parameter(String.class); + binds.put(pl, configuration.like + escapedAttributeValue + configuration.like); + expr = cb.like(extractAttribute(entityRoot, attrName), pl); + break; + + case LIKE_IGNORE_CASE: + ParameterExpression plci = cb.parameter(String.class); + binds.put(plci, configuration.like + escapedAttributeValue.toLowerCase() + configuration.like); + expr = cb.like(cb.lower(extractAttribute(entityRoot, attrName)), plci); + break; + + case STARTS_WITH: + ParameterExpression psw = cb.parameter(String.class); + binds.put(psw, escapedAttributeValue + configuration.like); + expr = cb.like(extractAttribute(entityRoot, attrName), psw); + break; + + case STARTS_WITH_IGNORE_CASE: + ParameterExpression pswci = cb.parameter(String.class); + binds.put(pswci, escapedAttributeValue.toLowerCase() + configuration.like); + expr = cb.like(cb.lower(extractAttribute(entityRoot, attrName)), pswci); + break; + + case IS_NULL: + expr = cb.isNull(extractAttribute(entityRoot, attrName)); + break; + + case NOT_NULL: + expr = cb.isNotNull(extractAttribute(entityRoot, attrName)); + break; + + case NOT_EQUAL: + expr = cb.notEqual(extractAttribute(entityRoot, attrName), attributeValue); + break; + + case GREATER_THAN: + if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { + Comparable comparableAttrValue = (Comparable) attributeValue; + Expression comparableExpression = extractAttribute(entityRoot, attrName); + expr = cb.greaterThan(comparableExpression, comparableAttrValue); + } else { + throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); + } + break; + + case GREATER_THAN_OR_EQUAL: + if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { + Expression comparableExpression = extractAttribute(entityRoot, attrName); + Comparable comparableAttrValue = (Comparable) attributeValue; + expr = cb.greaterThanOrEqualTo(comparableExpression, comparableAttrValue); + } else { + throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); + } + break; + + case LESS_THAN: + if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { + Expression comparableExpression = extractAttribute(entityRoot, attrName); + Comparable comparableAttrValue = (Comparable) attributeValue; + expr = cb.lessThan(comparableExpression, comparableAttrValue); + } else { + throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); + } + break; + case LESS_THAN_OR_EQUAL: + if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { + Expression comparableExpression = extractAttribute(entityRoot, attrName); + Comparable comparableAttrValue = (Comparable) attributeValue; + expr = cb.lessThanOrEqualTo(comparableExpression, comparableAttrValue); + } else { + throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); + } + break; + + case EQUAL: + default: + expr = cb.equal(extractAttribute(entityRoot, attrName), attributeValue); } } return expr; @@ -558,12 +569,14 @@ private Predicate handleAttributePredicate(@NonNull AttributePredicate at *

* Filter predicates takes advantage of the dot notation to access {@link Embedded} attributes and nested {@link KapuaEntity}es. * - * @param entityRoot The {@link Root} entity from which extract the attribute. - * @param attributeName The full attribute name. + * @param entityRoot + * The {@link Root} entity from which extract the attribute. + * @param attributeName + * The full attribute name. * @return The {@link Path} expression that matches the given {@code attributeName} parameter. * @since 1.0.0 */ - private Path

extractAttribute(@NonNull Root entityRoot, @NonNull String attributeName) { + private Path

extractAttribute(Root entityRoot, String attributeName) { Path

expressionPath; if (attributeName.contains(ATTRIBUTE_SEPARATOR)) { String[] pathComponents = attributeName.split(ATTRIBUTE_SEPARATOR_ESCAPED); @@ -582,11 +595,12 @@ private Path

extractAttribute(@NonNull Root entityRoot, @NonNull St /** * Check if the given {@link PersistenceException} is a SQL constraint violation error. * - * @param persistenceException {@link PersistenceException} to check. + * @param persistenceException + * {@link PersistenceException} to check. * @return {@code true} if it is a constraint validation error, {@code false} otherwise. * @since 1.0.0 */ - public static boolean isInsertConstraintViolation(@NonNull PersistenceException persistenceException) { + public static boolean isInsertConstraintViolation(PersistenceException persistenceException) { Throwable cause = persistenceException.getCause(); while (cause != null && !(cause instanceof SQLException)) { cause = cause.getCause(); @@ -600,18 +614,18 @@ public static boolean isInsertConstraintViolation(@NonNull PersistenceException return SQL_ERROR_CODE_CONSTRAINT_VIOLATION.equals(innerExc.getSQLState()); } - protected Optional doFindByField(@NonNull TxContext txContext, - @NonNull KapuaId scopeId, - @NonNull String fieldName, - @NonNull Object fieldValue) { + protected Optional doFindByField(TxContext txContext, + KapuaId scopeId, + String fieldName, + Object fieldValue) { final List result = doFindAllByField(txContext, scopeId, fieldName, fieldValue); switch (result.size()) { - case 0: - return Optional.empty(); - case 1: - return Optional.of(result.get(0)); - default: - throw new NonUniqueResultException(String.format("Multiple %s results found for field %s with value %s", concreteClass.getName(), fieldName, fieldValue.toString())); + case 0: + return Optional.empty(); + case 1: + return Optional.of(result.get(0)); + default: + throw new NonUniqueResultException(String.format("Multiple %s results found for field %s with value %s", concreteClass.getName(), fieldName, fieldValue.toString())); } } diff --git a/commons/src/main/java/org/eclipse/kapua/commons/service/internal/ServiceDAO.java b/commons/src/main/java/org/eclipse/kapua/commons/service/internal/ServiceDAO.java index e3febf8c3da..7fe552ae58d 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/service/internal/ServiceDAO.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/service/internal/ServiceDAO.java @@ -12,9 +12,33 @@ *******************************************************************************/ package org.eclipse.kapua.commons.service.internal; -import com.google.common.base.MoreObjects; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.persistence.Embedded; +import javax.persistence.EntityExistsException; +import javax.persistence.NonUniqueResultException; +import javax.persistence.PersistenceException; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Expression; +import javax.persistence.criteria.JoinType; +import javax.persistence.criteria.Order; +import javax.persistence.criteria.ParameterExpression; +import javax.persistence.criteria.Path; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; +import javax.persistence.metamodel.Attribute; +import javax.persistence.metamodel.EntityType; +import javax.validation.constraints.Null; + import org.apache.commons.lang.ArrayUtils; -import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.eclipse.kapua.KapuaEntityExistsException; import org.eclipse.kapua.KapuaEntityNotFoundException; @@ -69,30 +93,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.persistence.Embedded; -import javax.persistence.EntityExistsException; -import javax.persistence.NonUniqueResultException; -import javax.persistence.PersistenceException; -import javax.persistence.TypedQuery; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Expression; -import javax.persistence.criteria.JoinType; -import javax.persistence.criteria.Order; -import javax.persistence.criteria.ParameterExpression; -import javax.persistence.criteria.Path; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; -import javax.persistence.metamodel.Attribute; -import javax.persistence.metamodel.EntityType; -import javax.validation.constraints.Null; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import com.google.common.base.MoreObjects; /** * {@link ServiceDAO} utility methods. @@ -169,12 +170,14 @@ protected ServiceDAO() { *

* This method checks for the constraint violation and, in this case, it throws a specific exception ({@link KapuaEntityExistsException}). * - * @param em The {@link EntityManager} that holds the transaction. - * @param entity The {@link KapuaEntity} to be persisted. + * @param em + * The {@link EntityManager} that holds the transaction. + * @param entity + * The {@link KapuaEntity} to be persisted. * @return The persisted {@link KapuaEntity}. * @since 1.0.0 */ - public static E create(@NonNull EntityManager em, @NonNull E entity) { + public static E create(EntityManager em, E entity) { try { em.persist(entity); em.flush(); @@ -199,14 +202,18 @@ public static E create(@NonNull EntityManager em, @NonNu /** * Updates the {@link KapuaUpdatableEntity}. * - * @param em The {@link EntityManager} that holds the transaction. - * @param clazz The {@link KapuaUpdatableEntity} class. This must be the implementing {@code class}. - * @param entity The {@link KapuaUpdatableEntity} to be updated. + * @param em + * The {@link EntityManager} that holds the transaction. + * @param clazz + * The {@link KapuaUpdatableEntity} class. This must be the implementing {@code class}. + * @param entity + * The {@link KapuaUpdatableEntity} to be updated. * @return The updated {@link KapuaUpdatableEntity}. - * @throws KapuaEntityNotFoundException If the {@link KapuaEntity} does not exist. + * @throws KapuaEntityNotFoundException + * If the {@link KapuaEntity} does not exist. * @since 1.0.0 */ - public static E update(@NonNull EntityManager em, @NonNull Class clazz, @NonNull E entity) throws KapuaEntityNotFoundException { + public static E update(EntityManager em, Class clazz, E entity) throws KapuaEntityNotFoundException { // // Checking existence E entityToUpdate = em.find(clazz, entity.getId()); @@ -231,13 +238,17 @@ public static E update(@NonNull EntityManager e /** * Finds a {@link KapuaEntity}. * - * @param em The {@link EntityManager} that holds the transaction. - * @param clazz The {@link KapuaEntity} class. This must be the implementing {@code class}. - * @param scopeId The {@link KapuaEntity#getScopeId()} the entity to be found. - * @param entityId The {@link KapuaEntity#getId()} of the entity to be found. + * @param em + * The {@link EntityManager} that holds the transaction. + * @param clazz + * The {@link KapuaEntity} class. This must be the implementing {@code class}. + * @param scopeId + * The {@link KapuaEntity#getScopeId()} the entity to be found. + * @param entityId + * The {@link KapuaEntity#getId()} of the entity to be found. * @since 1.0.0 */ - public static E find(@NonNull EntityManager em, @NonNull Class clazz, @Null KapuaId scopeId, @NonNull KapuaId entityId) { + public static E find(EntityManager em, Class clazz, @Null KapuaId scopeId, KapuaId entityId) { // // Checking existence E entityToFind = em.find(clazz, entityId); @@ -263,76 +274,96 @@ public static E find(@NonNull EntityManager em, @NonNull /** * Finds a {@link KapuaNamedEntity} by {@link KapuaNamedEntity#getName()}. * - * @param em The {@link EntityManager} that holds the transaction. - * @param clazz The {@link KapuaNamedEntity} class. This must be the implementing {@code class}. - * @param value The value of the {@link KapuaNamedEntity#getName()} to search. + * @param em + * The {@link EntityManager} that holds the transaction. + * @param clazz + * The {@link KapuaNamedEntity} class. This must be the implementing {@code class}. + * @param value + * The value of the {@link KapuaNamedEntity#getName()} to search. * @return The {@link KapuaNamedEntity} found, or {@code null} if not found. - * @throws NonUniqueResultException When more than one result is returned + * @throws NonUniqueResultException + * When more than one result is returned * @since 2.0.0 */ @Nullable - public static E findByName(@NonNull EntityManager em, - @NonNull Class clazz, - @NonNull Object value) { + public static E findByName(EntityManager em, + Class clazz, + Object value) { return findByName(em, clazz, KapuaId.ANY, value); } /** * Finds a {@link KapuaNamedEntity} by {@link KapuaNamedEntity#getName()}. * - * @param em The {@link EntityManager} that holds the transaction. - * @param clazz The {@link KapuaNamedEntity} class. This must be the implementing {@code class}. - * @param scopeId The {@link KapuaNamedEntity#getScopeId()} in which to look for results. - * @param value The value of the field from which to search. + * @param em + * The {@link EntityManager} that holds the transaction. + * @param clazz + * The {@link KapuaNamedEntity} class. This must be the implementing {@code class}. + * @param scopeId + * The {@link KapuaNamedEntity#getScopeId()} in which to look for results. + * @param value + * The value of the field from which to search. * @return The {@link KapuaNamedEntity} found, or {@code null} if not found. - * @throws NonUniqueResultException When more than one result is returned. + * @throws NonUniqueResultException + * When more than one result is returned. * @since 1.0.0 */ @Nullable - public static E findByName(@NonNull EntityManager em, - @NonNull Class clazz, - @NonNull KapuaId scopeId, - @NonNull Object value) { + public static E findByName(EntityManager em, + Class clazz, + KapuaId scopeId, + Object value) { return findByField(em, clazz, scopeId, KapuaNamedEntityAttributes.NAME, value); } /** * Find a {@link KapuaEntity} by one of its fields. * - * @param em The {@link EntityManager} that holds the transaction. - * @param clazz The {@link KapuaEntity} class. This must be the implementing {@code class}. - * @param name The {@link KapuaEntity} name of the field from which to search. - * @param value The value of the field from which to search. + * @param em + * The {@link EntityManager} that holds the transaction. + * @param clazz + * The {@link KapuaEntity} class. This must be the implementing {@code class}. + * @param name + * The {@link KapuaEntity} name of the field from which to search. + * @param value + * The value of the field from which to search. * @return The {@link KapuaEntity} found, or {@code null} if not found. - * @throws NonUniqueResultException When more than one result is returned. + * @throws NonUniqueResultException + * When more than one result is returned. * @since 1.0.0 */ @Nullable - public static E findByField(@NonNull EntityManager em, - @NonNull Class clazz, - @NonNull String name, - @NonNull Object value) { + public static E findByField(EntityManager em, + Class clazz, + String name, + Object value) { return findByField(em, clazz, KapuaId.ANY, name, value); } /** * Find a {@link KapuaEntity} by one of its fields. * - * @param em The {@link EntityManager} that holds the transaction. - * @param clazz The {@link KapuaEntity} class. This must be the implementing {@code class}. - * @param scopeId The {@link KapuaEntity#getScopeId()} in which to look for results. - * @param name The {@link KapuaEntity} name of the field from which to search. - * @param value The value of the field from which to search. + * @param em + * The {@link EntityManager} that holds the transaction. + * @param clazz + * The {@link KapuaEntity} class. This must be the implementing {@code class}. + * @param scopeId + * The {@link KapuaEntity#getScopeId()} in which to look for results. + * @param name + * The {@link KapuaEntity} name of the field from which to search. + * @param value + * The value of the field from which to search. * @return The {@link KapuaEntity} found, or {@code null} if not found. - * @throws NonUniqueResultException When more than one result is returned. + * @throws NonUniqueResultException + * When more than one result is returned. * @since 1.0.0 */ @Nullable - public static E findByField(@NonNull EntityManager em, - @NonNull Class clazz, - @NonNull KapuaId scopeId, - @NonNull String name, - @NonNull Object value) { + public static E findByField(EntityManager em, + Class clazz, + KapuaId scopeId, + String name, + Object value) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery criteriaSelectQuery = cb.createQuery(clazz); @@ -371,32 +402,38 @@ public static E findByField(@NonNull EntityManager em, // QUERY! List result = query.getResultList(); switch (result.size()) { - case 0: - return null; - case 1: - return result.get(0); - default: - throw new NonUniqueResultException(String.format("Multiple %s results found for field %s with value %s", clazz.getName(), pName, value.toString())); + case 0: + return null; + case 1: + return result.get(0); + default: + throw new NonUniqueResultException(String.format("Multiple %s results found for field %s with value %s", clazz.getName(), pName, value.toString())); } } /** * Queries the {@link KapuaEntity}es. * - * @param em The {@link EntityManager} that holds the transaction. - * @param interfaceClass {@link KapuaQuery} result entity interface class - * @param implementingClass {@link KapuaQuery} result entity implementation class - * @param resultContainer The {@link KapuaListResult} in which load the result. It must be empty. - * @param kapuaQuery The {@link KapuaQuery} to perform. + * @param em + * The {@link EntityManager} that holds the transaction. + * @param interfaceClass + * {@link KapuaQuery} result entity interface class + * @param implementingClass + * {@link KapuaQuery} result entity implementation class + * @param resultContainer + * The {@link KapuaListResult} in which load the result. It must be empty. + * @param kapuaQuery + * The {@link KapuaQuery} to perform. * @return The reference of the {@code resultContainer} parameter. Results are added to the given {@code resultContainer} parameter. - * @throws KapuaException If filter predicates in the {@link KapuaQuery} are incorrect. See {@link #handleKapuaQueryPredicates(QueryPredicate, Map, CriteriaBuilder, Root, EntityType)}. + * @throws KapuaException + * If filter predicates in the {@link KapuaQuery} are incorrect. See {@link #handleKapuaQueryPredicates(QueryPredicate, Map, CriteriaBuilder, Root, EntityType)}. * @since 1.0.0 */ - public static > L query(@NonNull EntityManager em, - @NonNull Class interfaceClass, - @NonNull Class implementingClass, - @NonNull L resultContainer, - @NonNull KapuaQuery kapuaQuery) + public static > L query(EntityManager em, + Class interfaceClass, + Class implementingClass, + L resultContainer, + KapuaQuery kapuaQuery) throws KapuaException { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery criteriaSelectQuery = cb.createQuery(implementingClass); @@ -506,18 +543,23 @@ public static > /** * Counts the {@link KapuaEntity}es. * - * @param em The {@link EntityManager} that holds the transaction. - * @param interfaceClass {@link KapuaQuery} result entity interface class - * @param implementingClass {@link KapuaQuery} result entity implementation class - * @param kapuaQuery The {@link KapuaQuery} to perform. + * @param em + * The {@link EntityManager} that holds the transaction. + * @param interfaceClass + * {@link KapuaQuery} result entity interface class + * @param implementingClass + * {@link KapuaQuery} result entity implementation class + * @param kapuaQuery + * The {@link KapuaQuery} to perform. * @return The number of {@link KapuaEntity}es that matched the filter predicates. - * @throws KapuaException If filter predicates in the {@link KapuaQuery} are incorrect. See {@link #handleKapuaQueryPredicates(QueryPredicate, Map, CriteriaBuilder, Root, EntityType)}. + * @throws KapuaException + * If filter predicates in the {@link KapuaQuery} are incorrect. See {@link #handleKapuaQueryPredicates(QueryPredicate, Map, CriteriaBuilder, Root, EntityType)}. * @since 1.0.0 */ - public static long count(@NonNull EntityManager em, - @NonNull Class interfaceClass, - @NonNull Class implementingClass, - @NonNull KapuaQuery kapuaQuery) + public static long count(EntityManager em, + Class interfaceClass, + Class implementingClass, + KapuaQuery kapuaQuery) throws KapuaException { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery criteriaSelectQuery = cb.createQuery(Long.class); @@ -573,15 +615,20 @@ public static long count(@NonNull EntityMan /** * Deletes a {@link KapuaEntity}. * - * @param em The {@link EntityManager} that holds the transaction. - * @param clazz The {@link KapuaEntity} class. This must be the implementing {@code class}. - * @param scopeId The {@link KapuaEntity#getScopeId()} of the entity to be deleted. - * @param entityId The {@link KapuaEntity#getId()} of the entity to be deleted. + * @param em + * The {@link EntityManager} that holds the transaction. + * @param clazz + * The {@link KapuaEntity} class. This must be the implementing {@code class}. + * @param scopeId + * The {@link KapuaEntity#getScopeId()} of the entity to be deleted. + * @param entityId + * The {@link KapuaEntity#getId()} of the entity to be deleted. * @return The deleted {@link KapuaEntity}. - * @throws KapuaEntityNotFoundException If the {@link KapuaEntity} does not exists. + * @throws KapuaEntityNotFoundException + * If the {@link KapuaEntity} does not exists. * @since 1.0.0 */ - public static E delete(@NonNull EntityManager em, @NonNull Class clazz, @NonNull KapuaId scopeId, @NonNull KapuaId entityId) + public static E delete(EntityManager em, Class clazz, KapuaId scopeId, KapuaId entityId) throws KapuaEntityNotFoundException { // // Checking existence @@ -617,19 +664,25 @@ public static E delete(@NonNull EntityManager em, @NonNu *

* It can be invoked recursively (i.e. to handle {@link AttributePredicate}s of the {@link AndPredicate}. * - * @param queryPredicate The {@link QueryPredicate} to handle. - * @param binds The {@link Map}≶{@link String}, {@link Object}> of the query values. - * @param cb The JPA {@link CriteriaBuilder} of the {@link javax.persistence.Query}. - * @param userPermissionRoot The JPA {@link Root} of the {@link javax.persistence.Query}. - * @param entityType The JPA {@link EntityType} of the {@link javax.persistence.Query}. + * @param queryPredicate + * The {@link QueryPredicate} to handle. + * @param binds + * The {@link Map}≶{@link String}, {@link Object}> of the query values. + * @param cb + * The JPA {@link CriteriaBuilder} of the {@link javax.persistence.Query}. + * @param userPermissionRoot + * The JPA {@link Root} of the {@link javax.persistence.Query}. + * @param entityType + * The JPA {@link EntityType} of the {@link javax.persistence.Query}. * @return The handled {@link Predicate} - * @throws KapuaException If any problem occurs. + * @throws KapuaException + * If any problem occurs. */ - private static Predicate handleKapuaQueryPredicates(@NonNull QueryPredicate queryPredicate, - @NonNull Map binds, - @NonNull CriteriaBuilder cb, - @NonNull Root userPermissionRoot, - @NonNull EntityType entityType) + private static Predicate handleKapuaQueryPredicates(QueryPredicate queryPredicate, + Map binds, + CriteriaBuilder cb, + Root userPermissionRoot, + EntityType entityType) throws KapuaException { Predicate predicate = null; if (queryPredicate instanceof AttributePredicate) { @@ -652,11 +705,11 @@ private static Predicate handleKapuaQueryPredicates(@NonNull QueryPredicate return predicate; } - private static Predicate handleAndPredicate(@NonNull AndPredicate andPredicate, - @NonNull Map binds, - @NonNull CriteriaBuilder cb, - @NonNull Root entityRoot, - @NonNull EntityType entityType) + private static Predicate handleAndPredicate(AndPredicate andPredicate, + Map binds, + CriteriaBuilder cb, + Root entityRoot, + EntityType entityType) throws KapuaException { Predicate[] jpaAndPredicates = @@ -671,11 +724,11 @@ private static Predicate handleAndPredicate(@NonNull AndPredicate andPredica } - private static Predicate handleOrPredicate(@NonNull OrPredicate orPredicate, - @NonNull Map binds, - @NonNull CriteriaBuilder cb, - @NonNull Root entityRoot, - @NonNull EntityType entityType) + private static Predicate handleOrPredicate(OrPredicate orPredicate, + Map binds, + CriteriaBuilder cb, + Root entityRoot, + EntityType entityType) throws KapuaException { Predicate[] jpaOrPredicates = @@ -689,11 +742,11 @@ private static Predicate handleOrPredicate(@NonNull OrPredicate orPredicate, return cb.or(jpaOrPredicates); } - private static Predicate[] handlePredicate(@NonNull List orPredicates, - @NonNull Map binds, - @NonNull CriteriaBuilder cb, - @NonNull Root entityRoot, - @NonNull EntityType entityType) throws KapuaException { + private static Predicate[] handlePredicate(List orPredicates, + Map binds, + CriteriaBuilder cb, + Root entityRoot, + EntityType entityType) throws KapuaException { Predicate[] jpaOrPredicates = new Predicate[orPredicates.size()]; for (int i = 0; i < orPredicates.size(); i++) { @@ -703,11 +756,11 @@ private static Predicate[] handlePredicate(@NonNull List orP return jpaOrPredicates; } - private static Predicate handleAttributePredicate(@NonNull AttributePredicate attrPred, - @NonNull Map binds, - @NonNull CriteriaBuilder cb, - @NonNull Root entityRoot, - @NonNull EntityType entityType) + private static Predicate handleAttributePredicate(AttributePredicate attrPred, + Map binds, + CriteriaBuilder cb, + Root entityRoot, + EntityType entityType) throws KapuaException { Predicate expr; String attrName = attrPred.getAttributeName(); @@ -753,88 +806,88 @@ private static Predicate handleAttributePredicate(@NonNull AttributePredicat } else { String strAttrValue; switch (attrPred.getOperator()) { - case LIKE: - strAttrValue = attributeValue.toString().replace(LIKE, ESCAPE + LIKE).replace(ANY, ESCAPE + ANY); - ParameterExpression pl = cb.parameter(String.class); - binds.put(pl, LIKE + strAttrValue + LIKE); - expr = cb.like(extractAttribute(entityRoot, attrName), pl); - break; - - case LIKE_IGNORE_CASE: - strAttrValue = attributeValue.toString().replace(LIKE, ESCAPE + LIKE).replace(ANY, ESCAPE + ANY).toLowerCase(); - ParameterExpression plci = cb.parameter(String.class); - binds.put(plci, LIKE + strAttrValue + LIKE); - expr = cb.like(cb.lower(extractAttribute(entityRoot, attrName)), plci); - break; - - case STARTS_WITH: - strAttrValue = attributeValue.toString().replace(LIKE, ESCAPE + LIKE).replace(ANY, ESCAPE + ANY); - ParameterExpression psw = cb.parameter(String.class); - binds.put(psw, strAttrValue + LIKE); - expr = cb.like(extractAttribute(entityRoot, attrName), psw); - break; - - case STARTS_WITH_IGNORE_CASE: - strAttrValue = attributeValue.toString().replace(LIKE, ESCAPE + LIKE).replace(ANY, ESCAPE + ANY).toLowerCase(); - ParameterExpression pswci = cb.parameter(String.class); - binds.put(pswci, strAttrValue + LIKE); - expr = cb.like(cb.lower(extractAttribute(entityRoot, attrName)), pswci); - break; - - case IS_NULL: - expr = cb.isNull(extractAttribute(entityRoot, attrName)); - break; - - case NOT_NULL: - expr = cb.isNotNull(extractAttribute(entityRoot, attrName)); - break; - - case NOT_EQUAL: - expr = cb.notEqual(extractAttribute(entityRoot, attrName), attributeValue); - break; - - case GREATER_THAN: - if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { - Comparable comparableAttrValue = (Comparable) attributeValue; - Expression comparableExpression = extractAttribute(entityRoot, attrName); - expr = cb.greaterThan(comparableExpression, comparableAttrValue); - } else { - throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); - } - break; - - case GREATER_THAN_OR_EQUAL: - if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { - Expression comparableExpression = extractAttribute(entityRoot, attrName); - Comparable comparableAttrValue = (Comparable) attributeValue; - expr = cb.greaterThanOrEqualTo(comparableExpression, comparableAttrValue); - } else { - throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); - } - break; - - case LESS_THAN: - if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { - Expression comparableExpression = extractAttribute(entityRoot, attrName); - Comparable comparableAttrValue = (Comparable) attributeValue; - expr = cb.lessThan(comparableExpression, comparableAttrValue); - } else { - throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); - } - break; - case LESS_THAN_OR_EQUAL: - if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { - Expression comparableExpression = extractAttribute(entityRoot, attrName); - Comparable comparableAttrValue = (Comparable) attributeValue; - expr = cb.lessThanOrEqualTo(comparableExpression, comparableAttrValue); - } else { - throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); - } - break; + case LIKE: + strAttrValue = attributeValue.toString().replace(LIKE, ESCAPE + LIKE).replace(ANY, ESCAPE + ANY); + ParameterExpression pl = cb.parameter(String.class); + binds.put(pl, LIKE + strAttrValue + LIKE); + expr = cb.like(extractAttribute(entityRoot, attrName), pl); + break; + + case LIKE_IGNORE_CASE: + strAttrValue = attributeValue.toString().replace(LIKE, ESCAPE + LIKE).replace(ANY, ESCAPE + ANY).toLowerCase(); + ParameterExpression plci = cb.parameter(String.class); + binds.put(plci, LIKE + strAttrValue + LIKE); + expr = cb.like(cb.lower(extractAttribute(entityRoot, attrName)), plci); + break; + + case STARTS_WITH: + strAttrValue = attributeValue.toString().replace(LIKE, ESCAPE + LIKE).replace(ANY, ESCAPE + ANY); + ParameterExpression psw = cb.parameter(String.class); + binds.put(psw, strAttrValue + LIKE); + expr = cb.like(extractAttribute(entityRoot, attrName), psw); + break; + + case STARTS_WITH_IGNORE_CASE: + strAttrValue = attributeValue.toString().replace(LIKE, ESCAPE + LIKE).replace(ANY, ESCAPE + ANY).toLowerCase(); + ParameterExpression pswci = cb.parameter(String.class); + binds.put(pswci, strAttrValue + LIKE); + expr = cb.like(cb.lower(extractAttribute(entityRoot, attrName)), pswci); + break; + + case IS_NULL: + expr = cb.isNull(extractAttribute(entityRoot, attrName)); + break; + + case NOT_NULL: + expr = cb.isNotNull(extractAttribute(entityRoot, attrName)); + break; + + case NOT_EQUAL: + expr = cb.notEqual(extractAttribute(entityRoot, attrName), attributeValue); + break; + + case GREATER_THAN: + if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { + Comparable comparableAttrValue = (Comparable) attributeValue; + Expression comparableExpression = extractAttribute(entityRoot, attrName); + expr = cb.greaterThan(comparableExpression, comparableAttrValue); + } else { + throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); + } + break; + + case GREATER_THAN_OR_EQUAL: + if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { + Expression comparableExpression = extractAttribute(entityRoot, attrName); + Comparable comparableAttrValue = (Comparable) attributeValue; + expr = cb.greaterThanOrEqualTo(comparableExpression, comparableAttrValue); + } else { + throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); + } + break; + + case LESS_THAN: + if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { + Expression comparableExpression = extractAttribute(entityRoot, attrName); + Comparable comparableAttrValue = (Comparable) attributeValue; + expr = cb.lessThan(comparableExpression, comparableAttrValue); + } else { + throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); + } + break; + case LESS_THAN_OR_EQUAL: + if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { + Expression comparableExpression = extractAttribute(entityRoot, attrName); + Comparable comparableAttrValue = (Comparable) attributeValue; + expr = cb.lessThanOrEqualTo(comparableExpression, comparableAttrValue); + } else { + throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); + } + break; - case EQUAL: - default: - expr = cb.equal(extractAttribute(entityRoot, attrName), attributeValue); + case EQUAL: + default: + expr = cb.equal(extractAttribute(entityRoot, attrName), attributeValue); } } return expr; @@ -847,12 +900,14 @@ private static Predicate handleAttributePredicate(@NonNull AttributePredicat *

* Filter predicates takes advantage of the dot notation to access {@link Embedded} attributes and nested {@link KapuaEntity}es. * - * @param entityRoot The {@link Root} entity from which extract the attribute. - * @param attributeName The full attribute name. + * @param entityRoot + * The {@link Root} entity from which extract the attribute. + * @param attributeName + * The full attribute name. * @return The {@link Path} expression that matches the given {@code attributeName} parameter. * @since 1.0.0 */ - private static Path

extractAttribute(@NonNull Root entityRoot, @NonNull String attributeName) { + private static Path

extractAttribute(Root entityRoot, String attributeName) { Path

expressionPath = null; if (attributeName.contains(ATTRIBUTE_SEPARATOR)) { String[] pathComponents = attributeName.split(ATTRIBUTE_SEPARATOR_ESCAPED); @@ -870,12 +925,15 @@ private static Path

extractAttribute(@NonNull Root entityRoot, @Non /** * Handles the {@link Groupable} property of the {@link KapuaEntity}. * - * @param query The {@link KapuaQuery} to manage. - * @param domain The {@link Domain} inside which the {@link KapuaQuery} param targets. - * @param groupPredicateName The name of the {@link Group} id field. + * @param query + * The {@link KapuaQuery} to manage. + * @param domain + * The {@link Domain} inside which the {@link KapuaQuery} param targets. + * @param groupPredicateName + * The name of the {@link Group} id field. * @since 1.0.0 */ - protected static void handleKapuaQueryGroupPredicate(@NonNull KapuaQuery query, @NonNull Domain domain, @NonNull String groupPredicateName) throws KapuaException { + protected static void handleKapuaQueryGroupPredicate(KapuaQuery query, Domain domain, String groupPredicateName) throws KapuaException { KapuaSession kapuaSession = KapuaSecurityUtils.getSession(); if (ACCESS_INFO_FACTORY != null) { if (kapuaSession != null && !kapuaSession.isTrustedMode()) { @@ -955,7 +1013,7 @@ private static void handleKapuaQueryGroupPredicate(KapuaSession kapuaSession, Ka * @return * @since 1.0.0 */ - private static boolean checkGroupPermission(@NonNull Domain domain, @NonNull List groupPermissions, @NonNull Permission permission) { + private static boolean checkGroupPermission(Domain domain, List groupPermissions, Permission permission) { if ((permission.getDomain() == null || domain.getName().equals(permission.getDomain())) && (permission.getAction() == null || Actions.read.equals(permission.getAction()))) { if (permission.getGroupId() == null) { @@ -971,11 +1029,12 @@ private static boolean checkGroupPermission(@NonNull Domain domain, @NonNull Lis /** * Check if the given {@link PersistenceException} is a SQL constraint violation error. * - * @param persistenceException {@link PersistenceException} to check. + * @param persistenceException + * {@link PersistenceException} to check. * @return {@code true} if it is a constraint validation error, {@code false} otherwise. * @since 1.0.0 */ - private static boolean isInsertConstraintViolation(@NonNull PersistenceException persistenceException) { + private static boolean isInsertConstraintViolation(PersistenceException persistenceException) { Throwable cause = persistenceException.getCause(); while (cause != null && !(cause instanceof SQLException)) { cause = cause.getCause(); diff --git a/pom.xml b/pom.xml index 7ab04eb2f75..bb64d61993f 100644 --- a/pom.xml +++ b/pom.xml @@ -47,15 +47,14 @@ 8 - 3.21.0 - 5.3.23 - 5.7.5 - 2.5.14 + 3.21.0 + 5.3.23 + 5.7.5 + 2.5.14 1.0 2.31.2 3.2.0 - 3.15.0 1.9.4 1.4 1.15 @@ -143,7 +142,7 @@ 3.0.0 5.1.8 2.17 - 3.6.1 + 3.13.0 3.0.1 2.8.2 1.4.1 @@ -1495,10 +1494,6 @@ com.google.j2objc j2objc-annotations - - org.checkerframework - checker-qual - @@ -1896,11 +1891,6 @@ javassist ${javassist.version} - - org.checkerframework - checker-qual - ${checker-framework.version} - io.dropwizard.metrics metrics-core diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/GroupQueryHelperImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/GroupQueryHelperImpl.java index 7fc6f02b2fb..83adf166aa6 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/GroupQueryHelperImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/GroupQueryHelperImpl.java @@ -12,7 +12,12 @@ *******************************************************************************/ package org.eclipse.kapua.service.authorization.access.shiro; -import org.checkerframework.checker.nullness.qual.NonNull; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import javax.inject.Inject; + import org.eclipse.kapua.KapuaEntityNotFoundException; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.model.id.KapuaEid; @@ -43,12 +48,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.inject.Inject; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - public class GroupQueryHelperImpl implements GroupQueryHelper { + private final TxManager txManager; private final AccessInfoFactory accessInfoFactory; private final AccessInfoRepository accessInfoRepository; @@ -146,7 +147,7 @@ private void handleKapuaQueryGroupPredicate(TxContext txContext, KapuaSession ka } } - private static boolean checkGroupPermission(@NonNull String domain, @NonNull List groupPermissions, @NonNull Permission permission) { + private static boolean checkGroupPermission(String domain, List groupPermissions, Permission permission) { if ((permission.getDomain() == null || domain.equals(permission.getDomain())) && (permission.getAction() == null || Actions.read.equals(permission.getAction()))) { if (permission.getGroupId() == null) {