Project

General

Profile

« Previous | Next » 

Revision 45241

codebase used to migrate to java8 the production system

View differences:

modules/dnet-modular-cleaning-rules-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-cleaning-rules-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-cleaning-rules-ui"}
modules/dnet-modular-cleaning-rules-ui/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/cleaningrules/model/Rule.java
1
package eu.dnetlib.functionality.modular.ui.cleaningrules.model;
2

  
3
import java.util.List;
4

  
5
public class Rule {
6
	private String xpath;
7
	private List<String> appliedVocabularies;
8
	private boolean strict;
9

  
10
	public Rule() {
11
	}
12

  
13
	public Rule(String xpath, List<String> appliedVocabularies, boolean strict) {
14
		super();
15
		this.xpath = xpath;
16
		this.appliedVocabularies = appliedVocabularies;
17
		this.strict = strict;
18
	}
19

  
20
	public String getXpath() {
21
		return xpath;
22
	}
23

  
24
	public void setXpath(String xpath) {
25
		this.xpath = xpath;
26
	}
27

  
28
	public List<String> getAppliedVocabularies() {
29
		return appliedVocabularies;
30
	}
31

  
32
	public void setAppliedVocabularies(List<String> appliedVocabularies) {
33
		this.appliedVocabularies = appliedVocabularies;
34
	}
35

  
36
	public boolean isStrict() {
37
		return strict;
38
	}
39

  
40
	public void setStrict(boolean strict) {
41
		this.strict = strict;
42
	}
43

  
44
}
modules/dnet-modular-cleaning-rules-ui/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/cleaningrules/model/Cleaner.java
1
package eu.dnetlib.functionality.modular.ui.cleaningrules.model;
2

  
3
public class Cleaner {
4
	private String id;
5
	private String idHtml;
6
	private String name;
7
	private String description;
8

  
9
	public Cleaner() {
10
	}
11

  
12
	public Cleaner(String id, String idHtml, String name, String description) {
13
		super();
14
		this.id = id;
15
		this.idHtml = idHtml;
16
		this.name = name;
17
		this.description = description;
18
	}
19

  
20
	public String getId() {
21
		return id;
22
	}
23

  
24
	public void setId(String id) {
25
		this.id = id;
26
	}
27

  
28
	public String getIdHtml() {
29
		return idHtml;
30
	}
31

  
32
	public void setIdHtml(String idHtml) {
33
		this.idHtml = idHtml;
34
	}
35

  
36
	public String getName() {
37
		return name;
38
	}
39

  
40
	public void setName(String name) {
41
		this.name = name;
42
	}
43

  
44
	public String getDescription() {
45
		return description;
46
	}
47

  
48
	public void setDescription(String description) {
49
		this.description = description;
50
	}
51

  
52
}
modules/dnet-modular-cleaning-rules-ui/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/cleaningrules/adapters/RuleAdapter.java
1
package eu.dnetlib.functionality.modular.ui.cleaningrules.adapters;
2

  
3
import java.util.ArrayList;
4
import java.util.Arrays;
5
import java.util.List;
6

  
7
import com.google.common.base.Function;
8

  
9
import eu.dnetlib.functionality.modular.ui.cleaningrules.controllers.CleaningRuleController;
10
import eu.dnetlib.functionality.modular.ui.cleaningrules.model.Rule;
11

  
12
/**
13
 * This class is used in {@link CleaningRuleController} when un-marshaling of a {@link Rule} object is needed.
14
 * 
15
 * @author Andrea Mannocci
16
 */
17
public class RuleAdapter implements Function<String, Rule> {
18

  
19
	@Override
20
	public Rule apply(final String s) {
21
		String[] tokens = s.split("§§§");
22
		return new Rule(tokens[0].trim(), // xpath
23
				parseVocabularyList(tokens[1].trim()), // vocabularies
24
				Boolean.valueOf(tokens[2].trim()));// strict
25
	}
26

  
27
	List<String> parseVocabularyList(final String s) {
28
		return new ArrayList<String>(Arrays.asList(s.split(", ")));
29
	}
30

  
31
}
modules/dnet-modular-cleaning-rules-ui/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/cleaningrules/adapters/CleanerAdapter.java
1
package eu.dnetlib.functionality.modular.ui.cleaningrules.adapters;
2

  
3
import com.google.common.base.Function;
4

  
5
import eu.dnetlib.functionality.modular.ui.cleaningrules.controllers.CleaningRuleController;
6
import eu.dnetlib.functionality.modular.ui.cleaningrules.model.Cleaner;
7

  
8
/**
9
 * This class is used in {@link CleaningRuleController} when un-marshaling of
10
 * a {@link Cleaner} object is needed.
11
 * @author Andrea Mannocci
12
 */
