gcube-sdi-suite/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/GSRESTClientImpl.java

103 lines
2.7 KiB
Java
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package org.gcube.spatial.data.clients.geoserver;
import java.util.List;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import org.gcube.common.clients.Call;
import org.gcube.spatial.data.clients.AbstractGenericRESTClient;
import org.gcube.spatial.data.clients.GenericLoginClient;
import org.gcube.spatial.data.clients.model.ConnectionDescriptor;
import org.gcube.spatial.data.sdi.model.credentials.Credentials;
import org.gcube.spatial.data.sdi.model.faults.RemoteException;
import org.gcube.spatial.data.sdi.model.gn.LoginLevel;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class GSRESTClientImpl extends AbstractGenericRESTClient implements GSRESTClient,GenericLoginClient{
private static final String API_BASE_PATH="rest";
private static final String WS_BASE_PATH="workspaces";
private static final String DATASTORE_BASE_PATH="datastores";
private static final String STYLES_BASE_PATH="styles";
private static final String LAYERS_BASE_PATH="layers";
public GSRESTClientImpl(ConnectionDescriptor conn) {
super(conn);
setBasePath(API_BASE_PATH);
log.info("Connecting to GS @ "+conn.getEndpoint());
Credentials cr=conn.getCredentials().get(0);
log.debug("Using "+cr);
register(HttpAuthenticationFeature.universal(cr.getUsername(), cr.getPassword()));
}
@Override
public void login() {
}
@Override
public void login(LoginLevel lvl) {
// TODO Auto-generated method stub
}
@Override
public JSONObject getWorkspaces() throws RemoteException,Exception {
return get(WS_BASE_PATH);
}
@Override
public JSONObject getWorkspace(String workspace) throws RemoteException, Exception {
return get(WS_BASE_PATH+"/"+workspace);
}
@Override
public JSONObject getDataStoresInWorkspace(String ws) throws RemoteException, Exception {
return get(WS_BASE_PATH+"/"+ws+"/datastores");
}
@Override
public JSONObject getStyles() throws RemoteException, Exception {
return get(STYLES_BASE_PATH);
}
@Override
public JSONObject getStylesByLayer(String layer) throws RemoteException, Exception {
return get(LAYERS_BASE_PATH+"/"+layer+"/styles");
}
@Override
public JSONObject getStylesInWorkspace(String ws) throws RemoteException, Exception {
return get(WS_BASE_PATH+"/"+ws+"/styles");
}
@Override
public void createStyle(String name, String content) throws RemoteException, Exception {
// TODO Auto-generated method stub
}
@Override
public void createWorkspace(String ws) throws RemoteException, Exception {
post(WS_BASE_PATH,Entity.entity(new JSONObject().put("name", ws),MediaType.APPLICATION_JSON));
}
}