2021-02-16 17:03:28 +01:00
|
|
|
|
package org.gcube.spatial.data.clients;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collection;
|
2021-02-19 12:25:00 +01:00
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
2021-02-16 17:03:28 +01:00
|
|
|
|
import java.util.ServiceLoader;
|
|
|
|
|
|
2021-02-19 12:25:00 +01:00
|
|
|
|
import org.gcube.spatial.data.clients.model.ClientInfo;
|
|
|
|
|
import org.gcube.spatial.data.clients.model.ConnectionDescriptor;
|
2021-02-19 18:45:01 +01:00
|
|
|
|
import org.gcube.spatial.data.sdi.model.service.GeoServiceDescriptor;
|
2021-02-19 12:25:00 +01:00
|
|
|
|
|
2021-02-16 17:03:28 +01:00
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class SDIClientManager {
|
|
|
|
|
|
2021-04-21 12:48:12 +02:00
|
|
|
|
private List<SDIGenericPlugin> clients=new ArrayList<SDIGenericPlugin>();
|
2021-02-16 17:03:28 +01:00
|
|
|
|
|
|
|
|
|
public SDIClientManager() {
|
2021-04-21 12:48:12 +02:00
|
|
|
|
ServiceLoader.load(SDIGenericPlugin.class).forEach((SDIGenericPlugin c)->{clients.add(c);});
|
2021-02-16 17:03:28 +01:00
|
|
|
|
log.info("Loaded {} clients ",clients.size());
|
2021-04-21 12:48:12 +02:00
|
|
|
|
clients.forEach((SDIGenericPlugin c)->{
|
2021-02-16 17:03:28 +01:00
|
|
|
|
log.debug("Loaded "+c.getInfo());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the implementation for the target engine. Null if no suitable plugin is found
|
|
|
|
|
*
|
|
|
|
|
* @param engine
|
|
|
|
|
* @param version
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2021-04-21 12:48:12 +02:00
|
|
|
|
public SDIGenericPlugin get(String engine,String version) {
|
2021-02-16 17:03:28 +01:00
|
|
|
|
log.info("Looking for clients [target : {} {} ] ",engine,version);
|
2021-04-21 12:48:12 +02:00
|
|
|
|
for(SDIGenericPlugin c:clients) {
|
2021-02-16 17:03:28 +01:00
|
|
|
|
if(c.getInfo().getSupportedEngine().getEngineUniqueString().equals(engine)
|
|
|
|
|
&& c.getInfo().getSupportedEngine().getRange().supports(version))
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2021-02-19 12:25:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the implementation for the target engine's Connection. Null if no suitable plugin is found
|
|
|
|
|
*
|
|
|
|
|
* @param engine
|
|
|
|
|
* @param version
|
|
|
|
|
* @return
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2021-04-21 12:48:12 +02:00
|
|
|
|
public SDIGenericPlugin get(ConnectionDescriptor conn) throws Exception {
|
|
|
|
|
SDIGenericPlugin toReturn=get(conn.getEngineUniqueID(),conn.getVersion());
|
2021-02-19 12:25:00 +01:00
|
|
|
|
if(toReturn==null) throw new Exception("Unable to get client for "+conn.getEngineUniqueID()+" "+conn.getVersion());
|
|
|
|
|
return toReturn.at(conn);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-19 18:45:01 +01:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the implementation for the target service. Null if no suitable plugin is found
|
|
|
|
|
*
|
|
|
|
|
* @param engine
|
|
|
|
|
* @param version
|
|
|
|
|
* @return
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2021-04-21 12:48:12 +02:00
|
|
|
|
public SDIGenericPlugin get(GeoServiceDescriptor service) throws Exception {
|
2021-02-19 18:45:01 +01:00
|
|
|
|
return get(service.getConnection());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-02-19 12:25:00 +01:00
|
|
|
|
public List<ClientInfo> list(){
|
|
|
|
|
List<ClientInfo> toReturn=new ArrayList<ClientInfo>();
|
2021-04-21 12:48:12 +02:00
|
|
|
|
clients.forEach((SDIGenericPlugin c)->{toReturn.add(c.getInfo());});
|
2021-02-19 12:25:00 +01:00
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
2021-02-19 18:45:01 +01:00
|
|
|
|
|
|
|
|
|
public List<ClientInfo> list(String engineId){
|
|
|
|
|
List<ClientInfo> toReturn=new ArrayList<ClientInfo>();
|
2021-04-21 12:48:12 +02:00
|
|
|
|
clients.forEach((SDIGenericPlugin c)->{
|
2021-02-19 18:45:01 +01:00
|
|
|
|
if(c.getInfo().getSupportedEngine().getEngineUniqueString().equals(engineId))
|
|
|
|
|
toReturn.add(c.getInfo());});
|
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
2021-02-16 17:03:28 +01:00
|
|
|
|
}
|