13
public class CleanerAdapter implements Function<String, Cleaner> {
14

  
15
	public Cleaner apply(String s) {
16
		String[] tokens = s.split("§§§");
17
		return new Cleaner(		tokens[0].trim(), 
18
								tokens[0].trim().replaceAll("\\W", ""), 
19
								tokens[1].trim(), 
20
								tokens[2].trim());
21
	}
22

  
23
}
modules/dnet-modular-cleaning-rules-ui/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/cleaningrules/controllers/EntryPointController.java
1
package eu.dnetlib.functionality.modular.ui.cleaningrules.controllers;
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 EntryPointController extends ModuleEntryPoint {
11

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

  
17
}
modules/dnet-modular-cleaning-rules-ui/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/cleaningrules/controllers/CleaningRuleController.java
1
package eu.dnetlib.functionality.modular.ui.cleaningrules.controllers;
2

  
3
import java.io.IOException;
4
import java.io.StringReader;
5
import java.lang.reflect.Type;
6
import java.util.ArrayList;
7
import java.util.List;
8

  
9
import javax.annotation.Resource;
10
import javax.servlet.http.HttpServletRequest;
11
import javax.servlet.http.HttpServletResponse;
12
import javax.xml.bind.JAXBException;
13

  
14
import org.antlr.stringtemplate.StringTemplate;
15
import org.apache.commons.io.IOUtils;
16
import org.apache.commons.lang.StringEscapeUtils;
17
import org.apache.commons.logging.Log;
18
import org.apache.commons.logging.LogFactory;
19
import org.springframework.stereotype.Controller;
20
import org.springframework.web.bind.annotation.RequestMapping;
21
import org.springframework.web.bind.annotation.RequestMethod;
22
import org.springframework.web.bind.annotation.RequestParam;
23

  
24
import com.google.common.collect.Lists;
25
import com.google.gson.Gson;
26
import com.google.gson.reflect.TypeToken;
27

  
28
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
29
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
30
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException;
31
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
32
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
33
import eu.dnetlib.functionality.modular.ui.cleaningrules.adapters.CleanerAdapter;
34
import eu.dnetlib.functionality.modular.ui.cleaningrules.adapters.RuleAdapter;
35
import eu.dnetlib.functionality.modular.ui.cleaningrules.model.Cleaner;
36
import eu.dnetlib.functionality.modular.ui.cleaningrules.model.Rule;
37
import eu.dnetlib.miscutils.datetime.DateUtils;
38

  
39
@Controller
40
public class CleaningRuleController {
41

  
42
	private final Log log = LogFactory.getLog(CleaningRuleController.class);
43

  
44
	@Resource
45
	private UniqueServiceLocator serviceLocator;
46

  
47
	@RequestMapping("/ui/cleaners.json")
48
	public void getCleaners(final HttpServletResponse response) throws ISLookUpException, IOException {
49
		log.info("cleaners.json");
50
		String query = "for $x in collection('/db/DRIVER/CleanerDSResources/CleanerDSResourceType') order by $x//CLEANER_NAME "
51
				+ "return concat ($x//RESOURCE_IDENTIFIER/@value,' §§§ ',$x//CLEANER_NAME,' §§§ ',$x//CLEANER_DESCRIPTION)";
52

  
53
		List<Cleaner> cleaners = Lists.transform(serviceLocator.getService(ISLookUpService.class).quickSearchProfile(query), new CleanerAdapter());
54
		IOUtils.copy(new StringReader(new Gson().toJson(cleaners)), response.getOutputStream());
55
	}
56

  
57
	@RequestMapping("/ui/rules.json")
58
	public void getRules(final HttpServletResponse response, @RequestParam(value = "cleanerId", required = true) final String cleanerId)
59
			throws ISLookUpException, IOException {
60
		log.info("rules.json?cleanerId=" + cleanerId);
61

  
62
		String query = "for $x in /*[.//RESOURCE_IDENTIFIER/@value=\"{cleanerId}\"]//RULE order by $x/@xpath "
63
				+ "return concat ($x/@xpath,' §§§ ',$x/@vocabularies,' §§§ ',$x/@strict)";
64
		query = query.replace("{cleanerId}", cleanerId);
65

  
66
		List<Rule> rules = Lists.transform(serviceLocator.getService(ISLookUpService.class).quickSearchProfile(query), new RuleAdapter());
67
		IOUtils.copy(new StringReader(new Gson().toJson(rules)), response.getOutputStream());
68
	}
69

  
70
	@RequestMapping(value = "/ui/createCleaner", method = RequestMethod.POST)
71
	public void createCleaner(final HttpServletResponse response, final HttpServletRequest request) throws IOException, ISRegistryException, JAXBException {
72
		log.info("create vocabulary");
73

  
74
		Cleaner cleaner = new Gson().fromJson(request.getReader(), Cleaner.class);
75

  
76
		StringTemplate st = new StringTemplate(IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/functionality/modular/templates/cleaner.xml.st")));
77
		st.setAttribute("name", cleaner.getName());
78
		st.setAttribute("description", cleaner.getDescription());
79
		st.setAttribute("date", DateUtils.now_ISO8601());
80
		String newVocabularyId = serviceLocator.getService(ISRegistryService.class).registerProfile(st.toString());
81

  
82
		IOUtils.copy(new StringReader(newVocabularyId), response.getOutputStream());
83
	}
84

  
85
	@RequestMapping(value = "/ui/commitCleanerInfo", method = RequestMethod.POST)
86
	public void commitCleanerInfo(final HttpServletResponse response,
87
			final HttpServletRequest request,
88
			@RequestParam(value = "cleanerId", required = true) final String cleanerId) throws IOException, ISRegistryException, JAXBException {
89
		log.info("committing cleaner info id = " + cleanerId);
90

  
91
		Cleaner cleaner = new Gson().fromJson(request.getReader(), Cleaner.class);
92

  
93
		String xml = "<CLEANER_NAME>{name}</CLEANER_NAME>";
94
		xml = xml.replace("{name}", StringEscapeUtils.escapeXml(cleaner.getName()));
95
		serviceLocator.getService(ISRegistryService.class).updateProfileNode(cleanerId, "//CLEANER_NAME", xml);
96

  
97
		xml = "<CLEANER_DESCRIPTION>{desc}</CLEANER_DESCRIPTION>";
98
		xml = xml.replace("{desc}", StringEscapeUtils.escapeXml(cleaner.getDescription()));
99
		serviceLocator.getService(ISRegistryService.class).updateProfileNode(cleanerId, "//CLEANER_DESCRIPTION", xml);
100

  
101
		IOUtils.copy(new StringReader("Vocabulary info saved correctly!"), response.getOutputStream());
102
	}
103

  
104
	@RequestMapping(value = "/ui/commitCleaner", method = RequestMethod.POST)
105
	public void commitRules(final HttpServletResponse response,
106
			final HttpServletRequest request,
107
			@RequestParam(value = "cleanerId", required = true) final String cleanerId) throws IOException, JAXBException, ISRegistryException {
108
		log.info("committing rules for cleaner id=" + cleanerId);
109

  
110
		Type collectionType = new TypeToken<ArrayList<Rule>>() {}.getType();
111
		ArrayList<Rule> rules = new Gson().fromJson(request.getReader(), collectionType);
112

  
113
		// prepare terms for XML
114
		for (Rule r : rules) {
115
			r.setXpath(StringEscapeUtils.escapeXml(r.getXpath()));
116
			List<String> vocabulariesXmlAdapted = new ArrayList<String>();
117
			for (String v : r.getAppliedVocabularies()) {
118
				vocabulariesXmlAdapted.add(StringEscapeUtils.escapeXml(v));
119
			}
120
			r.setAppliedVocabularies(vocabulariesXmlAdapted);
121
		}
122

  
123
		StringTemplate st = new StringTemplate(IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/functionality/modular/templates/rules.xml.st")));
124
		st.setAttribute("rules", rules);
125
		serviceLocator.getService(ISRegistryService.class).updateProfileNode(cleanerId, "//CLEANER_RULES", st.toString());
126

  
127
		IOUtils.copy(new StringReader("Cleaner saved correctly!"), response.getOutputStream());
128
	}
129

  
130
	@RequestMapping(value = "/ui/dropCleaner", method = RequestMethod.GET)
131
	public void dropCleaner(final HttpServletResponse response,
132
			final HttpServletRequest request,
133
			@RequestParam(value = "cleanerId", required = true) final String cleanerId) throws IOException, ISRegistryException, JAXBException {
134
		log.info("delete cleaner id=" + cleanerId);
135

  
136
		serviceLocator.getService(ISRegistryService.class).deleteProfile(cleanerId);
137
	}
138
}
modules/dnet-modular-cleaning-rules-ui/trunk/src/main/resources/eu/dnetlib/functionality/modular/ui/webContext-modular-ui-cleaning-rules.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<beans xmlns="http://www.springframework.org/schema/beans"
4
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
5
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
6

  
7
	<bean name="/ui/cleaningRules.do"
8
		class="eu.dnetlib.functionality.modular.ui.cleaningrules.controllers.EntryPointController"
9
		p:menu="Cleaning rules editor" 
10
		p:title="D-NET cleaning rules editor"
11
		p:description="D-NET cleaning rules editor" 
12
		p:group="Configuration">
13
		<property name="permissionLevels">
14
			<set>
15
				<value>USER</value>
16
			</set>
17
		</property>
18
	</bean>
19

  
20
</beans>
modules/dnet-modular-cleaning-rules-ui/trunk/src/main/resources/eu/dnetlib/functionality/modular/ui/views/ui/cleaningRules.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/cleaningRules.js" ></script>
4
}, body={
5
	<div ng-app="cleaningRulesUI" ng-controller="cleaningRulesCtrl">
6
		<div class="row">
7
			<div class="column col-xs-12 col-sm-12 col-md-3 col-lg-3">
8
				<form role="form" class="form-inline">
9
					<button type="button" class="btn btn-default" ng-click="selectedCleanerIndex = null; showInfoModal()">
10
						New cleaner <span class="glyphicon glyphicon-plus"></span>
11
					</button>
12
					<div class="form-group pull-right">
13
						<input type="text" class="form-control" ng-model="cleanerFilter" placeholder="Filter by...">
14
					</div>
15
				</form>
16
				<br/><br/>
17
				<ul class="nav nav-pills nav-stacked">
18
					<li ng-repeat="cleaner in cleaners | filter:cleanerFilter"
19
						ng-class="{'active': (selectedCleanerIndex != null) && (cleaner.id == cleaners[selectedCleanerIndex].id)}"
20
						ng-click="loadRules(cleaner)">
21
							<a>{{cleaner.name}}<span class="glyphicon glyphicon-chevron-right pull-right"/></a>
22
					</li>
23
				</ul>
24
			</div>
25
			<div class="col-xs-12 col-sm-12 col-md-9 col-lg-9" ng-show="rules != null && selectedCleanerIndex != null">
26
				<form role="form" class="form-inline">
27
					<div class="btn-group">
28
						<button type="button" class="btn btn-default" ng-click="showInfoModal()">
29
							Edit info <span class="glyphicon glyphicon-book"></span>
30
						</button>
31
						<button type="button" class="btn btn-default" ng-click="showRuleModal(null)">
32
							New rule <span class="glyphicon glyphicon-pencil"></span>
33
						</button>
34
						<button type="button" class="btn btn-default" ng-click="commit()">
35
							Commit <span class="glyphicon glyphicon-floppy-saved"></span>
36
						</button>
37
						<button type="button" class="btn btn-default" ng-click="reloadRules()">
38
							Discard all <span class="glyphicon glyphicon-repeat"></span>
39
						</button>
40
						<button type="button" class="btn btn-default" ng-click="dropCleaner()">
41
							Drop cleaner <span class="glyphicon glyphicon-trash"></span>
42
						</button>
43
					</div>
44
					<div class="form-group pull-right">
45
						<input type="text" class="form-control" ng-model="ruleFilter" placeholder="Filter by...">
46
					</div>
47
				</form>
48
				<br><br>
49
	            <table class="table table-bordered">
50
	            	<thead>
51
	            	    <tr>
52
	            	     	<th>XPath</th>
53
	            	      	<th>Applied vocabularies</th>
54
	            	      	<th>Strict</th>
55
	            	      	<th>Actions</th>
56
	            	    </tr>
57
            	  	</thead>
58
            	  	<tbody>
59
	        	  		<tr ng-repeat="rule in rules | filter:ruleFilter">
60
					      	<td class="col-xs-7">{{rule.xpath}}</td>
61
					      	<td class="col-xs-3">
62
						      	<ul>
63
						      		<li ng-repeat="vocabulary in rule.appliedVocabularies">{{vocabulary}} <span ng-show="!isValid(vocabulary)" class="label label-important">Missing!!</span></li>
64
						      	</ul>
65
					      	</td>
66
					      	<td class="col-xs-1">
67
					      		<span class="glyphicon" ng-class="{'glyphicon-ok': rule.strict, 'glyphicon-remove': !rule.strict}"></span>
68
					      	</td>
69
					      	<td class="col-xs-1">
70
					      		<button type="button" class="btn btn-xs btn-primary"  ng-click="showRuleModal(rule)">
71
					      			<span class="glyphicon glyphicon-pencil"></span>
72
				      			</button>
73
					      		<button type="button" class="btn btn-xs btn-danger" ng-click="deleteRule(rule)">
74
					      			<span class="glyphicon glyphicon-trash"></span>
75
				      			</button>
76
				      		</td>
77
					    </tr>
78
            	  	</tbody>
79
				</table>
80
			</div>
81
		</div>
82
			
83
		<!-- infoModal -->
84
		<div id="infoModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="infoModalLabel" aria-hidden="true">
85
			<div class="modal-dialog">
86
				<div class="modal-content">
87
					<div class="modal-header">
88
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
89
						<h4 id="infoModalLabel">Cleaner information</h4>
90
					</div>
91
					<div class="modal-body">
92
						<form name="infoForm" class="form-horizontal" role="form">
93
							<div class="form-group" ng-class="{'has-warning': !modalInfo.name}">
94
								<label class="col-sm-4 control-label" for="cleanerName">Cleaner name</label>
95
							    <div class="col-sm-8">
96
							      	<input class="form-control" ng-disabled="selectedCleanerIndex != null" type="text" name="cleanerName" placeholder="cleaner name" ng-model="modalInfo.name">
97
							    </div>
98
							</div>
99
							<div class="form-group">
100
								<label class="col-sm-4 control-label" for="cleanerDescription">Cleaner description</label>
101
								<div class="col-sm-8">
102
									<input class="form-control" ng-disabled="selectedCleanerIndex != null" type="text" name="cleanerDescription" placeholder="cleaner description" ng-model="modalInfo.description">
103
								</div>
104
							</div>
105
						</form>
106
					</div>
107
					<div class="modal-footer">
108
						<button class="btn btn-primary" ng-disabled="!modalInfo.name" ng-click="editInfo()">Save</button>
109
					</div>
110
				</div>
111
			</div>
112
		</div> <!-- info modal -->
113
			
114
		<!-- Le rule modal -->
115
		<div id="ruleModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="ruleModalLabel" aria-hidden="true">
116
			<div class="modal-dialog  modal-lg">
117
				<div class="modal-content">
118
					<div class="modal-header">
119
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
120
						<h4 id="ruleModalLabel">Rule editor</h4>
121
					</div>
122
					<div class="modal-body">
123
						<form name="infoForm" class="form-horizontal" role="form">
124
							<div class="form-group" ng-class="{'has-warning': !modalRule.xpath}">
125
								<label class="col-sm-4 control-label">XPath</label>
126
								<div class="col-sm-8">
127
									<textarea rows="3" class="col-xs-12" type="text" placeholder="xpath" ng-model="modalRule.xpath"></textarea> 
128
								</div>
129
							</div>
130
							<div class="form-group">
131
								<label class="col-sm-4 control-label">Strict</label>
132
								<div class="col-sm-8">
133
									<label class="radio"><input type="radio" ng-model="modalRule.strict" ng-value="true"> True</label>
134
									<label class="radio"><input type="radio" ng-model="modalRule.strict" ng-value="false" checked> False</label>
135
								</div>
136
							</div>
137
							<div class="form-group">
138
								<label class="col-sm-4 control-label">Vocabularies applied</label>
139
								<div class="col-sm-8">
140
									<input type="text" class="form-control" ng-model="vocabularyFilter" placeholder="Filter by...">
141
									<label class="checkbox" ng-repeat="vocabulary in modalRule.vocabularies | filter:vocabularyFilter"><input type="checkbox" ng-model="vocabulary.checked"> {{vocabulary.name}}</label>
142
								</div>
143
							</div>
144
						</form>
145
					</div>
146
					<div class="modal-footer">
147
						<button type="button" class="btn btn-primary" ng-disabled="!modalRule.xpath" ng-click="editRule()">Save</button>
148
					</div>
149
				</div>
150
			</div>
151
		</div> <!-- rule modal -->
152
			
153
	</div>
154
} )$
modules/dnet-modular-cleaning-rules-ui/trunk/src/main/resources/eu/dnetlib/functionality/modular/templates/cleaner.xml.st
1
<?xml version="1.0" encoding="UTF-8"?>
2
<RESOURCE_PROFILE>
3
	<HEADER>
