1
|
/**
|
2
|
* Copyright (C) 2014 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.api.application;
|
10
|
|
11
|
import java.util.List;
|
12
|
|
13
|
import org.apache.log4j.Logger;
|
14
|
import org.hibernate.collection.internal.AbstractPersistentCollection;
|
15
|
import org.hibernate.proxy.AbstractLazyInitializer;
|
16
|
import org.springframework.context.ApplicationListener;
|
17
|
import org.springframework.core.io.ClassPathResource;
|
18
|
import org.springframework.core.io.Resource;
|
19
|
|
20
|
import eu.etaxonomy.cdm.api.service.ITestService;
|
21
|
import eu.etaxonomy.cdm.cache.CdmRemoteCacheManager;
|
22
|
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
|
23
|
import eu.etaxonomy.cdm.common.monitor.NullProgressMonitor;
|
24
|
import eu.etaxonomy.cdm.ext.geo.IEditGeoService;
|
25
|
import eu.etaxonomy.cdm.io.service.IIOService;
|
26
|
import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
|
27
|
import eu.etaxonomy.taxeditor.service.ICachedCommonService;
|
28
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
|
29
|
|
30
|
/**
|
31
|
* CDM Application Controller class for remoting clients
|
32
|
*
|
33
|
* FIXME:Remoting extending {@link CdmApplicationController} is a temporary workaround.
|
34
|
* The {@link CdmApplicationController} should be split into a CdmApplicationControllerBase
|
35
|
* class with {@link CdmApplicationController} and this class as subclasses
|
36
|
*/
|
37
|
public class CdmApplicationRemoteController extends CdmApplicationController {
|
38
|
|
39
|
private static final Logger logger = Logger.getLogger(CdmApplicationRemoteController.class);
|
40
|
|
41
|
public static final Resource DEFAULT_REMOTE_APPLICATION_CONTEXT_RESOURCE =
|
42
|
new ClassPathResource("/eu/etaxonomy/cdm/remotingApplicationContext.xml");
|
43
|
private final Resource applicationContextResource;
|
44
|
private final IProgressMonitor progressMonitor;
|
45
|
private final ICdmRemoteSource remoteSource;
|
46
|
|
47
|
// public static CdmApplicationRemoteController NewInstance(Resource applicationContextResource,
|
48
|
// ICdmRemoteSource remoteSource,
|
49
|
// IProgressMonitor progressMonitor,
|
50
|
// List<ApplicationListener> listeners) {
|
51
|
// return new CdmApplicationRemoteController(applicationContextResource,
|
52
|
// remoteSource,
|
53
|
// false,
|
54
|
// progressMonitor,
|
55
|
// listeners);
|
56
|
//
|
57
|
// }
|
58
|
|
59
|
/**
|
60
|
* Creates new instance of CdmApplicationRemoteController
|
61
|
*
|
62
|
* @param applicationContextResource
|
63
|
* @param remoteSource
|
64
|
* @param omitTermLoading
|
65
|
* @param progressMonitor
|
66
|
* @param listeners
|
67
|
* @return
|
68
|
*/
|
69
|
public static CdmApplicationRemoteController NewInstance(ICdmRemoteSource remoteSource,
|
70
|
IProgressMonitor progressMonitor,
|
71
|
List<ApplicationListener> listeners) {
|
72
|
|
73
|
return new CdmApplicationRemoteController(DEFAULT_REMOTE_APPLICATION_CONTEXT_RESOURCE,
|
74
|
remoteSource,
|
75
|
false,
|
76
|
progressMonitor,
|
77
|
listeners);
|
78
|
}
|
79
|
|
80
|
public static CdmApplicationRemoteController NewInstance(ICdmRemoteSource remoteSource,
|
81
|
boolean validateXml,
|
82
|
IProgressMonitor progressMonitor,
|
83
|
List<ApplicationListener> listeners) {
|
84
|
|
85
|
return new CdmApplicationRemoteController(DEFAULT_REMOTE_APPLICATION_CONTEXT_RESOURCE,
|
86
|
remoteSource,
|
87
|
validateXml,
|
88
|
progressMonitor,
|
89
|
listeners);
|
90
|
}
|
91
|
|
92
|
/**
|
93
|
* Constructs CdmApplicationRemoteController
|
94
|
*
|
95
|
* @param applicationContextResource
|
96
|
* @param remoteSource
|
97
|
* @param omitTermLoading
|
98
|
* @param progressMonitor
|
99
|
* @param listeners
|
100
|
*/
|
101
|
private CdmApplicationRemoteController(Resource applicationContextResource,
|
102
|
ICdmRemoteSource remoteSource,
|
103
|
boolean validateXml,
|
104
|
IProgressMonitor progressMonitor,
|
105
|
List<ApplicationListener> listeners){
|
106
|
logger.info("Start CdmApplicationRemoteController with remote source: " + remoteSource.getName());
|
107
|
this.applicationContextResource =
|
108
|
applicationContextResource != null ? applicationContextResource : DEFAULT_REMOTE_APPLICATION_CONTEXT_RESOURCE;
|
109
|
this.progressMonitor = progressMonitor != null ? progressMonitor : new NullProgressMonitor();
|
110
|
this.remoteSource = remoteSource;
|
111
|
setNewRemoteSource(remoteSource, validateXml, listeners);
|
112
|
|
113
|
}
|
114
|
|
115
|
/**
|
116
|
* Creates and starts a new spring application context
|
117
|
*
|
118
|
* @param remoteSource object for connecting to an http-invoker server
|
119
|
* @param omitTermLoading
|
120
|
* @param listeners
|
121
|
* @return
|
122
|
*/
|
123
|
public boolean setNewRemoteSource(ICdmRemoteSource remoteSource,
|
124
|
boolean validateXml,
|
125
|
List<ApplicationListener> listeners){
|
126
|
|
127
|
logger.info("Connecting to '" + remoteSource.getName() + "'");
|
128
|
|
129
|
int nTasks = 2;
|
130
|
|
131
|
progressMonitor.beginTask("Connecting to '" + remoteSource.getName() + "'", nTasks);
|
132
|
|
133
|
progressMonitor.subTask("Initialising CDM Model Cache ...");
|
134
|
CdmRemoteCacheManager.getInstance();
|
135
|
CdmRemoteCacheManager.removeEntityCaches();
|
136
|
progressMonitor.worked(1);
|
137
|
progressMonitor.subTask("Starting application context ...");
|
138
|
init();
|
139
|
progressMonitor.worked(1);
|
140
|
progressMonitor.done();
|
141
|
return true;
|
142
|
}
|
143
|
|
144
|
@Override
|
145
|
protected void init(){
|
146
|
configuration = new CdmApplicationRemoteConfiguration(remoteSource);
|
147
|
((CdmApplicationRemoteConfiguration)configuration).setApplicationContext(applicationContext);
|
148
|
AbstractLazyInitializer.setConfiguration((CdmApplicationRemoteConfiguration)configuration);
|
149
|
AbstractPersistentCollection.setConfiguration((CdmApplicationRemoteConfiguration)configuration);
|
150
|
}
|
151
|
|
152
|
public ICdmEntitySessionManager getCdmEntitySessionManager() {
|
153
|
return ((CdmApplicationRemoteConfiguration)configuration).getCdmEntitySessionManager();
|
154
|
}
|
155
|
|
156
|
public IIOService getIOService(){
|
157
|
return ((CdmApplicationRemoteConfiguration)configuration).getIOService();
|
158
|
}
|
159
|
|
160
|
public ITestService getTestService(){
|
161
|
return ((CdmApplicationRemoteConfiguration)configuration).getTestService();
|
162
|
}
|
163
|
|
164
|
public ICachedCommonService getCachedCommonService(){
|
165
|
return ((CdmApplicationRemoteConfiguration)configuration).getCachedCommonService();
|
166
|
}
|
167
|
|
168
|
public IEditGeoService getEditGeoService() {
|
169
|
return ((CdmApplicationRemoteConfiguration)configuration).getEditGeoService();
|
170
|
}
|
171
|
}
|