Index: modules/dnet-modular-repositories-ui/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/repositories/RepoInternalController.java
===================================================================
--- modules/dnet-modular-repositories-ui/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/repositories/RepoInternalController.java	(revision 58379)
+++ modules/dnet-modular-repositories-ui/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/repositories/RepoInternalController.java	(revision 58380)
@@ -1,8 +1,8 @@
 package eu.dnetlib.functionality.modular.ui.repositories;
 
+import java.io.IOException;
 import java.io.StringReader;
 import java.util.Date;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -29,6 +29,7 @@
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.client.RestTemplate;
 
 import com.google.common.collect.Maps;
 import com.google.gson.Gson;
@@ -77,12 +78,18 @@
 	@Resource
 	private RepoUIUtils repoUIUtils;
 
+	@Value("${repo.ui.mdstore.sync.button}")
+	private String syncButton;
+
 	@Value("${repo.ui.mdstore.sync.desc}")
-	private String syncDescription;
+	private String syncDesc;
 
-	@Value("${repo.ui.mdstore.sync.baseUrl}")
-	private String syncApi;
+	@Value("${repo.ui.mdstore.sync.api.baseUrl}")
+	private String syncApiBaseUrl;
 
+	@Value("${repo.ui.mdstore.sync.is.baseUrl}")
+	private String syncISBaseUrl;
+
 	@Value("${services.mdstore.mongodb.db}")
 	private String mongoDb;
 