4
		<RESOURCE_IDENTIFIER value="" />
5
		<RESOURCE_TYPE value="CleanerDSResourceType" />
6
		<RESOURCE_KIND value="CleanerDSResources" />
7
		<RESOURCE_URI value="" />
8
		<DATE_OF_CREATION value="$date$" />
9
	</HEADER>
10
	<BODY>
11
		<CONFIGURATION>
12
			<CLEANER_NAME>$name$</CLEANER_NAME>
13
			<CLEANER_DESCRIPTION>$description$</CLEANER_DESCRIPTION>
14
			<CLEANER_RULES>
15
				<RULE xpath="//whatever" vocabularies="" strict="true" />
16
			</CLEANER_RULES>
17
		</CONFIGURATION>
18
		<STATUS>
19
			<LAST_UPDATE value="$date$" />
20
		</STATUS>
21
		<SECURITY_PARAMETERS>String</SECURITY_PARAMETERS>
22
	</BODY>
23
</RESOURCE_PROFILE>
modules/dnet-modular-cleaning-rules-ui/trunk/src/main/resources/eu/dnetlib/functionality/modular/templates/rules.xml.st
1
<CLEANER_RULES>
2
	$rules:{r|
3
	<RULE vocabularies='$r.appliedVocabularies:{v|$v$};separator=", "$' xpath="$r.xpath$" strict="$r.strict$" />
4
	}$
