[CLAMP-1] Initial ONAP CLAMP seed code commit
[clamp.git] / src / main / resources / META-INF / resources / designer / scripts / AutosaveProjectCtrl.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License"); 
9  * you may not use this file except in compliance with the License. 
10  * You may obtain a copy of the License at
11  * 
12  * http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software 
15  * distributed under the License is distributed on an "AS IS" BASIS, 
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
17  * See the License for the specific language governing permissions and 
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23
24 function AutosaveProject($scope,$rootScope,$resource, $http, $timeout, $location, $interval, $q, Datafactory) 
25 {       
26     console.log("//////////Autosaveproject");   
27         $scope.saveProjectToUrl = function(UTMMDTProject,svnUploadURL){
28             console.log("saveProjectURL");   
29         console.log('Autosaveproject Enter == ' + new Date().getTime());
30         console.log(new Date());
31         var def = $q.defer();
32         
33         $http.post(svnUploadURL, UTMMDTProject)
34         .success(function(data){ 
35         console.log("success");         
36                 def.resolve(data);
37         })
38         .error(function(data){ 
39         console.log("error");                         
40                 def.reject("Autosave unsuccessful");
41         });
42         
43         return def.promise;        
44        
45     };
46         
47         $scope.autosave = function(){
48                 console.log("autosave");
49                 
50                 var saveProjectURL = "/utm-service/project_administration/autoSaveProject";
51         
52                 var UTMProjectExplorer = {};
53                 UTMProjectExplorer.projectName = $rootScope.projectName;
54                 UTMProjectExplorer.utmModels = $rootScope.utmModels;
55                 UTMProjectExplorer.revision = autoSaveRevision;
56                 UTMProjectExplorer.utmDepthValueMap = $rootScope.depthElementKeyMap;
57                 UTMProjectExplorer.utmCountValueMap = $rootScope.countElementKeyMap;
58
59                 var utm_models = [];
60                 $rootScope.populateUTMModelArray(utm_models,$rootScope.utmModels);                      
61                                                                                 
62                 var UTMMDTProject = {};
63                 UTMMDTProject.utmProjectExplorer = UTMProjectExplorer;
64                 UTMMDTProject.utmModels = utm_models;           
65                 UTMMDTProject.almqcdata = $rootScope.almqcData;         
66                 UTMMDTProject.wsdlInfo = null;
67                 UTMMDTProject.schemaLocation = null;
68                 
69                 if ($rootScope.wsdlInfo != null) {
70                         UTMMDTProject.schemaLocation = $rootScope.wsdlInfo.schemaLocation;
71                         UTMMDTProject.oldSchemaLocation = $rootScope.wsdlInfo.oldSchemaLocation;
72                         UTMMDTProject.schemaUpgradedFlag = $rootScope.wsdlInfo.schemaUpgradedFlag;
73                 }
74
75                 UTMMDTProject.revision=$rootScope.revision;
76                 console.log(UTMMDTProject.revision);
77                 
78                 UTMMDTProject.checkOutPath=$rootScope.checkOutPath;
79                 UTMMDTProject.oldNewModelNameMap = old_new_model_name;          
80                 UTMMDTProject.automationDetails={};
81                 
82                 UTMMDTProject.automationDetails.projectPreferenceInfo =  Datafactory.getProjectPreferenceInfo();
83                 UTMMDTProject.automationDetails.environmentData =  $rootScope.environmentData;
84                 UTMMDTProject.automationDetails.pythonScriptList =  Datafactory.getCommonPythonScriptList();
85                 UTMMDTProject.automationDetails.dbToolRequestList =  Datafactory.getDbToolProjectLevelList();                                   
86                 UTMMDTProject.automationDetails.runtimePythonScriptList =  Datafactory.getRuntimePythonScriptProjectLevelList();
87                 UTMMDTProject.automationDetails.xmlValidatorList =  Datafactory.getXmlValidatorList();
88                 UTMMDTProject.automationDetails.fileWriterList =  Datafactory.getWriteFileDataList();
89                 UTMMDTProject.automationDetails.fileStreamWriterList =  Datafactory.getFileStreamWriterList();
90                 
91                 
92                 
93                 if($rootScope.openedProject != null){
94                         console.log('opened project...')                        
95                         var existingData = JSON.stringify($rootScope.openedProject);
96                         var currentgData = JSON.stringify(UTMMDTProject);                       
97                         if(angular.equals(existingData, currentgData)){
98                                 //do nothing
99                                 console.log('No changes found.');
100                         }else{
101                                 console.log('Changes found.');
102                                 $scope.saveProjectToUrl(UTMMDTProject,saveProjectURL)
103                                 .then(function(pars) {  
104                                 console.log("");                                
105                                 },
106                                 function(data) {
107                                         
108                                 });
109                         }
110                         
111                 }else{
112                         console.log('autosaving project...')
113                         $scope.saveProjectToUrl(UTMMDTProject,saveProjectURL)
114                         .then(function(pars) {
115                                 
116                         },
117                         function(data) {
118                                 
119                         });
120                 }               
121                 
122         }
123         
124         $scope.autosave();
125 }