diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/managers/scope/ScopeManager.java b/src/main/java/org/gcube/resourcemanagement/support/server/managers/scope/ScopeManager.java index 80189c0..0cd0e40 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/server/managers/scope/ScopeManager.java +++ b/src/main/java/org/gcube/resourcemanagement/support/server/managers/scope/ScopeManager.java @@ -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 toCopy = readScopes(confFile); + for (String key : toCopy.keySet()) { + SCOPES.put(key, toCopy.get(key)); + } + } + /** + * + * @param confFile + * @return + * @throws Exception + */ + public static LinkedHashMap readScopes(String confFile) throws Exception { if (confFile == null) { throw new NullPointerException("the scope file has not been defined"); } + LinkedHashMap toReturn = new LinkedHashMap(); 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); + toReturn.put(vo.toString(), vo); try { - //vo.setServiceMap(loadServiceMap((VO) vo, fileName)); - SCOPES.put(vo.toString(), vo); - - ServerConsole.info(LOG_PREFIX, " Scopes in VO " + vo.toString()); - - try { - for (String vre : getVREFromVO(vo)) { - // This operation overrides the vo map - SCOPES.put(vre.toString(), new ScopeBean(vo.toString()+"/"+vre)); - } - } catch (Exception e) { - ServerConsole.error(LOG_PREFIX, "Exception raised while loading VREs for VO : " + vo, e); + for (String vre : getVREFromVO(vo)) { + // This operation overrides the vo map + toReturn.put(vre.toString(), new ScopeBean(vo.toString()+"/"+vre)); } + } catch (Exception 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); - } - - } - ServerConsole.info(LOG_PREFIX, "*** found scopes : " + SCOPES.keySet()); - } + return toReturn; + } + /** + * query the IS to get the VRE list given a VO + * @param vo + * @return + * @throws Exception + */ protected static List getVREFromVO(final ScopeBean vo) throws Exception { ServerConsole.info(LOG_PREFIX, "Starting Retrieving VREs for VO : " + vo); List toReturn = new ArrayList();