5
</CLEANER_RULES>
modules/dnet-modular-cleaning-rules-ui/trunk/src/main/resources/eu/dnetlib/web/resources/js/cleaningRules.js
1
var module = angular.module('cleaningRulesUI', []);
2

  
3
module.directive('tooltip', function() {
4
    return {
5
    	restrict: 'A',
6
    	link: function(scope, element, attrs)
7
        {
8
            $(element).tooltip();
9
        }
10
    }
11
});
12

  
13
function cleaningRulesCtrl($scope, $http) {
14
	$scope.rules = [];
15
	$scope.modalInfo = {};
16
	$scope.modalCleaner = {};
17
	$scope.modalRule = {};
18

  
19
	initSpinner();
20
	showSpinner();
21
	
22
	$scope.startup = function() {
23
		$http.get('cleaners.json')
24
		.success(
25
			function(data) {
26
	    		$scope.cleaners = data;
27
	    		// load vocabularies
28
			    $http.get('vocabularies.json')
29
				.success(
30
					function(data) {
31
			    		$scope.modalRule.vocabularies = data;
32
			    		hideSpinner();
33
			 		})
34
				.error(
35
			        function() {
36
			        	show_notification("error",'An error occurred while fetching available vocabularies..');
37
			        	hideSpinner();
38
			        }
39
			    );
40
	 		})
41
		.error(
42
	        function() {
43
	        	show_notification("error",'An error occurred while fetching registered Cleaner Service Profiles');
44
	        	hideSpinner();
45
	        }
46
	    );
47
	}
48
	
49
	$scope.startup();
50

  
51
    $scope.loadRules = function(cleaner) {
52
    	showSpinner();
53
		$http.get('rules.json?cleanerId=' + cleaner.id)
54
        .success(
55
            function(data) {
56
                $scope.selectedCleanerIndex = $scope.cleaners.indexOf(cleaner);
57
                $scope.rules = data;
58
                hidePermanotice();
59
                hideSpinner();
60
            }
61
        ).error(
62
            function() {
63
            	show_notification("error",'An error occurred while fetching cleaning rules for cleaner ' + cleaner.name);
64
            	hideSpinner();
65
            }
66
        );	
67
    }
68

  
69
    $scope.reloadRules = function() {
70
        $scope.loadRules($scope.cleaners[$scope.selectedCleanerIndex]);
71
    }
72
    
73
    /*---------ADD/EDIT---------*/
74
	$scope.showInfoModal = function() {
75
		if ($scope.selectedCleanerIndex != null) {
76
			// show modal for editing info of existing vocabulary
77
			$scope.modalInfo.name = $scope.cleaners[$scope.selectedCleanerIndex].name;
78
			$scope.modalInfo.description = $scope.cleaners[$scope.selectedCleanerIndex].description;
79
		} else {
80
			// show modal for new vocabulary
81
			$scope.modalInfo.name = '';
82
			$scope.modalInfo.description = '';
83
			hidePermanotice();
84
		}
85
		$('#infoModal').modal();
86
	}
87

  
88
    $scope.showRuleModal = function(rule) {
89
    	$scope.selectedRuleIndex = $scope.rules.indexOf(rule);
90
		if(rule != null) {
91
			$scope.modalRule.xpath = rule.xpath;
92
			$scope.modalRule.strict = rule.strict;
93
			$scope.tickAppliedVocabularies(rule.appliedVocabularies);
94
		} else {
95
			// reset modal variables
96
			$scope.modalRule.xpath = '';
97
			$scope.modalRule.strict = '';
98
			$scope.tickAppliedVocabularies(null);
99
		}
100
		$('#ruleModal').modal();
101
    }
102
    
103
	$scope.editInfo = function() {
104
		showSpinner();
105
		if ($scope.selectedCleanerIndex == null) {
106
			// new cleaner
107
			$http.post('createCleaner', {"name" : $scope.modalInfo.name, "description" : $scope.modalInfo.description})
108
				.success(
109
					function(data) {
110
						show_notification("success", "Cleaner created successfully!");
111
						$scope.cleaners.push({
112
							"id" : data,
113
							"name" : $scope.modalInfo.name,
114
							"description" : $scope.modalInfo.description});
115
						$scope.startup();
116
						hideSpinner();
117
					})
118
				.error(
119
					function() {
120
						show_notification("error", "An error occurred while creating the cleaner profile");
121
						hideSpinner();
122
					});
123
		} else {
124
			// edit existing cleaner info
125
			$http.post('commitCleanerInfo?cleanerId=' + $scope.cleaners[$scope.selectedCleanerIndex].id, {
126
						"name" : $scope.modalInfo.name, 
127
						"description" : $scope.modalInfo.description})
128
				.success(
129
					function(data) {
130
						// update model
131
						$scope.cleaners[$scope.selectedCleanerIndex].name = $scope.modalInfo.name;
132
						$scope.cleaners[$scope.selectedCleanerIndex].description = $scope.modalInfo.description;
133
						show_notification("success", data);
134
						$scope.startup();
135
						hideSpinner();
136
					})
137
				.error(
138
					function() {
139
						show_notification("error", "Cannot edit info..");
140
						hideSpinner();
141
					});
142
		}
143
		// dismiss modal
144
		$('.modal').modal('hide');
145
	}
146

  
147
	$scope.editRule = function() {
148
		var appliedVocabularies = [];
149
		for (var i in $scope.modalRule.vocabularies) {
150
			if ($scope.modalRule.vocabularies[i].checked)
151
				appliedVocabularies.push($scope.modalRule.vocabularies[i].name);
152
		}
153

  
154
		if ($scope.selectedRuleIndex == -1) {
155
			// new rule being added
156
			$scope.rules.push({"xpath":$scope.modalRule.xpath,"strict":$scope.modalRule.strict,"appliedVocabularies":appliedVocabularies});
157
		} else {
158
			// existing rule being updated
159
			$scope.rules[$scope.selectedRuleIndex].xpath = $scope.modalRule.xpath;
160
			$scope.rules[$scope.selectedRuleIndex].strict = $scope.modalRule.strict;
161
			$scope.rules[$scope.selectedRuleIndex].appliedVocabularies = appliedVocabularies;
162
		}
163
		// dismiss modal
164
		$('.modal').modal('hide');
165
		showPermanotice("Uncommitted changes!");
166
    }
167
	
168
	/*---------DELETE---------*/
169
	$scope.dropCleaner = function() {
170
		showSpinner();
171
		$http.get('dropCleaner?cleanerId=' + $scope.cleaners[$scope.selectedCleanerIndex].id)
172
			.success(
173
				function() {
174
					$scope.cleaners.splice($scope.selectedCleanerIndex, 1);
175
					$scope.selectedCleanerIndex = null;
176
					show_notification('success', "Vocabulary deleted successfully!");
177
					hideSpinner();
178
				})
179
			.error(
180
				function() {
181
					hideSpinner();
182
					show_notification('error', "Cannot drop cleaner "+$scope.cleaners[$scope.selectedCleanerIndex].name);
183
				});
184
	}
185

  
186
    $scope.deleteRule = function(rule) {
187
    	var ruleIndex = $scope.rules.indexOf(rule);
188
    	$scope.rules.splice(ruleIndex,1);
189
    	showPermanotice("Uncommitted changes!");
190
    }
191
    
192
    /*-----------UTILITY----------*/
193
    $scope.tickAppliedVocabularies = function(appliedVocabularies) {
194
    	if (appliedVocabularies == null) {
195
    		// i.e. new rule
196
    		for (var i in $scope.modalRule.vocabularies){
197
    			$scope.modalRule.vocabularies[i].checked = false;
198
    		}
199
    	} else {
200
    		// i.e. existing rule
201
    		for (var i in $scope.modalRule.vocabularies){
202
    			for (var j in appliedVocabularies) {
203
    				if ($scope.modalRule.vocabularies[i].name == appliedVocabularies[j]) {
204
    					$scope.modalRule.vocabularies[i].checked = true;
205
    					break;
206
    				} else {
207
    					$scope.modalRule.vocabularies[i].checked = false;
208
    				}
209
    			}
210
    		}
211
    	}
212
    }
213

  
214
	/*---------COMMIT---------*/
215
    $scope.commit = function() {
216
    	showSpinner();
217
    	$http.post('commitCleaner?cleanerId='+$scope.cleaners[$scope.selectedCleanerIndex].id, $scope.rules)
218
    	.success(function(data){
219
    		hidePermanotice();
220
    		$scope.reloadRules();
221
    		show_notification("success", data);
222
    		hideSpinner();
223
    	})
224
    	.error(function(){
225
    		show_notification("error",'An error occurred while saving modifications for cleaner '+$scope.cleaners[$scope.selectedCleanerIndex].name);
226
    		showPermanotice("Uncommitted changes!");
227
    		hideSpinner();
228
    	});
229
    }
230
    
231
    /*---------UTILITY---------*/
232
    $scope.isValid = function(vocabularyName) {
233
    	var ret =  false;
234
    	for (var i in $scope.modalRule.vocabularies) {
235
			if ($scope.modalRule.vocabularies[i].name == vocabularyName)
236
				ret = true;
237
		}
238
    	return ret;
239
    }
240
}
modules/dnet-modular-cleaning-rules-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/xsd/maven-4.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-cleaning-rules-ui</artifactId>
11
	<packaging>jar</packaging>
