/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2023 Nordix Foundation
+ * Copyright (C) 2022-2024 Nordix Foundation
* Modifications Copyright (C) 2023 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import java.util.Map;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
+import org.onap.cps.ncmp.api.impl.config.embeddedcache.TrustLevelCacheConfig;
import org.onap.cps.ncmp.api.impl.inventory.enums.PropertyType;
+import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel;
import org.onap.cps.spi.CpsDataPersistenceService;
import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.model.DataNode;
+import org.onap.cps.spi.utils.CpsValidator;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
@RequiredArgsConstructor
public class CmHandleQueriesImpl implements CmHandleQueries {
private static final String DESCENDANT_PATH = "//";
-
- private final CpsDataPersistenceService cpsDataPersistenceService;
private static final String ANCESTOR_CM_HANDLES = "/ancestor::cm-handles";
+ private final CpsDataPersistenceService cpsDataPersistenceService;
+
+ @Qualifier(TrustLevelCacheConfig.TRUST_LEVEL_PER_DMI_PLUGIN)
+ private final Map<String, TrustLevel> trustLevelPerDmiPlugin;
+
+ @Qualifier(TrustLevelCacheConfig.TRUST_LEVEL_PER_CM_HANDLE)
+ private final Map<String, TrustLevel> trustLevelPerCmHandle;
+
+ private final CpsValidator cpsValidator;
@Override
public Collection<String> queryCmHandleAdditionalProperties(final Map<String, String> privatePropertyQueryPairs) {
return queryCmHandleAnyProperties(publicPropertyQueryPairs, PropertyType.PUBLIC);
}
+ @Override
+ public Collection<String> queryCmHandlesByTrustLevel(final Map<String, String> trustLevelPropertyQueryPairs) {
+ final String trustLevelProperty = trustLevelPropertyQueryPairs.values().iterator().next();
+ final TrustLevel targetTrustLevel = TrustLevel.valueOf(trustLevelProperty);
+
+ return getCmHandleIdsByTrustLevel(targetTrustLevel);
+ }
+
@Override
public List<DataNode> queryCmHandlesByState(final CmHandleState cmHandleState) {
return queryCmHandleAncestorsByCpsPath("//state[@cm-handle-state=\"" + cmHandleState + "\"]",
return cmHandleIds;
}
+ private Collection<String> getCmHandleIdsByTrustLevel(final TrustLevel targetTrustLevel) {
+ final Collection<String> selectedCmHandleIds = new HashSet<>();
+
+ for (final Map.Entry<String, TrustLevel> mapEntry : trustLevelPerDmiPlugin.entrySet()) {
+ final String dmiPluginIdentifier = mapEntry.getKey();
+ final TrustLevel dmiTrustLevel = mapEntry.getValue();
+ final Collection<String> candidateCmHandleIds = getCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifier);
+ for (final String candidateCmHandleId : candidateCmHandleIds) {
+ final TrustLevel candidateCmHandleTrustLevel = trustLevelPerCmHandle.get(candidateCmHandleId);
+ final TrustLevel effectiveTrustlevel =
+ candidateCmHandleTrustLevel.getEffectiveTrustLevel(dmiTrustLevel);
+ if (targetTrustLevel.equals(effectiveTrustlevel)) {
+ selectedCmHandleIds.add(candidateCmHandleId);
+ }
+ }
+ }
+
+ return selectedCmHandleIds;
+ }
+
private Collection<String> collectCmHandleIdsFromDataNodes(final Collection<DataNode> dataNodes) {
return dataNodes.stream().map(dataNode -> (String) dataNode.getLeaves().get("id")).collect(Collectors.toSet());
}
}
private DataNode getCmHandleState(final String cmHandleId) {
+ cpsValidator.validateNameCharacters(cmHandleId);
final String xpath = NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='" + cmHandleId + "']/state";
return cpsDataPersistenceService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
xpath, OMIT_DESCENDANTS).iterator().next();