Project

General

Profile

« Previous | Next » 

Revision 45277

codebase used to migrate to java8 the production system

View differences:

modules/dnet-modular-database-ui/trunk/deploy.info
1
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/dnet-modular-database-ui/trunk/", "deploy_repository": "dnet4-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet4-snapshots", "name": "dnet-modular-database-ui"}
modules/dnet-modular-database-ui/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/db/DbManagerEntryPointController.java
1
package eu.dnetlib.functionality.modular.ui.db;
2

  
3
import javax.servlet.http.HttpServletRequest;
4
import javax.servlet.http.HttpServletResponse;
5

  
6
import org.springframework.ui.ModelMap;
7

  
8
import eu.dnetlib.functionality.modular.ui.ModuleEntryPoint;
9

  
10
public class DbManagerEntryPointController extends ModuleEntryPoint {
11

  
12
	@Override
13
	protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
14

  
15
	}
16

  
17
}
modules/dnet-modular-database-ui/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/db/DbManagerInternalController.java
1
package eu.dnetlib.functionality.modular.ui.db;
2

  
3
import java.io.IOException;
4
import java.io.StringReader;
5
import java.util.ArrayList;
6
import java.util.HashMap;
7
import java.util.List;
8
import java.util.Map;
9

  
10
import javax.annotation.Resource;
11
import javax.servlet.ServletOutputStream;
12
import javax.servlet.ServletResponse;
13
import javax.servlet.http.HttpServletResponse;
14

  
15
import org.apache.commons.io.IOUtils;
16
import org.springframework.jdbc.support.rowset.SqlRowSet;
17
import org.springframework.stereotype.Controller;
18
import org.springframework.web.bind.annotation.RequestMapping;
19
import org.springframework.web.bind.annotation.RequestParam;
20
import org.springframework.web.bind.annotation.ResponseBody;
21

  
22
import com.google.common.collect.Iterables;
23
import com.google.common.collect.Lists;
24

  
25
import eu.dnetlib.enabling.database.DatabaseServiceCore;
26
import eu.dnetlib.enabling.database.objects.DnetDatabase;
27
import eu.dnetlib.enabling.database.resultset.IterableRowSet;
28
import eu.dnetlib.enabling.resultset.client.utils.EPRUtils;
29

  
30
@Controller
31
public class DbManagerInternalController {
32
	public static final String CTYPE_CSS = "text/css";
33
	public static final String CTYPE_JS = "text/javascript";
34
	public static final String CTYPE_XML = "text/xml";
35
	public static final String CTYPE_TEXT = "text/plain";
36
	public static final String CTYPE_HTML = "text/html";
37
	
38
	@Resource
39
	private DatabaseServiceCore core;
40

  
41
	@RequestMapping("/ui/listDBs.do")
42
	public @ResponseBody List<DnetDatabase> listDatabases() throws Exception {
43
		return core.listDatabases();
44
	}
45

  
46
	@RequestMapping("/ui/listTables.do")
47
	public @ResponseBody List<Map<String, Object>> listTables(@RequestParam(value = "db", required = true) String db) throws Exception {
48
		
49
		final List<Map<String, Object>> tables = new ArrayList<Map<String, Object>>();
50
		final Map<String, String> logSize = new HashMap<String, String>();
51
		
52
		final String sql = IOUtils.toString(getClass().getResourceAsStream("tables_info.sql"));
53
		
54
		final SqlRowSet rows = core.getDbUtils().executeSql(db, sql, SqlRowSet.class);
55
		while (rows.next()) {
56
			final String tname = rows.getString("name");
57
			if (tname.endsWith("_log")) {
58
				logSize.put(tname.substring(0, tname.length() - 4), rows.getString("total"));
59
			} else {
60
				final Map<String, Object> t = new HashMap<String, Object>();
61
				t.put("name", rows.getString("name"));
62
				t.put("view", rows.getString("kind").equalsIgnoreCase("v"));
63
				t.put("data", rows.getString("data"));
64
				t.put("indices", rows.getString("indices"));
65
				t.put("total", rows.getString("total"));
66
				t.put("managed", core.getDbUtils().isManagedTable(db, tname));
67
				t.put("logged", core.getDbUtils().isLoggedTable(db, tname));
68
				t.put("dnetIdentifier", core.getDbUtils().getDefaultDnetIdentifier(db, tname));
69
				tables.add(t);
70
			}
71
		}
72
		for (Map<String, Object> t : tables) {
73
			if (logSize.containsKey(t.get("name"))) {
74
				t.put("logdata", logSize.get(t.get("name")));
75
			} else {
76
				t.put("logdata", "-");
77
			}
78
		}
79
		
80
		return tables;
81
	}
82

  
83
	@RequestMapping("/ui/manageDB.do")
84
	public @ResponseBody boolean manageDB(@RequestParam(value = "db", required = true) String db,
85
			@RequestParam(value = "manage", required = true) boolean b) throws Exception {
86
		core.changeDatabaseStatus(db, b);
87
		return true;
88
	}
89

  
90
	@RequestMapping("/ui/importEPR.do")
91
	public @ResponseBody boolean importEPR(@RequestParam(value = "db", required = true) String db,
92
			@RequestParam(value = "epr", required = true) String epr) throws Exception {
93

  
94
		core.importFromResultset(db, (new EPRUtils()).getEpr(epr));
95

  
96
		return true;
97
	}
98
	
99
	
100
	@RequestMapping("/ui/query.do")
101
	public @ResponseBody List<String> query(@RequestParam(value = "query", required = true) final String query,
102
			@RequestParam(value = "db", required = true) final String db,
103
			@RequestParam(value = "limit", required = true) int limit) throws Exception {
104
		
105
		return Lists.newArrayList(Iterables.limit(new IterableRowSet(db, query, null, core.getDbUtils()), limit));
106
	
107
	}
108
	
109
	@RequestMapping("/ui/changeTableManagement.do")
110
	public @ResponseBody boolean changeTableManagement(@RequestParam(value = "db", required = true) final String db,
111
			@RequestParam(value = "t", required = true) final String t) throws Exception {
112
		
113
		if (core.getDbUtils().isManagedTable(db, t)) {
114
			core.getDbUtils().removeManagementOfTable(db, t);
115
		} else {
116
			core.getDbUtils().prepareManagementOfTable(db, t);			
117
		}
118
		
119
		return true;
120
	} 
121

  
122
	
123
	@RequestMapping("/ui/changeIdentifiers.do")
124
	public @ResponseBody boolean changeId(HttpServletResponse res, 
125
			@RequestParam(value = "db", required = true) final String db,
126
			@RequestParam(value = "t", required = false) final String t) throws Exception {
127
		
128
		if (t == null || t.isEmpty()) {
129
			core.getDbUtils().reassignDefaultDnetIdentifiers(db);
130
		} else {
131
			core.getDbUtils().reassignDefaultDnetIdentifiers(db, t);
132
		}
133
		
134
		return true;
135
	} 
136
	
137
	@RequestMapping("/ui/changeTableLog.do")
138
	public @ResponseBody boolean changeTableLog(@RequestParam(value = "db", required = true) final String db,
139
			@RequestParam(value = "t", required = true) final String t) throws Exception {
140

  
141
		if (core.getDbUtils().isManagedTable(db, t)) {
142
			if (core.getDbUtils().isLoggedTable(db, t)) {
143
				core.getDbUtils().removeLogTable(db, t);
144
			} else {
145
				core.getDbUtils().addLogTable(db, t);			
146
			}
147
		}
148

  
149
		return true;
150
	} 
151

  
152
	@RequestMapping("/ui/describeTable.do")
153
	public @ResponseBody List<Map<?, ?>> describeTable(@RequestParam(value = "db", required = true) final String db,
154
			@RequestParam(value = "t", required = true) final String t) throws Exception {
155
		return core.getDbUtils().describeTable(db, t);
156
	} 
157

  
158
	@RequestMapping("/ui/dumpTable.do")
159
	public void dumpTable(final ServletResponse response, @RequestParam(value = "db", required = true) final String db,
160
			@RequestParam(value = "t", required = true) final String t) throws Exception {
161
		sendXML(response, core.getDbUtils().dumpTableAsXML(db,t));
162
	}
163

  
164
	@RequestMapping("/ui/dumpTableEPR.do")
165
	public void dumpTableEPR(final ServletResponse response, 
166
			@RequestParam(value = "db", required = true) final String db,
167
			@RequestParam(value = "t", required = true) final String t) throws Exception {
168
		
169
		sendXML(response, core.generateResultSet(db, t, null).toString());
170
	}
171
	
172
	
173
	public void sendXML(final ServletResponse response, final String xml) throws IOException {
174
		response.setContentType("text/xml");
175
		
176
		final ServletOutputStream out = response.getOutputStream();
177
		IOUtils.copy(new StringReader(xml), out);
178
		
179
		out.flush();
180
		out.close();
181
	}
182
}
modules/dnet-modular-database-ui/trunk/src/main/resources/eu/dnetlib/functionality/modular/ui/webContext-modular-ui-database.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns="http://www.springframework.org/schema/beans"
3
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
4
	xmlns:sec="http://cxf.apache.org/configuration/security" xmlns:wsa="http://cxf.apache.org/ws/addressing"