12
	<version>2.0.1-SNAPSHOT</version>
13
	<scm>
14
	  <developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/dnet-modular-cleaning-rules-ui/trunk</developerConnection>
15
	</scm>
16
	<dependencies>
17
		<dependency>
18
			<groupId>eu.dnetlib</groupId>
19
			<artifactId>dnet-modular-ui</artifactId>
20
			<version>[3.0.0,4.0.0)</version>
21
		</dependency>
22
		
23
		<dependency>
24
			<groupId>javax.servlet</groupId>
25
			<artifactId>javax.servlet-api</artifactId>
26
			<version>${javax.servlet.version}</version>
27
			<scope>provided</scope>
28
		</dependency>
29
	</dependencies>
30

  
31
	<properties>
32
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
33
	</properties>
34
</project>
modules/dnet-modular-cleaning-rules-ui/tags/dnet-modular-cleaning-rules-ui-1.0.1/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-cleaning-rules-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-cleaning-rules-ui"}
modules/dnet-modular-cleaning-rules-ui/tags/dnet-modular-cleaning-rules-ui-1.0.1/src/main/java/eu/dnetlib/functionality/modular/ui/cleaningrules/model/Rule.java
1
package eu.dnetlib.functionality.modular.ui.cleaningrules.model;
2

  
3
import java.util.List;
4

  
5
public class Rule {
6
	private String xpath;
7
	private List<String> appliedVocabularies;
8
	private boolean strict;
9

  
10
	public Rule() {
11
	}
12

  
13
	public Rule(String xpath, List<String> appliedVocabularies, boolean strict) {
14
		super();
15
		this.xpath = xpath;
16
		this.appliedVocabularies = appliedVocabularies;
17
		this.strict = strict;
18
	}
19

  
20
	public String getXpath() {
21
		return xpath;
22
	}
23

  
24
	public void setXpath(String xpath) {
25
		this.xpath = xpath;
26
	}
27

  
28
	public List<String> getAppliedVocabularies() {
29
		return appliedVocabularies;
30
	}
31

  
32
	public void setAppliedVocabularies(List<String> appliedVocabularies) {
33
		this.appliedVocabularies = appliedVocabularies;
34
	}
35

  
36
	public boolean isStrict() {
37
		return strict;
38
	}
39

  
40
	public void setStrict(boolean strict) {
41
		this.strict = strict;
42
	}
43

  
44
}
modules/dnet-modular-cleaning-rules-ui/tags/dnet-modular-cleaning-rules-ui-1.0.1/src/main/java/eu/dnetlib/functionality/modular/ui/cleaningrules/model/Cleaner.java
1
package eu.dnetlib.functionality.modular.ui.cleaningrules.model;
2

  
3
public class Cleaner {
4
	private String id;
5
	private String idHtml;
6
	private String name;
7
	private String description;
8

  
9
	public Cleaner() {
10
	}
11

  
12
	public Cleaner(String id, String idHtml, String name, String description) {
13
		super();
14
		this.id = id;
15
		this.idHtml = idHtml;
16
		this.name = name;
17
		this.description = description;
18
	}
19

  
20
	public String getId() {
21
		return id;
22
	}
23

  
24
	public void setId(String id) {
25
		this.id = id;
26
	}
27

  
28
	public String getIdHtml() {
29
		return idHtml;
30
	}
31

  
32
	public void setIdHtml(String idHtml) {
33
		this.idHtml = idHtml;
34
	}
35

  
36
	public String getName() {
37
		return name;
38
	}
39

  
40
	public void setName(String name) {
41
		this.name = name;
42
	}
43

  
44
	public String getDescription() {
45
		return description;
46
	}
47

  
48
	public void setDescription(String description) {
49
		this.description = description;
50
	}
51

  
52
}
modules/dnet-modular-cleaning-rules-ui/tags/dnet-modular-cleaning-rules-ui-1.0.1/src/main/java/eu/dnetlib/functionality/modular/ui/cleaningrules/adapters/RuleAdapter.java
1
package eu.dnetlib.functionality.modular.ui.cleaningrules.adapters;
2

  
3
import java.util.ArrayList;
4
import java.util.Arrays;
5
import java.util.List;
6

  
7
import com.google.common.base.Function;
8

  
9
import eu.dnetlib.functionality.modular.ui.cleaningrules.controllers.CleaningRuleController;
10
import eu.dnetlib.functionality.modular.ui.cleaningrules.model.Rule;
11

  
12
/**
13
 * This class is used in {@link CleaningRuleController} when un-marshaling of a {@link Rule} object is needed.
14
 * 
15
 * @author Andrea Mannocci
16
 */
