Merge "Add resource resolution component DSL"
diff --git a/cds-ui/client/src/app/common/core/store/models/resourcesState.model.ts b/cds-ui/client/src/app/common/core/store/models/resourcesState.model.ts
index 7dacf32..df9c287 100644
--- a/cds-ui/client/src/app/common/core/store/models/resourcesState.model.ts
+++ b/cds-ui/client/src/app/common/core/store/models/resourcesState.model.ts
@@ -22,7 +22,7 @@
 
 export interface IResourcesState {
     resources: IResources,
-    isLoadSuccess: boolean;
-    isUpdateSuccess: boolean;
-    isSaveSuccess: boolean;
+    isLoadSuccess?: boolean;
+    isUpdateSuccess?: boolean;
+    isSaveSuccess?: boolean;
 }
\ No newline at end of file
diff --git a/cds-ui/client/src/app/common/core/store/reducers/resources.reducer.ts b/cds-ui/client/src/app/common/core/store/reducers/resources.reducer.ts
index c9d587d..b6b11b9 100644
--- a/cds-ui/client/src/app/common/core/store/reducers/resources.reducer.ts
+++ b/cds-ui/client/src/app/common/core/store/reducers/resources.reducer.ts
@@ -29,6 +29,10 @@
             return {...state,
                     resources: action.payload
                     }
+        case ResourcesActions.SET_RESOURCES_STATE:
+            return {...state,
+                    resources: action.payload.resources
+                    }
         default:
             return state;
     }
diff --git a/cds-ui/client/src/app/feature-modules/resource-definition/resource-edit/resource-edit.component.ts b/cds-ui/client/src/app/feature-modules/resource-definition/resource-edit/resource-edit.component.ts
index aa8a106..faf7fbd 100644
--- a/cds-ui/client/src/app/feature-modules/resource-definition/resource-edit/resource-edit.component.ts
+++ b/cds-ui/client/src/app/feature-modules/resource-definition/resource-edit/resource-edit.component.ts
@@ -77,6 +77,7 @@
     
  onChange($event) {
       this.data=JSON.parse($event.srcElement.value);
+      this.updateResourcesState();
   };
   
  updateResourcesState(){
diff --git a/docs/datadictionary/resourcesource.rst b/docs/datadictionary/resourcesource.rst
index 852a34f..49ef6a1 100644
--- a/docs/datadictionary/resourcesource.rst
+++ b/docs/datadictionary/resourcesource.rst
@@ -9,28 +9,34 @@
 ======
 Expects the value to be provided as input to the request.
 
-source-input:
 
-.. code: json
-print("
-  "description": "This is Input Resource Source Node Type",
-  "version": "1.0.0",
-  "properties": {},
-  "derived_from": "tosca.nodes.ResourceSource"
-")
+
+.. code-block:: json
+   :linenos:
+
+   source-input
+   {
+    "description": "This is Input Resource Source Node Type",
+    "version": "1.0.0",
+    "properties": {},
+    "derived_from": "tosca.nodes.ResourceSource"
+   }
 
 
 Default:
 ========
 Expects the value to be defaulted in the model itself.
 
-source-default:
+.. code-block:: json
+   :linenos:
 
-  "description": "This is Default Resource Source Node Type",
-  "version": "1.0.0",
-  "properties": {},
-  "derived_from": "tosca.nodes.ResourceSource"
-
+   source-default
+   {
+    "description": "This is Default Resource Source Node Type",
+    "version": "1.0.0",
+    "properties": {},
+    "derived_from": "tosca.nodes.ResourceSource"
+   }
 
 
 sql:
diff --git a/docs/index.rst b/docs/index.rst
index 45b124f..e80917b 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -47,7 +47,7 @@
 
 
 Modeling Concept
-================
+----------------
 
 In Dublin release, the CDS community has contributed a framework to automate
 the resolution of resources for instantiation and any config provisioning
@@ -69,7 +69,7 @@
 |image0|
 
 Modeling Concept Links:
------------------------
+~~~~~~~~~~~~~~~~~~~~~~~
 
 .. toctree::
    :maxdepth: 1
@@ -82,7 +82,7 @@
 
 
 Design tools
-============
+------------
 .. toctree::
    :maxdepth: 1
    :glob:
@@ -94,19 +94,21 @@
 
 
 Scripts
-=======
-
-Library
 -------
 
-*NetconfClient
---------------
+Library
+~~~~~~~
+
+* NetconfClient
+~~~~~~~~~~~~~~
+
 In order to facilitate NETCONF interaction within scripts, a python NetconfClient binded to our Kotlin implementation is made available. This NetconfClient can be used when using the component-netconf-executor.
 
 The client can be find here: https://github.com/onap/ccsdk-cds/blob/master/components/scripts/python/ccsdk_netconf/netconfclient.py
 
-*ResolutionHelper
------------------
+* ResolutionHelper
+~~~~~~~~~~~~~~~~~
+
 When executing a component executor script, designer might want to perform
 resource resolution along with template meshing directly from the script
 itself.
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolution.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolution.kt
index 70aadb4..e3f8763 100755
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolution.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolution.kt
@@ -71,7 +71,7 @@
     @get:ApiModelProperty(value = "If resolution occurred multiple time, this field provides the index.",
         required = true)
     @Column(name = "occurrence", nullable = false)
-    var occurrence: Int = 0
+    var occurrence: Int = 1
 
     @Id
     @Column(name = "template_resolution_id")
@@ -87,4 +87,4 @@
     companion object {
         private const val serialVersionUID = 1L
     }
-}
\ No newline at end of file
+}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionService.kt
index 55f7e77..c64605e 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionService.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionService.kt
@@ -53,7 +53,7 @@
                                                                                       blueprintVersion: String,
                                                                                       artifactPrefix: String,
                                                                                       resolutionKey: String,
