diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/CommonsConfigurationModule.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/CommonsConfigurationModule.java
deleted file mode 100644
index f97b4f23f9b..00000000000
--- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/CommonsConfigurationModule.java
+++ /dev/null
@@ -1,23 +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.configuration;
-
-import org.eclipse.kapua.commons.core.AbstractKapuaModule;
-import org.eclipse.kapua.service.config.ServiceConfigurationFactory;
-
-public class CommonsConfigurationModule extends AbstractKapuaModule {
- @Override
- protected void configureModule() {
- bind(ServiceConfigurationFactory.class).to(ServiceConfigurationFactoryImpl.class);
- }
-}
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 daebf7f0cf0..be0698d338d 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
@@ -12,11 +12,13 @@
*******************************************************************************/
package org.eclipse.kapua.commons.configuration;
+import java.util.Collections;
import java.util.Map;
import java.util.Optional;
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;
@@ -29,10 +31,10 @@
/**
* Base {@link KapuaConfigurableService} implementation, build upon {@link ServiceConfigurationManager}.
*
- * Note: at first glance, this might seems like a violation of Composition over Inheritance principle, however:
- * - in this case inheritance is an acceptable strategy due to the strong link between {@link ServiceConfigurationManager#isServiceEnabled(org.eclipse.kapua.storage.TxContext, KapuaId)}
- * and {@link org.eclipse.kapua.service.KapuaService#isServiceEnabled(KapuaId)} (the latter being dependent from the first for configurable services).
- * - this class is nothing more than glue and convenience, demanding all of its logic to the {@link ServiceConfigurationManager}'s instance provided, so no flexibility has been sacrificed
+ * Note: at first glance, this might seems like a violation of Composition over Inheritance principle, however: - in this case inheritance is an acceptable strategy due to the strong link between
+ * {@link ServiceConfigurationManager#isServiceEnabled(org.eclipse.kapua.storage.TxContext, KapuaId)} and {@link org.eclipse.kapua.service.KapuaService#isServiceEnabled(KapuaId)} (the latter being
+ * dependent from the first for configurable services). - this class is nothing more than glue and convenience, demanding all of its logic to the {@link ServiceConfigurationManager}'s instance
+ * provided, so no flexibility has been sacrificed
*
* @since 2.0.0
*/
@@ -73,8 +75,11 @@ public KapuaTocd getConfigMetadata(KapuaId scopeId) throws KapuaException {
ArgumentValidator.notNull(scopeId, "scopeId");
// Check access
- authorizationService.checkPermission(permissionFactory.newPermission(domain, Actions.read, scopeId));
- return txManager.execute(tx -> serviceConfigurationManager.getConfigMetadata(tx, scopeId, true));
+ if (!authorizationService.isPermitted(permissionFactory.newPermission(domain, Actions.read, scopeId))) {
+ //Temporary, use Optional instead
+ return new EmptyTocd();
+ }
+ return serviceConfigurationManager.getConfigMetadata(scopeId, true).orElse(null);
}
@Override
@@ -83,9 +88,10 @@ public Map getConfigValues(KapuaId scopeId) throws KapuaExceptio
ArgumentValidator.notNull(scopeId, "scopeId");
// Check access
- authorizationService.checkPermission(permissionFactory.newPermission(domain, Actions.read, scopeId));
-
- return txManager.execute(tx -> serviceConfigurationManager.getConfigValues(tx, scopeId, true));
+ if (!authorizationService.isPermitted(permissionFactory.newPermission(domain, Actions.read, scopeId))) {
+ return Collections.emptyMap();
+ }
+ return serviceConfigurationManager.getConfigValues(scopeId, true);
}
@Override
@@ -96,9 +102,6 @@ public void setConfigValues(KapuaId scopeId, KapuaId parentId, Mapexecute(tx -> {
- serviceConfigurationManager.setConfigValues(tx, scopeId, Optional.ofNullable(parentId), values);
- return null;
- });
+ serviceConfigurationManager.setConfigValues(scopeId, Optional.ofNullable(parentId), values);
}
}
diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ResourceBasedServiceConfigurationMetadataProvider.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ResourceBasedServiceConfigurationMetadataProvider.java
new file mode 100644
index 00000000000..0f26ed91e0a
--- /dev/null
+++ b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ResourceBasedServiceConfigurationMetadataProvider.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * 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.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Optional;
+
+import org.eclipse.kapua.commons.util.ResourceUtils;
+import org.eclipse.kapua.commons.util.xml.XmlUtil;
+import org.eclipse.kapua.model.config.metatype.KapuaTmetadata;
+import org.eclipse.kapua.storage.TxContext;
+
+public class ResourceBasedServiceConfigurationMetadataProvider implements ServiceConfigurationMetadataProvider {
+
+ private final XmlUtil xmlUtil;
+
+ public ResourceBasedServiceConfigurationMetadataProvider(XmlUtil xmlUtil) {
+ this.xmlUtil = xmlUtil;
+ }
+
+ @Override
+ public Optional fetchMetadata(TxContext txContext, String pid) {
+ URL url = ResourceUtils.getResource(String.format("META-INF/metatypes/%s.xml", pid));
+
+ if (url == null) {
+ return Optional.empty();
+ }
+
+ try {
+ return Optional.ofNullable(xmlUtil.unmarshal(ResourceUtils.openAsReader(url, StandardCharsets.UTF_8), KapuaTmetadata.class))
+ .filter(v -> v.getOCD() != null && !v.getOCD().isEmpty());
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ResourceLimitedServiceConfigurationManagerImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ResourceLimitedServiceConfigurationManagerImpl.java
index f6761ac7510..a517a73163e 100644
--- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ResourceLimitedServiceConfigurationManagerImpl.java
+++ b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ResourceLimitedServiceConfigurationManagerImpl.java
@@ -21,13 +21,13 @@
import org.eclipse.kapua.commons.configuration.exception.ServiceConfigurationLimitExceededException;
import org.eclipse.kapua.commons.configuration.exception.ServiceConfigurationParentLimitExceededException;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
-import org.eclipse.kapua.commons.util.xml.XmlUtil;
import org.eclipse.kapua.model.config.metatype.KapuaTocd;
import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.service.account.Account;
import org.eclipse.kapua.service.account.AccountListResult;
import org.eclipse.kapua.service.config.KapuaConfigurableService;
import org.eclipse.kapua.storage.TxContext;
+import org.eclipse.kapua.storage.TxManager;
public class ResourceLimitedServiceConfigurationManagerImpl
extends ServiceConfigurationManagerImpl
@@ -38,12 +38,14 @@ public class ResourceLimitedServiceConfigurationManagerImpl
public ResourceLimitedServiceConfigurationManagerImpl(
String pid,
+ String domain,
+ TxManager txManager,
ServiceConfigRepository serviceConfigRepository,
RootUserTester rootUserTester,
AccountRelativeFinder accountRelativeFinder,
UsedEntitiesCounter usedEntitiesCounter,
- XmlUtil xmlUtil) {
- super(pid, serviceConfigRepository, rootUserTester, xmlUtil);
+ ServiceConfigurationMetadataProvider serviceConfigurationMetadataProvider) {
+ super(pid, domain, txManager, serviceConfigRepository, rootUserTester, serviceConfigurationMetadataProvider);
this.accountRelativeFinder = accountRelativeFinder;
this.usedEntitiesCounter = usedEntitiesCounter;
}
@@ -134,7 +136,7 @@ private long allowedChildEntities(TxContext txContext, KapuaId scopeId, Optional
if (configuration.isPresent()) { // Checked exceptions be damned, could have been .orElseGet(()->...)
finalConfig = configuration.get();
} else {
- finalConfig = getConfigValues(txContext, scopeId, false);
+ finalConfig = doGetConfigValues(txContext, scopeId, false);
}
boolean allowInfiniteChildEntities = (boolean) finalConfig.getOrDefault("infiniteChildEntities", false);
if (allowInfiniteChildEntities) {
@@ -148,7 +150,7 @@ private long allowedChildEntities(TxContext txContext, KapuaId scopeId, Optional
// Resources assigned to children
long childCount = 0;
for (Account childAccount : childAccounts.getItems()) {
- Map childConfigValues = getConfigValues(txContext, childAccount.getId(), true);
+ Map childConfigValues = doGetConfigValues(txContext, childAccount.getId(), true);
// maxNumberChildEntities can be null if such property is disabled via the
// isPropertyEnabled() method in the service implementation. In such case,
// it makes sense to treat the service as it had 0 available entities
diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceComponentConfigurationImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceComponentConfigurationImpl.java
deleted file mode 100644
index 4358ab8198e..00000000000
--- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceComponentConfigurationImpl.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2019, 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.Map;
-
-import org.eclipse.kapua.service.config.ServiceComponentConfiguration;
-import org.eclipse.kapua.commons.configuration.metatype.TocdImpl;
-import org.eclipse.kapua.model.config.metatype.KapuaTocd;
-
-/**
- * Service component configuration entity implementation.
- *
- * @since 1.0
- */
-public class ServiceComponentConfigurationImpl implements ServiceComponentConfiguration {
-
- private String id;
- private String name;
- private TocdImpl definition;
- private Map properties;
-
- /**
- * Constructor
- */
- public ServiceComponentConfigurationImpl() {
- }
-
- /**
- * Constructor
- *
- * @param id
- */
- public ServiceComponentConfigurationImpl(String id) {
- this.id = id;
- }
-
- @Override
- public String getId() {
- return id;
- }
-
- @Override
- public void setId(String id) {
- this.id = id;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void setName(String name) {
- this.name = name;
- }
-
- @Override
- public void setDefinition(KapuaTocd definition) {
- this.definition = (TocdImpl) definition;
- }
-
- @Override
- public KapuaTocd getDefinition() {
- return definition;
- }
-
- @Override
- public Map getProperties() {
- return properties;
- }
-
- @Override
- public void setProperties(Map properties) {
- this.properties = properties;
- }
-}
diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationFactoryImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationFactoryImpl.java
deleted file mode 100644
index 2be35298a32..00000000000
--- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationFactoryImpl.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2019, 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.service.config.ServiceComponentConfiguration;
-import org.eclipse.kapua.service.config.ServiceConfiguration;
-import org.eclipse.kapua.service.config.ServiceConfigurationFactory;
-
-import javax.inject.Singleton;
-
-/**
- * Service configuration entity service factory implementation.
- *
- * @since 1.0
- */
-@Singleton
-public class ServiceConfigurationFactoryImpl implements ServiceConfigurationFactory {
-
- @Override
- public ServiceComponentConfiguration newComponentConfigurationInstance(String componentConfigurationId) {
- return new ServiceComponentConfigurationImpl(componentConfigurationId);
- }
-
- @Override
- public ServiceConfiguration newConfigurationInstance() {
- return new ServiceConfigurationImpl();
- }
-
-}
diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationManager.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationManager.java
index 6bcc162ea5e..bb9c4ea9436 100644
--- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationManager.java
+++ b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationManager.java
@@ -12,20 +12,23 @@
*******************************************************************************/
package org.eclipse.kapua.commons.configuration;
+import java.util.Map;
+import java.util.Optional;
+
import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.model.config.metatype.KapuaTocd;
import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.service.KapuaService;
+import org.eclipse.kapua.service.config.ServiceComponentConfiguration;
import org.eclipse.kapua.storage.TxContext;
-import java.util.Map;
-import java.util.Optional;
-
public interface ServiceConfigurationManager {
+
/**
* Whether this {@link KapuaService} is enabled for the given scope {@link KapuaId}.
*
- * @param scopeId The scope {@link KapuaId} for which to check.
+ * @param scopeId
+ * The scope {@link KapuaId} for which to check.
* @return {@code true} if the {@link KapuaService} is enabled, {@code false} otherwise.
* @since 1.2.0
*/
@@ -33,11 +36,17 @@ default boolean isServiceEnabled(TxContext txContext, KapuaId scopeId) {
return true;
}
+ String getDomain();
+
void checkAllowedEntities(TxContext txContext, KapuaId scopeId, String entityType) throws KapuaException;
- void setConfigValues(TxContext txContext, KapuaId scopeId, Optional parentId, Map values) throws KapuaException;
+ void setConfigValues(KapuaId scopeId, Optional parentId, Map values) throws KapuaException;
Map getConfigValues(TxContext txContext, KapuaId scopeId, boolean excludeDisabled) throws KapuaException;
- KapuaTocd getConfigMetadata(TxContext txContext, KapuaId scopeId, boolean excludeDisabled) throws KapuaException;
+ Map getConfigValues(KapuaId scopeId, boolean excludeDisabled) throws KapuaException;
+
+ Optional getConfigMetadata(KapuaId scopeId, boolean excludeDisabled) throws KapuaException;
+
+ Optional extractServiceComponentConfiguration(KapuaId scopeId) throws KapuaException;
}
diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationManagerCachingWrapper.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationManagerCachingWrapper.java
index f8bb6fc3bb4..285a7b02dd7 100644
--- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationManagerCachingWrapper.java
+++ b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationManagerCachingWrapper.java
@@ -12,6 +12,9 @@
*******************************************************************************/
package org.eclipse.kapua.commons.configuration;
+import java.util.Map;
+import java.util.Optional;
+
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import org.eclipse.kapua.KapuaException;
@@ -23,12 +26,11 @@
import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.service.account.Account;
import org.eclipse.kapua.service.config.KapuaConfigurableService;
+import org.eclipse.kapua.service.config.ServiceComponentConfiguration;
import org.eclipse.kapua.storage.TxContext;
-import java.util.Map;
-import java.util.Optional;
-
public class ServiceConfigurationManagerCachingWrapper implements ServiceConfigurationManager {
+
private final ServiceConfigurationManager wrapped;
private static final int LOCAL_CACHE_SIZE_MAX = SystemSetting.getInstance().getInt(SystemSettingKey.TMETADATA_LOCAL_CACHE_SIZE_MAXIMUM, 100);
@@ -48,29 +50,36 @@ public class ServiceConfigurationManagerCachingWrapper implements ServiceConfigu
private final LocalCache, KapuaTocd> kapuaTocdLocalCache = new LocalCache<>(LOCAL_CACHE_SIZE_MAX, null);
/**
- * This cache only holds the {@link Boolean} value {@literal True} if the {@link KapuaTocd} has been already read from the file
- * at least once, regardless of the value. With this we can know when a read from {@code KAPUA_TOCD_LOCAL_CACHE}
- * returns {@literal null} because of the requested key is not present, and when the key is present but its actual value
- * is {@literal null}.
+ * This cache only holds the {@link Boolean} value {@literal True} if the {@link KapuaTocd} has been already read from the file at least once, regardless of the value. With this we can know when a
+ * read from {@code KAPUA_TOCD_LOCAL_CACHE} returns {@literal null} because of the requested key is not present, and when the key is present but its actual value is {@literal null}.
*
* @since 1.2.0
*/
private final LocalCache, Boolean> kapuaTocdEmptyLocalCache = new LocalCache<>(LOCAL_CACHE_SIZE_MAX, false);
-
public ServiceConfigurationManagerCachingWrapper(ServiceConfigurationManager wrapped) {
this.wrapped = wrapped;
}
+ @Override
+ public String getDomain() {
+ return wrapped.getDomain();
+ }
+
@Override
public void checkAllowedEntities(TxContext txContext, KapuaId scopeId, String entityType) throws KapuaException {
wrapped.checkAllowedEntities(txContext, scopeId, entityType);
}
@Override
- public void setConfigValues(TxContext txContext, KapuaId scopeId, Optional parentId, Map values) throws KapuaException {
- wrapped.setConfigValues(txContext, scopeId, parentId, values);
+ public void setConfigValues(KapuaId scopeId, Optional parentId, Map values) throws KapuaException {
+ wrapped.setConfigValues(scopeId, parentId, values);
+
+ }
+ @Override
+ public Map getConfigValues(KapuaId scopeId, boolean excludeDisabled) throws KapuaException {
+ return wrapped.getConfigValues(scopeId, excludeDisabled);
}
@Override
@@ -79,24 +88,24 @@ public Map getConfigValues(TxContext txContext, KapuaId scopeId,
}
@Override
- public KapuaTocd getConfigMetadata(TxContext txContext, KapuaId scopeId, boolean excludeDisabled) throws KapuaException {
+ public Optional getConfigMetadata(KapuaId scopeId, boolean excludeDisabled) throws KapuaException {
// Argument validation
ArgumentValidator.notNull(scopeId, "scopeId");
// Get the Tocd
// Keep distinct values for service PID, Scope ID and disabled properties included/excluded from AD
- Pair cacheKey = Pair.of(scopeId, excludeDisabled);
+ final Pair cacheKey = Pair.of(scopeId, excludeDisabled);
try {
// Check if the OCD is already in cache, but not in the "empty" cache
- KapuaTocd tocd;
- tocd = kapuaTocdLocalCache.get(cacheKey);
- if (tocd == null && !kapuaTocdEmptyLocalCache.get(cacheKey)) {
+ Optional tocd;
+ tocd = Optional.ofNullable(kapuaTocdLocalCache.get(cacheKey));
+ if (!tocd.isPresent() && !kapuaTocdEmptyLocalCache.get(cacheKey)) {
// If not, read metadata and process it
- tocd = wrapped.getConfigMetadata(txContext, scopeId, excludeDisabled);
+ tocd = wrapped.getConfigMetadata(scopeId, excludeDisabled);
// If null, put it in the "empty" ocd cache, else put it in the "standard" cache
- if (tocd != null) {
+ if (tocd.isPresent()) {
// If the value is not null, put it in "standard" cache and remove the entry from the "empty" cache if present
- kapuaTocdLocalCache.put(cacheKey, tocd);
+ kapuaTocdLocalCache.put(cacheKey, tocd.get());
kapuaTocdEmptyLocalCache.remove(cacheKey);
} else {
// If the value is null, just remember we already read it from file at least once
@@ -108,4 +117,9 @@ public KapuaTocd getConfigMetadata(TxContext txContext, KapuaId scopeId, boolean
throw KapuaException.internalError(e);
}
}
+
+ @Override
+ public Optional extractServiceComponentConfiguration(KapuaId scopeId) throws KapuaException {
+ return wrapped.extractServiceComponentConfiguration(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 db73a029e27..7dd2137e2c7 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
@@ -12,9 +12,7 @@
*******************************************************************************/
package org.eclipse.kapua.commons.configuration;
-import java.io.IOException;
-import java.net.URL;
-import java.nio.charset.StandardCharsets;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -24,7 +22,6 @@
import java.util.stream.Collectors;
import javax.validation.constraints.NotNull;
-import javax.xml.bind.JAXBException;
import javax.xml.namespace.QName;
import org.eclipse.kapua.KapuaEntityNotFoundException;
@@ -32,36 +29,39 @@
import org.eclipse.kapua.KapuaIllegalArgumentException;
import org.eclipse.kapua.KapuaIllegalNullArgumentException;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
-import org.eclipse.kapua.commons.service.internal.KapuaServiceDisabledException;
import org.eclipse.kapua.commons.util.ArgumentValidator;
-import org.eclipse.kapua.commons.util.ResourceUtils;
import org.eclipse.kapua.commons.util.StringUtil;
-import org.eclipse.kapua.commons.util.xml.XmlUtil;
import org.eclipse.kapua.model.KapuaEntityAttributes;
import org.eclipse.kapua.model.config.metatype.KapuaTad;
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.service.config.KapuaConfigurableService;
+import org.eclipse.kapua.service.config.ServiceComponentConfiguration;
import org.eclipse.kapua.storage.TxContext;
-import org.xml.sax.SAXException;
+import org.eclipse.kapua.storage.TxManager;
public class ServiceConfigurationManagerImpl implements ServiceConfigurationManager {
protected final String pid;
+ protected final TxManager txManager;
+ private final String domain;
private final ServiceConfigRepository serviceConfigRepository;
private final RootUserTester rootUserTester;
- private final XmlUtil xmlUtil;
+ private final ServiceConfigurationMetadataProvider serviceConfigurationMetadataProvider;
public ServiceConfigurationManagerImpl(
String pid,
+ String domain, TxManager txManager,
ServiceConfigRepository serviceConfigRepository,
RootUserTester rootUserTester,
- XmlUtil xmlUtil) {
+ ServiceConfigurationMetadataProvider serviceConfigurationMetadataProvider) {
this.pid = pid;
+ this.txManager = txManager;
+ this.domain = domain;
this.serviceConfigRepository = serviceConfigRepository;
this.rootUserTester = rootUserTester;
- this.xmlUtil = xmlUtil;
+ this.serviceConfigurationMetadataProvider = serviceConfigurationMetadataProvider;
}
/**
@@ -101,6 +101,11 @@ protected boolean validateNewConfigValuesCoherence(TxContext txContext, KapuaToc
return true;
}
+ @Override
+ public String getDomain() {
+ return domain;
+ }
+
/**
* Checks if the given scope {@link KapuaId} can have more entities for this {@link KapuaConfigurableService}.
*
@@ -117,58 +122,71 @@ public void checkAllowedEntities(TxContext txContext, KapuaId scopeId, String en
}
@Override
- public void setConfigValues(TxContext txContext, KapuaId scopeId, Optional parentId, Map values) throws KapuaException {
- KapuaTocd ocd = getConfigMetadata(txContext, scopeId, false);
+ public void setConfigValues(KapuaId scopeId, Optional parentId, Map values) throws KapuaException {
+ txManager.execute(tx -> {
+ Optional maybeOcd = doGetConfigMetadata(tx, scopeId, false);
+ if (!maybeOcd.isPresent()) {
+ return null;
+ //throw?
+ }
- Map originalValues = getConfigValues(txContext, scopeId, true);
+ final Optional maybeKapuaTocd = doGetConfigMetadata(tx, scopeId, true);
+ if (!maybeKapuaTocd.isPresent()) {
+ return null;
+ //throw?
+ }
- for (KapuaTad ad : ocd.getAD()) {
- boolean allowSelfEdit = Boolean.parseBoolean(ad.getOtherAttributes().getOrDefault(new QName("allowSelfEdit"), "false"));
-
- final KapuaId currentUserId = KapuaSecurityUtils.getSession().getUserId();
- boolean preventChange =
- // if current user is not root user...
- !rootUserTester.isRoot(currentUserId) &&
- // current configuration does not allow self edit...
- !allowSelfEdit &&
- // a configuration for the current logged account is about to be changed...
- KapuaSecurityUtils.getSession().getScopeId().equals(scopeId) &&
- // and the new value is different from the other one...
- !originalValues.get(ad.getId()).equals(values.get(ad.getId()));
-
- if (preventChange) {
- // ... prevent the change!
- throw KapuaException.internalError(String.format("The configuration \"%s\" cannot be changed by this user in this account", ad.getId()));
+ Map originalValues = doGetConfigValues(tx, scopeId, maybeKapuaTocd.get());
+
+ for (KapuaTad ad : maybeOcd.get().getAD()) {
+ boolean allowSelfEdit = Boolean.parseBoolean(ad.getOtherAttributes().getOrDefault(new QName("allowSelfEdit"), "false"));
+
+ final KapuaId currentUserId = KapuaSecurityUtils.getSession().getUserId();
+ boolean preventChange =
+ // if current user is not root user...
+ !rootUserTester.isRoot(currentUserId) &&
+ // current configuration does not allow self edit...
+ !allowSelfEdit &&
+ // a configuration for the current logged account is about to be changed...
+ KapuaSecurityUtils.getSession().getScopeId().equals(scopeId) &&
+ // and the new value is different from the other one...
+ !originalValues.get(ad.getId()).equals(values.get(ad.getId()));
+
+ if (preventChange) {
+ // ... prevent the change!
+ throw KapuaException.internalError(String.format("The configuration \"%s\" cannot be changed by this user in this account", ad.getId()));
+ }
}
- }
- validateConfigurations(txContext, ocd, values, scopeId, parentId);
+ validateConfigurations(tx, maybeOcd.get(), values, scopeId, parentId);
- ServiceConfigQueryImpl query = new ServiceConfigQueryImpl(scopeId);
- query.setPredicate(
- query.andPredicate(
- query.attributePredicate(ServiceConfigAttributes.SERVICE_ID, pid),
- query.attributePredicate(KapuaEntityAttributes.SCOPE_ID, scopeId)
- )
- );
+ ServiceConfigQueryImpl query = new ServiceConfigQueryImpl(scopeId);
+ query.setPredicate(
+ query.andPredicate(
+ query.attributePredicate(ServiceConfigAttributes.SERVICE_ID, pid),
+ query.attributePredicate(KapuaEntityAttributes.SCOPE_ID, scopeId)
+ )
+ );
- ServiceConfigListResult result = serviceConfigRepository.query(txContext, query);
+ ServiceConfigListResult result = serviceConfigRepository.query(tx, query);
- Properties props = toProperties(values);
- if (result == null || result.isEmpty()) {
- // In not exists create then return
- ServiceConfig serviceConfigNew = new ServiceConfigImpl(scopeId);
- serviceConfigNew.setPid(pid);
- serviceConfigNew.setConfigurations(props);
+ Properties props = toProperties(values);
+ if (result == null || result.isEmpty()) {
+ // In not exists create then return
+ ServiceConfig serviceConfigNew = new ServiceConfigImpl(scopeId);
+ serviceConfigNew.setPid(pid);
+ serviceConfigNew.setConfigurations(props);
- createConfig(txContext, serviceConfigNew);
- } else {
- // If exists update it
- ServiceConfig serviceConfig = result.getFirstItem();
- serviceConfig.setConfigurations(props);
+ createConfig(tx, serviceConfigNew);
+ } else {
+ // If exists update it
+ ServiceConfig serviceConfig = result.getFirstItem();
+ serviceConfig.setConfigurations(props);
- updateConfig(txContext, serviceConfig);
- }
+ updateConfig(tx, serviceConfig);
+ }
+ return null;
+ });
}
/**
@@ -252,7 +270,7 @@ private void validateConfigurations(TxContext txContext, KapuaTocd ocd, Map originalValues = getConfigValues(txContext, scopeId, false);
+ Map originalValues = doGetConfigValues(txContext, scopeId, false);
if (originalValues != null) {
disabledProperties.forEach(disabledProp -> updatedProps.put(disabledProp.getId(), originalValues.get(disabledProp.getId())));
}
@@ -329,10 +347,37 @@ private void checkRequiredProperties(KapuaTocd ocd, Map updatedP
* @throws KapuaException
* @since 1.3.0
*/
+ @Override
+ public Map getConfigValues(KapuaId scopeId, boolean excludeDisabled) throws KapuaException {
+ // Argument validation
+ ArgumentValidator.notNull(scopeId, "scopeId");
+
+ return txManager.execute(txContext -> doGetConfigValues(txContext, scopeId, excludeDisabled));
+ }
+
@Override
public Map getConfigValues(TxContext txContext, KapuaId scopeId, boolean excludeDisabled) throws KapuaException {
// Argument validation
ArgumentValidator.notNull(scopeId, "scopeId");
+
+ return doGetConfigValues(txContext, scopeId, excludeDisabled);
+ }
+
+ protected Map doGetConfigValues(TxContext txContext, KapuaId scopeId, boolean excludeDisabled) throws KapuaException {
+ final Optional metadata = doGetConfigMetadata(txContext, scopeId, excludeDisabled);
+ return metadata.map(m -> {
+ try {
+ return doGetConfigValues(txContext, scopeId, m);
+ } catch (KapuaException e) {
+ throw new RuntimeException(e);
+ }
+ }).orElse(Collections.emptyMap());
+ }
+
+ protected Map doGetConfigValues(TxContext txContext, KapuaId scopeId, KapuaTocd metadata) throws KapuaException {
+ if (metadata == null) {
+ return null;
+ }
// Get configuration values
final ServiceConfigListResult result = serviceConfigRepository.findByScopeAndPid(txContext, scopeId, pid);
@@ -341,9 +386,7 @@ public Map getConfigValues(TxContext txContext, KapuaId scopeId,
properties = result.getFirstItem().getConfigurations();
}
- KapuaTocd ocd = getConfigMetadata(txContext, scopeId, excludeDisabled);
-
- return ocd == null ? null : toValues(ocd, properties);
+ return toValues(metadata, properties);
}
/**
@@ -380,21 +423,42 @@ private static Map toValues(@NotNull KapuaTocd ocd, Properties p
* @since 1.3.0
*/
@Override
- public KapuaTocd getConfigMetadata(TxContext txContext, KapuaId scopeId, boolean excludeDisabled) throws KapuaException {
+ public Optional getConfigMetadata(KapuaId scopeId, boolean excludeDisabled) throws KapuaException {
+ return txManager.execute(txContext -> doGetConfigMetadata(txContext, scopeId, excludeDisabled));
+ }
+
+ protected Optional doGetConfigMetadata(TxContext txContext, KapuaId scopeId, boolean excludeDisabled) throws KapuaException {
// Argument validation
ArgumentValidator.notNull(scopeId, "scopeId");
// Check disabled service
if (!isServiceEnabled(txContext, scopeId)) {
- throw new KapuaServiceDisabledException(pid);
+ return Optional.empty();
}
// Get the Tocd
try {
- return processMetadata(txContext, readMetadata(pid), scopeId, excludeDisabled);
+ return processMetadata(txContext, serviceConfigurationMetadataProvider.fetchMetadata(txContext, pid), scopeId, excludeDisabled);
} catch (Exception e) {
throw KapuaException.internalError(e);
}
}
+ @Override
+ public Optional extractServiceComponentConfiguration(KapuaId scopeId) throws KapuaException {
+ return txManager.execute(txContext -> {
+ final Optional maybeMetadata = this.doGetConfigMetadata(txContext, scopeId, true);
+ if (!maybeMetadata.isPresent()) {
+ return Optional.empty();
+ }
+ final KapuaTocd metadata = maybeMetadata.get();
+ final Map values = this.doGetConfigValues(txContext, scopeId, metadata);
+ final ServiceComponentConfiguration res = new ServiceComponentConfiguration(metadata.getId());
+ res.setDefinition(metadata);
+ res.setName(metadata.getName());
+ res.setProperties(values);
+ return Optional.of(res);
+ });
+ }
+
/**
* Process {@link KapuaTmetadata} to exclude disabled {@link KapuaTocd}s and {@link KapuaTad}s if requested.
*
@@ -405,35 +469,15 @@ public KapuaTocd getConfigMetadata(TxContext txContext, KapuaId scopeId, boolean
* @return The processed {@link KapuaTocd}.
* @since 1.3.0
*/
- private KapuaTocd processMetadata(TxContext txContext, KapuaTmetadata metadata, KapuaId scopeId, boolean excludeDisabled) {
- if (metadata != null && metadata.getOCD() != null && !metadata.getOCD().isEmpty()) {
- for (KapuaTocd ocd : metadata.getOCD()) {
+ private Optional processMetadata(TxContext txContext, Optional metadata, KapuaId scopeId, boolean excludeDisabled) {
+ return metadata.flatMap(meta -> {
+ for (KapuaTocd ocd : meta.getOCD()) {
if (ocd.getId() != null && ocd.getId().equals(pid) && isServiceEnabled(txContext, scopeId)) {
ocd.getAD().removeIf(ad -> excludeDisabled && !isPropertyEnabled(ad, scopeId));
- return ocd;
+ return Optional.of(ocd);
}
}
- }
- return null;
+ return Optional.empty();
+ });
}
-
- /**
- * Reads the {@link KapuaTmetadata} for the given {@link KapuaConfigurableService} pid.
- *
- * @param pid
- * The {@link KapuaConfigurableService} pid
- * @return The {@link KapuaTmetadata} for the given {@link KapuaConfigurableService} pid.
- * @throws Exception
- * @since 1.0.0
- */
- private KapuaTmetadata readMetadata(String pid) throws JAXBException, SAXException, IOException {
- URL url = ResourceUtils.getResource(String.format("META-INF/metatypes/%s.xml", pid));
-
- if (url == null) {
- return null;
- }
-
- return xmlUtil.unmarshal(ResourceUtils.openAsReader(url, StandardCharsets.UTF_8), KapuaTmetadata.class);
- }
-
}
\ No newline at end of file
diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationMetadataProvider.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationMetadataProvider.java
new file mode 100644
index 00000000000..85d334aa49b
--- /dev/null
+++ b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationMetadataProvider.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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.Optional;
+
+import org.eclipse.kapua.model.config.metatype.KapuaTmetadata;
+import org.eclipse.kapua.model.config.metatype.KapuaTocd;
+import org.eclipse.kapua.service.config.KapuaConfigurableService;
+import org.eclipse.kapua.storage.TxContext;
+
+public interface ServiceConfigurationMetadataProvider {
+
+ /**
+ * Reads the {@link KapuaTmetadata} for the given {@link KapuaConfigurableService} pid. If no metadata can be found, just return Optional.empty() Same if the metadata is empty (containing no
+ * {@link KapuaTocd}s)
+ *
+ * @param txContext
+ * the transaction context (can be ignored if the data source is not transactional)
+ * @param pid
+ * The {@link KapuaConfigurableService} pid
+ * @return The {@link KapuaTmetadata} for the given {@link KapuaConfigurableService} pid.
+ * @since 1.0.0
+ */
+ Optional fetchMetadata(TxContext txContext, String pid);
+}
diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationsFacade.java
similarity index 50%
rename from commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationImpl.java
rename to commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationsFacade.java
index c2a82883382..b7d350889b8 100644
--- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationImpl.java
+++ b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationsFacade.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2019, 2022 Eurotech and/or its affiliates and others
+ * 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
@@ -12,30 +12,19 @@
*******************************************************************************/
package org.eclipse.kapua.commons.configuration;
-import java.util.ArrayList;
-import java.util.List;
-
+import org.eclipse.kapua.KapuaException;
+import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.service.config.ServiceComponentConfiguration;
import org.eclipse.kapua.service.config.ServiceConfiguration;
-/**
- * Service configuration entity implementation.
- *
- * @since 1.0
- */
-public class ServiceConfigurationImpl implements ServiceConfiguration {
+public interface ServiceConfigurationsFacade {
- private static final long serialVersionUID = -2167999497954676423L;
+ ServiceConfiguration fetchAllConfigurations(KapuaId scopeId) throws KapuaException;
- private List configurations;
+ void update(KapuaId scopeId, ServiceConfiguration serviceConfiguration) throws KapuaException;
- public ServiceConfigurationImpl() {
- configurations = new ArrayList<>();
- }
+ ServiceComponentConfiguration fetchConfiguration(KapuaId scopeId, String serviceId) throws KapuaException;
- @Override
- public List getComponentConfigurations() {
- return configurations;
- }
+ void update(KapuaId scopeId, String serviceId, ServiceComponentConfiguration newServiceComponentConfiguration) throws KapuaException;
}
diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationsFacadeImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationsFacadeImpl.java
new file mode 100644
index 00000000000..a686d807ad5
--- /dev/null
+++ b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationsFacadeImpl.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * 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.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import javax.inject.Inject;
+
+import org.eclipse.kapua.KapuaException;
+import org.eclipse.kapua.KapuaIllegalArgumentException;
+import org.eclipse.kapua.model.domain.Actions;
+import org.eclipse.kapua.model.id.KapuaId;
+import org.eclipse.kapua.service.account.Account;
+import org.eclipse.kapua.service.account.AccountService;
+import org.eclipse.kapua.service.authorization.AuthorizationService;
+import org.eclipse.kapua.service.authorization.permission.PermissionFactory;
+import org.eclipse.kapua.service.config.ServiceComponentConfiguration;
+import org.eclipse.kapua.service.config.ServiceConfiguration;
+
+public class ServiceConfigurationsFacadeImpl implements ServiceConfigurationsFacade {
+
+ private final 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) {
+ 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;
+ }
+
+ @Override
+ public ServiceConfiguration fetchAllConfigurations(KapuaId scopeId) throws KapuaException {
+ final ServiceConfiguration res = new ServiceConfiguration();
+
+ for (ServiceConfigurationManager configurableService : serviceConfigurationManagersByServiceClass.values()) {
+ if (!authorizationService.isPermitted(permissionFactory.newPermission(configurableService.getDomain(), Actions.read, scopeId))) {
+ continue;
+ }
+ configurableService.extractServiceComponentConfiguration(scopeId).ifPresent(res.getComponentConfigurations()::add);
+ }
+ return res;
+ }
+
+ @Override
+ public ServiceComponentConfiguration fetchConfiguration(KapuaId scopeId, String serviceId) throws KapuaException {
+ final ServiceConfigurationManager serviceConfigurationManager = serviceConfigurationManagersByServiceClassName.get(serviceId);
+ if (serviceConfigurationManager == null) {
+ throw new KapuaIllegalArgumentException("service.pid", serviceId);
+ }
+ authorizationService.checkPermission(permissionFactory.newPermission(serviceConfigurationManager.getDomain(), Actions.read, scopeId));
+ return serviceConfigurationManager.extractServiceComponentConfiguration(scopeId).orElse(null);
+ }
+
+ @Override
+ public void update(KapuaId scopeId, ServiceConfiguration newServiceConfiguration) throws KapuaException {
+ final Account account = accountService.find(scopeId);
+
+ for (ServiceComponentConfiguration newServiceComponentConfiguration : newServiceConfiguration.getComponentConfigurations()) {
+ doUpdateServiceComponentConfiguration(account, scopeId, newServiceComponentConfiguration.getId(), newServiceComponentConfiguration);
+ }
+ }
+
+ @Override
+ public void update(KapuaId scopeId, String serviceId, ServiceComponentConfiguration newServiceComponentConfiguration) throws KapuaException {
+ final Account account = accountService.find(scopeId);
+ doUpdateServiceComponentConfiguration(account, scopeId, serviceId, newServiceComponentConfiguration);
+ }
+
+ private void doUpdateServiceComponentConfiguration(Account account, KapuaId scopeId, String serviceId, ServiceComponentConfiguration newServiceComponentConfiguration) throws KapuaException {
+ final ServiceConfigurationManager serviceConfigurationManager = serviceConfigurationManagersByServiceClassName.get(serviceId);
+ if (serviceConfigurationManager == null) {
+ throw new KapuaIllegalArgumentException("serviceConfiguration.componentConfiguration.id", newServiceComponentConfiguration.getId());
+ }
+ if (!authorizationService.isPermitted(permissionFactory.newPermission(serviceConfigurationManager.getDomain(), Actions.write, scopeId))) {
+ //TODO: Or maybe throw?
+ return;
+ }
+ serviceConfigurationManager.setConfigValues(scopeId, Optional.ofNullable(account.getScopeId()), newServiceComponentConfiguration.getProperties());
+ }
+}
diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ValueTokenizer.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ValueTokenizer.java
index afde37a28c5..0658873c578 100644
--- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/ValueTokenizer.java
+++ b/commons/src/main/java/org/eclipse/kapua/commons/configuration/ValueTokenizer.java
@@ -13,20 +13,19 @@
*******************************************************************************/
package org.eclipse.kapua.commons.configuration;
-import org.eclipse.kapua.commons.configuration.metatype.TscalarImpl;
-import org.eclipse.kapua.model.config.metatype.KapuaTad;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import org.eclipse.kapua.model.config.metatype.KapuaTad;
+import org.eclipse.kapua.model.config.metatype.KapuaTscalar;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
- * The implementation of this class is inspired from the org.eclipse.equinox.metatype.impl.ValueTokenizer class
- * in the Eclipse Equinox project.
+ * The implementation of this class is inspired from the org.eclipse.equinox.metatype.impl.ValueTokenizer class in the Eclipse Equinox project.
*
* @since 1.0
*/
@@ -215,7 +214,7 @@ else if (values.size() > cardinality) {
boolean rangeError = false;
Object minVal = null;
Object maxVal = null;
- TscalarImpl adScalarType = TscalarImpl.fromValue(ad.getType().value());
+ KapuaTscalar adScalarType = KapuaTscalar.fromValue(ad.getType().value());
switch (adScalarType) {
case PASSWORD:
case STRING:
diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/metatype/CommonsMetatypeModule.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/metatype/CommonsMetatypeModule.java
deleted file mode 100644
index 7768fa46364..00000000000
--- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/metatype/CommonsMetatypeModule.java
+++ /dev/null
@@ -1,23 +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.configuration.metatype;
-
-import org.eclipse.kapua.commons.core.AbstractKapuaModule;
-import org.eclipse.kapua.model.config.metatype.KapuaMetatypeFactory;
-
-public class CommonsMetatypeModule extends AbstractKapuaModule {
- @Override
- protected void configureModule() {
- bind(KapuaMetatypeFactory.class).to(KapuaMetatypeFactoryImpl.class);
- }
-}
diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/metatype/KapuaMetatypeFactoryImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/metatype/KapuaMetatypeFactoryImpl.java
deleted file mode 100644
index 2062cc53a83..00000000000
--- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/metatype/KapuaMetatypeFactoryImpl.java
+++ /dev/null
@@ -1,71 +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.metatype;
-
-import org.eclipse.kapua.model.config.metatype.KapuaMetatypeFactory;
-import org.eclipse.kapua.model.config.metatype.KapuaTad;
-import org.eclipse.kapua.model.config.metatype.KapuaTdesignate;
-import org.eclipse.kapua.model.config.metatype.KapuaTicon;
-import org.eclipse.kapua.model.config.metatype.KapuaTmetadata;
-import org.eclipse.kapua.model.config.metatype.KapuaTobject;
-import org.eclipse.kapua.model.config.metatype.KapuaTocd;
-import org.eclipse.kapua.model.config.metatype.KapuaToption;
-import org.eclipse.kapua.model.config.metatype.KapuaTscalar;
-
-import javax.inject.Singleton;
-
-/**
- * Kapua metatype objects factory service implementation.
- *
- * @since 1.0
- */
-@Singleton
-public class KapuaMetatypeFactoryImpl implements KapuaMetatypeFactory {
-
- @Override
- public KapuaTocd newKapuaTocd() {
- return new TocdImpl();
- }
-
- @Override
- public KapuaTad newKapuaTad() {
- return new TadImpl();
- }
-
- @Override
- public KapuaTscalar newKapuaTscalar(String type) {
- return TscalarImpl.fromValue(type);
- }
-
- @Override
- public KapuaToption newKapuaToption() {
- return new ToptionImpl();
- }
-
- @Override
- public KapuaTicon newKapuaTicon() {
- return new TiconImpl();
- }
-
- public KapuaTmetadata newKapuaTmetadata() {
- return new TmetadataImpl();
- }
-
- public KapuaTdesignate newKapuaTdesignate() {
- return new TdesignateImpl();
- }
-
- public KapuaTobject newKapuaTobject() {
- return new TobjectImpl();
- }
-}
diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/metatype/ObjectFactoryImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/metatype/ObjectFactoryImpl.java
deleted file mode 100644
index 7ebdaa7b2a2..00000000000
--- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/metatype/ObjectFactoryImpl.java
+++ /dev/null
@@ -1,102 +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.metatype;
-
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.annotation.XmlElementDecl;
-import javax.xml.bind.annotation.XmlRegistry;
-import javax.xml.namespace.QName;
-
-/**
- * ObjectFactory allows you to programmatically construct new instances of the Java representation for XML content.
- * The Java representation of XML content can consist of schema derived interfaces and classes representing the binding of schema type definitions, element declarations and model groups. Factory
- * methods for each of these are provided in this class.
- *
- * @since 1.0
- */
-@XmlRegistry
-public class ObjectFactoryImpl {
-
- private static final QName _MetaData_QNAME = new QName("http://www.osgi.org/xmlns/metatype/v1.2.0", "MetaData");
-
- /**
- * Create a new ObjectFactory that can be used to create new instances of schema derived classes.
- */
- public ObjectFactoryImpl() {
- }
-
- /**
- * Create an instance of {@link TiconImpl }
- */
- public TiconImpl createTicon() {
- return new TiconImpl();
- }
-
- /**
- * Create an instance of {@link TattributeImpl }
- */
- public TattributeImpl createTattribute() {
- return new TattributeImpl();
- }
-
- /**
- * Create an instance of {@link TmetadataImpl }
- */
- public TmetadataImpl createTmetadata() {
- return new TmetadataImpl();
- }
-
- /**
- * Create an instance of {@link TdesignateImpl }
- */
- public TdesignateImpl createTdesignate() {
- return new TdesignateImpl();
- }
-
- /**
- * Create an instance of {@link TadImpl }
- */
- public TadImpl createTad() {
- return new TadImpl();
- }
-
- /**
- * Create an instance of {@link TobjectImpl }
- */
- public TobjectImpl createTobject() {
- return new TobjectImpl();
- }
-
- /**
- * Create an instance of {@link TocdImpl }
- */
- public TocdImpl createTocd() {
- return new TocdImpl();
- }
-
- /**
- * Create an instance of {@link ToptionImpl }
- */
- public ToptionImpl createToption() {
- return new ToptionImpl();
- }
-
- /**
- * Create an instance of {@link JAXBElement }{@code <}{@link TmetadataImpl }{@code >}}
- */
- @XmlElementDecl(namespace = "http://www.osgi.org/xmlns/metatype/v1.2.0", name = "MetaData")
- public JAXBElement createMetaData(TmetadataImpl value) {
- return new JAXBElement<>(_MetaData_QNAME, TmetadataImpl.class, null, value);
- }
-
-}
diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/metatype/PasswordPropertyAdapter.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/metatype/PasswordPropertyAdapter.java
index 68e5147c6a9..62bc7c33215 100644
--- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/metatype/PasswordPropertyAdapter.java
+++ b/commons/src/main/java/org/eclipse/kapua/commons/configuration/metatype/PasswordPropertyAdapter.java
@@ -12,15 +12,18 @@
*******************************************************************************/
package org.eclipse.kapua.commons.configuration.metatype;
-import com.google.common.base.Strings;
+import java.util.Arrays;
+import java.util.stream.Collectors;
+
import org.eclipse.kapua.commons.crypto.CryptoUtil;
+import org.eclipse.kapua.model.config.metatype.Password;
import org.eclipse.kapua.model.xml.XmlPropertyAdapted;
import org.eclipse.kapua.model.xml.adapters.ClassBasedXmlPropertyAdapterBase;
-import java.util.Arrays;
-import java.util.stream.Collectors;
+import com.google.common.base.Strings;
public class PasswordPropertyAdapter extends ClassBasedXmlPropertyAdapterBase {
+
private final CryptoUtil cryptoUtil;
public PasswordPropertyAdapter(CryptoUtil cryptoUtil) {
@@ -51,8 +54,10 @@ public Password unmarshallValue(String value) {
/**
* Unmarshalls the given value according to {@link XmlPropertyAdapted#isEncrypted()}.
*
- * @param value The value to unmarshall.
- * @param isEncrypted The {@link XmlPropertyAdapted#isEncrypted()}.
+ * @param value
+ * The value to unmarshall.
+ * @param isEncrypted
+ * The {@link XmlPropertyAdapted#isEncrypted()}.
* @return The unmarshalled {@link Password}
* @since 2.1.0
*/
diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/metatype/TadImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/metatype/TadImpl.java
deleted file mode 100644
index 4697b30f65d..00000000000
--- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/metatype/TadImpl.java
+++ /dev/null
@@ -1,378 +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.metatype;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.namespace.QName;
-
-import org.eclipse.kapua.model.config.metatype.KapuaTad;
-import org.eclipse.kapua.model.config.metatype.KapuaToption;
-import org.eclipse.kapua.model.config.metatype.KapuaTscalar;
-import org.w3c.dom.Element;
-
-/**
- *
- * Java class for Tad complex type.
- *
- *
- * The following schema fragment specifies the expected content contained within this class.
- *
- *
- *
- * <complexType name="Tad">
- * <complexContent>
- * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- * <sequence>
- * <element name="Option" type="{http://www.osgi.org/xmlns/metatype/v1.2.0}Toption" maxOccurs="unbounded" minOccurs="0"/>
- * <any processContents='lax' namespace='##other' maxOccurs="unbounded" minOccurs="0"/>
- * </sequence>
- * <attribute name="name" type="{http://www.w3.org/2001/XMLSchema}string" />
- * <attribute name="description" type="{http://www.w3.org/2001/XMLSchema}string" />
- * <attribute name="id" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- * <attribute name="type" use="required" type="{http://www.osgi.org/xmlns/metatype/v1.2.0}Tscalar" />
- * <attribute name="cardinality" type="{http://www.w3.org/2001/XMLSchema}int" default="0" />
- * <attribute name="min" type="{http://www.w3.org/2001/XMLSchema}string" />
- * <attribute name="max" type="{http://www.w3.org/2001/XMLSchema}string" />
- * <attribute name="default" type="{http://www.w3.org/2001/XMLSchema}string" />
- * <attribute name="required" type="{http://www.w3.org/2001/XMLSchema}boolean" default="true" />
- * <anyAttribute/>
- * </restriction>
- * </complexContent>
- * </complexType>
- *
- *
- * @since 1.0
- */
-
-public class TadImpl implements KapuaTad {
-
- protected List option;
- protected List