Project

General

Profile

« Previous | Next » 

Revision 15a62a24

Added by Cherian Mathew over 8 years ago

#4073 Initial implementation of local cdm-server

View differences:

eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/CdmServerInfo.java
28 28
import org.json.JSONObject;
29 29

  
30 30
import eu.etaxonomy.cdm.config.CdmSourceException;
31
import eu.etaxonomy.cdm.database.CdmPersistentDataSource;
32
import eu.etaxonomy.cdm.database.ICdmDataSource;
31 33
import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
32 34

  
33 35
/**
......
48 50
    private final static String NAME_TEST = "edit-test";
49 51
    private final static String SERVER_TEST = "test.e-taxonomy.eu";
50 52

  
51
    private final static String SERVER_LOCALHOST = "localhost";
53
    public final static String SERVER_LOCALHOST = "localhost";
52 54
    private final static String NAME_LOCALHOST = "localhost";
53
    private final static String NAME_LOCALHOST_MGD = "localhost mgd.";
55
    public final static String NAME_LOCALHOST_MGD = "localhost mgd.";
54 56

  
55 57
    private final static String NAME_LOCALHOST_DEV = "localhost-dev";
56 58
    private final static String NAME_INSTANCE_LOCALHOST_DEV = "local-dev";
......
63 65
    private final int port;
64 66
    private final List<CdmInstanceInfo> instances;
65 67

  
68
    private static List<CdmServerInfo> cdmServerInfoList;
66 69

  
67 70
    public CdmServerInfo(String name, String server, int port) {
68 71
        this.name = name;
......
80 83
    }
81 84

  
82 85
    public boolean isLocalhost() {
83
        return name.startsWith(SERVER_LOCALHOST_DEV);
86
        return name.startsWith(SERVER_LOCALHOST);
84 87
    }
88

  
89
    public boolean isLocalhostMgd() {
90
        return NAME_LOCALHOST_MGD.equals(name);
91
    }
92

  
85 93
    public void refreshInstances() throws CDMServerException {
86 94
        instances.clear();
95
        if(isLocalhostMgd()) {
96
            addInstancesFromDataSourcesConfig();
97
        } else {
98
            addInstancesViaHttp();
99
        }
100

  
101
    }
102

  
103
    public void addInstancesViaHttp() throws CDMServerException {
87 104
        String url = "http://" + server + ":" + String.valueOf(port) + "/" + CDMSERVER_PREFIX + "/instances.jsp";
88 105

  
89 106
        HttpClient client = new DefaultHttpClient();
......
138 155
                throw new CDMServerException(e);
139 156
            }
140 157
        }
158
    }
159

  
160
    public void addInstancesFromDataSourcesConfig() {
161

  
162
        for(ICdmDataSource dataSource : CdmPersistentDataSource.getAllDataSources()){
163
            logger.warn("Adding local instance " + dataSource.getName());
164
            addInstance(dataSource.getName(), dataSource.getName());
165
        }
141 166

  
142 167
    }
143 168

  
......
196 221
    }
197 222

  
198 223
    public static List<CdmServerInfo> getCdmServers() {
199
        List<CdmServerInfo> cdmServerInfoList = new ArrayList<CdmServerInfo>();
200
        cdmServerInfoList.add(new CdmServerInfo(NAME_PRODUCTION, SERVER_PRODUCTION, 80));
201
        cdmServerInfoList.add(new CdmServerInfo(NAME_INTEGRATION, SERVER_INTEGRATION, 80));
202
        cdmServerInfoList.add(new CdmServerInfo(NAME_TEST, SERVER_TEST, 80));
203
        cdmServerInfoList.add(new CdmServerInfo(NAME_LOCALHOST, SERVER_LOCALHOST, 8080));
204
        cdmServerInfoList.add(new CdmServerInfo(NAME_LOCALHOST_MGD, SERVER_LOCALHOST,8080));
224
        if(cdmServerInfoList == null) {
225
            cdmServerInfoList = new ArrayList<CdmServerInfo>();
226
            cdmServerInfoList.add(new CdmServerInfo(NAME_PRODUCTION, SERVER_PRODUCTION, 80));
227
            cdmServerInfoList.add(new CdmServerInfo(NAME_INTEGRATION, SERVER_INTEGRATION, 80));
228
            cdmServerInfoList.add(new CdmServerInfo(NAME_TEST, SERVER_TEST, 80));
229
            cdmServerInfoList.add(new CdmServerInfo(NAME_LOCALHOST, SERVER_LOCALHOST, 8080));
230
            cdmServerInfoList.add(new CdmServerInfo(NAME_LOCALHOST_MGD, SERVER_LOCALHOST,8080));
231
        }
205 232
        return cdmServerInfoList;
206 233
    }
207 234

  
......
248 275

  
249 276
    public class CdmInstanceInfo {
250 277
        private final String name;
278

  
279
        /**
280
         * The full path of the instance including the the prefix (if any).
281
         * E.g. for an EDIT instance this would be something like "cdmserver/remoting"
282
         * For a managed local server this would simply be "remoting"
283
         */
251 284
        private final String basePath;
252 285

  
253 286

  

Also available in: Unified diff