86 lines
2.2 KiB
Java
86 lines
2.2 KiB
Java
|
package org.gcube.common.portal;
|
||
|
|
||
|
import java.io.File;
|
||
|
import java.io.FileInputStream;
|
||
|
import java.io.IOException;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.List;
|
||
|
import java.util.Properties;
|
||
|
|
||
|
import org.slf4j.Logger;
|
||
|
import org.slf4j.LoggerFactory;
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Clients can obtain the single instance of the {@link Portal} by invoking its static method {@link #getConfiguration()}.
|
||
|
* The first invocation of the method triggers the initialisation of the instance.
|
||
|
*
|
||
|
* @author Massimiliano Assante (ISTI-CNR)
|
||
|
*
|
||
|
*/
|
||
|
public class Portal {
|
||
|
private static final Logger _log = LoggerFactory.getLogger(Portal.class);
|
||
|
|
||
|
public static final String INFRASTRUCTURE_NAME = "infrastructure";
|
||
|
public static final String SCOPES = "scopes";
|
||
|
|
||
|
protected static Portal singleton = new Portal();
|
||
|
|
||
|
private String infra;
|
||
|
private String vos;
|
||
|
|
||
|
private Portal() {
|
||
|
initialize();
|
||
|
}
|
||
|
/**
|
||
|
*
|
||
|
* @return the instance
|
||
|
*/
|
||
|
public synchronized static Portal getConfiguration() {
|
||
|
return singleton == null ? new Portal() : singleton;
|
||
|
}
|
||
|
|
||
|
|
||
|
private void initialize() {
|
||
|
Properties props = new Properties();
|
||
|
try {
|
||
|
String propertyfile = getGCoreFolder() + File.separator + "infrastructure.properties";
|
||
|
File propsFile = new File(propertyfile);
|
||
|
FileInputStream fis = new FileInputStream(propsFile);
|
||
|
props.load( fis);
|
||
|
infra = props.getProperty(INFRASTRUCTURE_NAME);
|
||
|
vos = props.getProperty(SCOPES);
|
||
|
}
|
||
|
catch(IOException e) {
|
||
|
infra = "gcube";
|
||
|
vos = "";
|
||
|
_log.error("infrastructure.properties file not found under $CATALINA_HOME/ dir, setting default infrastructure Name and no Scopes" + infra);
|
||
|
}
|
||
|
_log.info("Portal configurator correctly initialized on " + infra);
|
||
|
}
|
||
|
|
||
|
public String getInfrastructureName() {
|
||
|
return this.infra;
|
||
|
}
|
||
|
|
||
|
public List<String> getVOs() {
|
||
|
List<String> toReturn = new ArrayList<String>();
|
||
|
if (vos == null || vos.equals(""))
|
||
|
return toReturn;
|
||
|
String[] split = vos.split(",");
|
||
|
for (int i = 0; i < split.length; i++) {
|
||
|
toReturn.add(split[i].trim());
|
||
|
}
|
||
|
return toReturn;
|
||
|
}
|
||
|
/**
|
||
|
*
|
||
|
* @return $CATALINA_HOME
|
||
|
*/
|
||
|
private static String getGCoreFolder() {
|
||
|
return (System.getenv("GLOBUS_LOCATION").endsWith("/") ? System.getenv("GLOBUS_LOCATION") : System.getenv("GLOBUS_LOCATION")+"/");
|
||
|
}
|
||
|
}
|