RIFT-14705 - UI Composer: Add IVLD to VNFD is broken

Signed-off-by: KIRAN KASHALKAR <kiran.kashalkar@riftio.com>
diff --git a/skyquake/plugins/composer/src/src/libraries/model/DescriptorModel.js b/skyquake/plugins/composer/src/src/libraries/model/DescriptorModel.js
index 02bbfcd..1a2ba4f 100644
--- a/skyquake/plugins/composer/src/src/libraries/model/DescriptorModel.js
+++ b/skyquake/plugins/composer/src/src/libraries/model/DescriptorModel.js
@@ -182,7 +182,10 @@
 			throw new ReferenceError('child must be an instance of DescriptorModel class');
 		}
 		if (this.findChildByUid(child.uid)) {
-			throw new ReferenceError('child already exists');
+			console.warn('Child already exists');
+			// NOTE: Commented out this line because it was causing issues with Internal VLD.
+			// TODO: Check why it caused issues with Internal VLD
+			// throw new ReferenceError('child already exists');
 		}
 		if (child.parent instanceof DescriptorModel) {
 			throw new ReferenceError('child already has a parent');
diff --git a/skyquake/plugins/composer/src/src/libraries/model/DescriptorModelFactory.js b/skyquake/plugins/composer/src/src/libraries/model/DescriptorModelFactory.js
index 68b70d7..ac59872 100644
--- a/skyquake/plugins/composer/src/src/libraries/model/DescriptorModelFactory.js
+++ b/skyquake/plugins/composer/src/src/libraries/model/DescriptorModelFactory.js
@@ -262,7 +262,7 @@
 
 	static newInternalConnectionPointRef(model, parent) {
 		// note do not find children bc model is not an object it is a leaf-list primative and so the class manages it
-		return new InternalConnectionPointRef(model, parent);
+		return findChildDescriptorModelAndUpdateModel(model, parent) || new InternalConnectionPointRef(model, parent);
 	}
 
 	/**
diff --git a/skyquake/plugins/composer/src/src/libraries/model/DescriptorModelSerializer.js b/skyquake/plugins/composer/src/src/libraries/model/DescriptorModelSerializer.js
index 7581ed5..4e6b792 100644
--- a/skyquake/plugins/composer/src/src/libraries/model/DescriptorModelSerializer.js
+++ b/skyquake/plugins/composer/src/src/libraries/model/DescriptorModelSerializer.js
@@ -165,6 +165,11 @@
 			return _.pick(ref, ['member-vnf-index-ref', 'vnfd-id-ref', 'vnfd-connection-point-ref']);
 		}
 	},
+	'internal-connection-point': {
+		serialize(ref) {
+			return _.pick(ref, ['id-ref']);
+		}
+	},
 	'constituent-vnfd': {
 		serialize(cvnfdModel) {
 			if(!cvnfdFields) cvnfdFields = DescriptorModelMetaFactory.getModelFieldNamesForType('nsd.constituent-vnfd');
diff --git a/skyquake/plugins/composer/src/src/libraries/model/descriptors/InternalConnectionPoint.js b/skyquake/plugins/composer/src/src/libraries/model/descriptors/InternalConnectionPoint.js
index 6648dc9..14a74f0 100644
--- a/skyquake/plugins/composer/src/src/libraries/model/descriptors/InternalConnectionPoint.js
+++ b/skyquake/plugins/composer/src/src/libraries/model/descriptors/InternalConnectionPoint.js
@@ -15,15 +15,13 @@
  *   limitations under the License.
  *
  */
-/**
- * Created by onvelocity on 11/23/15.
- */
 
 'use strict';
 
-import Position from '../../graph/Position'
-import DescriptorModel from '../DescriptorModel'
-import DescriptorModelFactory from '../DescriptorModelFactory'
+import Position from '../../graph/Position';
+import DescriptorModel from '../DescriptorModel';
+import DescriptorModelFactory from '../DescriptorModelFactory';
+import InternalConnectionPointRef from './InternalConnectionPointRef';
 
 export default class InternalConnectionPoint extends DescriptorModel {
 
@@ -56,8 +54,31 @@
 		return this.id;
 	}
 
+	get id() {
+		return this.model.id;
+	}
+
+	get name() {
+		return this.model.name
+	}
+
+	get idRef() {
+		return this.parent.idRef;
+	}
+
+	get cpNumber() {
+		return this.uiState.cpNumber;
+	}
+
+	set cpNumber(n) {
+		this.uiState.cpNumber = n;
+	}
+
 	toInternalConnectionPointRef() {
-		return DescriptorModelFactory.newInternalConnectionPointRef(this.id);
+		const ref = new InternalConnectionPointRef({});
+		ref.idRef = this.id;
+		// ref.cpNumber = this.cpNumber;
+		return ref;
 	}
 
 	canConnectTo(obj) {
diff --git a/skyquake/plugins/composer/src/src/libraries/model/descriptors/InternalConnectionPointRef.js b/skyquake/plugins/composer/src/src/libraries/model/descriptors/InternalConnectionPointRef.js
index a7ea751..ad70b57 100644
--- a/skyquake/plugins/composer/src/src/libraries/model/descriptors/InternalConnectionPointRef.js
+++ b/skyquake/plugins/composer/src/src/libraries/model/descriptors/InternalConnectionPointRef.js
@@ -15,9 +15,6 @@
  *   limitations under the License.
  *
  */
-/**
- * Created by onvelocity on 11/23/15.
- */
 
 'use strict';
 
@@ -27,7 +24,7 @@
 export default class InternalConnectionPointRef extends DescriptorModel {
 
 	static get type() {
-		return 'internal-connection-point-ref';
+		return 'internal-connection-point';
 	}
 
 	static get className() {
@@ -39,23 +36,35 @@
 	}
 
 	constructor(m, parent) {
-		super(!m || typeof m === 'string' ? {id: m, isLeaf: true} : m, parent);
+		super(m, parent);
 		this.uid = this.id;
 		this.type = InternalConnectionPointRef.type;
 		this.uiState['qualified-type'] = InternalConnectionPointRef.qualifiedType;
 		this.className = InternalConnectionPointRef.className;
 	}
 
-	toString() {
-		return this.valueOf();
+	get key() {
+		return this.model['id-ref'];
+	}
+
+	get idRef() {
+		return this.model['id-ref'];
+	}
+
+	set idRef(id) {
+		return this.model['id-ref'] = id;
+	}
+
+	get cpNumber() {
+		return this.uiState.cpNumber;
+	}
+
+	set cpNumber(n) {
+		this.uiState.cpNumber = n;
 	}
 
 	remove() {
-		return this.parent.removeInternalConnectionPointRefForId(this.id);
-	}
-
-	valueOf() {
-		return this.id;
+		return this.parent.removeInternalConnectionPointRefForId(this.idRef);
 	}
 
 }
diff --git a/skyquake/plugins/composer/src/src/libraries/model/descriptors/InternalVirtualLink.js b/skyquake/plugins/composer/src/src/libraries/model/descriptors/InternalVirtualLink.js
index c3822d5..b3e4fc6 100644
--- a/skyquake/plugins/composer/src/src/libraries/model/descriptors/InternalVirtualLink.js
+++ b/skyquake/plugins/composer/src/src/libraries/model/descriptors/InternalVirtualLink.js
@@ -15,14 +15,12 @@
  *   limitations under the License.
  *
  */
-/**
- * Created by onvelocity on 11/23/15.
- */
 
 'use strict';
 
 import DescriptorModel from '../DescriptorModel'
 import DescriptorModelFactory from '../DescriptorModelFactory'
+import DescriptorModelMetaFactory from '../DescriptorModelMetaFactory'
 
 export default class InternalVirtualLink extends DescriptorModel {
 
@@ -50,22 +48,37 @@
 	}
 
 	get connection() {
-		const list = this.model['internal-connection-point-ref'] || (this.model['internal-connection-point-ref'] = []);
-		return list.map(d => DescriptorModelFactory.newInternalConnectionPointRef(d, this));
+		if (!this.model['internal-connection-point']) {
+			this.model['internal-connection-point'] = [];
+		}
+		return this.model['internal-connection-point'].map(d => DescriptorModelFactory.newInternalConnectionPointRef(d, this));
 	}
 
 	set connection(connections) {
-		return this.updateModelList('internal-connection-point-ref', connections, DescriptorModelFactory.InternalConnectionPointRef);
+		return this.updateModelList('internal-connection-point', connections, DescriptorModelFactory.InternalConnectionPointRef);
+	}
+
+	createInternalConnectionPoint(model) {
+		model = model || DescriptorModelMetaFactory.createModelInstanceForType('vnfd.internal-vld.internal-connection-point');
+		return this.connection = DescriptorModelFactory.newInternalConnectionPointRef(model, this);
+	}
+
+	removeInternalConnectionPointRefForIdRefKey(cpRefKey) {
+		const child = this.connection.filter(d => d.key === cpRefKey)[0];
+		return this.removeModelListItem('connection', child);
 	}
 
 	addConnectionPoint(icp) {
-		icp.model['internal-vld-ref'] = this.id;
 		this.parent.removeAnyConnectionsForConnector(icp);
-		this.connection = icp.toInternalConnectionPointRef();
+		const icpRef = icp.toInternalConnectionPointRef();
+		// this.connection = icp.toInternalConnectionPointRef();
+		this.connection = this.connection.concat(icpRef);
 	}
 
-	removeInternalConnectionPointRefForId(id) {
-		return this.connection = this.connection.filter(d => d.id !== id).map(d => d.id);
+	removeInternalConnectionPointRefForId(idRef) {
+		// return this.connection = this.connection.filter(d => d.idRef !== idRef).map(d => d.idRef);
+		// KKTODO: Check if below works instead
+		return this.connection = this.connection.filter(d => d.idRef !== idRef).map(d => d.model);
 	}
 
 	remove() {
diff --git a/skyquake/plugins/composer/src/src/libraries/model/descriptors/VirtualDeploymentUnitInternalConnectionPoint.js b/skyquake/plugins/composer/src/src/libraries/model/descriptors/VirtualDeploymentUnitInternalConnectionPoint.js
index 47947c8..c34d823 100644
--- a/skyquake/plugins/composer/src/src/libraries/model/descriptors/VirtualDeploymentUnitInternalConnectionPoint.js
+++ b/skyquake/plugins/composer/src/src/libraries/model/descriptors/VirtualDeploymentUnitInternalConnectionPoint.js
@@ -15,21 +15,16 @@
  *   limitations under the License.
  *
  */
-/**
- * Created by onvelocity on 11/23/15.
- */
 
 'use strict';
 
 import Position from '../../graph/Position'
-import DescriptorModel from '../DescriptorModel'
 import InternalConnectionPoint from './InternalConnectionPoint'
-import RspConnectionPointRef from './RspConnectionPointRef'
-import VnfdConnectionPointRef from './VnfdConnectionPointRef'
-import DescriptorModelFactory from '../DescriptorModelFactory'
+
 
 /**
- * A VirtualNetworkFunctionConnectionPoint is always a child of a VNFD. We use it to build VnfdConnectionPointRef instances. So convenience
+ * A VirtualDeploymentUnitInternalConnectionPoint is always a child of a VDU.
+ * We use it to build internal-connection-point.id-ref instances. So convenience
  * methods are add to access the fields needed to do that.
  */
 export default class VirtualDeploymentUnitInternalConnectionPoint extends InternalConnectionPoint {
diff --git a/skyquake/plugins/composer/src/src/libraries/model/descriptors/VirtualLink.js b/skyquake/plugins/composer/src/src/libraries/model/descriptors/VirtualLink.js
index 50c4653..47370e5 100644
--- a/skyquake/plugins/composer/src/src/libraries/model/descriptors/VirtualLink.js
+++ b/skyquake/plugins/composer/src/src/libraries/model/descriptors/VirtualLink.js
@@ -15,9 +15,6 @@
  *   limitations under the License.
  *
  */
-/**
- * Created by onvelocity on 11/23/15.
- */
 
 'use strict';