Project

General

Profile

Download (2.25 KB) Statistics
| Branch: | Tag: | Revision:
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
			        UpdateResult result = (UpdateResult)rir.getValue();
47
			        if(result.isOk()){
48
			            cdmEntitySessionManager.load(result, true);
49
			        }
50
			    } else {
51
			        rir = new RemoteInvocationResult(cdmEntitySessionManager.load(rir.getValue(), false));
52
			    }
53
			}
54
			cache(currentRemoteInvocation, rir);
55
		}
56
		currentRemoteInvocation = null;
57

    
58
		return rir;
59
	}
60

    
61
	public void cache(RemoteInvocation ri, RemoteInvocationResult rir) {
62

    
63
	}
64

    
65
	public RemoteInvocationResult fromCache(RemoteInvocation ri) {
66
	    return null;
67
	}
68
}
(4-4/6)