5
	xmlns:p="http://www.springframework.org/schema/p" xmlns:http="http://cxf.apache.org/transports/http/configuration"
6
	xmlns:t="http://dnetlib.eu/springbeans/t" xmlns:template="http://dnetlib.eu/springbeans/template"
7
	xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context"
8
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
9
						http://cxf.apache.org/ws/addressing http://cxf.apache.org/schemas/ws-addr-conf.xsd
10
						http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd
11
						http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
12
						http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
13
						http://dnetlib.eu/springbeans/template http://dnetlib.eu/springbeans/template.xsd
14
						http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
15
						http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
16

  
17

  
18
	<bean name="/ui/dbManager.do"
19
		class="eu.dnetlib.functionality.modular.ui.db.DbManagerEntryPointController"
20
		p:menu="Database Manager" 
21
		p:title="Database Manager"
22
		p:description="Manager for the Database Service" 
23
		p:group="Tools">
24
		<property name="permissionLevels">
25
			<set>
26
				<value>IS_ADMIN</value>
27
			</set>
28
		</property>
29
	</bean>
30

  
31
</beans>
modules/dnet-modular-database-ui/trunk/src/main/resources/eu/dnetlib/functionality/modular/ui/db/tables_info.sql
1
SELECT c.relname AS name, 
2
		c.relkind as kind,
3
		pg_size_pretty(pg_relation_size(c.relname::text)) AS data,
4
		pg_size_pretty(pg_total_relation_size(c.relname::text)-pg_relation_size(c.relname::text)) AS indices,
5
		pg_size_pretty(pg_total_relation_size(c.relname::text)) AS total
6
FROM pg_class c
7
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
8
WHERE c.relkind IN ('r','v','')
9
	AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
10
	AND pg_table_is_visible(c.oid)
11
ORDER BY c.relname;
modules/dnet-modular-database-ui/trunk/src/main/resources/eu/dnetlib/functionality/modular/ui/views/ui/dbManager.st
1
$common/master( header={
2
	<script type="text/javascript" src="../resources/js/angular.min.js" ></script>
3
	<script type="text/javascript" src="../resources/js/angular-route.min.js"></script>
4
	<script type="text/javascript" src="../resources/js/db_manager.js"></script>
5
	<script type="text/javascript" src="../resources/js/db_manager_controllers.js"></script>
6
}, body={
7
	<div ng-app="dbManager">
8
		<div ng-view></div>
9
	</div>
10
} )$
modules/dnet-modular-database-ui/trunk/src/main/resources/eu/dnetlib/web/resources/html/tableDesc.html
1
<div class="well">
2
	<fieldset>
3
		<legend>
4
			<b>Database: </b><i>{{db}}</i> - <b>table: </b><i>{{table}}</i>  
5
		</legend>
6
		<div class="panel panel-info" ng-repeat="field in details">
7
			<div class="panel-heading"><b>Field: </b><i>{{field.column_name}}</i></div>
8
			<table class="table table-condensed">
9
				<tr ng-repeat="(k, v) in field" ng-show="v">
10
					<th class="col-xs-3">{{k}}</th>
11
					<td class="col-xs-9">{{v}}</td>
12
				</tr>
13
			</table>
14
		</div>
15
	</fieldset>
16
</div>
modules/dnet-modular-database-ui/trunk/src/main/resources/eu/dnetlib/web/resources/html/databases.html
1
<table class="table table-hover">
2
	<thead>
3
		<tr>
4
			<th>Database</th>
5
			<th class="text-center">is Managed</th>
6
			<th class="text-right">Operations</th>
7
		</tr>
8
	</thead>
9
	<tbody>
10
		<tr ng-repeat="db in databases">
11
			<td><a href="javascript:void(0)" ng-click="go('/db/'+db.dbName)">{{db.dbName}}</a></td>
12
			<td class="text-center">
13
				<span ng-show="db.managed">
14
					<span class="label label-success">YES</span> / <a href="javascript:void(0)" ng-click="manageDB(db.dbName, false)">NO</a>
15
				</span>
16
				<span ng-show="!db.managed">
17
					<a href="javascript:void(0)" ng-click="manageDB(db.dbName, true)">YES</a> / <span class="label label-danger">NO</span>
18
				</span>
19
	  		</td>
20
			<td class="text-right">
21
				<button class="btn btn-sm btn-primary" ng-click="go('/q/' + db.dbName)">
22
					SQL Query
23
				</button>
24
				<button class="btn btn-sm btn-warning" ng-click="changeIdentifiers(db.dbName)">
25
					Fix D-Net Identifiers				
26
				</button>
27
			</td>
28
		</tr>
29
	</tbody>
30
</table>
modules/dnet-modular-database-ui/trunk/src/main/resources/eu/dnetlib/web/resources/html/tables.html
1
<table class="table table-hover">
2
	<thead>
3
		<tr>
4
			<th>Table</th>
5
			<th>Database</th>
6
			<th class="text-center">Data</th>
7
			<th class="text-center">Indices</th>
8
			<th class="text-center">Total</th>
9
			<th class="text-center">Log data</th>
10
			<th class="text-center">Type</th>
11
			<th class="text-center">is Managed</th>
12
			<th class="text-center">is Logged</th>
13
			<th class="text-center">Default value for Dnet-ID</th>
14
			<th class="text-right">Dump</th>
15
		</tr>
16
	</thead>
17
	<tbody>
18
		<tr ng-repeat="t in dbtables">
