edited scopeManager to make it exploitable by other widgets

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/admin/rmp-common-library@81594 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2013-09-17 09:25:43 +00:00
parent 8a52b59368
commit da7a38a6b4
1 changed files with 34 additions and 29 deletions

View File

@ -24,8 +24,8 @@ import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -35,18 +35,13 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.gcube.common.resources.gcore.GenericResource;
import org.gcube.common.resources.gcore.utils.XPathHelper;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.resourcemanagement.support.server.gcube.CacheManager;
import org.gcube.resourcemanagement.support.server.gcube.ISClientRequester;
import org.gcube.resourcemanagement.support.server.utils.ServerConsole;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
@ -91,46 +86,56 @@ public class ScopeManager {
SCOPES.clear();
}
public static void update()
throws Exception {
public static void update() throws Exception {
if (confFile == null) {
throw new NullPointerException("the scope file has not been defined");
}
LinkedHashMap<String, ScopeBean> toCopy = readScopes(confFile);
for (String key : toCopy.keySet()) {
SCOPES.put(key, toCopy.get(key));
}
}
/**
*
* @param confFile
* @return
* @throws Exception
*/
public static LinkedHashMap<String, ScopeBean> readScopes(String confFile) throws Exception {
if (confFile == null) {
throw new NullPointerException("the scope file has not been defined");
}
LinkedHashMap<String, ScopeBean> toReturn = new LinkedHashMap<String, ScopeBean>();
String scopeXML = fileToString(confFile);
ServerConsole.info(LOG_PREFIX, "Starting retrieving scopes..");
Document scopeDocument = getDocumentGivenXML(scopeXML);
NodeList voElements = scopeDocument.getElementsByTagName("vo");
for (int i = 0; i < voElements.getLength(); i++) {
NodeList voDetails = voElements.item(i).getChildNodes();
String voString = voDetails.item(5).getFirstChild().getNodeValue();
String fileName = voDetails.item(3).getFirstChild().getNodeValue();
// String voName = voDetails.item(1).getFirstChild().getNodeValue();
ScopeBean vo = new ScopeBean(voString);
try {
//vo.setServiceMap(loadServiceMap((VO) vo, fileName));
SCOPES.put(vo.toString(), vo);
ServerConsole.info(LOG_PREFIX, " Scopes in VO " + vo.toString());
toReturn.put(vo.toString(), vo);
try {
for (String vre : getVREFromVO(vo)) {
// This operation overrides the vo map
SCOPES.put(vre.toString(), new ScopeBean(vo.toString()+"/"+vre));
toReturn.put(vre.toString(), new ScopeBean(vo.toString()+"/"+vre));
}
} catch (Exception e) {
ServerConsole.error(LOG_PREFIX, "Exception raised while loading VREs for VO : " + vo, e);
ServerConsole.error("Exception raised while loading VREs for VO : " + vo, e);
}
}
catch (Exception e) {
ServerConsole.warn(LOG_PREFIX, "skipping... map not found for VO : " + vo, e);
}
return toReturn;
}
ServerConsole.info(LOG_PREFIX, "*** found scopes : " + SCOPES.keySet());
}
/**
* query the IS to get the VRE list given a VO
* @param vo
* @return
* @throws Exception
*/
protected static List<String> getVREFromVO(final ScopeBean vo) throws Exception {
ServerConsole.info(LOG_PREFIX, "Starting Retrieving VREs for VO : " + vo);
List<String> toReturn = new ArrayList<String>();