Project

General

Profile

« Previous | Next » 

Revision 27162

a few changes edition wf. still WIP

View differences:

modules/dnet-eagle-workflows/trunk/src/main/java/eu/dnetlib/msro/eagle/workflows/nodes/composition/ComposeEprJobNode.java
3 3
import java.io.StringReader;
4 4
import java.util.Iterator;
5 5
import java.util.Queue;
6
import java.util.concurrent.PriorityBlockingQueue;
6
import java.util.concurrent.LinkedBlockingQueue;
7 7

  
8 8
import javax.xml.ws.wsaddressing.W3CEndpointReference;
9 9

  
......
12 12
import org.dom4j.Document;
13 13
import org.dom4j.DocumentException;
14 14
import org.dom4j.Element;
15
import org.dom4j.Node;
16 15
import org.dom4j.io.SAXReader;
17 16
import org.springframework.beans.factory.annotation.Required;
18 17

  
......
31 30

  
32 31
	private String inputEprParam;
33 32
	private String alternateEprParam;
34
	private String xpathToIdOnInput;
35
	private String xpathToIdOnAlternate;
36
	private String xpathToFragment;
33
	private String xpathToInputId;
34
	private String xpathToAlternateId;
35
	private String xpathToReplacedFragment;
36
	private String xpathToReplacingFragment;
37 37
	private String composedEprParam;
38 38
	
39 39
	private MappedResultSetFactory mappedResultSetFactory;
......
43 43
	protected String execute(final NodeToken token) throws Exception {
44 44
		final W3CEndpointReference inputEpr = new EPRUtils().getEpr(token.getEnv().getAttribute(inputEprParam));
45 45
		final Iterator<String> alternateRsClient = resultSetClientFactory.getClient(token.getEnv().getAttribute(alternateEprParam)).iterator();
46
		final Queue<Document> alternateQueue = new PriorityBlockingQueue<Document>();
46
		final Queue<Document> alternateQueue = new LinkedBlockingQueue<Document>();
47 47
		final SAXReader reader = new SAXReader();
48 48
		
49
		if (alternateRsClient.hasNext()) {
50
			populateQueue(alternateQueue, alternateRsClient.next());
51
		}
52
		
49 53
		final W3CEndpointReference composedEpr = mappedResultSetFactory.createMappedResultSet(inputEpr, new UnaryFunction<String, String>() {
50 54

  
51 55
			@Override
52 56
			public String evaluate(String current) {
53 57
				try {
54 58
					Document currentDoc = reader.read(new StringReader(current));
55
					String currentId = currentDoc.valueOf(getXpathToIdOnInput());
59
					String currentId = currentDoc.valueOf(xpathToInputId);
56 60
					
57 61
					Document matchFragment = getCurrentMatch(currentId);
58 62
					if (matchFragment != null) {
......
67 71
			}
68 72
			
69 73
			private Document getCurrentMatch(String currentId) {
70
				while (alternateRsClient.hasNext()) {
71
					try {
72
						alternateQueue.add(reader.read(new StringReader(alternateRsClient.next())));
73
					} catch (DocumentException e) {
74
						e.printStackTrace();
74
				Document peeked = alternateQueue.peek();
75
				while (!alternateQueue.isEmpty() && currentId.compareTo(peeked.valueOf(xpathToAlternateId) + "_transcription") <= 0) {
76
					if (currentId.equals(peeked.valueOf(xpathToAlternateId) + "_transcription"))  {
77
						alternateQueue.remove();
78
						return peeked;
75 79
					}
76
					while (!alternateQueue.isEmpty() && currentId.compareTo(alternateQueue.peek().valueOf(xpathToIdOnAlternate)) < 0) {
77
						Document matchDoc = alternateQueue.remove();
78
						if (currentId.equals(matchDoc.valueOf(xpathToIdOnAlternate)))  {
79
							return matchDoc;
80
						}
80
					if (alternateRsClient.hasNext() && alternateQueue.isEmpty()) {
81
						populateQueue(alternateQueue, alternateRsClient.next());
81 82
					}
82 83
				}
83
				
84 84
				return null;
85 85
			}
86 86

  
87 87
			private void compose(Document doc, Document docFragment) {
88
				Element node = (Element) doc.selectSingleNode(getXpathToFragment());
89
				for (Object o : node.selectNodes("*")) {
90
					((Node) o).detach();
91
				}
92
				node.add(docFragment.getRootElement());
88
				// Prepare replacing fragment (source)
89
				Element replacingElement = (Element) docFragment.selectSingleNode(getXpathToReplacingFragment());
90
				replacingElement.detach();
91
				// Prepare replaced fragment (destination)
92
				Element replacedElement = (Element) doc.selectSingleNode(getXpathToReplacedFragment());
93
				// Move node around
94
				replacedElement.add(replacingElement);
93 95
			}
94 96
			
95 97
		});		
......
97 99
		return Arc.DEFAULT_ARC;
98 100
	}
99 101
	
102
	private void populateQueue(Queue<Document> alternateQueue, String next) {
103
		final SAXReader reader = new SAXReader();
104
		try {
105
			alternateQueue.add(reader.read(new StringReader(next)));
106
		} catch (DocumentException e) {
107
			e.printStackTrace();
108
		}
109
	}
110

  
100 111
	public MappedResultSetFactory getMappedResultSetFactory() {
101 112
		return mappedResultSetFactory;
102 113
	}
......
107 118
		this.mappedResultSetFactory = mappedResultSetFactory;
108 119
	}
109 120

  
110

  
111 121
	public ResultSetClientFactory getResultSetClientFactory() {
112 122
		return resultSetClientFactory;
113 123
	}
......
142 152
		this.composedEprParam = composedEprParam;
143 153
	}
144 154

  
155
	public String getXpathToInputId() {
156
		return xpathToInputId;
157
	}
145 158

  
146
	public String getXpathToIdOnInput() {
147
		return xpathToIdOnInput;
159
	public void setXpathToInputId(String xpathToInputId) {
160
		this.xpathToInputId = xpathToInputId;
148 161
	}
149 162

  
163
	public String getXpathToAlternateId() {
164
		return xpathToAlternateId;
165
	}
150 166

  
151
	public void setXpathToIdOnInput(String xpathToIdOnInput) {
152
		this.xpathToIdOnInput = xpathToIdOnInput;
167
	public void setXpathToAlternateId(String xpathToAlternateId) {
168
		this.xpathToAlternateId = xpathToAlternateId;
153 169
	}
154 170

  
155

  
156
	public String getXpathToIdOnAlternate() {
157
		return xpathToIdOnAlternate;
171
	public String getXpathToReplacedFragment() {
172
		return xpathToReplacedFragment;
158 173
	}
159 174

  
160

  
161
	public void setXpathToIdOnAlternate(String xpathToIdOnAlternate) {
162
		this.xpathToIdOnAlternate = xpathToIdOnAlternate;
175
	public void setXpathToReplacedFragment(String xpathToReplacedFragment) {
176
		this.xpathToReplacedFragment = xpathToReplacedFragment;
163 177
	}
164 178

  
165

  
166
	public String getXpathToFragment() {
167
		return xpathToFragment;
179
	public String getXpathToReplacingFragment() {
180
		return xpathToReplacingFragment;
168 181
	}
169 182

  
170

  
171
	public void setXpathToFragment(String xpathToFragment) {
172
		this.xpathToFragment = xpathToFragment;
183
	public void setXpathToReplacingFragment(String xpathToReplacingFragment) {
184
		this.xpathToReplacingFragment = xpathToReplacingFragment;
173 185
	}
174 186

  
175 187
}
modules/dnet-eagle-workflows/trunk/src/main/resources/eu/dnetlib/msro/eagle/workflows/repo/transform-wip.wf.st
100 100
	<PARAMETERS>
101 101
		<PARAM required="true" type="string" name="inputEprParam" managedBy="system">trans_epr</PARAM>
102 102
		<PARAM required="true" type="string" name="alternateEprParam" managedBy="system">edition_epr</PARAM>
103
		<PARAM required="true" type="string" name="xpathToIdOnInput" managedBy="system">//*[local-name()='objIdentifier']</PARAM>
104
		<PARAM required="true" type="string" name="xpathToIdOnAlternate" managedBy="system">//*[local-name()='objIdentifier']</PARAM>
105
		<PARAM required="true" type="string" name="xpathToFragment" managedBy="system">//*[local-name()='div'][@id='edition']</PARAM>
103
		<PARAM required="true" type="string" name="xpathToInputId" managedBy="system">//*[local-name()='objIdentifier']</PARAM>
104
		<PARAM required="true" type="string" name="xpathToAlternateId" managedBy="system">//*[local-name()='objIdentifier']</PARAM>
105
		<PARAM required="true" type="string" name="xpathToReplacedFragment" managedBy="system">//*[local-name()='text']</PARAM>
106
		<PARAM required="true" type="string" name="xpathToReplacingFragment" managedBy="system">//*[local-name()='div'][@id='edition']</PARAM>
106 107
		<PARAM required="true" type="string" name="composedEprParam" managedBy="system">edited_epr</PARAM>
107 108
	</PARAMETERS>
108 109
	<ARCS>

Also available in: Unified diff