19
			<td><a href="javascript:void(0)" ng-click="go('/t/' + db + '/' + t.name)">{{t.name}}</a></td>
20
			<td>{{db}}</td>
21
			<td class="text-center">{{t.data}}</td>
22
			<td class="text-center">{{t.indices}}</td>
23
			<td class="text-center">{{t.total}}</td>
24
			<td class="text-center">{{t.logdata}}</td>
25
			<td class="text-center">
26
				<span ng-show="t.view" class="label label-default">VIEW</span>
27
				<span ng-show="!t.view" class="label label-primary">TABLE</span>
28
			</td>
29
			<td class="text-center">
30
				<span ng-show="!t.view">
31
					<span ng-show="t.managed">
32
						<span class="label label-success">YES</span> / <a href="javascript:void(0)" ng-click="changeTableManagement(db, t.name)">NO</a>
33
					</span>
34
					<span ng-show="!t.managed">
35
						<a href="javascript:void(0)" ng-click="changeTableManagement(db, t.name)">YES</a> / <span class="label label-danger">NO</span>
36
					</span>
37
				</span>
38
			</td>
39
			<td class="text-center">
40
				<span ng-show="!t.view && t.managed">
41
					<span ng-show="t.logged">
42
						<span class="label label-success">YES</span> / <a href="javascript:void(0)" ng-click="changeTableLog(db, t.name)">NO</a>
43
					</span>
44
					<span ng-show="!t.logged">
45
						<a href="javascript:void(0)" ng-click="changeTableLog(db, t.name)">YES</a> / <span class="label label-danger">NO</span>
46
					</span>
47
				</span>
48
			</td>
49
			<td class="text-center">
50
				<form class="form-inline" ng-show="!t.view && t.managed">
51
					<input class="form-control input-sm" type="text" readonly="readonly"  ng-model="t.dnetIdentifier" />
52
					<button class="btn btn-sm btn-primary" ng-click="changeIdentifiers(db, t.name)">fix</button>
53
				</form>
54
			</td>
55
			<td class="text-right">
56
				<a href="dumpTable.do?db={{db}}&t={{t.name}}" class="btn btn-sm btn-primary">as XML</a>
57
				<a href="dumpTableEPR.do?db={{db}}&t={{t.name}}" class="btn btn-sm btn-primary">as EPR</a>
58
			</td>
59
		</tr>
60
	</tbody>
61
</table>
modules/dnet-modular-database-ui/trunk/src/main/resources/eu/dnetlib/web/resources/html/dbQuery.html
1
<form class="form-horizontal" role="form">
2
	<div class="form-group">
3
		<label for="dbInput" class="col-sm-2 control-label">Database</label>
4
		<div class="col-sm-4">
5
			<input class="form-control" id="dbInput" ng-model="db" readonly="readonly" />
6
		</div>
7
	</div>
8
	<div class="form-group">
9
		<label for="sqlInput" class="col-sm-2 control-label">SQL Query</label>
10
		<div class="col-sm-4">
11
			<textarea class="form-control" id="sqlInput" ng-model="sql"></textarea>
12
		</div>
13
	</div>
14
	<div class="form-group">
15
		<label for="limitInput" class="col-sm-2 control-label">Limit</label>
16
		<div class="col-sm-1">
17
			<input class="form-control" id="limitInput" ng-model="limit" />
18
		</div>
19
	</div>
20
	<div class="form-group">
21
		<div class="col-sm-offset-2 col-sm-4">
22
			<button class="btn btn-default" ng-click="searchSQL()">Search</button>
23
		</div>
24
	</div>
25
</form>
26

  
27
<div class="panel panel-primary" ng-repeat="r in results">
28
	<div class="panel-heading"><b>Result: </b><i>{{$index + 1}}</i></div>
29
	<div class="panel-body">
30
		{{r}}
31
	</div>
