This commit is contained in:
Fabio Sinibaldi 2017-03-30 13:31:39 +00:00
parent cab61799f9
commit 7877a10868
17 changed files with 457 additions and 76 deletions

View File

@ -8,4 +8,5 @@ public class Constants {
public static final String GEONETWORK_CONFIGURATION_PATH="configuration";
public static final String GEONETWORK_GROUPS_PATH="groups";
public static final String SDI_INTERFACE="SDI";
}

View File

@ -0,0 +1,9 @@
package org.gcube.spatial.data.sdi.engine;
import org.gcube.spatial.data.sdi.model.ScopeConfiguration;
public interface SDIManager {
public ScopeConfiguration getContextConfiguration();
}

View File

@ -0,0 +1,39 @@
package org.gcube.spatial.data.sdi.engine.impl;
import java.util.Arrays;
import javax.inject.Singleton;
import org.gcube.spatial.data.sdi.engine.SDIManager;
import org.gcube.spatial.data.sdi.model.ScopeConfiguration;
import org.gcube.spatial.data.sdi.model.credentials.AccessType;
import org.gcube.spatial.data.sdi.model.credentials.Credentials;
import org.gcube.spatial.data.sdi.model.service.GeoNetworkConfiguration;
import org.gcube.spatial.data.sdi.model.service.GeoServerClusterConfiguration;
import org.gcube.spatial.data.sdi.model.service.GeoServerConfiguration;
import org.gcube.spatial.data.sdi.model.service.ThreddsConfiguration;
import org.gcube.spatial.data.sdi.model.service.Version;
@Singleton
public class SDIManagerImpl implements SDIManager {
@Override
public ScopeConfiguration getContextConfiguration() {
GeoNetworkConfiguration gn=new GeoNetworkConfiguration(new Version(2,2,2), "http://geonetwork.d4science.org/geonetwork",
Arrays.asList(new Credentials("GNuser","pwd",AccessType.ADMIN)), "vre_group", "vre_shared", "global public access");
ThreddsConfiguration thredds=new ThreddsConfiguration(new Version(2,2,2), "http://thredds.d4sciecne.org/thredds",
Arrays.asList(new Credentials("THuser","pwd",AccessType.ADMIN)));
GeoServerConfiguration gs1=new GeoServerConfiguration(new Version(2,10,1), "http://geoserver1.d4science.org/geoserver",
Arrays.asList(new Credentials("GS1user","pwd",AccessType.ADMIN)), "context_confidential_ws", "context_only_ws", "context_ws", "public_access_ws");
GeoServerConfiguration gs2=new GeoServerConfiguration(new Version(2,6,1), "http://geoserver2.d4science.org/geoserver",
Arrays.asList(new Credentials("GS1user","pwd",AccessType.ADMIN)), "context_confidential_ws", "context_only_ws", "context_ws", "public_access_ws");
ScopeConfiguration toReturn=new ScopeConfiguration("/some/context", gn, new GeoServerClusterConfiguration(Arrays.asList(gs1,gs2)), thredds);
return toReturn;
}
}

View File

@ -0,0 +1,39 @@
package org.gcube.spatial.data.sdi.model;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import org.gcube.spatial.data.sdi.model.service.GeoNetworkConfiguration;
import org.gcube.spatial.data.sdi.model.service.GeoServerClusterConfiguration;
import org.gcube.spatial.data.sdi.model.service.ThreddsConfiguration;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
@NoArgsConstructor
@RequiredArgsConstructor
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class ScopeConfiguration {
@NonNull
private String contextName;
@NonNull
private GeoNetworkConfiguration geonetworkConfiguration;
@NonNull
private GeoServerClusterConfiguration geoserverClusterConfiguration;
@NonNull
private ThreddsConfiguration threddsConfiguration;
}

View File

@ -0,0 +1,6 @@
package org.gcube.spatial.data.sdi.model.credentials;
public enum AccessType {
CKAN,ADMIN,CONTEXT_USER,CONTEXT_MANAGER
}

View File

@ -0,0 +1,35 @@
package org.gcube.spatial.data.sdi.model.credentials;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
@RequiredArgsConstructor
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Credentials {
@NonNull
private String username;
@NonNull
private String password;
@NonNull
private AccessType accessType;
@Override
public String toString() {
return "Credentials [username=" + username + ", password=****, accessType=" + accessType + "]";
}
}

View File

