package org.onap.cps.ncmp.api.data.models;
-import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.onap.cps.ncmp.config.CpsApplicationContext;
public class CmResourceAddress {
private final String datastoreName;
- @Getter(AccessLevel.NONE)
private final String cmHandleReference;
private final String resourceIdentifier;
- public String getResolvedCmHandleId() {
- return CpsApplicationContext.getCpsBean(AlternateIdMatcher.class).getCmHandleId(cmHandleReference);
+ public String resolveCmHandleReferenceToId() {
+ final AlternateIdMatcher alternateIdMatcher = CpsApplicationContext.getCpsBean(AlternateIdMatcher.class);
+ return alternateIdMatcher.getCmHandleId(cmHandleReference);
}
}
import org.onap.cps.ncmp.impl.utils.http.RestServiceUrlTemplateBuilder;
import org.onap.cps.ncmp.impl.utils.http.UrlTemplateParameters;
import org.onap.cps.spi.exceptions.CpsException;
+import org.onap.cps.spi.exceptions.DataNodeNotFoundException;
import org.onap.cps.utils.JsonObjectMapper;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
final String topic,
final String requestId,
final String authorization) {
- final YangModelCmHandle yangModelCmHandle = getYangModelCmHandle(cmResourceAddress.getResolvedCmHandleId());
+ final YangModelCmHandle yangModelCmHandle = resolveYangModelCmHandleFromCmHandleReference(cmResourceAddress);
final CmHandleState cmHandleState = yangModelCmHandle.getCompositeState().getCmHandleState();
validateIfCmHandleStateReady(yangModelCmHandle, cmHandleState);
final String jsonRequestBody = getDmiRequestBody(READ, requestId, null, null, yangModelCmHandle);
final CmResourceAddress cmResourceAddress =
new CmResourceAddress(PASSTHROUGH_RUNNING.getDatastoreName(), cmHandleId, resourceId);
- final YangModelCmHandle yangModelCmHandle = getYangModelCmHandle(cmResourceAddress.getResolvedCmHandleId());
+ final YangModelCmHandle yangModelCmHandle =
+ getYangModelCmHandle(cmResourceAddress.resolveCmHandleReferenceToId());
policyExecutor.checkPermission(yangModelCmHandle, operationType, authorization, resourceId, requestData);
}).subscribe();
}
+ private YangModelCmHandle resolveYangModelCmHandleFromCmHandleReference(final CmResourceAddress cmResourceAddress) {
+ String cmHandleId = cmResourceAddress.getCmHandleReference();
+ try {
+ return getYangModelCmHandle(cmHandleId);
+ } catch (final DataNodeNotFoundException ignored) {
+ cmHandleId = cmResourceAddress.resolveCmHandleReferenceToId();
+ return getYangModelCmHandle(cmHandleId);
+ }
+ }
+
private String createDmiDataOperationRequestAsJsonString(
final List<DmiDataOperation> dmiDataOperationRequestBodies) {
final DmiDataOperationRequest dmiDataOperationRequest = DmiDataOperationRequest.builder()
final FetchDescendantsOption fetchDescendantsOption = getFetchDescendantsOption(includeDescendants);
final DataNode dataNode = cpsDataService.getDataNodes(cmResourceAddress.getDatastoreName(),
- cmResourceAddress.getResolvedCmHandleId(),
+ cmResourceAddress.resolveCmHandleReferenceToId(),
cmResourceAddress.getResourceIdentifier(),
fetchDescendantsOption).iterator().next();
return Mono.justOrEmpty(dataNode);
import org.onap.cps.ncmp.impl.utils.AlternateIdMatcher
import org.onap.cps.ncmp.impl.utils.http.UrlTemplateParameters
import org.onap.cps.ncmp.utils.TestUtils
+import org.onap.cps.spi.exceptions.DataNodeNotFoundException
import org.onap.cps.utils.JsonObjectMapper
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
mockDmiRestClient.asynchronousPostOperationWithJsonData(DATA, expectedUrlTemplateWithVariables, expectedJson, READ, NO_AUTH_HEADER) >> responseFromDmi
when: 'get resource data is invoked'
def cmResourceAddress = new CmResourceAddress(expectedDataStore.datastoreName, cmHandleId, resourceIdentifier)
- alternateIdMatcher.getCmHandleId(cmHandleId) >> cmHandleId
def result = objectUnderTest.getResourceDataFromDmi(cmResourceAddress, expectedOptions, NO_TOPIC, NO_REQUEST_ID, NO_AUTH_HEADER).block()
then: 'the result is the response from the DMI service'
assert result.body == '{some-key:some-value}'
CmHandleState.ADVISED || true
}
+ def 'Resolving cm handle references with cm handle id.'() {
+ given: 'a resource address with a cm handle id'
+ def cmResourceAddress = new CmResourceAddress('some store', 'cm-handle-id', 'some resource')
+ and: 'the given cm handle id is available in the inventory'
+ mockInventoryPersistence.getYangModelCmHandle('cm-handle-id') >> yangModelCmHandle
+ expect: 'resolving the cm handle id returns the cm handle'
+ assert objectUnderTest.resolveYangModelCmHandleFromCmHandleReference(cmResourceAddress) == yangModelCmHandle
+ }
+
+ def 'Resolving cm handle references with alternate id.'() {
+ given: 'a resource with a alternate id'
+ def cmResourceAddress = new CmResourceAddress('some store', 'alternate-id', 'some resource')
+ and: 'the alternate id cannot be found in the inventory directly and that results in a data node not found exception'
+ mockInventoryPersistence.getYangModelCmHandle('alternate-id') >> { throw new DataNodeNotFoundException('','') }
+ and: 'the alternate id can be matched to a cm handle id'
+ alternateIdMatcher.getCmHandleId('alternate-id') >> 'cm-handle-id'
+ and: 'that cm handle id is available in the inventory'
+ mockInventoryPersistence.getYangModelCmHandle('cm-handle-id') >> yangModelCmHandle
+ expect: 'resolving that cm handle id returns the cm handle'
+ assert objectUnderTest.resolveYangModelCmHandleFromCmHandleReference(cmResourceAddress) == yangModelCmHandle
+ }
+
+
def extractDataValue(actualDataOperationCloudEvent) {
return toTargetEvent(actualDataOperationCloudEvent, DataOperationEvent).data.responses[0]
}
ObjectMapper spyObjectMapper = Spy()
def yangModelCmHandle = new YangModelCmHandle()
+ def otherYangModelCmHandle = new YangModelCmHandle()
def static dmiServiceName = 'myServiceName'
def static cmHandleId = 'some-cm-handle'
def static alternateId = 'alt-id-' + cmHandleId