@@ -234,8 +241,10 @@
 
 	@RequestMapping("/ui/repos/repoApi.html")
 	public void repoApiHtml(final ModelMap map) throws Exception {
-		if (StringUtils.isNoneBlank(syncDescription, syncApi)) {
-			map.addAttribute("syncDesc", syncDescription);
+		if (StringUtils.isNoneBlank(syncButton, syncDesc, syncApiBaseUrl, syncISBaseUrl)) {
+			map.addAttribute("syncButton", syncButton);
+			map.addAttribute("syncDesc", syncDesc);
+			map.addAttribute("syncISBaseUrl", syncISBaseUrl);
 			map.addAttribute("mongoDB", mongoDb);
 			map.addAttribute("mongoUrl", String.format("mongodb://%s:%s", mongoHost, mongoPort));
 		}
@@ -282,16 +291,35 @@
 	}
 
 	@RequestMapping(value = "/ui/remoteDatasource/apis", method = RequestMethod.GET)
-	public @ResponseBody Map<String, String> listRemoteApis(@RequestParam(value = "repo", required = true) final String repoId) {
-		// TODO
-		return new HashMap<>();
+	public void listRemoteApis(@RequestParam(value = "repo", required = true) final String repoId,
+			final HttpServletResponse response) throws IOException {
+
+		final RestTemplate restTemplate = new RestTemplate();
+
+		final String res = restTemplate.getForObject(syncApiBaseUrl + "/ds/api/" + repoId, String.class);
+
+		response.setContentType("application/json;charset=UTF-8");
+
+		IOUtils.write(res, response.getOutputStream());
 	}
 
 	@RequestMapping(value = "/ui/remoteDatasource/api", method = RequestMethod.POST)
-	public @ResponseBody Map<String, String> listRemoteApis(@RequestParam(value = "repo", required = true) final String repoId,
-			@RequestBody final Api<ApiParam> api) {
-		// TODO
-		return new HashMap<>();
+	public void saveRemoteApi(@RequestBody final Api<ApiParamImpl> api, final HttpServletResponse response) throws IOException {
+
+		final String url = syncApiBaseUrl + "/ds/api/add";
+
+		log.info("Adding new remote API:");
+		log.info(" - repo id: " + api.getDatasource());
+		log.info(" - api id: " + api.getId());
+		log.info(" - rest call: " + url);
+
+		final RestTemplate restTemplate = new RestTemplate();
+
+		final String res = restTemplate.postForObject(url, api, String.class);
+
+		response.setContentType("application/json;charset=UTF-8");
+
+		IOUtils.write(res, response.getOutputStream());
 	}
 
 	@ExceptionHandler(Exception.class)
Index: modules/dnet-modular-repositories-ui/trunk/src/main/resources/eu/dnetlib/functionality/modular/ui/repositories/applicationContext-modular-ui-repositories.properties
===================================================================
--- modules/dnet-modular-repositories-ui/trunk/src/main/resources/eu/dnetlib/functionality/modular/ui/repositories/applicationContext-modular-ui-repositories.properties	(revision 58379)
+++ modules/dnet-modular-repositories-ui/trunk/src/main/resources/eu/dnetlib/functionality/modular/ui/repositories/applicationContext-modular-ui-repositories.properties	(revision 58380)
@@ -9,5 +9,8 @@
 repo.ui.validator.address               = http://dev.openaire.research-infrastructures.eu:8880/validator/compatibility/browseHistory
 repo.ui.validatorService.address        = http://dev.openaire.research-infrastructures.eu:8880/validator-service
 
-repo.ui.mdstore.sync.desc               = sync with beta
-repo.ui.mdstore.sync.baseUrl            = http://xxxxxx
\ No newline at end of file
+
+repo.ui.mdstore.sync.button             = sync with DEV
+repo.ui.mdstore.sync.desc               = OpenAIRE DEV Infrastructure
+repo.ui.mdstore.sync.api.baseUrl        = https://dev-openaire.d4science.org/openaire
+repo.ui.mdstore.sync.is.baseUrl         = https://dev-openaire.d4science.org/is
Index: modules/dnet-modular-repositories-ui/trunk/src/main/resources/eu/dnetlib/functionality/modular/ui/views/ui/repos/repoApi.st
===================================================================
--- modules/dnet-modular-repositories-ui/trunk/src/main/resources/eu/dnetlib/functionality/modular/ui/views/ui/repos/repoApi.st	(revision 58379)
+++ modules/dnet-modular-repositories-ui/trunk/src/main/resources/eu/dnetlib/functionality/modular/ui/views/ui/repos/repoApi.st	(revision 58380)
@@ -82,8 +82,8 @@
 			
 		<div class="input-group input-group-sm col-xs-12 col-md-6" style="padding: 10px; float: left;">
 	  		<span class="input-group-addon" style="width: 150px;"><b>Last aggregation</b></span>
-	  		<ng-api-mdstore-info label="Collect" date="currentRepoApi.collDate" total="currentRepoApi.collTotal" id="currentRepoApi.collMdId" sync-description="$syncDesc$" sync-function="showCreateRemoteSyncApi('$mongoUrl$','$mongoDB$',currentRepoApi.collMdId, 'remoteCollectedMdStore')"></ng-api-mdstore-info>	  		
-	  		<ng-api-mdstore-info label="Transform" date="currentRepoApi.aggrDate" total="currentRepoApi.aggrTotal" id="currentRepoApi.aggrMdId" sync-description="$syncDesc$" sync-function="showCreateRemoteSyncApi('$mongoUrl$','$mongoDB$',currentRepoApi.aggrMdId, 'remoteAggregatedMdStore')"></ng-api-mdstore-info>
+	  		<ng-api-mdstore-info label="Collect" date="currentRepoApi.collDate" total="currentRepoApi.collTotal" id="currentRepoApi.collMdId"   sync-button-label="$syncButton$" sync-function="showCreateRemoteSyncApi('$mongoUrl$','$mongoDB$',currentRepoApi.collMdId, 'remoteCollectedMdStore')"></ng-api-mdstore-info>	  		
+	  		<ng-api-mdstore-info label="Transform" date="currentRepoApi.aggrDate" total="currentRepoApi.aggrTotal" id="currentRepoApi.aggrMdId" sync-button-label="$syncButton$" sync-function="showCreateRemoteSyncApi('$mongoUrl$','$mongoDB$',currentRepoApi.aggrMdId, 'remoteAggregatedMdStore')"></ng-api-mdstore-info>
 	  		<ng-api-objectstore-info label="Download" date="currentRepoApi.downloadDate" total="currentRepoApi.downloadTotal" id="currentRepoApi.downloadObjId"></ng-api-objectstore-info>
 		</div>		
 		
@@ -241,20 +241,42 @@
 	</div>
 </div>
 
-<div id="remoteSyncApiModal" class="modal fade" tabindex="-1" role="dialog">
+
+<div id="showRemoteSyncApiModal" class="modal fade" tabindex="-1" role="dialog">
 	<div class="modal-dialog modal-lg">
 		<div class="modal-content">
 			<div class="modal-header">
 				<button type="button" class="close" data-dismiss="modal">&times;</button>
+				<h4 class="modal-title">Remote API</h4>
+			</div>
+			<div class="modal-body">
+				The following API has been already registered on
+				<a href="$syncISBaseUrl$/mvc/ui/repoApis.do#/api/{{syncApi.datasource}}/{{syncApi.id}}/ALL/ALL" target="_blank">
+					 $syncDesc$
+				</a>
+			</div>
+			<div class="modal-footer">
+				<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
+			</div>
+		</div>
+	</div>
+</div>
+
+
+<div id="newRemoteSyncApiModal" class="modal fade" tabindex="-1" role="dialog">
+	<div class="modal-dialog modal-lg">
+		<div class="modal-content">
+			<div class="modal-header">
+				<button type="button" class="close" data-dismiss="modal">&times;</button>
 				<h4 class="modal-title">Create remote API</h4>
 			</div>
 			<div class="modal-body">
-				The following API will be created on ...:
+				The following API will be created on <b>$syncDesc$</b>:
 				<br /><br />
-				<pre>{{newSyncApi | json}}</pre>
+				<pre>{{syncApi | json}}</pre>
 			</div>
 			<div class="modal-footer">
-				<button type="button" class="btn btn-primary" data-dismiss="modal">Confirm</button>
+				<button type="button" class="btn btn-primary" ng-click="createRemoteSyncApi(syncApi)">Confirm</button>
 				<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
 			</div>
 		</div>
Index: modules/dnet-modular-repositories-ui/trunk/src/main/resources/eu/dnetlib/web/resources/html/ngApiMdstoreInfo.html
===================================================================
--- modules/dnet-modular-repositories-ui/trunk/src/main/resources/eu/dnetlib/web/resources/html/ngApiMdstoreInfo.html	(revision 58379)
+++ modules/dnet-modular-repositories-ui/trunk/src/main/resources/eu/dnetlib/web/resources/html/ngApiMdstoreInfo.html	(revision 58380)
@@ -1,4 +1,4 @@
-<div class="input-group">
+<div ng-class="{'input-group': id && syncButtonLabel}">
 	<div class="form-control">
 		<b>{{label}}:</b>
 		<span ng-show="date">
@@ -16,7 +16,7 @@
 			</a>
 		</span>
 	</div>
-	<span class="input-group-btn" ng-if="id && syncDescription">
-		<button class="btn btn-default" ng-click="syncFunction()">{{syncDescription}}</button>
+	<span class="input-group-btn" ng-if="id && syncButtonLabel">
+		<button class="btn btn-default" ng-click="syncFunction()">{{syncButtonLabel}}</button>
 	</span>
 </div>
\ No newline at end of file
Index: modules/dnet-modular-repositories-ui/trunk/src/main/resources/eu/dnetlib/web/resources/js/repos.js
===================================================================
--- modules/dnet-modular-repositories-ui/trunk/src/main/resources/eu/dnetlib/web/resources/js/repos.js	(revision 58379)
+++ modules/dnet-modular-repositories-ui/trunk/src/main/resources/eu/dnetlib/web/resources/js/repos.js	(revision 58380)
@@ -21,7 +21,7 @@
 			'date'  : '=',
 			'total' : '=',
 			'id'    : '=',
-			'syncDescription' : '@',
+			'syncButtonLabel' : '@',
 			'syncFunction'    : '&',
 		},
 		templateUrl: '../resources/html/ngApiMdstoreInfo.html'
Index: modules/dnet-modular-repositories-ui/trunk/src/main/resources/eu/dnetlib/web/resources/js/repoControllers.js
===================================================================
--- modules/dnet-modular-repositories-ui/trunk/src/main/resources/eu/dnetlib/web/resources/js/repoControllers.js	(revision 58379)
+++ modules/dnet-modular-repositories-ui/trunk/src/main/resources/eu/dnetlib/web/resources/js/repoControllers.js	(revision 58380)
@@ -5,16 +5,16 @@
 	function ($scope, $http, $timeout, $sce, $location) {
 		common_init($scope, $http, $sce, $location);
 		$scope.repoBrowseFields = getBrowseFields();
-		
+
 		$scope.sortType     = 'term';
 		$scope.sortReverse  = false;
-		
+
 		$scope.repoBrowseData = { 'data' : [] };
-			
+
 		$scope.searchApis = function (text) {
 			$scope.go('/list/__SEARCH__/' + text); 
 		} 
-		
+
 		$scope.browseApis = function (field, value) {
 			$('#showRepoBrowseData').modal('hide');
 			$scope.showSpinner();
@@ -22,29 +22,29 @@
 				$scope.go('/list/' + field + '/' + value);
 			}, 1500);
 		}
-		
+
 		$scope.browseRepoField = function(field) {
 			$scope.repoBrowseData = {
-				'label' : field.label,
-				'id' :    field.id,
-				'data'  : []
+					'label' : field.label,
+					'id' :    field.id,
+					'data'  : []
 			};
 			$scope.showSpinner();
-	      	$http.get('browseRepoField.do?field=' + field.id).success(
-	            function(data) {
-	            	$scope.hideSpinner();
-	            	$scope.repoBrowseData.data = data;
-	            	$('#showRepoBrowseData').modal('show');
-	            }
-	        ).error(
-	            function() {
-	            	$scope.showError('Something really bad must have happened to our fellow hamster..');
-	            	$scope.hideSpinner();
-	            }
-	        );
+			$http.get('browseRepoField.do?field=' + field.id).success(
+					function(data) {
+						$scope.hideSpinner();
+						$scope.repoBrowseData.data = data;
+						$('#showRepoBrowseData').modal('show');
+					}
+			).error(
+					function() {
+						$scope.showError('Something really bad must have happened to our fellow hamster..');
+						$scope.hideSpinner();
+					}
+			);
 		};
 	}