32
</div>
modules/dnet-modular-database-ui/trunk/src/main/resources/eu/dnetlib/web/resources/js/db_manager_controllers.js
1
var dbManagerControllers = angular.module('dbManagerControllers', []);
2

  
3
function common_init($scope, $http, $sce, $location) {
4
	initSpinner();
5
	$scope.showError        = function(error)   { show_notification("error", error); }
6
	$scope.showNotification = function(message) { show_notification("info", message); }
7
	$scope.showSpinner      = function()        { showSpinner(); }
8
	$scope.hideSpinner      = function()        { hideSpinner(); }
9
	$scope.to_trusted       = function(html)    { return $sce.trustAsHtml(html); }
10
	$scope.go               = function(path)    { $location.path(path); }
11
	$scope.encodeValue      = function(val)     { return val; }
12
}
13

  
14
dbManagerControllers.controller('databasesCtrl', [
15
	'$scope', '$http', '$sce', '$location', 
16
	function ($scope, $http, $sce, $location) {
17
		common_init($scope, $http, $sce, $location);
18
		
19
		$scope.databases = [];
20
		
21
		$scope.listDatabases = function() {
22
			$scope.databases = [];
23

  
24
			$scope.showSpinner();
25
			
26
			$http.get('listDBs.do').success(function(data) {
27
				$scope.hideSpinner();
28
				$scope.databases = data;
29
		    }).error(function() {
30
	            $scope.showError('Something really bad must have happened to our fellow hamster..');
31
	            $scope.hideSpinner();
32
		    });
33
		}
34
		
35
		$scope.manageDB = function(db, b) {
36
			$scope.showSpinner();
37
			
38
			$http.get('manageDB.do?db=' + db + "&manage=" + b).success(function(data) {
39
				$scope.hideSpinner();
40
				$scope.showNotification("Management Mode Updated !");
41
				$scope.listDatabases();
42
		    }).error(function() {
43
	            $scope.showError('Something really bad must have happened to our fellow hamster..');
44
	            $scope.hideSpinner();
45
		    });
46
		}
47
		
48
		$scope.changeIdentifiers = function(db) {
49
			if (confirm("Are you sure ?")) {
50
				$scope.showSpinner();
51
				
52
				$http.get('changeIdentifiers.do?db=' + db).success(function(data) {
53
					$scope.hideSpinner();
54
					$scope.showNotification("Identifiers changed !");
55
					$scope.listDatabases();
56
			    }).error(function() {
57
		            $scope.showError('Something really bad must have happened to our fellow hamster..');
58
		            $scope.hideSpinner();
59
			    });
60
			}
61
		}
62
			
63
		$scope.listDatabases();
64
	}
65
]);
66

  
67
dbManagerControllers.controller('tablesCtrl', [
68
	'$scope', '$http', '$sce', '$location', '$routeParams',  
69
    function ($scope, $http, $sce, $location, $routeParams) {
70
		common_init($scope, $http, $sce, $location);
71
		
72
		$scope.db       = $routeParams.db;
73
		$scope.dbtables = [];
74
		
75
		$scope.listTables = function() {
76
			$scope.dbtables = [];
77

  
78
			$scope.showSpinner();
79
			
80
			$http.get('listTables.do?db=' + $scope.db).success(function(data) {
81
				$scope.hideSpinner();
82
				$scope.dbtables = data;
83
		    }).error(function() {
84
	            $scope.showError('Something really bad must have happened to our fellow hamster..');
85
	            $scope.hideSpinner();
86
		    });
87
		}
88
		
89
		$scope.changeTableManagement = function(db, t) {
90
			$scope.showSpinner();
91
			
92
			$http.get('changeTableManagement.do?db=' + db + "&t=" + t).success(function(data) {
93
				$scope.hideSpinner();
94
				$scope.showNotification("Management Mode Updated !");
95
				$scope.listTables();
96
		    }).error(function() {
97
	            $scope.showError('Something really bad must have happened to our fellow hamster..');
98
	            $scope.hideSpinner();
99
		    });
100
		}
101
		
102
		$scope.changeTableLog = function(db, t) {
103
			$scope.showSpinner();
104
			
105
			$http.get('changeTableLog.do?db=' + db + "&t=" + t).success(function(data) {
106
				$scope.hideSpinner();
107
				$scope.showNotification("Log Mode Updated !");
108
				$scope.listTables();
109
		    }).error(function() {
110
	            $scope.showError('Something really bad must have happened to our fellow hamster..');
111
	            $scope.hideSpinner();
112
		    });
113
		}
114
		
115
		$scope.changeIdentifiers = function(db, t) {
116
			if (confirm("Are you sure ?")) {
117
				$scope.showSpinner();
118
				
119
				$http.get('changeIdentifiers.do?db=' + db + '&t=' + t).success(function(data) {
120
					$scope.hideSpinner();
121
					$scope.showNotification("Identifiers changed !");
122
					$scope.listDatabases();
123
			    }).error(function() {
124
		            $scope.showError('Something really bad must have happened to our fellow hamster..');
125
		            $scope.hideSpinner();
126
			    });
127
			}
128
		}
129
		
130
		$scope.listTables();
131
	}
132
]);
133

  
134
dbManagerControllers.controller('tableDescCtrl', [
135
	'$scope', '$http', '$sce', '$location', '$routeParams',  
136
	function ($scope, $http, $sce, $location, $routeParams) {
137
		common_init($scope, $http, $sce, $location);
138
		
139
		$scope.db       = $routeParams.db;
140
		$scope.table    = $routeParams.t;
141
		$scope.details  = [];
142
		
143
		$scope.getTableDetails = function() {
144
			$scope.details = [];
145

  
146
			$scope.showSpinner();
147
			
148
			$http.get('describeTable.do?db=' + $scope.db + "&t=" + $scope.table).success(function(data) {
149
				$scope.hideSpinner();
150
				$scope.details = data;
151
		    }).error(function() {
152
	            $scope.showError('Something really bad must have happened to our fellow hamster..');
153
	            $scope.hideSpinner();
154
		    });
155
		}
156
		
157
		$scope.getTableDetails();
158
	}
159

  
160
]);
161

  
162
dbManagerControllers.controller('dbQueryCtrl', [
163
	'$scope', '$http', '$sce', '$location', '$routeParams',  
164
	function ($scope, $http, $sce, $location, $routeParams) {
165
		common_init($scope, $http, $sce, $location);
166
                                            		
167
        $scope.db = $routeParams.db;
168
        $scope.sql = 'SELECT 1';
169
        $scope.limit = 100;
170
        $scope.results = [];
171
        
172
        $scope.searchSQL = function() {
173
			$scope.results = [];
174

  
175
			$scope.showSpinner();
176
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
177
            $http.post('query.do', $.param({
178
                    'db'    : $scope.db,
179
                    'limit' : $scope.limit,
180
                    'query' : $scope.sql
181
            })).success(function(data) {
182
				$scope.hideSpinner();
183
				$scope.results = data;
184
		    }).error(function() {
185
	            $scope.showError('Something really bad must have happened to our fellow hamster..');
186
	            $scope.hideSpinner();
187
		    });
188
		}
189
        
190
	}
191
]);
modules/dnet-modular-database-ui/trunk/src/main/resources/eu/dnetlib/web/resources/js/db_manager.js
1
var module = angular.module('dbManager', ['ngRoute', 'dbManagerControllers']);
2

  
3
module.config([
4
	'$routeProvider',
5
	function($routeProvider) {
6
		$routeProvider
7
			.when('/dbs',      { templateUrl: '../resources/html/databases.html', controller: 'databasesCtrl' })
8
			.when('/db/:db',   { templateUrl: '../resources/html/tables.html',    controller: 'tablesCtrl'    })
9
			.when('/t/:db/:t', { templateUrl: '../resources/html/tableDesc.html', controller: 'tableDescCtrl' })
10
			.when('/q/:db',    { templateUrl: '../resources/html/dbQuery.html',   controller: 'dbQueryCtrl'   })
11
			.otherwise({ redirectTo: '/dbs' });
12
	}
13
]);
modules/dnet-modular-database-ui/trunk/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
	<parent>
4
		<groupId>eu.dnetlib</groupId>
5
		<artifactId>dnet-parent</artifactId>
6
		<version>1.0.0</version>
7
	</parent>
8
	<modelVersion>4.0.0</modelVersion>
9
	<groupId>eu.dnetlib</groupId>
10
	<artifactId>dnet-modular-database-ui</artifactId>
11
	<packaging>jar</packaging>
12
	<version>2.1.1-SNAPSHOT</version>
13
	<scm>
14
	  <developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/dnet-modular-database-ui/trunk</developerConnection>
15
	</scm>
16
	<dependencies>
17
		<dependency>
18
			<groupId>commons-fileupload</groupId>
19
			<artifactId>commons-fileupload</artifactId>
20
			<version>1.3.1</version>
21
		</dependency>
22
		<dependency>
23
			<groupId>eu.dnetlib</groupId>
24
			<artifactId>dnet-modular-ui</artifactId>
25
			<version>[3.0.0,4.0.0)</version>
26
		</dependency>
27
		<dependency>
28
			<groupId>junit</groupId>
29
			<artifactId>junit</artifactId>
30
			<version>${junit.version}</version>
31
			<scope>test</scope>
32
		</dependency>
33
		<dependency>
34
			<groupId>eu.dnetlib</groupId>
35
			<artifactId>cnr-enabling-database-service</artifactId>
36
			<version>[3.0.0,4.0.0)</version>
37
		</dependency>
38
		<dependency>
39
			<groupId>javax.servlet</groupId>
40
			<artifactId>javax.servlet-api</artifactId>
41
			<version>${javax.servlet.version}</version>
42
			<scope>provided</scope>
43
		</dependency>
44
	</dependencies>
45
</project>
modules/dnet-modular-database-ui/tags/dnet-modular-database-ui-1.0.0/deploy.info
1
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/dnet-modular-database-ui/trunk/", "deploy_repository": "dnet4-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet4-snapshots", "name": "dnet-modular-database-ui"}
modules/dnet-modular-database-ui/tags/dnet-modular-database-ui-1.0.0/src/main/java/eu/dnetlib/functionality/modular/ui/db/DbManagerEntryPointController.java
1
package eu.dnetlib.functionality.modular.ui.db;
2

  
3
import javax.servlet.http.HttpServletRequest;
4
import javax.servlet.http.HttpServletResponse;
5

  
6
import org.springframework.ui.ModelMap;
7

  
8
import eu.dnetlib.functionality.modular.ui.ModuleEntryPoint;
9

  
10
public class DbManagerEntryPointController extends ModuleEntryPoint {
11

  
12
	@Override
13
	protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
14

  
15
	}
