@@ -48,28 +47,27 @@ *
The {@link KapuaQuery} type. - * @paramThe {@link KapuaEntityFactory} type. + * @param + * The {@link KapuaEntity} type. + * @param + * The {@link KapuaEntityCreator} type. + * @param + * The {@link KapuaEntityService} type. + * @param+ * The {@link KapuaEntityFactory} type. * @since 1.0.0 * @deprecated since 2.0.0, in favour of separate configuration component - see {@link ServiceConfigurationManager} and implementations for more details */ @Deprecated public abstract class AbstractKapuaConfigurableResourceLimitedService< E extends KapuaEntity, - C extends KapuaEntityCreator , + C extends KapuaEntityCreator, S extends KapuaEntityService , - L extends KapuaListResult , - Q extends KapuaQuery, - F extends KapuaEntityFactory + F extends KapuaEntityFactory > extends AbstractKapuaConfigurableService implements KapuaEntityService { - //TODO: make final as soon as deprecated constructors are removed private AccountRelativeFinder accountRelativeFinder; private F factory; @@ -79,11 +77,16 @@ public abstract class AbstractKapuaConfigurableResourceLimitedService< /** * Constructor. * - * @param pid The {@link KapuaConfigurableService} id. - * @param domain The {@link Domain} on which check access. - * @param entityManagerFactory The {@link EntityManagerFactory} that handles persistence unit - * @param serviceClass The {@link KapuaService} type. - * @param factoryClass The {@link KapuaEntityFactory} type. + * @param pid + * The {@link KapuaConfigurableService} id.KapuaEntit + * @param domain + * The {@link Domain} on which check access. + * @param entityManagerFactory + * The {@link EntityManagerFactory} that handles persistence unit + * @param serviceClass + * The {@link KapuaService} type. + * @param factoryClass + * The {@link KapuaEntityFactory} type. * @deprecated Since 1.2.0. This constructor will be removed in a next release (may be) */ @Deprecated @@ -104,12 +107,18 @@ protected AbstractKapuaConfigurableResourceLimitedService( /** * Constructor. * - * @param pid The {@link KapuaConfigurableService} id. - * @param domain The {@link Domain} on which check access. - * @param entityManagerFactory The {@link EntityManagerFactory} that handles persistence unit - * @param abstractCacheFactory The {@link CacheFactory} that handles caching of the entities + * @param pid + * The {@link KapuaConfigurableService} id. + * @param domain + * The {@link Domain} on which check access. + * @param entityManagerFactory + * The {@link EntityManagerFactory} that handles persistence unit + * @param abstractCacheFactory + * The {@link CacheFactory} that handles caching of the entities * @since 1.2.0 - * @deprecated Since 2.0.0. Please use {@link #AbstractKapuaConfigurableResourceLimitedService(String, Domain, EntityManagerFactory, EntityCacheFactory, KapuaEntityFactory, PermissionFactory, AuthorizationService, AccountRelativeFinder, RootUserTester)} This constructor may be removed in a next release + * @deprecated Since 2.0.0. Please use + * {@link #AbstractKapuaConfigurableResourceLimitedService(String, Domain, EntityManagerFactory, EntityCacheFactory, KapuaEntityFactory, AuthorizationService, AccountRelativeFinder, + * RootUserTester)} This constructor may be removed in a next release */ @Deprecated protected AbstractKapuaConfigurableResourceLimitedService( @@ -119,7 +128,7 @@ protected AbstractKapuaConfigurableResourceLimitedService( EntityCacheFactory abstractCacheFactory, Class serviceClass, ClassfactoryClass) { - super(pid, domain, entityManagerFactory, abstractCacheFactory, null, null, null); + super(pid, domain, entityManagerFactory, abstractCacheFactory, null, null); /* These should be provided by the Locator, but in most cases when this class is instantiated through this constructor the Locator is not yet ready, @@ -133,25 +142,30 @@ protected AbstractKapuaConfigurableResourceLimitedService( /** * Constructor. * - * @param pid The {@link KapuaConfigurableService} id. - * @param domain The {@link Domain} on which check access. - * @param entityManagerFactory The {@link EntityManagerFactory} that handles persistence unit - * @param abstractCacheFactory The {@link CacheFactory} that handles caching of the entities - * @param factory The {@link KapuaEntityFactory} instance. - * @param permissionFactory The {@link PermissionFactory} instance. - * @param authorizationService The {@link AuthorizationService} instance. - * @param rootUserTester The {@link RootUserTester} instance. + * @param pid + * The {@link KapuaConfigurableService} id. + * @param domain + * The {@link Domain} on which check access. + * @param entityManagerFactory + * The {@link EntityManagerFactory} that handles persistence unit + * @param abstractCacheFactory + * The {@link CacheFactory} that handles caching of the entities + * @param factory + * The {@link KapuaEntityFactory} instance. + * @param authorizationService + * The {@link AuthorizationService} instance. + * @param rootUserTester + * The {@link RootUserTester} instance. */ protected AbstractKapuaConfigurableResourceLimitedService(String pid, - Domain domain, - EntityManagerFactory entityManagerFactory, - EntityCacheFactory abstractCacheFactory, - F factory, - PermissionFactory permissionFactory, - AuthorizationService authorizationService, - AccountRelativeFinder accountRelativeFinder, - RootUserTester rootUserTester) { - super(pid, domain, entityManagerFactory, abstractCacheFactory, permissionFactory, authorizationService, rootUserTester); + Domain domain, + EntityManagerFactory entityManagerFactory, + EntityCacheFactory abstractCacheFactory, + F factory, + AuthorizationService authorizationService, + AccountRelativeFinder accountRelativeFinder, + RootUserTester rootUserTester) { + super(pid, domain, entityManagerFactory, abstractCacheFactory, authorizationService, rootUserTester); this.factory = factory; this.factoryClass = null; //TODO: not needed for this construction path, remove as soon as the deprecated constructor is removed this.accountRelativeFinder = accountRelativeFinder; @@ -180,8 +194,10 @@ protected boolean validateNewConfigValuesCoherence(KapuaTocd ocd, Map * The exclusion of the scope is required when updating a limit for a target account. * - * @param scopeId The scope {@link KapuaId}. - * @param targetScopeId The excluded scope {@link KapuaId}. + * @param scopeId + * The scope {@link KapuaId}. + * @param targetScopeId + * The excluded scope {@link KapuaId}. * @return The number of entities remaining for the given scope * @throws KapuaException * @since 1.0.0 @@ -220,14 +239,16 @@ private long allowedChildEntities(KapuaId scopeId, KapuaId targetScopeId) throws } /** - * Gets the number of remaining allowed entity for the given scope, according to the given {@link KapuaConfigurableService} - * excluding a specific scope when checking resources available. + * Gets the number of remaining allowed entity for the given scope, according to the given {@link KapuaConfigurableService} excluding a specific scope when checking resources available. * * The exclusion of the scope is required when updating a limit for a target account. * - * @param scopeId The scope {@link KapuaId}. - * @param targetScopeId The excluded scope {@link KapuaId}. - * @param configuration The configuration to be checked. If not provided will be read from the current service configuration + * @param scopeId + * The scope {@link KapuaId}. + * @param targetScopeId + * The excluded scope {@link KapuaId}. + * @param configuration + * The configuration to be checked. If not provided will be read from the current service configuration * @return The number of entities remaining for the given scope * @throws KapuaException * @since 1.0.0 @@ -239,7 +260,7 @@ private long allowedChildEntities(KapuaId scopeId, KapuaId targetScopeId, Map
{ - Q countQuery = getFactory().newQuery(scopeId); + KapuaQuery countQuery = new KapuaQuery(scopeId); // Current used entities long currentUsedEntities = this.count(countQuery); @@ -263,10 +284,9 @@ private long allowedChildEntities(KapuaId scopeId, KapuaId targetScopeId, Map d.getName()).orElse(null), Actions.read, scopeId)); + getAuthorizationService().checkPermission(new Permission(Optional.ofNullable(domain).map(d -> d.getName()).orElse(null), Actions.read, scopeId)); // Get the Tocd // Keep distinct values for service PID, Scope ID and disabled properties included/excluded from AD Triple cacheKey = Triple.of(pid, scopeId, excludeDisabled); @@ -525,9 +521,9 @@ protected Map getConfigValues(KapuaId scopeId, boolean excludeDi // Argument validation ArgumentValidator.notNull(scopeId, "scopeId"); // Check access - getAuthorizationService().checkPermission(getPermissionFactory().newPermission(Optional.ofNullable(domain).map(d -> d.getName()).orElse(null), Actions.read, scopeId)); + getAuthorizationService().checkPermission(new Permission(Optional.ofNullable(domain).map(d -> d.getName()).orElse(null), Actions.read, scopeId)); // Get configuration values - ServiceConfigQueryImpl query = new ServiceConfigQueryImpl(scopeId); + KapuaQuery query = new KapuaQuery(scopeId); query.setPredicate( query.andPredicate( @@ -537,7 +533,7 @@ protected Map getConfigValues(KapuaId scopeId, boolean excludeDi ); ServiceConfigListResult result = entityManagerSession.doAction(EntityManagerContainer. create() - .onResultHandler(em -> ServiceDAO.query(em, ServiceConfig.class, ServiceConfigImpl.class, new ServiceConfigListResultImpl(), query)) + .onResultHandler(em -> ServiceDAO.query(em, ServiceConfig.class, ServiceConfigImpl.class, new ServiceConfigListResult(), query)) .onBeforeHandler(() -> (ServiceConfigListResult) PRIVATE_ENTITY_CACHE.getList(scopeId, pid)) .onAfterHandler(entity -> PRIVATE_ENTITY_CACHE.putList(scopeId, pid, entity))); @@ -579,11 +575,11 @@ public void setConfigValues(KapuaId scopeId, KapuaId parentId, Map d.getName()).orElse(null), Actions.write, scopeId)); + getAuthorizationService().checkPermission(new Permission(Optional.ofNullable(domain).map(d -> d.getName()).orElse(null), Actions.write, scopeId)); validateConfigurations(ocd, values, scopeId, parentId); - ServiceConfigQueryImpl query = new ServiceConfigQueryImpl(scopeId); + KapuaQuery query = new KapuaQuery(scopeId); query.setPredicate( query.andPredicate( query.attributePredicate(ServiceConfigAttributes.SERVICE_ID, pid), @@ -592,7 +588,7 @@ public void setConfigValues(KapuaId scopeId, KapuaId parentId, Map create(). - onResultHandler(em -> ServiceDAO.query(em, ServiceConfig.class, ServiceConfigImpl.class, new ServiceConfigListResultImpl(), query)) + onResultHandler(em -> ServiceDAO.query(em, ServiceConfig.class, ServiceConfigImpl.class, new ServiceConfigListResult(), query)) ); Properties props = toProperties(values); @@ -638,20 +634,6 @@ public String getServicePid() { return pid; } - /** - * PermissionFactory should be provided by the Locator, but in most cases when this class is instantiated through this constructor the Locator is not yet ready, therefore fetching of the required - * instance is demanded to this artificial getter. - * - * @return The instantiated (hopefully) {@link PermissionFactory} instance - */ - //TODO: Remove as soon as deprecated constructors are removed, use field directly instead. - protected PermissionFactory getPermissionFactory() { - if (permissionFactory == null) { - permissionFactory = KapuaLocator.getInstance().getFactory(PermissionFactory.class); - } - return permissionFactory; - } - /** * AuthorizationService should be provided by the Locator, but in most cases when this class is instantiated through the deprecated constructor the Locator is not yet ready, therefore fetching of * the required instance is demanded to this artificial getter. diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/KapuaConfigurableServiceBase.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/KapuaConfigurableServiceBase.java index be0698d338d..61fb8ea46f0 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/KapuaConfigurableServiceBase.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/configuration/KapuaConfigurableServiceBase.java @@ -18,13 +18,12 @@ import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.util.ArgumentValidator; -import org.eclipse.kapua.model.config.metatype.EmptyTocd; import org.eclipse.kapua.model.config.metatype.KapuaTocd; import org.eclipse.kapua.model.domain.Actions; import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.service.KapuaService; import org.eclipse.kapua.service.authorization.AuthorizationService; -import org.eclipse.kapua.service.authorization.permission.PermissionFactory; +import org.eclipse.kapua.service.authorization.permission.Permission; import org.eclipse.kapua.service.config.KapuaConfigurableService; import org.eclipse.kapua.storage.TxManager; @@ -46,19 +45,16 @@ public class KapuaConfigurableServiceBase protected final ServiceConfigurationManager serviceConfigurationManager; private final String domain; protected final AuthorizationService authorizationService; - protected final PermissionFactory permissionFactory; public KapuaConfigurableServiceBase( TxManager txManager, ServiceConfigurationManager serviceConfigurationManager, String authorizationDomain, - AuthorizationService authorizationService, - PermissionFactory permissionFactory) { + AuthorizationService authorizationService) { this.txManager = txManager; this.serviceConfigurationManager = serviceConfigurationManager; this.domain = authorizationDomain; this.authorizationService = authorizationService; - this.permissionFactory = permissionFactory; } @Override @@ -75,9 +71,9 @@ public KapuaTocd getConfigMetadata(KapuaId scopeId) throws KapuaException { ArgumentValidator.notNull(scopeId, "scopeId"); // Check access - if (!authorizationService.isPermitted(permissionFactory.newPermission(domain, Actions.read, scopeId))) { + if (!authorizationService.isPermitted(new Permission(domain, Actions.read, scopeId))) { //Temporary, use Optional instead - return new EmptyTocd(); + return KapuaTocd.empty(); } return serviceConfigurationManager.getConfigMetadata(scopeId, true).orElse(null); } @@ -88,7 +84,7 @@ public Map getConfigValues(KapuaId scopeId) throws KapuaExceptio ArgumentValidator.notNull(scopeId, "scopeId"); // Check access - if (!authorizationService.isPermitted(permissionFactory.newPermission(domain, Actions.read, scopeId))) { + if (!authorizationService.isPermitted(new Permission(domain, Actions.read, scopeId))) { return Collections.emptyMap(); } return serviceConfigurationManager.getConfigValues(scopeId, true); @@ -100,7 +96,7 @@ public void setConfigValues(KapuaId scopeId, KapuaId parentId, Map { +public class ServiceConfigCreator extends KapuaUpdatableEntityCreator { + + private static final long serialVersionUID = 7508550960304732465L; + + @XmlElement(name = "pid") + private String pid; + + @XmlElement(name = "configurations") + private Properties configurations; + + public ServiceConfigCreator() { + } + + public ServiceConfigCreator(KapuaId scopeId) { + super(scopeId); + } + + public ServiceConfigCreator(KapuaEntityCreator entityCreator) { + super(entityCreator); + } /** * Return service pid * * @return */ - public String getPid(); + public String getPid() { + return pid; + } /** * Set service pid * * @param pid */ - public void setPid(String pid); + public void setPid(String pid) { + this.pid = pid; + } /** * Return service configurations * * @return - * @throws KapuaException */ - public Properties getConfigurations() throws KapuaException; + public Properties getConfigurations() { + return this.configurations; + } /** * Set service configurations * * @param configurations - * @throws KapuaException */ - public void setConfigurations(Properties configurations) throws KapuaException; + public void setConfigurations(Properties configurations) { + this.configurations = configurations; + } } diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigCreatorImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigCreatorImpl.java deleted file mode 100644 index 8713525270a..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigCreatorImpl.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.configuration; - -import java.util.Properties; - -import javax.xml.bind.annotation.XmlElement; - -import org.eclipse.kapua.commons.model.AbstractKapuaUpdatableEntityCreator; -import org.eclipse.kapua.model.id.KapuaId; - -/** - * Service configuration creator reference implementation. - * - * @since 1.0 - * - */ -public class ServiceConfigCreatorImpl extends AbstractKapuaUpdatableEntityCreator - implements ServiceConfigCreator { - - private static final long serialVersionUID = 7508550960304732465L; - - @XmlElement(name = "pid") - private String pid; - - @XmlElement(name = "configurations") - private Properties configurations; - - /** - * Constructor - * - * @param scopeId - */ - protected ServiceConfigCreatorImpl(KapuaId scopeId) { - super(scopeId); - } - - @Override - public String getPid() { - return pid; - } - - @Override - public void setPid(String pid) { - this.pid = pid; - } - - @Override - public Properties getConfigurations() { - return this.configurations; - } - - @Override - public void setConfigurations(Properties configurations) { - this.configurations = configurations; - } -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigImpl.java index 7ad7c0b71c7..42ace129aa8 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigImpl.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigImpl.java @@ -27,8 +27,8 @@ import javax.xml.bind.annotation.XmlType; import org.eclipse.kapua.KapuaException; +import org.eclipse.kapua.PropertiesUtils; import org.eclipse.kapua.commons.model.AbstractKapuaUpdatableEntity; -import org.eclipse.kapua.commons.util.PropertiesUtils; import org.eclipse.kapua.model.id.KapuaId; @XmlRootElement diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigImplJpaRepository.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigImplJpaRepository.java index 31b63e33cab..d94c39e0e56 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigImplJpaRepository.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigImplJpaRepository.java @@ -16,18 +16,19 @@ import org.eclipse.kapua.commons.jpa.KapuaJpaRepositoryConfiguration; import org.eclipse.kapua.commons.jpa.KapuaUpdatableEntityJpaRepository; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.storage.TxContext; public class ServiceConfigImplJpaRepository extends KapuaUpdatableEntityJpaRepository implements ServiceConfigRepository { public ServiceConfigImplJpaRepository(KapuaJpaRepositoryConfiguration jpaRepoConfig) { - super(ServiceConfigImpl.class, ServiceConfig.TYPE, () -> new ServiceConfigListResultImpl(), jpaRepoConfig); + super(ServiceConfigImpl.class, ServiceConfig.TYPE, () -> new ServiceConfigListResult(), jpaRepoConfig); } @Override public ServiceConfigListResult findByScopeAndPid(TxContext txContext, KapuaId scopeId, String pid) throws KapuaException { - final ServiceConfigQueryImpl query = new ServiceConfigQueryImpl(scopeId); + final KapuaQuery query = new KapuaQuery(scopeId); query.setPredicate( query.andPredicate( diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigListResult.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigListResult.java index 5701270b445..22229c46b19 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigListResult.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigListResult.java @@ -18,7 +18,9 @@ * Service configuration result list definition. * * @since 1.0 - * */ -public interface ServiceConfigListResult extends KapuaListResult { +public class ServiceConfigListResult extends KapuaListResult { + + private static final long serialVersionUID = -2550359084026132096L; + } diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigListResultImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigListResultImpl.java deleted file mode 100644 index 79136d21865..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigListResultImpl.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.configuration; - -import org.eclipse.kapua.commons.model.query.KapuaListResultImpl; - -/** - * Service configuration result list reference implementation. - * - * @since 1.0 - * - */ -public class ServiceConfigListResultImpl extends KapuaListResultImpl implements ServiceConfigListResult { - - private static final long serialVersionUID = -2550359084026132096L; -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigQuery.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigQuery.java deleted file mode 100644 index a933f50e6fb..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigQuery.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.configuration; - -import org.eclipse.kapua.model.query.KapuaQuery; - -/** - * {@link ServiceConfig} {@link KapuaQuery} definition. - * - * @see KapuaQuery - * @since 1.0.0 - */ -public interface ServiceConfigQuery extends KapuaQuery { -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigQueryImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigQueryImpl.java deleted file mode 100644 index aff2e0593bd..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigQueryImpl.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.configuration; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaQuery; -import org.eclipse.kapua.model.id.KapuaId; - -/** - * {@link ServiceConfigQuery} implementation. - * - * @since 1.0.0 - */ -public class ServiceConfigQueryImpl extends AbstractKapuaQuery implements ServiceConfigQuery { - - /** - * Constructor. - * - * @since 1.0.0 - */ - private ServiceConfigQueryImpl() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public ServiceConfigQueryImpl(KapuaId scopeId) { - this(); - setScopeId(scopeId); - } -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationManagerImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationManagerImpl.java index 7dd2137e2c7..f8e2d439d84 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationManagerImpl.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationManagerImpl.java @@ -36,6 +36,7 @@ import org.eclipse.kapua.model.config.metatype.KapuaTmetadata; import org.eclipse.kapua.model.config.metatype.KapuaTocd; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.config.KapuaConfigurableService; import org.eclipse.kapua.service.config.ServiceComponentConfiguration; import org.eclipse.kapua.storage.TxContext; @@ -160,7 +161,7 @@ public void setConfigValues(KapuaId scopeId, Optional parentId, Map , ServiceConfigurationManager> serviceConfigurationManagersByServiceClass; private final Map serviceConfigurationManagersByServiceClassName; protected final AuthorizationService authorizationService; - protected final PermissionFactory permissionFactory; protected final AccountService accountService; @Inject public ServiceConfigurationsFacadeImpl(Map , ServiceConfigurationManager> serviceConfigurationManagersByServiceClass, AuthorizationService authorizationService, - PermissionFactory permissionFactory, AccountService accountService) { + AccountService accountService) { this.serviceConfigurationManagersByServiceClass = serviceConfigurationManagersByServiceClass; this.serviceConfigurationManagersByServiceClassName = serviceConfigurationManagersByServiceClass.entrySet().stream().collect(Collectors.toMap(kv -> kv.getKey().getName(), kv -> kv.getValue())); this.authorizationService = authorizationService; - this.permissionFactory = permissionFactory; this.accountService = accountService; } @@ -53,7 +51,7 @@ public ServiceConfiguration fetchAllConfigurations(KapuaId scopeId) throws Kapua final ServiceConfiguration res = new ServiceConfiguration(); for (ServiceConfigurationManager configurableService : serviceConfigurationManagersByServiceClass.values()) { - if (!authorizationService.isPermitted(permissionFactory.newPermission(configurableService.getDomain(), Actions.read, scopeId))) { + if (!authorizationService.isPermitted(new Permission(configurableService.getDomain(), Actions.read, scopeId))) { continue; } configurableService.extractServiceComponentConfiguration(scopeId).ifPresent(res.getComponentConfigurations()::add); @@ -67,7 +65,7 @@ public ServiceComponentConfiguration fetchConfiguration(KapuaId scopeId, String if (serviceConfigurationManager == null) { throw new KapuaIllegalArgumentException("service.pid", serviceId); } - authorizationService.checkPermission(permissionFactory.newPermission(serviceConfigurationManager.getDomain(), Actions.read, scopeId)); + authorizationService.checkPermission(new Permission(serviceConfigurationManager.getDomain(), Actions.read, scopeId)); return serviceConfigurationManager.extractServiceComponentConfiguration(scopeId).orElse(null); } @@ -91,7 +89,7 @@ private void doUpdateServiceComponentConfiguration(Account account, KapuaId scop if (serviceConfigurationManager == null) { throw new KapuaIllegalArgumentException("serviceConfiguration.componentConfiguration.id", newServiceComponentConfiguration.getId()); } - if (!authorizationService.isPermitted(permissionFactory.newPermission(serviceConfigurationManager.getDomain(), Actions.write, scopeId))) { + if (!authorizationService.isPermitted(new Permission(serviceConfigurationManager.getDomain(), Actions.write, scopeId))) { //TODO: Or maybe throw? return; } diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/UsedEntitiesCounterImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/UsedEntitiesCounterImpl.java index 227dccac161..601e4a6ddc0 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/UsedEntitiesCounterImpl.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/configuration/UsedEntitiesCounterImpl.java @@ -15,8 +15,6 @@ import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.model.KapuaEntity; -import org.eclipse.kapua.model.KapuaEntityCreator; -import org.eclipse.kapua.model.KapuaEntityFactory; import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.model.query.KapuaListResult; import org.eclipse.kapua.model.query.KapuaQuery; @@ -25,24 +23,18 @@ public class UsedEntitiesCounterImpl< E extends KapuaEntity, - C extends KapuaEntityCreator , - L extends KapuaListResult , - Q extends KapuaQuery, - F extends KapuaEntityFactory - > implements UsedEntitiesCounter { + L extends KapuaListResult > implements UsedEntitiesCounter { - private final F factory; private final KapuaEntityRepository entityRepository; - public UsedEntitiesCounterImpl(F factory, - KapuaEntityRepository entityRepository) { - this.factory = factory; + public UsedEntitiesCounterImpl( + KapuaEntityRepository entityRepository) { this.entityRepository = entityRepository; } @Override public long countEntitiesInScope(TxContext tx, KapuaId scopeId) throws KapuaException { - final Q query = factory.newQuery(scopeId); + final KapuaQuery query = new KapuaQuery(scopeId); // Do count return entityRepository.count(tx, query); } diff --git a/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventHousekeeper.java b/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventHousekeeper.java index b6b6363879e..4ad90d127fc 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventHousekeeper.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventHousekeeper.java @@ -12,6 +12,11 @@ *******************************************************************************/ package org.eclipse.kapua.commons.event; +import java.time.Duration; +import java.time.temporal.ChronoUnit; +import java.util.Date; +import java.util.List; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.jpa.EntityManager; import org.eclipse.kapua.commons.jpa.EntityManagerFactory; @@ -22,7 +27,6 @@ import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordQuery; import org.eclipse.kapua.commons.service.event.store.api.EventStoreService; import org.eclipse.kapua.commons.service.event.store.api.ServiceEventUtil; -import org.eclipse.kapua.commons.service.event.store.internal.EventStoreFactoryImpl; import org.eclipse.kapua.commons.setting.system.SystemSetting; import org.eclipse.kapua.commons.setting.system.SystemSettingKey; import org.eclipse.kapua.commons.util.KapuaDateUtils; @@ -35,11 +39,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.time.Duration; -import java.time.temporal.ChronoUnit; -import java.util.Date; -import java.util.List; - /** * Event bus housekeeper. It is responsible to send unsent messages or send again messages gone in error. * @@ -78,7 +77,8 @@ private enum EventsProcessType { * @param servicesEntryList * @throws KapuaException */ - public ServiceEventHousekeeper(EventStoreService eventStoreService, EntityManagerFactory entityManagerFactory, ServiceEventBus eventbus, List servicesEntryList) throws KapuaException { + public ServiceEventHousekeeper(EventStoreService eventStoreService, EntityManagerFactory entityManagerFactory, ServiceEventBus eventbus, List servicesEntryList) + throws KapuaException { this.eventbus = eventbus; this.servicesEntryList = servicesEntryList; manager = entityManagerFactory.createEntityManager(); @@ -161,7 +161,7 @@ private void findAndSendUnsentEvents(String serviceName, EventsProcessType event } private EventStoreRecordListResult getUnsentEvents(String serviceName, EventsProcessType eventsProcessType) throws KapuaException { - EventStoreRecordQuery query = new EventStoreFactoryImpl().newQuery(null); + EventStoreRecordQuery query = new EventStoreRecordQuery(null); AndPredicate andPredicate = query.andPredicate(); andPredicate.and(query.attributePredicate(EventStoreRecordAttributes.SERVICE_NAME, serviceName)); diff --git a/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventModule.java b/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventModule.java index d043594a9bf..20e92ae1355 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventModule.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventModule.java @@ -12,30 +12,28 @@ *******************************************************************************/ package org.eclipse.kapua.commons.event; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; + import org.apache.commons.lang3.StringUtils; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.core.ServiceModule; import org.eclipse.kapua.commons.jpa.JpaTxContext; -import org.eclipse.kapua.commons.service.event.store.internal.EventStoreFactoryImpl; import org.eclipse.kapua.commons.service.event.store.internal.EventStoreRecordImplJpaRepository; import org.eclipse.kapua.commons.service.event.store.internal.EventStoreServiceImpl; import org.eclipse.kapua.event.ServiceEventBus; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.service.authorization.AuthorizationService; -import org.eclipse.kapua.service.authorization.permission.PermissionFactory; import org.eclipse.kapua.storage.TxManagerImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; - /** * Base {@link ServiceModule} implementation to be used by the modules that listen for events. * @@ -101,9 +99,8 @@ public void start() throws KapuaException { final KapuaLocator locator = KapuaLocator.getInstance(); houseKeeperJob = new ServiceEventHousekeeper( new EventStoreServiceImpl(locator.getService(AuthorizationService.class), - locator.getFactory(PermissionFactory.class), - new TxManagerImpl(() -> new JpaTxContext(serviceEventModuleConfiguration.getEntityManagerFactory().getJpaEntityManagerFactory()), serviceEventModuleConfiguration.maxInsertAttempts), - new EventStoreFactoryImpl(), + new TxManagerImpl(() -> new JpaTxContext(serviceEventModuleConfiguration.getEntityManagerFactory().getJpaEntityManagerFactory()), + serviceEventModuleConfiguration.maxInsertAttempts), new EventStoreRecordImplJpaRepository(serviceEventModuleConfiguration.getKapuaJpaRepositoryConfiguration()) ), serviceEventModuleConfiguration.getEntityManagerFactory(), diff --git a/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventTransactionalHousekeeper.java b/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventTransactionalHousekeeper.java index 3895e025656..048b37ea1d4 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventTransactionalHousekeeper.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventTransactionalHousekeeper.java @@ -12,6 +12,14 @@ *******************************************************************************/ package org.eclipse.kapua.commons.event; +import java.time.Duration; +import java.time.temporal.ChronoUnit; +import java.util.Date; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.LockModeType; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.jpa.JpaAwareTxContext; import org.eclipse.kapua.commons.security.KapuaSecurityUtils; @@ -21,7 +29,6 @@ import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordQuery; import org.eclipse.kapua.commons.service.event.store.api.EventStoreService; import org.eclipse.kapua.commons.service.event.store.api.ServiceEventUtil; -import org.eclipse.kapua.commons.service.event.store.internal.EventStoreFactoryImpl; import org.eclipse.kapua.commons.setting.system.SystemSetting; import org.eclipse.kapua.commons.setting.system.SystemSettingKey; import org.eclipse.kapua.commons.util.KapuaDateUtils; @@ -36,13 +43,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.persistence.EntityManager; -import javax.persistence.LockModeType; -import java.time.Duration; -import java.time.temporal.ChronoUnit; -import java.util.Date; -import java.util.List; - /** * Event bus housekeeper. It is responsible to send unsent messages or send again messages gone in error. * @@ -156,7 +156,7 @@ private void findAndSendUnsentEvents(String serviceName, EventsProcessType event } private EventStoreRecordListResult getUnsentEvents(String serviceName, EventsProcessType eventsProcessType) throws KapuaException { - EventStoreRecordQuery query = new EventStoreFactoryImpl().newQuery(null); + EventStoreRecordQuery query = new EventStoreRecordQuery(null); AndPredicate andPredicate = query.andPredicate(); andPredicate.and(query.attributePredicate(EventStoreRecordAttributes.SERVICE_NAME, serviceName)); diff --git a/commons/src/main/java/org/eclipse/kapua/commons/jpa/JpaTxContext.java b/commons/src/main/java/org/eclipse/kapua/commons/jpa/JpaTxContext.java index 13c5e14b0cc..480f30fb912 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/jpa/JpaTxContext.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/jpa/JpaTxContext.java @@ -12,13 +12,9 @@ *******************************************************************************/ package org.eclipse.kapua.commons.jpa; -import org.eclipse.kapua.KapuaEntityExistsException; -import org.eclipse.kapua.KapuaException; -import org.eclipse.kapua.commons.util.KapuaExceptionUtils; -import org.eclipse.kapua.storage.TxContext; -import org.eclipse.persistence.exceptions.DatabaseException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.io.IOException; +import java.util.Optional; +import java.util.function.Predicate; import javax.persistence.EntityExistsException; import javax.persistence.EntityManager; @@ -27,11 +23,17 @@ import javax.persistence.OptimisticLockException; import javax.persistence.PessimisticLockException; import javax.persistence.RollbackException; -import java.io.IOException; -import java.util.Optional; -import java.util.function.Predicate; + +import org.eclipse.kapua.KapuaEntityExistsException; +import org.eclipse.kapua.KapuaException; +import org.eclipse.kapua.commons.util.KapuaExceptionUtils; +import org.eclipse.kapua.storage.TxContext; +import org.eclipse.persistence.exceptions.DatabaseException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class JpaTxContext implements JpaAwareTxContext, TxContext { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); public final EntityManagerFactory entityManagerFactory; Optional entityManager = Optional.empty(); @@ -97,7 +99,7 @@ public KapuaException convertPersistenceException(Exception ex) { public boolean isRecoverableException(Exception ex) { if (ex instanceof KapuaEntityExistsException || ex instanceof EntityExistsException) { /* - * Most KapuaEntities inherit from AbstractKapuaEntity, which auto-generates ids via a method marked with @PrePersist and the use of + * Most KapuaEntities inherit from KapuaEntityBase, which auto-generates ids via a method marked with @PrePersist and the use of * a org.eclipse.kapua.commons.model.id.IdGenerator. Ids are pseudo-randomic. To deal with potential conflicts, a number of retries * is allowed. The entity needs to be detached in order for the @PrePersist method to be invoked once more, generating a new id * */ 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 429bef059b9..65fa4a44808 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 @@ -48,8 +48,6 @@ import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.model.AbstractKapuaEntity_; import org.eclipse.kapua.commons.model.id.KapuaEid; -import org.eclipse.kapua.commons.model.query.predicate.AttributePredicateImpl; -import org.eclipse.kapua.commons.model.query.predicate.OrPredicateImpl; import org.eclipse.kapua.model.KapuaEntity; import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.model.query.FieldSortCriteria; @@ -373,9 +371,9 @@ private Predicate handleKapuaQueryPredicates(@NonNull QueryPredicate queryPr predicate = handleOrPredicate(orPredicate, binds, cb, userPermissionRoot, entityType); } else if (queryPredicate instanceof MatchPredicate) { MatchPredicate> matchPredicate = (MatchPredicate>) queryPredicate; - OrPredicate orPredicate = new OrPredicateImpl(); + OrPredicate orPredicate = new OrPredicate(); for (String attributeName : matchPredicate.getAttributeNames()) { - orPredicate.getPredicates().add(new AttributePredicateImpl<>(attributeName, matchPredicate.getMatchTerm(), AttributePredicate.Operator.STARTS_WITH_IGNORE_CASE)); + orPredicate.getPredicates().add(new AttributePredicate<>(attributeName, matchPredicate.getMatchTerm(), AttributePredicate.Operator.STARTS_WITH_IGNORE_CASE)); } predicate = handleOrPredicate(orPredicate, binds, cb, userPermissionRoot, entityType); } diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaEntityCreator.java b/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaEntityCreator.java deleted file mode 100644 index 9ce733b593c..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaEntityCreator.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.model; - -import java.io.Serializable; - -import org.eclipse.kapua.model.KapuaEntity; -import org.eclipse.kapua.model.KapuaEntityCreator; -import org.eclipse.kapua.model.id.KapuaId; - -/** - * Kapua entity base creator service (reference abstract implementation). - * - * @param - * entity type - * - * @since 1.0 - * - */ -@SuppressWarnings("serial") -public abstract class AbstractKapuaEntityCreator implements KapuaEntityCreator , Serializable { - - protected KapuaId scopeId; - - /** - * Constructor - * - * @param scopeId - */ - protected AbstractKapuaEntityCreator(KapuaId scopeId) { - super(); - setScopeId(scopeId); - } - - protected AbstractKapuaEntityCreator(AbstractKapuaEntityCreator abstractEntityCreator) { - this(abstractEntityCreator.getScopeId()); - } - - @Override - public KapuaId getScopeId() { - return scopeId; - } - - @Override - public void setScopeId(KapuaId scopeId) { - - this.scopeId = scopeId; - } -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaNamedEntityCreator.java b/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaNamedEntityCreator.java deleted file mode 100644 index 3fe4a69e00c..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaNamedEntityCreator.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.model; - -import org.eclipse.kapua.model.KapuaEntity; -import org.eclipse.kapua.model.KapuaNamedEntityCreator; -import org.eclipse.kapua.model.id.KapuaId; - -/** - * {@link KapuaNamedEntityCreator} {@code abstract} implementation. - * - * @param {@link KapuaEntity} which this {@link AbstractKapuaUpdatableEntityCreator} is for - * @since 1.0.0 - */ -public abstract class AbstractKapuaNamedEntityCreator extends AbstractKapuaUpdatableEntityCreator implements KapuaNamedEntityCreator { - - protected String name; - protected String description; - - /** - * Constructor - * - * @param scopeId the scope {@link KapuaId} - * @param name the name - * @since 1.0.0 - */ - protected AbstractKapuaNamedEntityCreator(KapuaId scopeId, String name) { - super(scopeId); - - setName(name); - } - - public AbstractKapuaNamedEntityCreator(KapuaId scopeId) { - super(scopeId); - } - - @Override - public String getName() { - return name; - } - - @Override - public void setName(String name) { - this.name = name; - } - - @Override - public String getDescription() { - return description; - } - - @Override - public void setDescription(String description) { - this.description = description; - } -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaUpdatableEntity.java b/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaUpdatableEntity.java index fd0febcdf9f..82c8301753a 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaUpdatableEntity.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaUpdatableEntity.java @@ -12,14 +12,9 @@ *******************************************************************************/ package org.eclipse.kapua.commons.model; -import org.eclipse.kapua.commons.model.id.KapuaEid; -import org.eclipse.kapua.commons.security.KapuaSecurityUtils; -import org.eclipse.kapua.commons.util.PropertiesUtils; -import org.eclipse.kapua.entity.EntityPropertiesReadException; -import org.eclipse.kapua.entity.EntityPropertiesWriteException; -import org.eclipse.kapua.model.KapuaEntity; -import org.eclipse.kapua.model.KapuaUpdatableEntity; -import org.eclipse.kapua.model.id.KapuaId; +import java.io.IOException; +import java.util.Date; +import java.util.Properties; import javax.persistence.Access; import javax.persistence.AccessType; @@ -33,9 +28,15 @@ import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Version; -import java.io.IOException; -import java.util.Date; -import java.util.Properties; + +import org.eclipse.kapua.PropertiesUtils; +import org.eclipse.kapua.commons.model.id.KapuaEid; +import org.eclipse.kapua.commons.security.KapuaSecurityUtils; +import org.eclipse.kapua.entity.EntityPropertiesReadException; +import org.eclipse.kapua.entity.EntityPropertiesWriteException; +import org.eclipse.kapua.model.KapuaEntity; +import org.eclipse.kapua.model.KapuaUpdatableEntity; +import org.eclipse.kapua.model.id.KapuaId; /** * {@link KapuaUpdatableEntity} {@code abstract} implementation. @@ -69,8 +70,7 @@ public abstract class AbstractKapuaUpdatableEntity extends AbstractKapuaEntity i protected String properties; /** - * Protected default constructor.
- * Required by JPA. + * Protected default constructor.
Required by JPA. * * @since 1.0.0 */ @@ -81,7 +81,8 @@ protected AbstractKapuaUpdatableEntity() { /** * Constructor. * - * @param scopeId The scope {@link KapuaId} to set for this {@link KapuaUpdatableEntity} + * @param scopeId + * The scope {@link KapuaId} to set for this {@link KapuaUpdatableEntity} * @since 1.0.0 */ public AbstractKapuaUpdatableEntity(KapuaId scopeId) { @@ -93,8 +94,10 @@ public AbstractKapuaUpdatableEntity(KapuaId scopeId) { ** It can be used to clone the {@link KapuaUpdatableEntity} * - * @throws EntityPropertiesReadException see {@link #getEntityProperties()} and {@link #getEntityAttributes()} - * @throws EntityPropertiesWriteException see {@link #setEntityProperties(Properties)} and {@link #setEntityAttributes(Properties)} + * @throws EntityPropertiesReadException + * see {@link #getEntityProperties()} and {@link #getEntityAttributes()} + * @throws EntityPropertiesWriteException + * see {@link #setEntityProperties(Properties)} and {@link #setEntityAttributes(Properties)} * @since 1.0.0 */ protected AbstractKapuaUpdatableEntity(KapuaUpdatableEntity entity) { @@ -103,8 +106,8 @@ protected AbstractKapuaUpdatableEntity(KapuaUpdatableEntity entity) { setModifiedOn(entity.getModifiedOn()); setModifiedBy(entity.getModifiedBy()); setOptlock(entity.getOptlock()); - setEntityAttributes(entity.getEntityAttributes()); - setEntityProperties(entity.getEntityProperties()); + // setEntityAttributes(entity.getEntityAttributes()); + // setEntityProperties(entity.getEntityProperties()); } @Override @@ -115,7 +118,8 @@ public Date getModifiedOn() { /** * Sets the date of the last update * - * @param modifiedOn The date of the last update + * @param modifiedOn + * The date of the last update * @since 1.0.0 */ public void setModifiedOn(Date modifiedOn) { @@ -130,7 +134,8 @@ public KapuaId getModifiedBy() { /** * Sets the identity {@link KapuaId} who has updated this {@link KapuaEntity} * - * @param modifiedBy The identity {@link KapuaId} who has updated this {@link KapuaEntity} + * @param modifiedBy + * The identity {@link KapuaId} who has updated this {@link KapuaEntity} * @since 1.0.0 */ public void setModifiedBy(KapuaId modifiedBy) { @@ -151,7 +156,7 @@ public void setOptlock(int optlock) { // Attributes APIs // ------------------------------------------------- - @Override + // @Override public Properties getEntityAttributes() { try { return PropertiesUtils.readPropertiesFromString(attributes); @@ -160,7 +165,7 @@ public Properties getEntityAttributes() { } } - @Override + // @Override public void setEntityAttributes(Properties entityAttributes) { try { this.attributes = PropertiesUtils.writePropertiesToString(entityAttributes); @@ -173,7 +178,7 @@ public void setEntityAttributes(Properties entityAttributes) { // Properties APIs // ------------------------------------------------- - @Override + // @Override public Properties getEntityProperties() { try { return PropertiesUtils.readPropertiesFromString(properties); @@ -182,7 +187,7 @@ public Properties getEntityProperties() { } } - @Override + // @Override public void setEntityProperties(Properties properties) { try { this.properties = PropertiesUtils.writePropertiesToString(properties); @@ -192,8 +197,7 @@ public void setEntityProperties(Properties properties) { } /** - * Before create action invokes {@link AbstractKapuaEntity#prePersistsAction()} and - * sets {@link KapuaUpdatableEntity} {@link #modifiedBy} and {@link #modifiedOn}. + * Before create action invokes {@link AbstractKapuaEntity#prePersistsAction()} and sets {@link KapuaUpdatableEntity} {@link #modifiedBy} and {@link #modifiedOn}. * * @since 1.0.0 */ diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaUpdatableEntityCreator.java b/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaUpdatableEntityCreator.java deleted file mode 100644 index a0f596d3032..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaUpdatableEntityCreator.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.model; - -import org.eclipse.kapua.commons.util.PropertiesUtils; -import org.eclipse.kapua.entity.EntityPropertiesReadException; -import org.eclipse.kapua.entity.EntityPropertiesWriteException; -import org.eclipse.kapua.model.KapuaEntity; -import org.eclipse.kapua.model.KapuaUpdatableEntityCreator; -import org.eclipse.kapua.model.id.KapuaId; - -import java.io.IOException; -import java.util.Properties; - -/** - * {@link KapuaUpdatableEntityCreator} {@code abstract} implementation. - * - * @param
the {@link KapuaEntity} for which this {@link AbstractKapuaEntityCreator} is for. - * @since 1.0.0 - */ -public abstract class AbstractKapuaUpdatableEntityCreator extends AbstractKapuaEntityCreator implements KapuaUpdatableEntityCreator { - - protected String attributes; - - /** - * Constructor. - * - * @param scopeId The scope {@link KapuaId} to set to in the {@link KapuaUpdatableEntityCreator} - * @since 1.0.0 - */ - public AbstractKapuaUpdatableEntityCreator(KapuaId scopeId) { - super(scopeId); - } - - @Override - public Properties getEntityAttributes() { - try { - return PropertiesUtils.readPropertiesFromString(attributes); - } catch (IOException e) { - throw new EntityPropertiesReadException(e, "attributes", attributes); - } - } - - @Override - public void setEntityAttributes(Properties attributes) { - try { - this.attributes = PropertiesUtils.writePropertiesToString(attributes); - } catch (IOException e) { - throw new EntityPropertiesWriteException(e, "attributes", attributes); - } - } -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/mappers/KapuaBaseMapper.java b/commons/src/main/java/org/eclipse/kapua/commons/model/mappers/KapuaBaseMapper.java index f66f1103711..9bfbdb6c6c5 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/mappers/KapuaBaseMapper.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/model/mappers/KapuaBaseMapper.java @@ -41,6 +41,8 @@ public interface KapuaBaseMapper { @Mapping(target = "modifiedOn", ignore = true) @Mapping(target = "modifiedBy", ignore = true) @Mapping(target = "optlock", ignore = true) + @Mapping(target = "entityProperties", ignore = true) + @Mapping(target = "entityAttributes", ignore = true) @IgnoreKapuaEntityReadonlyFields public @interface IgnoreKapuaUpdatableEntityReadonlyFields { diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/query/AbstractKapuaForwardableEntityQuery.java b/commons/src/main/java/org/eclipse/kapua/commons/model/query/AbstractKapuaForwardableEntityQuery.java deleted file mode 100644 index 40b0954c96c..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/query/AbstractKapuaForwardableEntityQuery.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2024, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.model.query; - -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.model.query.KapuaForwardableEntityQuery; -import org.eclipse.kapua.model.query.KapuaQuery; - -public class AbstractKapuaForwardableEntityQuery extends AbstractKapuaNamedQuery implements KapuaForwardableEntityQuery { - - protected Boolean includeInherited = Boolean.FALSE; - - /** - * Constructor. - * - */ - public AbstractKapuaForwardableEntityQuery() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - */ - public AbstractKapuaForwardableEntityQuery(KapuaId scopeId) { - super(scopeId); - } - - /** - * Clone constructor. - * - * @param query The {@link AbstractKapuaForwardableEntityQuery} to clone. - */ - public AbstractKapuaForwardableEntityQuery(KapuaQuery query) { - super(query); - if(query instanceof KapuaForwardableEntityQuery) { - this.includeInherited = ((KapuaForwardableEntityQuery) query).getIncludeInherited(); - } - } - - @Override - public Boolean getIncludeInherited() { - return includeInherited; - } - - @Override - public void setIncludeInherited(Boolean includeInherited) { - this.includeInherited = includeInherited; - } -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/query/AbstractKapuaQuery.java b/commons/src/main/java/org/eclipse/kapua/commons/model/query/AbstractKapuaQuery.java deleted file mode 100644 index bcbb7588a10..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/query/AbstractKapuaQuery.java +++ /dev/null @@ -1,206 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.model.query; - -import org.eclipse.kapua.commons.model.id.KapuaEid; -import org.eclipse.kapua.commons.model.query.predicate.AndPredicateImpl; -import org.eclipse.kapua.commons.model.query.predicate.AttributePredicateImpl; -import org.eclipse.kapua.commons.model.query.predicate.OrPredicateImpl; -import org.eclipse.kapua.model.KapuaEntityAttributes; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.model.query.FieldSortCriteria; -import org.eclipse.kapua.model.query.KapuaQuery; -import org.eclipse.kapua.model.query.KapuaSortCriteria; -import org.eclipse.kapua.model.query.SortOrder; -import org.eclipse.kapua.model.query.predicate.AndPredicate; -import org.eclipse.kapua.model.query.predicate.AttributePredicate; -import org.eclipse.kapua.model.query.predicate.OrPredicate; -import org.eclipse.kapua.model.query.predicate.QueryPredicate; - -import javax.validation.constraints.NotNull; -import java.util.ArrayList; -import java.util.List; - -/** - * {@link KapuaQuery} {@code abstract} implementation. - * - * @since 1.0.0 - */ -public abstract class AbstractKapuaQuery implements KapuaQuery { - - private KapuaId scopeId; - - private QueryPredicate predicate; - private KapuaSortCriteria sortCriteria; - private List fetchAttributes; - - private Integer offset; - private Integer limit; - private Boolean askTotalCount; - - /** - * Constructor. - * - * @since 1.0.0 - */ - public AbstractKapuaQuery() { - } - - /** - * Constructor. - * - * @param scopeId The scope {@link KapuaId} of the {@link KapuaQuery} - * @since 1.0.0 - */ - public AbstractKapuaQuery(KapuaId scopeId) { - this(); - - setScopeId(scopeId); - } - - /** - * Constructor. - * - * It deeply clones the given {@link KapuaQuery} - * - * @param query the query to clone. - */ - public AbstractKapuaQuery(@NotNull KapuaQuery query) { - setFetchAttributes(query.getFetchAttributes()); - setPredicate(query.getPredicate()); - setLimit(query.getLimit()); - setOffset(query.getOffset()); - setSortCriteria(query.getSortCriteria()); - setAskTotalCount(query.getAskTotalCount()); - } - - @Override - public KapuaId getScopeId() { - return scopeId; - } - - @Override - public void setScopeId(KapuaId scopeId) { - this.scopeId = KapuaEid.parseKapuaId(scopeId); - } - - @Override - public void addFetchAttributes(String fetchAttribute) { - getFetchAttributes().add(fetchAttribute); - } - - @Override - public List
getFetchAttributes() { - if (fetchAttributes == null) { - fetchAttributes = new ArrayList<>(); - } - - return fetchAttributes; - } - - @Override - public void setFetchAttributes(List fetchAttributes) { - this.fetchAttributes = fetchAttributes; - } - - @Override - public QueryPredicate getPredicate() { - return this.predicate; - } - - @Override - public void setPredicate(QueryPredicate queryPredicate) { - this.predicate = queryPredicate; - } - - @Override - public KapuaSortCriteria getSortCriteria() { - return sortCriteria; - } - - @Override - public void setSortCriteria(KapuaSortCriteria sortCriteria) { - this.sortCriteria = sortCriteria; - } - - @Override - public KapuaSortCriteria getDefaultSortCriteria() { - return fieldSortCriteria(KapuaEntityAttributes.ENTITY_ID, SortOrder.ASCENDING); - } - - @Override - public Integer getOffset() { - return offset; - } - - @Override - public void setOffset(Integer offset) { - this.offset = offset; - } - - @Override - public Integer getLimit() { - return limit; - } - - @Override - public void setLimit(Integer limit) { - this.limit = limit; - } - - @Override - public Boolean getAskTotalCount() { - return askTotalCount; - } - - @Override - public void setAskTotalCount(Boolean askTotalCount) { - this.askTotalCount = askTotalCount; - } - - // Predicate factory - @Override - public AttributePredicate attributePredicate(String attributeName, T attributeValue) { - return new AttributePredicateImpl<>(attributeName, attributeValue); - } - - @Override - public AttributePredicate attributePredicate(String attributeName, T attributeValue, AttributePredicate.Operator operator) { - return new AttributePredicateImpl<>(attributeName, attributeValue, operator); - } - - @Override - public AndPredicate andPredicate() { - return new AndPredicateImpl(); - } - - @Override - public AndPredicate andPredicate(QueryPredicate... queryPredicates) { - return new AndPredicateImpl(queryPredicates); - } - - @Override - public OrPredicate orPredicate() { - return new OrPredicateImpl(); - } - - @Override - public OrPredicate orPredicate(QueryPredicate... queryPredicates) { - return new OrPredicateImpl(queryPredicates); - } - - @Override - public FieldSortCriteria fieldSortCriteria(String attributeName, SortOrder sortOrder) { - return new FieldSortCriteriaImpl(attributeName, sortOrder); - } -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/query/FieldSortCriteriaImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/model/query/FieldSortCriteriaImpl.java deleted file mode 100644 index b5f08a94f84..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/query/FieldSortCriteriaImpl.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.model.query; - -import org.eclipse.kapua.model.query.FieldSortCriteria; -import org.eclipse.kapua.model.query.SortOrder; - -/** - * Field sort criteria. - * - * @since 1.0 - * - */ -public class FieldSortCriteriaImpl implements FieldSortCriteria { - - /** - * Field attribute name - */ - private String attributeName; - - /** - * Field sort order - */ - private SortOrder sortOrder; - - /** - * Constructor - * - * @param attributeName - * @param sortOrder - */ - public FieldSortCriteriaImpl(String attributeName, SortOrder sortOrder) { - this.attributeName = attributeName; - this.sortOrder = sortOrder; - } - - /** - * Get the sort attribute name - * - * @return - */ - @Override - public String getAttributeName() { - return attributeName; - } - - /** - * Get the sort attribute order - * - * @return - */ - @Override - public SortOrder getSortOrder() { - return sortOrder; - } -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/query/KapuaListResultImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/model/query/KapuaListResultImpl.java deleted file mode 100644 index 3ff330435d3..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/query/KapuaListResultImpl.java +++ /dev/null @@ -1,134 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.model.query; - -import org.eclipse.kapua.model.KapuaEntity; -import org.eclipse.kapua.model.query.KapuaListResult; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -/** - * {@link KapuaListResult} implementation. - * - * @param {@link KapuaEntity} type. - * @since 1.0.0 - */ -public class KapuaListResultImpl implements KapuaListResult { - - private static final long serialVersionUID = 8939666089540269261L; - - private ArrayList items; - private boolean limitExceeded; - private Long totalCount; - - /** - * Constructor. - * - * @since 1.0.0 - */ - public KapuaListResultImpl() { - limitExceeded = false; - } - - @Override - public boolean isLimitExceeded() { - return limitExceeded; - } - - @Override - public void setLimitExceeded(boolean limitExceeded) { - this.limitExceeded = limitExceeded; - } - - @Override - public List getItems() { - if (items == null) { - items = new ArrayList<>(); - } - - return items; - } - - @Override - public List getItems(Predicate filter) { - return getItems().stream().filter(filter).collect(Collectors.toList()); - } - - @Override - public Map getItemsAsMap(Function keyMapper) { - return getItems().stream().collect(Collectors.toMap(keyMapper, e -> e)); - } - - @Override - public Map getItemsAsMap(Function keyMapper, Function valueMapper) { - return getItems().stream().collect(Collectors.toMap(keyMapper, valueMapper)); - } - - @Override - public E getItem(int index) { - return getItems().get(index); - } - - @Override - public E getFirstItem() { - return this.isEmpty() ? null : getItem(0); - } - - @Override - public int getSize() { - return getItems().size(); - } - - @Override - public boolean isEmpty() { - return getItems().isEmpty(); - } - - @Override - public void addItems(Collection extends E> items) { - getItems().addAll(items); - } - - @Override - public void addItem(E item) { - getItems().add(item); - } - - @Override - public void clearItems() { - getItems().clear(); - } - - @Override - public void sort(Comparator comparator) { - getItems().sort(comparator); - } - - @Override - public Long getTotalCount() { - return totalCount; - } - - @Override - public void setTotalCount(Long totalCount) { - this.totalCount = totalCount; - } - -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/query/QueryFactoryImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/model/query/QueryFactoryImpl.java deleted file mode 100644 index ee03bb26e2b..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/query/QueryFactoryImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.model.query; - -import org.eclipse.kapua.model.query.KapuaQuery; -import org.eclipse.kapua.model.query.QueryFactory; - -import javax.inject.Singleton; - -/** - * {@link QueryFactory} implementation. - * - * @since 2.0.0 - */ -@Singleton -public class QueryFactoryImpl implements QueryFactory { - - @Override - public KapuaQuery newQuery() { - return new AbstractKapuaQuery() { - }; - } -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/AndPredicateImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/AndPredicateImpl.java deleted file mode 100644 index a07c30cc5a2..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/AndPredicateImpl.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.model.query.predicate; - -import com.google.common.collect.Lists; -import org.eclipse.kapua.model.query.predicate.AndPredicate; -import org.eclipse.kapua.model.query.predicate.QueryPredicate; - -import javax.validation.constraints.NotNull; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -/** - * {@link AndPredicate} implementation. - * - * @since 1.0.0 - */ -public class AndPredicateImpl implements AndPredicate { - - private List predicates; - - /** - * Constructor. - * - * @since 1.0.0 - */ - public AndPredicateImpl() { - setPredicates(new ArrayList<>()); - } - - /** - * Constructor which accepts a not null array of {@link QueryPredicate}s. - * - * @param predicates the {@link QueryPredicate}s to add. - * @throws NullPointerException if the given parameter is {@code null}. - * @since 1.0.0 - */ - public AndPredicateImpl(@NotNull QueryPredicate... predicates) { - Objects.requireNonNull(predicates); - - setPredicates(Lists.newArrayList(predicates)); - } - - @Override - public AndPredicateImpl and(@NotNull QueryPredicate predicate) { - Objects.requireNonNull(predicates); - - getPredicates().add(predicate); - - return this; - } - - @Override - public List getPredicates() { - return this.predicates; - } - - @Override - public void setPredicates(List predicates) { - this.predicates = predicates; - } -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/AttributePredicateImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/AttributePredicateImpl.java deleted file mode 100644 index bca11012e26..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/AttributePredicateImpl.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.model.query.predicate; - -import org.eclipse.kapua.model.query.predicate.AttributePredicate; - -/** - * {@link AttributePredicate} implementation. - * - * @since 1.0.0 - */ -public class AttributePredicateImpl implements AttributePredicate { - - private String attributeName; - private T attributeValue; - private Operator operator; - - /** - * Constructor. - * - * Defaults ot {@link org.eclipse.kapua.model.query.predicate.AttributePredicate.Operator#EQUAL} - * - * @param attributeName The name of {@link org.eclipse.kapua.model.KapuaEntityAttributes} to set into the {@link AttributePredicate}. - * @param attributeValue The value of {@link org.eclipse.kapua.model.KapuaEntityAttributes} to set into the {@link AttributePredicate}. - * @since 1.0.0 - */ - public AttributePredicateImpl(String attributeName, T attributeValue) { - this(attributeName, attributeValue, Operator.EQUAL); - } - - /** - * Constructor. - * - * @param attributeName The name of {@link org.eclipse.kapua.model.KapuaEntityAttributes} to set into the {@link AttributePredicate}. - * @param attributeValue The value of {@link org.eclipse.kapua.model.KapuaEntityAttributes} to set into the {@link AttributePredicate}. - * @param operator The {@link org.eclipse.kapua.model.query.predicate.AttributePredicate.Operator} to set into the {@link AttributePredicate}. - * @since 1.0.0 - */ - public AttributePredicateImpl(String attributeName, T attributeValue, Operator operator) { - this.attributeName = attributeName; - this.attributeValue = attributeValue; - this.operator = operator; - } - - @Override - public String getAttributeName() { - return attributeName; - } - - @Override - public T getAttributeValue() { - return attributeValue; - } - - @Override - public Operator getOperator() { - return operator; - } - -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/OrPredicateImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/OrPredicateImpl.java deleted file mode 100644 index 579e51c40de..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/OrPredicateImpl.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2018, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.model.query.predicate; - -import com.google.common.collect.Lists; -import org.eclipse.kapua.model.query.predicate.OrPredicate; -import org.eclipse.kapua.model.query.predicate.QueryPredicate; - -import javax.validation.constraints.NotNull; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -/** - * {@link OrPredicate} implementation. - * - * @since 1.0.0 - */ -public class OrPredicateImpl implements OrPredicate { - - private List
predicates; - - /** - * Constructor. - * - * @since 1.0.0 - */ - public OrPredicateImpl() { - setPredicates(new ArrayList<>()); - } - - /** - * Constructor which accepts a not {@code null} array of {@link QueryPredicate}s. - * - * @param predicates the {@link QueryPredicate}s to add. - * @throws NullPointerException if the given parameter is {@code null}. - * @since 1.0.0 - */ - public OrPredicateImpl(@NotNull QueryPredicate... predicates) { - Objects.requireNonNull(predicates); - - setPredicates(Lists.newArrayList(predicates)); - } - - @Override - public OrPredicateImpl or(@NotNull QueryPredicate predicate) { - Objects.requireNonNull(predicates); - - getPredicates().add(predicate); - - return this; - } - - @Override - public List getPredicates() { - return this.predicates; - } - - @Override - public void setPredicates(List predicates) { - this.predicates = predicates; - } -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreFactory.java b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreFactory.java index d26edcfbaca..80843bbbd1b 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreFactory.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreFactory.java @@ -20,6 +20,6 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface EventStoreFactory extends KapuaEntityFactory { +public interface EventStoreFactory extends KapuaEntityFactory { } diff --git a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreRecordCreator.java b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreRecordCreator.java index 196599158c4..b78b5766229 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreRecordCreator.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreRecordCreator.java @@ -13,7 +13,20 @@ package org.eclipse.kapua.commons.service.event.store.api; import org.eclipse.kapua.model.KapuaEntityCreator; +import org.eclipse.kapua.model.id.KapuaId; -public interface EventStoreRecordCreator extends KapuaEntityCreator { +public class EventStoreRecordCreator extends KapuaEntityCreator { + private static final long serialVersionUID = 1048699703033893534L; + + public EventStoreRecordCreator() { + } + + public EventStoreRecordCreator(KapuaId scopeId) { + super(scopeId); + } + + public EventStoreRecordCreator(KapuaEntityCreator entityCreator) { + super(entityCreator); + } } diff --git a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreRecordListResult.java b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreRecordListResult.java index 1ca0de04f84..604c3b771ea 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreRecordListResult.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreRecordListResult.java @@ -23,11 +23,12 @@ * KapuaEvent result list definition. * * @since 1.0 - * */ @XmlRootElement(name = "eventStoreRecords") @XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = EventStoreXmlRegistry.class,factoryMethod = "newEventStoreRecordListResult") -public interface EventStoreRecordListResult extends KapuaListResult { +@XmlType +public class EventStoreRecordListResult extends KapuaListResult { + + private static final long serialVersionUID = -5118004898345748297L; } diff --git a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreRecordQuery.java b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreRecordQuery.java index 9f359cf8d18..6f05c3403c3 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreRecordQuery.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreRecordQuery.java @@ -12,13 +12,14 @@ *******************************************************************************/ package org.eclipse.kapua.commons.service.event.store.api; -import org.eclipse.kapua.model.query.KapuaQuery; - import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; + /** * {@link EventStoreRecord} {@link KapuaQuery} definition. * @@ -27,6 +28,27 @@ */ @XmlRootElement(name = "query") @XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = EventStoreXmlRegistry.class, factoryMethod = "newQuery") -public interface EventStoreRecordQuery extends KapuaQuery { +@XmlType +public class EventStoreRecordQuery extends KapuaQuery { + + /** + * Constructor. + * + * @since 1.0.0 + */ + public EventStoreRecordQuery() { + super(); + } + + /** + * Constructor. + * + * @param scopeId + * The {@link #getScopeId()}. + * @since 1.0.0 + */ + public EventStoreRecordQuery(KapuaId scopeId) { + this(); + setScopeId(scopeId); + } } diff --git a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreXmlRegistry.java b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreXmlRegistry.java index 39fd356fa6b..4a53749ef2a 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreXmlRegistry.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreXmlRegistry.java @@ -12,10 +12,10 @@ *******************************************************************************/ package org.eclipse.kapua.commons.service.event.store.api; -import org.eclipse.kapua.commons.service.event.store.internal.EventStoreFactoryImpl; - import javax.xml.bind.annotation.XmlRegistry; +import org.eclipse.kapua.commons.service.event.store.internal.EventStoreFactoryImpl; + @XmlRegistry public class EventStoreXmlRegistry { @@ -29,27 +29,4 @@ public class EventStoreXmlRegistry { public EventStoreRecord newEventStoreRecord() { return kapuaEventFactory.newEntity(null); } - - /** - * Creates a new kapuaEvent creator instance - * - * @return - */ - public EventStoreRecordCreator newEventStoreRecordCreator() { - return kapuaEventFactory.newCreator(null); - } - - /** - * Creates a new kapuaEvent list result instance - * - * @return - */ - public EventStoreRecordListResult newEventStoreRecordListResult() { - return kapuaEventFactory.newListResult(); - } - - public EventStoreRecordQuery newQuery() { - return kapuaEventFactory.newQuery(null); - } - } diff --git a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreFactoryImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreFactoryImpl.java index e5622dfc59c..53543b4f33d 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreFactoryImpl.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreFactoryImpl.java @@ -12,16 +12,13 @@ *******************************************************************************/ package org.eclipse.kapua.commons.service.event.store.internal; +import javax.inject.Singleton; + import org.eclipse.kapua.KapuaEntityCloneException; import org.eclipse.kapua.commons.service.event.store.api.EventStoreFactory; import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecord; -import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordCreator; -import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordListResult; -import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordQuery; import org.eclipse.kapua.model.id.KapuaId; -import javax.inject.Singleton; - /** * {@link EventStoreFactory} implementation * @@ -35,21 +32,6 @@ public EventStoreRecord newEntity(KapuaId scopeId) { return new EventStoreRecordImpl(scopeId); } - @Override - public EventStoreRecordCreator newCreator(KapuaId scopeId) { - return new EventStoreRecordCreatorImpl(scopeId); - } - - @Override - public EventStoreRecordQuery newQuery(KapuaId scopeId) { - return new EventStoreQueryImpl(scopeId); - } - - @Override - public EventStoreRecordListResult newListResult() { - return new EventStoreRecordListResultImpl(); - } - @Override public EventStoreRecord clone(EventStoreRecord eventStoreRecord) { try { diff --git a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreQueryImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreQueryImpl.java deleted file mode 100644 index b50c177ccc4..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreQueryImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.service.event.store.internal; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaQuery; -import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordQuery; -import org.eclipse.kapua.model.id.KapuaId; - -/** - * {@link EventStoreRecordQuery} implementation. - * - * @since 1.0.0 - */ -public class EventStoreQueryImpl extends AbstractKapuaQuery implements EventStoreRecordQuery { - - /** - * Constructor. - * - * @since 1.0.0 - */ - public EventStoreQueryImpl() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public EventStoreQueryImpl(KapuaId scopeId) { - this(); - setScopeId(scopeId); - } -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreRecordCreatorImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreRecordCreatorImpl.java deleted file mode 100644 index 63057c711d6..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreRecordCreatorImpl.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.service.event.store.internal; - -import org.eclipse.kapua.commons.model.AbstractKapuaEntityCreator; -import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecord; -import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordCreator; -import org.eclipse.kapua.model.id.KapuaId; - -/** - * KapuaEvent creator service implementation. - * - * @since 1.0 - * - */ -public class EventStoreRecordCreatorImpl extends AbstractKapuaEntityCreator implements EventStoreRecordCreator { - - private static final long serialVersionUID = 1048699703033893534L; - - /** - * Constructor - * - * @param scopeId - */ - public EventStoreRecordCreatorImpl(KapuaId scopeId) { - super(scopeId); - } - -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreRecordImplJpaRepository.java b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreRecordImplJpaRepository.java index 10363ed304a..67b965941f6 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreRecordImplJpaRepository.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreRecordImplJpaRepository.java @@ -21,9 +21,9 @@ public class EventStoreRecordImplJpaRepository extends KapuaUpdatableEntityJpaRepository implements EventStoreRecordRepository { + public EventStoreRecordImplJpaRepository(KapuaJpaRepositoryConfiguration jpaRepoConfig) { - super(EventStoreRecordImpl.class, EventStoreRecord.TYPE, () -> new EventStoreRecordListResultImpl(), jpaRepoConfig); + super(EventStoreRecordImpl.class, EventStoreRecord.TYPE, () -> new EventStoreRecordListResult(), jpaRepoConfig); } - } diff --git a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreRecordListResultImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreRecordListResultImpl.java deleted file mode 100644 index 38ed77fbcc8..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreRecordListResultImpl.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.service.event.store.internal; - -import org.eclipse.kapua.commons.model.query.KapuaListResultImpl; -import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecord; -import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordListResult; - -/** - * KapuaEvent list result implementation. - * - * @since 1.0 - */ -public class EventStoreRecordListResultImpl extends KapuaListResultImpl implements EventStoreRecordListResult { - - private static final long serialVersionUID = -5118004898345748297L; -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreServiceImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreServiceImpl.java index f4a1fa61807..fe6865cbb1c 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreServiceImpl.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreServiceImpl.java @@ -12,9 +12,10 @@ *******************************************************************************/ package org.eclipse.kapua.commons.service.event.store.internal; +import javax.inject.Inject; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.model.domains.Domains; -import org.eclipse.kapua.commons.service.event.store.api.EventStoreFactory; import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecord; import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordCreator; import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordListResult; @@ -27,11 +28,9 @@ import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.authorization.AuthorizationService; -import org.eclipse.kapua.service.authorization.permission.PermissionFactory; +import org.eclipse.kapua.service.authorization.permission.Permission; import org.eclipse.kapua.storage.TxManager; -import javax.inject.Inject; - /** * {@link EventStoreService} implementation. * @@ -41,22 +40,16 @@ public class EventStoreServiceImpl implements EventStoreService { private final AuthorizationService authorizationService; - private final PermissionFactory permissionFactory; private final TxManager txManager; - private final EventStoreFactory entityFactory; private final EventStoreRecordRepository repository; @Inject public EventStoreServiceImpl( AuthorizationService authorizationService, - PermissionFactory permissionFactory, TxManager txManager, - EventStoreFactory entityFactory, EventStoreRecordRepository repository) { this.authorizationService = authorizationService; - this.permissionFactory = permissionFactory; this.txManager = txManager; - this.entityFactory = entityFactory; this.repository = repository; } @@ -75,7 +68,7 @@ public EventStoreRecord update(EventStoreRecord kapuaEvent) // Validation of the fields ArgumentValidator.notNull(kapuaEvent.getId(), "kapuaEvent.id"); // Check Access - authorizationService.checkPermission(permissionFactory.newPermission(Domains.EVENT_STORE, Actions.write, kapuaEvent.getScopeId())); + authorizationService.checkPermission(new Permission(Domains.EVENT_STORE, Actions.write, kapuaEvent.getScopeId())); // Do update return txManager.execute(tx -> repository.update(tx, kapuaEvent)); } @@ -89,7 +82,7 @@ public void delete(KapuaId scopeId, KapuaId kapuaEventId) ArgumentValidator.notNull(kapuaEventId, KapuaEntityAttributes.ENTITY_ID); // Check Access Actions action = Actions.write; - authorizationService.checkPermission(permissionFactory.newPermission(Domains.EVENT_STORE, action, scopeId)); + authorizationService.checkPermission(new Permission(Domains.EVENT_STORE, action, scopeId)); // Do delete txManager.execute(tx -> repository.delete(tx, scopeId, kapuaEventId)); } @@ -101,7 +94,7 @@ public EventStoreRecord find(KapuaId scopeId, KapuaId kapuaEventId) ArgumentValidator.notNull(scopeId, KapuaEntityAttributes.SCOPE_ID); ArgumentValidator.notNull(kapuaEventId, KapuaEntityAttributes.ENTITY_ID); // Check Access - authorizationService.checkPermission(permissionFactory.newPermission(Domains.EVENT_STORE, Actions.read, scopeId)); + authorizationService.checkPermission(new Permission(Domains.EVENT_STORE, Actions.read, scopeId)); // Make sure kapuaEvent exists return txManager.execute(tx -> repository.find(tx, scopeId, kapuaEventId)) .orElse(null); @@ -113,7 +106,7 @@ public EventStoreRecord find(KapuaId kapuaEventId) // Validation of the fields ArgumentValidator.notNull(kapuaEventId, KapuaEntityAttributes.ENTITY_ID); // Check Access - authorizationService.checkPermission(permissionFactory.newPermission(Domains.EVENT_STORE, Actions.read, kapuaEventId)); + authorizationService.checkPermission(new Permission(Domains.EVENT_STORE, Actions.read, kapuaEventId)); return txManager.execute(tx -> repository.find(tx, KapuaId.ANY, kapuaEventId)) .orElse(null); @@ -124,7 +117,7 @@ public EventStoreRecordListResult query(KapuaQuery query) throws KapuaException { ArgumentValidator.notNull(query, "query"); // Check Access - authorizationService.checkPermission(permissionFactory.newPermission(Domains.EVENT_STORE, Actions.read, query.getScopeId())); + authorizationService.checkPermission(new Permission(Domains.EVENT_STORE, Actions.read, query.getScopeId())); return txManager.execute(tx -> repository.query(tx, query)); } @@ -133,7 +126,7 @@ public long count(KapuaQuery query) throws KapuaException { ArgumentValidator.notNull(query, "query"); // Check Access - authorizationService.checkPermission(permissionFactory.newPermission(Domains.EVENT_STORE, Actions.read, query.getScopeId())); + authorizationService.checkPermission(new Permission(Domains.EVENT_STORE, Actions.read, query.getScopeId())); return txManager.execute(tx -> repository.count(tx, query)); } } diff --git a/commons/src/main/java/org/eclipse/kapua/commons/service/internal/KapuaNamedEntityServiceUtils.java b/commons/src/main/java/org/eclipse/kapua/commons/service/internal/KapuaNamedEntityServiceUtils.java index 47ab5ce0c2a..c0816fad61a 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/service/internal/KapuaNamedEntityServiceUtils.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/service/internal/KapuaNamedEntityServiceUtils.java @@ -12,6 +12,11 @@ *******************************************************************************/ package org.eclipse.kapua.commons.service.internal; +import java.util.Collections; +import java.util.List; + +import javax.validation.constraints.NotNull; + import org.eclipse.kapua.KapuaDuplicateNameException; import org.eclipse.kapua.KapuaDuplicateNameInAnotherAccountError; import org.eclipse.kapua.KapuaException; @@ -21,16 +26,11 @@ import org.eclipse.kapua.model.KapuaNamedEntityAttributes; import org.eclipse.kapua.model.KapuaNamedEntityCreator; import org.eclipse.kapua.model.query.KapuaQuery; -import org.eclipse.kapua.model.query.QueryFactory; import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.model.query.predicate.AttributePredicate; import org.eclipse.kapua.model.query.predicate.QueryPredicate; import org.eclipse.kapua.service.KapuaEntityService; -import javax.validation.constraints.NotNull; -import java.util.Collections; -import java.util.List; - /** * Util class that offers checks on the {@link KapuaNamedEntity#getName()} uniqueness in different flavors. * @@ -41,7 +41,6 @@ public class KapuaNamedEntityServiceUtils { private static final KapuaLocator LOCATOR = KapuaLocator.getInstance(); - private static final QueryFactory QUERY_FACTORY = LOCATOR.getFactory(QueryFactory.class); /** * Constructor. @@ -56,36 +55,52 @@ private KapuaNamedEntityServiceUtils() { /** * Checks that the given {@link KapuaNamedEntityCreator#getName()} is unique within the {@link KapuaNamedEntityCreator#getScopeId()}. * - * @param kapuaNamedEntityService The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. - * @param creator The {@link KapuaNamedEntityCreator} to check. - * @param The {@link KapuaNamedEntity} type. - * @param The {@link KapuaNamedEntityCreator} type. - * @throws KapuaDuplicateNameException if the {@link KapuaNamedEntityCreator#getName()} is duplicated within the {@link KapuaNamedEntityCreator#getScopeId()}. - * @throws KapuaException if any other error occurs. + * @param kapuaNamedEntityService + * The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. + * @param creator + * The {@link KapuaNamedEntityCreator} to check. + * @param + * The {@link KapuaNamedEntity} type. + * @param + * The {@link KapuaNamedEntityCreator} type. + * @throws KapuaDuplicateNameException + * if the {@link KapuaNamedEntityCreator#getName()} is duplicated within the {@link KapuaNamedEntityCreator#getScopeId()}. + * @throws KapuaException + * if any other error occurs. * @since 2.0.0 * @deprecated since 2.0.0 - use {@link org.eclipse.kapua.storage.KapuaNamedEntityRepository} instead */ @Deprecated - public static > void checkEntityNameUniqueness(@NotNull KapuaEntityService kapuaNamedEntityService, @NotNull C creator) throws KapuaException { + public static void checkEntityNameUniqueness(@NotNull KapuaEntityService kapuaNamedEntityService, @NotNull C creator) + throws KapuaException { checkEntityNameUniqueness(kapuaNamedEntityService, creator, Collections.emptyList()); } /** - * Checks that the given {@link KapuaNamedEntityCreator#getName()} is unique within the {@link KapuaNamedEntityCreator#getScopeId()} with additional {@link QueryPredicate}s to customize the check. + * Checks that the given {@link KapuaNamedEntityCreator#getName()} is unique within the {@link KapuaNamedEntityCreator#getScopeId()} with additional {@link QueryPredicate}s to customize the + * check. * - * @param kapuaNamedEntityService The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. - * @param creator The {@link KapuaNamedEntityCreator} to check. - * @param additionalPredicates The additional {@link QueryPredicate}s to customize the check - * @param The {@link KapuaNamedEntity} type. - * @param The {@link KapuaNamedEntityCreator} type. - * @throws KapuaDuplicateNameException if the {@link KapuaNamedEntityCreator#getName()} is duplicated within the {@link KapuaNamedEntityCreator#getScopeId()}. - * @throws KapuaException if any other error occurs. + * @param kapuaNamedEntityService + * The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. + * @param creator + * The {@link KapuaNamedEntityCreator} to check. + * @param additionalPredicates + * The additional {@link QueryPredicate}s to customize the check + * @param + * The {@link KapuaNamedEntity} type. + * @param + * The {@link KapuaNamedEntityCreator} type. + * @throws KapuaDuplicateNameException + * if the {@link KapuaNamedEntityCreator#getName()} is duplicated within the {@link KapuaNamedEntityCreator#getScopeId()}. + * @throws KapuaException + * if any other error occurs. * @since 2.0.0 * @deprecated since 2.0.0 - use {@link org.eclipse.kapua.storage.KapuaNamedEntityRepository} instead */ @Deprecated - public static > void checkEntityNameUniqueness(@NotNull KapuaEntityService kapuaNamedEntityService, @NotNull C creator, @NotNull List additionalPredicates) throws KapuaException { - KapuaQuery query = QUERY_FACTORY.newQuery(); + public static void checkEntityNameUniqueness(@NotNull KapuaEntityService kapuaNamedEntityService, @NotNull C creator, + @NotNull List additionalPredicates) throws KapuaException { + KapuaQuery query = new KapuaQuery(); query.setScopeId(creator.getScopeId()); AndPredicate andPredicate = query.andPredicate(); @@ -105,11 +120,16 @@ public static > /** * Checks that the given {@link KapuaNamedEntity#getName()} is unique within the {@link KapuaNamedEntity#getScopeId()}. * - * @param kapuaNamedEntityService The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. - * @param entity The {@link KapuaNamedEntity} to check. - * @param The {@link KapuaNamedEntity} type. - * @throws KapuaDuplicateNameException if the {@link KapuaNamedEntity#getName()} is duplicated within the {@link KapuaNamedEntity#getScopeId()}. - * @throws KapuaException if any other error occurs. + * @param kapuaNamedEntityService + * The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. + * @param entity + * The {@link KapuaNamedEntity} to check. + * @param + * The {@link KapuaNamedEntity} type. + * @throws KapuaDuplicateNameException + * if the {@link KapuaNamedEntity#getName()} is duplicated within the {@link KapuaNamedEntity#getScopeId()}. + * @throws KapuaException + * if any other error occurs. * @since 2.0.0 * @deprecated since 2.0.0 - use {@link org.eclipse.kapua.storage.KapuaNamedEntityRepository} instead */ @@ -121,18 +141,25 @@ public static void checkEntityNameUniqueness(@NotNu /** * Checks that the given {@link KapuaNamedEntity#getName()} is unique within the {@link KapuaNamedEntity#getScopeId()} with additional {@link QueryPredicate}s to customize the check. * - * @param kapuaNamedEntityService The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. - * @param entity The {@link KapuaNamedEntity} to check. - * @param additionalPredicates The additional {@link QueryPredicate}s to customize the check - * @param The {@link KapuaNamedEntity} type. - * @throws KapuaDuplicateNameException if the {@link KapuaNamedEntity#getName()} is duplicated within the {@link KapuaNamedEntity#getScopeId()}. - * @throws KapuaException if any other error occurs. + * @param kapuaNamedEntityService + * The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. + * @param entity + * The {@link KapuaNamedEntity} to check. + * @param additionalPredicates + * The additional {@link QueryPredicate}s to customize the check + * @param + * The {@link KapuaNamedEntity} type. + * @throws KapuaDuplicateNameException + * if the {@link KapuaNamedEntity#getName()} is duplicated within the {@link KapuaNamedEntity#getScopeId()}. + * @throws KapuaException + * if any other error occurs. * @since 2.0.0 * @deprecated since 2.0.0 - use {@link org.eclipse.kapua.storage.KapuaNamedEntityRepository} instead */ @Deprecated - public static void checkEntityNameUniqueness(@NotNull KapuaEntityService kapuaNamedEntityService, @NotNull E entity, @NotNull List additionalPredicates) throws KapuaException { - KapuaQuery query = QUERY_FACTORY.newQuery(); + public static void checkEntityNameUniqueness(@NotNull KapuaEntityService kapuaNamedEntityService, @NotNull E entity, + @NotNull List additionalPredicates) throws KapuaException { + KapuaQuery query = new KapuaQuery(); query.setScopeId(entity.getScopeId()); AndPredicate andPredicate = query.andPredicate(); @@ -153,18 +180,25 @@ public static void checkEntityNameUniqueness(@NotNu /** * Checks that the given {@link KapuaNamedEntityCreator#getName()} is unique within all the scopes. * - * @param kapuaNamedEntityService The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. - * @param creator The {@link KapuaNamedEntityCreator} to check. - * @param The {@link KapuaNamedEntity} type. - * @param The {@link KapuaNamedEntityCreator} type. - * @throws KapuaDuplicateNameException if the {@link KapuaNamedEntityCreator#getName()} is duplicated within all the scopes - * @throws KapuaException if any other error occurs. + * @param kapuaNamedEntityService + * The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. + * @param creator + * The {@link KapuaNamedEntityCreator} to check. + * @param + * The {@link KapuaNamedEntity} type. + * @param + * The {@link KapuaNamedEntityCreator} type. + * @throws KapuaDuplicateNameException + * if the {@link KapuaNamedEntityCreator#getName()} is duplicated within all the scopes + * @throws KapuaException + * if any other error occurs. * @since 2.0.0 * @deprecated since 2.0.0 - use {@link org.eclipse.kapua.storage.KapuaNamedEntityRepository} instead */ @Deprecated - public static > void checkEntityNameUniquenessInAllScopes(@NotNull KapuaEntityService kapuaNamedEntityService, @NotNull C creator) throws KapuaException { - KapuaQuery query = QUERY_FACTORY.newQuery(); + public static void checkEntityNameUniquenessInAllScopes(@NotNull KapuaEntityService kapuaNamedEntityService, + @NotNull C creator) throws KapuaException { + KapuaQuery query = new KapuaQuery(); query.setPredicate(query.attributePredicate(KapuaNamedEntityAttributes.NAME, creator.getName())); if (KapuaSecurityUtils.doPrivileged(() -> kapuaNamedEntityService.count(query) > 0)) { @@ -175,17 +209,22 @@ public static > /** * Checks that the given {@link KapuaNamedEntity#getName()} is unique within all the scopes. * - * @param kapuaNamedEntityService The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. - * @param entity The {@link KapuaNamedEntity} to check. - * @param The {@link KapuaNamedEntity} type. - * @throws KapuaDuplicateNameException if the {@link KapuaNamedEntity#getName()} is duplicated within all the scopes - * @throws KapuaException if any other error occurs. + * @param kapuaNamedEntityService + * The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. + * @param entity + * The {@link KapuaNamedEntity} to check. + * @param + * The {@link KapuaNamedEntity} type. + * @throws KapuaDuplicateNameException + * if the {@link KapuaNamedEntity#getName()} is duplicated within all the scopes + * @throws KapuaException + * if any other error occurs. * @since 2.0.0 * @deprecated since 2.0.0 - use {@link org.eclipse.kapua.storage.KapuaNamedEntityRepository} instead */ @Deprecated public static void checkEntityNameUniquenessInAllScopes(@NotNull KapuaEntityService kapuaNamedEntityService, @NotNull E entity) throws KapuaException { - KapuaQuery query = QUERY_FACTORY.newQuery(); + KapuaQuery query = new KapuaQuery(); query.setPredicate( query.andPredicate( query.attributePredicate(KapuaNamedEntityAttributes.NAME, entity.getName()), 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..ee179add2f1 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,7 +12,32 @@ *******************************************************************************/ 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; @@ -23,8 +48,6 @@ import org.eclipse.kapua.commons.jpa.EntityManager; import org.eclipse.kapua.commons.model.AbstractKapuaUpdatableEntity; import org.eclipse.kapua.commons.model.id.KapuaEid; -import org.eclipse.kapua.commons.model.query.predicate.AttributePredicateImpl; -import org.eclipse.kapua.commons.model.query.predicate.OrPredicateImpl; import org.eclipse.kapua.commons.security.KapuaSecurityUtils; import org.eclipse.kapua.commons.security.KapuaSession; import org.eclipse.kapua.commons.setting.system.SystemSetting; @@ -69,30 +92,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,8 +169,10 @@ 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 */ @@ -199,11 +201,15 @@ 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 { @@ -231,10 +237,14 @@ 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) { @@ -263,76 +273,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) { + @NonNull Class clazz, + @NonNull 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) { + @NonNull Class clazz, + @NonNull KapuaId scopeId, + @NonNull 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) { + @NonNull Class clazz, + @NonNull String name, + @NonNull 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) { + @NonNull Class clazz, + @NonNull KapuaId scopeId, + @NonNull String name, + @NonNull Object value) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery criteriaSelectQuery = cb.createQuery(clazz); @@ -371,32 +401,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) + @NonNull Class interfaceClass, + @NonNull Class implementingClass, + @NonNull L resultContainer, + @NonNull KapuaQuery kapuaQuery) throws KapuaException { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery criteriaSelectQuery = cb.createQuery(implementingClass); @@ -506,18 +542,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) + @NonNull Class interfaceClass, + @NonNull Class implementingClass, + @NonNull KapuaQuery kapuaQuery) throws KapuaException { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery criteriaSelectQuery = cb.createQuery(Long.class); @@ -573,12 +614,17 @@ 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) @@ -617,19 +663,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) + @NonNull Map binds, + @NonNull CriteriaBuilder cb, + @NonNull Root userPermissionRoot, + @NonNull EntityType entityType) throws KapuaException { Predicate predicate = null; if (queryPredicate instanceof AttributePredicate) { @@ -643,9 +695,9 @@ private static Predicate handleKapuaQueryPredicates(@NonNull QueryPredicate predicate = handleOrPredicate(orPredicate, binds, cb, userPermissionRoot, entityType); } else if (queryPredicate instanceof MatchPredicate) { MatchPredicate> matchPredicate = (MatchPredicate>) queryPredicate; - OrPredicate orPredicate = new OrPredicateImpl(); + OrPredicate orPredicate = new OrPredicate(); for (String attributeName : matchPredicate.getAttributeNames()) { - orPredicate.getPredicates().add(new AttributePredicateImpl<>(attributeName, matchPredicate.getMatchTerm(), Operator.STARTS_WITH_IGNORE_CASE)); + orPredicate.getPredicates().add(new AttributePredicate<>(attributeName, matchPredicate.getMatchTerm(), Operator.STARTS_WITH_IGNORE_CASE)); } predicate = handleOrPredicate(orPredicate, binds, cb, userPermissionRoot, entityType); } @@ -653,10 +705,10 @@ private static Predicate handleKapuaQueryPredicates(@NonNull QueryPredicate } private static Predicate handleAndPredicate(@NonNull AndPredicate andPredicate, - @NonNull Map binds, - @NonNull CriteriaBuilder cb, - @NonNull Root entityRoot, - @NonNull EntityType entityType) + @NonNull Map binds, + @NonNull CriteriaBuilder cb, + @NonNull Root entityRoot, + @NonNull EntityType entityType) throws KapuaException { Predicate[] jpaAndPredicates = @@ -672,10 +724,10 @@ 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) + @NonNull Map binds, + @NonNull CriteriaBuilder cb, + @NonNull Root entityRoot, + @NonNull EntityType entityType) throws KapuaException { Predicate[] jpaOrPredicates = @@ -690,10 +742,10 @@ private static Predicate handleOrPredicate(@NonNull OrPredicate orPredicate, } private static Predicate[] handlePredicate(@NonNull List orPredicates, - @NonNull Map binds, - @NonNull CriteriaBuilder cb, - @NonNull Root entityRoot, - @NonNull EntityType entityType) throws KapuaException { + @NonNull Map binds, + @NonNull CriteriaBuilder cb, + @NonNull Root entityRoot, + @NonNull EntityType entityType) throws KapuaException { Predicate[] jpaOrPredicates = new Predicate[orPredicates.size()]; for (int i = 0; i < orPredicates.size(); i++) { @@ -704,10 +756,10 @@ private static Predicate[] handlePredicate(@NonNull List orP } private static Predicate handleAttributePredicate(@NonNull AttributePredicate> attrPred, - @NonNull Map binds, - @NonNull CriteriaBuilder cb, - @NonNull Root entityRoot, - @NonNull EntityType entityType) + @NonNull Map binds, + @NonNull CriteriaBuilder cb, + @NonNull Root entityRoot, + @NonNull EntityType entityType) throws KapuaException { Predicate expr; String attrName = attrPred.getAttributeName(); @@ -753,88 +805,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 extends Comparable> 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 extends Comparable> 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 extends Comparable> 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 extends Comparable> 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 extends Comparable> 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 extends Comparable> 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 extends Comparable> 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 extends Comparable> 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,8 +899,10 @@ 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 */ @@ -870,9 +924,12 @@ 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 { @@ -971,7 +1028,8 @@ 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 */ diff --git a/commons/src/main/java/org/eclipse/kapua/commons/service/internal/cache/EntityCache.java b/commons/src/main/java/org/eclipse/kapua/commons/service/internal/cache/EntityCache.java index f17db8d4930..481a90e69d7 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/service/internal/cache/EntityCache.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/service/internal/cache/EntityCache.java @@ -12,6 +12,10 @@ *******************************************************************************/ package org.eclipse.kapua.commons.service.internal.cache; +import java.io.Serializable; + +import javax.cache.Cache; + import org.eclipse.kapua.commons.metric.CommonsMetric; import org.eclipse.kapua.model.KapuaEntity; import org.eclipse.kapua.model.id.KapuaId; @@ -19,12 +23,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.cache.Cache; -import java.io.Serializable; - /** - * The basic cache class, it contains two {@link Cache} objects. - * The {@code idCache} cache contains {@link KapuaEntity} objects, while the {@code listsCache} contains {@link KapuaListResult} objects. + * The basic cache class, it contains two {@link Cache} objects. The {@code idCache} cache contains {@link KapuaEntity} objects, while the {@code listsCache} contains {@link KapuaListResult} objects. */ public class EntityCache { @@ -134,11 +134,13 @@ public KapuaListResult removeList(KapuaId scopeId, Serializable id) { } /** - * Checks that the scopeId of the entity matches the provided one. - * This mimics the checks that are performed in the 'find' method of the {@link org.eclipse.kapua.commons.jpa.KapuaEntityJpaRepository} class. + * Checks that the scopeId of the entity matches the provided one. This mimics the checks that are performed in the 'find' method of the + * {@link org.eclipse.kapua.commons.jpa.KapuaEntityJpaRepository} class. * - * @param scopeId a {@link KapuaId} representing the scopeId - * @param entity the {@link KapuaEntity} to be checked + * @param scopeId + * a {@link KapuaId} representing the scopeId + * @param entity + * the {@link KapuaEntity} to be checked * @return the provided entity if it has the required scopeId, null otherwise */ protected KapuaEntity checkResult(KapuaId scopeId, KapuaEntity entity) { @@ -158,14 +160,16 @@ protected KapuaEntity checkResult(KapuaId scopeId, KapuaEntity entity) { } /** - * Checks that the scopeId of the entity matches the provided one. - * This mimics the checks that are performed in the 'find' method of the {@link org.eclipse.kapua.commons.jpa.KapuaEntityJpaRepository} class. + * Checks that the scopeId of the entity matches the provided one. This mimics the checks that are performed in the 'find' method of the + * {@link org.eclipse.kapua.commons.jpa.KapuaEntityJpaRepository} class. * - * @param scopeId a {@link KapuaId} representing the scopeId - * @param entity the {@link KapuaListResult} entity to be checked + * @param scopeId + * a {@link KapuaId} representing the scopeId + * @param entity + * the {@link KapuaListResult} entity to be checked * @return the provided entity if it has the required scopeId, null otherwise */ - protected KapuaListResult checkResult(KapuaId scopeId, KapuaListResult entity) { + protected KapuaListResult checkResult(KapuaId scopeId, KapuaListResult entity) { if (entity != null) { if (entity.getSize() == 0) { return entity; // If the list is empty, I want to return the empty list @@ -186,10 +190,14 @@ protected KapuaListResult checkResult(KapuaId scopeId, KapuaListResult entity) { /** * Handles logging for cache exceptions. * - * @param operation the name of the method/operation - * @param cacheName the name of the cache in which the operation is performed - * @param keyId the Id of the entry's key in the cache - * @param t the exception + * @param operation + * the name of the method/operation + * @param cacheName + * the name of the cache in which the operation is performed + * @param keyId + * the Id of the entry's key in the cache + * @param t + * the exception */ protected void cacheErrorLogger(String operation, String cacheName, Serializable keyId, Throwable t) { commonsMetric.getCacheError().inc(); diff --git a/commons/src/test/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationCreatorImplTest.java b/commons/src/test/java/org/eclipse/kapua/commons/configuration/ServiceConfigCreatorTest.java similarity index 92% rename from commons/src/test/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationCreatorImplTest.java rename to commons/src/test/java/org/eclipse/kapua/commons/configuration/ServiceConfigCreatorTest.java index 1ccb058a742..1a5b911beae 100644 --- a/commons/src/test/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationCreatorImplTest.java +++ b/commons/src/test/java/org/eclipse/kapua/commons/configuration/ServiceConfigCreatorTest.java @@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.kapua.commons.configuration; +import java.util.Properties; + import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.qa.markers.junit.JUnitTests; import org.junit.Assert; @@ -19,17 +21,15 @@ import org.junit.Test; import org.junit.experimental.categories.Category; -import java.util.Properties; - - @Category(JUnitTests.class) -public class ServiceConfigurationCreatorImplTest { - ServiceConfigCreatorImpl configCreator; +public class ServiceConfigCreatorTest { + + ServiceConfigCreator configCreator; @Before public void createInstanceOfClass() { KapuaId id = KapuaId.ONE; - configCreator = new ServiceConfigCreatorImpl(id); + configCreator = new ServiceConfigCreator(id); } @Test diff --git a/commons/src/test/java/org/eclipse/kapua/commons/configuration/ServiceConfigImplTest.java b/commons/src/test/java/org/eclipse/kapua/commons/configuration/ServiceConfigImplTest.java deleted file mode 100644 index dc430321e74..00000000000 --- a/commons/src/test/java/org/eclipse/kapua/commons/configuration/ServiceConfigImplTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2020, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.configuration; - -import org.eclipse.kapua.KapuaException; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.qa.markers.junit.JUnitTests; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import java.util.Properties; - - -@Category(JUnitTests.class) -public class ServiceConfigImplTest { - ServiceConfigImpl serviceConfigImpl; - - @Before - public void createInstenceOfClass() { - KapuaId id = KapuaId.ONE; - serviceConfigImpl = new ServiceConfigImpl(id); - } - - @Test - public void constructorWithNoValuesTest() { - ServiceConfigImpl config = new ServiceConfigImpl(); - Assert.assertNull(config.getPid()); - } - - @Test - public void setPidRegularTest() { - serviceConfigImpl.setPid("123"); - Assert.assertEquals(serviceConfigImpl.getPid(), "123"); - } - - @Test - public void setPidNullValueTest() { - serviceConfigImpl.setPid(null); - Assert.assertNull(serviceConfigImpl.getPid()); - } - - @Test - public void setConfigurationsNullValueTest() throws KapuaException { - serviceConfigImpl.setConfigurations(null); - Assert.assertEquals(serviceConfigImpl.getConfigurations(), new Properties()); - } - - @Test - public void setConfigurationsRegularTest() throws KapuaException { - Properties properties = new Properties(); - properties.setProperty("prop1", "value1"); - serviceConfigImpl.setConfigurations(properties); - Assert.assertEquals(serviceConfigImpl.getConfigurations(), properties); - } - - @Test - public void getTypeTest() { - Assert.assertEquals(serviceConfigImpl.getType(), ServiceConfig.TYPE); - } -} diff --git a/commons/src/test/java/org/eclipse/kapua/commons/configuration/ServiceConfigQueryImplTest.java b/commons/src/test/java/org/eclipse/kapua/commons/configuration/ServiceConfigQueryImplTest.java deleted file mode 100644 index 43e8195d15c..00000000000 --- a/commons/src/test/java/org/eclipse/kapua/commons/configuration/ServiceConfigQueryImplTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2020, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.configuration; - -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.qa.markers.junit.JUnitTests; -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - - - -@Category(JUnitTests.class) -public class ServiceConfigQueryImplTest { - - @Test - public void createInstanceTest() { - ServiceConfigQueryImpl query = new ServiceConfigQueryImpl(KapuaId.ONE); - Assert.assertEquals(query.getScopeId(), KapuaId.ONE); - } - -} diff --git a/commons/src/test/java/org/eclipse/kapua/commons/model/AbstractKapuaUpdatableEntityTest.java b/commons/src/test/java/org/eclipse/kapua/commons/model/AbstractKapuaUpdatableEntityTest.java index f46aca5c8cc..c093343e97d 100644 --- a/commons/src/test/java/org/eclipse/kapua/commons/model/AbstractKapuaUpdatableEntityTest.java +++ b/commons/src/test/java/org/eclipse/kapua/commons/model/AbstractKapuaUpdatableEntityTest.java @@ -12,6 +12,10 @@ *******************************************************************************/ package org.eclipse.kapua.commons.model; +import java.math.BigInteger; +import java.util.Date; +import java.util.Random; + import org.eclipse.kapua.commons.model.id.KapuaEid; import org.eclipse.kapua.commons.security.KapuaSecurityUtils; import org.eclipse.kapua.commons.security.KapuaSession; @@ -24,12 +28,6 @@ import org.junit.experimental.categories.Category; import org.mockito.Mockito; -import java.math.BigInteger; -import java.util.Date; -import java.util.Properties; -import java.util.Random; - - @Category(JUnitTests.class) public class AbstractKapuaUpdatableEntityTest { @@ -65,8 +63,8 @@ public void abstractKapuaUpdatableEntityScopeIdTest() { @Test public void abstractKapuaUpdatableEntityEntityIdTest() { KapuaUpdatableEntity entity = new ActualKapuaUpdatableEntity(); - entity.setEntityAttributes(new Properties()); - entity.setEntityProperties(new Properties()); + // entity.setEntityAttributes(new Properties()); + // entity.setEntityProperties(new Properties()); entity.setOptlock(10); AbstractKapuaUpdatableEntity updatableEntity = new ActualKapuaUpdatableEntity(entity); updatableEntity.setModifiedOn(new Date()); diff --git a/commons/src/test/java/org/eclipse/kapua/commons/model/AbstractKapuaEntityCreatorTest.java b/commons/src/test/java/org/eclipse/kapua/commons/model/KapuaEntityBaseCreatorTest.java similarity index 77% rename from commons/src/test/java/org/eclipse/kapua/commons/model/AbstractKapuaEntityCreatorTest.java rename to commons/src/test/java/org/eclipse/kapua/commons/model/KapuaEntityBaseCreatorTest.java index d224355c2fb..03fcbf01f22 100644 --- a/commons/src/test/java/org/eclipse/kapua/commons/model/AbstractKapuaEntityCreatorTest.java +++ b/commons/src/test/java/org/eclipse/kapua/commons/model/KapuaEntityBaseCreatorTest.java @@ -12,9 +12,14 @@ *******************************************************************************/ package org.eclipse.kapua.commons.model; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.Random; + import org.eclipse.kapua.commons.model.id.KapuaEid; import org.eclipse.kapua.commons.util.RandomUtils; import org.eclipse.kapua.model.KapuaEntity; +import org.eclipse.kapua.model.KapuaEntityCreator; import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.qa.markers.junit.JUnitTests; import org.junit.Assert; @@ -24,14 +29,9 @@ import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.Random; - - @Category(JUnitTests.class) @RunWith(value = Parameterized.class) -public class AbstractKapuaEntityCreatorTest { +public class KapuaEntityBaseCreatorTest { private final static Random RANDOM = RandomUtils.getInstance(); @@ -39,20 +39,20 @@ public class AbstractKapuaEntityCreatorTest { @Parameters public static Iterable