-                                                                                      occurrence: Int = 0): String =
+                                                                                      occurrence: Int = 1): String =
         withContext(Dispatchers.IO) {
 
             templateResolutionRepository.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
@@ -69,7 +69,7 @@
                                                                                                  artifactPrefix: String,
                                                                                                  resourceId: String,
                                                                                                  resourceType: String,
-                                                                                                 occurrence: Int = 0): String =
+                                                                                                 occurrence: Int = 1): String =
         withContext(Dispatchers.IO) {
 
             templateResolutionRepository.findByResourceIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
@@ -93,7 +93,6 @@
         val resourceId = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] as String
         val resourceType = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] as String
         val occurrence = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] as Int
-
         write(blueprintName,
             blueprintVersion,
             artifactPrefix,
@@ -105,7 +104,7 @@
     }
 
     suspend fun write(blueprintName: String, blueprintVersion: String, artifactPrefix: String,
-                      template: String, occurrence: Int = 0, resolutionKey: String = "", resourceId: String = "",
+                      template: String, occurrence: Int = 1, resolutionKey: String = "", resourceId: String = "",
                       resourceType: String = ""): TemplateResolution =
         withContext(Dispatchers.IO) {
 
@@ -148,9 +147,13 @@
                 }
             }
             try {
+                log.info("Writing out template_resolution result: bpName: $blueprintName bpVer $blueprintVersion resKey:$resolutionKey" +
+                    " (resourceId: $resourceId resourceType: $resourceType) occurrence:$occurrence")
                 templateResolutionRepository.saveAndFlush(resourceResolutionResult)
             } catch (ex: DataIntegrityViolationException) {
+                log.error("Error writing out template_resolution result: bpName: $blueprintName bpVer $blueprintVersion resKey:$resolutionKey" +
+                    " (resourceId: $resourceId resourceType: $resourceType) occurrence:$occurrence error: {}", ex.message)
                 throw BluePrintException("Failed to store resource api result.", ex)
             }
         }
-}
\ No newline at end of file
+}