Skip to content

Commit

Permalink
💥 KapuaListResult is now concrete, as are all subclasses (needed only…
Browse files Browse the repository at this point in the history
… to provide xml annotations), avoiding the split between interfaces and implementations

Signed-off-by: dseurotech <[email protected]>
  • Loading branch information
dseurotech committed Jan 14, 2025
1 parent d795152 commit e13bc0d
Show file tree
Hide file tree
Showing 253 changed files with 1,320 additions and 2,796 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
*******************************************************************************/
package org.eclipse.kapua.commons.configuration;

import java.util.Map;
import java.util.Optional;

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.KapuaMaxNumberOfItemsReachedException;
import org.eclipse.kapua.commons.configuration.exception.ServiceConfigurationLimitExceededException;
Expand All @@ -36,9 +39,6 @@
import org.eclipse.kapua.service.authorization.permission.PermissionFactory;
import org.eclipse.kapua.service.config.KapuaConfigurableService;

import java.util.Map;
import java.util.Optional;

/**
* Base {@code abstract} {@link KapuaConfigurableService} implementation for services that have a max number of entities allowed.
* <p>
Expand All @@ -48,12 +48,16 @@
* <li>maxNumberChildEntities</li>
* </ul>
*
* @param <E> The {@link KapuaEntity} type.
* @param <C> The {@link KapuaEntityCreator} type.
* @param <S> The {@link KapuaEntityService} type.
* @param <L> The {@link KapuaListResult} type.
* @param <Q> The {@link KapuaQuery} type.
* @param <F> The {@link KapuaEntityFactory} type.
* @param <E>
* The {@link KapuaEntity} type.
* @param <C>
* The {@link KapuaEntityCreator} type.
* @param <S>
* The {@link KapuaEntityService} type.
* @param <Q>
* The {@link KapuaQuery} type.
* @param <F>
* 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
*/
Expand All @@ -62,14 +66,12 @@ public abstract class AbstractKapuaConfigurableResourceLimitedService<
E extends KapuaEntity,
C extends KapuaEntityCreator<E>,
S extends KapuaEntityService<E, C>,
L extends KapuaListResult<E>,
Q extends KapuaQuery,
F extends KapuaEntityFactory<E, C, Q, L>
F extends KapuaEntityFactory<E, C, Q>
>
extends AbstractKapuaConfigurableService
implements KapuaEntityService<E, C> {


//TODO: make final as soon as deprecated constructors are removed
private AccountRelativeFinder accountRelativeFinder;
private F factory;
Expand All @@ -79,11 +81,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.
* @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
Expand All @@ -104,12 +111,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, PermissionFactory, AuthorizationService,
* AccountRelativeFinder, RootUserTester)} This constructor may be removed in a next release
*/
@Deprecated
protected AbstractKapuaConfigurableResourceLimitedService(
Expand All @@ -133,24 +146,32 @@ 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 permissionFactory
* The {@link PermissionFactory} 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) {
Domain domain,
EntityManagerFactory entityManagerFactory,
EntityCacheFactory abstractCacheFactory,
F factory,
PermissionFactory permissionFactory,
AuthorizationService authorizationService,
AccountRelativeFinder accountRelativeFinder,
RootUserTester rootUserTester) {
super(pid, domain, entityManagerFactory, abstractCacheFactory, permissionFactory, authorizationService, rootUserTester);
this.factory = factory;
this.factoryClass = null; //TODO: not needed for this construction path, remove as soon as the deprecated constructor is removed
Expand Down Expand Up @@ -180,8 +201,10 @@ protected boolean validateNewConfigValuesCoherence(KapuaTocd ocd, Map<String, Ob
/**
* Checks if the given scope {@link KapuaId} can have more entities for this {@link KapuaConfigurableService}.
*
* @param scopeId The scope {@link KapuaId} to check.
* @param entityType The entity type of this {@link KapuaConfigurableService}
* @param scopeId
* The scope {@link KapuaId} to check.
* @param entityType
* The entity type of this {@link KapuaConfigurableService}
* @throws KapuaException
* @since 2.0.0
*/
Expand All @@ -194,7 +217,8 @@ protected void checkAllowedEntities(KapuaId scopeId, String entityType) throws K
/**
* Gets the number of remaining allowed entity for the given scope, according to the {@link KapuaConfigurableService#getConfigValues(KapuaId)}
*
* @param scopeId The scope {@link KapuaId}.
* @param scopeId
* The scope {@link KapuaId}.
* @return The number of entities remaining for the given scope
* @throws KapuaException
* @since 1.0.0
Expand All @@ -204,13 +228,15 @@ private long allowedChildEntities(KapuaId scopeId) throws KapuaException {
}

/**
* Gets the number of remainisng allowed entity for the given scope, according to the {@link KapuaConfigurableService#getConfigValues(KapuaId)}
* excluding a specific scope when checking resources available.
* Gets the number of remainisng allowed entity for the given scope, according to the {@link KapuaConfigurableService#getConfigValues(KapuaId)} excluding a specific scope when checking resources
* available.
* <p>
* 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
Expand All @@ -220,14 +246,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.
* <p>
* 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
Expand Down Expand Up @@ -263,10 +291,9 @@ private long allowedChildEntities(KapuaId scopeId, KapuaId targetScopeId, Map<St
});
}


/**
* KapuaEntityFactory instance 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.
* KapuaEntityFactory instance 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.
*
* @return The instantiated (hopefully) {@link KapuaEntityFactory} instance
*/
Expand All @@ -282,8 +309,8 @@ protected F getFactory() {
}

/**
* This instance 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.
* This instance 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.
*
* @return The instantiated (hopefully) {@link AccountRelativeFinder} instance
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ protected Map<String, Object> getConfigValues(KapuaId scopeId, boolean excludeDi
);

ServiceConfigListResult result = entityManagerSession.doAction(EntityManagerContainer.<ServiceConfigListResult>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)));

Expand Down Expand Up @@ -592,7 +592,7 @@ public void setConfigValues(KapuaId scopeId, KapuaId parentId, Map<String, Objec
);

ServiceConfigListResult result = entityManagerSession.doAction(EntityManagerContainer.<ServiceConfigListResult>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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ServiceConfigImplJpaRepository
extends KapuaUpdatableEntityJpaRepository<ServiceConfig, ServiceConfigImpl, ServiceConfigListResult> implements ServiceConfigRepository {

public ServiceConfigImplJpaRepository(KapuaJpaRepositoryConfiguration jpaRepoConfig) {
super(ServiceConfigImpl.class, ServiceConfig.TYPE, () -> new ServiceConfigListResultImpl(), jpaRepoConfig);
super(ServiceConfigImpl.class, ServiceConfig.TYPE, () -> new ServiceConfigListResult(), jpaRepoConfig);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
* Service configuration result list definition.
*
* @since 1.0
*
*/
public interface ServiceConfigListResult extends KapuaListResult<ServiceConfig> {
public class ServiceConfigListResult extends KapuaListResult<ServiceConfig> {

private static final long serialVersionUID = -2550359084026132096L;

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public class UsedEntitiesCounterImpl<
C extends KapuaEntityCreator<E>,
L extends KapuaListResult<E>,
Q extends KapuaQuery,
F extends KapuaEntityFactory<E, C, Q, L>
F extends KapuaEntityFactory<E, C, Q>
> implements UsedEntitiesCounter {

private final F factory;
private final KapuaEntityRepository<E, L> entityRepository;

public UsedEntitiesCounterImpl(F factory,
KapuaEntityRepository<E, L> entityRepository) {
KapuaEntityRepository<E, L> entityRepository) {
this.factory = factory;
this.entityRepository = entityRepository;
}
Expand Down
Loading

0 comments on commit e13bc0d

Please sign in to comment.