@ -0,0 +1,36 @@
package org.gcube.spatial.data.sdi.model.service;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import org.gcube.spatial.data.sdi.model.credentials.Credentials;
import lombok.NoArgsConstructor;
import lombok.NonNull;
@NoArgsConstructor
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class GeoNetworkConfiguration extends GeoService{
public GeoNetworkConfiguration(Version version, String baseEndpoint, List<Credentials> accessibleCredentials,
String contextGroup, String sharedGroup, String publicGroup) {
super(version, baseEndpoint, accessibleCredentials);
this.contextGroup = contextGroup;
this.sharedGroup = sharedGroup;
this.publicGroup = publicGroup;
}
@NonNull
private String contextGroup;
@NonNull
private String sharedGroup;
@NonNull
private String publicGroup;
}

View File

@ -0,0 +1,30 @@
package org.gcube.spatial.data.sdi.model.service;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
@NoArgsConstructor
@RequiredArgsConstructor
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class GeoServerClusterConfiguration {
@NonNull
private List<GeoServerConfiguration> availableInstances;
}

View File

@ -0,0 +1,47 @@
package org.gcube.spatial.data.sdi.model.service;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import org.gcube.spatial.data.sdi.model.credentials.Credentials;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
@NoArgsConstructor
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class GeoServerConfiguration extends GeoService {
public GeoServerConfiguration(Version version, String baseEndpoint, List<Credentials> accessibleCredentials,
String confidentialWorkspace, String contextVisibilityWorkspace, String sharedWorkspace,
String publicWorkspace) {
super(version, baseEndpoint, accessibleCredentials);
this.confidentialWorkspace = confidentialWorkspace;
this.contextVisibilityWorkspace = contextVisibilityWorkspace;
this.sharedWorkspace = sharedWorkspace;
this.publicWorkspace = publicWorkspace;
}
@NonNull
private String confidentialWorkspace;
@NonNull
private String contextVisibilityWorkspace;
@NonNull
private String sharedWorkspace;
@NonNull
private String publicWorkspace;
}

View File

@ -0,0 +1,38 @@
package org.gcube.spatial.data.sdi.model.service;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import org.gcube.spatial.data.sdi.model.credentials.Credentials;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
@NoArgsConstructor
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class GeoService {
public GeoService(Version version, String baseEndpoint, List<Credentials> accessibleCredentials) {
super();
this.version = version;
this.baseEndpoint = baseEndpoint;
this.accessibleCredentials = accessibleCredentials;
}
@NonNull
private Version version;
@NonNull
private String baseEndpoint;
@NonNull
private List<Credentials> accessibleCredentials;
}

View File

@ -0,0 +1,32 @@
package org.gcube.spatial.data.sdi.model.service;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import org.gcube.spatial.data.sdi.model.credentials.Credentials;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@ToString
@Getter
@Setter
@NoArgsConstructor
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class ThreddsConfiguration extends GeoService{
public ThreddsConfiguration(Version version, String baseEndpoint, List<Credentials> accessibleCredentials) {
super(version, baseEndpoint, accessibleCredentials);
// TODO Auto-generated constructor stub
}
}

View File

@ -0,0 +1,27 @@
package org.gcube.spatial.data.sdi.model.service;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Data
@RequiredArgsConstructor
@NoArgsConstructor
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Version {
@NonNull
private Integer major;
@NonNull
private Integer minor;
@NonNull
private Integer build;
}

View File