17
public class RuleAdapter implements Function<String, Rule> {
18

  
19
	@Override
20
	public Rule apply(final String s) {
21
		String[] tokens = s.split("§§§");
22
		return new Rule(tokens[0].trim(), // xpath
23
				parseVocabularyList(tokens[1].trim()), // vocabularies
24
				Boolean.valueOf(tokens[2].trim()));// strict
25
	}
26

  
27
	List<String> parseVocabularyList(final String s) {
28
		return new ArrayList<String>(Arrays.asList(s.split(", ")));
29
	}
30

  
31
}
modules/dnet-modular-cleaning-rules-ui/tags/dnet-modular-cleaning-rules-ui-1.0.1/src/main/java/eu/dnetlib/functionality/modular/ui/cleaningrules/adapters/CleanerAdapter.java
1
package eu.dnetlib.functionality.modular.ui.cleaningrules.adapters;
2

  
3
import com.google.common.base.Function;
4

  
5
import eu.dnetlib.functionality.modular.ui.cleaningrules.controllers.CleaningRuleController;
6
import eu.dnetlib.functionality.modular.ui.cleaningrules.model.Cleaner;
7

  
8
/**
9
 * This class is used in {@link CleaningRuleController} when un-marshaling of
10
 * a {@link Cleaner} object is needed.
11
 * @author Andrea Mannocci
12
 */
