Initial import.
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/uri-resolver-manager@100670 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
179b39f897
commit
c725d44ddf
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/uri-resolver-manager-1.0.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/uri-resolver-manager-1.0.0-SNAPSHOT/WEB-INF/classes"/>
|
||||
</classpath>
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>uri-resolver-manager</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,3 @@
|
|||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding/<project>=UTF-8
|
|
@ -0,0 +1,5 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
||||
org.eclipse.jdt.core.compiler.compliance=1.5
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.5
|
|
@ -0,0 +1,4 @@
|
|||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
|
@ -0,0 +1,244 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.gcube.portlets.user</groupId>
|
||||
<artifactId>uri-resolver-manager</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>uri-resolver-manager</name>
|
||||
|
||||
|
||||
<description>The URI Resolver Manager</description>
|
||||
<scm>
|
||||
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/${project.artifactId}</url>
|
||||
</scm>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<name>Francesco Mangiacrapa</name>
|
||||
<email>francesco.mangiacrapa@isti.cnr.it</email>
|
||||
<organization>CNR Pisa, Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo"</organization>
|
||||
<roles>
|
||||
<role>architect</role>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>maven-bom</artifactId>
|
||||
<version>LATEST</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
<properties>
|
||||
<distroDirectory>${project.basedir}/distro</distroDirectory>
|
||||
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
|
||||
<release.date>2014-05-16</release.date>
|
||||
<templatesDirectory>templates</templatesDirectory>
|
||||
<distroDirectory>distro</distroDirectory>
|
||||
<configDirectory>config</configDirectory>
|
||||
|
||||
<!-- Convenience property to set the GWT version -->
|
||||
<gwtVersion>2.5.1</gwtVersion>
|
||||
<!-- To make this work on gwt-run you need to set up global env vars. on
|
||||
MacOSX edit this file /etc/launchd.conf and put "setenv GLOBUS_LOCATION /Users/massi/portal/Portal-Bundle/gCore"
|
||||
on Linux? -->
|
||||
<GLOBUS_LOCATION>${env.GLOBUS_LOCATION}</GLOBUS_LOCATION>
|
||||
<!-- GWT needs at least java 1.5 -->
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
</properties>
|
||||
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- FWS -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.resources.discovery</groupId>
|
||||
<artifactId>ic-client</artifactId>
|
||||
<!-- <version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> -->
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- END FWS -->
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-httpclient</groupId>
|
||||
<artifactId>commons-httpclient</artifactId>
|
||||
<version>3.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-encryption</artifactId>
|
||||
<version>[1.0.1-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
<version>1.0.0.GA</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
<version>1.0.0.GA</version>
|
||||
<classifier>sources</classifier>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- JSON PARSER -->
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20090211</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<!-- <version>1.2.16</version> -->
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<!-- <version>1.6.4</version> -->
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- JUNIT -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<!-- Generate compiled stuff in the folder used for developing mode -->
|
||||
<outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.16</version>
|
||||
<configuration>
|
||||
<skipTests>true</skipTests>
|
||||
</configuration>
|
||||
<!-- TODO check if needed -->
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.surefire</groupId>
|
||||
<artifactId>surefire-junit47</artifactId>
|
||||
<version>2.16</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
|
||||
<!-- Maven -->
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-profile</id>
|
||||
<phase>process-resources</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${configDirectory}</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${templatesDirectory}</directory>
|
||||
<includes>
|
||||
<include>profile.xml</include>
|
||||
</includes>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>copy-distro-resources</id>
|
||||
<phase>process-resources</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${distroDirectory}</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${templatesDirectory}</directory>
|
||||
<excludes>
|
||||
<exclude>profile.xml</exclude>
|
||||
<exclude>descriptor.xml</exclude>
|
||||
</excludes>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
<configuration>
|
||||
<filesets>
|
||||
<fileset>
|
||||
<directory>${distroDirectory}</directory>
|
||||
<includes>
|
||||
<include>**</include>
|
||||
</includes>
|
||||
<followSymlinks>false</followSymlinks>
|
||||
</fileset>
|
||||
<fileset>
|
||||
<directory>${configDirectory}</directory>
|
||||
<includes>
|
||||
<include>**</include>
|
||||
</includes>
|
||||
<followSymlinks>false</followSymlinks>
|
||||
</fileset>
|
||||
</filesets>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>${templatesDirectory}/descriptor.xml</descriptor>
|
||||
</descriptors>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>servicearchive</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,55 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
|
||||
<settings>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>it-repo</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>local.central</id>
|
||||
<url>@localRepositoryUrl@</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>local.central</id>
|
||||
<url>@localRepositoryUrl@</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
</profile>
|
||||
</profiles>
|
||||
</settings>
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.gcube.portlets.user.it</groupId>
|
||||
<artifactId>simple-it</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<description>A simple IT verifying the basic use case.</description>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>@project.groupId@</groupId>
|
||||
<artifactId>@project.artifactId@</artifactId>
|
||||
<version>@project.version@</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>touch</id>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>touch</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,3 @@
|
|||
File touchFile = new File( basedir, "target/touch.txt" );
|
||||
|
||||
assert touchFile.isFile()
|
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.uriresolvermanager;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.portlets.user.uriresolvermanager.type.ApplicationTypePropertyReader;
|
||||
import org.gcube.portlets.user.uriresolvermanager.type.PropertyFileNotFoundException;
|
||||
|
||||
/**
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* @Oct 14, 2014
|
||||
*
|
||||
*/
|
||||
public class UriResolveManager {
|
||||
|
||||
|
||||
private ApplicationTypePropertyReader applicationTypeReader;
|
||||
private String userApplicationType;
|
||||
|
||||
private Map<String, String> applicationTypes;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param scope
|
||||
* @param applicationType a key Application Type
|
||||
*/
|
||||
public UriResolveManager(String scope, String applicationType){
|
||||
try {
|
||||
|
||||
this.applicationTypes = new ApplicationTypePropertyReader().getApplicationTypes();
|
||||
|
||||
this.userApplicationType = applicationType;
|
||||
|
||||
if(!this.applicationTypeReader.getApplicationTypes().containsKey(applicationType)){
|
||||
|
||||
}
|
||||
|
||||
|
||||
} catch (PropertyFileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the Application Types availables
|
||||
*/
|
||||
public Set<String> getApplicationTypes(){
|
||||
return this.applicationTypes.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return a map Application Type - Resource Name
|
||||
*/
|
||||
public Map<String, String> getCapabilities(){
|
||||
return this.applicationTypes;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.uriresolvermanager.entity;
|
||||
|
||||
/**
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* @Oct 14, 2014
|
||||
*
|
||||
*/
|
||||
public class ServiceProperty {
|
||||
|
||||
private String key;
|
||||
private String defaultValue;
|
||||
private boolean isMandatory;
|
||||
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* @param defaultValue
|
||||
* @param isMandatory
|
||||
*/
|
||||
public ServiceProperty(String key, boolean isMandatory) {
|
||||
super();
|
||||
this.key = key;
|
||||
this.isMandatory = isMandatory;
|
||||
}
|
||||
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
public boolean isMandatory() {
|
||||
return isMandatory;
|
||||
}
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
public void setDefaultValue(String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
public void setMandatory(boolean isMandatory) {
|
||||
this.isMandatory = isMandatory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("ServiceProperty [key=");
|
||||
builder.append(key);
|
||||
builder.append(", defaultValue=");
|
||||
builder.append(defaultValue);
|
||||
builder.append(", isMandatory=");
|
||||
builder.append(isMandatory);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.uriresolvermanager.exception;
|
||||
|
||||
/**
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* @Oct 14, 2014
|
||||
*
|
||||
*/
|
||||
public class IllegalArgumentException extends Exception {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 769797235962949500L;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public IllegalArgumentException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public IllegalArgumentException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package org.gcube.portlets.user.uriresolvermanager.type;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class ApplicationTypePropertyReader {
|
||||
|
||||
protected static final String RESOURCE_FILE_PROPERTIES = "applicationtyperesources.properties";
|
||||
|
||||
private Map<String, String> applicationTypes; //A map ApplicationType - Resource Name
|
||||
|
||||
private Logger logger = Logger.getLogger(ApplicationTypePropertyReader.class);
|
||||
|
||||
public ApplicationTypePropertyReader() throws PropertyFileNotFoundException {
|
||||
|
||||
Properties prop = new Properties();
|
||||
|
||||
try {
|
||||
|
||||
InputStream in = (InputStream) ApplicationTypePropertyReader.class.getResourceAsStream(RESOURCE_FILE_PROPERTIES);
|
||||
|
||||
// load a properties file
|
||||
prop.load(in);
|
||||
|
||||
applicationTypes = new HashMap<String, String>(prop.keySet().size());
|
||||
|
||||
for (Object key : prop.keySet()) {
|
||||
String resource = (String) prop.get(key);
|
||||
applicationTypes.put((String)key, resource);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
logger.error("An error occurred on read property file "+e, e);
|
||||
throw new PropertyFileNotFoundException("An error occurred on read property file "+e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("ApplicationTypePropertyReader [applicationTypes=");
|
||||
builder.append(applicationTypes);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public Map<String, String> getApplicationTypes() {
|
||||
return applicationTypes;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
ApplicationTypePropertyReader reader = new ApplicationTypePropertyReader();
|
||||
System.out.println(reader);
|
||||
} catch (PropertyFileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package org.gcube.portlets.user.uriresolvermanager.type;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class PropertyFileNotFoundException extends Exception {
|
||||
public PropertyFileNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
# Property files
|
||||
#
|
||||
# author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
# created 10/2014
|
||||
#
|
||||
#
|
||||
|
||||
GIS = Gis-Resolver
|
||||
SMP = HTTP-URI-Resolver
|
|
@ -0,0 +1,140 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.uriresolvermanager.util;
|
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
||||
import org.gcube.common.resources.gcore.utils.Group;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.portlets.user.uriresolvermanager.entity.ServiceProperty;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* @Oct 7, 2014
|
||||
*
|
||||
*/
|
||||
public class RuntimeResourceReader {
|
||||
|
||||
public static final String RESOURCE_NAME = "Gis-Resolver";
|
||||
|
||||
public static final Logger logger = LoggerFactory.getLogger(RuntimeResourceReader.class);
|
||||
|
||||
public List<ServiceProperty> serviceProperties;
|
||||
|
||||
private String resourceName;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param scope
|
||||
* @return the application URI
|
||||
* @throws Exception
|
||||
*/
|
||||
private String readResource(String scope, String resourceName) throws Exception
|
||||
{
|
||||
try{
|
||||
|
||||
this.resourceName = resourceName;
|
||||
|
||||
String infraName = ScopeUtil.getInfrastructureNameFromScope(scope);
|
||||
|
||||
logger.info("Instancing root scope: "+infraName);
|
||||
ScopeProvider.instance.set(infraName);
|
||||
|
||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||
query.addCondition("$resource/Profile/Name/string() eq '"+resourceName+"'");
|
||||
|
||||
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||
|
||||
List<ServiceEndpoint> r = client.submit(query);
|
||||
if (r == null || r.isEmpty()) throw new Exception("Cannot retrieve the runtime resource: "+resourceName);
|
||||
|
||||
ServiceEndpoint se = r.get(0);
|
||||
if(se.profile()==null)
|
||||
throw new Exception("IS profile is null for resource: "+resourceName);
|
||||
|
||||
Group<AccessPoint> accessPoints = se.profile().accessPoints();
|
||||
if(accessPoints.size()==0) throw new Exception("Accesspoint in resource "+resourceName+" not found");
|
||||
|
||||
AccessPoint ap = accessPoints.iterator().next();
|
||||
logger.info("returning GIS resolver URI root scope: "+ap.address());
|
||||
|
||||
Group<Property> properties = ap.properties();
|
||||
|
||||
if(properties.size()==0){
|
||||
logger.warn("Properties in resource "+resourceName+" not found");
|
||||
}else{
|
||||
|
||||
serviceProperties = new ArrayList<ServiceProperty>(properties.size());
|
||||
|
||||
Iterator<Property> iter = properties.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
|
||||
Property prop = iter.next();
|
||||
|
||||
serviceProperties.add(new ServiceProperty(prop.value(), true));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return ap.address();
|
||||
// parameters.setUser(ap.username()); //username
|
||||
//
|
||||
// String decryptedPassword = StringEncrypter.getEncrypter().decrypt(ap.password());
|
||||
//
|
||||
// parameters.setPassword(decryptedPassword); //password
|
||||
// Group<Property> properties = ap.properties();
|
||||
|
||||
}catch (Exception e) {
|
||||
logger.error("Sorry, an error occurred on reading the resource "+RESOURCE_NAME+ "Runtime Reosurces",e);
|
||||
throw new Exception("Sorry, an error occurred on reading the resource "+RESOURCE_NAME+ "Runtime Reosurces");
|
||||
}
|
||||
}
|
||||
|
||||
public List<ServiceProperty> getServiceProperties() {
|
||||
return serviceProperties;
|
||||
}
|
||||
|
||||
public String getResourceName() {
|
||||
return resourceName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("RuntimeResourceReader [serviceProperties=");
|
||||
builder.append(serviceProperties);
|
||||
builder.append(", resourceName=");
|
||||
builder.append(resourceName);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
RuntimeResourceReader resolver = new RuntimeResourceReader();
|
||||
try {
|
||||
resolver.readResource("/gcube", "Gis-Resolver");
|
||||
System.out.println(resolver);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.uriresolvermanager.util;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* @Oct 13, 2014
|
||||
*
|
||||
*/
|
||||
public class ScopeUtil {
|
||||
|
||||
private static final String SCOPE_SEPARATOR = "/";
|
||||
public static final Logger logger = LoggerFactory.getLogger(ScopeUtil.class);
|
||||
|
||||
|
||||
public static String getInfrastructureNameFromScope(String scope) throws Exception{
|
||||
|
||||
if(scope==null || scope.isEmpty()){
|
||||
throw new Exception("Scope is null or empty");
|
||||
}
|
||||
|
||||
if(!scope.startsWith(SCOPE_SEPARATOR)){
|
||||
logger.warn("Input scope: "+scope+" not have / is a really scope?");
|
||||
scope = SCOPE_SEPARATOR+scope;
|
||||
logger.warn("Tentative as scope: "+scope);
|
||||
}
|
||||
|
||||
String[] splitScope = scope.split(SCOPE_SEPARATOR);
|
||||
|
||||
String rootScope = SCOPE_SEPARATOR + splitScope[1];
|
||||
|
||||
if(rootScope.length()<2){
|
||||
throw new Exception("Infrastructure name not found in "+scope);
|
||||
}
|
||||
|
||||
return rootScope;
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue