Project

General

Profile

1
var repoControllers = angular.module('repoControllers', []);
2

    
3
repoControllers.controller('repoBrowseCtrl', [
4
	'$scope', '$http', '$timeout', '$sce', '$location',
5
	function ($scope, $http, $timeout, $sce, $location) {
6
		common_init($scope, $http, $sce, $location);
7
		$scope.repoBrowseFields = getBrowseFields();
8
		
9
		$scope.sortType     = 'term';
10
		$scope.sortReverse  = false;
11
		
12
		$scope.repoBrowseData = { 'data' : [] };
13
			
14
		$scope.searchApis = function (text) {
15
			$scope.go('/list/__SEARCH__/' + text); 
16
		} 
17
		
18
		$scope.browseApis = function (field, value) {
19
			$('#showRepoBrowseData').modal('hide');
20
			$scope.showSpinner();
21
			$timeout(function() {
22
				$scope.go('/list/' + field + '/' + value);
23
			}, 1500);
24
		}
25
		
26
		$scope.browseRepoField = function(field) {
27
			$scope.repoBrowseData = {
28
				'label' : field.label,
29
				'id' :    field.id,
30
				'data'  : []
31
			};
32
			$scope.showSpinner();
33
	      	$http.get('browseRepoField.do?field=' + field.id).success(
34
	            function(data) {
35
	            	$scope.hideSpinner();
36
	            	$scope.repoBrowseData.data = data;
37
	            	$('#showRepoBrowseData').modal('show');
38
	            }
39
	        ).error(
40
	            function() {
41
	            	$scope.showError('Something really bad must have happened to our fellow hamster..');
42
	            	$scope.hideSpinner();
43
	            }
44
	        );
45
		};
46
	}
47
]);
48

    
49
repoControllers.controller('repoListCtrl', [
50
	'$scope', '$http', '$timeout', '$sce', '$routeParams', '$location',
51
	function ($scope, $http, $timeout, $sce, $routeParams, $location) {
52
		common_init($scope, $http, $sce, $location);
53

    
54
		$scope.sortType     = 'repoName';
55
		$scope.sortReverse  = false;
56
		$scope.apis = [];		
57
    	$scope.currentApiSelectionParam = $routeParams.param;
58
    	$scope.currentApiSelectionValue = $routeParams.value;
59
    	
60
    	$scope.updateApis = function(refresh) {
61
			$scope.showSpinner();
62
						    
63
			var params = {
64
				'param' : $scope.currentApiSelectionParam,
65
				'value' : $scope.currentApiSelectionValue
66
			};
67
			if (refresh) {
68
				params.refresh = 1;
69
			}
70

    
71
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
72
			$http.post('listApis.do', $.param(params)).success(
73
	            function(data) {
74
	            	$scope.hideSpinner();
75
	            	$scope.apis = data;
76
	            }
77
	        ).error(
78
	            function() {
79
	            	$scope.showError('Something really bad must have happened to our fellow hamster..');
80
	            	$scope.hideSpinner();
81
	            }
82
	        );
83
    	};
84
        	
85
    	$scope.updateApis(false);
86
	}
87
]);
88

    
89
repoControllers.controller('repoApiCtrl', [
90
	'$scope', '$http', '$timeout', '$sce', '$routeParams', '$location',
91
	function ($scope, $http, $timeout, $sce, $routeParams, $location) {
92
		common_init($scope, $http, $sce, $location);
93
		
94
		commonInitialize($scope, $http, $sce);
95
		wf_init($scope, $http, $sce);
96
		
97
		$scope.availableRepohiWfs = getAvailableRepohiWfs();
98
		$scope.compatibilityLevels = getCompatibilityLevels();
99
		
100
		$scope.validatorBlacklistAddress = '';
101
		$scope.validatorBlacklistAddress = '';
102
    			
103
		$scope.currentRepoApi = {};
104
		$scope.currentSets = [];
105
		$scope.selectedSets = [];
106
		
107
		$scope.newSyncApi = {};
108
    	
109
    	$scope.loadApi = function() {
110
    		$scope.showSpinner();
111
    		$(".btnRefreshApi").attr("disabled", "disabled");
112
    		$http.get('repoApi.get?repoId=' + $routeParams.repoId + "&ifaceId=" +  $routeParams.ifaceId)
113
            .success(
114
                function(data) {
115
                	$scope.currentRepoApi = data;
116
                	$scope.metaworkflows = data.metaWFs;
117

    
118
                	angular.forEach(data.otherParams, function(term){
119
                		if (term.id == 'last_validation_job') {
120
                			if (getValidatorAddress()) {
121
                				$scope.validatorDetailsAddress = getValidatorAddress() + "/" + term.value;
122
                			}
123
                			if (getValidatorServiceAddress()) {
124
                				$scope.validatorBlacklistAddress = getValidatorServiceAddress() + "/workflows?request=GetBlacklistedRecords&datasourceId=" + $routeParams.repoId;
125
                			}
126
                		}                                       
127
                	});
128
                	
129
                	if (data.protocol == 'oai') {
130
    	            	var found = false;
131
    	            	angular.forEach(data.accessParams, function(param, pos){
132
    	                    if (param.name == 'set') {
133
    	                    	$scope.listSets($scope.currentRepoApi.accessParams);
134
    	                    }
135
    	        		});
136
                	}
137
                	$scope.hideSpinner(); 
138
                	            	
139
                	$(".btnRefreshApi").removeAttr("disabled");
140
                	
141
                	if ($routeParams.metawf != 'ALL' && $routeParams.wf != 'ALL') {
142
                		$scope.getAtomicWorkflowAndMetaWf($routeParams.metawf, $routeParams.wf);
143
                		$timeout(function() {
144
                			$("#collapse_" + $routeParams.metawf.substring(0, 36)).collapse('show');
145
                		}, 2000);
146
                	}
147
                }
148
            ).error(
149
                function() {
150
                	$scope.showError('Something really bad must have happened to our fellow hamster..');
151
                	$scope.hideSpinner();
152
                }
153
            );
154
    	};
155
    	
156
    	
157
    	$scope.removeApi = function() {
158
    		if (confirm("You are deleting the current API.\n\nAre you sure?")) {
159
	    		$scope.showSpinner();
160
	    		$http.get('repoApi.delete?repo=' + $routeParams.repoId + "&iface=" +  $routeParams.ifaceId).success(function(data) {
161
	    			alert("The API has been deleted !!!");
162
	    			$scope.hideSpinner();
163
	    			$scope.go("/browse");
164
	    		}).error(function(err) {
165
	    			$scope.showError('Error removing API: '  + err.message);
166
	    			$scope.hideSpinner();
167
	    		});
168
    		}
169
    	};
170
   	
171
    	
172
		$scope.newDataProviderWorkflow = function (wf) {
173
			
174
			if (wf == undefined) {
175
				$scope.showError('Please choose a workflow !');
176
	    		return;
177
			}
178
			
179
			$scope.showSpinner();
180
	
181
			$scope.metaworkflows.push({"id":"","name":"Waiting...","status":"MISSING","progress":0});
182
	    				
183
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
184
			$http.post('repoMetaWf.new', $.param({
185
				'wf'    : wf,
186
				'iface' : $scope.currentRepoApi.id,
187
				'id'    : $scope.currentRepoApi.repoId, 
188
				'name'  : $scope.currentRepoApi.repoName
189
			})).success(
190
	       			function(data) {
191
	       				$scope.hideSpinner();
192
	       				$(".btnRefreshApi").attr("disabled", "disabled");
193
	       				$timeout(function () { $scope.loadApi() }, 7000);
194
		            }
195
	       	).error(
196
	       			function() {
197
	       				$scope.showError('Something really bad must have happened to our fellow hamster..');
198
	       				$scope.hideSpinner();
199
		           }
200
	       	);
201
		};
202
		
203
		$scope.destroyDataProviderWorkflow = function (metaWf) {
204
			
205
			if (metaWf.destroyWorkflow == undefined) {
206
				$scope.showError('Destroy wf is missing !');
207
	    		return;
208
			}
209
			
210
			if (!confirm("Are you sure ?")) {
211
				return;
212
			}
213
					
214
			$scope.showSpinner();
215
			
216
			metaWf.deleting = true;
217
			
218
			$http.get('repoMetaWf.destroy?destroyWf=' + metaWf.destroyWorkflow)
219
	       	.success(
220
	       			function(data) {
221
	       				$scope.hideSpinner();
222
	       				$(".btnRefreshApi").attr("disabled", "disabled");
223
	       				$timeout(function () { $scope.loadApi() }, 7000);
224
		            }
225
	       	).error(
226
	       			function() {
227
	       				$scope.showError('Something really bad must have happened to our fellow hamster..');
228
	       				$scope.hideSpinner();
229
		           }
230
	       	);
231
		};
232
		
233
		$scope.testOAI = function (params) {
234
			angular.forEach(params, function(param, pos){
235
	            if (param.name == 'baseUrl') {
236
	            	location.href = "oaiExplorer.do?oaiBaseUrl=" + param.value;
237
	            }
238
			});
239
		}
240
	
241
		$scope.prepareUpdateRepoApi = function() {
242
			$scope.tempAccessParams = angular.copy($scope.currentRepoApi.accessParams); 
243

    
244
			$scope.tempMdIdPath = '';
245
			angular.forEach($scope.currentRepoApi.otherParams, function(param, pos){
246
	            if (param.name == 'metadata_identifier_path') {
247
	            	$scope.tempMdIdPath = param.value;
248
	            }
249
			});
250
		}
251
		
252
		
253
		$scope.updateRepoApi = function() {
254
			$scope.showSpinner();
255
	
256
			var map = {};
257
			angular.forEach($scope.tempAccessParams, function(param, pos){
258
	            if (param.name) {
259
	            	map[param.name] = param.value
260
	            }
261
			});
262
			
263
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
264
	        $http.post('repoApi.update', $.param({
265
	      		'id'           : $scope.currentRepoApi.repoId,
266
	      		'iface'        : $scope.currentRepoApi.id,
267
	      		'mdIdPath'     : $scope.tempMdIdPath,
268
	      		'accessParams' : JSON.stringify(map)
269
	      	})).success(function(data) {
270
	      		$scope.showNotification('Api correctly saved !');
271
	        	$scope.loadApi(); 
272
	        }).error(function(err) {
273
	        	$scope.hideSpinner();
274
	        	$scope.showError('Error updating api: ' + err.message);
275
	        });
276
		};
277
		
278
		
279
		$scope.updateSets = function(selection, accessParams) {
280
			var s = selection.join();
281
			angular.forEach(accessParams, function(param, pos){
282
	            if (param.name == 'set') {
283
	            	param.value = s;
284
	            }
285
			});
286
		}
287
		
288
		$scope.listSets = function(accessParams) {
289
			var baseUrl = '';
290
			
291
			$scope.selectedSets = [];
292
			$scope.currentSets = [];
293
			
294
			angular.forEach(accessParams, function(param, pos){
295
	            if (param.name == 'baseUrl') {
296
	            	baseUrl = param.value
297
	            }
298
	            if (param.name == 'set') {
299
	            	$scope.selectedSets = param.value.split(",");
300
	            }
301
			});
302
			
303
			if (!baseUrl) {
304
				$scope.showError("baseUrl param is missing");
305
				return;
306
			}
307

    
308
			$scope.showSpinner();
309
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
310
	        $http.post("listValidValuesForParam.do", $.param({
311
	        	'protocol' : 'oai',
312
	        	'param'    : 'set',
313
	        	'baseUrl'  : baseUrl
314
	        })).success(function(data) {
315
				$scope.hideSpinner();
316
	        	$scope.currentSets = data;
317
	        	angular.forEach($scope.currentSets, function(curr, pos1) {
318
		        	angular.forEach($scope.selectedSets, function(sel, pos2) {
319
		        		if (curr.id.trim() == sel.trim()) {
320
		        			curr.selected = true;
321
		        		}
322
		        	});
323
				});
324
	        }).error(function(err) {
325
				$scope.hideSpinner();
326
				$scope.showError(err.message);
327
			});
328
	        
329
		};
330
		
331
		
332
		$scope.verifyMetaWf = function(ds, wf) {
333
			var compliance = '';
334
			var type = '';
335
			angular.forEach(ds.commonParams, function(p,pos) {
336
	        	if (p.id == 'compliance') {
337
	        		compliance = p.value;
338
	        	}
339
	        	if (p.id == 'typology') {
340
	        		type = p.value;
341
	        	}
342
			});
343
			
344
			return (compliance && type && $scope.isValidTerm(compliance, wf.compliances) && $scope.isValidTerm(type, wf.ifaceTypes)); 
345
		}
346

    
347
		$scope.isValidTerm = function(term, list) {
348
			
349
			if (list.length == 0) {
350
				return true;
351
			}
352
			var res = false;
353
			angular.forEach(list, function(curr,pos) {
354
	        	if (term.lastIndexOf(curr, 0) === 0) { // implementation of term.startsWith(curr)
355
	        		res = true;
356
	        	}
357
			});
358
			return res;
359
		}
360

    
361
		$scope.overrideApiCompliance = function(level) {
362
			$scope.showSpinner();
363
			$http.get('repoApiCompliance.update?id=' + $scope.currentRepoApi.repoId + '&iface=' + $scope.currentRepoApi.id + '&compliance=' + level)
364
	        .success(
365
	        		function(data) {
366
	        			$scope.hideSpinner();
367
	        			$scope.showNotification('Api correctly updated !');
368
	        			$scope.loadApi(); 
369
	        		}
370
	        ).error(
371
	        		function() {
372
	        			$scope.showError('Something really bad must have happened to our fellow hamster..');
373
	        			$scope.hideSpinner();
374
	        		}
375
	        );
376
		}
377
		
378
		$scope.resetApiCompliance = function() {
379
			$scope.showSpinner();
380
			$http.get('repoApiCompliance.reset?id=' + $scope.currentRepoApi.repoId + '&iface=' + $scope.currentRepoApi.id)
381
	        .success(
382
	        		function(data) {
383
	        			$scope.hideSpinner();
384
	        			$scope.showNotification('Api correctly updated !');
385
	        			$scope.loadApi(); 
386
	        		}
387
	        ).error(
388
	        		function() {
389
	        			$scope.showError('Something really bad must have happened to our fellow hamster..');
390
	        			$scope.hideSpinner();
391
	        		}
392
	        );
393
		}
394
		
395
		$scope.showCreateRemoteSyncApi = function(mongoUrl, mongoDB, mdId, apiSuffix) {
396
			
397
			var path = "//*[local-name()='header']/*[local-name()='identifier']";
398
			angular.forEach($scope.currentRepoApi.otherParams, function(p) {
399
				if (p.id=='metadata_identifier_path') {
400
					path = p.value;
401
				}
402
			});
403
			
404
			var compliance = "UNKNOWN";
405
			angular.forEach($scope.currentRepoApi.commonParams, function(p) {
406
				if (p.id=='compliance') {
407
					compliance = p.value;
408
				}
409
			});
410
			
411
			$scope.newSyncApi = {
412
				'dsId'  : $routeParams.repoId,
413
				'apiId' : 'api_________::' + $routeParams.repoId + "::" + apiSuffix,
414
				'compatibility' : compliance,
415
				'contentdescription' : 'metadata',
416
				'protocol' : 'remoteMdstore',
417
				'baseurl'  : mongoUrl,
418
				'apiParams' : {
419
					'remote_database'   : mongoDB,
420
					'remote_mdstore_id' : mdId
421
				},
422
				'metadataIdentifierPath' : path
423
			};
424
			
425
			$('#remoteSyncApiModal').modal('show');
426
			
427
		}
428
				
429
    	$scope.loadApi();
430
	}
431
		
432
 ]);
433

    
(3-3/7)