2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
23 var MsoService = function($http, $log, PropertyService, UtilityService, COMPONENT, FIELD) {
\r
28 * Common function to handle both create and delete instance requests
\r
30 var requestInstanceUpdate = function(request, successCallbackFunction) {
\r
31 $log.debug("MsoService:requestInstanceUpdate: request:");
\r
32 $log.debug(request);
\r
33 $http.post( "mso/" + request.url, {
\r
34 requestDetails : request.requestDetails
\r
36 timeout : PropertyService.getServerResponseTimeoutMsec()
\r
37 }).then(successCallbackFunction)["catch"]
\r
38 (UtilityService.runHttpErrorHandler);
\r
41 var checkValidStatus = function(response) {
\r
42 if (response.data.status < 200 || response.data.status > 202) {
\r
44 type : FIELD.ID.MSO_FAILURE
\r
49 var addListEntry = function(name, value) {
\r
50 var entry = '"' + name + '": ';
\r
51 if (value === undefined) {
\r
52 return entry + "undefined";
\r
54 return entry + '"' + value + '"';
\r
59 createInstance : requestInstanceUpdate,
\r
60 deleteInstance : requestInstanceUpdate,
\r
61 getOrchestrationRequest : function(requestId, successCallbackFunction) {
\r
62 $log.debug("MsoService:getOrchestrationRequest: requestId: "
\r
65 "mso/mso_get_orch_req/"
\r
66 + requestId + "?r=" + Math.random(),
\r
68 timeout : PropertyService
\r
69 .getServerResponseTimeoutMsec()
\r
70 }).then(successCallbackFunction)["catch"]
\r
71 (UtilityService.runHttpErrorHandler);
\r
73 getOrchestrationRequests : function(filterString,
\r
74 successCallbackFunction) {
\r
75 $log.debug("MsoService:getOrchestrationRequests: filterString: "
\r
78 "mso/mso_get_orch_reqs/"
\r
79 + encodeURIComponent(filterString) + "?r="
\r
82 timeout : PropertyService
\r
83 .getServerResponseTimeoutMsec()
\r
84 }).then(successCallbackFunction)["catch"]
\r
85 (UtilityService.runHttpErrorHandler);
\r
87 getFormattedCommonResponse : function(response) {
\r
88 return UtilityService.getCurrentTime() + " HTTP Status: "
\r
89 + UtilityService.getHttpStatusText(response.data.status)
\r
90 + "\n" + angular.toJson(response.data.entity, true)
\r
93 checkValidStatus : checkValidStatus,
\r
94 getFormattedGetOrchestrationRequestsResponse : function(response) {
\r
95 UtilityService.checkUndefined(COMPONENT.ENTITY, response.data.entity);
\r
96 UtilityService.checkUndefined(COMPONENT.STATUS, response.data.status);
\r
97 checkValidStatus(response);
\r
99 var list = response.data.entity.requestList
\r
100 UtilityService.checkUndefined(FIELD.ID.REQUEST_LIST, list);
\r
104 for (var i = 0; i < list.length; i++) {
\r
105 var request = list[i].request;
\r
106 message += addListEntry(FIELD.ID.REQUEST_ID, request.requestId) + ",\n";
\r
107 message += addListEntry(FIELD.ID.REQUEST_TYPE, request.requestType)
\r
109 var status = request.requestStatus;
\r
110 if (status === undefined) {
\r
111 message += addListEntry(FIELD.ID.REQUEST_STATUS, undefined) + "\n";
\r
113 message += addListEntry(FIELD.ID.TIMESTAMP, status.timestamp)
\r
115 message += addListEntry(FIELD.ID.REQUEST_STATE, status.requestState)
\r
117 message += addListEntry(FIELD.ID.REQUEST_STATUS,
\r
118 status.statusMessage)
\r
120 message += addListEntry(FIELD.ID.PERCENT_PROGRESS,
\r
121 status.percentProgress)
\r
124 if (i < (list.length - 1)) {
\r
130 getFormattedSingleGetOrchestrationRequestResponse : function (response) {
\r
131 UtilityService.checkUndefined(COMPONENT.ENTITY, response.data.entity);
\r
132 UtilityService.checkUndefined(COMPONENT.STATUS, response.data.status);
\r
133 checkValidStatus(response);
\r
136 if ( UtilityService.hasContents (response.data.entity.request) ) {
\r
137 var request = response.data.entity.request;
\r
138 message += addListEntry(FIELD.ID.REQUEST_ID, request.requestId) + ",\n";
\r
139 message += addListEntry(FIELD.ID.REQUEST_TYPE, request.requestType)
\r
141 var status = request.requestStatus;
\r
142 if (status === undefined) {
\r
143 message += addListEntry(FIELD.ID.REQUEST_STATUS, undefined) + "\n";
\r
145 message += addListEntry(FIELD.ID.TIMESTAMP, status.timestamp)
\r
147 message += addListEntry(FIELD.ID.REQUEST_STATE, status.requestState)
\r
149 message += addListEntry(FIELD.ID.REQUEST_STATUS,
\r
150 status.statusMessage)
\r
152 message += addListEntry(FIELD.ID.PERCENT_PROGRESS,
\r
153 status.percentProgress)
\r
159 showResponseContentError : function(error, showFunction) {
\r
160 switch (error.type) {
\r
161 case "undefinedObject":
\r
162 showFunction(FIELD.ERROR.SYSTEM_FAILURE, error.message);
\r
165 showFunction(FIELD.ERROR.MSO, "")
\r
168 showFunction(FIELD.ERROR.SYSTEM_FAILURE);
\r
174 appDS2.factory("MsoService", [ "$http", "$log", "PropertyService",
\r
175 "UtilityService", "COMPONENT", "FIELD", MsoService ]);
\r