16

  
17
}
modules/dnet-modular-database-ui/tags/dnet-modular-database-ui-1.0.0/src/main/java/eu/dnetlib/functionality/modular/ui/db/DbManagerInternalController.java
1
package eu.dnetlib.functionality.modular.ui.db;
2

  
3
import java.io.IOException;
4
import java.io.StringReader;
5
import java.util.ArrayList;
6
import java.util.HashMap;
7
import java.util.List;
8
import java.util.Map;
9

  
10
import javax.annotation.Resource;
11
import javax.servlet.ServletOutputStream;
12
import javax.servlet.ServletResponse;
13
import javax.servlet.http.HttpServletResponse;
14

  
15
import org.apache.commons.io.IOUtils;
16
import org.springframework.jdbc.support.rowset.SqlRowSet;
17
import org.springframework.stereotype.Controller;
18
import org.springframework.web.bind.annotation.RequestMapping;
19
import org.springframework.web.bind.annotation.RequestParam;
20
import org.springframework.web.bind.annotation.ResponseBody;
21

  
22
import com.google.common.collect.Iterables;
23
import com.google.common.collect.Lists;
24

  
25
import eu.dnetlib.enabling.database.DatabaseServiceCore;
26
import eu.dnetlib.enabling.database.objects.DnetDatabase;
27
import eu.dnetlib.enabling.database.resultset.IterableRowSet;
28
import eu.dnetlib.enabling.resultset.client.utils.EPRUtils;
29

  
30
@Controller
31
public class DbManagerInternalController {
32
	public static final String CTYPE_CSS = "text/css";
33
	public static final String CTYPE_JS = "text/javascript";
34
	public static final String CTYPE_XML = "text/xml";
35
	public static final String CTYPE_TEXT = "text/plain";
36
	public static final String CTYPE_HTML = "text/html";
37
	
38
	@Resource
39
	private DatabaseServiceCore core;
40

  
41
	@RequestMapping("/ui/listDBs.do")
42
	public @ResponseBody List<DnetDatabase> listDatabases() throws Exception {
43
		return core.listDatabases();
44
	}
45

  
46
	@RequestMapping("/ui/listTables.do")
47
	public @ResponseBody List<Map<String, Object>> listTables(@RequestParam(value = "db", required = true) String db) throws Exception {
48
		
49
		final List<Map<String, Object>> tables = new ArrayList<Map<String, Object>>();
50
		final Map<String, String> logSize = new HashMap<String, String>();
51
		
52
		final String sql = IOUtils.toString(getClass().getResourceAsStream("tables_info.sql"));
53
		
54
		final SqlRowSet rows = core.getDbUtils().executeSql(db, sql, SqlRowSet.class);
55
		while (rows.next()) {
56
			final String tname = rows.getString("name");
57
			if (tname.endsWith("_log")) {
58
				logSize.put(tname.substring(0, tname.length() - 4), rows.getString("total"));
59
			} else {
60
				final Map<String, Object> t = new HashMap<String, Object>();
61
				t.put("name", rows.getString("name"));
62
				t.put("view", rows.getString("kind").equalsIgnoreCase("v"));
63
				t.put("data", rows.getString("data"));
64
				t.put("indices", rows.getString("indices"));
65
				t.put("total", rows.getString("total"));
66
				t.put("managed", core.getDbUtils().isManagedTable(db, tname));
67
				t.put("logged", core.getDbUtils().isLoggedTable(db, tname));
68
				t.put("dnetIdentifier", core.getDbUtils().getDefaultDnetIdentifier(db, tname));
69
				tables.add(t);
70
			}
71
		}
72
		for (Map<String, Object> t : tables) {
73
			if (logSize.containsKey(t.get("name"))) {
74
				t.put("logdata", logSize.get(t.get("name")));
75
			} else {
76
				t.put("logdata", "-");
77
			}
78
		}
79
		
80
		return tables;
81
	}
82

  
83
	@RequestMapping("/ui/manageDB.do")
84
	public @ResponseBody boolean manageDB(@RequestParam(value = "db", required = true) String db,
85
			@RequestParam(value = "manage", required = true) boolean b) throws Exception {
86
		core.changeDatabaseStatus(db, b);
87
		return true;
88
	}
89

  
90
	@RequestMapping("/ui/importEPR.do")
91
	public @ResponseBody boolean importEPR(@RequestParam(value = "db", required = true) String db,
92
			@RequestParam(value = "epr", required = true) String epr) throws Exception {
93

  
94
		core.importFromResultset(db, (new EPRUtils()).getEpr(epr));
95

  
96
		return true;
97
	}
98
	
99
	
100
	@RequestMapping("/ui/query.do")
101
	public @ResponseBody List<String> query(@RequestParam(value = "query", required = true) final String query,
102
			@RequestParam(value = "db", required = true) final String db,
103
			@RequestParam(value = "limit", required = true) int limit) throws Exception {
104
		
105
		return Lists.newArrayList(Iterables.limit(new IterableRowSet(db, query, null, core.getDbUtils()), limit));
106
	
107
	}
108
	
109
	@RequestMapping("/ui/changeTableManagement.do")
110
	public @ResponseBody boolean changeTableManagement(@RequestParam(value = "db", required = true) final String db,
111
			@RequestParam(value = "t", required = true) final String t) throws Exception {
112
		
113
		if (core.getDbUtils().isManagedTable(db, t)) {
114
			core.getDbUtils().removeManagementOfTable(db, t);
115
		} else {
116
			core.getDbUtils().prepareManagementOfTable(db, t);			
117
		}
118
		
119
		return true;
120
	} 
121

  
122
	
123
	@RequestMapping("/ui/changeIdentifiers.do")
124
	public @ResponseBody boolean changeId(HttpServletResponse res, 
125
			@RequestParam(value = "db", required = true) final String db,
126
			@RequestParam(value = "t", required = false) final String t) throws Exception {
127
		
128
		if (t == null || t.isEmpty()) {
129
			core.getDbUtils().reassignDefaultDnetIdentifiers(db);
130
		} else {
131
			core.getDbUtils().reassignDefaultDnetIdentifiers(db, t);
132
		}
133
		
134
		return true;
135
	} 
136
	
137
	@RequestMapping("/ui/changeTableLog.do")
138
	public @ResponseBody boolean changeTableLog(@RequestParam(value = "db", required = true) final String db,
139
			@RequestParam(value = "t", required = true) final String t) throws Exception {
140

  
141
		if (core.getDbUtils().isManagedTable(db, t)) {
142
			if (core.getDbUtils().isLoggedTable(db, t)) {
143
				core.getDbUtils().removeLogTable(db, t);
144
			} else {
145
				core.getDbUtils().addLogTable(db, t);			
146
			}
147
		}
148

  
149
		return true;
150
	} 
151

  
152
	@RequestMapping("/ui/describeTable.do")
153
	public @ResponseBody List<Map<?, ?>> describeTable(@RequestParam(value = "db", required = true) final String db,
154
			@RequestParam(value = "t", required = true) final String t) throws Exception {
155
		return core.getDbUtils().describeTable(db, t);
156
	} 
157

  
158
	@RequestMapping("/ui/dumpTable.do")
159
	public void dumpTable(final ServletResponse response, @RequestParam(value = "db", required = true) final String db,
160
			@RequestParam(value = "t", required = true) final String t) throws Exception {
161
		sendXML(response, core.getDbUtils().dumpTableAsXML(db,t));
162
	}
163

  
164
	@RequestMapping("/ui/dumpTableEPR.do")
165
	public void dumpTableEPR(final ServletResponse response, 
166
			@RequestParam(value = "db", required = true) final String db,
167
			@RequestParam(value = "t", required = true) final String t) throws Exception {
168
		
169
		sendXML(response, core.generateResultSet(db, t, null).toString());
170
	}
171
	
172
	
173
	public void sendXML(final ServletResponse response, final String xml) throws IOException {
174
		response.setContentType("text/xml");
175
		
176
		final ServletOutputStream out = response.getOutputStream();
177
		IOUtils.copy(new StringReader(xml), out);
178
		
179
		out.flush();
180
		out.close();
181
	}
182
}
modules/dnet-modular-database-ui/tags/dnet-modular-database-ui-1.0.0/src/main/resources/eu/dnetlib/functionality/modular/ui/webContext-modular-ui-database.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns="http://www.springframework.org/schema/beans"
3
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
4
	xmlns:sec="http://cxf.apache.org/configuration/security" xmlns:wsa="http://cxf.apache.org/ws/addressing"