13
public class CleanerAdapter implements Function<String, Cleaner> {
14

  
15
	public Cleaner apply(String s) {
16
		String[] tokens = s.split("§§§");
17
		return new Cleaner(		tokens[0].trim(), 
18
								tokens[0].trim().replaceAll("\\W", ""), 
19
								tokens[1].trim(), 
20
								tokens[2].trim());
21
	}
22

  
23
}
modules/dnet-modular-cleaning-rules-ui/tags/dnet-modular-cleaning-rules-ui-1.0.1/src/main/java/eu/dnetlib/functionality/modular/ui/cleaningrules/controllers/EntryPointController.java
1
package eu.dnetlib.functionality.modular.ui.cleaningrules.controllers;
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 EntryPointController extends ModuleEntryPoint {
11

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

  
17
}
modules/dnet-modular-cleaning-rules-ui/tags/dnet-modular-cleaning-rules-ui-1.0.1/src/main/java/eu/dnetlib/functionality/modular/ui/cleaningrules/controllers/CleaningRuleController.java
1
package eu.dnetlib.functionality.modular.ui.cleaningrules.controllers;
2

  
3
import java.io.IOException;
4
import java.io.StringReader;
5
import java.lang.reflect.Type;
6
import java.util.ArrayList;
7
import java.util.List;
8

  
9
import javax.annotation.Resource;
10
import javax.servlet.http.HttpServletRequest;
11
import javax.servlet.http.HttpServletResponse;
12
import javax.xml.bind.JAXBException;
13

  
14
import org.antlr.stringtemplate.StringTemplate;
15
import org.apache.commons.io.IOUtils;
16
import org.apache.commons.lang.StringEscapeUtils;
17
import org.apache.commons.logging.Log;
18
import org.apache.commons.logging.LogFactory;
19
import org.springframework.stereotype.Controller;
20
import org.springframework.web.bind.annotation.RequestMapping;
21
import org.springframework.web.bind.annotation.RequestMethod;
22
import org.springframework.web.bind.annotation.RequestParam;
23

  
24
import com.google.common.collect.Lists;
25
import com.google.gson.Gson;
26
import com.google.gson.reflect.TypeToken;
27

  
28
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
29
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
30
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException;
31
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
32
import eu.dnetlib.enabling.tools.ServiceLocator;
33
import eu.dnetlib.functionality.modular.ui.cleaningrules.adapters.CleanerAdapter;
34
import eu.dnetlib.functionality.modular.ui.cleaningrules.adapters.RuleAdapter;
35
import eu.dnetlib.functionality.modular.ui.cleaningrules.model.Cleaner;
36
import eu.dnetlib.functionality.modular.ui.cleaningrules.model.Rule;
37
import eu.dnetlib.miscutils.datetime.DateUtils;
38

  
39
@Controller
40
public class CleaningRuleController {
41
	private final Log log =  LogFactory.getLog(CleaningRuleController.class);
42

  
43
	@Resource(name = "lookupLocator")
44
	private ServiceLocator<ISLookUpService> lookupLocator;
45

  
46
	@Resource(name = "registryLocator")
47
	private ServiceLocator<ISRegistryService> registryLocator;
48

  
49
	@RequestMapping("/ui/cleaners.json")
50
	public void getCleaners(final HttpServletResponse response) throws ISLookUpException, IOException {
51
		log.info("cleaners.json");
52
		String query = "for $x in collection('/db/DRIVER/CleanerDSResources/CleanerDSResourceType') order by $x//CLEANER_NAME "
53
				+ "return concat ($x//RESOURCE_IDENTIFIER/@value,' §§§ ',$x//CLEANER_NAME,' §§§ ',$x//CLEANER_DESCRIPTION)";
54

  
55
		List<Cleaner> cleaners = Lists.transform(lookupLocator.getService().quickSearchProfile(query), new CleanerAdapter());
56
//		Map<String, Cleaner> map = new HashMap<String, Cleaner>();
57
//		for (Cleaner cleaner : cleaners) {
58
//			map.put(cleaner.getId(), cleaner);
59
//		}
60
		IOUtils.copy(new StringReader(new Gson().toJson(cleaners)), response.getOutputStream());
61
	}
62

  
63
	@RequestMapping("/ui/rules.json")
64
	public void getRules(final HttpServletResponse response, @RequestParam(value = "cleanerId", required = true) final String cleanerId)
65
			throws ISLookUpException, IOException {
66
		log.info("rules.json?cleanerId=" + cleanerId);
67

  
68
		String query = "for $x in /*[.//RESOURCE_IDENTIFIER/@value=\"{cleanerId}\"]//RULE order by $x/@xpath "
69
				+ "return concat ($x/@xpath,' §§§ ',$x/@vocabularies,' §§§ ',$x/@strict)";
70
		query = query.replace("{cleanerId}", cleanerId);
71

  
72
		List<Rule> rules = Lists.transform(lookupLocator.getService().quickSearchProfile(query), new RuleAdapter());
73
		IOUtils.copy(new StringReader(new Gson().toJson(rules)), response.getOutputStream());
74
	}
75

  
76
	@RequestMapping(value = "/ui/createCleaner", method = RequestMethod.POST)
77
	public void createCleaner(final HttpServletResponse response, final HttpServletRequest request) throws IOException, ISRegistryException, JAXBException {
78
		log.info("create vocabulary");
79

  
80
		Cleaner cleaner = new Gson().fromJson(request.getReader(), Cleaner.class);
81

  
82
		StringTemplate st = new StringTemplate(IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/functionality/modular/templates/cleaner.xml.st")));
83
		st.setAttribute("name", cleaner.getName());
84
		st.setAttribute("description", cleaner.getDescription());
85
		st.setAttribute("date", DateUtils.now_ISO8601());
86
		String newVocabularyId = registryLocator.getService().registerProfile(st.toString());
87

  
88
		IOUtils.copy(new StringReader(newVocabularyId), response.getOutputStream());
89
	}
90

  
91
	@RequestMapping(value = "/ui/commitCleanerInfo", method = RequestMethod.POST)
92
	public void commitCleanerInfo(final HttpServletResponse response,
93
			final HttpServletRequest request,
94
			@RequestParam(value = "cleanerId", required = true) final String cleanerId) throws IOException, ISRegistryException, JAXBException {
95
		log.info("committing cleaner info id = " + cleanerId);
96

  
97
		Cleaner cleaner = new Gson().fromJson(request.getReader(), Cleaner.class);
98

  
99
		String xml = "<CLEANER_NAME>{name}</CLEANER_NAME>";
100
		xml = xml.replace("{name}", StringEscapeUtils.escapeXml(cleaner.getName()));
101
		registryLocator.getService().updateProfileNode(cleanerId, "//CLEANER_NAME", xml);
102

  
103
		xml = "<CLEANER_DESCRIPTION>{desc}</CLEANER_DESCRIPTION>";
104
		xml = xml.replace("{desc}", StringEscapeUtils.escapeXml(cleaner.getDescription()));
105
		registryLocator.getService().updateProfileNode(cleanerId, "//CLEANER_DESCRIPTION", xml);
106

  
107
		IOUtils.copy(new StringReader("Vocabulary info saved correctly!"), response.getOutputStream());
108
	}
109

  
110
	@RequestMapping(value = "/ui/commitCleaner", method = RequestMethod.POST)
111
	public void commitRules(final HttpServletResponse response,
112
			final HttpServletRequest request,
113
			@RequestParam(value = "cleanerId", required = true) final String cleanerId) throws IOException, JAXBException, ISRegistryException {
114
		log.info("committing rules for cleaner id=" + cleanerId);
115

  
116
		Type collectionType = new TypeToken<ArrayList<Rule>>() {}.getType();
117
		ArrayList<Rule> rules = new Gson().fromJson(request.getReader(), collectionType);
118

  
119
		// prepare terms for XML
120
		for (Rule r : rules) {
121
			r.setXpath(StringEscapeUtils.escapeXml(r.getXpath()));
122
			List<String> vocabulariesXmlAdapted = new ArrayList<String>();
123
			for (String v : r.getAppliedVocabularies()) {
124
				vocabulariesXmlAdapted.add(StringEscapeUtils.escapeXml(v));
125
			}
126
			r.setAppliedVocabularies(vocabulariesXmlAdapted);
127
		}
128

  
129
		StringTemplate st = new StringTemplate(IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/functionality/modular/templates/rules.xml.st")));
130
		st.setAttribute("rules", rules);
131
		registryLocator.getService().updateProfileNode(cleanerId, "//CLEANER_RULES", st.toString());
132

  
133
		IOUtils.copy(new StringReader("Cleaner saved correctly!"), response.getOutputStream());
134
	}
135

  
136
	@RequestMapping(value = "/ui/dropCleaner", method = RequestMethod.GET)
137
	public void dropCleaner(final HttpServletResponse response,
138
			final HttpServletRequest request,
139
			@RequestParam(value = "cleanerId", required = true) final String cleanerId) throws IOException, ISRegistryException, JAXBException {
140
		log.info("delete cleaner id=" + cleanerId);
141

  
142
		registryLocator.getService().deleteProfile(cleanerId);
143
	}
144
}
modules/dnet-modular-cleaning-rules-ui/tags/dnet-modular-cleaning-rules-ui-1.0.1/src/main/resources/eu/dnetlib/functionality/modular/ui/webContext-modular-ui-cleaning-rules.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<beans xmlns="http://www.springframework.org/schema/beans"
4
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
5
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
6

  
7
	<bean name="/ui/cleaningRules.do"
8
		class="eu.dnetlib.functionality.modular.ui.cleaningrules.controllers.EntryPointController"
9
		p:menu="Cleaning rules editor" 
10
		p:title="D-NET cleaning rules editor"
11
		p:description="D-NET cleaning rules editor" 
12
		p:group="Configuration">
13
		<property name="permissionLevels">
14
			<set>
15
				<value>USER</value>
16
			</set>
17
		</property>
18
	</bean>
19

  
20
</beans>
modules/dnet-modular-cleaning-rules-ui/tags/dnet-modular-cleaning-rules-ui-1.0.1/src/main/resources/eu/dnetlib/functionality/modular/ui/views/ui/cleaningRules.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/cleaningRules.js" ></script>
4
}, body={
5
	<div ng-app="cleaningRulesUI" ng-controller="cleaningRulesCtrl">
6
		<div class="row">
7
			<div class="column col-xs-12 col-sm-12 col-md-3 col-lg-3">
8
				<form role="form" class="form-inline">
9
					<button type="button" class="btn btn-default" ng-click="selectedCleanerIndex = null; showInfoModal()">
10
						New cleaner <span class="glyphicon glyphicon-plus"></span>
11
					</button>
12
					<div class="form-group pull-right">
13
						<input type="text" class="form-control" ng-model="cleanerFilter" placeholder="Filter by...">
14
					</div>
15
				</form>
16
				<br/><br/>
17
				<ul class="nav nav-pills nav-stacked">
18
					<li ng-repeat="cleaner in cleaners | filter:cleanerFilter"
19
						ng-class="{'active': (selectedCleanerIndex != null) && (cleaner.id == cleaners[selectedCleanerIndex].id)}"
20
						ng-click="loadRules(cleaner)">
21
							<a>{{cleaner.name}}<span class="glyphicon glyphicon-chevron-right pull-right"/></a>
22
					</li>
23
				</ul>
24
			</div>
25
			<div class="col-xs-12 col-sm-12 col-md-9 col-lg-9" ng-show="rules != null && selectedCleanerIndex != null">
26
				<form role="form" class="form-inline">
27
					<div class="btn-group">
28
						<button type="button" class="btn btn-default" ng-click="showInfoModal()">
29
							Edit info <span class="glyphicon glyphicon-book"></span>
30
						</button>
31
						<button type="button" class="btn btn-default" ng-click="showRuleModal(null)">
32
							New rule <span class="glyphicon glyphicon-pencil"></span>
33
						</button>
34
						<button type="button" class="btn btn-default" ng-click="commit()">
35
							Commit <span class="glyphicon glyphicon-floppy-saved"></span>
36
						</button>
37
						<button type="button" class="btn btn-default" ng-click="reloadRules()">
38
							Discard all <span class="glyphicon glyphicon-repeat"></span>
39
						</button>
40
						<button type="button" class="btn btn-default" ng-click="dropCleaner()">
41
							Drop cleaner <span class="glyphicon glyphicon-trash"></span>
42
						</button>
43
					</div>
44
					<div class="form-group pull-right">
45
						<input type="text" class="form-control" ng-model="ruleFilter" placeholder="Filter by...">
46
					</div>
47
				</form>
48
				<br><br>
49
	            <table class="table table-bordered">
50
	            	<thead>
51
	            	    <tr>
52
	            	     	<th>XPath</th>
53
	            	      	<th>Applied vocabularies</th>
54
	            	      	<th>Strict</th>
55
	            	      	<th>Actions</th>
56
	            	    </tr>
57
            	  	</thead>
58
            	  	<tbody>
59
	        	  		<tr ng-repeat="rule in rules | filter:ruleFilter">
60
					      	<td class="col-xs-7">{{rule.xpath}}</td>
61
					      	<td class="col-xs-3">
62
						      	<ul>
63
						      		<li ng-repeat="vocabulary in rule.appliedVocabularies">{{vocabulary}} <span ng-show="!isValid(vocabulary)" class="label label-important">Missing!!</span></li>
64
						      	</ul>
65
					      	</td>
66
					      	<td class="col-xs-1">
67
					      		<span class="glyphicon" ng-class="{'glyphicon-ok': rule.strict, 'glyphicon-remove': !rule.strict}"></span>
68
					      	</td>
69
					      	<td class="col-xs-1">
70
					      		<button type="button" class="btn btn-xs btn-primary"  ng-click="showRuleModal(rule)">
71
					      			<span class="glyphicon glyphicon-pencil"></span>
72
				      			</button>
73
					      		<button type="button" class="btn btn-xs btn-danger" ng-click="deleteRule(rule)">
74
					      			<span class="glyphicon glyphicon-trash"></span>
75
				      			</button>
76
				      		</td>
77
					    </tr>
78
            	  	</tbody>
79
				</table>
80
			</div>
81
		</div>
82
			
83
		<!-- infoModal -->
84
		<div id="infoModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="infoModalLabel" aria-hidden="true">
85
			<div class="modal-dialog">
86
				<div class="modal-content">
87
					<div class="modal-header">
88
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
89
						<h4 id="infoModalLabel">Cleaner information</h4>
90
					</div>
91
					<div class="modal-body">
92
						<form name="infoForm" class="form-horizontal" role="form">
93
							<div class="form-group" ng-class="{'has-warning': !modalInfo.name}">
94
								<label class="col-sm-4 control-label" for="cleanerName">Cleaner name</label>
95
							    <div class="col-sm-8">
96
							      	<input class="form-control" ng-disabled="selectedCleanerIndex != null" type="text" name="cleanerName" placeholder="cleaner name" ng-model="modalInfo.name">
97
							    </div>
98
							</div>
99
							<div class="form-group">
100
								<label class="col-sm-4 control-label" for="cleanerDescription">Cleaner description</label>
101
								<div class="col-sm-8">
102
									<input class="form-control" ng-disabled="selectedCleanerIndex != null" type="text" name="cleanerDescription" placeholder="cleaner description" ng-model="modalInfo.description">
103
								</div>
104
							</div>
105
						</form>
106
					</div>
107
					<div class="modal-footer">
108
						<button class="btn btn-primary" ng-disabled="!modalInfo.name" ng-click="editInfo()">Save</button>
109
					</div>
110
				</div>
111
			</div>
112
		</div> <!-- info modal -->
113
			
114
		<!-- Le rule modal -->
115
		<div id="ruleModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="ruleModalLabel" aria-hidden="true">
116
			<div class="modal-dialog  modal-lg">
117
				<div class="modal-content">
118
					<div class="modal-header">
119
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
120
						<h4 id="ruleModalLabel">Rule editor</h4>
121
					</div>
122
					<div class="modal-body">
123
						<form name="infoForm" class="form-horizontal" role="form">
124
							<div class="form-group" ng-class="{'has-warning': !modalRule.xpath}">
125
								<label class="col-sm-4 control-label">XPath</label>
126
								<div class="col-sm-8">
127
									<textarea rows="3" class="col-xs-12" type="text" placeholder="xpath" ng-model="modalRule.xpath"></textarea> 
128
								</div>
129
							</div>
130
							<div class="form-group">
131
								<label class="col-sm-4 control-label">Strict</label>
132
								<div class="col-sm-8">
133
									<label class="radio"><input type="radio" ng-model="modalRule.strict" ng-value="true"> True</label>
134
									<label class="radio"><input type="radio" ng-model="modalRule.strict" ng-value="false" checked> False</label>
135
								</div>
136
							</div>
137
							<div class="form-group">
138
								<label class="col-sm-4 control-label">Vocabularies applied</label>
139
								<div class="col-sm-8">
140
									<input type="text" class="form-control" ng-model="vocabularyFilter" placeholder="Filter by...">
141
									<label class="checkbox" ng-repeat="vocabulary in modalRule.vocabularies | filter:vocabularyFilter"><input type="checkbox" ng-model="vocabulary.checked"> {{vocabulary.name}}</label>
142
								</div>
143
							</div>
144
						</form>
145
					</div>
146
					<div class="modal-footer">
147
						<button type="button" class="btn btn-primary" ng-disabled="!modalRule.xpath" ng-click="editRule()">Save</button>
148
					</div>
149
				</div>
150
			</div>
151
		</div> <!-- rule modal -->
152
			
153
	</div>
154
} )$
modules/dnet-modular-cleaning-rules-ui/tags/dnet-modular-cleaning-rules-ui-1.0.1/src/main/resources/eu/dnetlib/functionality/modular/templates/cleaner.xml.st
1
<?xml version="1.0" encoding="UTF-8"?>
2
<RESOURCE_PROFILE>
3
	<HEADER>
