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
24 * "msoCommitController.js" provides controller code to commit MSO requests.
\r
28 * Parent HTML/JSP code is expected to include "msoCommit.htm" (via
\r
29 * "ng-include") and this file (via "<script>"). "msoCommit.jsp" (displayed
\r
30 * when the parent code includes "msoCommit.htm") renders a popup window, but
\r
31 * initially hides the display.
\r
33 * The parent controller code is expected to broadcast either the
\r
34 * "createInstance" or "deleteInstance" events when it is ready to commit the
\r
37 * This controller receives these events (via "$scope.on" declarations), calls
\r
38 * "$scope.init()" to "unhide" and initialize the popup display and then makes a
\r
39 * REST request to the appropriate server Java controller.
\r
41 * The initial REST response is handled by "handleInitialResponse". This method
\r
42 * then polls the server (via "getRequestStatus") if the request is successful.
\r
44 * The subsequent "getRequestStatus" responses are handled by
\r
45 * "handleGetResponse".
\r
47 * "handleInitialResponse" and "handleGetResponse" primarily filter response
\r
48 * data, manipulate the display and provide error handling.
\r
50 * The mechanism has these dependencies (in addition to "msoCommit.htm"):
\r
52 * 1) Three services: MsoService, PropertyService and UtilityService
\r
54 * 2) The popup window directive found in "popupWindow.htm" and
\r
55 * "popupWindowDirective.js"
\r
57 * 2) Display styling defined in "dialogs.css"
\r
61 * The parent HTML is assumed to be the "popup-window" directive and the
\r
62 * corresponding parent controller is assumed to define the object
\r
66 var msoCommitController = function(COMPONENT, FIELD, $scope, $http, $timeout, $window, $log,
\r
67 MsoService, PropertyService, UtilityService, DataService) {
\r
69 $scope.isViewVisible = false;
\r
70 $scope.progressBarControl = {};
\r
71 $scope.popupWindowControl = {};
\r
75 $scope.$on("createInstance", function(event, request) {
\r
76 init(request, COMPONENT.MSO_CREATE_REQ );
\r
77 MsoService.createInstance(request, handleInitialResponse);
\r
80 $scope.$on("deleteInstance", function(event, request) {
\r
81 init(request, COMPONENT.MSO_DELETE_REQ);
\r
82 MsoService.deleteInstance(request, handleInitialResponse);
\r
85 var init = function(request, msoRequestType ) {
\r
86 $scope.status = FIELD.STATUS.SUBMITTING_REQUEST;
\r
87 $scope.isSpinnerVisible = true;
\r
88 $scope.isProgressVisible = true;
\r
91 $scope.isCloseEnabled = false;
\r
92 $scope.isViewVisible = true;
\r
93 $scope.popup.isVisible = true;
\r
95 _this.pollAttempts = 0;
\r
96 _this.callbackFunction = request.callbackFunction;
\r
97 _this.componentId = request.componentId;
\r
98 _this.msoRequestType = msoRequestType;
\r
99 _this.isMsoError = false;
\r
101 if (angular.isFunction($scope.progressBarControl.reset)) {
\r
102 $scope.progressBarControl.reset();
\r
104 $scope.percentProgress = 2; // Show "a little" progress
\r
106 UtilityService.setHttpErrorHandler(function(response) {
\r
107 $scope.isCloseEnabled = true;
\r
108 _this.isMsoError = true;
\r
109 showError(FIELD.ERROR.SYSTEM_FAILURE, UtilityService
\r
110 .getHttpErrorMessage(response));
\r
114 var handleInitialResponse = function(response) {
\r
116 updateViewAfterInitialResponse(response);
\r
118 _this.timer = $timeout(getRequestStatus, PropertyService
\r
119 .getMsoMaxPollingIntervalMsec());
\r
121 $scope.instanceId = response.data.entity.instanceId;
\r
122 if ($scope.instanceId == null) {
\r
123 $scope.instanceId = response.data.entity.requestReferences.instanceId;
\r
126 if ( response.data != null && response.data.status != null ) {
\r
127 if (response.data.status > 299 || response.data.status < 200 ) {
\r
128 // MSO returned an error
\r
129 _this.isMsoError = true;
\r
132 MsoService.showResponseContentError(error, showError);
\r
136 var getRequestStatus = function() {
\r
137 MsoService.getOrchestrationRequest(_this.requestId, handleGetResponse);
\r
140 var handleGetResponse = function(response) {
\r
142 if (isUpdateViewAfterGetResponseComplete(response)) {
\r
145 //console.log ( "msoCommitController _this.pollAttempts=" + _this.pollAttempts + " max polls=" + PropertyService.getMsoMaxPolls());
\r
146 if (++_this.pollAttempts > PropertyService.getMsoMaxPolls()) {
\r
147 _this.isMsoError = true;
\r
148 showError(FIELD.ERROR.MAX_POLLS_EXCEEDED);
\r
150 _this.timer = $timeout(getRequestStatus, PropertyService
\r
151 .getMsoMaxPollingIntervalMsec());
\r
154 _this.isMsoError = true;
\r
155 MsoService.showResponseContentError(error, showError);
\r
159 var updateViewAfterInitialResponse = function(response) {
\r
160 $scope.isCloseEnabled = true;
\r
162 updateLog(response);
\r
164 _this.requestId = UtilityService.checkUndefined(FIELD.ID.REQUEST_ID,
\r
165 UtilityService.checkUndefined(FIELD.ID.REQUEST_REFERENCES,
\r
166 response.data.entity.requestReferences).requestId);
\r
168 $scope.percentProgress = 4; // Show "a little more" progress
\r
169 $scope.status = FIELD.STATUS.IN_PROGRESS;
\r
173 * Updates the view and returns "true" if the MSO operation has returned a
\r
174 * "Complete" status.
\r
176 var isUpdateViewAfterGetResponseComplete = function(response) {
\r
177 //console.log("msoCommitController isUpdateViewAfterGetResponseComplete");
\r
178 updateLogFinalResponse(response);
\r
180 var requestStatus = UtilityService.checkUndefined(FIELD.ID.REQUEST_STATUS,
\r
181 UtilityService.checkUndefined(FIELD.ID.REQUEST,
\r
182 response.data.entity.request).requestStatus);
\r
184 var requestState = requestStatus.requestState;
\r
185 console.log("msoCommitController requestState=" + requestState);
\r
186 // look for "progress" or "pending"
\r
187 var patt1 = /progress/i;
\r
188 var patt2 = /pending/i;
\r
189 var result1 = patt1.test(requestState);
\r
190 var result2 = patt2.test(requestState)
\r
191 if (result1 || result2) {
\r
192 requestState = FIELD.STATUS.IN_PROGRESS;
\r
194 var statusMessage = requestStatus.statusMessage;
\r
195 console.log("msoCommitController statusMessage=" + statusMessage);
\r
196 if (UtilityService.hasContents(statusMessage)) {
\r
197 $scope.status = requestState + " - " + statusMessage;
\r
199 $scope.status = requestState;
\r
201 if (UtilityService.hasContents(requestStatus.percentProgress)) {
\r
202 $scope.percentProgress = requestStatus.percentProgress;
\r
205 if ( (requestState.toLowerCase() === FIELD.STATUS.FAILED.toLowerCase()) || (requestState.toLowerCase() === FIELD.STATUS.UNLOCKED.toLowerCase())) {
\r
207 type : FIELD.STATUS.MSO_FAILURE
\r
211 if (requestState.toLowerCase() === FIELD.STATUS.COMPLETE.toLowerCase()) {
\r
212 $scope.isSpinnerVisible = false;
\r
219 var updateLog = function(response) {
\r
220 $scope.log = MsoService.getFormattedCommonResponse(response)
\r
222 UtilityService.checkUndefined("entity", response.data.entity);
\r
223 UtilityService.checkUndefined("status", response.data.status);
\r
224 MsoService.checkValidStatus(response);
\r
226 var updateLogFinalResponse = function(response) {
\r
227 $scope.log = MsoService.getFormattedSingleGetOrchestrationRequestResponse(response)
\r
229 UtilityService.checkUndefined("entity", response.data.entity);
\r
230 UtilityService.checkUndefined("status", response.data.status);
\r
231 MsoService.checkValidStatus(response);
\r
233 $scope.close = function() {
\r
234 if (_this.timer !== undefined) {
\r
235 $timeout.cancel(_this.timer);
\r
237 $scope.isViewVisible = false;
\r
238 if (angular.isFunction(_this.callbackFunction)) {
\r
239 if ($scope.error === "") {
\r
240 _this.callbackFunction({
\r
241 isSuccessful : true,
\r
242 instanceId : $scope.instanceId
\r
245 _this.callbackFunction({
\r
246 isSuccessful : false
\r
248 findNextPage(_this.componentId, _this.msoRequestType, _this.isMsoError);
\r
251 $scope.popup.isVisible = false;
\r
255 var showError = function(summary, details) {
\r
256 var message = summary;
\r
257 if (UtilityService.hasContents(details)) {
\r
258 message += " (" + details + ")";
\r
260 $scope.isSpinnerVisible = false;
\r
261 $scope.isProgressVisible = false;
\r
262 $scope.error = message;
\r
263 $scope.status = FIELD.STATUS.ERROR;
\r
266 var findNextPage = function ( cid, msoRequestType, isMsoError ) {
\r
267 //console.log ("window.location.href" + window.location.href);
\r
268 //console.log ("component id " + cid);
\r
269 var originalUrl = window.location.href;
\r
270 if ( (cid === COMPONENT.SERVICE) && (msoRequestType === COMPONENT.MSO_CREATE_REQ) ) {
\r
271 var url = originalUrl;
\r
275 for ( x = 0; x < url.length; x++) {
\r
276 if ( url.charAt(x) == '/' ) {
\r
278 if ( count == 4 ) {
\r
279 firstStr = url.substring (0,x);
\r
284 // By default show the search existing service instances screen
\r
285 //var newUrl = firstStr + COMPONENT.SERVICEMODELS_INSTANCES_SERVICES_PATH;
\r
286 var newUrl = COMPONENT.SERVICEMODELS_INSTANCES_SERVICES_PATH;
\r
288 if ( isMsoError ) {
\r
289 //Show the Browse SDC models screen
\r
290 //newUrl = firstStr + COMPONENT.SERVICEMODELS_MODELS_SERVICES_PATH;
\r
291 newUrl = COMPONENT.SERVICEMODELS_MODELS_SERVICES_PATH;
\r
293 window.location.href = newUrl;
\r
298 appDS2.controller("msoCommitController", [ "COMPONENT", "FIELD", "$scope", "$http", "$timeout",
\r
299 "$window", "$log", "MsoService", "PropertyService", "UtilityService",
\r
300 msoCommitController ]);
\r