diff options
Diffstat (limited to 'vid/src/main/webapp/app/vid/scripts/services')
10 files changed, 2209 insertions, 0 deletions
diff --git a/vid/src/main/webapp/app/vid/scripts/services/aaiService.js b/vid/src/main/webapp/app/vid/scripts/services/aaiService.js new file mode 100644 index 000000000..063f7a988 --- /dev/null +++ b/vid/src/main/webapp/app/vid/scripts/services/aaiService.js @@ -0,0 +1,111 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +"use strict"; + +var AaiService = function($http, $log, PropertyService, UtilityService) { + return { + getSubscriptionServiceTypeList : function(globalCustomerId, + successCallbackFunction) { + $log + .debug("AaiService:getSubscriptionServiceTypeList: globalCustomerId: " + + globalCustomerId); + $http.get( + PropertyService.getAaiBaseUrl() + + "/aai_sub_details/" + + globalCustomerId + "?r=" + Math.random(), + { + timeout : PropertyService + .getServerResponseTimeoutMsec() + }).then(function(response) { + if (response.data && response.data["service-subscriptions"]) { + var serviceTypes = []; + var serviceSubscriptions = response.data["service-subscriptions"]["service-subscription"]; + + for (var i = 0; i < serviceSubscriptions.length; i++) { + serviceTypes.push(serviceSubscriptions[i]["service-type"]); + } + + successCallbackFunction(serviceTypes); + } else { + successCallbackFunction([]); + } + })["catch"] + (UtilityService.runHttpErrorHandler); + }, + getLcpCloudRegionTenantList : function(globalCustomerId, serviceType, + successCallbackFunction) { + $log + .debug("AaiService:getLcpCloudRegionTenantList: globalCustomerId: " + + globalCustomerId); + var url = PropertyService.getAaiBaseUrl() + + "/aai_get_tenants/" + + globalCustomerId + "/" + serviceType + "?r=" + Math.random(); + + $http.get(url, + { + timeout : PropertyService + .getServerResponseTimeoutMsec() + }).then(function(response) { + var lcpCloudRegionTenants = []; + var aaiLcpCloudRegionTenants = response.data; + + lcpCloudRegionTenants.push({ + "cloudRegionId": "", + "tenantName": "Please choose a region", + "tenantId": "" + }); + + for (var i = 0; i < aaiLcpCloudRegionTenants.length; i++) { + lcpCloudRegionTenants.push({ + "cloudRegionId": aaiLcpCloudRegionTenants[i]["cloudRegionID"], + "tenantName": aaiLcpCloudRegionTenants[i]["tenantName"], + "tenantId": aaiLcpCloudRegionTenants[i]["tenantID"] + }); + } + + successCallbackFunction(lcpCloudRegionTenants); + })["catch"] + (UtilityService.runHttpErrorHandler); + }, + getSubscribers : function(successCallbackFunction) { + $log + .debug("AaiService:getSubscribers"); + var url = PropertyService.getAaiBaseUrl() + + "/aai_get_subscribers?r=" + Math.random(); + + $http.get(url, + { + timeout : PropertyService + .getServerResponseTimeoutMsec() + }).then(function(response) { + if (response.data) { + successCallbackFunction(response.data.customer); + } else { + successCallbackFunction([]); + } + })["catch"] + (UtilityService.runHttpErrorHandler); + } + } +} + +app.factory("AaiService", [ "$http", "$log", "PropertyService", + "UtilityService", AaiService ]); diff --git a/vid/src/main/webapp/app/vid/scripts/services/asdcService.js b/vid/src/main/webapp/app/vid/scripts/services/asdcService.js new file mode 100644 index 000000000..532b8f508 --- /dev/null +++ b/vid/src/main/webapp/app/vid/scripts/services/asdcService.js @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +"use strict"; + +var AsdcService = function($http, $log, PropertyService, UtilityService) { + return { + getModel : function(modelId, successCallbackFunction) { + $log.debug("SdcService:getModel: modelId: " + modelId); + $http.get( + PropertyService.getAsdcBaseUrl() + "/getModel/" + modelId + + "?r=" + Math.random(), + { + timeout : PropertyService + .getServerResponseTimeoutMsec() + }).then(successCallbackFunction)["catch"] + (UtilityService.runHttpErrorHandler); + } + } +} + +app.factory("AsdcService", [ "$http", "$log", "PropertyService", + "UtilityService", AsdcService ]); diff --git a/vid/src/main/webapp/app/vid/scripts/services/componentService.js b/vid/src/main/webapp/app/vid/scripts/services/componentService.js new file mode 100644 index 000000000..7c1cfcb9c --- /dev/null +++ b/vid/src/main/webapp/app/vid/scripts/services/componentService.js @@ -0,0 +1,148 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +"use strict"; + +var ComponentService = function($log, COMPONENT, UtilityService) { + + var _this = this; + + var componentList = [ { + id : COMPONENT.NETWORK, + displayName : "Network" + }, { + id : COMPONENT.SERVICE, + displayName : "Service Instance" + }, { + id : COMPONENT.VNF, + displayName : "Virtual Network Function" + }, { + id : COMPONENT.VF_MODULE, + displayName : "VF Module" + }, { + id : COMPONENT.VOLUME_GROUP, + displayName : "Volume Group" + } ]; + + var getInventoryInfo = function(suffix, inventoryItem) { + var pattern = new RegExp(suffix + "-"); + for ( var key in inventoryItem) { + if (pattern.exec(key)) { + return inventoryItem[key]; + } + } + }; + + /* + * Converts 'id' to a user friendly version. + * + * The algorithm used is: + * + * 1) If "id" found in COMPONENT.FULL_NAME_MAP, return the name found in the + * map. + * + * 2) Otherwise, if camel case, add "-" between camel case words. + * + * 3) Split id into multiple "partial names" assuming "-" is the delimiter. + * + * 4) Map any partial names found in COMPONENT.PARTIAL_NAME_MAP to the name + * found in the map. + * + * 5) Use partial names whenever not found in map. + * + * 5) Return name by combining all partial names with " " delimiter. + */ + var getDisplayName = function(id) { + var tmp = COMPONENT.FULL_NAME_MAP[id.toLowerCase()]; + if (UtilityService.hasContents(tmp)) { + return tmp; + } + /* + * Add "-" if camel case found. + */ + var id = id.replace(/([a-z](?=[A-Z]))/g, '$1-'); + var name = ""; + var arg = id.split("-"); + for (var i = 0; i < arg.length; i++) { + if (i > 0) { + name += " "; + } + var tmp = COMPONENT.PARTIAL_NAME_MAP[arg[i].toLowerCase()]; + if (UtilityService.hasContents(tmp)) { + name += tmp; + } else { + name += arg[i].slice(0, 1).toUpperCase() + arg[i].slice(1); + } + } + return name; + }; + + return { + initialize : function(componentId) { + for (var i = 0; i < componentList.length; i++) { + if (componentList[i].id === componentId) { + _this.componentId = componentList[i].id; + return componentId; + } + } + throw "ComponentService:initializeComponent: componentId not found: " + + componentId; + }, + getComponentDisplayName : function() { + for (var i = 0; i < componentList.length; i++) { + if (componentList[i].id === _this.componentId) { + return componentList[i].displayName; + } + } + }, + getInventoryInfo : getInventoryInfo, + getInventoryParameterList : function(suffix, inventoryItem) { + var parameterList = new Array(); + // var pattern = new RegExp("-[intv][a-z]*$"); + // var inventoryInfo = getInventoryInfo(suffix, inventoryItem); + for ( var id in inventoryItem) { + //if (pattern.exec(id)) { + parameterList.push({ + id : id, + value : inventoryItem[id] + }); + //} + } + return parameterList; + }, + getDisplayNames : function(inputList) { + var outputList = new Array(); + for (var i = 0; i < inputList.length; i++) { + var entry = angular.copy(inputList[i]); + if (!UtilityService.hasContents(entry.name)) { + entry.name = getDisplayName(entry.id); + } + outputList.push(entry); + } + return outputList; + }, + getFieldDisplayName : function(name) { + return getDisplayName(name); + } + } +} + +app.factory("ComponentService", [ "$log", "COMPONENT", "UtilityService", + ComponentService ]); diff --git a/vid/src/main/webapp/app/vid/scripts/services/creationService.js b/vid/src/main/webapp/app/vid/scripts/services/creationService.js new file mode 100644 index 000000000..fda27eac3 --- /dev/null +++ b/vid/src/main/webapp/app/vid/scripts/services/creationService.js @@ -0,0 +1,683 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +"use strict"; + +/* + * "CreationService" isolates the "component-specific" logic required by the + * "CreationDialog" controller. + * + * "Components" are defined as the 5 element types managed by the dialogs: A) + * Service B) VNF C) VF Module D) Volume Group and E) Network. + * + */ + +var CreationService = function($log, AaiService, AsdcService, DataService, + ComponentService, COMPONENT, FIELD, PARAMETER, UtilityService) { + + var _this = this; + + var getAsyncOperationList = function() { + switch (_this.componentId) { + case COMPONENT.SERVICE: + return [ getSubscribers ]; + case COMPONENT.NETWORK: + return []; + case COMPONENT.VNF: + return [ getLcpCloudRegionTenantList ]; + case COMPONENT.VF_MODULE: + return [ getLcpCloudRegionTenantList ]; + case COMPONENT.VOLUME_GROUP: + return [ getLcpCloudRegionTenantList ]; + } + }; + + /* + * "getSummaryList" and "getUserProvidedList" return parameters that should + * be displayed in the summary and user provided sections, respectively. The + * functions are expected to return lists that are in the format needed by + * the parameter-block directive. + */ + + var getSummaryList = function() { + + /* + * These placeholders should be removed and their usage in + * "getSummaryList" should be replaced by appropriate code as the + * requirements and interfaces firm up. + */ + + var PLACEHOLDER_RESOURCE_DESCRIPTION = "Resource Description (PLACEHOLDER)"; + var PLACEHOLDER_SERVICE_CATEGORY = "Service Category (PLACEHOLDER)"; + var PLACEHOLDER_VF_MODULE_DESCRIPTION = "VF Module Description (PLACEHOLDER)"; + var PLACEHOLDER_VF_MODULE_LABEL = "VF Module Label (PLACEHOLDER)"; + var PLACEHOLDER_VF_MODULE_TYPE = "VF Module Type (PLACEHOLDER)"; + + _this.parameterList = new Array(); + + /* + * Common fields displayed at the top of all create instance screens. + */ + addToList(FIELD.NAME.SERVICE_NAME, DataService.getServiceName()); + + switch (_this.componentId) { + case COMPONENT.SERVICE: + addToList(FIELD.NAME.SERVICE_INVARIANT_UUID, DataService + .getModelInfo(_this.componentId)["modelInvariantId"]); + addToList(FIELD.NAME.SERVICE_VERSION, DataService + .getModelInfo(_this.componentId)["modelVersion"]); + addToList(FIELD.NAME.SERVICE_UUID, DataService + .getModelInfo(_this.componentId)["modelNameVersionId"]); + addToList(FIELD.NAME.SERVICE_DESCRIPTION, DataService + .getModelInfo(_this.componentId)["description"]); + addToList(FIELD.NAME.SERVICE_CATEGORY, DataService + .getModelInfo(_this.componentId)["category"]); + break; + case COMPONENT.VF_MODULE: + addToList(FIELD.NAME.SUBSCRIBER_NAME, DataService + .getSubscriberName()); + addToList(FIELD.NAME.SERVICE_INSTANCE_NAME, DataService + .getServiceInstanceName()); + addToList(FIELD.NAME.MODEL_NAME, DataService + .getModelInfo(_this.componentId)["modelName"]); + addToList(FIELD.NAME.MODEL_INVARIANT_UUID, DataService + .getModelInfo(_this.componentId)["modelInvariantId"]); + addToList(FIELD.NAME.MODEL_VERSION, DataService + .getModelInfo(_this.componentId)["modelVersion"]); + addToList(FIELD.NAME.MODEL_UUID, DataService + .getModelInfo(_this.componentId)["modelNameVersionId"]); + break; + case COMPONENT.NETWORK: + case COMPONENT.VNF: + case COMPONENT.VOLUME_GROUP: + addToList(FIELD.NAME.SUBSCRIBER_NAME, DataService + .getSubscriberName()); + addToList(FIELD.NAME.SERVICE_INSTANCE_NAME, DataService + .getServiceInstanceName()); + addToList(FIELD.NAME.MODEL_NAME, DataService + .getModelInfo(_this.componentId)["modelName"]); + addToList(FIELD.NAME.MODEL_INVARIANT_UUID, DataService + .getModelInfo(_this.componentId)["modelInvariantId"]); + addToList(FIELD.NAME.MODEL_VERSION, DataService + .getModelInfo(_this.componentId)["modelVersion"]); + addToList(FIELD.NAME.MODEL_UUID, DataService + .getModelInfo(_this.componentId)["modelNameVersionId"]); + break; + } + + return _this.parameterList; + }; + + var getUserProvidedList = function() { + + var parameterList = [ FIELD.PARAMETER.INSTANCE_NAME ]; + + switch (_this.componentId) { + case COMPONENT.SERVICE: + parameterList = parameterList.concat([ getSubscribersParameter(), + FIELD.PARAMETER.SERVICE_TYPE_DISABLED ]); + break; + case COMPONENT.NETWORK: + case COMPONENT.VNF: + parameterList = parameterList.concat([ getServiceId(), + getLcpRegion(), FIELD.PARAMETER.LCP_REGION_TEXT_HIDDEN, + FIELD.PARAMETER.TENANT_DISABLED ]); + break; + case COMPONENT.VF_MODULE: + parameterList = parameterList.concat([ + getLcpRegion(), + FIELD.PARAMETER.LCP_REGION_TEXT_HIDDEN, + FIELD.PARAMETER.TENANT_DISABLED + ]); + + var availableVolumeGroupList = DataService.getAvailableVolumeGroupList(); + + if (availableVolumeGroupList && availableVolumeGroupList.length > 0) { + var availableVolumeGroupNames = ["None"]; + + for (var i = 0; i < availableVolumeGroupList.length; i++) { + availableVolumeGroupNames.push(availableVolumeGroupList[i].instance.name); + } + + parameterList.push(addOptionList( + FIELD.PARAMETER.AVAILABLE_VOLUME_GROUP, + availableVolumeGroupNames)); + } + break; + case COMPONENT.VOLUME_GROUP: + parameterList = parameterList.concat([ getLcpRegion(), + FIELD.PARAMETER.LCP_REGION_TEXT_HIDDEN, + FIELD.PARAMETER.TENANT_DISABLED ]); + } + + parameterList.push(FIELD.PARAMETER.SUPPRESS_ROLLBACK); + + addArbitraryParameters(parameterList); + + return parameterList; + }; + + var addArbitraryParameters = function(parameterList) { + var inputs = DataService.getModelInfo(_this.componentId).inputs; + if (inputs) { + for ( var key in inputs) { + parameterList.push({ + id : key, + /* + * "name" is the display name. The simplest option is to just + * display this value (e.g. "name: key"). An alternative used + * here is to use "getFieldDisplayName" to display a more "user + * friendly" value. See "componentService:getDisplayName" for + * mapping details. + */ + name : ComponentService.getFieldDisplayName(key), + value : inputs[key]["default"], + isRequired : true, + /* + * If the field needs to be considered required, the attribute + * "isRequired: true" can be added here. + */ + description : inputs[key]["description"] + }); + } + } + }; + + var addToList = function(name, value) { + _this.parameterList.push({ + name : name, + value : value + }); + }; + + /* + * The "*Mso*" functions return URL and request details that can be passed + * to the MSO controller. The request details defines the info passed as + * part of the POST body. + */ + + var getMsoUrl = function() { + switch (_this.componentId) { + case COMPONENT.NETWORK: + return "mso_create_nw_instance/" + + DataService.getServiceInstanceId(); + case COMPONENT.SERVICE: + return "mso_create_svc_instance"; + case COMPONENT.VNF: + return "mso_create_vnf_instance/" + + DataService.getServiceInstanceId(); + case COMPONENT.VF_MODULE: + return "mso_create_vfmodule_instance/" + + DataService.getServiceInstanceId() + "/vnfs/" + + DataService.getVnfInstanceId(); + case COMPONENT.VOLUME_GROUP: + return "mso_create_volumegroup_instance/" + + DataService.getServiceInstanceId() + "/vnfs/" + + DataService.getVnfInstanceId(); + } + }; + + var getMsoRequestDetails = function(parameterList) { + console.log("getMsoRequestDetails invoked"); + var modelInfo = DataService.getModelInfo(_this.componentId); + var requestDetails = { + requestInfo : { + instanceName : getValueFromList(FIELD.ID.INSTANCE_NAME, + parameterList), + source : "VID", + suppressRollback : getValueFromList(FIELD.ID.SUPPRESS_ROLLBACK, + parameterList), + }, + modelInfo : { + modelType : _this.componentId, + modelInvariantId : modelInfo.modelInvariantId, + modelNameVersionId : modelInfo.modelNameVersionId, + modelName : modelInfo.modelName, + modelVersion : modelInfo.modelVersion + }, + requestParameters : { + userParams : getArbitraryParameters(parameterList) + } + }; + + switch (_this.componentId) { + case COMPONENT.SERVICE: + requestDetails.subscriberInfo = { + globalSubscriberId : DataService.getGlobalCustomerId(), + subscriberName : DataService.getSubscriberName() + }; + requestDetails.requestParameters.subscriptionServiceType = getValueFromList( + FIELD.ID.SERVICE_TYPE, parameterList); + break; + case COMPONENT.NETWORK: + case COMPONENT.VNF: + console.log("getMsoRequestDetails COMPONENT.VNF"); + var lcpRegion = getValueFromList(FIELD.ID.LCP_REGION, parameterList); + if (lcpRegion === FIELD.KEY.LCP_REGION_TEXT) { + lcpRegion = getValueFromList(FIELD.ID.LCP_REGION_TEXT, + parameterList); + } + requestDetails.cloudConfiguration = { + lcpCloudRegionId : lcpRegion, + tenantId : getValueFromList(FIELD.ID.TENANT, parameterList) + }; + requestDetails.requestInfo.productFamilyId = getValueFromList( + FIELD.ID.PRODUCT_FAMILY, parameterList); + // override model info for VNF since it needs the customization name + var vnfModelInfo = { + modelType : _this.componentId, + modelInvariantId : modelInfo.modelInvariantId, + modelNameVersionId : modelInfo.modelNameVersionId, + modelName : modelInfo.modelName, + modelVersion : modelInfo.modelVersion, + modelCustomizationName : modelInfo.modelCustomizationName + }; + requestDetails.modelInfo = vnfModelInfo; + break; + case COMPONENT.VF_MODULE: + var lcpRegion = getValueFromList(FIELD.ID.LCP_REGION, parameterList); + if (lcpRegion === FIELD.KEY.LCP_REGION_TEXT) { + lcpRegion = getValueFromList(FIELD.ID.LCP_REGION_TEXT, + parameterList); + } + requestDetails.cloudConfiguration = { + lcpCloudRegionId : lcpRegion, + tenantId : getValueFromList(FIELD.ID.TENANT, parameterList) + }; + break; + case COMPONENT.VOLUME_GROUP: + var lcpRegion = getValueFromList(FIELD.ID.LCP_REGION, parameterList); + if (lcpRegion === FIELD.KEY.LCP_REGION_TEXT) { + lcpRegion = getValueFromList(FIELD.ID.LCP_REGION_TEXT, + parameterList); + } + requestDetails.cloudConfiguration = { + lcpCloudRegionId : lcpRegion, + tenantId : getValueFromList(FIELD.ID.TENANT, parameterList) + }; + + break; + } + + var relatedInstanceList = getRelatedInstanceList(parameterList); + + if (relatedInstanceList !== undefined) { + requestDetails.relatedInstanceList = relatedInstanceList; + } + + return requestDetails; + }; + + var getRelatedInstanceList = function(parameterList) { + var relatedInstanceList = new Array(); + switch (_this.componentId) { + case COMPONENT.SERVICE: + return undefined; + case COMPONENT.NETWORK: + case COMPONENT.VNF: + addRelatedInstance(relatedInstanceList, COMPONENT.SERVICE, + DataService.getServiceInstanceId()); + break; + case COMPONENT.VF_MODULE: + addRelatedInstance(relatedInstanceList, COMPONENT.SERVICE, + DataService.getServiceInstanceId()); + addRelatedInstance(relatedInstanceList, COMPONENT.VNF, DataService + .getVnfInstanceId()); + + var availableVolumeGroup = getValueFromList( + FIELD.ID.AVAILABLE_VOLUME_GROUP, parameterList); + + if (UtilityService.hasContents(availableVolumeGroup) && availableVolumeGroup !== "None") { + var availableVolumeGroups = DataService.getAvailableVolumeGroupList(); + + for (var i = 0; i < availableVolumeGroups.length; i++) { + if (availableVolumeGroups[i].instance.name == availableVolumeGroup) { + DataService.setModelInfo(COMPONENT.VOLUME_GROUP, DataService.getModelInfo(COMPONENT.VF_MODULE)); + DataService.setVolumeGroupInstanceId(availableVolumeGroups[i].instance.object["volume-group-id"]); + break; + } + } + + addRelatedInstance(relatedInstanceList, COMPONENT.VOLUME_GROUP, + DataService.getVolumeGroupInstanceId()); + } + break; + case COMPONENT.VOLUME_GROUP: + addRelatedInstance(relatedInstanceList, COMPONENT.SERVICE, + DataService.getServiceInstanceId()); + addRelatedInstance(relatedInstanceList, COMPONENT.VNF, DataService + .getVnfInstanceId()); + break; + } + + return relatedInstanceList; + }; + + var addRelatedInstance = function(relatedInstanceList, componentId, + instanceId) { + var modelInfo = DataService.getModelInfo(componentId); + var relatedInstance; + if (modelInfo !== undefined) { + if (componentId === COMPONENT.VNF) { + relatedInstance = { + "instanceId" : instanceId, + "modelInfo" : { + "modelType" : componentId, + "modelName" : modelInfo.modelName, + "modelInvariantId" : modelInfo.modelInvariantId, + "modelVersion" : modelInfo.modelVersion, + "modelNameVersionId" : modelInfo.modelNameVersionId, + "modelCustomizationName" : modelInfo.modelCustomizationName + } + }; + } else { + relatedInstance = { + "instanceId" : instanceId, + "modelInfo" : { + "modelType" : componentId, + "modelName" : modelInfo.modelName, + "modelInvariantId" : modelInfo.modelInvariantId, + "modelVersion" : modelInfo.modelVersion, + "modelNameVersionId" : modelInfo.modelNameVersionId + } + }; + } + relatedInstanceList.push({ + relatedInstance : relatedInstance + }); + } + }; + + /* + * var getArbitraryParameters = function(parameterList) { var + * arbitraryParameters = new Object(); for (var i = 0; i < + * parameterList.length; i++) { var parameter = parameterList[i]; switch + * (parameter.id) { case FIELD.ID.INSTANCE_NAME: case + * FIELD.ID.PRODUCT_FAMILY: case FIELD.ID.LCP_REGION: case + * FIELD.ID.LCP_REGION_TEXT: case FIELD.ID.SERVICE_TYPE: case + * FIELD.ID.TENANT: case FIELD.ID.SUPPRESS_ROLLBACK: break; default: + * arbitraryParameters[parameter.id] = parameter.value; } } return + * arbitraryParameters; } + */ + var getArbitraryParameters = function(parameterList) { + var arbitraryParameters = new Object(); + var arbitraryArray = new Array(); + for (var i = 0; i < parameterList.length; i++) { + var parameter = parameterList[i]; + switch (parameter.id) { + case FIELD.ID.AVAILABLE_VOLUME_GROUP: + break; + case FIELD.ID.INSTANCE_NAME: + break; + case FIELD.ID.PRODUCT_FAMILY: + break; + case FIELD.ID.LCP_REGION: + break; + case FIELD.ID.LCP_REGION_TEXT: + break; + case FIELD.ID.SERVICE_TYPE: + break; + case FIELD.ID.TENANT: + break; + case FIELD.ID.SUPPRESS_ROLLBACK: + break; + case FIELD.ID.SUBSCRIBER_NAME: + break; + default: + arbitraryParameters = { + name : parameter.id, + value : parameter.value + } + arbitraryArray.push(arbitraryParameters); + } + } + return (arbitraryArray); + } + + var getModel = function() { + AsdcService.getModel(DataService.getModelId(), function(response) { + DataService.setModelInfo(_this.componentId, { + modelInvariantId : response.data.invariantUUID, + modelNameVersionId : response.data.uuid, + modelName : response.data.name, + modelVersion : response.data.version, + inputs : response.data.inputs + }); + UtilityService.startNextAsyncOperation(); + }); + }; + + var getSubscriptionServiceTypeList = function() { + AaiService.getSubscriptionServiceTypeList(DataService + .getGlobalCustomerId(), function(response) { + DataService.setSubscriptionServiceTypeList(response); + UtilityService.startNextAsyncOperation(); + }); + }; + + var getSubscribers = function() { + AaiService.getSubscribers(function(response) { + DataService.setSubscribers(response); + UtilityService.startNextAsyncOperation(); + }); + }; + + var getLcpCloudRegionTenantList = function() { + AaiService.getLcpCloudRegionTenantList(DataService + .getGlobalCustomerId(), DataService.getServiceType(), function( + response) { + DataService.setCloudRegionTenantList(response); + UtilityService.startNextAsyncOperation(); + }); + }; + + var internalGetParametersHandler = function() { + if (angular.isFunction(_this.getParametersHandler)) { + _this.getParametersHandler({ + summaryList : getSummaryList(), + userProvidedList : getUserProvidedList() + }); + } + }; + + var getSubscribersParameter = function() { + var subscribers = DataService.getSubscribers(); + var parameter = FIELD.PARAMETER.SUBSCRIBER_NAME; + parameter.optionList = []; + + for (var i = 0; i < subscribers.length; i++) { + parameter.optionList.push({ + id : subscribers[i]["global-customer-id"], + name : subscribers[i]["subscriber-name"] + }) + } + return parameter; + }; + + var getServiceId = function() { + var serviceIdList = DataService.getServiceIdList(); + var serviceTypeList = DataService.getSubscriptionServiceTypeList(); + var parameter = FIELD.PARAMETER.PRODUCT_FAMILY; + parameter.optionList = new Array(); + + if (serviceTypeList == null) { + getSubscriptionServiceTypeList(); + serviceTypeList = DataService.getSubscriptionServiceTypeList(); + } + var went = 0; + for (var i = 0; i < serviceIdList.length; i++) { + var go = 0; + var name = serviceIdList[i].id; + + if (serviceTypeList != null) { + console.log("STL: " + serviceTypeList); + for (var k = 0; k < serviceTypeList.length; k++) { + if (angular.equals(name,serviceTypeList[k])) { + go = 1; + went = 1; + } + } + } else { + go = 1; + went = 1; + } + if (go == 1) { + parameter.optionList.push({ + id : serviceIdList[i].id, + name : serviceIdList[i].description + }); + } + } // load them all, ours wasn't in the list + if (went == 0) { + for (var i = 0; i < serviceIdList.length; i++) { + parameter.optionList.push({ + id : serviceIdList[i].id, + name : serviceIdList[i].description + }); + } + } + return parameter; + }; + + var getLcpRegion = function() { + var cloudRegionTenantList = DataService.getCloudRegionTenantList(); + var parameter = FIELD.PARAMETER.LCP_REGION; + parameter.optionList = new Array(); + for (var i = 0; i < cloudRegionTenantList.length; i++) { + for (var j = 0; j < parameter.optionList.length; j++) { + if (parameter.optionList[j].id === cloudRegionTenantList[i].cloudRegionId) { + break; + } + } + if (j < parameter.optionList.length) { + continue; + } + parameter.optionList.push({ + id : cloudRegionTenantList[i].cloudRegionId + }); + } + return parameter; + }; + + var getTenantList = function(cloudRegionId) { + var cloudRegionTenantList = DataService.getCloudRegionTenantList(); + var parameter = FIELD.PARAMETER.TENANT_ENABLED; + parameter.optionList = new Array(); + for (var i = 0; i < cloudRegionTenantList.length; i++) { + if (cloudRegionTenantList[i].cloudRegionId === cloudRegionId) { + parameter.optionList.push({ + id : cloudRegionTenantList[i].tenantId, + name : cloudRegionTenantList[i].tenantName + }); + } + } + return parameter; + + }; + + var addOptionList = function(parameter, optionSimpleArray) { + var optionList = new Array(); + if (!angular.isArray(optionSimpleArray)) { + return optionList; + } + for (var i = 0; i < optionSimpleArray.length; i++) { + optionList.push({ + name : optionSimpleArray[i] + }); + } + parameter.optionList = optionList; + return parameter; + }; + + var getValueFromList = function(id, parameterList) { + for (var i = 0; i < parameterList.length; i++) { + if (parameterList[i].id === id) { + return parameterList[i].value; + } + } + }; + + var updateUserParameterList = function(updatedId, parameterListControl) { + if (updatedId === FIELD.ID.LCP_REGION) { + var list = parameterListControl.getList(updatedId); + if (list[0].selectedIndex >= 0) { + parameterListControl + .updateList([ getTenantList(list[0].value) ]); + } else { + parameterListControl + .updateList([ FIELD.PARAMETER.TENANT_DISABLED ]); + } + if (list[0].value === FIELD.KEY.LCP_REGION_TEXT) { + parameterListControl + .updateList([ FIELD.PARAMETER.LCP_REGION_TEXT_VISIBLE ]); + } else { + parameterListControl + .updateList([ FIELD.PARAMETER.LCP_REGION_TEXT_HIDDEN ]); + } + } else if (updatedId === FIELD.ID.SUBSCRIBER_NAME) { + var list = parameterListControl.getList(updatedId); + if (list[0].selectedIndex >= 0) { + DataService.setGlobalCustomerId(list[0].value); + + AaiService.getSubscriptionServiceTypeList(DataService + .getGlobalCustomerId(), function(response) { + DataService.setSubscriptionServiceTypeList(response); + var serviceTypeParameters = FIELD.PARAMETER.SERVICE_TYPE; + serviceTypeParameters.optionList = []; + + for (var i = 0; i < response.length; i++) { + serviceTypeParameters.optionList.push({ + "id" : response[i], + "name" : response[i] + }); + } + parameterListControl.updateList([ serviceTypeParameters ]); + }); + + } else { + parameterListControl + .updateList([ FIELD.PARAMETER.SERVICE_TYPE_DISABLED ]); + } + } + }; + + return { + initializeComponent : function(componentId) { + _this.componentId = ComponentService.initialize(componentId); + }, + setHttpErrorHandler : function(httpErrorHandler) { + _this.httpErrorHandler = httpErrorHandler; + }, + getComponentDisplayName : ComponentService.getComponentDisplayName, + getParameters : function(getParametersHandler) { + _this.getParametersHandler = getParametersHandler; + UtilityService.setHttpErrorHandler(_this.httpErrorHandler); + UtilityService.startAsyncOperations(getAsyncOperationList(), + internalGetParametersHandler); + }, + updateUserParameterList : updateUserParameterList, + getMsoRequestDetails : getMsoRequestDetails, + getMsoUrl : getMsoUrl + } +} + +app.factory("CreationService", [ "$log", "AaiService", "AsdcService", + "DataService", "ComponentService", "COMPONENT", "FIELD", "PARAMETER", + "UtilityService", CreationService ]); diff --git a/vid/src/main/webapp/app/vid/scripts/services/dataService.js b/vid/src/main/webapp/app/vid/scripts/services/dataService.js new file mode 100644 index 000000000..724d4b12c --- /dev/null +++ b/vid/src/main/webapp/app/vid/scripts/services/dataService.js @@ -0,0 +1,197 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +"use strict"; + +var DataService = function($log, DataService) { + + var _this = this; + + return { + getAvailableVolumeGroupList : function() { + return _this.availableVolumeGroupList; + }, + setAvailableVolumeGroupList : function(availableVolumeGroupList) { + _this.availableVolumeGroupList = availableVolumeGroupList; + }, + getCloudRegionTenantList : function() { + return _this.cloudRegionTenantList; + }, + setCloudRegionTenantList : function(cloudRegionTenantList) { + _this.cloudRegionTenantList = cloudRegionTenantList; + }, + getGlobalCustomerId : function() { + return _this.globalCustomerId; + }, + setGlobalCustomerId : function(globalCustomerId) { + _this.globalCustomerId = globalCustomerId; + }, + getInventoryItem : function() { + return _this.inventoryItem; + }, + setInventoryItem : function(inventoryItem) { + _this.inventoryItem = inventoryItem; + }, + getModelId : function() { + return _this.modelId; + }, + setModelId : function(modelId) { + _this.modelId = modelId; + }, + getModelInstanceName : function() { + return _this.modelInstanceName; + }, + setModelInstanceName : function(modelInstanceName) { + _this.modelInstanceName = modelInstanceName; + }, + getModelInfo : function(componentId) { + return _this.modelInfo[componentId]; + }, + setModelInfo : function(componentId, modelInfo) { + if (_this.modelInfo === undefined) { + _this.modelInfo = new Object; + } + _this.modelInfo[componentId] = modelInfo; + }, + getNetworkInstanceId : function() { + return _this.networkInstanceId; + }, + setNetworkInstanceId : function(networkInstanceId) { + _this.networkInstanceId = networkInstanceId; + }, + getServiceIdList : function() { + return _this.serviceIdList; + }, + setServiceIdList : function(serviceIdList) { + _this.serviceIdList = serviceIdList; + }, + getServiceInstanceId : function() { + return _this.serviceInstanceId; + }, + setServiceInstanceId : function(serviceInstanceId) { + _this.serviceInstanceId = serviceInstanceId; + }, + getServiceInstanceName : function() { + return _this.serviceInstanceName; + }, + setServiceInstanceName : function(serviceInstanceName) { + _this.serviceInstanceName = serviceInstanceName; + }, + getServiceName : function() { + return _this.serviceName; + }, + setServiceName : function(serviceName) { + _this.serviceName = serviceName; + }, + getServiceType : function() { + return _this.serviceType; + }, + setServiceType : function(serviceType) { + _this.serviceType = serviceType; + }, + getServiceUuid : function() { + return _this.serviceUuid; + }, + setServiceUuid : function(serviceUuid) { + _this.serviceUuid = serviceUuid; + }, + getSubscriberId : function() { + return _this.subscriberId; + }, + setSubscriberId : function(subscriberId) { + _this.subscriberId = subscriberId; + }, + getSubscriberName : function() { + return _this.subscriberName; + }, + setSubscriberName : function(subscriberName) { + _this.subscriberName = subscriberName; + }, + getSubscribers : function() { + return _this.subscribers; + }, + setSubscribers : function(subscribers) { + _this.subscribers = subscribers; + }, + getSubscriptionServiceTypeList : function() { + return _this.subscriptionServiceTypeList; + }, + setSubscriptionServiceTypeList : function(subscriptionServiceTypeList) { + _this.subscriptionServiceTypeList = subscriptionServiceTypeList; + }, + getUserParams : function() { + return _this.userParams; + }, + setUserParams : function(userParams) { + _this.userParams = userParams; + }, + getUserServiceInstanceName : function() { + return _this.userServiceInstanceName; + }, + setUserServiceInstanceName : function(userServiceInstanceName) { + _this.userServiceInstanceName = userServiceInstanceName; + }, + getVfModuleInstanceId : function() { + return _this.vfModuleInstanceId; + }, + setVfModuleInstanceId : function(vfModuleInstanceId) { + _this.vfModuleInstanceId = vfModuleInstanceId; + }, + getVnfInstanceId : function() { + return _this.vnfInstanceId; + }, + setVnfInstanceId : function(vnfInstanceId) { + _this.vnfInstanceId = vnfInstanceId; + }, + getVolumeGroupInstanceId : function() { + return _this.volumeGroupInstanceId; + }, + setVolumeGroupInstanceId : function(volumeGroupInstanceId) { + _this.volumeGroupInstanceId = volumeGroupInstanceId; + }, + getLcpRegion : function() { + return _this.lcpRegion; + }, + setLcpRegion : function(lcpRegion) { + _this.lcpRegion = lcpRegion; + }, + getTenant : function() { + return _this.tenant; + }, + setTenant : function(tenant) { + _this.tenant = tenant; + }, + getTreeHandle : function() { + return _this.treeHandle; + }, + setTreeHandle : function(treeHandle) { + _this.treeHandle = treeHandle; + }, + setServiceInstanceToCustomer : function(serviceInstanceToCustomer) { + _this.serviceInstanceToCustomer = []; + _this.serviceInstanceToCustomer = serviceInstanceToCustomer; + }, + getServiceInstanceToCustomer : function() { + return _this.serviceInstanceToCustomer; + } + } +} + +app.factory("DataService", [ "$log", DataService ]); diff --git a/vid/src/main/webapp/app/vid/scripts/services/deletionService.js b/vid/src/main/webapp/app/vid/scripts/services/deletionService.js new file mode 100644 index 000000000..5ab5ee79b --- /dev/null +++ b/vid/src/main/webapp/app/vid/scripts/services/deletionService.js @@ -0,0 +1,442 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +"use strict"; + +var DeletionService = function($log, AaiService, AsdcService, DataService, + ComponentService, COMPONENT, FIELD, UtilityService) { + + var _this = this; + + var getAsyncOperationList = function() { + switch (_this.componentId) { + case COMPONENT.SERVICE: + return [ getSubscribers ]; + case COMPONENT.NETWORK: + return []; + case COMPONENT.VNF: + return [ getLcpCloudRegionTenantList ]; + case COMPONENT.VF_MODULE: + return [ getLcpCloudRegionTenantList ]; + case COMPONENT.VOLUME_GROUP: + return [ getLcpCloudRegionTenantList ]; + } + }; + + var getLcpCloudRegionTenantList = function() { + AaiService.getLcpCloudRegionTenantList(DataService + .getGlobalCustomerId(), DataService.getServiceType(), function( + response) { + DataService.setCloudRegionTenantList(response); + UtilityService.startNextAsyncOperation(); + }); + }; + + var getSubscribers = function() { + AaiService.getSubscribers(function(response) { + DataService.setSubscribers(response); + UtilityService.startNextAsyncOperation(); + }); + }; + + var internalGetParametersHandler = function() { + if (angular.isFunction(_this.getParametersHandler)) { + if (_this.componentId == COMPONENT.SERVICE) + _this.getParametersHandler({ + summaryList : getSummaryList(), + userProvidedList : getUserProvidedList() + }, true); + else + _this.getParametersHandler({ + summaryList : getSummaryList(), + userProvidedList : getUserProvidedList() + }, false); + } + }; + + var getSubscribersParameter = function() { + var subscribers = DataService.getSubscribers(); + var parameter = FIELD.PARAMETER.SUBSCRIBER_NAME; + parameter.optionList = []; + + for (var i = 0; i < subscribers.length; i++) { + parameter.optionList.push({ + id : subscribers[i]["global-customer-id"], + name : subscribers[i]["subscriber-name"] + }) + } + return parameter; + }; + + var getServiceId = function() { + var serviceIdList = DataService.getServiceIdList(); + var parameter = FIELD.PARAMETER.PRODUCT_FAMILY; + parameter.optionList = new Array(); + for (var i = 0; i < serviceIdList.length; i++) { + parameter.optionList.push({ + id : serviceIdList[i].id, + name : serviceIdList[i].description + }); + } + return parameter; + }; + + var getUserProvidedList = function() { + + //var parameterList = [ FIELD.PARAMETER.INSTANCE_NAME ]; + + var parameterList = []; + + switch (_this.componentId) { + case COMPONENT.SERVICE: +// parameterList = parameterList.concat([ getSubscribersParameter(), +// FIELD.PARAMETER.SERVICE_TYPE_DISABLED ]); + parameterList = []; + break; + case COMPONENT.NETWORK: + case COMPONENT.VNF: + parameterList = parameterList.concat([ //getServiceId(), + getLcpRegion(), FIELD.PARAMETER.LCP_REGION_TEXT_HIDDEN, + FIELD.PARAMETER.TENANT_DISABLED ]); + break; + case COMPONENT.VF_MODULE: + parameterList = parameterList.concat([ + getLcpRegion(), + FIELD.PARAMETER.LCP_REGION_TEXT_HIDDEN, + FIELD.PARAMETER.TENANT_DISABLED + ]); + + break; + case COMPONENT.VOLUME_GROUP: + parameterList = parameterList.concat([ getLcpRegion(), + FIELD.PARAMETER.LCP_REGION_TEXT_HIDDEN, + FIELD.PARAMETER.TENANT_DISABLED ]); + } + + parameterList.push(FIELD.PARAMETER.SUPPRESS_ROLLBACK); + + //addArbitraryParameters(parameterList); + + return parameterList; + }; + var getSummaryList = function() { + switch (_this.componentId) { + case COMPONENT.NETWORK: + case COMPONENT.SERVICE: + case COMPONENT.VNF: + case COMPONENT.VF_MODULE: + case COMPONENT.VOLUME_GROUP: + var summaryList = [ { + name : FIELD.NAME.SUBSCRIBER_NAME, + value : DataService.getSubscriberName() + }, { + name : FIELD.NAME.CUSTOMER_ID, + value : DataService.getGlobalCustomerId() + }, { + name : FIELD.NAME.SERVICE_UUID, + value : DataService.getServiceUuid() + }, { + name : FIELD.NAME.SERVICE_NAME, + value : DataService.getServiceName() + /* }, { + name : FIELD.NAME.USER_SERVICE_INSTANCE_NAME, + value : DataService.getUserServiceInstanceName()*/ + } ]; + + _this.parameterList = new Array(); + + addToList(FIELD.NAME.SERVICE_NAME, DataService.getServiceName()); + + switch (_this.componentId) { + case COMPONENT.SERVICE: + addToList(FIELD.NAME.SERVICE_INVARIANT_UUID, DataService + .getModelInfo(_this.componentId)["modelInvariantId"]); + addToList(FIELD.NAME.SERVICE_VERSION, DataService + .getModelInfo(_this.componentId)["modelVersion"]); + addToList(FIELD.NAME.SERVICE_UUID, DataService + .getModelInfo(_this.componentId)["modelNameVersionId"]); + addToList(FIELD.NAME.SERVICE_DESCRIPTION, DataService + .getModelInfo(_this.componentId)["description"]); + addToList(FIELD.NAME.SERVICE_CATEGORY, DataService + .getModelInfo(_this.componentId)["category"]); + break; + case COMPONENT.VF_MODULE: + addToList(FIELD.NAME.SUBSCRIBER_NAME, DataService + .getSubscriberName()); + addToList(FIELD.NAME.SERVICE_INSTANCE_NAME, DataService + .getServiceInstanceName()); + addToList(FIELD.NAME.MODEL_NAME, DataService + .getModelInfo(_this.componentId)["modelName"]); + addToList(FIELD.NAME.MODEL_INVARIANT_UUID, DataService + .getModelInfo(_this.componentId)["modelInvariantId"]); + addToList(FIELD.NAME.MODEL_VERSION, DataService + .getModelInfo(_this.componentId)["modelVersion"]); + addToList(FIELD.NAME.MODEL_UUID, DataService + .getModelInfo(_this.componentId)["modelNameVersionId"]); + break; + case COMPONENT.NETWORK: + case COMPONENT.VNF: + case COMPONENT.VOLUME_GROUP: + addToList(FIELD.NAME.SUBSCRIBER_NAME, DataService + .getSubscriberName()); + addToList(FIELD.NAME.SERVICE_INSTANCE_NAME, DataService + .getServiceInstanceName()); + addToList(FIELD.NAME.MODEL_NAME, DataService + .getModelInfo(_this.componentId)["modelName"]); + addToList(FIELD.NAME.MODEL_INVARIANT_UUID, DataService + .getModelInfo(_this.componentId)["modelInvariantId"]); + addToList(FIELD.NAME.MODEL_VERSION, DataService + .getModelInfo(_this.componentId)["modelVersion"]); + addToList(FIELD.NAME.MODEL_UUID, DataService + .getModelInfo(_this.componentId)["modelNameVersionId"]); + break; + } + + var additionalList = ComponentService.getInventoryParameterList( + _this.componentId, DataService.getInventoryItem()); + + return summaryList.concat(ComponentService + .getDisplayNames(additionalList)); + } + }; + + var getMsoUrl = function() { + switch (_this.componentId) { + case COMPONENT.NETWORK: + return "mso_delete_nw_instance/" + + DataService.getServiceInstanceId() + "/networks/" + + DataService.getNetworkInstanceId(); + case COMPONENT.SERVICE: + return "mso_delete_svc_instance/" + + DataService.getServiceInstanceId(); + case COMPONENT.VNF: + return "mso_delete_vnf_instance/" + + DataService.getServiceInstanceId() + "/vnfs/" + + DataService.getVnfInstanceId(); + case COMPONENT.VF_MODULE: + return "mso_delete_vfmodule_instance/" + + DataService.getServiceInstanceId() + "/vnfs/" + + DataService.getVnfInstanceId() + "/vfModules/" + + DataService.getVfModuleInstanceId(); + case COMPONENT.VOLUME_GROUP: + return "mso_delete_volumegroup_instance/" + + DataService.getServiceInstanceId() + "/vnfs/" + + DataService.getVnfInstanceId() + "/volumeGroups/" + + DataService.getVolumeGroupInstanceId(); + } + } + + var addToList = function(name, value) { + _this.parameterList.push({ + name : name, + value : value + }); + }; + + var getMsoRequestDetails = function(parameterList) { + console.log("getMsoRequestDetails invoked"); + var inventoryInfo = ComponentService.getInventoryInfo( + _this.componentId, DataService.getInventoryItem()); + var modelInfo = DataService.getModelInfo(_this.componentId); + var requestDetails = { + modelInfo : { + modelType : _this.componentId, + modelInvariantId : modelInfo.modelInvariantId, + modelNameVersionId : modelInfo.modelNameVersionId, + modelName : modelInfo.modelName, + modelCustomizationName : modelInfo.modelCustomizationName, + modelVersion : modelInfo.modelVersion + }, + requestInfo : { + source : "VID" + } + }; + + switch (_this.componentId) { + case COMPONENT.SERVICE: + break; + case COMPONENT.VNF: + console.log("getMsoRequestDetails COMPONENT.VNF"); + var lcpRegion = getValueFromList(FIELD.ID.LCP_REGION, parameterList); + if (lcpRegion === FIELD.KEY.LCP_REGION_TEXT) { + lcpRegion = getValueFromList(FIELD.ID.LCP_REGION_TEXT, + parameterList); + } + requestDetails.cloudConfiguration = { + lcpCloudRegionId : lcpRegion, + tenantId : getValueFromList(FIELD.ID.TENANT, parameterList) + }; + + break; + case COMPONENT.VF_MODULE: + var lcpRegion = getValueFromList(FIELD.ID.LCP_REGION, parameterList); + if (lcpRegion === FIELD.KEY.LCP_REGION_TEXT) { + lcpRegion = getValueFromList(FIELD.ID.LCP_REGION_TEXT, + parameterList); + } + requestDetails.cloudConfiguration = { + lcpCloudRegionId : lcpRegion, + tenantId : getValueFromList(FIELD.ID.TENANT, parameterList) + }; + break; + case COMPONENT.VOLUME_GROUP: + var lcpRegion = getValueFromList(FIELD.ID.LCP_REGION, parameterList); + if (lcpRegion === FIELD.KEY.LCP_REGION_TEXT) { + lcpRegion = getValueFromList(FIELD.ID.LCP_REGION_TEXT, + parameterList); + } + requestDetails.cloudConfiguration = { + lcpCloudRegionId : lcpRegion, + tenantId : getValueFromList(FIELD.ID.TENANT, parameterList) + }; + + break; + default: + requestDetails.cloudConfiguration = { + lcpCloudRegionId : DataService.getLcpRegion(), + tenantId : DataService.getTenant() + }; + } + return requestDetails; + } + + var getLcpRegion = function() { + var cloudRegionTenantList = DataService.getCloudRegionTenantList(); + var parameter = FIELD.PARAMETER.LCP_REGION; + parameter.optionList = new Array(); + for (var i = 0; i < cloudRegionTenantList.length; i++) { + for (var j = 0; j < parameter.optionList.length; j++) { + if (parameter.optionList[j].id === cloudRegionTenantList[i].cloudRegionId) { + break; + } + } + if (j < parameter.optionList.length) { + continue; + } + parameter.optionList.push({ + id : cloudRegionTenantList[i].cloudRegionId + }); + } + return parameter; + }; + + var getTenantList = function(cloudRegionId) { + var cloudRegionTenantList = DataService.getCloudRegionTenantList(); + var parameter = FIELD.PARAMETER.TENANT_ENABLED; + parameter.optionList = new Array(); + for (var i = 0; i < cloudRegionTenantList.length; i++) { + if (cloudRegionTenantList[i].cloudRegionId === cloudRegionId) { + parameter.optionList.push({ + id : cloudRegionTenantList[i].tenantId, + name : cloudRegionTenantList[i].tenantName + }); + } + } + return parameter; + + }; + + var addOptionList = function(parameter, optionSimpleArray) { + var optionList = new Array(); + if (!angular.isArray(optionSimpleArray)) { + return optionList; + } + for (var i = 0; i < optionSimpleArray.length; i++) { + optionList.push({ + name : optionSimpleArray[i] + }); + } + parameter.optionList = optionList; + return parameter; + }; + + var getValueFromList = function(id, parameterList) { + for (var i = 0; i < parameterList.length; i++) { + if (parameterList[i].id === id) { + return parameterList[i].value; + } + } + }; + + var updateUserParameterList = function(updatedId, parameterListControl) { + if (updatedId === FIELD.ID.LCP_REGION) { + var list = parameterListControl.getList(updatedId); + if (list[0].selectedIndex >= 0) { + parameterListControl + .updateList([ getTenantList(list[0].value) ]); + } else { + parameterListControl + .updateList([ FIELD.PARAMETER.TENANT_DISABLED ]); + } + if (list[0].value === FIELD.KEY.LCP_REGION_TEXT) { + parameterListControl + .updateList([ FIELD.PARAMETER.LCP_REGION_TEXT_VISIBLE ]); + } else { + parameterListControl + .updateList([ FIELD.PARAMETER.LCP_REGION_TEXT_HIDDEN ]); + } + } else if (updatedId === FIELD.ID.SUBSCRIBER_NAME) { + var list = parameterListControl.getList(updatedId); + if (list[0].selectedIndex >= 0) { + DataService.setGlobalCustomerId(list[0].value); + + AaiService.getSubscriptionServiceTypeList(DataService + .getGlobalCustomerId(), function(response) { + DataService.setSubscriptionServiceTypeList(response); + var serviceTypeParameters = FIELD.PARAMETER.SERVICE_TYPE; + serviceTypeParameters.optionList = []; + + for (var i = 0; i < response.length; i++) { + serviceTypeParameters.optionList.push({ + "id" : response[i], + "name" : response[i] + }); + } + parameterListControl.updateList([ serviceTypeParameters ]); + }); + + } else { + parameterListControl + .updateList([ FIELD.PARAMETER.SERVICE_TYPE_DISABLED ]); + } + } + }; + + return { + initializeComponent : function(componentId) { + _this.componentId = ComponentService.initialize(componentId); + }, + getComponentDisplayName : ComponentService.getComponentDisplayName, + getSummaryList : getSummaryList, + getParameters : function(getParametersHandler) { + _this.getParametersHandler = getParametersHandler; + UtilityService.setHttpErrorHandler(_this.httpErrorHandler); + UtilityService.startAsyncOperations(getAsyncOperationList(), + internalGetParametersHandler); + }, + updateUserParameterList : updateUserParameterList, + getMsoRequestDetails : getMsoRequestDetails, + getMsoUrl : getMsoUrl + } +} + +app.factory("DeletionService", [ "$log", "AaiService", "AsdcService", + "DataService", "ComponentService", "COMPONENT", "FIELD", + "UtilityService", DeletionService ]); diff --git a/vid/src/main/webapp/app/vid/scripts/services/detailsService.js b/vid/src/main/webapp/app/vid/scripts/services/detailsService.js new file mode 100644 index 000000000..38f161d05 --- /dev/null +++ b/vid/src/main/webapp/app/vid/scripts/services/detailsService.js @@ -0,0 +1,98 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +"use strict"; + +var DetailsService = function($log, DataService, ComponentService, COMPONENT, + FIELD, UtilityService) { + + var _this = this; + + var getSummaryList = function() { + switch (_this.componentId) { + case COMPONENT.NETWORK: + case COMPONENT.SERVICE: + case COMPONENT.VNF: + case COMPONENT.VF_MODULE: + case COMPONENT.VOLUME_GROUP: + return [ { + name : FIELD.NAME.SUBSCRIBER_NAME, + value : DataService.getSubscriberName() + }, { + name : FIELD.NAME.SERVICE_INSTANCE_ID, + value : DataService.getServiceInstanceId() + }, { + name : FIELD.NAME.SERVICE_TYPE, + value : DataService.getServiceType() + } ]; + } + }; + + var getDetailsList = function() { + switch (_this.componentId) { + case COMPONENT.NETWORK: + case COMPONENT.SERVICE: + case COMPONENT.VNF: + case COMPONENT.VF_MODULE: + case COMPONENT.VOLUME_GROUP: + return ComponentService.getDisplayNames(ComponentService + .getInventoryParameterList(_this.componentId, DataService + .getInventoryItem())); + } + }; + + var getMsoFilterString = function() { + + var instanceId = ""; + + switch (_this.componentId) { + case COMPONENT.NETWORK: + instanceId = DataService.getNetworkInstanceId(); + break; + case COMPONENT.SERVICE: + instanceId = DataService.getServiceInstanceId(); + break; + case COMPONENT.VNF: + instanceId = DataService.getVnfInstanceId(); + break; + case COMPONENT.VF_MODULE: + instanceId = DataService.getVfModuleInstanceId(); + break; + case COMPONENT.VOLUME_GROUP: + instanceId = DataService.getVolumeGroupInstanceId(); + } + + return "filter=" + _this.componentId + "InstanceId:EQUALS:" + + instanceId; + }; + + return { + initializeComponent : function(componentId) { + _this.componentId = ComponentService.initialize(componentId); + }, + getComponentDisplayName : ComponentService.getComponentDisplayName, + getSummaryList : getSummaryList, + getDetailsList : getDetailsList, + getMsoFilterString : getMsoFilterString + } +} + +app.factory("DetailsService", [ "$log", "DataService", "ComponentService", + "COMPONENT", "FIELD", "UtilityService", DetailsService ]); diff --git a/vid/src/main/webapp/app/vid/scripts/services/msoService.js b/vid/src/main/webapp/app/vid/scripts/services/msoService.js new file mode 100644 index 000000000..2d4344685 --- /dev/null +++ b/vid/src/main/webapp/app/vid/scripts/services/msoService.js @@ -0,0 +1,146 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +"use strict"; + +var MsoService = function($http, $log, PropertyService, UtilityService) { + + var _this = this; + + /* + * Common function to handle both create and delete instance requests + */ + var requestInstanceUpdate = function(request, successCallbackFunction) { + $log.debug("MsoService:requestInstanceUpdate: request:"); + $log.debug(request); + $http.post(PropertyService.getMsoBaseUrl() + "/" + request.url, { + requestDetails : request.requestDetails + }, { + timeout : PropertyService.getServerResponseTimeoutMsec() + }).then(successCallbackFunction)["catch"] + (UtilityService.runHttpErrorHandler); + } + + var checkValidStatus = function(response) { + if (response.data.status < 200 || response.data.status > 202) { + throw { + type : "msoFailure" + } + } + } + + var addListEntry = function(name, value) { + var entry = '"' + name + '": '; + if (value === undefined) { + return entry + "undefined"; + } else { + return entry + '"' + value + '"'; + } + } + + return { + createInstance : requestInstanceUpdate, + deleteInstance : requestInstanceUpdate, + getOrchestrationRequest : function(requestId, successCallbackFunction) { + $log.debug("MsoService:getOrchestrationRequest: requestId: " + + requestId); + $http.get( + PropertyService.getMsoBaseUrl() + "/mso_get_orch_req/" + + requestId + "?r=" + Math.random(), + { + timeout : PropertyService + .getServerResponseTimeoutMsec() + }).then(successCallbackFunction)["catch"] + (UtilityService.runHttpErrorHandler); + }, + getOrchestrationRequests : function(filterString, + successCallbackFunction) { + $log.debug("MsoService:getOrchestrationRequests: filterString: " + + filterString); + $http.get( + PropertyService.getMsoBaseUrl() + "/mso_get_orch_reqs/" + + encodeURIComponent(filterString) + "?r=" + + Math.random(), + { + timeout : PropertyService + .getServerResponseTimeoutMsec() + }).then(successCallbackFunction)["catch"] + (UtilityService.runHttpErrorHandler); + }, + getFormattedCommonResponse : function(response) { + return UtilityService.getCurrentTime() + " HTTP Status: " + + UtilityService.getHttpStatusText(response.data.status) + + "\n" + angular.toJson(response.data.entity, true) + + "\n\n"; + }, + checkValidStatus : checkValidStatus, + getFormattedGetOrchestrationRequestsResponse : function(response) { + UtilityService.checkUndefined("entity", response.data.entity); + UtilityService.checkUndefined("status", response.data.status); + checkValidStatus(response); + + var list = response.data.entity.requestList + UtilityService.checkUndefined("requestList", list); + + var message = ""; + + for (var i = 0; i < list.length; i++) { + var request = list[i].request; + message += addListEntry("requestId", request.requestId) + ",\n"; + message += addListEntry("requestType", request.requestType) + + ",\n"; + var status = request.requestStatus; + if (status === undefined) { + message += addListEntry("requestStatus", undefined) + "\n"; + } else { + message += addListEntry("timestamp", status.timestamp) + + ",\n"; + message += addListEntry("requestState", status.requestState) + + ",\n"; + message += addListEntry("statusMessage", + status.statusMessage) + + ",\n"; + message += addListEntry("percentProgress", + status.percentProgress) + + "\n"; + } + if (i < (list.length - 1)) { + message += "\n"; + } + } + return message; + }, + showResponseContentError : function(error, showFunction) { + switch (error.type) { + case "undefinedObject": + showFunction("System failure", error.message); + break; + case "msoFailure": + showFunction("MSO failure", "see log below for details") + break; + default: + showFunction("System failure"); + } + } + } +} + +app.factory("MsoService", [ "$http", "$log", "PropertyService", + "UtilityService", MsoService ]); diff --git a/vid/src/main/webapp/app/vid/scripts/services/propertyService.js b/vid/src/main/webapp/app/vid/scripts/services/propertyService.js new file mode 100644 index 000000000..bfdc7ef33 --- /dev/null +++ b/vid/src/main/webapp/app/vid/scripts/services/propertyService.js @@ -0,0 +1,116 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +"use strict"; + +var PropertyService = function($location, $http) { + + var RE = /.*?:\/\/.*?:.*?\/(.*?)\//g; + var BASE_PATH = RE.exec($location.absUrl())[1]; + var DEFAULT_AAI_BASE_URL = "/" + BASE_PATH; + var DEFAULT_ASDC_BASE_URL = "asdc"; + var DEFAULT_MSO_MAX_POLLING_INTERVAL_MSEC = 60000; + var DEFAULT_MSO_MAX_POLLS = 10; + var DEFAULT_MSO_BASE_URL = "/" + BASE_PATH + "/mso"; + var DEFAULT_SERVER_RESPONSE_TIMEOUT_MSEC = 60000; + var MSO_POLLING_INTERVAL_MSECS = "mso_polling_interval_msecs"; + var MSO_MAX_POLLS = "mso_max_polls"; + + var _this = this; + + _this.asdcBaseUrl = DEFAULT_ASDC_BASE_URL; + _this.aaiBaseUrl = DEFAULT_AAI_BASE_URL; + _this.msoMaxPollingIntervalMsec = DEFAULT_MSO_MAX_POLLING_INTERVAL_MSEC; + _this.msoMaxPolls = DEFAULT_MSO_MAX_POLLS; + _this.msoBaseUrl = DEFAULT_MSO_BASE_URL; + _this.serverResponseTimeoutMsec = DEFAULT_SERVER_RESPONSE_TIMEOUT_MSEC; + + return { + getAaiBaseUrl : function() { + return _this.aaiBaseUrl; + }, + setAaiBaseUrl : function(aaiBaseUrl) { + _this.aaiBaseUrl = aaiBaseUrl; + }, + getAsdcBaseUrl : function() { + return _this.asdcBaseUrl; + }, + setAsdcBaseUrl : function(asdcBaseUrl) { + _this.asdcBaseUrl = asdcBaseUrl; + }, + retrieveMsoMaxPollingIntervalMsec : function(defaultvalue) { + _this.msoMaxPollingIntervalMsec = defaultvalue; + $http.get( _this.aaiBaseUrl + "/get_property/" + MSO_POLLING_INTERVAL_MSECS + "/" + defaultvalue, { + + },{ + timeout: _this.serverResponseTimeoutMsec + }).then(function(response) { + //console.log ( "retrieveMsoMaxPollingIntervalMsec: " ); console.log ( JSON.stringify(response) ); + //console.log ( "retrieveMsoMaxPollingIntervalMsec: " + response.data ); + _this.msoMaxPollingIntervalMsec = response.data; + console.log ("retrieveMsoMaxPollingIntervalMsec: " + _this.msoMaxPollingIntervalMsec); + },function errorCallback(response) { + console.log ( "retrieveMsoMaxPollingIntervalMsec: " + response.status ); + //console.log ( "retrieveMsoMaxPollingIntervalMsec: " ); console.log ( JSON.stringify(response) ); + }); + return _this.msoMaxPollingIntervalMsec; + }, + getMsoMaxPollingIntervalMsec : function() { + return _this.msoMaxPollingIntervalMsec; + }, + setMsoMaxPollingIntervalMsec : function(msoMaxPollingIntervalMsec) { + _this.msoMaxPollingIntervalMsec = msoMaxPollingIntervalMsec; + }, + retrieveMsoMaxPolls : function(defaultvalue) { + _this.msoMaxPolls = defaultvalue; + $http.get( _this.aaiBaseUrl + "/get_property/" + MSO_MAX_POLLS + "/" + defaultvalue, { + + },{ + timeout: _this.serverResponseTimeoutMsec + }).then(function(response) { + //console.log ( "retrieveMsoMaxPolls: " ); console.log ( JSON.stringify(response) ); + //console.log ( "retrieveMsoMaxPolls: " + response.data.entity ); + _this.msoMaxPolls = response.data; + console.log ("retrieveMsoMaxPolls: " + _this.msoMaxPolls); + }); + return _this.msoMaxPolls; + }, + getMsoMaxPolls : function() { + return _this.msoMaxPolls; + }, + setMsoMaxPolls : function(msoMaxPolls) { + _this.msoMaxPolls = msoMaxPolls; + }, + getMsoBaseUrl : function() { + return _this.msoBaseUrl; + }, + setMsoBaseUrl : function(msoBaseUrl) { + _this.msoBaseUrl = msoBaseUrl; + }, + getServerResponseTimeoutMsec : function() { + return _this.serverResponseTimeoutMsec; + }, + setServerResponseTimeoutMsec : function(serverResponseTimeoutMsec) { + _this.serverResponseTimeoutMsec = serverResponseTimeoutMsec; + } + }; +} + +app.factory("PropertyService", PropertyService); diff --git a/vid/src/main/webapp/app/vid/scripts/services/utilityService.js b/vid/src/main/webapp/app/vid/scripts/services/utilityService.js new file mode 100644 index 000000000..fc7d97123 --- /dev/null +++ b/vid/src/main/webapp/app/vid/scripts/services/utilityService.js @@ -0,0 +1,228 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +"use strict"; + +/* + * "UtilityService" contains various generic methods. + * + * (*** DEPRECATED - Use PropertyService instead ***) setProperties() and + * getProperties() + * + * SYNTAX: hasContents(object) + * + * Returns "true" if "object" contains contents (i.e. is NOT undefined, null or + * ""), "false" otherwise. + * + * SYNTAX: checkUndefined(name, value) + * + * Throws an exception if "value" is undefined. The exception includes "name" as + * the cause of the exception. Returns "value" if it is defined. + * + * SYNTAX: getCurrentTime() + * + * Returns the current local date and time in the format "MM/DD/YY HH:MM:SS" + * + * SYNTAX: setHttpErrorHandler(function) + * + * Sets the HTTP error handler to "function". + * + * SYNTAX: runHttpErrorHandler(response, status) + * + * Logs warning messages and the runs the HTTP error handler previously set by + * "setHttpErrorHandler". The intended usage is for "$http" calls. Example: + * $http.get(...).then(...)["catch"](UtilityService.runHttpErrorHandler); + * + * SYNTAX: getHttpStatusText(statusCode) + * + * Expects "statusCode" to be an HTTP response code (e.g. 404). The function + * returns a string that includes both the code and an equivalent text summary. + * Example: "Not found (404)" + * + * SYNTAX: getHttpErrorMessage(response) + * + * Expects "response" to be the response object generated by a "$http" error + * condition. "getHttpErrorMessage" examines the object and returns a summary + * string for some known conditions. + */ + +var UtilityService = function($log) { + + var _this = this; + + function hasContents(object) { + if (object === undefined || object === null || object === "") { + return false; + } + return true; + } + + function padZero(number) { + if (number < 10) { + return "0" + number; + } else { + return "" + number; + } + } + + var httpErrorHandler = function(response, status) { + $log.warn("UtilityService:httpErrorHandler: response:"); + $log.warn(response); + $log.warn("UtilityService:httpErrorHandler: status:"); + $log.warn(status); + if (angular.isFunction(_this.httpErrorHandler)) { + _this.httpErrorHandler(response, status); + } + }; + + var startNextAsyncOperation = function() { + if (_this.asyncOperations.count < _this.asyncOperations.operationList.length) { + _this.asyncOperations.operationList[_this.asyncOperations.count++] + (); + } else { + if (angular.isFunction(_this.asyncOperations.callbackFunction)) { + _this.asyncOperations.callbackFunction(); + } + } + }; + + return { + setProperties : function(properties) { + _this.properties = properties; + }, + getProperties : function() { + return _this.properties; + }, + hasContents : hasContents, + checkUndefined : function(name, value) { + if (value === undefined) { + throw { + type : "undefinedObject", + message : "undefined object: \"" + name + "\"" + }; + } + return value; + }, + getCurrentTime : function() { + var time = new Date(); + return padZero(time.getMonth() + 1) + "/" + + padZero(time.getDate() + 1) + "/" + + (time.getFullYear() - 2000) + " " + + padZero(time.getHours()) + ":" + + padZero(time.getMinutes()) + ":" + + padZero(time.getSeconds()) + }, + getHttpStatusText : function(statusCode) { + var statusMap = { + "200" : "OK", + "201" : "Created", + "202" : "Accepted", + "400" : "Bad Request", + "401" : "Unauthorized", + "404" : "Not Found", + "405" : "Method Not Allowed", + "409" : "Locked", + "500" : "Internal Server Error", + "503" : "Service Unavailable", + "504" : "Gateway Timeout" + } + + if (status === undefined) { + return "Undefined"; + } + + var statusText = statusMap[statusCode]; + if (statusText === undefined) { + statusText = "Unknown"; + } + + return statusText + " (" + statusCode + ")"; + }, + getHttpErrorMessage : function(response) { + var data = response.data; + if (response.status === 500 && hasContents(data.exception)) { + var summary = "exception: " + data.exception; + if (hasContents(data.message)) { + summary += " message: " + data.message; + } + return summary; + } + if (response.status === 0 && response.statusText === "") { + /* + * This logic is somewhat "fuzzy". Potential (brainstorming) + * enhancements if users find the message unreliable include: + * + * A) SERVER TIMEOUT: perhaps a newer version of Angular can + * reliably determine timeouts. + * + * B) SERVER TIMEOUT: recording start / end times and using that + * to determine if timeout occured + * + * C) SESSION TIMEOUT "Potentially" examine cookies, although + * that may not be feasible if cookies are set to "httponly". + */ + if (data === null) { + return "possible server timeout"; + } + if (data === "") { + return "Possible reasons include a session timeout or a server issue. " + + "A session timeout might be resolved by refreshing the screen and re-logging in"; + } + } + var summary = ""; + if (response.status !== undefined && response.status > 0) { + summary = "status: " + response.status; + } + if (hasContents(response.statusText)) { + if (summary !== "") { + summary += " "; + } + summary += "message: " + response.statusText; + } + return summary; + }, + setHttpErrorHandler : function(httpErrorHandler) { + _this.httpErrorHandler = httpErrorHandler; + }, + runHttpErrorHandler : function(response, status) { + httpErrorHandler(response, status); + }, + startAsyncOperations : function(operationList, callbackFunction) { + for (var i = 0; i < operationList.length; i++) { + if (!angular.isFunction(operationList[i])) { + throw "UtilityService:startAsyncOperations: invalid function: index: " + + i; + } + } + _this.asyncOperations = { + operationList : operationList, + callbackFunction : callbackFunction, + count : 0 + }; + startNextAsyncOperation(); + }, + startNextAsyncOperation : startNextAsyncOperation, + stopAsyncOperations : function() { + _this.asyncOperations.count = _this.asyncOperations.operationList.length; + } + } +} + +app.factory("UtilityService", UtilityService); |