merged 4.1

git-svn-id: http://svn.research-infrastructures.eu/d4science/gcube/trunk/spatial-data/geonetwork@133591 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Fabio Sinibaldi 2016-10-26 15:35:40 +00:00
parent ae4b04a1d1
commit 56bed0b8ab
27 changed files with 55443 additions and 1171382 deletions

View File

@ -13,6 +13,8 @@
<Change>Improved check on configuration constraints</Change>
</Changeset>
<Changeset component="geonetwork.3-1-0" date="2016-09-09">
<Change>Added Security token management</Change>
<Change>Added Security token management</Change>
<Change>Multiple GN version handling by integrating geonetwork-manager 1.4-SNAPSHOT</Change>
<Change>Introduced 'Publish and promote' API</Change>
</Changeset>
</ReleaseNotes>

View File

@ -1,5 +0,0 @@
24968
24969
24970
24971
24975

245034
log.txt

File diff suppressed because one or more lines are too long

967084
log.txt.1

File diff suppressed because one or more lines are too long

View File

19
pom.xml
View File

@ -61,13 +61,19 @@
<groupId>org.gcube.resources</groupId>
<artifactId>common-gcore-resources</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>uri-resolver-manager</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<!-- EXTERNAL -->
<dependency>
<groupId>it.geosolutions</groupId>
<artifactId>geonetwork-manager</artifactId>
<version>1.1</version>
<version>1.4-SNAPSHOT</version>
</dependency>
<dependency>
@ -95,7 +101,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>0.11.6</version>
<version>1.14.8</version>
</dependency>
<!-- TEST -->
@ -107,12 +113,7 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>uri-resolver-manager</artifactId>
<scope>test</scope>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
@ -125,7 +126,7 @@
<repositories>
<repository>
<id>GeoSolutions</id>
<url>http://maven.research-infrastructures.eu:8081/nexus/content/repositories/geo-solutions/</url>
<url>http://maven.research-infrastructures.eu/nexus/content/repositories/geo-solutions-snapshots/</url>
</repository>
<repository>
<id>GeoToolkit</id>

View File

