1
|
package eu.etaxonomy.taxeditor.service;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
import java.io.OutputStream;
|
5
|
|
6
|
import org.springframework.beans.factory.annotation.Autowired;
|
7
|
import org.springframework.remoting.httpinvoker.HttpInvokerClientConfiguration;
|
8
|
import org.springframework.remoting.support.RemoteInvocation;
|
9
|
import org.springframework.remoting.support.RemoteInvocationResult;
|
10
|
import org.springframework.stereotype.Component;
|
11
|
|
12
|
import eu.etaxonomy.cdm.api.service.UpdateResult;
|
13
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
|
14
|
|
15
|
@Component
|
16
|
public class CdmServiceRequestExecutor extends CdmAuthenticatedHttpInvokerRequestExecutor {
|
17
|
|
18
|
@Autowired
|
19
|
private ICdmEntitySessionManager cdmEntitySessionManager;
|
20
|
|
21
|
private RemoteInvocation currentRemoteInvocation;
|
22
|
|
23
|
@Override
|
24
|
protected void writeRemoteInvocation(RemoteInvocation invocation, OutputStream os) throws IOException {
|
25
|
currentRemoteInvocation = invocation;
|
26
|
super.writeRemoteInvocation(invocation, os);
|
27
|
}
|
28
|
|
29
|
@Override
|
30
|
protected RemoteInvocationResult doExecuteRequest(HttpInvokerClientConfiguration config,
|
31
|
java.io.ByteArrayOutputStream baos)
|
32
|
throws java.io.IOException,
|
33
|
java.lang.ClassNotFoundException {
|
34
|
RemoteInvocationResult rir = fromCache(currentRemoteInvocation);
|
35
|
|
36
|
// if rir is not null at this point we assume that the
|
37
|
// the object has already been loaded in the cache and
|
38
|
// does not need to be reloaded
|
39
|
|
40
|
if(rir == null) {
|
41
|
rir = super.doExecuteRequest(config, baos);
|
42
|
if(rir.getValue() != null && !rir.hasException()) {
|
43
|
if(currentRemoteInvocation.getMethodName().equals("merge")) {
|
44
|
rir = new RemoteInvocationResult(cdmEntitySessionManager.load(rir.getValue(), true));
|
45
|
} else if(rir.getValue() instanceof UpdateResult){
|
46
|
//FIXME:Remoting if the new handler / operation architecture works then this is not required
|
47
|
// UpdateResult result = (UpdateResult)rir.getValue();
|
48
|
// if(result.isOk()){
|
49
|
// //FIXME:Remoting replace with call to CdmApplicationState if required
|
50
|
// }
|
51
|
} else {
|
52
|
rir = new RemoteInvocationResult(cdmEntitySessionManager.load(rir.getValue(), false));
|
53
|
}
|
54
|
}
|
55
|
cache(currentRemoteInvocation, rir);
|
56
|
}
|
57
|
currentRemoteInvocation = null;
|
58
|
|
59
|
return rir;
|
60
|
}
|
61
|
|
62
|
public void cache(RemoteInvocation ri, RemoteInvocationResult rir) {
|
63
|
|
64
|
}
|
65
|
|
66
|
public RemoteInvocationResult fromCache(RemoteInvocation ri) {
|
67
|
return null;
|
68
|
}
|
69
|
}
|