4
		<RESOURCE_IDENTIFIER value="" />
5
		<RESOURCE_TYPE value="CleanerDSResourceType" />
6
		<RESOURCE_KIND value="CleanerDSResources" />
7
		<RESOURCE_URI value="" />
8
		<DATE_OF_CREATION value="$date$" />
9
	</HEADER>
10
	<BODY>
11
		<CONFIGURATION>
12
			<CLEANER_NAME>$name$</CLEANER_NAME>
13
			<CLEANER_DESCRIPTION>$description$</CLEANER_DESCRIPTION>
14
			<CLEANER_RULES>
15
				<RULE xpath="//whatever" vocabularies="" strict="true" />
16
			</CLEANER_RULES>
17
		</CONFIGURATION>
18
		<STATUS>
19
			<LAST_UPDATE value="$date$" />
20
		</STATUS>
21
		<SECURITY_PARAMETERS>String</SECURITY_PARAMETERS>
22
	</BODY>
23
</RESOURCE_PROFILE>
modules/dnet-modular-cleaning-rules-ui/tags/dnet-modular-cleaning-rules-ui-1.0.1/src/main/resources/eu/dnetlib/functionality/modular/templates/rules.xml.st
1
<CLEANER_RULES>
2
	$rules:{r|
3
	<RULE vocabularies='$r.appliedVocabularies:{v|$v$};separator=", "$' xpath="$r.xpath$" strict="$r.strict$" />
4
	}$
5
</CLEANER_RULES>
modules/dnet-modular-cleaning-rules-ui/tags/dnet-modular-cleaning-rules-ui-1.0.1/src/main/resources/eu/dnetlib/web/resources/js/cleaningRules.js
1
var module = angular.module('cleaningRulesUI', []);
2

  
3
module.directive('tooltip', function() {
4
    return {
5
    	restrict: 'A',
6
    	link: function(scope, element, attrs)
7
        {
8
            $(element).tooltip();
9
        }
10
    }
11
});
12

  
13
function cleaningRulesCtrl($scope, $http) {
14
	$scope.rules = [];
15
	$scope.modalInfo = {};
16
	$scope.modalCleaner = {};
17
	$scope.modalRule = {};
18

  
19
	initSpinner();
20
	showSpinner();
21
	
22
	$scope.startup = function() {
23
		$http.get('cleaners.json')
24
		.success(
25
			function(data) {
26
	    		$scope.cleaners = data;
27
	    		// load vocabularies
28
			    $http.get('vocabularies.json')
29
				.success(
30
					function(data) {
31
			    		$scope.modalRule.vocabularies = data;
32
			    		hideSpinner();
33
			 		})
34
				.error(
35
			        function() {
36
			        	show_notification("error",'An error occurred while fetching available vocabularies..');
37
			        	hideSpinner();
38
			        }
39
			    );
40
	 		})
41
		.error(
42
	        function() {
43
	        	show_notification("error",'An error occurred while fetching registered Cleaner Service Profiles');
44
	        	hideSpinner();
45
	        }
46
	    );
47
	}
48
	
49
	$scope.startup();
50

  
51
    $scope.loadRules = function(cleaner) {
52
    	showSpinner();
53
		$http.get('rules.json?cleanerId=' + cleaner.id)
54
        .success(
55
            function(data) {
56
                $scope.selectedCleanerIndex = $scope.cleaners.indexOf(cleaner);
57
                $scope.rules = data;
58
                hidePermanotice();
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff