Project

General

Profile

« Previous | Next » 

Revision 52861

processing for bulk tagging configuration

View differences:

modules/dnet-openaireplus-workflows/branches/solr7/src/main/java/eu/dnetlib/msro/openaireplus/workflows/nodes/bulktag/LoadBulkTaggingConfigurationJobNode.java
1 1
package eu.dnetlib.msro.openaireplus.workflows.nodes.bulktag;
2 2

  
3
import java.io.StringReader;
4
import java.util.ArrayList;
3 5
import java.util.List;
4 6

  
5 7
import com.googlecode.sarasvati.Arc;
......
10 12
import org.apache.commons.logging.Log;
11 13
import org.apache.commons.logging.LogFactory;
12 14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.dom4j.Document;
16
import org.dom4j.DocumentException;
17
import org.dom4j.Node;
18
import org.dom4j.io.SAXReader;
13 19

  
20

  
14 21
public class LoadBulkTaggingConfigurationJobNode extends SimpleJobNode {
15 22

  
16 23
	private static final Log log = LogFactory.getLog(LoadBulkTaggingConfigurationJobNode.class);
......
24 31

  
25 32
	@Override
26 33
	protected String execute(final NodeToken token) throws Exception {
27

  
34
		xquery = "for $x in collection('/db/DRIVER/ContextDSResources/ContextDSResourceType') \n" +
35
				"let $id := $x//CONFIGURATION/context/@id\n" +
36
				"let $subj := $x//CONFIGURATION/context/param[./@name='subject']/text()\n" +
37
				"let $datasources := $x//CONFIGURATION/context/category[./@id=concat($id,'::contentproviders')]/concept\n" +
38
				"let $communities := $x//CONFIGURATION/context/category[./@id=concat($id,'::zenodocommunities')]/concept\n" +
39
				"where $x//CONFIGURATION/context[./@type='community'] \n" +
40
				"return \n" +
41
				"<community>\n" +
42
				"{ $x//CONFIGURATION/context/@id}\n" +
43
				"<subjects>\n" +
44
				"{for $y in tokenize($subj,',')\n" +
45
				"return \n" +
46
				"<subj>{$y}</subj>}\n" +
47
				"</subjects>\n" +
48
				"<datasources>\n" +
49
				"{for $d in $datasources\n" +
50
				"return \n" +
51
				"<datasource>\n" +
52
				"<openaireId>\n" +
53
				"{$d//param[./@name='openaireId']/text()}\n" +
54
				"</openaireId>\n" +
55
				"<selcriteria>\n" +
56
				"{$d//param[./@name='selcriteria']/text()}\n" +
57
				"</selcriteria>\n" +
58
				"</datasource>\n" +
59
				"}\n" +
60
				"</datasources>\n" +
61
				"<zenodocommunities>\n" +
62
				"{$communities}\n" +
63
				"</zenodocommunities>\n" +
64
				"</community>";
28 65
		final List<String> res = serviceLocator.getService(ISLookUpService.class).quickSearchProfile(getXquery());
29 66

  
67
		Configuration c = new Configuration();
30 68

  
31
		//TODO manipulate res
69
		for(String r : res){
70
			c.addCommunity(parseCommunity(r));
71
		}
32 72

  
33
		token.getEnv().setAttribute(getBulkTaggingConfParam(), res.toString());
73
		token.getEnv().setAttribute(getBulkTaggingConfParam(), c.getTaggingConfiguration());
34 74

  
75
		log.info("tagging configuration " + c.getTaggingConfiguration());
35 76
		return Arc.DEFAULT_ARC;
36 77
	}
37 78

  
79
	private Community parseCommunity(String r) {
80

  
81
		try{
82
			SAXReader reader = new SAXReader();
83
			Document doc = reader.read(new StringReader(r));
84
			Community c = new Community();
85
			c.setId(doc.valueOf("./@id"));
86

  
87
			List <Node> list = doc.selectNodes("//subject");
88
			final List<String> sbj = new ArrayList<>();
89
			for(Node n : list){
90
				sbj.add(n.getText());
91
			}
92
			if(sbj.size()>0)
93
				c.setSubjects(sbj);
94

  
95
			list = doc.selectNodes("//datasource");
96
			final List<Datasource> datasourceList = new ArrayList<>();
97
			for(Node n : list){
98
				Datasource d = new Datasource();
99
				Document dd = n.getDocument();
100
				d.setOpenaireId(dd.valueOf(("./openaireId")));
101
				d.setSelCriteria(dd.valueOf("./selcriteria"));
102
				datasourceList.add(d);
103
			}
104
			if(datasourceList.size()>0)
105
				c.setDatasources(datasourceList);
106

  
107
			list = doc.selectNodes("//zenodocommunities");
108
			final List<ZenodoCommunity> zenodoCommunityList = new ArrayList<>();
109
			for(Node n : list){
110
				ZenodoCommunity zc = new ZenodoCommunity();
111
				Document dd = n.getDocument();
112
				zc.setZenodoCommunityId(dd.valueOf("./zenodoid"));
113
				zc.setSelCriteria(dd.valueOf("./selcriteria"));
114
				zenodoCommunityList.add(zc);
115
			}
116
			if(zenodoCommunityList.size()>0)
117
				c.setZenodoCommunities(zenodoCommunityList);
118
			if(c.getSubjects() == null && c.getDatasources() == null && c.getZenodoCommunities() == null)
119
				return null;
120
			return c;
121
		}catch(DocumentException e){
122
			log.error("Impossible to read the configuration for  " + r);
123
			return null;
124
		}
125

  
126
	}
127

  
38 128
	public String getXquery() {
39 129
		return xquery;
40 130
	}

Also available in: Unified diff