5
	xmlns:p="http://www.springframework.org/schema/p" xmlns:http="http://cxf.apache.org/transports/http/configuration"
6
	xmlns:t="http://dnetlib.eu/springbeans/t" xmlns:template="http://dnetlib.eu/springbeans/template"
7
	xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context"
8
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
9
						http://cxf.apache.org/ws/addressing http://cxf.apache.org/schemas/ws-addr-conf.xsd
10
						http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd
11
						http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
12
						http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
13
						http://dnetlib.eu/springbeans/template http://dnetlib.eu/springbeans/template.xsd
14
						http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
15
						http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
16

  
17

  
18
	<bean name="/ui/dbManager.do"
19
		class="eu.dnetlib.functionality.modular.ui.db.DbManagerEntryPointController"
20
		p:menu="Database Manager" 
21
		p:title="Database Manager"
22
		p:description="Manager for the Database Service" 
23
		p:group="Tools">
24
		<property name="permissionLevels">
25
			<set>
26
				<value>IS_ADMIN</value>
27
			</set>
28
		</property>
29
	</bean>
30

  
31
</beans>
modules/dnet-modular-database-ui/tags/dnet-modular-database-ui-1.0.0/src/main/resources/eu/dnetlib/functionality/modular/ui/db/tables_info.sql
1
SELECT c.relname AS name, 
2
		c.relkind as kind,
3
		pg_size_pretty(pg_relation_size(c.relname::text)) AS data,
4
		pg_size_pretty(pg_total_relation_size(c.relname::text)-pg_relation_size(c.relname::text)) AS indices,
5
		pg_size_pretty(pg_total_relation_size(c.relname::text)) AS total
6
FROM pg_class c
7
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
8
WHERE c.relkind IN ('r','v','')
9
	AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
10
	AND pg_table_is_visible(c.oid)
11
ORDER BY c.relname;
modules/dnet-modular-database-ui/tags/dnet-modular-database-ui-1.0.0/src/main/resources/eu/dnetlib/functionality/modular/ui/views/ui/dbManager.st
1
$common/master( header={
2
	<script type="text/javascript" src="../resources/js/angular.min.js" ></script>
3
	<script type="text/javascript" src="../resources/js/angular-route.min.js"></script>
4
	<script type="text/javascript" src="../resources/js/db_manager.js"></script>
5
	<script type="text/javascript" src="../resources/js/db_manager_controllers.js"></script>
6
}, body={
7
	<div ng-app="dbManager">
8
		<div ng-view></div>
9
	</div>
10
} )$
modules/dnet-modular-database-ui/tags/dnet-modular-database-ui-1.0.0/src/main/resources/eu/dnetlib/web/resources/html/tableDesc.html
1
<div class="well">
2
	<fieldset>
3
		<legend>
4
			<b>Database: </b><i>{{db}}</i> - <b>table: </b><i>{{table}}</i>  
5
		</legend>
6
		<div class="panel panel-info" ng-repeat="field in details">
7
			<div class="panel-heading"><b>Field: </b><i>{{field.column_name}}</i></div>
8
			<table class="table table-condensed">
9
				<tr ng-repeat="(k, v) in field" ng-show="v">
10
					<th class="col-xs-3">{{k}}</th>
11
					<td class="col-xs-9">{{v}}</td>
12
				</tr>
13
			</table>
14
		</div>
15
	</fieldset>
16
</div>
modules/dnet-modular-database-ui/tags/dnet-modular-database-ui-1.0.0/src/main/resources/eu/dnetlib/web/resources/html/databases.html
1
<table class="table table-hover">
2
	<thead>
3
		<tr>
4
			<th>Database</th>
5
			<th class="text-center">is Managed</th>
6
			<th class="text-right">Operations</th>
7
		</tr>
8
	</thead>
9
	<tbody>
10
		<tr ng-repeat="db in databases">
11
			<td><a href="javascript:void(0)" ng-click="go('/db/'+db.dbName)">{{db.dbName}}</a></td>
12
			<td class="text-center">
13
				<span ng-show="db.managed">
14
					<span class="label label-success">YES</span> / <a href="javascript:void(0)" ng-click="manageDB(db.dbName, false)">NO</a>
15
				</span>
16
				<span ng-show="!db.managed">
17
					<a href="javascript:void(0)" ng-click="manageDB(db.dbName, true)">YES</a> / <span class="label label-danger">NO</span>
18
				</span>
19
	  		</td>
20
			<td class="text-right">
21
				<button class="btn btn-sm btn-primary" ng-click="go('/q/' + db.dbName)">
22
					SQL Query
23
				</button>
24
				<button class="btn btn-sm btn-warning" ng-click="changeIdentifiers(db.dbName)">
25
					Fix D-Net Identifiers				
26
				</button>
27
			</td>
28
		</tr>
29
	</tbody>
30
</table>
modules/dnet-modular-database-ui/tags/dnet-modular-database-ui-1.0.0/src/main/resources/eu/dnetlib/web/resources/html/tables.html
1
<table class="table table-hover">
2
	<thead>
3
		<tr>
4
			<th>Table</th>
5
			<th>Database</th>
6
			<th class="text-center">Data</th>
7
			<th class="text-center">Indices</th>
8
			<th class="text-center">Total</th>
9
			<th class="text-center">Log data</th>
10
			<th class="text-center">Type</th>
11
			<th class="text-center">is Managed</th>
12
			<th class="text-center">is Logged</th>
13
			<th class="text-center">Default value for Dnet-ID</th>
14
			<th class="text-right">Dump</th>
15
		</tr>
16
	</thead>
17
	<tbody>
18
		<tr ng-repeat="t in dbtables">
19
			<td><a href="javascript:void(0)" ng-click="go('/t/' + db + '/' + t.name)">{{t.name}}</a></td>
20
			<td>{{db}}</td>
21
			<td class="text-center">{{t.data}}</td>
22
			<td class="text-center">{{t.indices}}</td>
23
			<td class="text-center">{{t.total}}</td>
24
			<td class="text-center">{{t.logdata}}</td>
25
			<td class="text-center">
26
				<span ng-show="t.view" class="label label-default">VIEW</span>
27
				<span ng-show="!t.view" class="label label-primary">TABLE</span>
28
			</td>
29
			<td class="text-center">
30
				<span ng-show="!t.view">
31
					<span ng-show="t.managed">
32
						<span class="label label-success">YES</span> / <a href="javascript:void(0)" ng-click="changeTableManagement(db, t.name)">NO</a>
