-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ isolating TMetadata retrieval logic for ServiceConfigurations in i…
…ts own class Signed-off-by: dseurotech <[email protected]>
- Loading branch information
1 parent
7ece681
commit 68817c4
Showing
19 changed files
with
126 additions
and
59 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...clipse/kapua/commons/configuration/ResourceBasedServiceConfigurationMetadataProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
|
||
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...in/java/org/eclipse/kapua/commons/configuration/ServiceConfigurationMetadataProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<KapuaTmetadata> fetchMetadata(TxContext txContext, String pid); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.