2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
23 var ComponentService = function($log, COMPONENT, UtilityService) {
27 var componentList = [ {
28 id : COMPONENT.NETWORK,
29 displayName : "Network"
31 id : COMPONENT.SERVICE,
32 displayName : "Service Instance"
35 displayName : "Virtual Network Function"
37 id : COMPONENT.VF_MODULE,
38 displayName : "VF Module"
40 id : COMPONENT.VOLUME_GROUP,
41 displayName : "Volume Group"
44 var getInventoryInfo = function(suffix, inventoryItem) {
45 var pattern = new RegExp(suffix + "-");
46 for ( var key in inventoryItem) {
47 if (pattern.exec(key)) {
48 return inventoryItem[key];
54 * Converts 'id' to a user friendly version.
56 * The algorithm used is:
58 * 1) If "id" found in COMPONENT.FULL_NAME_MAP, return the name found in the
61 * 2) Otherwise, if camel case, add "-" between camel case words.
63 * 3) Split id into multiple "partial names" assuming "-" is the delimiter.
65 * 4) Map any partial names found in COMPONENT.PARTIAL_NAME_MAP to the name
68 * 5) Use partial names whenever not found in map.
70 * 5) Return name by combining all partial names with " " delimiter.
72 var getDisplayName = function(id) {
73 var tmp = COMPONENT.FULL_NAME_MAP[id.toLowerCase()];
74 if (UtilityService.hasContents(tmp)) {
78 * Add "-" if camel case found.
80 var id = id.replace(/([a-z](?=[A-Z]))/g, '$1-');
82 var arg = id.split("-");
83 for (var i = 0; i < arg.length; i++) {
87 var tmp = COMPONENT.PARTIAL_NAME_MAP[arg[i].toLowerCase()];
88 if (UtilityService.hasContents(tmp)) {
91 name += arg[i].slice(0, 1).toUpperCase() + arg[i].slice(1);
98 initialize : function(componentId) {
99 for (var i = 0; i < componentList.length; i++) {
100 if (componentList[i].id === componentId) {
101 _this.componentId = componentList[i].id;
105 throw "ComponentService:initializeComponent: componentId not found: "
108 getComponentDisplayName : function() {
109 for (var i = 0; i < componentList.length; i++) {
110 if (componentList[i].id === _this.componentId) {
111 return componentList[i].displayName;
115 getInventoryInfo : getInventoryInfo,
116 getInventoryParameterList : function(suffix, inventoryItem) {
117 var parameterList = new Array();
118 // var pattern = new RegExp("-[intv][a-z]*$");
119 // var inventoryInfo = getInventoryInfo(suffix, inventoryItem);
120 for ( var id in inventoryItem) {
121 //if (pattern.exec(id)) {
124 value : inventoryItem[id]
128 return parameterList;
130 getDisplayNames : function(inputList) {
131 var outputList = new Array();
132 for (var i = 0; i < inputList.length; i++) {
133 var entry = angular.copy(inputList[i]);
134 if (!UtilityService.hasContents(entry.name)) {
135 entry.name = getDisplayName(entry.id);
137 outputList.push(entry);
141 getFieldDisplayName : function(name) {
142 return getDisplayName(name);
147 app.factory("ComponentService", [ "$log", "COMPONENT", "UtilityService",