33
					</span>
34
					<span ng-show="!t.managed">
35
						<a href="javascript:void(0)" ng-click="changeTableManagement(db, t.name)">YES</a> / <span class="label label-danger">NO</span>
36
					</span>
37
				</span>
38
			</td>
39
			<td class="text-center">
40
				<span ng-show="!t.view && t.managed">
41
					<span ng-show="t.logged">
42
						<span class="label label-success">YES</span> / <a href="javascript:void(0)" ng-click="changeTableLog(db, t.name)">NO</a>
43
					</span>
44
					<span ng-show="!t.logged">
45
						<a href="javascript:void(0)" ng-click="changeTableLog(db, t.name)">YES</a> / <span class="label label-danger">NO</span>
46
					</span>
47
				</span>
48
			</td>
49
			<td class="text-center">
50
				<form class="form-inline" ng-show="!t.view && t.managed">
51
					<input class="form-control input-sm" type="text" readonly="readonly"  ng-model="t.dnetIdentifier" />
52
					<button class="btn btn-sm btn-primary" ng-click="changeIdentifiers(db, t.name)">fix</button>
53
				</form>
54
			</td>
55
			<td class="text-right">
56
				<a href="dumpTable.do?db={{db}}&t={{t.name}}" class="btn btn-sm btn-primary">as XML</a>
57
				<a href="dumpTableEPR.do?db={{db}}&t={{t.name}}" class="btn btn-sm btn-primary">as EPR</a>
58
			</td>
59
		</tr>
60
	</tbody>
61
</table>
modules/dnet-modular-database-ui/tags/dnet-modular-database-ui-1.0.0/src/main/resources/eu/dnetlib/web/resources/html/dbQuery.html
1
<form class="form-horizontal" role="form">
2
	<div class="form-group">
3
		<label for="dbInput" class="col-sm-2 control-label">Database</label>
4
		<div class="col-sm-4">
5
			<input class="form-control" id="dbInput" ng-model="db" readonly="readonly" />
6
		</div>
7
	</div>
8
	<div class="form-group">
9
		<label for="sqlInput" class="col-sm-2 control-label">SQL Query</label>
10
		<div class="col-sm-4">
11
			<textarea class="form-control" id="sqlInput" ng-model="sql"></textarea>
12
		</div>
13
	</div>
14
	<div class="form-group">
15
		<label for="limitInput" class="col-sm-2 control-label">Limit</label>
16
		<div class="col-sm-1">
17
			<input class="form-control" id="limitInput" ng-model="limit" />
18
		</div>
19
	</div>
20
	<div class="form-group">
21
		<div class="col-sm-offset-2 col-sm-4">
22
			<button class="btn btn-default" ng-click="searchSQL()">Search</button>
23
		</div>
24
	</div>
25
</form>
26

  
27
<div class="panel panel-primary" ng-repeat="r in results">
28
	<div class="panel-heading"><b>Result: </b><i>{{$index + 1}}</i></div>
29
	<div class="panel-body">
30
		{{r}}
31
	</div>
32
</div>
modules/dnet-modular-database-ui/tags/dnet-modular-database-ui-1.0.0/src/main/resources/eu/dnetlib/web/resources/js/db_manager_controllers.js
1
var dbManagerControllers = angular.module('dbManagerControllers', []);
2

  
3
function common_init($scope, $http, $sce, $location) {
4
	initSpinner();
5
	$scope.showError        = function(error)   { show_notification("error", error); }
6
	$scope.showNotification = function(message) { show_notification("info", message); }
7
	$scope.showSpinner      = function()        { showSpinner(); }
8
	$scope.hideSpinner      = function()        { hideSpinner(); }
9
	$scope.to_trusted       = function(html)    { return $sce.trustAsHtml(html); }
10
	$scope.go               = function(path)    { $location.path(path); }
11
	$scope.encodeValue      = function(val)     { return val; }
12
}
13

  
14
dbManagerControllers.controller('databasesCtrl', [
15
	'$scope', '$http', '$sce', '$location', 
16
	function ($scope, $http, $sce, $location) {
17
		common_init($scope, $http, $sce, $location);
18
		
19
		$scope.databases = [];
20
		
21
		$scope.listDatabases = function() {
22
			$scope.databases = [];
23

  
24
			$scope.showSpinner();
25
			
26
			$http.get('listDBs.do').success(function(data) {
27
				$scope.hideSpinner();
28
				$scope.databases = data;
29
		    }).error(function() {
30
	            $scope.showError('Something really bad must have happened to our fellow hamster..');
31
	            $scope.hideSpinner();
32
		    });
33
		}
34
		
35
		$scope.manageDB = function(db, b) {
36
			$scope.showSpinner();
37
			
38
			$http.get('manageDB.do?db=' + db + "&manage=" + b).success(function(data) {
39
				$scope.hideSpinner();
40
				$scope.showNotification("Management Mode Updated !");
41
				$scope.listDatabases();
42
		    }).error(function() {
43
	            $scope.showError('Something really bad must have happened to our fellow hamster..');
44
	            $scope.hideSpinner();
45
		    });
46
		}
47
		
48
		$scope.changeIdentifiers = function(db) {
49
			if (confirm("Are you sure ?")) {
50
				$scope.showSpinner();
51
				
52
				$http.get('changeIdentifiers.do?db=' + db).success(function(data) {
53
					$scope.hideSpinner();
54
					$scope.showNotification("Identifiers changed !");
55
					$scope.listDatabases();
56
			    }).error(function() {
57
		            $scope.showError('Something really bad must have happened to our fellow hamster..');
58
		            $scope.hideSpinner();
59
			    });
60
			}
61
		}
62
			
63
		$scope.listDatabases();
64
	}
65
]);
66

  
67
dbManagerControllers.controller('tablesCtrl', [
68
	'$scope', '$http', '$sce', '$location', '$routeParams',  
69
    function ($scope, $http, $sce, $location, $routeParams) {
70
		common_init($scope, $http, $sce, $location);
71
		
72
		$scope.db       = $routeParams.db;
73
		$scope.dbtables = [];
74
		
75
		$scope.listTables = function() {
76
			$scope.dbtables = [];
77

  
78
			$scope.showSpinner();
79
			
80
			$http.get('listTables.do?db=' + $scope.db).success(function(data) {
81
				$scope.hideSpinner();
82
				$scope.dbtables = data;
83
		    }).error(function() {
84
	            $scope.showError('Something really bad must have happened to our fellow hamster..');
85
	            $scope.hideSpinner();
86
		    });
87
		}
88
		
89
		$scope.changeTableManagement = function(db, t) {
90
			$scope.showSpinner();
91
			
92
			$http.get('changeTableManagement.do?db=' + db + "&t=" + t).success(function(data) {
93
				$scope.hideSpinner();
94
				$scope.showNotification("Management Mode Updated !");
95
				$scope.listTables();
96
		    }).error(function() {
97
	            $scope.showError('Something really bad must have happened to our fellow hamster..');
98
	            $scope.hideSpinner();
99
		    });
100
		}
101
		
102
		$scope.changeTableLog = function(db, t) {
103
			$scope.showSpinner();
104
			
105
			$http.get('changeTableLog.do?db=' + db + "&t=" + t).success(function(data) {
106
				$scope.hideSpinner();
107
				$scope.showNotification("Log Mode Updated !");
108
				$scope.listTables();
109
		    }).error(function() {
110
	            $scope.showError('Something really bad must have happened to our fellow hamster..');
111
	            $scope.hideSpinner();
112
		    });
113
		}
114
		
115
		$scope.changeIdentifiers = function(db, t) {
116
			if (confirm("Are you sure ?")) {
117
				$scope.showSpinner();
118
				
119
				$http.get('changeIdentifiers.do?db=' + db + '&t=' + t).success(function(data) {
120
					$scope.hideSpinner();
121
					$scope.showNotification("Identifiers changed !");
122
					$scope.listDatabases();
123
			    }).error(function() {
124
		            $scope.showError('Something really bad must have happened to our fellow hamster..');
125
		            $scope.hideSpinner();
126
			    });
127
			}
128
		}
129
		
130
		$scope.listTables();
131
	}
132
]);
133

  
134
dbManagerControllers.controller('tableDescCtrl', [
135
	'$scope', '$http', '$sce', '$location', '$routeParams',  
136
	function ($scope, $http, $sce, $location, $routeParams) {
137
		common_init($scope, $http, $sce, $location);
138
		
139
		$scope.db       = $routeParams.db;
140
		$scope.table    = $routeParams.t;
141
		$scope.details  = [];
142
		
143
		$scope.getTableDetails = function() {
144
			$scope.details = [];
145

  
146
			$scope.showSpinner();
147
			
148
			$http.get('describeTable.do?db=' + $scope.db + "&t=" + $scope.table).success(function(data) {
149
				$scope.hideSpinner();
150
				$scope.details = data;
151
		    }).error(function() {
152
	            $scope.showError('Something really bad must have happened to our fellow hamster..');
153
	            $scope.hideSpinner();
154
		    });
155
		}
156
		
157
		$scope.getTableDetails();
158
	}
159

  
160
]);
161

  
162
dbManagerControllers.controller('dbQueryCtrl', [
163
	'$scope', '$http', '$sce', '$location', '$routeParams',  
164
	function ($scope, $http, $sce, $location, $routeParams) {
165
		common_init($scope, $http, $sce, $location);
166
                                            		
167
        $scope.db = $routeParams.db;
168
        $scope.sql = 'SELECT 1';
169
        $scope.limit = 100;
170
        $scope.results = [];
171
        
172
        $scope.searchSQL = function() {
173
			$scope.results = [];
174

  
175
			$scope.showSpinner();
176
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
177
            $http.post('query.do', $.param({
178
                    'db'    : $scope.db,
179
                    'limit' : $scope.limit,
180
                    'query' : $scope.sql
181
            })).success(function(data) {
182
				$scope.hideSpinner();
183
				$scope.results = data;
184
		    }).error(function() {
185
	            $scope.showError('Something really bad must have happened to our fellow hamster..');
186
	            $scope.hideSpinner();
187
		    });
188
		}
189
        
190
	}
191
]);
modules/dnet-modular-database-ui/tags/dnet-modular-database-ui-1.0.0/src/main/resources/eu/dnetlib/web/resources/js/db_manager.js
1
var module = angular.module('dbManager', ['ngRoute', 'dbManagerControllers']);
2

  
3
module.config([
4
	'$routeProvider',
5
	function($routeProvider) {
6
		$routeProvider
7
			.when('/dbs',      { templateUrl: '../resources/html/databases.html', controller: 'databasesCtrl' })
8
			.when('/db/:db',   { templateUrl: '../resources/html/tables.html',    controller: 'tablesCtrl'    })
9
			.when('/t/:db/:t', { templateUrl: '../resources/html/tableDesc.html', controller: 'tableDescCtrl' })
10
			.when('/q/:db',    { templateUrl: '../resources/html/dbQuery.html',   controller: 'dbQueryCtrl'   })
11
			.otherwise({ redirectTo: '/dbs' });
12
	}
13
]);
modules/dnet-modular-database-ui/tags/dnet-modular-database-ui-1.0.0/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
	<parent>