@ -1,81 +1,60 @@
package org.gcube.spatial.data.sdi.rest;
import java.util.Collection;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response.Status;
import org.gcube.spatial.data.geonetwork.GeoNetworkAdministration;
import org.gcube.spatial.data.geonetwork.LoginLevel;
import org.gcube.spatial.data.geonetwork.model.Group;
import org.gcube.spatial.data.geonetwork.model.ScopeConfiguration;
import org.gcube.spatial.data.geonetwork.model.faults.AuthorizationException;
import org.gcube.spatial.data.geonetwork.model.faults.MissingConfigurationException;
import org.gcube.spatial.data.geonetwork.model.faults.MissingServiceEndpointException;
import org.gcube.spatial.data.geonetwork.utils.ScopeUtils;
import org.gcube.spatial.data.sdi.Constants;
import org.gcube.spatial.data.sdi.engine.GeoNetworkProvider;
import org.gcube.spatial.data.sdi.engine.impl.faults.ClientInitializationException;
import io.swagger.annotations.Api;
import it.geosolutions.geonetwork.exception.GNLibException;
import it.geosolutions.geonetwork.exception.GNServerException;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Path(Constants.GEONETWORK_INTERFACE)
@Api(value="GeoNetwork")
//@Api(value="GeoNetwork")
public class GeoNetwork {
@Inject
GeoNetworkProvider geonetworkProvider;
@GET
@Path(Constants.GEONETWORK_CONFIGURATION_PATH)
@Produces(MediaType.APPLICATION_JSON)
public ScopeConfiguration getConfiguration(){
try {
return geonetworkProvider.getGeoNetwork().getConfiguration().getScopeConfiguration();
} catch (MissingConfigurationException | MissingServiceEndpointException e) {
log.warn("Unable to get GeoNetwork configuration. Current scope is {} ",ScopeUtils.getCurrentScope(),e);
throw new WebApplicationException("Scope is not well configured. Please contact administrator.", e, Status.PRECONDITION_FAILED);
} catch (ClientInitializationException e) {
log.warn("Unable to get GN Client",e);
throw new WebApplicationException("Internal Error. Please contact administrator.", e, Status.INTERNAL_SERVER_ERROR);
}
}
@GET
@Path(Constants.GEONETWORK_GROUPS_PATH)
@Produces(MediaType.APPLICATION_JSON)
public Collection<Group> getGroups(){
try {
GeoNetworkAdministration admin=geonetworkProvider.getGeoNetwork();
admin.login(LoginLevel.ADMIN);
return admin.getGroups();
} catch (MissingConfigurationException | MissingServiceEndpointException e) {
log.warn("Unable to get GeoNetwork configuration. Current scope is {} ",ScopeUtils.getCurrentScope(),e);
throw new WebApplicationException("Scope is not well configured. Please contact administrator.", e, Status.PRECONDITION_FAILED);
} catch (AuthorizationException e) {
log.warn("Unable to use Admin rights.",e);
throw new WebApplicationException("Unable to use Admin rights on GeoNetwork. Please contact administrator.", e, Status.INTERNAL_SERVER_ERROR);
} catch (GNLibException e) {
log.warn("Internal library exception.",e);
throw new WebApplicationException("Internal library exception.", e, Status.INTERNAL_SERVER_ERROR);
} catch (GNServerException e) {
log.warn("GeoNEtwork service exception.",e);
throw new WebApplicationException("GeoNetwork service exception.", e, Status.INTERNAL_SERVER_ERROR);
} catch (ClientInitializationException e) {
log.warn("Unable to get GN Client",e);
throw new WebApplicationException("Internal Error. Please contact administrator.", e, Status.INTERNAL_SERVER_ERROR);
}
}
//
// @Inject
// GeoNetworkProvider geonetworkProvider;
//
//
// @GET
// @Path(Constants.GEONETWORK_CONFIGURATION_PATH)
// @Produces(MediaType.APPLICATION_JSON)
// public ScopeConfiguration getConfiguration(){
// try {
// return geonetworkProvider.getGeoNetwork().getConfiguration().getScopeConfiguration();
// } catch (MissingConfigurationException | MissingServiceEndpointException e) {
// log.warn("Unable to get GeoNetwork configuration. Current scope is {} ",ScopeUtils.getCurrentScope(),e);
// throw new WebApplicationException("Scope is not well configured. Please contact administrator.", e, Status.PRECONDITION_FAILED);
// } catch (ClientInitializationException e) {
// log.warn("Unable to get GN Client",e);
// throw new WebApplicationException("Internal Error. Please contact administrator.", e, Status.INTERNAL_SERVER_ERROR);
// }
// }
//
// @GET
// @Path(Constants.GEONETWORK_GROUPS_PATH)
// @Produces(MediaType.APPLICATION_JSON)
// public Collection<Group> getGroups(){
// try {
// GeoNetworkAdministration admin=geonetworkProvider.getGeoNetwork();
// admin.login(LoginLevel.ADMIN);
// return admin.getGroups();
// } catch (MissingConfigurationException | MissingServiceEndpointException e) {
// log.warn("Unable to get GeoNetwork configuration. Current scope is {} ",ScopeUtils.getCurrentScope(),e);
// throw new WebApplicationException("Scope is not well configured. Please contact administrator.", e, Status.PRECONDITION_FAILED);
// } catch (AuthorizationException e) {
// log.warn("Unable to use Admin rights.",e);
// throw new WebApplicationException("Unable to use Admin rights on GeoNetwork. Please contact administrator.", e, Status.INTERNAL_SERVER_ERROR);
// } catch (GNLibException e) {
// log.warn("Internal library exception.",e);
// throw new WebApplicationException("Internal library exception.", e, Status.INTERNAL_SERVER_ERROR);
// } catch (GNServerException e) {
// log.warn("GeoNEtwork service exception.",e);
// throw new WebApplicationException("GeoNetwork service exception.", e, Status.INTERNAL_SERVER_ERROR);
// } catch (ClientInitializationException e) {
// log.warn("Unable to get GN Client",e);
// throw new WebApplicationException("Internal Error. Please contact administrator.", e, Status.INTERNAL_SERVER_ERROR);
// }
// }

View File

@ -0,0 +1,32 @@
package org.gcube.spatial.data.sdi.rest;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.gcube.spatial.data.sdi.Constants;
import org.gcube.spatial.data.sdi.engine.SDIManager;
import org.gcube.spatial.data.sdi.model.ScopeConfiguration;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Path(Constants.SDI_INTERFACE)
@Api(value=Constants.SDI_INTERFACE)
public class SDI {
@Inject
private SDIManager sdiManager;
@GET
@Produces(MediaType.APPLICATION_JSON)
public ScopeConfiguration getConfiguration(){
return sdiManager.getContextConfiguration();
}
}

View File

@ -25,7 +25,7 @@ no. 654119), SoBigData (grant no. 654024);
Version
--------------------------------------------------
0.0.1-SNAPSHOT (2017-03-28)
0.0.1-SNAPSHOT (2017-03-30)
Please see the file named "changelog.xml" in this directory for the release notes.

