Request to create the cmHandle | POST {ncmpRoot}/ncmpInventory/v1/ch/ |
JSON Viewer |
---|
{
"dmiPlugin": "onap.dmi.plugin",
"updatedCmHandles": [
{
"cmHandle": "myHandle1",
"cmHandleProperties": {
"prop1": "value1",
"prop2": "value2",
"prop3": "value3"
}
}
]
} |
{ "dmiPlugin": "onap.dmi.plugin", "createdCmHandles": [ { "cmHandle": "myHandle1", "cmHandleProperties": { "prop1": "value1", "prop2": "value2", "prop3": "value3" } } ] } |
---|
| No Impact. It will create the cmHandle. | Existing behaviour. |
Request has updatedCmHandles tag present in the incoming request. | POST {ncmpRoot}/ncmpInventory/v1/ch/ |
JSON Viewer |
---|
{
"dmiPlugin": "onap.dmi.plugin",
"updatedCmHandles": [
{
"cmHandle": "myHandle1",
"cmHandleProperties": {
: {
"prop1": null,
//case-1
"prop2": "newValue2", //case-2
"prop4": "value4"
//case-3
}
}
]
} |
{ "dmiPlugin": "onap.dmi.plugin", "updatedCmHandles": [ { "cmHandle": "myHandle1", "cmHandleProperties": { "prop1": null, //case-1 "prop2": "newValue2", //case-2 "prop4": "value4" //case-3 } } ] } |
---|
case-1 : Property which needs to be removed must be explicitly set to null case-2: Property which needs to be updated can have the new values in the incoming request. case-3: Property which needs to be added can be present in the form of "name" : "value" as seen above. |
JSON Viewer |
---|
{
"cmHandle": "myHandle1",
"cmHandleProperties": {
"prop2": "newValue2",
"prop3": "value3",
"prop4": "value4"
}
} |
Code Block |
---|
language | java |
---|
title | Constants |
---|
| NCMP_DATASPACE_NAME = "NCMP-Admin";
NCMP_DMI_REGISTRY_ANCHOR = "ncmp-dmi-registry"; |
Changes: – NetworkCmProxyDataServiceImpl [ step1 to step3 ] – CpsDataServiceImpl [ step4 ]
Since the incoming request has updatedCmHandles tag hence we need to check if there are properties eligible to be updated.
- Iterate over the incoming cmHandles and for each cmHandle do the following.
Form the xpath from the incoming request.
Code Block |
---|
language | java |
---|
title | Form xpath |
---|
| final String targetXpath = "/dmi-registry/cm-handles[@id='" + cmHandleID + "']";
eg : "/dmi-registry/cm-handles[@id=myHandle1]" |
Get the dataNodes using the above xpath been created including all the leaves (leaves denotes the attributes).
Code Block |
---|
language | java |
---|
title | Get Data Nodes using xpath |
---|
| final DataNode dataNode = cpsDataService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
targetXpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS); |
Get handle of the leaves(with existing data) and apply the changes only to the attribute which are present in the incoming request. The attributes which are explicitly set to null will be removed and others which are present will be updated. The attributes which are not specified will not be touched.
Code Block |
---|
language | java |
---|
title | Core logic to add or remove attributes |
---|
| if (leaves.containsKey(targetAttributeKey)) {
if (targetAttributeValue == null) {
log.info("Removing the attribute with ( key : {} , existingValue : {} )", targetAttributeKey,
leaves.get(targetAttributeKey));
leaves.remove(targetAttributeKey);
} else {
log.info("Updating the attribute with ( key : {} , existingValue : {} to newValue : {}",
targetAttributeKey, leaves.get(targetAttributeKey), targetAttributeValue);
leaves.put(targetAttributeKey, targetAttributeValue);
}
} |
- Perform step-2 for all the cmHandles and collect the updated dataNodes.
Now since from step-3 we have a Collection<DataNode> which have the updated changes , we can make use of replaceListContent method to apply our changes.
Note : We are creating an overloaded version of replaceListContent method which takes in Collection<DataNode> directly instead of String jsonData as we directly have the dataNode from step 2.b.
Code Block |
---|
language | java |
---|
title | replaceListContent(final String dataspaceName, final String anchorName, final String parentNodeXpath, final Collection<DataNode> dataNodes, final OffsetDateTime observedTimestamp) |
---|
| @Override
public void replaceListContent(final String dataspaceName, final String anchorName, final String parentNodeXpath,
final Collection<DataNode> dataNodes, final OffsetDateTime observedTimestamp) {
cpsDataPersistenceService.replaceListContent(dataspaceName, anchorName, parentNodeXpath, dataNodes);
processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp, parentNodeXpath, Operation.UPDATE);
} |
|
|