4
		<groupId>eu.dnetlib</groupId>
5
		<artifactId>dnet-parent</artifactId>
6
		<version>1.0.0</version>
7
	</parent>
8
	<modelVersion>4.0.0</modelVersion>
9
	<groupId>eu.dnetlib</groupId>
10
	<artifactId>dnet-modular-database-ui</artifactId>
11
	<packaging>jar</packaging>
12
	<version>1.0.0</version>
13
	<scm>
14
	  <developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/dnet-modular-database-ui/tags/dnet-modular-database-ui-1.0.0</developerConnection>
15
	</scm>
16
	<dependencies>
17
		<dependency>
18
			<groupId>commons-fileupload</groupId>
19
			<artifactId>commons-fileupload</artifactId>
20
			<version>1.3.1</version>
21
		</dependency>
22
		<dependency>
23
			<groupId>eu.dnetlib</groupId>
24
			<artifactId>dnet-modular-ui</artifactId>
25
			<version>[2.0.0,3.0.0)</version>
26
		</dependency>
27
		<dependency>
28
			<groupId>junit</groupId>
29
			<artifactId>junit</artifactId>
30
			<version>${junit.version}</version>
31
			<scope>test</scope>
32
		</dependency>
33
		<dependency>
34
			<groupId>eu.dnetlib</groupId>
35
			<artifactId>cnr-enabling-database-service</artifactId>
36
			<version>[1.0.0,)</version>
37
		</dependency>
38
		<dependency>
39
			<groupId>javax.servlet</groupId>
40
			<artifactId>javax.servlet-api</artifactId>
41
			<version>${javax.servlet.version}</version>
42
			<scope>provided</scope>
43
		</dependency>
44
	</dependencies>
45
</project>
modules/dnet-modular-database-ui/tags/dnet-modular-database-ui-2.0.0/deploy.info
1
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/dnet-modular-database-ui/trunk/", "deploy_repository": "dnet4-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet4-snapshots", "name": "dnet-modular-database-ui"}
modules/dnet-modular-database-ui/tags/dnet-modular-database-ui-2.0.0/src/main/java/eu/dnetlib/functionality/modular/ui/db/DbManagerEntryPointController.java
1
package eu.dnetlib.functionality.modular.ui.db;
2

  
3
import javax.servlet.http.HttpServletRequest;
4
import javax.servlet.http.HttpServletResponse;
5

  
6
import org.springframework.ui.ModelMap;
7

  
8
import eu.dnetlib.functionality.modular.ui.ModuleEntryPoint;
9

  
10
public class DbManagerEntryPointController extends ModuleEntryPoint {
11

  
12
	@Override
13
	protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
14

  
15
	}
16

  
17
}
modules/dnet-modular-database-ui/tags/dnet-modular-database-ui-2.0.0/src/main/java/eu/dnetlib/functionality/modular/ui/db/DbManagerInternalController.java
1
package eu.dnetlib.functionality.modular.ui.db;
2

  
3
import java.io.IOException;
4
import java.io.StringReader;
5
import java.util.ArrayList;
6
import java.util.HashMap;
7
import java.util.List;
8
import java.util.Map;
9

  
10
import javax.annotation.Resource;
11
import javax.servlet.ServletOutputStream;
12
import javax.servlet.ServletResponse;
13
import javax.servlet.http.HttpServletResponse;
14

  
15
import org.apache.commons.io.IOUtils;
16
import org.springframework.jdbc.support.rowset.SqlRowSet;
17
import org.springframework.stereotype.Controller;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff