import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.onap.cps.ncmp.api.impl.inventory.enums.PropertyType;
+import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel;
+import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevelFilter;
import org.onap.cps.spi.CpsDataPersistenceService;
import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.model.DataNode;
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;
+ private final Map<String, TrustLevel> trustLevelPerCmHandle;
@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);
+
+ final TrustLevelFilter trustLevelFilter = new TrustLevelFilter(targetTrustLevel, trustLevelPerCmHandle);
+ return trustLevelFilter.getAllCmHandleIdsByTargetTrustLevel();
+ }
+
@Override
public List<DataNode> queryCmHandlesByState(final CmHandleState cmHandleState) {
- return queryCmHandleDataNodesByCpsPath("//state[@cm-handle-state=\"" + cmHandleState + "\"]",
+ return queryCmHandleAncestorsByCpsPath("//state[@cm-handle-state=\"" + cmHandleState + "\"]",
INCLUDE_ALL_DESCENDANTS);
}
@Override
- public List<DataNode> queryCmHandleDataNodesByCpsPath(final String cpsPath,
- final FetchDescendantsOption fetchDescendantsOption) {
+ public List<DataNode> queryNcmpRegistryByCpsPath(final String cpsPath,
+ final FetchDescendantsOption fetchDescendantsOption) {
return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- cpsPath + ANCESTOR_CM_HANDLES, fetchDescendantsOption);
+ cpsPath, fetchDescendantsOption);
+ }
+
+ @Override
+ public List<DataNode> queryCmHandleAncestorsByCpsPath(final String cpsPath,
+ final FetchDescendantsOption fetchDescendantsOption) {
+ return queryNcmpRegistryByCpsPath(cpsPath + ANCESTOR_CM_HANDLES, fetchDescendantsOption);
}
@Override
@Override
public List<DataNode> queryCmHandlesByOperationalSyncState(final DataStoreSyncState dataStoreSyncState) {
- return queryCmHandleDataNodesByCpsPath("//state/datastores" + "/operational[@sync-state=\""
+ return queryCmHandleAncestorsByCpsPath("//state/datastores" + "/operational[@sync-state=\""
+ dataStoreSyncState + "\"]", FetchDescendantsOption.OMIT_DESCENDANTS);
}
+ publicPropertyQueryPair.getKey()
+ "\" and @value=\"" + publicPropertyQueryPair.getValue() + "\"]";
- final Collection<DataNode> dataNodes = queryCmHandleDataNodesByCpsPath(cpsPath, OMIT_DESCENDANTS);
+ final Collection<DataNode> dataNodes = queryCmHandleAncestorsByCpsPath(cpsPath,
+ OMIT_DESCENDANTS);
if (cmHandleIds == null) {
cmHandleIds = collectCmHandleIdsFromDataNodes(dataNodes);
} else {