Project

General

Profile

« Previous | Next » 

Revision 32557

removed lombok

View differences:

modules/dnet-modular-contexts-ui/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/contexts/model/Context.java
1 1
package eu.dnetlib.functionality.modular.ui.contexts.model;
2 2

  
3
import lombok.AllArgsConstructor;
4
import lombok.Data;
5
import lombok.NoArgsConstructor;
3
public class Context implements Comparable<Context> {
6 4

  
7

  
8
@Data
9
@AllArgsConstructor
10
@NoArgsConstructor
11
public class Context implements Comparable<Context> {
12 5
	private String profileId;
13 6
	private String id;
14 7
	private String label;
15 8
	private String type;
16
	
9

  
17 10
	@Override
18
	public int compareTo(Context o) {
11
	public int compareTo(final Context o) {
19 12
		return label.compareTo(o.getLabel());
20 13
	}
14

  
15
	public Context() {}
16

  
17
	public Context(final String profileId, final String id, final String label, final String type) {
18
		super();
19
		this.profileId = profileId;
20
		this.id = id;
21
		this.label = label;
22
		this.type = type;
23
	}
24

  
25
	public String getProfileId() {
26
		return profileId;
27
	}
28

  
29
	public void setProfileId(final String profileId) {
30
		this.profileId = profileId;
31
	}
32

  
33
	public String getId() {
34
		return id;
35
	}
36

  
37
	public void setId(final String id) {
38
		this.id = id;
39
	}
40

  
41
	public String getLabel() {
42
		return label;
43
	}
44

  
45
	public void setLabel(final String label) {
46
		this.label = label;
47
	}
48

  
49
	public String getType() {
50
		return type;
51
	}
52

  
53
	public void setType(final String type) {
54
		this.type = type;
55
	}
21 56
}
modules/dnet-modular-contexts-ui/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/contexts/model/Concept.java
4 4
import java.util.List;
5 5
import java.util.Map;
6 6

  
7
import lombok.AllArgsConstructor;
8
import lombok.Data;
9
import lombok.NoArgsConstructor;
7
public class Concept implements Comparable<Concept> {
10 8

  
11
@Data
12
@AllArgsConstructor
13
@NoArgsConstructor
14
public class Concept implements Comparable<Concept> {
15 9
	private String id;
16 10
	private String label;
17 11
	private String claim;
18
	private Map<String,String> params;
12
	private Map<String, String> params;
19 13
	private List<Concept> concepts = new ArrayList<Concept>();
20
	
14

  
15
	public Concept() {}
16

  
17
	public Concept(final String id, final String label, final String claim, final Map<String, String> params, final List<Concept> concepts) {
18
		super();
19
		this.id = id;
20
		this.label = label;
21
		this.claim = claim;
22
		this.params = params;
23
		this.concepts = concepts;
24
	}
25

  
21 26
	@Override
22
	public int compareTo(Concept o) {
27
	public int compareTo(final Concept o) {
23 28
		return label.compareTo(o.getLabel());
24 29
	}
30

  
31
	public String getId() {
32
		return id;
33
	}
34

  
35
	public void setId(final String id) {
36
		this.id = id;
37
	}
38

  
39
	public String getLabel() {
40
		return label;
41
	}
42

  
43
	public void setLabel(final String label) {
44
		this.label = label;
45
	}
46

  
47
	public String getClaim() {
48
		return claim;
49
	}
50

  
51
	public void setClaim(final String claim) {
52
		this.claim = claim;
53
	}
54

  
55
	public Map<String, String> getParams() {
56
		return params;
57
	}
58

  
59
	public void setParams(final Map<String, String> params) {
60
		this.params = params;
61
	}
62

  
63
	public List<Concept> getConcepts() {
64
		return concepts;
65
	}
66

  
67
	public void setConcepts(final List<Concept> concepts) {
68
		this.concepts = concepts;
69
	}
25 70
}
modules/dnet-modular-contexts-ui/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/contexts/model/Category.java
3 3
import java.util.ArrayList;
4 4
import java.util.List;
5 5

  
6
import lombok.AllArgsConstructor;
7
import lombok.Data;
8
import lombok.NoArgsConstructor;
6
public class Category implements Comparable<Category> {
9 7

  
10
@Data
11
@AllArgsConstructor
12
@NoArgsConstructor
13
public class Category implements Comparable<Category> {
14 8
	private String id;
15 9
	private String label;
16 10
	private String claim;
17 11
	private List<Concept> concepts = new ArrayList<Concept>();
18
	
12

  
13
	public Category() {}
14

  
15
	public Category(final String id, final String label, final String claim, final List<Concept> concepts) {
16
		super();
17
		this.id = id;
18
		this.label = label;
19
		this.claim = claim;
20
		this.concepts = concepts;
21
	}
22

  
19 23
	@Override
20
	public int compareTo(Category o) {
24
	public int compareTo(final Category o) {
21 25
		return label.compareTo(o.getLabel());
22 26
	}
23
	
27

  
28
	public String getId() {
29
		return id;
30
	}
31

  
32
	public void setId(final String id) {
33
		this.id = id;
34
	}
35

  
36
	public String getLabel() {
37
		return label;
38
	}
39

  
40
	public void setLabel(final String label) {
41
		this.label = label;
42
	}
43

  
44
	public String getClaim() {
45
		return claim;
46
	}
47

  
48
	public void setClaim(final String claim) {
49
		this.claim = claim;
50
	}
51

  
52
	public List<Concept> getConcepts() {
53
		return concepts;
54
	}
55

  
56
	public void setConcepts(final List<Concept> concepts) {
57
		this.concepts = concepts;
58
	}
59

  
24 60
}
modules/dnet-modular-contexts-ui/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/contexts/controllers/ContextsController.java
10 10

  
11 11
import javax.annotation.Resource;
12 12

  
13
import lombok.extern.apachecommons.CommonsLog;
14

  
13
import org.apache.commons.logging.Log;
14
import org.apache.commons.logging.LogFactory;
15 15
import org.dom4j.Document;
16 16
import org.dom4j.DocumentException;
17 17
import org.dom4j.Element;
......
35 35

  
36 36
/**
37 37
 * Web controller for the UI
38
 * 
38
 *
39 39
 * @author Andrea Mannocci
40 40
 */
41
@CommonsLog
42 41
@Controller
43 42
public class ContextsController {
44 43

  
44
	private static final Log log = LogFactory.getLog(ContextsController.class);
45

  
45 46
	@Resource(name = "lookupLocator")
46 47
	private ServiceLocator<ISLookUpService> lookupLocator;
47 48

  
......
50 51

  
51 52
	/**
52 53
	 * Returns all contexts serialized in json. Invoked by angularJS
53
	 * 
54
	 *
54 55
	 * @param response
55
	 * @return 
56
	 * @return
56 57
	 * @throws ISLookUpException
57 58
	 * @throws IOException
58 59
	 */
59 60
	@RequestMapping("/ui/contexts.json")
60 61
	public @ResponseBody List<Context> getContexts() throws ISLookUpException, IOException {
61 62
		log.info("contexts.json");
62
		
63

  
63 64
		final String query = "for $x in collection('/db/DRIVER/ContextDSResources/ContextDSResourceType') order by $x//label "
64 65
				+ "return concat ($x//RESOURCE_IDENTIFIER/@value,' §§§ ',$x//context/@id,' §§§ ',$x//context/@label,' §§§ ',$x//context/@type)";
65 66

  
66 67
		final List<Context> contexts = Lists.transform(lookupLocator.getService().quickSearchProfile(query), new Function<String, Context>() {
68

  
67 69
			@Override
68 70
			public Context apply(final String s) {
69 71
				String[] tokens = s.split("§§§");
70 72
				return new Context(tokens[0].trim(), tokens[1].trim(), tokens[2].trim(), tokens[3].trim());
71 73
			}
72 74
		});
73
			
75

  
74 76
		return contexts;
75 77
	}
76 78

  
77 79
	/**
78 80
	 * Returns all categories and their concepts belonging to a context. Invoked by AngularJS
79
	 * 
81
	 *
80 82
	 * @param response
81 83
	 * @param contextId
82 84
	 * @throws ISLookUpException
83 85
	 * @throws IOException
84
	 * @throws DocumentException 
86
	 * @throws DocumentException
85 87
	 */
86 88
	@RequestMapping("/ui/categories.json")
87
	public @ResponseBody  List<Category> getCategories(@RequestParam(value = "contextId", required = true) final String contextId)
89
	public @ResponseBody List<Category> getCategories(@RequestParam(value = "contextId", required = true) final String contextId)
88 90
			throws ISLookUpException, IOException, DocumentException {
89 91
		log.info("categories.json?contextId=" + contextId);
90 92

  
91 93
		final String profile = lookupLocator.getService().getResourceProfile(contextId);
92
		final Document doc = (new SAXReader()).read(new StringReader(profile));
93
		
94
		final Document doc = new SAXReader().read(new StringReader(profile));
95

  
94 96
		final Map<String, Category> categories = Maps.newHashMap();
95
				
97

  
96 98
		for (Object cat : doc.selectNodes("//category")) {
97
								
99

  
98 100
			final Element categoryNode = (Element) cat;
99 101

  
100 102
			final String id = categoryNode.valueOf("@id");
101
			
103

  
102 104
			if (!categories.containsKey(id)) {
103 105
				final Category category = new Category();
104 106
				category.setId(categoryNode.valueOf("@id"));
......
108 110
				categories.put(id, category);
109 111
			}
110 112
			final Category category = categories.get(id);
111
			
113

  
112 114
			category.setConcepts(new ArrayList<Concept>());
113 115
			for (Object con : categoryNode.selectNodes("./concept")) {
114 116
				category.getConcepts().add(createConcept((Element) con));
115 117
			}
116
			
118

  
117 119
			Collections.sort(category.getConcepts());
118 120
		}
119
		
121

  
120 122
		final List<Category> list = Lists.newArrayList(categories.values());
121 123
		Collections.sort(list);
122 124

  
123 125
		return list;
124 126
	}
125
	
126
	private Concept createConcept(Element conceptNode) {
127

  
128
	private Concept createConcept(final Element conceptNode) {
127 129
		final Concept outerConcept = new Concept();
128 130
		outerConcept.setId(conceptNode.valueOf("@id"));
129 131
		outerConcept.setLabel(conceptNode.valueOf("@label"));
130 132
		outerConcept.setClaim(conceptNode.valueOf("@claim"));
131
		
133

  
132 134
		Map<String, String> paramsMap = new HashMap<String, String>();
133
		for (Object param: conceptNode.selectNodes("./param")) {
135
		for (Object param : conceptNode.selectNodes("./param")) {
134 136
			final Element paramNode = (Element) param;
135 137
			paramsMap.put(paramNode.valueOf("@name"), paramNode.valueOf("."));
136 138
		}
137 139
		outerConcept.setParams(paramsMap);
138
		
140

  
139 141
		outerConcept.setConcepts(new ArrayList<Concept>());
140 142
		for (Object nestedConcept : conceptNode.selectNodes("./concept")) {
141 143
			outerConcept.getConcepts().add(createConcept((Element) nestedConcept));
142 144
		}
143
		
145

  
144 146
		return outerConcept;
145 147
	}
146
	
147
//	@RequestMapping(value = "/ui/commitContext", method = RequestMethod.POST)
148
//	public @ResponseBody String commitTerms(@RequestBody(required=true) final List<Term> terms,
149
//			@RequestParam(value = "contextId", required = true) final String contextId) throws IOException, ISRegistryException, JAXBException {
150
//		log.info("committing context id = " + contextId);
151
//
152
//		// prepare terms for XML
153
//		for (Term t : terms) {
154
//			t.setCode(StringEscapeUtils.escapeXml(t.getCode()));
155
//			t.setEncoding(StringEscapeUtils.escapeXml(t.getEncoding()));
156
//			t.setEnglishName(StringEscapeUtils.escapeXml(t.getEnglishName()));
157
//			t.setNativeName(StringEscapeUtils.escapeXml(t.getNativeName()));
158
//			for (Synonym s : t.getSynonyms()) {
159
//				s.setEncoding(StringEscapeUtils.escapeXml(s.getEncoding()));
160
//				s.setTerm(StringEscapeUtils.escapeXml(s.getTerm()));
161
//			}
162
//			for (Relation r : t.getRelations()) {
163
//				r.setType(StringEscapeUtils.escapeXml(r.getType()));
164
//				r.setValue(StringEscapeUtils.escapeXml(r.getValue()));
165
//			}
166
//		}
167
//
168
//		StringTemplate st = new StringTemplate(IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/functionality/modular/templates/terms.xml.st")));
169
//		st.setAttribute("terms", terms);
170
//		registryLocator.getService().updateProfileNode(contextId, "//TERMS", st.toString());
171
//
172
//		return "Context saved correctly!";
173
//	}
174
//
175
//	@RequestMapping(value = "/ui/commitContextInfo", method = RequestMethod.POST)
176
//	public @ResponseBody String commitContextInfo(@RequestBody(required=true) final Context voc,
177
//			@RequestParam(value = "contextId", required = true) final String contextId) throws IOException, ISRegistryException, JAXBException {
178
//		log.info("committing context info id = " + contextId);
179
//
180
//		// String xml = "<VOCABULARY_NAME code='{code}'>{name}</VOCABULARY_NAME>";
181
//		// xml = xml.replace("{code}", StringEscapeUtils.escapeXml(voc.getCode())).replace("{name}",
182
//		// StringEscapeUtils.escapeXml(voc.getName()));
183
//		// registryLocator.getService().updateProfileNode(contextId, "//VOCABULARY_NAME", xml);
184
//
185
//		String xml = "<VOCABULARY_DESCRIPTION>{desc}</VOCABULARY_DESCRIPTION>";
186
//		xml = xml.replace("{desc}", StringEscapeUtils.escapeXml(voc.getDescription()));
187
//		registryLocator.getService().updateProfileNode(contextId, "//VOCABULARY_DESCRIPTION", xml);
188
//
189
//		return "Context info saved correctly!";
190
//	}
191
//
192
//	@RequestMapping(value = "/ui/createContext", method = RequestMethod.POST)
193
//	public @ResponseBody String createContext(@RequestBody(required=true) final Context voc) throws IOException, ISRegistryException, JAXBException {
194
//		log.info("create context");
195
//
196
//		StringTemplate st = new StringTemplate(
197
//				IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/functionality/modular/templates/context.xml.st")));
198
//		st.setAttribute("name", voc.getName());
199
//		st.setAttribute("description", voc.getDescription());
200
//		st.setAttribute("code", voc.getCode());
201
//		st.setAttribute("date", DateUtils.now_ISO8601());
202
//		String newContextId = registryLocator.getService().registerProfile(st.toString());
203
//
204
//		return newContextId;
205
//	}
206
//
207
//	@RequestMapping(value = "/ui/dropContext", method = RequestMethod.GET)
208
//	public @ResponseBody boolean dropContext(@RequestParam(value = "contextId", required = true) final String contextId) throws IOException, ISRegistryException, JAXBException {
209
//		log.info("delete context id=" + contextId);
210
//
211
//		return registryLocator.getService().deleteProfile(contextId);
212
//	}
148

  
149
	// @RequestMapping(value = "/ui/commitContext", method = RequestMethod.POST)
150
	// public @ResponseBody String commitTerms(@RequestBody(required=true) final List<Term> terms,
151
	// @RequestParam(value = "contextId", required = true) final String contextId) throws IOException, ISRegistryException, JAXBException {
152
	// log.info("committing context id = " + contextId);
153
	//
154
	// // prepare terms for XML
155
	// for (Term t : terms) {
156
	// t.setCode(StringEscapeUtils.escapeXml(t.getCode()));
157
	// t.setEncoding(StringEscapeUtils.escapeXml(t.getEncoding()));
158
	// t.setEnglishName(StringEscapeUtils.escapeXml(t.getEnglishName()));
159
	// t.setNativeName(StringEscapeUtils.escapeXml(t.getNativeName()));
160
	// for (Synonym s : t.getSynonyms()) {
161
	// s.setEncoding(StringEscapeUtils.escapeXml(s.getEncoding()));
162
	// s.setTerm(StringEscapeUtils.escapeXml(s.getTerm()));
163
	// }
164
	// for (Relation r : t.getRelations()) {
165
	// r.setType(StringEscapeUtils.escapeXml(r.getType()));
166
	// r.setValue(StringEscapeUtils.escapeXml(r.getValue()));
167
	// }
168
	// }
169
	//
170
	// StringTemplate st = new
171
	// StringTemplate(IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/functionality/modular/templates/terms.xml.st")));
172
	// st.setAttribute("terms", terms);
173
	// registryLocator.getService().updateProfileNode(contextId, "//TERMS", st.toString());
174
	//
175
	// return "Context saved correctly!";
176
	// }
177
	//
178
	// @RequestMapping(value = "/ui/commitContextInfo", method = RequestMethod.POST)
179
	// public @ResponseBody String commitContextInfo(@RequestBody(required=true) final Context voc,
180
	// @RequestParam(value = "contextId", required = true) final String contextId) throws IOException, ISRegistryException, JAXBException {
181
	// log.info("committing context info id = " + contextId);
182
	//
183
	// // String xml = "<VOCABULARY_NAME code='{code}'>{name}</VOCABULARY_NAME>";
184
	// // xml = xml.replace("{code}", StringEscapeUtils.escapeXml(voc.getCode())).replace("{name}",
185
	// // StringEscapeUtils.escapeXml(voc.getName()));
186
	// // registryLocator.getService().updateProfileNode(contextId, "//VOCABULARY_NAME", xml);
187
	//
188
	// String xml = "<VOCABULARY_DESCRIPTION>{desc}</VOCABULARY_DESCRIPTION>";
189
	// xml = xml.replace("{desc}", StringEscapeUtils.escapeXml(voc.getDescription()));
190
	// registryLocator.getService().updateProfileNode(contextId, "//VOCABULARY_DESCRIPTION", xml);
191
	//
192
	// return "Context info saved correctly!";
193
	// }
194
	//
195
	// @RequestMapping(value = "/ui/createContext", method = RequestMethod.POST)
196
	// public @ResponseBody String createContext(@RequestBody(required=true) final Context voc) throws IOException, ISRegistryException,
197
	// JAXBException {
198
	// log.info("create context");
199
	//
200
	// StringTemplate st = new StringTemplate(
201
	// IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/functionality/modular/templates/context.xml.st")));
202
	// st.setAttribute("name", voc.getName());
203
	// st.setAttribute("description", voc.getDescription());
204
	// st.setAttribute("code", voc.getCode());
205
	// st.setAttribute("date", DateUtils.now_ISO8601());
206
	// String newContextId = registryLocator.getService().registerProfile(st.toString());
207
	//
208
	// return newContextId;
209
	// }
210
	//
211
	// @RequestMapping(value = "/ui/dropContext", method = RequestMethod.GET)
212
	// public @ResponseBody boolean dropContext(@RequestParam(value = "contextId", required = true) final String contextId) throws
213
	// IOException, ISRegistryException, JAXBException {
214
	// log.info("delete context id=" + contextId);
215
	//
216
	// return registryLocator.getService().deleteProfile(contextId);
217
	// }
213 218
}
modules/dnet-modular-contexts-ui/trunk/pom.xml
4 4
	<parent>
5 5
		<groupId>eu.dnetlib</groupId>
6 6
		<artifactId>dnet-parent</artifactId>
7
		<version>1.0.0-SNAPSHOT</version>
7
		<version>1.0.0</version>
8 8
	</parent>
9 9
	<modelVersion>4.0.0</modelVersion>
10 10
	<groupId>eu.dnetlib</groupId>
......
15 15
		<dependency>
16 16
			<groupId>eu.dnetlib</groupId>
17 17
			<artifactId>dnet-modular-ui</artifactId>
18
			<version>2.0.0-SNAPSHOT</version>
18
			<version>2.0.0</version>
19 19
		</dependency>
20 20

  
21 21
		<dependency>
......
25 25
			<scope>provided</scope>
26 26
		</dependency>
27 27

  
28
		<dependency>
29
			<groupId>org.projectlombok</groupId>
30
			<artifactId>lombok</artifactId>
31
			<version>1.12.6</version>
32
			<scope>provided</scope>
33
		</dependency>
34 28
	</dependencies>
35 29

  
36 30
	<properties>

Also available in: Unified diff