@ -1,14 +1,5 @@
package org.gcube.spatial.data.geonetwork;
import it.geosolutions.geonetwork.GNClient;
import it.geosolutions.geonetwork.exception.GNLibException;
import it.geosolutions.geonetwork.exception.GNServerException;
import it.geosolutions.geonetwork.util.GNInsertConfiguration;
import it.geosolutions.geonetwork.util.GNPriv;
import it.geosolutions.geonetwork.util.GNPrivConfiguration;
import it.geosolutions.geonetwork.util.GNSearchRequest;
import it.geosolutions.geonetwork.util.GNSearchResponse;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
@ -23,12 +14,12 @@ import java.util.Set;
import javax.xml.bind.JAXBException;
import lombok.extern.slf4j.Slf4j;
import org.gcube.spatial.data.geonetwork.configuration.Configuration;
import org.gcube.spatial.data.geonetwork.configuration.ConfigurationManager;
import org.gcube.spatial.data.geonetwork.configuration.ScopeConfigurationUtils;
import org.gcube.spatial.data.geonetwork.configuration.XMLAdapter;
import org.gcube.spatial.data.geonetwork.extension.GNClientExtension;
import org.gcube.spatial.data.geonetwork.extension.ServerAccess;
import org.gcube.spatial.data.geonetwork.model.Account;
import org.gcube.spatial.data.geonetwork.model.Group;
import org.gcube.spatial.data.geonetwork.model.ScopeConfiguration;
@ -48,6 +39,16 @@ import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import org.opengis.metadata.Metadata;
import it.geosolutions.geonetwork.GNClient;
import it.geosolutions.geonetwork.exception.GNLibException;
import it.geosolutions.geonetwork.exception.GNServerException;
import it.geosolutions.geonetwork.util.GNInsertConfiguration;
import it.geosolutions.geonetwork.util.GNPriv;
import it.geosolutions.geonetwork.util.GNPrivConfiguration;
import it.geosolutions.geonetwork.util.GNSearchRequest;
import it.geosolutions.geonetwork.util.GNSearchResponse;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class GeoNetwork implements GeoNetworkAdministration {
@ -83,7 +84,6 @@ public class GeoNetwork implements GeoNetworkAdministration {
@Override
public void login(LoginLevel lvl) throws AuthorizationException, MissingServiceEndpointException, MissingConfigurationException {
GNClient client=getClient();
String user=null;
String password=null;
switch(lvl){
@ -106,16 +106,41 @@ public class GeoNetwork implements GeoNetworkAdministration {
break;
}
}
client.login(user, password);
currentLoggedLevel=lvl;
setAccess(new ServerAccess(config.getGeoNetworkEndpoint(),config.getGeoNetworkVersion(),true,password,user,lvl));
getClient();
}
private ServerAccess getAccess(ScopeConfiguration scopeConfig,LoginLevel lvl) throws MissingServiceEndpointException{
String user=null;
String password=null;
switch(lvl){
case ADMIN :{ user=config.getAdminAccount().getUser();
password=config.getAdminAccount().getPassword();
break;
}
case CKAN : {
ScopeConfiguration scopeConfiguration=scopeConfig;
Account account=scopeConfiguration.getAccounts().get(Account.Type.CKAN);
user=account.getUser();
password=account.getPassword();
break;
}
default: {
ScopeConfiguration scopeConfiguration=scopeConfig;
Account account=scopeConfiguration.getAccounts().get(Account.Type.SCOPE);
user=account.getUser();
password=account.getPassword();
break;
}
}
return new ServerAccess(config.getGeoNetworkEndpoint(),config.getGeoNetworkVersion(),true,password,user,lvl);
}
@Override
public void logout() {
theClient=null;
currentLoggedLevel=null;
public void logout() throws MissingServiceEndpointException {
setAccess(new ServerAccess(config.getGeoNetworkEndpoint(),config.getGeoNetworkVersion()));
}
@ -170,24 +195,24 @@ public class GeoNetwork implements GeoNetworkAdministration {
}
private void setCurrentLoginPrivileges(long metadataId) throws MissingConfigurationException, MissingServiceEndpointException, GNLibException, GNServerException{
private void setPrivileges(long metadataId,ScopeConfiguration toUseConfig,LoginLevel toUseLevel) throws MissingConfigurationException, MissingServiceEndpointException, GNLibException, GNServerException{
GNPrivConfiguration cfg=null;
switch(currentLoggedLevel){
switch(toUseLevel){
case ADMIN : break;
case CKAN : break;
case DEFAULT : {
cfg=new GNPrivConfiguration();
cfg.addPrivileges(config.getScopeConfiguration().getDefaultGroup(), EnumSet.of(GNPriv.VIEW,GNPriv.FEATURED));
cfg.addPrivileges(toUseConfig.getDefaultGroup(), EnumSet.of(GNPriv.VIEW,GNPriv.FEATURED));
break;
}
case PRIVATE :{
cfg=new GNPrivConfiguration();
cfg.addPrivileges(config.getScopeConfiguration().getPrivateGroup(), EnumSet.of(GNPriv.VIEW,GNPriv.FEATURED));
cfg.addPrivileges(toUseConfig.getPrivateGroup(), EnumSet.of(GNPriv.VIEW,GNPriv.FEATURED));
break;
}case SCOPE : {
cfg=new GNPrivConfiguration();
cfg.addPrivileges(config.getScopeConfiguration().getPublicGroup(), EnumSet.of(GNPriv.VIEW,GNPriv.FEATURED));
cfg.addPrivileges(toUseConfig.getPublicGroup(), EnumSet.of(GNPriv.VIEW,GNPriv.FEATURED));
break;
}
}
@ -197,15 +222,17 @@ public class GeoNetwork implements GeoNetworkAdministration {
}
}
/* (non-Javadoc)
* @see org.gcube.spatial.data.geonetwork.GeoNetworkReader#insertMetadata(it.geosolutions.geonetwork.util.GNInsertConfiguration, java.io.File)
*/
@Override
public long insertMetadata(GNInsertConfiguration configuration,File metadataFile) throws GNLibException, GNServerException, MissingServiceEndpointException, MissingConfigurationException, InvalidInsertConfigurationException, AuthorizationException{
checkPublishingConfiguration(configuration);
checkPublishingConfiguration(configuration,config.getScopeConfiguration());
GNClient client=getClient();
long toReturn=client.insertMetadata(configuration, metadataFile);
setCurrentLoginPrivileges(toReturn);
setPrivileges(toReturn,config.getScopeConfiguration(),getCurrentLoginLevel());
return toReturn;
}
/* (non-Javadoc)
@ -223,7 +250,7 @@ public class GeoNetwork implements GeoNetworkAdministration {
public long insertMetadata(File requestFile) throws GNLibException, GNServerException, MissingServiceEndpointException, MissingConfigurationException{
GNClient client=getClient();
long toReturn= client.insertRequest(requestFile);
setCurrentLoginPrivileges(toReturn);
setPrivileges(toReturn,config.getScopeConfiguration(),getCurrentLoginLevel());
return toReturn;
}
/* (non-Javadoc)
@ -235,6 +262,96 @@ public class GeoNetwork implements GeoNetworkAdministration {
}
//**************** INSERT AND PROMOTE
@Override
public long insertAndPromoteMetadata(File requestFile)
throws GNLibException, GNServerException, MissingServiceEndpointException, MissingConfigurationException {
LoginLevel currentLevel=getCurrentLoginLevel();
// get parent configuration set access to GN
ScopeConfiguration parentConfig=getParentConfiguration();
ServerAccess parentAccess=getAccess(parentConfig, LoginLevel.DEFAULT);
setAccess(parentAccess);
GNClient client=getClient();
// actually publish as promoted access
long toReturn= client.insertRequest(requestFile);
setPrivileges(toReturn,parentConfig,LoginLevel.DEFAULT);
// restore logged level
try{
login(currentLevel);
}catch(AuthorizationException e){
throw new GNLibException("Unabel to restore level. This should not happen.",e);
}
return toReturn;
}
@Override
public long insertAndPromoteMetadata(GNInsertConfiguration configuration, File metadataFile)
throws GNLibException, GNServerException, MissingServiceEndpointException, MissingConfigurationException,
InvalidInsertConfigurationException, AuthorizationException {
LoginLevel currentLevel=getCurrentLoginLevel();
// get parent configuration set access to GN
ScopeConfiguration parentConfig=getParentConfiguration();
ServerAccess parentAccess=getAccess(parentConfig, LoginLevel.DEFAULT);
setAccess(parentAccess);
GNInsertConfiguration toUseConfig=null;
try{
toUseConfig=getUserConfiguration(configuration.getCategory(), configuration.getStyleSheet(),parentConfig,LoginLevel.DEFAULT);
}catch(GeoNetworkException e){
throw new GNLibException("Unabel to get publish configuration ",e);
}
checkPublishingConfiguration(toUseConfig,parentConfig);
GNClient client=getClient();
// actually publish
long toReturn=client.insertMetadata(toUseConfig, metadataFile);
setPrivileges(toReturn,parentConfig,LoginLevel.DEFAULT);
// restore logged level
try{
login(currentLevel);
}catch(AuthorizationException e){
throw new GNLibException("Unabel to restore level. This should not happen.",e);
}
return toReturn;
}
@Override
public long insertAndPromoteMetadata(GNInsertConfiguration configuration, Metadata meta)
throws GNLibException, GNServerException, IOException, JAXBException, MissingServiceEndpointException,
MissingConfigurationException, InvalidInsertConfigurationException, AuthorizationException {
return insertAndPromoteMetadata(configuration, meta2File(meta,registeredXMLAdapters));
}
@Override
public long insertAndPromoteMetadata(Metadata meta) throws GNLibException, GNServerException, IOException,
JAXBException, MissingServiceEndpointException, MissingConfigurationException {
return insertAndPromoteMetadata(meta2File(meta, registeredXMLAdapters));
}
private ScopeConfiguration getParentConfiguration() throws MissingConfigurationException, MissingServiceEndpointException{
ArrayList<String> parent=ScopeUtils.getParentScopes();
return ScopeConfigurationUtils.getByScope(config.getExistingConfigurations(),parent.get(parent.size()-1));
}
/* (non-Javadoc)
* @see org.gcube.spatial.data.geonetwork.GeoNetworkReader#updateMetadata(long, java.io.File)
*/
@ -243,6 +360,8 @@ public class GeoNetwork implements GeoNetworkAdministration {
GNClient client=getClient();
client.updateMetadata(id, metadataFile);
}
/* (non-Javadoc)
* @see org.gcube.spatial.data.geonetwork.GeoNetworkReader#updateMetadata(long, org.opengis.metadata.Metadata)
*/
@ -265,24 +384,27 @@ public class GeoNetwork implements GeoNetworkAdministration {
@Override
public GNInsertConfiguration getCurrentUserConfiguration(String category,String styleSheet) throws AuthorizationException, GeoNetworkException {
if(currentLoggedLevel==null) throw new AuthorizationException("Client is not authenticated, please use Login before publishing");
ScopeConfiguration scopeConfig=config.getScopeConfiguration();
if(getCurrentLoginLevel()==null) throw new AuthorizationException("Client is not authenticated, please use Login before publishing");
return getUserConfiguration(category, styleSheet, config.getScopeConfiguration(), getCurrentLoginLevel());
}
public GNInsertConfiguration getUserConfiguration(String category,String styleSheet, ScopeConfiguration configuration,LoginLevel lvl) throws AuthorizationException, GeoNetworkException {
Integer configuredGroup=null;
switch(currentLoggedLevel){
case CKAN : throw new AuthorizationException("Current logged level "+currentLoggedLevel+"is read-only");
switch(getCurrentLoginLevel()){
case CKAN : throw new AuthorizationException("Current logged level "+getCurrentLoginLevel()+"is read-only");
case ADMIN : throw new GeoNetworkException("Current logged level is Admin, unable to determine publihing configuration");
case DEFAULT : configuredGroup=scopeConfig.getDefaultGroup();
case DEFAULT : configuredGroup=configuration.getDefaultGroup();
break;
case PRIVATE : configuredGroup=scopeConfig.getPrivateGroup();
case PRIVATE : configuredGroup=configuration.getPrivateGroup();
break;
case SCOPE : configuredGroup=scopeConfig.getPublicGroup();
case SCOPE : configuredGroup=configuration.getPublicGroup();
break;
}
return new GNInsertConfiguration(configuredGroup+"", category, styleSheet, true);
}
//******************************* ADMIN ********************************* //
@Override
@ -299,13 +421,13 @@ public class GeoNetwork implements GeoNetworkAdministration {
@Override
public String getAvailableOwnershipTransfer(Integer userId)
throws GNServerException, MissingServiceEndpointException {
throws GNServerException, MissingServiceEndpointException, GNLibException {
return getClient().getPossibleOwnershipTransfer(userId);
}
@Override
public String getMetadataOwners() throws GNServerException,
MissingServiceEndpointException {
MissingServiceEndpointException, GNLibException {
return getClient().getMetadataOwners();
}
@ -332,17 +454,18 @@ public class GeoNetwork implements GeoNetworkAdministration {
}
@Override
public void assignOwnership(List<Long> toTransferIds,Integer targetUserId, Integer targetGroupId) throws AuthorizationException, GNServerException, MissingServiceEndpointException {
if(this.currentLoggedLevel==null||(!this.currentLoggedLevel.equals(LoginLevel.ADMIN))) throw new AuthorizationException("You need to login as Admin to massively transfer ownership");
public void assignOwnership(List<Long> toTransferIds,Integer targetUserId, Integer targetGroupId) throws AuthorizationException, GNServerException, MissingServiceEndpointException, GNLibException {
if(getCurrentLoginLevel()==null||(!getCurrentLoginLevel().equals(LoginLevel.ADMIN))) throw new AuthorizationException("You need to login as Admin to massively transfer ownership");
getClient().assignOwnership(toTransferIds, targetUserId, targetGroupId);
}
@Override
public void transferOwnership(Integer sourceUserId, Integer sourceGroupId,
Integer targetUserId, Integer targetGroupId)
throws GNServerException, MissingServiceEndpointException {
throws GNServerException, MissingServiceEndpointException, GNLibException {
getClient().transferOwnership(sourceUserId, sourceGroupId, targetUserId, targetGroupId);
}
private ScopeConfiguration createCurrentScopeConfiguration() throws GNLibException, GNServerException, MissingServiceEndpointException {
try{
String currentScopeName=ScopeUtils.getCurrentScopeName();
@ -461,36 +584,50 @@ public class GeoNetwork implements GeoNetworkAdministration {
private GNClientExtension theClient=null;
private ServerAccess currentAccess=null;
private void setAccess(ServerAccess access){
this.currentAccess=access;
theClient=null;
}
private ServerAccess getCurrentAccess() throws MissingServiceEndpointException{
if(currentAccess==null) currentAccess=new ServerAccess(config.getGeoNetworkEndpoint(),config.getGeoNetworkVersion());
return currentAccess;
}
private LoginLevel getCurrentLoginLevel() throws MissingServiceEndpointException{
return getCurrentAccess().getLoggedLevel();
}
private synchronized GNClientExtension getClient() throws MissingServiceEndpointException{
if(theClient==null)
theClient = new GNClientExtension(config.getGeoNetworkEndpoint());
if(theClient==null)
theClient = new GNClientExtension(getCurrentAccess());
return theClient;
}
private LoginLevel currentLoggedLevel=null;
private void checkPublishingConfiguration(GNInsertConfiguration configuration) throws AuthorizationException, InvalidInsertConfigurationException, MissingConfigurationException, MissingServiceEndpointException{
if(currentLoggedLevel==null) throw new AuthorizationException("Client is not authenticated, please use Login before publishing");
private void checkPublishingConfiguration(GNInsertConfiguration configuration,ScopeConfiguration toUseConfig) throws AuthorizationException, InvalidInsertConfigurationException, MissingConfigurationException, MissingServiceEndpointException{
if(getCurrentLoginLevel()==null) throw new AuthorizationException("Client is not authenticated, please use Login before publishing");
if(!configuration.getValidate()) throw new InvalidInsertConfigurationException("Validate option is mandatory");
// CHECK GROUP
Integer targetGroup=Integer.parseInt(configuration.getGroup());
Integer configuredGroup=null;
ScopeConfiguration scopeConfig=config.getScopeConfiguration();
switch(currentLoggedLevel){
case CKAN : throw new AuthorizationException("Current logged level "+currentLoggedLevel+"is read-only");
switch(getCurrentLoginLevel()){
case CKAN : throw new AuthorizationException("Current logged level "+getCurrentLoginLevel()+"is read-only");
case ADMIN : break;
case DEFAULT : configuredGroup=scopeConfig.getDefaultGroup();
case DEFAULT : configuredGroup=toUseConfig.getDefaultGroup();
break;
case PRIVATE : configuredGroup=scopeConfig.getPrivateGroup();
case PRIVATE : configuredGroup=toUseConfig.getPrivateGroup();
break;
case SCOPE : configuredGroup=scopeConfig.getPublicGroup();
case SCOPE : configuredGroup=toUseConfig.getPublicGroup();
break;
}
if (configuredGroup!=null&&(!targetGroup.equals(configuredGroup)))
throw new InvalidInsertConfigurationException(String.format("Invalid logged level %s and specified group %d, expected %d", currentLoggedLevel,targetGroup,configuredGroup));
throw new InvalidInsertConfigurationException(String.format("Invalid logged level %s and specified group %d, expected %d", getCurrentLoginLevel(),targetGroup,configuredGroup));
}

View File

@ -21,9 +21,9 @@ public interface GeoNetworkAdministration extends GeoNetworkPublisher {
public void createUsers(String username, String password, Profile profile,
Collection<Integer> groups) throws GNLibException,
GNServerException, MissingServiceEndpointException;
public void assignOwnership(List<Long> toTransferIds,Integer targetUserId, Integer targetGroupId) throws AuthorizationException, GNServerException, MissingServiceEndpointException;
public void assignOwnership(List<Long> toTransferIds,Integer targetUserId, Integer targetGroupId) throws AuthorizationException, GNServerException, MissingServiceEndpointException, GNLibException;
public String getAvailableOwnershipTransfer(Integer userId)throws GNServerException, MissingServiceEndpointException;
public String getMetadataOwners()throws GNServerException, MissingServiceEndpointException;
public void transferOwnership(Integer sourceUserId,Integer sourceGroupId,Integer targetUserId,Integer targetGroupId) throws GNServerException, MissingServiceEndpointException;
public String getAvailableOwnershipTransfer(Integer userId)throws GNServerException, MissingServiceEndpointException, GNLibException;
public String getMetadataOwners()throws GNServerException, MissingServiceEndpointException, GNLibException;
public void transferOwnership(Integer sourceUserId,Integer sourceGroupId,Integer targetUserId,Integer targetGroupId) throws GNServerException, MissingServiceEndpointException, GNLibException;
}

View File

@ -23,19 +23,21 @@ public interface GeoNetworkPublisher extends GeoNetworkReader {
public void setPrivileges(long metadataId, GNPrivConfiguration cfg)
throws GNLibException, GNServerException,MissingServiceEndpointException;
public long insertMetadata(GNInsertConfiguration configuration,
File metadataFile) throws GNLibException, GNServerException,MissingServiceEndpointException, MissingConfigurationException, InvalidInsertConfigurationException, AuthorizationException;
public long insertMetadata(GNInsertConfiguration configuration,File metadataFile) throws GNLibException, GNServerException,MissingServiceEndpointException, MissingConfigurationException, InvalidInsertConfigurationException, AuthorizationException;
public long insertMetadata(GNInsertConfiguration configuration,
Metadata meta) throws GNLibException, GNServerException,
IOException, JAXBException,MissingServiceEndpointException, MissingConfigurationException, InvalidInsertConfigurationException, AuthorizationException;
public long insertMetadata(GNInsertConfiguration configuration,Metadata meta) throws GNLibException, GNServerException,IOException, JAXBException,MissingServiceEndpointException, MissingConfigurationException, InvalidInsertConfigurationException, AuthorizationException;
public long insertMetadata(File requestFile) throws GNLibException,
GNServerException,MissingServiceEndpointException, MissingConfigurationException;
public long insertMetadata(File requestFile) throws GNLibException, GNServerException,MissingServiceEndpointException, MissingConfigurationException;
public long insertMetadata(Metadata meta) throws GNLibException,
GNServerException, IOException,
JAXBException,MissingServiceEndpointException, MissingConfigurationException;
public long insertMetadata(Metadata meta) throws GNLibException,GNServerException, IOException, JAXBException,MissingServiceEndpointException, MissingConfigurationException;
public long insertAndPromoteMetadata(GNInsertConfiguration configuration,File metadataFile) throws GNLibException, GNServerException,MissingServiceEndpointException, MissingConfigurationException, InvalidInsertConfigurationException, AuthorizationException;
public long insertAndPromoteMetadata(GNInsertConfiguration configuration,Metadata meta) throws GNLibException, GNServerException,IOException, JAXBException,MissingServiceEndpointException, MissingConfigurationException, InvalidInsertConfigurationException, AuthorizationException;
public long insertAndPromoteMetadata(File requestFile) throws GNLibException, GNServerException,MissingServiceEndpointException, MissingConfigurationException;
public long insertAndPromoteMetadata(Metadata meta) throws GNLibException,GNServerException, IOException, JAXBException,MissingServiceEndpointException, MissingConfigurationException;
public void updateMetadata(long id, File metadataFile)

View File

@ -36,5 +36,5 @@ public interface GeoNetworkReader {
public void login(LoginLevel level)throws AuthorizationException,MissingServiceEndpointException, MissingConfigurationException;
public void logout();
public void logout() throws MissingServiceEndpointException;
}

View File

@ -2,6 +2,7 @@ package org.gcube.spatial.data.geonetwork.configuration;
import java.util.Set;
import org.gcube.spatial.data.geonetwork.extension.ServerAccess.Version;
import org.gcube.spatial.data.geonetwork.model.Account;
import org.gcube.spatial.data.geonetwork.model.ScopeConfiguration;
import org.gcube.spatial.data.geonetwork.model.faults.EncryptionException;
@ -12,6 +13,8 @@ public interface Configuration {
public String getGeoNetworkEndpoint()throws MissingServiceEndpointException;
public Version getGeoNetworkVersion()throws MissingServiceEndpointException;
/**
*
* @return current scope configuration

View File

@ -18,6 +18,7 @@ import org.gcube.informationsystem.publisher.RegistryPublisher;
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.spatial.data.geonetwork.extension.ServerAccess.Version;
import org.gcube.spatial.data.geonetwork.model.Account;
import org.gcube.spatial.data.geonetwork.model.Account.Type;
import org.gcube.spatial.data.geonetwork.model.ScopeConfiguration;
@ -98,6 +99,14 @@ public class DefaultConfiguration implements Configuration {
//**************************** INTERFACE IMPLEMENTATION
@Override
public Version getGeoNetworkVersion() throws MissingServiceEndpointException {
short version=getISServiceEndpoint().profile().platform().version();
if(version<3) return Version.DUE;
else return Version.TRE;
}
@Override
public Account getAdminAccount() throws MissingServiceEndpointException {
loadFromIs();
@ -141,7 +150,7 @@ public class DefaultConfiguration implements Configuration {
@Override
public Set<ScopeConfiguration> getParentScopesConfiguration() throws MissingServiceEndpointException{
Set<String> parentScopes=ScopeUtils.getParentScopes();
List<String> parentScopes=ScopeUtils.getParentScopes();
HashSet<ScopeConfiguration> toReturn=new HashSet<>();
if(!parentScopes.isEmpty()) {// in order to avoid loading from IS
@ -161,6 +170,7 @@ public class DefaultConfiguration implements Configuration {
private boolean loaded=false;
/**
* loads configuration from Is
* @throws MissingServiceEndpointException
@ -188,16 +198,6 @@ public class DefaultConfiguration implements Configuration {
}
}
/**
* Parse endpoint to load all configurations
*
* @param toUseEndpoint
* @return
*/
// protected Set<ScopeConfiguration> loadExisting(ServiceEndpoint toUseEndpoint) throws MissingServiceEndpointException{
// AccessPoint point=getTheRightAccessPoint(toUseEndpoint);
// return ScopeConfigurationUtils.fromMap(point.propertyMap(), props);
// }
protected AccessPoint getIsAccessPoint() throws MissingServiceEndpointException{
log.debug("Querying IS for Geonetwork information..");

View File

@ -63,7 +63,7 @@ public class ScopeConfigurationUtils {
return new ScopeConfiguration(assignedScope, publicGroup, privateGroup, accounts, defaultGroup);
}
static ScopeConfiguration getByScope(Set<ScopeConfiguration> existing, String scope) throws MissingConfigurationException{
public static ScopeConfiguration getByScope(Set<ScopeConfiguration> existing, String scope) throws MissingConfigurationException{
for(ScopeConfiguration configuration : existing)
if(configuration.getAssignedScope().equals(scope)) return configuration;
throw new MissingConfigurationException("Scope "+scope+" has no configuration");

View File

@ -1,9 +1,6 @@
package org.gcube.spatial.data.geonetwork.extension;
import it.geosolutions.geonetwork.GNClient;
import it.geosolutions.geonetwork.exception.GNLibException;
import it.geosolutions.geonetwork.exception.GNServerException;
import java.io.File;
import java.util.Collection;
import java.util.List;
import java.util.Set;
@ -13,64 +10,162 @@ import org.gcube.spatial.data.geonetwork.model.User;
import org.gcube.spatial.data.geonetwork.model.User.Profile;
import org.gcube.spatial.data.geonetwork.utils.GroupUtils;
import org.gcube.spatial.data.geonetwork.utils.UserUtils;
import org.jdom.Element;
public class GNClientExtension extends GNClient {
import it.geosolutions.geonetwork.GN26Client;
import it.geosolutions.geonetwork.GN3Client;
import it.geosolutions.geonetwork.GNClient;
import it.geosolutions.geonetwork.exception.GNLibException;
import it.geosolutions.geonetwork.exception.GNServerException;
import it.geosolutions.geonetwork.op.gn3.GN3MetadataGetInfo.MetadataInfo;
import it.geosolutions.geonetwork.util.GNInsertConfiguration;
import it.geosolutions.geonetwork.util.GNPrivConfiguration;
import it.geosolutions.geonetwork.util.GNSearchRequest;
import it.geosolutions.geonetwork.util.GNSearchResponse;
import it.geosolutions.geonetwork.util.HTTPUtils;
private String gnServiceURL;
public class GNClientExtension implements GNClient {
public GNClientExtension(String serviceURL) {
super(serviceURL);
this.gnServiceURL=serviceURL;
private GNClient client;
private ServerAccess access;
public GNClientExtension(ServerAccess access) {
this.access=access;
switch(access.getVersion()){
case DUE : {
client=access.isLogin()?new GN26Client(access.getGnServiceURL(), access.getUser(), access.getPassword()):new GN26Client(access.getGnServiceURL());
break;
}
default : {
client=access.isLogin()?new GN3Client(access.getGnServiceURL(), access.getUser(), access.getPassword()):new GN3Client(access.getGnServiceURL());
break;
}
}
}
public void createGroup(String name, String description, String mail)throws GNLibException, GNServerException {
GNMetadataAdminExtension.createGroup(getConnection(), gnServiceURL, name, description, mail);
GNMetadataAdminExtension.createGroup(getConnection(), access.getGnServiceURL(), name, description, mail);
}
public Set<Group> getGroups() throws GNLibException, GNServerException{
return GroupUtils.parseGroupXMLResponse(GNMetadataAdminExtension.getGroups(getConnection(), gnServiceURL));
return GroupUtils.parseGroupXMLResponse(GNMetadataAdminExtension.getGroups(getConnection(), access.getGnServiceURL()));
}
public Set<User> getUsers() throws GNLibException, GNServerException{
return UserUtils.parseUserXMLResponse(GNMetadataAdminExtension.getUsers(getConnection(), gnServiceURL));
return UserUtils.parseUserXMLResponse(GNMetadataAdminExtension.getUsers(getConnection(), access.getGnServiceURL()));
}
public void createUser(String name, String password, Profile profile, Collection<Integer> groups) throws GNServerException, GNLibException{
GNMetadataAdminExtension.createUser(getConnection(), gnServiceURL, name, password, profile, groups);
GNMetadataAdminExtension.createUser(getConnection(), access.getGnServiceURL(), name, password, profile, groups);
}
public void editUser(User toAdd, Collection<Integer> groups) throws GNServerException,GNLibException{
Set<Integer> alreadyAddedGroups=getGroupsByUser(toAdd.getId());
alreadyAddedGroups.addAll(groups);
GNMetadataAdminExtension.editUser(getConnection(), gnServiceURL, toAdd, alreadyAddedGroups);
GNMetadataAdminExtension.editUser(getConnection(), access.getGnServiceURL(), toAdd, alreadyAddedGroups);
}
public Set<Integer> getGroupsByUser(Integer userId) throws GNLibException, GNServerException{
return UserUtils.parseGroupsByUserResponse(GNMetadataAdminExtension.getUserGroupd(getConnection(), gnServiceURL, userId));
return UserUtils.parseGroupsByUserResponse(GNMetadataAdminExtension.getUserGroupd(getConnection(), access.getGnServiceURL(), userId));
}
public void assignOwnership(List<Long> toTransferIds,Integer targetUserId,Integer targetGroupId) throws GNServerException{
public void assignOwnership(List<Long> toTransferIds,Integer targetUserId,Integer targetGroupId) throws GNServerException, GNLibException{
try{
GNMetadataAdminExtension.selectMeta(getConnection(), gnServiceURL, toTransferIds);
GNMetadataAdminExtension.assignMassiveOwnership(getConnection(), gnServiceURL, targetUserId, targetGroupId);
GNMetadataAdminExtension.selectMeta(getConnection(), access.getGnServiceURL(), toTransferIds);
GNMetadataAdminExtension.assignMassiveOwnership(getConnection(), access.getGnServiceURL(), targetUserId, targetGroupId);
}finally{
GNMetadataAdminExtension.clearMetaSelection(getConnection(), gnServiceURL);
GNMetadataAdminExtension.clearMetaSelection(getConnection(), access.getGnServiceURL());
}
}
public String getPossibleOwnershipTransfer(Integer userId) throws GNServerException{
return GNMetadataAdminExtension.allowedOwnershipTransfer(getConnection(), gnServiceURL, userId);
public String getPossibleOwnershipTransfer(Integer userId) throws GNServerException, GNLibException{
return GNMetadataAdminExtension.allowedOwnershipTransfer(getConnection(), access.getGnServiceURL(), userId);
}
public String getMetadataOwners() throws GNServerException{
return GNMetadataAdminExtension.metadataOwners(getConnection(), gnServiceURL);
public String getMetadataOwners() throws GNServerException, GNLibException{
return GNMetadataAdminExtension.metadataOwners(getConnection(), access.getGnServiceURL());
}
public void transferOwnership(Integer sourceUserId,Integer sourceGroupId,Integer targetUserId,Integer targetGroupId) throws GNServerException{
GNMetadataAdminExtension.transferOwnership(getConnection(), gnServiceURL, sourceUserId, sourceGroupId, targetUserId, targetGroupId);
public void transferOwnership(Integer sourceUserId,Integer sourceGroupId,Integer targetUserId,Integer targetGroupId) throws GNServerException, GNLibException{
GNMetadataAdminExtension.transferOwnership(getConnection(), access.getGnServiceURL(), sourceUserId, sourceGroupId, targetUserId, targetGroupId);
}
//***************************** OVERRIDES
@Override
public boolean ping() {
return client.ping();
}
@Override
public long insertMetadata(GNInsertConfiguration cfg, File metadataFile) throws GNLibException, GNServerException {
return client.insertMetadata(cfg, metadataFile);
}
@Override
public long insertRequest(File requestFile) throws GNLibException, GNServerException {
return client.insertRequest(requestFile);
}
@Override
public void setPrivileges(long metadataId, GNPrivConfiguration cfg) throws GNLibException, GNServerException {
client.setPrivileges(metadataId, cfg);
}
@Override
public GNSearchResponse search(GNSearchRequest searchRequest) throws GNLibException, GNServerException {
return client.search(searchRequest);
}
@Override
public GNSearchResponse search(File fileRequest) throws GNLibException, GNServerException {
return client.search(fileRequest);
}
@Override
public Element get(Long id) throws GNLibException, GNServerException {
return client.get(id);
}
@Override
public Element get(String uuid) throws GNLibException, GNServerException {
return client.get(uuid);
}
@Override
public void deleteMetadata(long id) throws GNLibException, GNServerException {
client.deleteMetadata(id);
}
@Override
public void updateMetadata(long id, File metadataFile) throws GNLibException, GNServerException {
client.updateMetadata(id, metadataFile);
}
@Override
public void updateMetadata(long id, File metadataFile, String encoding) throws GNLibException, GNServerException {
client.updateMetadata(id, metadataFile,encoding);
}
@Override
public MetadataInfo getInfo(Long id) throws GNLibException, GNServerException {
return client.getInfo(id);
}
@Override
public MetadataInfo getInfo(String uuid) throws GNLibException, GNServerException {
return client.getInfo(uuid);
}
@Override
public HTTPUtils getConnection() throws GNLibException {
return client.getConnection();
}
}

View File

@ -0,0 +1,30 @@
package org.gcube.spatial.data.geonetwork.extension;
import org.gcube.spatial.data.geonetwork.LoginLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class ServerAccess{
public static enum Version{
TRE,DUE
}
private String gnServiceURL;
private Version version;
private boolean login=false;
private String password;
private String user;
private LoginLevel loggedLevel=null;
public ServerAccess(String gnServiceURL, Version version) {
super();
this.gnServiceURL = gnServiceURL;
this.version = version;
}
}

View File

@ -0,0 +1,84 @@
package org.gcube.spatial.data.geonetwork.iso;
public class BoundingBox {
public static final BoundingBox WORLD_EXTENT=new BoundingBox(90, -90, 180, -180);
private double N=90;
private double S=-90;
private double W=180;
private double E=-180;
public BoundingBox(double n, double s, double w, double e) {
super();
N = n;
S = s;
W = w;
E = e;
}
/**
* Assumed order is E, S, W, N
*
* @param bbox
*/
public BoundingBox(double[] bbox) {
// TODO Auto-generated constructor stub
}
public double getN() {
return N;
}
public void setN(double n) {
N = n;
}
public double getS() {
return S;
}
public void setS(double s) {
S = s;
}
public double getW() {
return W;
}
public void setW(double w) {
W = w;
}
public double getE() {
return E;
}
public void setE(double e) {
E = e;
}
/**
*
* @return E, S, W, N
*/
public double[] toArray(){
return new double[]{
E,S,W,N
};
}
/**
*
* @return E, S, W, N
*/
@Override
public String toString() {
return E+","+S+","+W+","+N;
}
}

View File

@ -5,11 +5,17 @@ import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import org.gcube.portlets.user.uriresolvermanager.UriResolverManager;
import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentException;
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
import org.gcube.spatial.data.geonetwork.utils.ScopeUtils;
import org.geotoolkit.metadata.iso.DefaultMetadata;
import org.geotoolkit.metadata.iso.citation.DefaultAddress;
import org.geotoolkit.metadata.iso.citation.DefaultCitation;
@ -59,6 +65,7 @@ public class ISOMetadataFactory {
distributorAddress.getElectronicMailAddresses().add(params.getConfig().getDistributorEMail());
distributorContact.setAddress(distributorAddress);
DefaultOnlineResource distributorOnline=new DefaultOnlineResource (new URI(params.getConfig().getDistributorSite()));
distributorOnline.setName(params.getConfig().getProjectName()+" site.");
distributorOnline.setProtocol(params.getConfig().getHttpProtocolDeclaration());
distributorContact.setOnlineResource(distributorOnline);
distributor.setContactInfo(distributorContact);
@ -72,6 +79,7 @@ public class ISOMetadataFactory {
providerAddress.getElectronicMailAddresses().add(params.getConfig().getProviderEMail());
providerContact.setAddress(providerAddress);
DefaultOnlineResource providerOnline=new DefaultOnlineResource (new URI(params.getConfig().getProviderSite()));
providerOnline.setName(params.getConfig().getProjectName()+" site.");
providerOnline.setProtocol(params.getConfig().getHttpProtocolDeclaration());
providerContact.setOnlineResource(providerOnline);
provider.setContactInfo(providerContact);
@ -115,7 +123,7 @@ public class ISOMetadataFactory {
thesaurusParty.setOrganisationName(new DefaultInternationalString(entry.getKey().getCitationOrganization()));
thesaurusParty.setRole(Role.POINT_OF_CONTACT);
DefaultContact thesaurusContact=new DefaultContact();
thesaurusContact.setOnlineResource(new DefaultOnlineResource(new URI(entry.getKey().getCitationUri())));
thesaurusContact.setOnlineResource(getOnline(entry.getKey().getTitle(),entry.getKey().getCitationUri()));
thesaurusParty.setContactInfo(thesaurusContact);
thesaurus.getCitedResponsibleParties().add(thesaurusParty);
}
@ -163,56 +171,7 @@ public class ISOMetadataFactory {
constraints.getAccessConstraints().add(Restriction.LICENSE);
constraints.getUseConstraints().add(Restriction.LICENSE);
//***************** Not general Approach
// DefaultDataQuality processQuality=new DefaultDataQuality();
// DefaultLineage processLineage=new DefaultLineage();
//
//
// DefaultSource source=new DefaultSource();
// DefaultNominalResolution sourceResolution=new DefaultNominalResolution();
// sourceResolution.setGroundResolution(0.5d);
// sourceResolution.setScanningResolution(0.5d);
// source.getSourceExtents().add(DefaultExtent.WORLD);
// //FIXME Breaks Validation
//// source.setResolution(sourceResolution);
//
//
//
//
// DefaultCitation sourceCitation=new DefaultCitation();
// sourceCitation.setTitle(new DefaultInternationalString(params.getSourceTitle()));
// sourceCitation.getDates().add(new DefaultCitationDate(params.getSourceGenerationDate(), DateType.CREATION));
// sourceCitation.getIdentifiers().add(new DefaultIdentifier(params.getSourceTableName()));
// source.setSourceCitation(sourceCitation);
//
// DefaultProcessStep processStep=new DefaultProcessStep();
// processStep.setDescription(new DefaultInternationalString("AquaMaps Ecological Niche Modelling"));
//// DefaultProcessing processing=new DefaultProcessing();
//// DefaultAlgorithm algorithm=new DefaultAlgorithm();
//// algorithm.setDescription(new DefaultInternationalString(AquaMapsObjectMetadataParameter.algorithmDescription));
//// StringBuilder customList=new StringBuilder();
//// for(SpeciesCustomization custom:params.getCustomizations())
//// customList.append(custom.toXML());
//// processing.setRunTimeParameters(new DefaultInternationalString(customList.toString()));
//// processing.getAlgorithms().add(algorithm);
//
// // FIXME Brakes Validation
//// processStep.setProcessingInformation(processing);
//
// processLineage.setStatement(new DefaultInternationalString(AquaMapsObjectMetadataParameter.algorithmDescription));
//
//
//
//
// processLineage.getProcessSteps().add(processStep);
// processLineage.getSources().add(source);
// processQuality.setLineage(processLineage);
// processQuality.setScope(new DefaultScope(ScopeCode.DATASET));
//*************** The Meta Object
@ -237,18 +196,21 @@ public class ISOMetadataFactory {
distribution.getTransferOptions().add(getTransferOptionsByLayer(layerName, geoserverUrl, style, bbox, config));
DefaultFormat format1 = new DefaultFormat();
format1.setName(new DefaultInternationalString("WMS"));
format1.setVersion(new DefaultInternationalString("1.1.0"));
format1.setName(new DefaultInternationalString(Protocol.WMS.getName()));
format1.setVersion(new DefaultInternationalString(Protocol.WMS.getVersion()));
DefaultFormat format2 = new DefaultFormat();
format2.setName(new DefaultInternationalString("WFS"));
format2.setVersion(new DefaultInternationalString("1.1.0"));
format2.setName(new DefaultInternationalString(Protocol.WFS.getName()));
format2.setVersion(new DefaultInternationalString(Protocol.WFS.getVersion()));
DefaultFormat format3 = new DefaultFormat();
format3.setName(new DefaultInternationalString("WCS"));
format3.setVersion(new DefaultInternationalString("1.0.0"));
format3.setName(new DefaultInternationalString(Protocol.WCS.getName()));
format3.setVersion(new DefaultInternationalString(Protocol.WCS.getVersion()));
DefaultFormat format4 = new DefaultFormat();
format4.setName(new DefaultInternationalString(Protocol.HTTP.getName()));
format4.setVersion(new DefaultInternationalString(Protocol.HTTP.getVersion()));
distribution.setDistributionFormats(new ArrayList<DefaultFormat>(Arrays.asList(format1, format2, format3)));
distribution.setDistributionFormats(new ArrayList<DefaultFormat>(Arrays.asList(format1, format2,format3, format4)));
return distribution;
}
@ -256,50 +218,61 @@ public class ISOMetadataFactory {
public static DefaultDigitalTransferOptions getTransferOptionsByLayer(String layerName, String geoserverUrl, String style, String bbox, EnvironmentConfiguration config ) throws URISyntaxException{
DefaultDigitalTransferOptions transferOptions=new DefaultDigitalTransferOptions();
transferOptions.getOnLines().add(getOnline(layerName,config.getWmsProtocolDeclaration(),getWmsUrl(geoserverUrl, layerName, style, bbox, config.getDefaultCRS())));
transferOptions.getOnLines().add(getOnline(layerName,config.getWfsProtocolDeclaration(),getWfsUrl(geoserverUrl,layerName)));
transferOptions.getOnLines().add(getOnline(layerName,config.getWcsProtocolDeclaration(),getWcsUrl(geoserverUrl,layerName,bbox)));
transferOptions.getOnLines().add(getOnline(Protocol.WMS.getName()+" link to layer.",config.getWmsProtocolDeclaration(),getWmsUrl(geoserverUrl, layerName, style, bbox, config.getDefaultCRS())));
transferOptions.getOnLines().add(getOnline(Protocol.WFS.getName()+" link to layer.",config.getWfsProtocolDeclaration(),getWfsUrl(geoserverUrl,layerName)));
transferOptions.getOnLines().add(getOnline(Protocol.WCS.getName()+" link to layer.",config.getWcsProtocolDeclaration(),getWcsUrl(geoserverUrl,layerName,bbox)));
return transferOptions;
}
public static DefaultOnlineResource getOnline(String name, String protocol, String uriString) throws URISyntaxException{
public static DefaultOnlineResource getOnline(String name,String uriString) throws URISyntaxException{
return getOnline(name,Protocol.getByURI(uriString).getDeclaration(),Protocol.getByURI(uriString).getName()+" link to resource.",uriString);
}
public static DefaultOnlineResource getOnline(String name,String protocolDeclaration,String uriString) throws URISyntaxException{
return getOnline(name,protocolDeclaration,Protocol.getByURI(uriString).getName()+" link to resource.",uriString);
}
public static DefaultOnlineResource getOnline(String name,String protocol, String description, String uriString) throws URISyntaxException{
URI uri=new URI(uriString);
DefaultOnlineResource resource=new DefaultOnlineResource(uri);
resource.setName(name);
resource.setProtocol(protocol);
resource.setDescription(new DefaultInternationalString(description));
return resource;
}
private static String getWmsUrl(String geoServerUrl, String layerName,String style, String bbox,String CRS) {
return geoServerUrl +
"/wms?service=wms&version=1.1.0"
+ "&request=GetMap&layers=" + layerName
+ "&styles=" + (style == null ? "" : style)
+ "&bbox=" + bbox + "&width=676&height=330" +
"&srs=EPSG:4326&crs="+CRS+"&format=application/openlayers";
public static String getWmsUrl(String geoServerUrl, String layerName,String style, String bbox,String CRS) {
if(bbox==null) bbox=BoundingBox.WORLD_EXTENT.toString();
return geoServerUrl +
"/wms?service=wms&version=1.1.0"
+ "&request=GetMap&layers=" + layerName
+ "&styles=" + (style == null ? "" : style)
+ "&bbox=" + bbox + "&width=676&height=330" +
"&srs=EPSG:4326&crs="+CRS+"&format=application/openlayers";
}
private static String getWfsUrl(String geoServerUrl, String layerName) {
public static String getWfsUrl(String geoServerUrl, String layerName) {
return geoServerUrl +
"/ows?service=wfs&version=1.0.0"
+ "&request=GetFeature&typeName=" + layerName
+"&format=json";
}
private static String getWcsUrl(String geoServerUrl, String layerName,String bbox) {
public static String getWcsUrl(String geoServerUrl, String layerName,String bbox) {
if(bbox==null) bbox=BoundingBox.WORLD_EXTENT.toString();
return geoServerUrl + "/wcs?service=wcs&version=1.0.0" + "&request=GetCoverage&coverage=" +
layerName + "&CRS=EPSG:4326" + "&bbox=" + bbox + "&width=676&height=330&format=geotiff";
}
// private static final String WMS_PROTOCOL="OGC:WMS-1.3.0-http-get-map";
// private static final String WFS_PROTOCOL="OGC:WFS-1.0.0-http-get-feature";
// private static final String HTTP_PROTOCOL="WWW:LINK-1.0-http--link";
//
// public static final String getProtocol(String uri){
// uri=uri.toLowerCase();
// if(uri.contains(("service=wms"))) return WMS_PROTOCOL;
// else if(uri.contains("service=wfs")) return WFS_PROTOCOL;
// else return HTTP_PROTOCOL;
// }
public static String getGisLinkByUUID(String uuid) throws UriResolverMapException, IllegalArgumentException{
Map<String,String> params=new HashMap<String,String>();
params.put("scope", ScopeUtils.getCurrentScope());
params.put("gis-UUID", uuid);
UriResolverManager resolver = new UriResolverManager("GIS");
return resolver.getLink(params, true);
}
}

View File

@ -0,0 +1,37 @@
package org.gcube.spatial.data.geonetwork.iso;
public enum Protocol {
HTTP("HTTP","WWW:LINK-1.0-http--link","1.0.0"),
WFS("WFS","OGC:WFS-1.0.0-http-get-feature","1.0.0"),
WCS("WCS","OGC:WCS-1.0.0-http-get-coverage","1.0.0"),
WMS("WMS","OGC:WMS-1.3.0-http-get-map","1.3.0");
private String name;
private String declaration;
private String version;
private Protocol(String name,String declaration,String version){
this.name=name;
this.declaration=declaration;
this.version=version;
}
public String getDeclaration() {
return declaration;
}
public String getName() {
return name;
}
public String getVersion() {
return version;
}
public static final Protocol getByURI(String uri){
uri=uri.toLowerCase();
if(uri.contains(("service=wms"))) return Protocol.WMS;
else if(uri.contains("service=wfs")) return Protocol.WFS;
else if(uri.contains("service=wcs")) return Protocol.WCS;
else return Protocol.HTTP;
}
}

View File

@ -2,8 +2,8 @@ package org.gcube.spatial.data.geonetwork.utils;
import static org.gcube.common.authorization.client.Constants.authorizationService;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
@ -51,10 +51,10 @@ public class ScopeUtils {
return current.substring(current.lastIndexOf('/')+1);
}
public static Set<String> getParentScopes(){
public static ArrayList<String> getParentScopes(){
String currentScope=getCurrentScope();
String[] splitted=currentScope.substring(1).split("/");
HashSet<String> toReturn=new HashSet<String>();
ArrayList<String> toReturn=new ArrayList<String>();
for(int i=0;i<splitted.length-1;i++){
toReturn.add(splitted[i]);
}

View File

@ -6,6 +6,7 @@ import java.util.Set;
import org.gcube.spatial.data.geonetwork.LoginLevel;
import org.gcube.spatial.data.geonetwork.configuration.Configuration;
import org.gcube.spatial.data.geonetwork.extension.ServerAccess.Version;
import org.gcube.spatial.data.geonetwork.model.Account;
import org.gcube.spatial.data.geonetwork.model.ScopeConfiguration;
import org.gcube.spatial.data.geonetwork.model.faults.MissingConfigurationException;
@ -62,6 +63,10 @@ public class MyConfiguration implements Configuration {
// TODO Auto-generated method stub
}
@Override
public Version getGeoNetworkVersion() throws MissingServiceEndpointException {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -1,8 +1,5 @@
package org.gcube.spatial.data.geonetwork.test;
import it.geosolutions.geonetwork.GNClient;
import it.geosolutions.geonetwork.util.GNInsertConfiguration;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
@ -64,6 +61,10 @@ import org.opengis.metadata.spatial.SpatialRepresentationType;
import org.opengis.metadata.spatial.TopologyLevel;
import org.opengis.util.InternationalString;
import it.geosolutions.geonetwork.GN26Client;
import it.geosolutions.geonetwork.GNClient;
import it.geosolutions.geonetwork.util.GNInsertConfiguration;
public class NetCDFMetadata {
private String geonetworkUrl = "http://geoserver-dev.d4science-ii.research-infrastructures.eu/geonetwork/";
@ -420,8 +421,7 @@ public class NetCDFMetadata {
meta.getDataQualityInfo().add(processQuality);
meta.setLanguage(Locale.ENGLISH);
GNClient client = new GNClient(geonetworkUrl);
client.login(geonetworkUser, geonetworkPwd);
GNClient client = new GN26Client(geonetworkUrl,geonetworkUser,geonetworkPwd);
File tmetafile = meta2File(meta);
client.insertMetadata(new GNInsertConfiguration("3", "datasets", "_none_", true), tmetafile);
tmetafile.delete();

View File

@ -19,10 +19,11 @@ public class ScopeTests {
String[] scopes=new String[]{
// "/gcube",
// "/gcube/devsec",
"/gcube/devsec/devVRE"
// "/gcube/devsec/devVRE",
// "/gcube/devNext/NextNext"
// "/d4science.research-infrastructures.eu"
// "/d4science.research-infrastructures.eu"
"/d4science.research-infrastructures.eu/gCubeApps/EcologicalModelling",
"/d4science.research-infrastructures.eu/gCubeApps"
};

View File

@ -5,6 +5,9 @@ import java.util.Properties;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class TokenSetter {
@ -20,11 +23,16 @@ public class TokenSetter {
}
public static void set(String scope){
if(!props.containsKey(scope)) throw new RuntimeException("No token found for scope : "+scope);
SecurityTokenProvider.instance.set(props.getProperty(scope));
public static void set(String scope){
try{
if(!props.containsKey(scope)) throw new RuntimeException("No token found for scope : "+scope);
SecurityTokenProvider.instance.set(props.getProperty(scope));
}catch(Throwable e){
log.warn("Unable to set token for scope "+scope,e);
}
ScopeProvider.instance.set(scope);
}
}

View File

@ -27,7 +27,7 @@ public class TrueMarbleMeta {
* @throws Exception
*/
public static void main(String[] args) throws Exception {
TokenSetter.set("/gcube/devsec/devVRE");
TokenSetter.set("/gcube/devNext/NextNext");
// TokenSetter.set("/d4science.research-infrastructures.eu");
GcubeISOMetadata gMeta=new GcubeISOMetadata();
gMeta.setAbstractField("This layer is used as a base layer for GIS VIewer widget");
@ -50,15 +50,9 @@ public class TrueMarbleMeta {
publisher.login(LoginLevel.PRIVATE);
GNInsertConfiguration config=publisher.getCurrentUserConfiguration("dataset", "_none_");
Long id=publisher.insertMetadata(config,meta);
Long id=publisher.insertAndPromoteMetadata(config,meta);
System.out.println("Inserted meta with id : "+id);
// setting privileges
// GNPrivConfiguration privs=new GNPrivConfiguration();
// ScopeConfiguration scopeConfig=publisher.getConfiguration().getScopeConfiguration();
// privs.addPrivileges(scopeConfig.getDefaultGroup(), EnumSet.of(GNPriv.VIEW,GNPriv.FEATURED));
// publisher.setPrivileges(id, privs);
// System.out.println("Privileges set");
}

File diff suppressed because it is too large Load Diff

View File