View File

@ -5,7 +5,7 @@ import javax.ws.rs.core.MediaType;
import org.gcube.spatial.data.sdi.Constants;
import org.gcube.spatial.data.sdi.SDIService;
import org.gcube.spatial.data.sdi.engine.GeoNetworkProvider;
import org.gcube.spatial.data.sdi.engine.SDIManager;
import org.gcube.spatial.data.sdi.rest.GeoNetwork;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.server.ResourceConfig;
@ -25,7 +25,8 @@ public class MainTest extends JerseyTest{
@Override
protected void configure() {
bindFactory(GeoNetworkProviderFactory.class).to(GeoNetworkProvider.class);
// bindFactory(GeoNetworkProviderFactory.class).to(GeoNetworkProvider.class);
bindFactory(SDIManagerFactory.class).to(SDIManager.class);
}
}
@ -60,15 +61,22 @@ public class MainTest extends JerseyTest{
}
// @Test
// public void getConfiguration(){
// System.out.println(target(Constants.GEONETWORK_INTERFACE).
// path(Constants.GEONETWORK_CONFIGURATION_PATH).
// request(MediaType.APPLICATION_JSON_TYPE).get(String.class));
// System.out.println(target(Constants.GEONETWORK_INTERFACE).
// path(Constants.GEONETWORK_CONFIGURATION_PATH).
// getUri());
// }
@Test
public void getConfiguration(){
System.out.println(target(Constants.GEONETWORK_INTERFACE).
path(Constants.GEONETWORK_CONFIGURATION_PATH).
request(MediaType.APPLICATION_JSON_TYPE).get(String.class));
System.out.println(target(Constants.GEONETWORK_INTERFACE).
path(Constants.GEONETWORK_CONFIGURATION_PATH).
getUri());
System.out.println(target(Constants.SDI_INTERFACE).request(MediaType.APPLICATION_JSON_TYPE).get(String.class));
}
//
// @Test
// public void getSwagger(){

View File

@ -0,0 +1,23 @@
package org.gcube.spatial.data.sdi.test;
import org.gcube.spatial.data.sdi.engine.SDIManager;
import org.gcube.spatial.data.sdi.engine.impl.SDIManagerImpl;
import org.glassfish.hk2.api.Factory;
public class SDIManagerFactory implements Factory<SDIManager>{
public SDIManagerFactory() {
// TODO Auto-generated constructor stub
}
@Override
public void dispose(SDIManager arg0) {
// TODO Auto-generated method stub
}
@Override
public SDIManager provide() {
return new SDIManagerImpl();
}
}