-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
…ts own class Signed-off-by: dseurotech <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<KapuaTmetadata> fetchMetadata(TxContext txContext, String pid) { | ||
URL url = ResourceUtils.getResource(String.format("META-INF/metatypes/%s.xml", pid)); | ||
Check warning on line 34 in commons/src/main/java/org/eclipse/kapua/commons/configuration/ResourceBasedServiceConfigurationMetadataProvider.java Codecov / codecov/patchcommons/src/main/java/org/eclipse/kapua/commons/configuration/ResourceBasedServiceConfigurationMetadataProvider.java#L34
|
||
|
||
if (url == null) { | ||
return Optional.empty(); | ||
Check warning on line 37 in commons/src/main/java/org/eclipse/kapua/commons/configuration/ResourceBasedServiceConfigurationMetadataProvider.java Codecov / codecov/patchcommons/src/main/java/org/eclipse/kapua/commons/configuration/ResourceBasedServiceConfigurationMetadataProvider.java#L37
|
||
} | ||
|
||
try { | ||
return Optional.ofNullable(xmlUtil.unmarshal(ResourceUtils.openAsReader(url, StandardCharsets.UTF_8), KapuaTmetadata.class)) | ||
Check warning on line 41 in commons/src/main/java/org/eclipse/kapua/commons/configuration/ResourceBasedServiceConfigurationMetadataProvider.java Codecov / codecov/patchcommons/src/main/java/org/eclipse/kapua/commons/configuration/ResourceBasedServiceConfigurationMetadataProvider.java#L41
|
||
.filter(v -> v.getOCD() != null && !v.getOCD().isEmpty()); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
Check warning on line 44 in commons/src/main/java/org/eclipse/kapua/commons/configuration/ResourceBasedServiceConfigurationMetadataProvider.java Codecov / codecov/patchcommons/src/main/java/org/eclipse/kapua/commons/configuration/ResourceBasedServiceConfigurationMetadataProvider.java#L43-L44
|
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/******************************************************************************* | ||
* 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. | ||
* @throws Exception | ||
* @since 1.0.0 | ||
*/ | ||
Optional<KapuaTmetadata> fetchMetadata(TxContext txContext, String pid); | ||
} |