From 756f7a96d74ca4aa565f1587f652cbf95a238a27 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Thu, 12 Sep 2013 16:47:59 +0000 Subject: [PATCH] gCore dep removed except for logging git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/admin/rmp-common-library@81325 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 2 +- pom.xml | 23 +--- .../server/gcube/ISClientRequester.java | 78 ++++++------- .../support/server/gcube/ISQueryCache.java | 2 - .../server/gcube/queries/QueryLocation.java | 4 + .../server/gcube/queries/xquery/getPlugins.xq | 1 - .../gcube/queries/xquery/related/GHN.xq | 9 +- .../queries/xquery/related/RETURN_GHN.xq | 8 ++ .../xquery/related/RETURN_RunningInstance.xq | 45 ++++++++ .../queries/xquery/related/RETURN_Service.xq | 21 ++++ .../queries/xquery/related/RunningInstance.xq | 48 +------- .../gcube/queries/xquery/related/Service.xq | 22 +--- .../resources/AbstractResourceManager.java | 56 ++-------- .../managers/resources/CollectionManager.java | 5 - .../resources/GenericResourceManager.java | 25 +++-- .../managers/resources/ManagementUtils.java | 11 +- .../server/managers/scope/ScopeManager.java | 105 ++++++++---------- .../support/server/tests/GenericTest.java | 50 +++++---- .../support/server/utils/ServerConsole.java | 21 ++-- .../utils/persistence/TestPersistence.java | 10 +- .../types/datamodel/ResourceDetailModel.java | 7 +- 21 files changed, 260 insertions(+), 293 deletions(-) create mode 100644 src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/RETURN_GHN.xq create mode 100644 src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/RETURN_RunningInstance.xq create mode 100644 src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/RETURN_Service.xq diff --git a/.classpath b/.classpath index 5d07f51..b48df3f 100644 --- a/.classpath +++ b/.classpath @@ -12,7 +12,7 @@ - + diff --git a/pom.xml b/pom.xml index 89fa6c9..b7481d1 100644 --- a/pom.xml +++ b/pom.xml @@ -35,6 +35,12 @@ UTF-8 + + org.gcube.core + gcf + [1.4.0-SNAPSHOT, 2.0.0-SNAPSHOT) + provided + com.google.gwt @@ -49,23 +55,6 @@ 2.2.5 provided - - org.gcube.core - gcf - [1.4.0-SNAPSHOT, 2.0.0-SNAPSHOT) - provided - - - org.gcube.distribution - ghn-client-runtime - [2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT) - provided - - - - - - org.gcube.resources.discovery diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/ISClientRequester.java b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/ISClientRequester.java index 96e3a28..b6e033b 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/ISClientRequester.java +++ b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/ISClientRequester.java @@ -42,12 +42,6 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; -import org.gcube.common.core.contexts.GHNContext; -import org.gcube.common.core.informationsystem.client.ISClient; -import org.gcube.common.core.informationsystem.client.XMLResult; -import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericQuery; -import org.gcube.common.core.scope.GCUBEScope; -import org.gcube.common.core.utils.logging.GCUBEClientLog; import org.gcube.common.resources.gcore.utils.XPathHelper; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.impl.ScopeBean; @@ -79,7 +73,6 @@ import org.xml.sax.SAXException; * @author Daniele Strollo */ public class ISClientRequester { - static GCUBEClientLog _log = new GCUBEClientLog(ISClientRequester.class); private static final ISQueryCache CACHE = new ISQueryCache(); private static final String LOG_PREFIX = "[ISCLIENT-REQS]"; @@ -254,7 +247,7 @@ public class ISClientRequester { retval.put(type, subtypes); } } catch (Exception e) { - _log.error(LOG_PREFIX, e); + ServerConsole.error(LOG_PREFIX, e); } } @@ -301,8 +294,8 @@ public class ISClientRequester { DiscoveryClient client = client(); isQuery.addParameter("RES_ID", id.trim()); - - + //add the return statement + isQuery.addParameter("RESOURCE", QueryLoader.getQuery(QueryLocation.valueOf("LIST_RELATED_RETURN_" + type))); ISQueryCacheKeyT cacheKey = new ISQueryCacheKeyT(queryScope.toString(), isQuery.expression(), "getResourceRelated"); @@ -317,6 +310,7 @@ public class ISClientRequester { } } if (resultz == null || resultz.size() == 0) { + ServerConsole.debug(LOG_PREFIX, "[getResourcesRelated] Got No Results"); return null; } // ENDOF Handle cache @@ -583,32 +577,36 @@ public class ISClientRequester { return null; } - public static Map getGenericResourcePlugins(final GCUBEScope scope) throws Exception { - ISClient client = GHNContext.getImplementation(ISClient.class); - GCUBEGenericQuery isQuery = null; - isQuery = client.getQuery(GCUBEGenericQuery.class); - isQuery.setExpression(QueryLoader.getQuery(QueryLocation.GET_GENERIC_RESOURCE_PLUGINS)); - List results = client.execute(isQuery, scope); + public static Map getGenericResourcePlugins(final ScopeBean scope) throws Exception { + //set the scope + ScopeProvider.instance.set(scope.toString()); + + Query isQuery = new QueryBox(QueryLoader.getQuery(QueryLocation.GET_GENERIC_RESOURCE_PLUGINS)); + DiscoveryClient client = client(); + List resultz= client.submit(isQuery); Map retval = new HashMap(); - gonext: for (XMLResult plugin : results) { + gonext: for (String plugin : resultz) { try { - for (String entry : plugin.evaluate("/CMPlugins/Plugin/Entry")) { + DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + Node node = docBuilder.parse(new InputSource(new StringReader(plugin))).getDocumentElement(); + XPathHelper helper = new XPathHelper(node); + for (String entry : helper.evaluate("/CMPlugins/Plugin/Entry")) { Document doc = ScopeManager.getDocumentGivenXML(entry); String name = doc.getElementsByTagName("name").item(0).getFirstChild().getNodeValue(); - _log.trace("[LOAD-PLUGIN] found: *** name " + name); + ServerConsole.trace("[LOAD-PLUGIN] found: *** name " + name); String pluginType = doc.getElementsByTagName("Type").item(0).getFirstChild().getNodeValue(); - _log.trace("[LOAD-PLUGIN] found: *** type " + pluginType); + ServerConsole.trace("[LOAD-PLUGIN] found: *** type " + pluginType); String description = doc.getElementsByTagName("description").item(0).getFirstChild().getNodeValue(); - _log.trace("[LOAD-PLUGIN] found: *** description " + description); + ServerConsole.trace("[LOAD-PLUGIN] found: *** description " + description); String namespace = null; try { namespace = doc.getElementsByTagName("namespace").item(0).getFirstChild().getNodeValue(); - _log.debug("[LOAD-PLUGIN] found: *** namespace " + namespace); + ServerConsole.debug("[LOAD-PLUGIN] found: *** namespace " + namespace); } catch (Exception e) { - _log.warn("[LOAD-PLUGIN] namespace not found"); + ServerConsole.warn("[LOAD-PLUGIN] namespace not found"); } GenericResourcePlugin toAdd = new GenericResourcePlugin(name, namespace, description, pluginType); @@ -629,7 +627,7 @@ public class ISClientRequester { } } - _log.trace("[LOAD-PLUGIN] found: param " + paramName); + ServerConsole.trace("[LOAD-PLUGIN] found: param " + paramName); GenericResourcePlugin.Field paramField = new GenericResourcePlugin.Field(paramName, GenericResourcePlugin.FieldType.string); if (paramDefinition != null) { @@ -688,32 +686,36 @@ public class ISClientRequester { * @return a map containing the plugin name as key and a List of formfield * @throws Exception */ - public static HashMap> getGenericResourceTreeManagerPlugins(final GCUBEScope scope) throws Exception { - ISClient client = GHNContext.getImplementation(ISClient.class); - GCUBEGenericQuery isQuery = null; - isQuery = client.getQuery(GCUBEGenericQuery.class); - isQuery.setExpression(QueryLoader.getQuery(QueryLocation.GET_GENERIC_RESOURCE_TREE_MANAGER_PLUGINS)); - List results = client.execute(isQuery, scope); + public static HashMap> getGenericResourceTreeManagerPlugins(final ScopeBean scope) throws Exception { + + ScopeProvider.instance.set(scope.toString()); + + Query isQuery = new QueryBox(QueryLoader.getQuery(QueryLocation.GET_GENERIC_RESOURCE_TREE_MANAGER_PLUGINS)); + DiscoveryClient client = client(); + List resultz= client.submit(isQuery); HashMap> retval = new HashMap>(); - gonext: for (XMLResult plugin : results) { + gonext: for (String plugin : resultz) { try { - for (String entry : plugin.evaluate("/TMPlugins/Plugin/Entry")) { + DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + Node node = docBuilder.parse(new InputSource(new StringReader(plugin))).getDocumentElement(); + XPathHelper helper = new XPathHelper(node); + for (String entry : helper.evaluate("/TMPlugins/Plugin/Entry")) { String requestName = null; boolean foundRequest = false; Document doc = ScopeManager.getDocumentGivenXML(entry); String name = doc.getElementsByTagName("name").item(0).getFirstChild().getNodeValue(); - _log.trace("[LOAD-TMPLUGIN] found: *** name " + name); + ServerConsole.trace("[LOAD-TMPLUGIN] found: *** name " + name); String pluginType = doc.getElementsByTagName("Type").item(0).getFirstChild().getNodeValue(); - _log.trace("[LOAD-TMPLUGIN] found: *** type " + pluginType); + ServerConsole.trace("[LOAD-TMPLUGIN] found: *** type " + pluginType); String description = doc.getElementsByTagName("description").item(0).getFirstChild().getNodeValue(); - _log.trace("[LOAD-TMPLUGIN] found: *** description " + description); + ServerConsole.trace("[LOAD-TMPLUGIN] found: *** description " + description); String namespace = null; try { namespace = doc.getElementsByTagName("namespace").item(0).getFirstChild().getNodeValue(); - _log.trace("[LOAD-TMPLUGIN] found: *** namespace " + namespace); + ServerConsole.trace("[LOAD-TMPLUGIN] found: *** namespace " + namespace); } catch (Exception e) { - _log.warn("[LOAD-TMPLUGIN] namespace not found"); + ServerConsole.warn("[LOAD-TMPLUGIN] namespace not found"); } NodeList params = doc.getElementsByTagName("param"); @@ -831,7 +833,7 @@ public class ISClientRequester { DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Node xnode = docBuilder.parse(new InputSource(new StringReader(node))).getDocumentElement(); XPathHelper helper = new XPathHelper(xnode); - + if (type.equalsIgnoreCase(ResourceTypeDecorator.GHN.name())) { try { return helper.evaluate("/Resource/Profile/GHNDescription/Name/text()").get(0); diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/ISQueryCache.java b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/ISQueryCache.java index 3b087a5..601dff4 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/ISQueryCache.java +++ b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/ISQueryCache.java @@ -20,8 +20,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.gcube.common.core.informationsystem.client.XMLResult; - class ISQueryCacheKeyT { String keyValue = null; String queryExpression = null; diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/QueryLocation.java b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/QueryLocation.java index 31b54e4..7b486b3 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/QueryLocation.java +++ b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/QueryLocation.java @@ -49,14 +49,18 @@ public enum QueryLocation { // To retrieve the list of generic resources publishing plugins // to deploy activation records GET_GENERIC_RESOURCE_PLUGINS("getPlugins.xq"), + RETURN_GET_GENERIC_RESOURCE_PLUGINS("RETURN_getPlugins.xq"), // to deploy activation records for Tree manager GET_GENERIC_RESOURCE_TREE_MANAGER_PLUGINS("getTreeManagerPlugins.xq"), // Related resources LIST_RELATED_GHN("related/GHN.xq"), + LIST_RELATED_RETURN_GHN("related/RETURN_GHN.xq"), LIST_RELATED_RunningInstance("related/RunningInstance.xq"), + LIST_RELATED_RETURN_RunningInstance("related/RETURN_RunningInstance.xq"), LIST_RELATED_Service("related/Service.xq"), + LIST_RELATED_RETURN_Service("related/RETURN_Service.xq"), // Queries for sweeper SWEEPER_EXPIRED_GHN("sweeper/expiredGhns.xq"), diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/getPlugins.xq b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/getPlugins.xq index 061ad85..504cfc4 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/getPlugins.xq +++ b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/getPlugins.xq @@ -1,4 +1,3 @@ - for $_outer in collection("/db/Properties")//Document where ($_outer//Document/Data/child::*[local-name()='ServiceClass']/text() = 'ContentManagement' and exists($_outer/Data/child::*[local-name()='Plugin']/name)) diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/GHN.xq b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/GHN.xq index d8916a5..ab2d884 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/GHN.xq +++ b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/GHN.xq @@ -15,11 +15,4 @@ for $ris in collection('/db/Profiles/RunningInstance')//Resource where $ris//Resource/Profile/GHN/@UniqueID/string() eq '' return - - {$ris/ID} - {$ris/Profile/ServiceName} - {$ris/Profile/ServiceClass} - {$ris//Resource/@version/string()} - {$ris/Profile/Version/text()} - {$ris/Profile/DeploymentData/Status/text()} - \ No newline at end of file + diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/RETURN_GHN.xq b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/RETURN_GHN.xq new file mode 100644 index 0000000..0b94a44 --- /dev/null +++ b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/RETURN_GHN.xq @@ -0,0 +1,8 @@ + + {$ris/ID} + {$ris/Profile/ServiceName} + {$ris/Profile/ServiceClass} + {$ris//Resource/@version/string()} + {$ris/Profile/Version/text()} + {$ris/Profile/DeploymentData/Status/text()} + \ No newline at end of file diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/RETURN_RunningInstance.xq b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/RETURN_RunningInstance.xq new file mode 100644 index 0000000..4334898 --- /dev/null +++ b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/RETURN_RunningInstance.xq @@ -0,0 +1,45 @@ + + + ID + {$ri//Resource/ID/string()} + + + ServiceStatus + {$ri/Profile/DeploymentData/Status/string()} + + + ActivationTime + {$ri/Profile/DeploymentData/ActivationTime/@value/string()} + + + GHNName + {$ghn-name} + + + GHNSite + {$relatedghn/Profile/Site/Domain/string()} + + + GHNStatus + {$relatedghn/Profile/GHNDescription/Status/string()} + + + GHNActivationTime + {$relatedghn/Profile/GHNDescription/ActivationTime/string()} + + + GHNLastUpdate + {$relatedghn/Profile/GHNDescription/LastUpdate/string()} + + + GHNLoad15Min + {$relatedghn/Profile/GHNDescription/Load/@Last15Min/string()} + + + GHNLoad5Min + {$relatedghn/Profile/GHNDescription/Load/@Last5Min/string()} + + GHNLoad1Min + {$relatedghn/Profile/GHNDescription/Load/@Last1Min/string()} + + \ No newline at end of file diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/RETURN_Service.xq b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/RETURN_Service.xq new file mode 100644 index 0000000..52dd6e4 --- /dev/null +++ b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/RETURN_Service.xq @@ -0,0 +1,21 @@ + + + {$ri/ID/string()} + {$ri/Profile/DeploymentData/Status/string()} + {$ri/Profile/DeploymentData/ActivationTime/@value/string()} + {$ri/Profile/Version/string()} + + {$ghn-id} + {$ghn/Profile/GHNDescription/Name/string()} + {$ghn/Profile/Site/Domain/string()} + {$ghn/Profile/GHNDescription/Status/string()} + {$ghn/Profile/GHNDescription/Load/@Last15Min/string()} + {$ghn/Profile/GHNDescription/Load/@Last15Min/string()} + {$ghn/Profile/GHNDescription/Load/@Last15Min/string()} + {$ghn/Profile/GHNDescription/ActivationTime/string()} + {$ghn/Profile/GHNDescription/LastUpdate/string()} + +return + + {$relatedris} + \ No newline at end of file diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/RunningInstance.xq b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/RunningInstance.xq index c1daae2..ef22c5e 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/RunningInstance.xq +++ b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/RunningInstance.xq @@ -1,55 +1,11 @@ -let $profiles := collection('/db/Profiles/')//Resource[ID/string() eq ''] +let $profiles := collection('/db/Profiles/')//Resource[ID/string() eq ''] let $relatedghn := collection('/db/Profiles/GHN')//Resource[ID/string() eq $profiles/Profile/GHN/@UniqueID/string()] let $ghn-name := if (empty($relatedghn/Profile/GHNDescription/Name/string())) then $profiles/Profile/GHN/@UniqueID/string() else $relatedghn/Profile/GHNDescription/Name/string() for $ri in $profiles return - - - ID - {$ri//Resource/ID/string()} - - - ServiceStatus - {$ri/Profile/DeploymentData/Status/string()} - - - ActivationTime - {$ri/Profile/DeploymentData/ActivationTime/@value/string()} - - - GHNName - {$ghn-name} - - - GHNSite - {$relatedghn/Profile/Site/Domain/string()} - - - GHNStatus - {$relatedghn/Profile/GHNDescription/Status/string()} - - - GHNActivationTime - {$relatedghn/Profile/GHNDescription/ActivationTime/string()} - - - GHNLastUpdate - {$relatedghn/Profile/GHNDescription/LastUpdate/string()} - - - GHNLoad15Min - {$relatedghn/Profile/GHNDescription/Load/@Last15Min/string()} - - - GHNLoad5Min - {$relatedghn/Profile/GHNDescription/Load/@Last5Min/string()} - - GHNLoad1Min - {$relatedghn/Profile/GHNDescription/Load/@Last1Min/string()} - - \ No newline at end of file + \ No newline at end of file diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/Service.xq b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/Service.xq index 80ca4d6..d74a3e5 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/Service.xq +++ b/src/main/java/org/gcube/resourcemanagement/support/server/gcube/queries/xquery/related/Service.xq @@ -13,24 +13,4 @@ let $relatedris := let $ghn := collection('/db/Profiles/GHN')//Resource[ID/string() eq $ghn-id] return - - - {$ri/ID/string()} - {$ri/Profile/DeploymentData/Status/string()} - {$ri/Profile/DeploymentData/ActivationTime/@value/string()} - {$ri/Profile/Version/string()} - - {$ghn-id} - {$ghn/Profile/GHNDescription/Name/string()} - {$ghn/Profile/Site/Domain/string()} - {$ghn/Profile/GHNDescription/Status/string()} - {$ghn/Profile/GHNDescription/Load/@Last15Min/string()} - {$ghn/Profile/GHNDescription/Load/@Last15Min/string()} - {$ghn/Profile/GHNDescription/Load/@Last15Min/string()} - {$ghn/Profile/GHNDescription/ActivationTime/string()} - {$ghn/Profile/GHNDescription/LastUpdate/string()} - -return - - {$relatedris} - \ No newline at end of file + \ No newline at end of file diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/AbstractResourceManager.java b/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/AbstractResourceManager.java index a93c173..95d065d 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/AbstractResourceManager.java +++ b/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/AbstractResourceManager.java @@ -22,9 +22,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Vector; -import org.gcube.common.core.security.GCUBESecurityManagerImpl; import org.gcube.common.resources.gcore.Resource; -import org.gcube.common.resources.gcore.ScopeGroup; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.impl.ScopeBean; import org.gcube.common.scope.impl.ScopeBean.Type; @@ -63,7 +61,6 @@ public abstract class AbstractResourceManager { private String name = null; private AllowedResourceTypes type = null; private String subType = null; - private GCUBESecurityManagerImpl managerSec = null; private RegistryPublisher publisher = null; private static final String LOG_PREFIX = "[AbstractResMgr]"; @@ -77,15 +74,6 @@ public abstract class AbstractResourceManager { this.type = type; - /** - * Initially the security management is disabled. - */ - this.managerSec = new GCUBESecurityManagerImpl() { - public boolean isSecurityEnabled() { - return false; - } - }; - try { this.publisher = RegistryPublisherFactory.create(); } catch (Exception e) { @@ -135,20 +123,6 @@ public abstract class AbstractResourceManager { return publisher; } - public final void setSecurityManager(final GCUBESecurityManagerImpl securityManager) { - this.managerSec = securityManager; - } - - /** - * The security manager is initially instantiated with empty permissions. - * The {@link AbstractResourceManager#setSecurityManager} can be used to - * change it. - * @return - */ - public final GCUBESecurityManagerImpl getSecurityManager() { - return this.managerSec; - } - /** * All resources must be identifiable through an unique ID. *
@@ -201,7 +175,7 @@ public abstract class AbstractResourceManager { * @throws ResourceParameterException if the parameters are invalid */ public final RMBinderLibrary getResourceManager(String scope) throws AbstractResourceException { - String currScope = ScopeProvider.instance.get(); + ScopeBean bscope = new ScopeBean(scope); if (bscope.is(Type.VRE)) { scope = bscope.enclosingScope().toString(); @@ -212,7 +186,6 @@ public abstract class AbstractResourceManager { if (rml == null) { // no managers found throw new ResourceAccessException("Unable to find ResourceManagers for resource " + this.getType() + " in scope: " + scope.toString()); } - ScopeProvider.instance.set(currScope); return rml; } @@ -224,7 +197,6 @@ public abstract class AbstractResourceManager { * @throws ResourceParameterException if the parameters are invalid */ public final RMReportingLibrary getReportResourceManager(String scope) throws AbstractResourceException { - String currScope = ScopeProvider.instance.get(); ScopeBean bscope = new ScopeBean(scope); if (bscope.is(Type.VRE)) { scope = bscope.enclosingScope().toString(); @@ -236,7 +208,6 @@ public abstract class AbstractResourceManager { if (rml == null) { // no managers found throw new ResourceAccessException("Unable to find ResourceManagers for resource " + this.getType() + " in scope: " + scope.toString()); } - ScopeProvider.instance.set(currScope); return rml; } @@ -259,7 +230,9 @@ public abstract class AbstractResourceManager { LOG_PREFIX, "[BIND-SCOPE-ENTER] Adding " + this.getType() + " " + this.getID() + " to scope [" + targetScope.toString() + "]"); - + String curr = ScopeProvider.instance.get(); + ScopeProvider.instance.set(targetScope.toString()); + AddResourcesParameters addParam = new AddResourcesParameters(); ResourceItem toAdd = new ResourceItem(); toAdd.setId(this.getID()); @@ -275,7 +248,6 @@ public abstract class AbstractResourceManager { RMBinderLibrary manager = this.getResourceManager(targetScope); try { - String curr = ScopeProvider.instance.get(); ScopeBean scope = new ScopeBean(targetScope); if (scope.is(Type.VRE)) { ScopeProvider.instance.set(scope.enclosingScope().toString()); @@ -305,7 +277,7 @@ public abstract class AbstractResourceManager { /** - * Add a scope to a gHN and the related Service Map is already available on the gHN. + * Add a scope to a Resource * @param nestingPublication true for resources different from gHN and RI. * @return the reportID generated */ @@ -314,7 +286,9 @@ public abstract class AbstractResourceManager { checker.validate(sourceScope != null, new ResourceParameterException("Invalid parameter sourceScope. null not allowed.")); checker.validate(targetScope != null, new ResourceParameterException("Invalid parameter targetScope. null not allowed.")); checker.validate(this.getID() != null, new ResourceOperationException("Invalid resource ID. null not allowed.")); - + + String curr = ScopeProvider.instance.get(); + ScopeProvider.instance.set(sourceScope.toString()); ReportBuilder report = new ReportBuilder(); ServerConsole.trace( @@ -345,7 +319,10 @@ public abstract class AbstractResourceManager { targetScope.toString() + " the remote report ID is: " + this.bindToScope(targetScope.toString()), true)); - return report.getXML(); + + String toReturn = report.getXML(); + ScopeProvider.instance.set(curr); + return toReturn; } @@ -431,7 +408,6 @@ public abstract class AbstractResourceManager { Assertion checker = new Assertion(); checker.validate(this.getID() != null, new ResourceAccessException("Cannot execute on resources with no ID.")); - String currScope = ScopeProvider.instance.get(); ScopeProvider.instance.set(scope.toString()); // Phase 1. retrieve the resource to copy @@ -447,7 +423,6 @@ public abstract class AbstractResourceManager { if (results == null || results.isEmpty()) throw new ResourceAccessException("Cannot retrieve the IS profile for resource: " + this.getID() + " in scope: " + scope.toString()); - ScopeProvider.instance.set(currScope); return results.get(0).toString(); } @@ -482,10 +457,8 @@ public abstract class AbstractResourceManager { ServerConsole.trace(LOG_PREFIX, "[REMOVE-FROM-SCOPE] Sending the Remove Resource request...."); try { RMBinderLibrary manager = this.getResourceManager(scope.toString()); - String currScope = ScopeProvider.instance.get(); ScopeProvider.instance.set(scope.toString()); retval = manager.removeResources(params); - ScopeProvider.instance.set(currScope); } catch (Exception e) { throw new ResourceOperationException("During removeFrom scope of " + this.getType() @@ -503,12 +476,9 @@ public abstract class AbstractResourceManager { checker.validate(scope != null, new ResourceParameterException("Invalid parameter scope. null not allowed.")); checker.validate(this.getID() != null, new ResourceOperationException("Invalid ID. null not allowed.")); - String currScope = ScopeProvider.instance.get(); ScopeProvider.instance.set(scope.toString()); - String retval = this.basicRemoveFromScope(scope); - ScopeProvider.instance.set(currScope); return retval; } @@ -558,7 +528,6 @@ public abstract class AbstractResourceManager { checker.validate(this.getID() != null, new ResourceOperationException("Invalid ID. null not allowed.")); System.out.println("DELETING TYPE: "+ this.getType()); - String currScope = ScopeProvider.instance.get(); ScopeProvider.instance.set(scope.toString()); Resource resStub = this.getResource(scope); @@ -578,7 +547,6 @@ public abstract class AbstractResourceManager { } catch (Exception e) { } - ScopeProvider.instance.set(currScope); } } diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/CollectionManager.java b/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/CollectionManager.java index 5bc8bda..2280084 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/CollectionManager.java +++ b/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/CollectionManager.java @@ -16,11 +16,6 @@ package org.gcube.resourcemanagement.support.server.managers.resources; -import java.io.StringReader; - -import org.gcube.common.core.contexts.GHNContext; -import org.gcube.common.core.resources.GCUBECollection; -import org.gcube.common.core.resources.GCUBEResource; import org.gcube.common.resources.gcore.Resource; import org.gcube.resourcemanagement.support.server.exceptions.AbstractResourceException; import org.gcube.resourcemanagement.support.server.exceptions.ResourceAccessException; diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/GenericResourceManager.java b/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/GenericResourceManager.java index 36c6ba7..10f8d89 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/GenericResourceManager.java +++ b/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/GenericResourceManager.java @@ -44,6 +44,7 @@ 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.Text; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -139,7 +140,6 @@ public class GenericResourceManager extends AbstractResourceManager { if (subType != null) resource.profile().type(subType.trim()); - String currScope = ScopeProvider.instance.get(); ScopeProvider.instance.set(scope.toString()); RegistryPublisher publisher = getRegistryPublisher(); String id = publisher.update(resource).id(); @@ -147,13 +147,11 @@ public class GenericResourceManager extends AbstractResourceManager { if (id == null || id.length() == 0) { throw new Exception("The GenericResource has not been updated"); } - ScopeProvider.instance.set(currScope); ServerConsole.info(LOG_PREFIX, "Resource Updated with ID: " + id); } private GenericResource getResourceToEditById(String id, ScopeBean scope) throws Exception { - String currScope = ScopeProvider.instance.get(); ScopeProvider.instance.set(scope.toString()); SimpleQuery query = queryFor(GenericResource.class); @@ -163,7 +161,6 @@ public class GenericResourceManager extends AbstractResourceManager { List r = client.submit(query); - ScopeProvider.instance.set(currScope); if (r == null || r.isEmpty()) throw new Exception("Could not retrieve GenericResource profile with id " + id + " in scope + " +scope); else @@ -194,7 +191,7 @@ public class GenericResourceManager extends AbstractResourceManager { GenericResourceManager gm = new GenericResourceManager(); - String currScope = ScopeProvider.instance.get(); + ScopeProvider.instance.set(scope.toString()); RegistryPublisher publisher = gm.getRegistryPublisher(); String id = publisher.create(resource).id(); @@ -202,7 +199,6 @@ public class GenericResourceManager extends AbstractResourceManager { if (id == null || id.length() == 0) { throw new Exception("The GenericResource has not been created"); } - ScopeProvider.instance.set(currScope); ServerConsole.info(LOG_PREFIX, "Resource Created with ID: " + id); return id; } @@ -227,12 +223,21 @@ public class GenericResourceManager extends AbstractResourceManager { * @throws SAXException * @throws ParserConfigurationException */ - public static void appendXmlFragment(Node parent, String fragment) throws IOException, SAXException, ParserConfigurationException { + public static void appendXmlFragment(Node parent, String fragment) throws IOException, ParserConfigurationException { DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = parent.getOwnerDocument(); - Node fragmentNode = docBuilder.parse(new InputSource(new StringReader(fragment))).getDocumentElement(); - fragmentNode = doc.importNode(fragmentNode, true); - parent.appendChild(fragmentNode); + Node fragmentNode; + try { + fragmentNode = docBuilder.parse(new InputSource(new StringReader(fragment))).getDocumentElement(); + fragmentNode = doc.importNode(fragmentNode, true); + parent.appendChild(fragmentNode); + } catch (SAXException e) { + //in case no xml is entered, just text + System.out.println("to append: " + fragment); + Text text = doc.createTextNode(fragment); + doc.importNode(text, true); + } + } } diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/ManagementUtils.java b/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/ManagementUtils.java index 9aa4539..9bec0f5 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/ManagementUtils.java +++ b/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/ManagementUtils.java @@ -66,12 +66,7 @@ public class ManagementUtils { * @param targetScope * @return the generated report ID */ - public static final synchronized String addToExistingScope( - final AllowedResourceTypes type, - final String[] resourceIDs, - final ScopeBean sourceScope, - final ScopeBean targetScope) - throws Exception { + public static final synchronized String addToExistingScope(AllowedResourceTypes type, String[] resourceIDs, ScopeBean sourceScope, ScopeBean targetScope) throws Exception { ServerConsole.trace( LOG_PREFIX, "[ADD-ToExistingScope] Adding from scope [" + @@ -97,10 +92,10 @@ public class ManagementUtils { for (String id : resourceIDs) { AbstractResourceManager res = ResourceFactory.createResourceManager(type, id); Resource resStub = res.getResource(sourceScope); - String curr = ScopeProvider.instance.get(); + ScopeProvider.instance.set(targetScope.toString()); res.getRegistryPublisher().update(resStub); - ScopeProvider.instance.set(curr); + } } catch (Exception e) { throw new ResourceAccessException(e.getMessage()); 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 1207392..80189c0 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 @@ -16,32 +16,37 @@ package org.gcube.resourcemanagement.support.server.managers.scope; +import static org.gcube.resources.discovery.icclient.ICFactory.clientFor; +import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; + import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; +import java.io.StringReader; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; + import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import org.gcube.common.core.contexts.GHNContext; -import org.gcube.common.core.informationsystem.ISException; -import org.gcube.common.core.informationsystem.client.AtomicCondition; -import org.gcube.common.core.informationsystem.client.ISClient; -import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericResourceQuery; -import org.gcube.common.core.resources.GCUBEGenericResource; -import org.gcube.common.core.scope.GCUBEScope; -import org.gcube.common.core.scope.ServiceMap; -import org.gcube.common.core.scope.VO; -import org.gcube.common.core.scope.VRE; + +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; /** @@ -52,18 +57,18 @@ import org.xml.sax.SAXException; * */ public class ScopeManager { - private static final Map SCOPES = new LinkedHashMap(); + private static final Map SCOPES = new LinkedHashMap(); private static String confFile = null; private static final String LOG_PREFIX = "[SCOPE-MGR]"; - public static GCUBEScope getScope(final String scope) throws Exception { + public static ScopeBean getScope(final String scope) throws Exception { synchronized (SCOPES) { if (getAvailableScopes().containsKey(scope)) { return getAvailableScopes().get(scope); } } ServerConsole.warn(LOG_PREFIX, "Using DEFAULT scope manager"); - return GCUBEScope.getScope(scope); + return new ScopeBean(scope); } public static void setScopeConfigFile(final String file) { @@ -74,7 +79,7 @@ public class ScopeManager { * Refreshes the list of scopes and associated maps. */ - public static Map getAvailableScopes() + public static Map getAvailableScopes() throws Exception { if (SCOPES.size() == 0) { update(); @@ -100,25 +105,24 @@ public class ScopeManager { String voString = voDetails.item(5).getFirstChild().getNodeValue(); String fileName = voDetails.item(3).getFirstChild().getNodeValue(); // String voName = voDetails.item(1).getFirstChild().getNodeValue(); - GCUBEScope vo = GCUBEScope.getScope(voString); + ScopeBean vo = new ScopeBean(voString); try { - vo.setServiceMap(loadServiceMap((VO) vo, fileName)); + //vo.setServiceMap(loadServiceMap((VO) vo, fileName)); SCOPES.put(vo.toString(), vo); - + ServerConsole.info(LOG_PREFIX, " Scopes in VO " + vo.toString()); - + try { - for (VRE vre : getVREFromVO((VO) vo)) { + for (String vre : getVREFromVO(vo)) { // This operation overrides the vo map - vre.getEnclosingScope().setServiceMap(vo.getServiceMap()); - SCOPES.put(vre.toString(), vre); + SCOPES.put(vre.toString(), new ScopeBean(vo.toString()+"/"+vre)); } - } catch (ISException e) { + } catch (Exception e) { ServerConsole.error(LOG_PREFIX, "Exception raised while loading VREs for VO : " + vo, e); } } - catch (FileNotFoundException e) { + catch (Exception e) { ServerConsole.warn(LOG_PREFIX, "skipping... map not found for VO : " + vo, e); } @@ -127,36 +131,23 @@ public class ScopeManager { ServerConsole.info(LOG_PREFIX, "*** found scopes : " + SCOPES.keySet()); } - protected static List getVREFromVO(final VO vo) - throws Exception { - ServerConsole.info(LOG_PREFIX, "*******************\n\n********************\nStarting Retrieving VREs for VO : " + vo); - List toReturn = new ArrayList(); + protected static List getVREFromVO(final ScopeBean vo) throws Exception { + ServerConsole.info(LOG_PREFIX, "Starting Retrieving VREs for VO : " + vo); + List toReturn = new ArrayList(); - ISClient client = GHNContext.getImplementation(ISClient.class); + ScopeProvider.instance.set(vo.toString()); + SimpleQuery query = queryFor(GenericResource.class); + query.addCondition("$resource/Profile/SecondaryType/text() eq 'VRE'"); - // FIXME query to get VREs - try { - GCUBEGenericResourceQuery query = client.getQuery(GCUBEGenericResourceQuery.class); - query.addAtomicConditions(new AtomicCondition("/Profile/SecondaryType", "VRE")); - //query.addGenericCondition("not($result/Scopes/Scope/string() eq '" + vo.toString() + "')"); - System.out.println( "************** \n\n\n *****************\nready to query : " + query.getExpression()); + DiscoveryClient client = clientFor(GenericResource.class); - for (GCUBEGenericResource resource : client.execute(query, vo)) { - ServerConsole.info(LOG_PREFIX, "Found: " + resource.getName()); - for (String vreName : resource.getScopes().keySet()) { - GCUBEScope vre = resource.getScopes().get(vreName); - if (vre.getType().equals(GCUBEScope.Type.VRE)) { - toReturn.add((VRE) vre); - } - } + List gRes = client.submit(query); - } - } catch (Exception e) { - ServerConsole.error(LOG_PREFIX, e); + for (GenericResource res : gRes) { + ServerConsole.info(LOG_PREFIX, "Found: " + res.profile().name()); + toReturn.add(res.profile().name()); } - return toReturn; - } /** @@ -167,7 +158,7 @@ public class ScopeManager { * @return * @throws Exception */ - public static String getMapXML(final GCUBEScope searchvo) throws Exception { + public static String getMapXML(final ScopeBean searchvo) throws Exception { if (confFile == null) { throw new NullPointerException("the scope file has not been defined"); } @@ -180,7 +171,7 @@ public class ScopeManager { String voString = voDetails.item(5).getFirstChild().getNodeValue(); String fileName = voDetails.item(3).getFirstChild().getNodeValue(); // String voName = voDetails.item(1).getFirstChild().getNodeValue(); - GCUBEScope vo = GCUBEScope.getScope(voString); + ScopeBean vo = new ScopeBean(voString); if (vo.equals(searchvo)) { return fileToString(System.getenv("GLOBUS_LOCATION") + File.separator + "config" + File.separator + fileName); @@ -190,13 +181,13 @@ public class ScopeManager { return null; } - private static ServiceMap loadServiceMap(final VO vo, final String fileName) throws Exception { - ServiceMap map = new ServiceMap(); - String filePath = System.getenv("GLOBUS_LOCATION") + File.separator + "config" + File.separator + fileName; - ServerConsole.info(LOG_PREFIX, "--- Loading " + vo.getName() + " from: " + filePath); - map.load(new FileReader(filePath)); - return map; - } + // private static ServiceMap loadServiceMap(final VO vo, final String fileName) throws Exception { + // ServiceMap map = new ServiceMap(); + // String filePath = System.getenv("GLOBUS_LOCATION") + File.separator + "config" + File.separator + fileName; + // ServerConsole.info(LOG_PREFIX, "--- Loading " + vo.getName() + " from: " + filePath); + // map.load(new FileReader(filePath)); + // return map; + // } public static String fileToString(final String path) throws IOException { BufferedReader filebuf = null; diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/tests/GenericTest.java b/src/main/java/org/gcube/resourcemanagement/support/server/tests/GenericTest.java index 7974db6..2b33f53 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/server/tests/GenericTest.java +++ b/src/main/java/org/gcube/resourcemanagement/support/server/tests/GenericTest.java @@ -22,30 +22,31 @@ package org.gcube.resourcemanagement.support.server.tests; -import static org.gcube.resources.discovery.icclient.ICFactory.client; - import java.io.File; +import java.io.StringReader; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; import java.util.List; -import org.gcube.common.core.scope.GCUBEScope; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + import org.gcube.common.resources.gcore.HostingNode; +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.client.utils.StatusHandler; import org.gcube.resourcemanagement.support.server.gcube.CacheManager; import org.gcube.resourcemanagement.support.server.gcube.ISClientRequester; -import org.gcube.resourcemanagement.support.server.gcube.queries.QueryLoader; -import org.gcube.resourcemanagement.support.server.gcube.queries.QueryLocation; import org.gcube.resourcemanagement.support.server.managers.resources.GHNManager; import org.gcube.resourcemanagement.support.server.managers.resources.GenericResourceManager; +import org.gcube.resourcemanagement.support.server.managers.resources.ManagementUtils; import org.gcube.resourcemanagement.support.server.managers.scope.ScopeManager; +import org.gcube.resourcemanagement.support.server.types.AllowedResourceTypes; import org.gcube.resourcemanagement.support.server.utils.ServerConsole; import org.gcube.resourcemanagement.support.shared.types.datamodel.ResourceDescriptor; -import org.gcube.resources.discovery.client.api.DiscoveryClient; -import org.gcube.resources.discovery.client.queries.api.Query; -import org.gcube.resources.discovery.client.queries.impl.QueryBox; +import org.w3c.dom.Node; +import org.xml.sax.InputSource; /** * @author Daniele Strollo (ISTI-CNR) @@ -63,9 +64,9 @@ public class GenericTest { resID = GenericResourceManager.create( null, new ScopeBean("/gcube/devsec"), - "RMP Test", + "RMP Test " + new Date(), "RMP Test Description", - "Hello", + "Hello", "test"); ServerConsole.trace(null, "Generic Resource Created with ID: " + resID); } catch (Exception e) { @@ -79,10 +80,12 @@ public class GenericTest { public static void testScopeCopy(final String resID, final String fromScope, final String toScope) { System.out.println("\n\n\n******************** TEST SCOPE COPY ***************"); try { - GenericResourceManager res = new GenericResourceManager(resID); - ServerConsole.trace(null, - res.addToExistingScope(new ScopeBean(fromScope), new ScopeBean(toScope)) - ); +// GenericResourceManager res = new GenericResourceManager(resID); +// ServerConsole.trace(null, +// res.addToExistingScope(new ScopeBean(fromScope), new ScopeBean(toScope)) +// ); + String[] ids = {resID}; + ManagementUtils.addToExistingScope(AllowedResourceTypes.GenericResource, ids, new ScopeBean(fromScope), new ScopeBean(toScope)); } catch (Exception e) { ServerConsole.error(LOG_PREFIX, e); } finally { @@ -161,9 +164,12 @@ public class GenericTest { } } - List descs = ISClientRequester.getResourceModels(scope, "GenericResource", null, null); - for (ResourceDescriptor resourceDescriptor : descs) { - System.out.println(resourceDescriptor); + List descs = ISClientRequester.getResourcesByType(cm, scope, "GenericResource", "VRE"); + for (String resourceDescriptor : descs) { + DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + Node node = docBuilder.parse(new InputSource(new StringReader(resourceDescriptor))).getDocumentElement(); + XPathHelper helper = new XPathHelper(node); + System.out.println(helper.evaluate("/Resource/Name/text()").get(0)); } } @@ -174,21 +180,21 @@ public class GenericTest { ScopeProvider.instance.set("/gcube/devsec"); - //testTree( new ScopeBean("/gcube")); + testTree( new ScopeBean("/gcube/devsec")); // boolean deepTest = true; // // // testGHN(); // if (deepTest) { - String resID = testCreation(); - testScopeCopy(resID, "/gcube/devsec", "/gcube/devsec/devVRE"); +// String resID = testCreation(); +// testScopeCopy(resID, "/gcube/devsec", "/gcube/devsec/devVRE"); ////// // System.out.println("\n\nWaiting for resource refresh 20secs.\n\n\n"); // Thread.sleep(20000); // // // //testResourceEdit(resID, new ScopeBean("/gcube/devsec")); -// //testDelete(resID, new ScopeBean("/gcube/devsec")); + //testDelete(resID, new ScopeBean("/gcube/devsec")); // // testRemoveFromScope(resID, new ScopeBean("/gcube/devsec/devVRE")); // } else { diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/utils/ServerConsole.java b/src/main/java/org/gcube/resourcemanagement/support/server/utils/ServerConsole.java index 4b4e1b6..dddc05a 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/server/utils/ServerConsole.java +++ b/src/main/java/org/gcube/resourcemanagement/support/server/utils/ServerConsole.java @@ -18,13 +18,17 @@ package org.gcube.resourcemanagement.support.server.utils; import org.gcube.common.core.utils.logging.GCUBEClientLog; import org.gcube.resourcemanagement.support.server.managers.resources.AbstractResourceManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author Daniele Strollo (ISTI-CNR) * */ public class ServerConsole { + //private static final Logger LOGGER = LoggerFactory.getLogger(AbstractResourceManager.class); private static final GCUBEClientLog LOGGER = new GCUBEClientLog(AbstractResourceManager.class); + private static final String LOG_PREFIX = "*** [RMP] "; public static void error(final String prefix, final String msg) { @@ -48,13 +52,16 @@ public class ServerConsole { public static void trace(final String prefix, final String msg) { LOGGER.trace(LOG_PREFIX + ((prefix != null) ? prefix + " " : "") + msg); } + public static void trace(final String msg) { + LOGGER.trace(msg); + } + public static void debug(final String msg) { + LOGGER.debug(msg); + } + public static void warn(final String msg) { + LOGGER.warn(msg); + } public static void debug(final String prefix, final String msg) { LOGGER.debug(LOG_PREFIX + ((prefix != null) ? prefix + " " : "") + msg); - } - public static void fatal(final String prefix, final String msg) { - LOGGER.fatal(LOG_PREFIX + ((prefix != null) ? prefix + " " : "") + msg); - } - public static void fatal(final String prefix, final String msg, final Throwable exc) { - LOGGER.fatal(LOG_PREFIX + ((prefix != null) ? prefix + " " : "") + msg, exc); - } + } } diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/utils/persistence/TestPersistence.java b/src/main/java/org/gcube/resourcemanagement/support/server/utils/persistence/TestPersistence.java index 8aefa43..3d00339 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/server/utils/persistence/TestPersistence.java +++ b/src/main/java/org/gcube/resourcemanagement/support/server/utils/persistence/TestPersistence.java @@ -2,7 +2,7 @@ package org.gcube.resourcemanagement.support.server.utils.persistence; import java.io.File; -import org.gcube.common.core.scope.GCUBEScope; +import org.gcube.common.scope.impl.ScopeBean; import org.gcube.resourcemanagement.support.server.managers.scope.ScopeManager; import org.gcube.resourcemanagement.support.server.utils.ServerConsole; @@ -12,12 +12,12 @@ public class TestPersistence { * @param args */ public static void main(final String[] args) { - PersistentItem persistentScopes = new PersistentItem("data.xml", 10000) { + PersistentItem persistentScopes = new PersistentItem("data.xml", 10000) { // Builds the data to persist private void refreshData() { try { - GCUBEScope[] toStore = - ScopeManager.getAvailableScopes().values().toArray(new GCUBEScope[]{}); + ScopeBean[] toStore = + ScopeManager.getAvailableScopes().values().toArray(new ScopeBean[]{}); this.setData(toStore); } catch (Exception e) { ServerConsole.error(LOG_PREFIX, e); @@ -32,7 +32,7 @@ public class TestPersistence { public void onRefresh() { this.refreshData(); - GCUBEScope[] scopes = this.getData(); + ScopeBean[] scopes = this.getData(); System.out.println(scopes); } public void onDestroy() { diff --git a/src/main/java/org/gcube/resourcemanagement/support/shared/types/datamodel/ResourceDetailModel.java b/src/main/java/org/gcube/resourcemanagement/support/shared/types/datamodel/ResourceDetailModel.java index 5d0d7aa..6aad909 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/shared/types/datamodel/ResourceDetailModel.java +++ b/src/main/java/org/gcube/resourcemanagement/support/shared/types/datamodel/ResourceDetailModel.java @@ -128,7 +128,12 @@ public class ResourceDetailModel { @Override public String render(BaseModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore store, Grid grid) { - int val = Integer.parseInt((String)model.get(property)); + int val = 0; + try { + val = Integer.parseInt((String)model.get(property)); + } catch (NumberFormatException e) { + val = 0; + } String style = val < 1000000 ? "red" : "green"; String toDisplay = number.format(val); if (toDisplay.length() > 4)