-]);
+	]);
 
 repoControllers.controller('repoListCtrl', [
 	'$scope', '$http', '$timeout', '$sce', '$routeParams', '$location',
@@ -54,15 +54,15 @@
 		$scope.sortType     = 'repoName';
 		$scope.sortReverse  = false;
 		$scope.apis = [];		
-    	$scope.currentApiSelectionParam = $routeParams.param;
-    	$scope.currentApiSelectionValue = $routeParams.value;
-    	
-    	$scope.updateApis = function(refresh) {
+		$scope.currentApiSelectionParam = $routeParams.param;
+		$scope.currentApiSelectionValue = $routeParams.value;
+
+		$scope.updateApis = function(refresh) {
 			$scope.showSpinner();
-						    
+
 			var params = {
-				'param' : $scope.currentApiSelectionParam,
-				'value' : $scope.currentApiSelectionValue
+					'param' : $scope.currentApiSelectionParam,
+					'value' : $scope.currentApiSelectionValue
 			};
 			if (refresh) {
 				params.refresh = 1;
@@ -70,116 +70,116 @@
 
 			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
 			$http.post('listApis.do', $.param(params)).success(
-	            function(data) {
-	            	$scope.hideSpinner();
-	            	$scope.apis = data;
-	            }
-	        ).error(
-	            function() {
-	            	$scope.showError('Something really bad must have happened to our fellow hamster..');
-	            	$scope.hideSpinner();
-	            }
-	        );
-    	};
-        	
-    	$scope.updateApis(false);
+					function(data) {
+						$scope.hideSpinner();
+						$scope.apis = data;
+					}
+			).error(
+					function() {
+						$scope.showError('Something really bad must have happened to our fellow hamster..');
+						$scope.hideSpinner();
+					}
+			);
+		};
+
+		$scope.updateApis(false);
 	}
-]);
+	]);
 
 repoControllers.controller('repoApiCtrl', [
 	'$scope', '$http', '$timeout', '$sce', '$routeParams', '$location',
 	function ($scope, $http, $timeout, $sce, $routeParams, $location) {
 		common_init($scope, $http, $sce, $location);
-		
+
 		commonInitialize($scope, $http, $sce);
 		wf_init($scope, $http, $sce);
-		
+
 		$scope.availableRepohiWfs = getAvailableRepohiWfs();
 		$scope.compatibilityLevels = getCompatibilityLevels();
-		
+
 		$scope.validatorBlacklistAddress = '';
 		$scope.validatorBlacklistAddress = '';
-    			
+
 		$scope.currentRepoApi = {};
 		$scope.currentSets = [];
 		$scope.selectedSets = [];
-		
-		$scope.newSyncApi = {};
-    	
-    	$scope.loadApi = function() {
-    		$scope.showSpinner();
-    		$(".btnRefreshApi").attr("disabled", "disabled");
-    		$http.get('repoApi.get?repoId=' + $routeParams.repoId + "&ifaceId=" +  $routeParams.ifaceId)
-            .success(
-                function(data) {
-                	$scope.currentRepoApi = data;
-                	$scope.metaworkflows = data.metaWFs;
 
-                	angular.forEach(data.otherParams, function(term){
-                		if (term.id == 'last_validation_job') {
-                			if (getValidatorAddress()) {
-                				$scope.validatorDetailsAddress = getValidatorAddress() + "/" + term.value;
-                			}
-                			if (getValidatorServiceAddress()) {
-                				$scope.validatorBlacklistAddress = getValidatorServiceAddress() + "/workflows?request=GetBlacklistedRecords&datasourceId=" + $routeParams.repoId;
-                			}
-                		}                                       
-                	});
-                	
-                	if (data.protocol == 'oai') {
-    	            	var found = false;
-    	            	angular.forEach(data.accessParams, function(param, pos){
-    	                    if (param.name == 'set') {
-    	                    	$scope.listSets($scope.currentRepoApi.accessParams);
-    	                    }
-    	        		});
-                	}
-                	$scope.hideSpinner(); 
-                	            	
-                	$(".btnRefreshApi").removeAttr("disabled");
-                	
-                	if ($routeParams.metawf != 'ALL' && $routeParams.wf != 'ALL') {
-                		$scope.getAtomicWorkflowAndMetaWf($routeParams.metawf, $routeParams.wf);
-                		$timeout(function() {
-                			$("#collapse_" + $routeParams.metawf.substring(0, 36)).collapse('show');
-                		}, 2000);
-                	}
-                }
-            ).error(
-                function() {
-                	$scope.showError('Something really bad must have happened to our fellow hamster..');
-                	$scope.hideSpinner();
-                }
-            );
-    	};
-    	
-    	
-    	$scope.removeApi = function() {
-    		if (confirm("You are deleting the current API.\n\nAre you sure?")) {
-	    		$scope.showSpinner();
-	    		$http.get('repoApi.delete?repo=' + $routeParams.repoId + "&iface=" +  $routeParams.ifaceId).success(function(data) {
-	    			alert("The API has been deleted !!!");
-	    			$scope.hideSpinner();
-	    			$scope.go("/browse");
-	    		}).error(function(err) {
-	    			$scope.showError('Error removing API: '  + err.message);
-	    			$scope.hideSpinner();
-	    		});
-    		}
-    	};
-   	
-    	
+		$scope.syncApi = {};
+
+		$scope.loadApi = function() {
+			$scope.showSpinner();
+			$(".btnRefreshApi").attr("disabled", "disabled");
+			$http.get('repoApi.get?repoId=' + $routeParams.repoId + "&ifaceId=" +  $routeParams.ifaceId)
+			.success(
+					function(data) {
+						$scope.currentRepoApi = data;
+						$scope.metaworkflows = data.metaWFs;
+
+						angular.forEach(data.otherParams, function(term){
+							if (term.id == 'last_validation_job') {
+								if (getValidatorAddress()) {
+									$scope.validatorDetailsAddress = getValidatorAddress() + "/" + term.value;
+								}
+								if (getValidatorServiceAddress()) {
+									$scope.validatorBlacklistAddress = getValidatorServiceAddress() + "/workflows?request=GetBlacklistedRecords&datasourceId=" + $routeParams.repoId;
+								}
+							}                                       
+						});
+
+						if (data.protocol == 'oai') {
+							var found = false;
+							angular.forEach(data.accessParams, function(param, pos){
+								if (param.name == 'set') {
+									$scope.listSets($scope.currentRepoApi.accessParams);
+								}
+							});
+						}
+						$scope.hideSpinner(); 
+
+						$(".btnRefreshApi").removeAttr("disabled");
+
+						if ($routeParams.metawf != 'ALL' && $routeParams.wf != 'ALL') {
+							$scope.getAtomicWorkflowAndMetaWf($routeParams.metawf, $routeParams.wf);
+							$timeout(function() {
+								$("#collapse_" + $routeParams.metawf.substring(0, 36)).collapse('show');
+							}, 2000);
+						}
+					}
+			).error(
+					function() {
+						$scope.showError('Something really bad must have happened to our fellow hamster..');
+						$scope.hideSpinner();
+					}
+			);
+		};
+
+
+		$scope.removeApi = function() {
+			if (confirm("You are deleting the current API.\n\nAre you sure?")) {
+				$scope.showSpinner();
+				$http.get('repoApi.delete?repo=' + $routeParams.repoId + "&iface=" +  $routeParams.ifaceId).success(function(data) {
+					alert("The API has been deleted !!!");
+					$scope.hideSpinner();
+					$scope.go("/browse");
+				}).error(function(err) {
+					$scope.showError('Error removing API: '  + err.message);
+					$scope.hideSpinner();
+				});
+			}
+		};
+
+
 		$scope.newDataProviderWorkflow = function (wf) {
-			
+
 			if (wf == undefined) {
 				$scope.showError('Please choose a workflow !');
-	    		return;
+				return;
 			}
-			
+
 			$scope.showSpinner();
-	
+
 			$scope.metaworkflows.push({"id":"","name":"Waiting...","status":"MISSING","progress":0});
-	    				
+
 			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
 			$http.post('repoMetaWf.new', $.param({
 				'wf'    : wf,
@@ -187,119 +187,119 @@
 				'id'    : $scope.currentRepoApi.repoId, 
 				'name'  : $scope.currentRepoApi.repoName
 			})).success(
-	       			function(data) {
-	       				$scope.hideSpinner();
-	       				$(".btnRefreshApi").attr("disabled", "disabled");
-	       				$timeout(function () { $scope.loadApi() }, 7000);
-		            }
-	       	).error(
-	       			function() {
-	       				$scope.showError('Something really bad must have happened to our fellow hamster..');
-	       				$scope.hideSpinner();
-		           }
-	       	);
+					function(data) {
+						$scope.hideSpinner();
+						$(".btnRefreshApi").attr("disabled", "disabled");
+						$timeout(function () { $scope.loadApi() }, 7000);
+					}
+			).error(
+					function() {
+						$scope.showError('Something really bad must have happened to our fellow hamster..');
+						$scope.hideSpinner();
+					}
+			);
 		};
-		
+
 		$scope.destroyDataProviderWorkflow = function (metaWf) {
-			
+
 			if (metaWf.destroyWorkflow == undefined) {
 				$scope.showError('Destroy wf is missing !');
-	    		return;
+				return;
 			}
-			
+
 			if (!confirm("Are you sure ?")) {
 				return;
 			}
-					
+
 			$scope.showSpinner();
-			
+
 			metaWf.deleting = true;
-			
+
 			$http.get('repoMetaWf.destroy?destroyWf=' + metaWf.destroyWorkflow)
-	       	.success(
-	       			function(data) {
-	       				$scope.hideSpinner();
-	       				$(".btnRefreshApi").attr("disabled", "disabled");
-	       				$timeout(function () { $scope.loadApi() }, 7000);
-		            }
-	       	).error(
-	       			function() {
-	       				$scope.showError('Something really bad must have happened to our fellow hamster..');
-	       				$scope.hideSpinner();
-		           }
-	       	);
+			.success(
+					function(data) {
+						$scope.hideSpinner();
+						$(".btnRefreshApi").attr("disabled", "disabled");
+						$timeout(function () { $scope.loadApi() }, 7000);
+					}
+			).error(
+					function() {
+						$scope.showError('Something really bad must have happened to our fellow hamster..');
+						$scope.hideSpinner();
+					}
+			);
 		};
-		
+
 		$scope.testOAI = function (params) {
 			angular.forEach(params, function(param, pos){
-	            if (param.name == 'baseUrl') {
-	            	location.href = "oaiExplorer.do?oaiBaseUrl=" + param.value;
-	            }
+				if (param.name == 'baseUrl') {
+					location.href = "oaiExplorer.do?oaiBaseUrl=" + param.value;
+				}
 			});
 		}
-	
+
 		$scope.prepareUpdateRepoApi = function() {
 			$scope.tempAccessParams = angular.copy($scope.currentRepoApi.accessParams); 
 
 			$scope.tempMdIdPath = '';
 			angular.forEach($scope.currentRepoApi.otherParams, function(param, pos){
-	            if (param.name == 'metadata_identifier_path') {
-	            	$scope.tempMdIdPath = param.value;
-	            }
+				if (param.name == 'metadata_identifier_path') {
+					$scope.tempMdIdPath = param.value;
+				}
 			});
 		}
-		
-		
+
+
 		$scope.updateRepoApi = function() {
 			$scope.showSpinner();
-	
+
 			var map = {};
 			angular.forEach($scope.tempAccessParams, function(param, pos){
-	            if (param.name) {
-	            	map[param.name] = param.value
-	            }
+				if (param.name) {
+					map[param.name] = param.value
+				}
 			});
-			
+
 			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
-	        $http.post('repoApi.update', $.param({
-	      		'id'           : $scope.currentRepoApi.repoId,
-	      		'iface'        : $scope.currentRepoApi.id,
-	      		'mdIdPath'     : $scope.tempMdIdPath,
-	      		'accessParams' : JSON.stringify(map)
-	      	})).success(function(data) {
-	      		$scope.showNotification('Api correctly saved !');
-	        	$scope.loadApi(); 
-	        }).error(function(err) {
-	        	$scope.hideSpinner();
-	        	$scope.showError('Error updating api: ' + err.message);
-	        });
+			$http.post('repoApi.update', $.param({
+				'id'           : $scope.currentRepoApi.repoId,
+				'iface'        : $scope.currentRepoApi.id,
+				'mdIdPath'     : $scope.tempMdIdPath,
+				'accessParams' : JSON.stringify(map)
+			})).success(function(data) {
+				$scope.showNotification('Api correctly saved !');
+				$scope.loadApi(); 
+			}).error(function(err) {
+				$scope.hideSpinner();
+				$scope.showError('Error updating api: ' + err.message);
+			});
 		};
-		
-		
+
+
 		$scope.updateSets = function(selection, accessParams) {
 			var s = selection.join();
 			angular.forEach(accessParams, function(param, pos){
-	            if (param.name == 'set') {
-	            	param.value = s;
-	            }
+				if (param.name == 'set') {
+					param.value = s;
+				}
 			});
 		}
-		
+
 		$scope.listSets = function(accessParams) {
 			var baseUrl = '';
-			
+
 			$scope.selectedSets = [];
 			$scope.currentSets = [];
-			
+
 			angular.forEach(accessParams, function(param, pos){
-	            if (param.name == 'baseUrl') {
-	            	baseUrl = param.value
-	            }
-	            if (param.name == 'set') {
-	            	$scope.selectedSets = param.value.split(",");
-	            }
+				if (param.name == 'baseUrl') {
+					baseUrl = param.value
+				}
+				if (param.name == 'set') {
+					$scope.selectedSets = param.value.split(",");
+				}
 			});
-			
+
 			if (!baseUrl) {
 				$scope.showError("baseUrl param is missing");
 				return;
@@ -307,53 +307,53 @@
 
 			$scope.showSpinner();
 			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
-	        $http.post("listValidValuesForParam.do", $.param({
-	        	'protocol' : 'oai',
-	        	'param'    : 'set',
-	        	'baseUrl'  : baseUrl
-	        })).success(function(data) {
+			$http.post("listValidValuesForParam.do", $.param({
+				'protocol' : 'oai',
+				'param'    : 'set',
+				'baseUrl'  : baseUrl
+			})).success(function(data) {
 				$scope.hideSpinner();
-	        	$scope.currentSets = data;
-	        	angular.forEach($scope.currentSets, function(curr, pos1) {
-		        	angular.forEach($scope.selectedSets, function(sel, pos2) {
-		        		if (curr.id.trim() == sel.trim()) {
-		        			curr.selected = true;
-		        		}
-		        	});
+				$scope.currentSets = data;
+				angular.forEach($scope.currentSets, function(curr, pos1) {
+					angular.forEach($scope.selectedSets, function(sel, pos2) {
+						if (curr.id.trim() == sel.trim()) {
+							curr.selected = true;
+						}
+					});
 				});
-	        }).error(function(err) {
+			}).error(function(err) {
 				$scope.hideSpinner();
 				$scope.showError(err.message);
 			});
-	        
+
 		};
-		
-		
+
+
 		$scope.verifyMetaWf = function(ds, wf) {
 			var compliance = '';
 			var type = '';
 			angular.forEach(ds.commonParams, function(p,pos) {
-	        	if (p.id == 'compliance') {
-	        		compliance = p.value;
-	        	}
-	        	if (p.id == 'typology') {
-	        		type = p.value;
-	        	}
+				if (p.id == 'compliance') {
+					compliance = p.value;
+				}
+				if (p.id == 'typology') {
+					type = p.value;
+				}
 			});
-			
+
 			return (compliance && type && $scope.isValidTerm(compliance, wf.compliances) && $scope.isValidTerm(type, wf.ifaceTypes)); 
 		}
 
 		$scope.isValidTerm = function(term, list) {
-			
+
 			if (list.length == 0) {
 				return true;
 			}
 			var res = false;
 			angular.forEach(list, function(curr,pos) {
-	        	if (term.lastIndexOf(curr, 0) === 0) { // implementation of term.startsWith(curr)
-	        		res = true;
-	        	}
+				if (term.lastIndexOf(curr, 0) === 0) { // implementation of term.startsWith(curr)
+					res = true;
+				}
 			});
 			return res;
 		}
@@ -361,39 +361,39 @@
 		$scope.overrideApiCompliance = function(level) {
 			$scope.showSpinner();
 			$http.get('repoApiCompliance.update?id=' + $scope.currentRepoApi.repoId + '&iface=' + $scope.currentRepoApi.id + '&compliance=' + level)
-	        .success(
-	        		function(data) {
-	        			$scope.hideSpinner();
-	        			$scope.showNotification('Api correctly updated !');
-	        			$scope.loadApi(); 
-	        		}
-	        ).error(
-	        		function() {
-	        			$scope.showError('Something really bad must have happened to our fellow hamster..');
-	        			$scope.hideSpinner();
-	        		}
-	        );
+			.success(
+					function(data) {
+						$scope.hideSpinner();
+						$scope.showNotification('Api correctly updated !');
+						$scope.loadApi(); 
+					}
+			).error(
+					function() {
+						$scope.showError('Something really bad must have happened to our fellow hamster..');
+						$scope.hideSpinner();
+					}
+			);
 		}
-		
+
 		$scope.resetApiCompliance = function() {
 			$scope.showSpinner();
 			$http.get('repoApiCompliance.reset?id=' + $scope.currentRepoApi.repoId + '&iface=' + $scope.currentRepoApi.id)
-	        .success(
-	        		function(data) {
-	        			$scope.hideSpinner();
-	        			$scope.showNotification('Api correctly updated !');
-	        			$scope.loadApi(); 
-	        		}
-	        ).error(
-	        		function() {
-	        			$scope.showError('Something really bad must have happened to our fellow hamster..');
-	        			$scope.hideSpinner();
-	        		}
-	        );
+			.success(
+					function(data) {
+						$scope.hideSpinner();
+						$scope.showNotification('Api correctly updated !');
+						$scope.loadApi(); 
+					}
+			).error(
+					function() {
+						$scope.showError('Something really bad must have happened to our fellow hamster..');
+						$scope.hideSpinner();
+					}
+			);
 		}
-		
+
 		$scope.showCreateRemoteSyncApi = function(mongoUrl, mongoDB, mdId, apiSuffix) {
-			
+
 			var path = "//*[local-name()='header']/*[local-name()='identifier']";
 			angular.forEach($scope.currentRepoApi.otherParams, function(p) {
 				if (p.id=='metadata_identifier_path') {
@@ -400,7 +400,7 @@
 					path = p.value;
 				}
 			});
-			
+
 			var compliance = "UNKNOWN";
 			angular.forEach($scope.currentRepoApi.commonParams, function(p) {
 				if (p.id=='compliance') {
@@ -408,26 +408,87 @@
 				}
 			});
 			
-			$scope.newSyncApi = {
-				'dsId'  : $routeParams.repoId,
-				'apiId' : 'api_________::' + $routeParams.repoId + "::" + apiSuffix,
-				'compatibility' : compliance,
-				'contentdescription' : 'metadata',
-				'protocol' : 'remoteMdstore',
-				'baseurl'  : mongoUrl,
-				'apiParams' : {
-					'remote_database'   : mongoDB,
-					'remote_mdstore_id' : mdId
-				},
-				'metadataIdentifierPath' : path
-			};
+			var typology = "UNKNOWN";
+			angular.forEach($scope.currentRepoApi.commonParams, function(p) {
+				if (p.id=='typology') {
+					typology = p.value;
+				}
+			});
+
+			$scope.showSpinner();
+			$http.get('remoteDatasource/apis?repo=' + $routeParams.repoId)
+			.success(
+					function(data) {
+						$scope.hideSpinner();
+
+						var alreadyPresent = false;
+						var apiId = 'api_________::' + $routeParams.repoId + "::" + apiSuffix;
+
+						if(data.api) {
+							angular.forEach(data.api, function(api) {
+								if (api.id == apiId) {
+									alreadyPresent = true;
+									$scope.syncApi = api;
+								}
+							});
+						}
+
+						if (alreadyPresent) {
+							$('#showRemoteSyncApiModal').modal('show');
+						} else {
+							$scope.syncApi = {
+									"datasource": $routeParams.repoId,
+									"id": apiId,
+									"protocol": "remoteMdstore",
+									"contentdescription": "metadata",
+									"typology": typology,
+									"compatibility": compliance,
+									"baseurl": mongoUrl,
+									"removable": true,
+									"apiParams": [
+										{
+											"param": "remote_database",
+											"value": mongoDB
+										},
+										{
+											"param": "remote_mdstore_id",
+											"value": mdId
+										}
+									],
+									"otherParams": [
+										{
+											"param": "metadata_identifier_path",
+											"value": path
+										}
+									]
+							};
+							$('#newRemoteSyncApiModal').modal('show');	        				
+						}
+					}
+			).error(
+					function() {
+						$scope.showError('Something really bad must have happened to our fellow hamster..');
+						$scope.hideSpinner();
+					}
+			);
+
+		}
+		
+		$scope.createRemoteSyncApi = function(api) {
+			$scope.showSpinner();
 			
-			$('#remoteSyncApiModal').modal('show');
-			
+			$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
+			$http.post('remoteDatasource/api', api).success(function(data) {
+				$scope.hideSpinner();
+
+			}).error(function() {
+				$scope.showError('Something really bad must have happened to our fellow hamster..');
+				$scope.hideSpinner();
+			});
 		}
-				
-    	$scope.loadApi();
+
+		$scope.loadApi();
 	}
-		
- ]);
 
+	]);
+
