added ISClientRequester from main Project

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/admin/rmp-common-library@65427 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2012-12-28 19:45:01 +00:00
parent 6ca4dc6393
commit bea355d633
16 changed files with 2694 additions and 1 deletions

View File

@ -35,6 +35,12 @@
<!-- "provided" so that we don't deploy --> <!-- "provided" so that we don't deploy -->
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.sencha.gxt</groupId>
<artifactId>gxt</artifactId>
<version>2.2.5</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>

View File

@ -0,0 +1,79 @@
/****************************************************************************
* This software is part of the gCube Project.
* Site: http://www.gcube-system.org/
****************************************************************************
* The gCube/gCore software is licensed as Free Open Source software
* conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
* The software and documentation is provided by its authors/distributors
* "as is" and no expressed or
* implied warranty is given for its use, quality or fitness for a
* particular case.
****************************************************************************
* Filename: ResourceTypeDecorator.java
****************************************************************************
* @author <a href="mailto:daniele.strollo@isti.cnr.it">Daniele Strollo</a>
***************************************************************************/
package org.gcube.resourcemanagement.support.client.views;
/**
* @author Daniele Strollo (ISTI-CNR)
*
*/
public enum ResourceTypeDecorator {
/****************************************
* RESOURCES IN THE TREE
****************************************/
GHN("gCube Hosting Node", "ghn-icon"),
RunningInstance("Running Instances", "runninginstance-icon"),
Service("Software", "service-icon"),
VIEW("View", "metadatacollection-icon"),
GenericResource("Generic Resources", "genericresource-icon"),
Collection("Collection", "collection-icon"),
WSResource("WSResource", "wsresources-icon"),
Empty("Empty Tree", "empty-icon"),
RuntimeResource("Runtime Resources", "runtimeresource-icon"),
/****************************************
* Other components
****************************************/
// For deploying services - similar to the software but with an
// extension to handle checkbox for install
InstallableSoftware("InstallableSoftware", "empty-icon"),
// In the taskbar for handlig the refresh of deployment reports
DeployReport("Deploy Report", "report-big-icon"),
AddScopeReport("Add Scope Report", "report-big-icon"),
/****************************************
* Related resources
****************************************/
GHNRelated("Running Instances", "runninginstance-icon"),
ServiceRelated("Running Instances", "runninginstance-icon"),
RunningInstanceRelated("Running Instances", "runninginstance-icon"),
/****************************************
* Models for SWEEPER
***************************************/
Sweeper_GHN("gCube Hosting Node", "ghn-icon"),
Sweeper_RI("Running Instance", "runninginstance-icon");
private String label = null;
private String icon = null;
ResourceTypeDecorator(
final String label,
final String icon) {
this.label = label;
this.icon = icon;
}
public String getLabel() {
return this.label;
}
public String getIcon() {
return this.icon;
}
}

View File

@ -0,0 +1,18 @@
package org.gcube.resourcemanagement.support.server.gcube;
public class CacheManager {
private boolean useCache = false;
public CacheManager() {
// for serialization only
}
public boolean isUsingCache() {
return this.useCache;
}
public void setUseCache(final boolean useCache) {
this.useCache = useCache;
}
}

View File

@ -0,0 +1,828 @@
/****************************************************************************
* This software is part of the gCube Project.
* Site: http://www.gcube-system.org/
****************************************************************************
* The gCube/gCore software is licensed as Free Open Source software
* conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
* The software and documentation is provided by its authors/distributors
* "as is" and no expressed or
* implied warranty is given for its use, quality or fitness for a
* particular case.
****************************************************************************
* Filename: ISClientRequester.java
****************************************************************************
* @author <a href="mailto:daniele.strollo@isti.cnr.it">Daniele Strollo</a>
***************************************************************************/
package org.gcube.resourcemanagement.support.server.gcube;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
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.QueryParameter;
import org.gcube.common.core.informationsystem.client.XMLResult;
import org.gcube.common.core.informationsystem.client.XMLResult.ISResultEvaluationException;
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.resourcemanagement.support.client.views.ResourceTypeDecorator;
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.scope.ScopeManager;
import org.gcube.resourcemanagement.support.server.utils.ServerConsole;
import org.gcube.resourcemanagement.support.shared.plugins.GenericResourcePlugin;
import org.gcube.resourcemanagement.support.shared.plugins.TMPluginFormField;
import org.gcube.resourcemanagement.support.shared.types.Tuple;
import org.gcube.resourcemanagement.support.shared.types.datamodel.CompleteResourceProfile;
import org.gcube.resourcemanagement.support.shared.types.datamodel.ResourceDescriptor;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* All the requests to the IS are implemented here.
* @author Massimiliano Assante (ISTI-CNR)
* @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]";
public static void emptyCache() {
CACHE.empty();
}
private static final List<String> getResourceTypes(
final CacheManager status,
final GCUBEScope queryScope)
throws Exception {
List<XMLResult> results = null;
ISClient client = GHNContext.getImplementation(ISClient.class);
GCUBEGenericQuery isQuery = null;
isQuery = client.getQuery(GCUBEGenericQuery.class);
isQuery.setExpression(QueryLoader.getQuery(QueryLocation.GET_TREE_TYPES));
// Handles the cache
ISQueryCacheKeyT cacheKey = new ISQueryCacheKeyT(queryScope.toString(),
isQuery.getExpression(),
"getResourcesTypes");
if (status.isUsingCache() && CACHE.contains(cacheKey) && CACHE.get(cacheKey) != null) {
results = CACHE.get(cacheKey);
} else {
try {
results = client.execute(isQuery, queryScope);
if (status.isUsingCache()) {
CACHE.insert(cacheKey, results);
}
} catch (Exception e) {
throw new Exception(e.getMessage());
}
}
if (results == null || results.size() == 0) {
return null;
}
String type = null;
List<String> types = new Vector<String>();
try {
for (XMLResult elem : results) {
type = elem.evaluate("/type/text()").get(0);
if (type != null && type.trim().length() > 0) {
types.add(type.trim());
}
}
//**** CHANGES TO KNOW IF VIEWS AND GCUBECollection are present
types.remove("MetadataCollection");
isQuery.setExpression("declare namespace vm = 'http://gcube-system.org/namespaces/contentmanagement/viewmanager';"+
"declare namespace gc = 'http://gcube-system.org/namespaces/common/core/porttypes/GCUBEProvider';"+
"declare namespace is = 'http://gcube-system.org/namespaces/informationsystem/registry';" +
"for $data in collection(\"/db/Properties\")//Document, $view in $data/Data where $view/gc:ServiceName/string() eq \"ViewManager\" " +
" and $view/gc:ServiceClass/string() eq \"ContentManagement\" and count($view//vm:View)>0 return <a>true</a>");
if (client.execute(isQuery, queryScope).size() > 0)
types.add("VIEW");
isQuery.setExpression("declare namespace gc = 'http://gcube-system.org/namespaces/common/core/porttypes/GCUBEProvider';"+
"declare namespace is = 'http://gcube-system.org/namespaces/informationsystem/registry';" +
"for $data in collection(\"/db/Profiles/GenericResource\")//Document/Data/is:Profile/Resource where $data/Profile/SecondaryType eq \"GCUBECollection\" " +
" return <a>true</a>");
if (client.execute(isQuery, queryScope).size() > 0)
types.add("Collection");
} catch (ISResultEvaluationException e) {
_log.error("error during getResourcesTypes");
} catch (IndexOutOfBoundsException e) {
// ignore exception
}
return types;
}
private static final List<String> getResourceSubTypes(
final CacheManager status,
final GCUBEScope queryScope,
final String resourceType)
throws Exception {
List<String> subtypes = new Vector<String>();
if (resourceType.equals("Collection")) {
subtypes.add("System");
subtypes.add("User");
return subtypes;
}
if (resourceType.equals("VIEW")) {
subtypes.add("Not supported");
return subtypes;
}
List<XMLResult> results = null;
ISClient client = GHNContext.getImplementation(ISClient.class);
GCUBEGenericQuery isQuery = null;
isQuery = client.getQuery(GCUBEGenericQuery.class);
isQuery.setExpression(QueryLoader.getQuery(QueryLocation.GET_TREE_SUBTYPES));
isQuery.addParameters(new QueryParameter("RES_TYPE", resourceType));
// Handles the cache
ISQueryCacheKeyT cacheKey = new ISQueryCacheKeyT(queryScope.toString(),
isQuery.getExpression(),
"getResourcesSubTypes");
if (status.isUsingCache() && CACHE.contains(cacheKey) && CACHE.get(cacheKey) != null) {
results = CACHE.get(cacheKey);
} else {
try {
results = client.execute(isQuery, queryScope);
if (status.isUsingCache()) {
CACHE.insert(cacheKey, results);
}
} catch (Exception e) {
throw new Exception(e.getMessage());
}
}
if (results == null || results.size() == 0) {
return null;
}
String subtype = null;
for (XMLResult elem : results) {
try {
subtype = elem.evaluate("/subtype/text()").get(0);
if (subtype != null && subtype.trim().length() > 0) {
subtypes.add(subtype.trim());
}
} catch (ISResultEvaluationException e) {
_log.error("error during getResourcesTypes");
} catch (IndexOutOfBoundsException e) {
// ignore exception
}
}
return subtypes;
}
/**
* For all the resource in the scope retrieves their
* (type, subtype) values.
* The result is a list of couples of that form.
* @return a list of string tuples (type, subtype)
* @throws Exception
*/
public static final Map<String, List<String>> getResourcesTree( //qui si perde
final CacheManager status,
final GCUBEScope queryScope)
throws Exception {
Map<String, List<String>> retval = new HashMap<String, List<String>>();
// Loads the Resources
List<String> types = getResourceTypes(status, queryScope);
List<String> subtypes = null;
for (String type : types) {
try {
subtypes = getResourceSubTypes(status, queryScope, type);
if (subtypes != null && subtypes.size() > 0) {
retval.put(type, subtypes);
}
} catch (Exception e) {
ServerConsole.error(LOG_PREFIX, e);
}
}
// Loads the WSResources
// This types is statically handled since it is a particular
// case of resource.
List<XMLResult> results = null;
ISClient client = GHNContext.getImplementation(ISClient.class);
GCUBEGenericQuery isQuery = null;
isQuery = client.getQuery(GCUBEGenericQuery.class);
isQuery.setExpression(QueryLoader.getQuery(QueryLocation.GET_WSRES_TYPES));
results = client.execute(isQuery, queryScope);
if (results == null || results.size() == 0) {
return retval;
}
subtypes = new Vector<String>();
for (XMLResult elem : results) {
subtypes.add(elem.toString());
}
retval.put("WSResource", subtypes);
return retval;
}
public static final List<String> getRelatedResources(
final CacheManager status,
final String type,
final String id,
final GCUBEScope queryScope)
throws Exception {
ISClient client = GHNContext.getImplementation(ISClient.class);
GCUBEGenericQuery isQuery = null;
isQuery = client.getQuery(GCUBEGenericQuery.class);
QueryLocation queryPath = null;
try {
queryPath = QueryLocation.valueOf("LIST_RELATED_" + type);
} catch (Exception e) {
ServerConsole.error(LOG_PREFIX, "Getting the resource query.", e);
throw new Exception(e.getMessage());
}
isQuery.setExpression(QueryLoader.getQuery(queryPath));
isQuery.addParameters(new QueryParameter("RES_ID", id.trim()));
ISQueryCacheKeyT cacheKey = new ISQueryCacheKeyT(queryScope.toString(),
isQuery.getExpression(),
"getResourceRelated");
List<XMLResult> results = null;
// Handle cache
if (status.isUsingCache() && CACHE.contains(cacheKey) && CACHE.get(cacheKey) != null) {
results = CACHE.get(cacheKey);
} else {
results = client.execute(isQuery, queryScope);
if (status.isUsingCache()) {
CACHE.insert(cacheKey, results);
}
}
if (results == null || results.size() == 0) {
return null;
}
// ENDOF Handle cache
List<String> retval = new Vector<String>();
for (XMLResult elem : results) {
// Removes the resources with no ID or empty
try {
String toAdd = elem.toString();
if (toAdd != null) {
toAdd = toAdd.replace("<Resources>", "");
toAdd = toAdd.replace("</Resources>", "");
}
retval.add(toAdd);
} catch (Exception e) {
ServerConsole.debug(LOG_PREFIX, "[getResourcesRelated] found and invalid resource");
}
}
ServerConsole.trace(LOG_PREFIX, "Retrieved (" + retval.size() + ") ServiceDetails for type: " + type);
return retval;
}
public static final List<String> getResourcesByType(
final CacheManager status,
final GCUBEScope queryScope,
final String type,
final String subType)
throws Exception {
ISClient client = GHNContext.getImplementation(ISClient.class);
GCUBEGenericQuery isQuery = null;
isQuery = client.getQuery(GCUBEGenericQuery.class);
QueryLocation queryPath = null;
try {
if (type.equals(ResourceTypeDecorator.WSResource.name())) {
queryPath = QueryLocation.GET_WSRES_DETAILS_BYSUBTYPE;
} else {
queryPath = QueryLocation.valueOf("LIST_" + type);
}
} catch (Exception e) {
ServerConsole.error(LOG_PREFIX, "Getting the resource query.", e);
throw new Exception(e.getMessage());
}
isQuery.setExpression(QueryLoader.getQuery(queryPath));
if (type.equals(ResourceTypeDecorator.WSResource.name())) {
if (subType != null && subType.length() > 0) {
isQuery.addParameters(new QueryParameter("RES_SUBTYPE",
subType.trim()));
}
} else {
if (subType != null && subType.length() > 0) {
if (subType.equalsIgnoreCase("User") || subType.equalsIgnoreCase("System")) {
isQuery.addParameters(new QueryParameter("RES_SUBTYPE", " and $profiles/Profile/Body/CollectionInfo/user/text() = \"" + ((subType.trim().equals("User")) ? "true" : "false") + "\""));
}
else
isQuery.addParameters(new QueryParameter("RES_SUBTYPE", "where $subtype = \"" + subType.trim() + "\""));
}
}
ISQueryCacheKeyT cacheKey = new ISQueryCacheKeyT(queryScope.toString(),
isQuery.getExpression(),
"getResourcesTypes");
List<XMLResult> results = null;
ServerConsole.debug(LOG_PREFIX, "XQUERYY:\n"+isQuery.getExpression());
if (status.isUsingCache() && CACHE.contains(cacheKey) && CACHE.get(cacheKey) != null) {
results = CACHE.get(cacheKey);
} else {
results = client.execute(isQuery, queryScope);
if (status.isUsingCache()) {
CACHE.insert(cacheKey, results);
}
}
if (results == null || results.size() == 0) {
return null;
}
List<String> retval = new Vector<String>();
for (XMLResult elem : results) {
// Removes the resources with no ID or empty
try {
if (elem.evaluate("//ID").get(0) != null && elem.evaluate("//ID").get(0).trim().length() > 0) {
retval.add(elem.toString());
//ServerConsole.debug("", elem.toString());// Print the result
} else {
ServerConsole.debug(LOG_PREFIX, "*** Found an invalid element with no ID");
}
} catch (Exception e) {
ServerConsole.debug(LOG_PREFIX, "[getResourcesByType] found a resource with empty ID");
}
}
ServerConsole.trace(LOG_PREFIX, "Retrieved (" + retval.size() + ") ServiceDetails for type: " + type);
return retval;
}
public static final List<ResourceDescriptor> getResourceModels(
final GCUBEScope queryScope,
final String type,
final String subType,
final List<Tuple<String>> additionalMaps)
throws Exception {
ISClient client = GHNContext.getImplementation(ISClient.class);
GCUBEGenericQuery isQuery = null;
isQuery = client.getQuery(GCUBEGenericQuery.class);
if (subType != null && subType.trim().length() > 0) {
isQuery.setExpression(QueryLoader.getQuery(QueryLocation.GET_RES_DETAILS_BYSUBTYPE));
isQuery.addParameters(
new QueryParameter("RES_TYPE", type)
);
isQuery.addParameters(
new QueryParameter("RES_SUBTYPE", subType)
);
} else {
isQuery.setExpression(QueryLoader.getQuery(QueryLocation.GET_RES_DETAILS_BYTYPE));
isQuery.addParameters(
new QueryParameter("RES_TYPE", type)
);
}
List<XMLResult> results = client.execute(isQuery, queryScope);
List<ResourceDescriptor> retval = new Vector<ResourceDescriptor>();
ResourceDescriptor toAdd = null;
for (XMLResult elem : results) {
// Removes the resources with no ID or empty
try {
if (elem.evaluate("//ID").get(0) != null) {
toAdd = new ResourceDescriptor(
elem.evaluate("//Type/text()").get(0),
elem.evaluate("//SubType/text()").get(0),
elem.evaluate("//ID/text()").get(0),
elem.evaluate("//Name/text()").get(0));
// Additional mappings can be defined by the requester.
// e.g. new Tuple("description", "//Profile/Description/text()");
if (additionalMaps != null && additionalMaps.size() > 0) {
for (Tuple<String> map : additionalMaps) {
try {
toAdd.addProperty(map.get(0),
elem.evaluate(map.get(1)).get(0));
} catch (final Exception e) {
toAdd.addProperty(map.get(0),
"");
}
}
}
retval.add(toAdd);
}
} catch (Exception e) {
ServerConsole.debug(LOG_PREFIX, "[getResourcesByType] found a resource with empty ID");
}
}
ServerConsole.trace(LOG_PREFIX, "Retrieved (" + retval.size() + ") ServiceDetails for type: " + type);
return retval;
}
public static final List<String> getWSResources(
final GCUBEScope queryScope)
throws Exception {
ISClient client = GHNContext.getImplementation(ISClient.class);
GCUBEGenericQuery isQuery = null;
isQuery = client.getQuery(GCUBEGenericQuery.class);
isQuery.setExpression(QueryLoader.getQuery(QueryLocation.GET_WSRES_DETAILS_BYTYPE));
List<XMLResult> results = client.execute(isQuery, queryScope);
List<String> retval = new Vector<String>();
for (XMLResult elem : results) {
retval.add(elem.toString());
}
ServerConsole.trace(LOG_PREFIX, "Retrieved (" + retval.size() + ") ServiceDetails for type: " + ResourceTypeDecorator.WSResource.name());
return retval;
}
public static final CompleteResourceProfile getResourceByID(
final String xmlFilePath,
final GCUBEScope queryScope,
final String resType,
final String resID)
throws Exception {
ISClient client = GHNContext.getImplementation(ISClient.class);
GCUBEGenericQuery isQuery = null;
isQuery = client.getQuery(GCUBEGenericQuery.class);
if (resType == null) {
isQuery.setExpression(QueryLoader.getQuery(QueryLocation.GET_RESOURCE_BYID));
isQuery.addParameters(
new QueryParameter("RES_ID", resID)
);
} else if (resType.equalsIgnoreCase(ResourceTypeDecorator.WSResource.name())) {
isQuery.setExpression(QueryLoader.getQuery(QueryLocation.GET_WSRESOURCE_BYID));
isQuery.addParameters(
new QueryParameter("RES_ID", resID)
);
} else {
isQuery.setExpression(QueryLoader.getQuery(QueryLocation.GET_RESOURCE_BYID));
isQuery.addParameters(
new QueryParameter("RES_ID", resID),
new QueryParameter("RES_TYPE", resType)
);
}
List<XMLResult> results = client.execute(isQuery, queryScope);
List<String> retval = new Vector<String>();
ServerConsole.trace(LOG_PREFIX, "Retrieved (" + retval.size() + ") Resource for ID: " + resID);
if (results != null && results.size() > 0) {
String type = null;
if (resType == null) {
try {
type = results.get(0).evaluate("/Resource/Type/text()").get(0);
} catch (Exception e) {
ServerConsole.error(LOG_PREFIX, e);
}
} else {
type = resType;
}
String xmlRepresentation = results.get(0).toString();
String htmlRepresentation = XML2HTML(xmlRepresentation, xmlFilePath);
return new CompleteResourceProfile(resID, ResourceTypeDecorator.valueOf(type), getResourceName(type, resID, results.get(0)), xmlRepresentation, htmlRepresentation);
}
return null;
}
public static Map<String, GenericResourcePlugin> 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<XMLResult> results = client.execute(isQuery, scope);
Map<String, GenericResourcePlugin> retval = new HashMap<String, GenericResourcePlugin>();
gonext: for (XMLResult plugin : results) {
System.out.println(plugin.toString());
try {
for (String entry : plugin.evaluate("/CMPlugins/Plugin/Entry")) {
Document doc = ScopeManager.getDocumentGivenXML(entry);
String name = doc.getElementsByTagName("name").item(0).getFirstChild().getNodeValue();
ServerConsole.info(LOG_PREFIX, "[LOAD-PLUGIN] found: *** name " + name);
String pluginType = doc.getElementsByTagName("Type").item(0).getFirstChild().getNodeValue();
ServerConsole.info(LOG_PREFIX, "[LOAD-PLUGIN] found: *** type " + pluginType);
String description = doc.getElementsByTagName("description").item(0).getFirstChild().getNodeValue();
ServerConsole.info(LOG_PREFIX, "[LOAD-PLUGIN] found: *** description " + description);
String namespace = null;
try {
namespace = doc.getElementsByTagName("namespace").item(0).getFirstChild().getNodeValue();
ServerConsole.info(LOG_PREFIX, "[LOAD-PLUGIN] found: *** namespace " + namespace);
} catch (Exception e) {
ServerConsole.warn(LOG_PREFIX, "[LOAD-PLUGIN] namespace not found");
}
GenericResourcePlugin toAdd = new GenericResourcePlugin(name, namespace, description, pluginType);
NodeList params = doc.getElementsByTagName("param");
for (int i = 0; i < params.getLength(); i++) {
NodeList paramTree = params.item(i).getChildNodes();
String paramName = null;
String paramDefinition = null;
for (int j = 0; j < paramTree.getLength(); j++) {
if (paramTree.item(j).getNodeName().equals("param-name")) {
paramName = paramTree.item(j).getFirstChild().getNodeValue();
}
if (paramTree.item(j).getNodeName().equals("param-definition")) {
paramDefinition = paramTree.item(j).getFirstChild().getNodeValue();
}
}
ServerConsole.info(LOG_PREFIX, "[LOAD-PLUGIN] found: param " + paramName);
GenericResourcePlugin.Field paramField = new GenericResourcePlugin.Field(paramName, GenericResourcePlugin.FieldType.string);
if (paramDefinition != null) {
StringTokenizer parser = new StringTokenizer(paramDefinition, ";");
while (parser.hasMoreTokens()) {
try {
String currElem = parser.nextToken();
String key = currElem.substring(0, currElem.indexOf("="));
String value = currElem.substring(currElem.indexOf("=") + 1, currElem.length()).trim();
if (key.equals("type")) {
paramField.setType(GenericResourcePlugin.FieldType.valueOf(value));
}
if (key.equals("opt")) {
paramField.setIsRequired(!Boolean.parseBoolean(value));
}
if (key.equals("label")) {
if (value.startsWith("'")) {
value = value.substring(1, value.length());
}
if (value.endsWith("'")) {
value = value.substring(0, value.length() - 1);
}
paramField.setLabel(value);
}
if (key.equals("default")) {
if (value.startsWith("'")) {
value = value.substring(1, value.length());
}
if (value.endsWith("'")) {
value = value.substring(0, value.length() - 1);
}
paramField.setDefaultValue(value);
}
} catch (Exception e) {
// parsing error - not well formed string
}
}
}
toAdd.addParam(paramField);
}
retval.put(name + "::" + pluginType, toAdd);
}
} catch (RuntimeException e) {
continue gonext;
}
}
return retval;
}
/**
* get the plugins for tree manager
* @param scope
* @return a map containing the plugin name as key and a List of formfield
* @throws Exception
*/
public static HashMap<String, ArrayList<TMPluginFormField>> 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<XMLResult> results = client.execute(isQuery, scope);
HashMap<String, ArrayList<TMPluginFormField>> retval = new HashMap<String, ArrayList<TMPluginFormField>>();
gonext: for (XMLResult plugin : results) {
System.out.println(plugin.toString());
try {
for (String entry : plugin.evaluate("/TMPlugins/Plugin/Entry")) {
Document doc = ScopeManager.getDocumentGivenXML(entry);
String name = doc.getElementsByTagName("name").item(0).getFirstChild().getNodeValue();
ServerConsole.info(LOG_PREFIX, "[LOAD-PLUGIN] found: *** name " + name);
String pluginType = doc.getElementsByTagName("Type").item(0).getFirstChild().getNodeValue();
ServerConsole.info(LOG_PREFIX, "[LOAD-PLUGIN] found: *** type " + pluginType);
String description = doc.getElementsByTagName("description").item(0).getFirstChild().getNodeValue();
ServerConsole.info(LOG_PREFIX, "[LOAD-PLUGIN] found: *** description " + description);
String namespace = null;
try {
namespace = doc.getElementsByTagName("namespace").item(0).getFirstChild().getNodeValue();
ServerConsole.info(LOG_PREFIX, "[LOAD-PLUGIN] found: *** namespace " + namespace);
} catch (Exception e) {
ServerConsole.warn(LOG_PREFIX, "[LOAD-PLUGIN] namespace not found");
}
NodeList params = doc.getElementsByTagName("param");
ArrayList<TMPluginFormField> formFields = new ArrayList<TMPluginFormField>();
for (int i = 0; i < params.getLength(); i++) {
NodeList paramTree = params.item(i).getChildNodes();
String paramName = null;
String xmlToParse = null;
boolean foundSample = false;
for (int j = 0; j < paramTree.getLength(); j++) {
if (paramTree.item(j).getNodeName().equals("param-name")) {
paramName = paramTree.item(j).getFirstChild().getNodeValue();
if (paramName.compareTo("requestSample") == 0) {
foundSample = true;
}
}
if (paramTree.item(j).getNodeName().equals("param-definition") && foundSample) {
xmlToParse = paramTree.item(j).getFirstChild().getNodeValue();
xmlToParse = xmlToParse.replaceAll("&lt;", "<");
xmlToParse = xmlToParse.replaceAll("&gt;", "<");
System.out.println("toParse:" + xmlToParse);
foundSample = false;
formFields = getPluginFormFromXml(xmlToParse);
}
}
}
retval.put(name, formFields);
}
} catch (RuntimeException e) {
continue gonext;
}
}
return retval;
}
/**
* parses the following and return the list to generate the form automatically
*
* sample
* <speciesRequest>
* <name>Parachela collection</name>
* <description>Parachela collection from Itis</description>
* <scientificNames repeatable="true">Parachela</scientificNames>
* <datasources repeatable="true">ITIS</datasources>
* <strictMatch>true</strictMatch>
* <refreshPeriod>5</refreshPeriod>
* <timeUnit>MINUTES</timeUnit>
* </speciesRequest>
*
* @param xmlToParse
* @return the list
*/
private static ArrayList<TMPluginFormField> getPluginFormFromXml(String xmlToParse) {
ArrayList<TMPluginFormField> toReturn = new ArrayList<TMPluginFormField>();
Document doc = ScopeManager.getDocumentGivenXML(xmlToParse);
Node root = doc.getElementsByTagName("speciesRequest").item(0);
NodeList children = root.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
String label = children.item(i).getNodeName();
String defaultValue = children.item(i).getFirstChild().getNodeValue();
boolean repeatable = false;
boolean required = false;
if (children.item(i).hasAttributes()) {
NamedNodeMap attributes = children.item(i).getAttributes();
if (children.item(i).getAttributes().getNamedItem("repeatable") != null)
repeatable = attributes.getNamedItem("repeatable").getNodeValue().equalsIgnoreCase("true");
if (children.item(i).getAttributes().getNamedItem("required") != null)
required = attributes.getNamedItem("required").getNodeValue().equalsIgnoreCase("true");
}
toReturn.add(new TMPluginFormField(label, defaultValue, required, repeatable));
}
return toReturn;
}
/**
* From the ID of a resource retrieves its name. Notice that resource name
* is retrieved according to their type.
* @param type the type of the resource
* @param ID the identifier of the resource
* @param node the XML node from which retrieve the information
* @return
*/
private static String getResourceName(String type, String ID, XMLResult node) {
if (type.equalsIgnoreCase(ResourceTypeDecorator.GHN.name())) {
try {
return node.evaluate("/Resource/Profile/GHNDescription/Name/text()").get(0);
} catch (Exception e) {
return ID;
}
}
if (type.equalsIgnoreCase(ResourceTypeDecorator.Collection.name())) {
try {
return node.evaluate("/Resource/Profile/Name/text()").get(0);
} catch (Exception e) {
return ID;
}
}
if (type.equalsIgnoreCase(ResourceTypeDecorator.Service.name())) {
try {
return node.evaluate("/Resource/Profile/Name/text()").get(0);
} catch (Exception e) {
return ID;
}
}
if (type.equalsIgnoreCase(ResourceTypeDecorator.RunningInstance.name())) {
try {
return node.evaluate("/Resource/Profile/ServiceName/text()").get(0);
} catch (Exception e) {
return ID;
}
}
if (type.equalsIgnoreCase(ResourceTypeDecorator.VIEW.name())) {
try {
return node.evaluate("/Resource/Profile/Name/text()").get(0);
} catch (Exception e) {
return ID;
}
}
if (type.equalsIgnoreCase(ResourceTypeDecorator.RuntimeResource.name())) {
try {
return node.evaluate("/Resource/Profile/Name/text()").get(0);
} catch (Exception e) {
return ID;
}
}
if (type.equalsIgnoreCase(ResourceTypeDecorator.GenericResource.name())) {
try {
return node.evaluate("/Resource/Profile/Name/text()").get(0);
} catch (Exception e) {
return ID;
}
}
if (type.equalsIgnoreCase(ResourceTypeDecorator.WSResource.name())) {
try {
return node.evaluate("/Document/Data/child::*[local-name()='ServiceName']/text()").get(0);
} catch (Exception e) {
return ID;
}
}
return null;
}
public static String XML2HTML(final String xml, final String xslt)
throws Exception {
TransformerFactory tf = TransformerFactory.newInstance();
InputStream stream = new FileInputStream(xslt);
BufferedReader in = new BufferedReader(new InputStreamReader(stream));
StringBuilder retval = new StringBuilder();
String currLine = null;
while ((currLine = in.readLine()) != null) {
// a comment
if (currLine.trim().length() > 0 && currLine.trim().startsWith("#")) {
continue;
}
if (currLine.trim().length() == 0) { continue; }
retval.append(currLine + System.getProperty("line.separator"));
}
in.close();
StreamSource source = new StreamSource(new ByteArrayInputStream(retval.toString().getBytes()));
Templates compiledXSLT = tf.newTemplates(source);
Transformer t = compiledXSLT.newTransformer();
t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "true");
StringWriter w = new StringWriter();
t.transform(new StreamSource(new StringReader(xml)), new StreamResult(w));
return w.toString();
}
}

View File

@ -0,0 +1,93 @@
/****************************************************************************
* This software is part of the gCube Project.
* Site: http://www.gcube-system.org/
****************************************************************************
* The gCube/gCore software is licensed as Free Open Source software
* conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
* The software and documentation is provided by its authors/distributors
* "as is" and no expressed or
* implied warranty is given for its use, quality or fitness for a
* particular case.
****************************************************************************
* Filename: ISQueryCache.java
****************************************************************************
* @author <a href="mailto:daniele.strollo@isti.cnr.it">Daniele Strollo</a>
***************************************************************************/
package org.gcube.resourcemanagement.support.server.gcube;
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;
public ISQueryCacheKeyT(String scope, String queryExpression, String... params) {
if (scope != null && queryExpression != null && params != null && params.length > 0) {
this.queryExpression = queryExpression.trim();
this.keyValue = scope + "*" + queryExpression + "*" + "[";
for (String entry : params) {
keyValue += "(" + entry + ")";
}
this.keyValue += "]";
}
}
public String getQueryExpression() {
return this.queryExpression;
}
@Override
public String toString() {
return this.keyValue;
}
@Override
public boolean equals(Object obj) {
if (this.keyValue == null) {
return false;
}
if (obj instanceof ISQueryCacheKeyT) {
return this.keyValue.equals(((ISQueryCacheKeyT) obj).keyValue);
}
return super.equals(obj);
}
public int hashCode() {
return this.keyValue.hashCode();
}
}
/**
* @author Daniele Strollo (ISTI-CNR)
*
*/
public class ISQueryCache {
Map<ISQueryCacheKeyT, List<XMLResult>> results = new HashMap<ISQueryCacheKeyT, List<XMLResult>>();
public void insert(ISQueryCacheKeyT key, List<XMLResult> elem) {
this.results.put(key, elem);
}
public boolean contains(ISQueryCacheKeyT key) {
if (key == null) {
return false;
}
return this.results.containsKey(key);
}
public List<XMLResult> get(ISQueryCacheKeyT key) {
if (key != null && this.results.containsKey(key)) {
return this.results.get(key);
}
return null;
}
public void empty() {
this.results.clear();
}
}

View File

@ -0,0 +1,44 @@
/****************************************************************************
* This software is part of the gCube Project.
* Site: http://www.gcube-system.org/
****************************************************************************
* The gCube/gCore software is licensed as Free Open Source software
* conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
* The software and documentation is provided by its authors/distributors
* "as is" and no expressed or
* implied warranty is given for its use, quality or fitness for a
* particular case.
****************************************************************************
* Filename: InvalidParameterException.java
****************************************************************************
* @author <a href="mailto:daniele.strollo@isti.cnr.it">Daniele Strollo</a>
***************************************************************************/
package org.gcube.resourcemanagement.support.shared.exceptions;
import com.google.gwt.user.client.rpc.IsSerializable;
/**
* @author Daniele Strollo (ISTI-CNR)
*
*/
public class InvalidParameterException extends Exception implements IsSerializable {
private static final long serialVersionUID = 1L;
public InvalidParameterException() {
super();
}
public InvalidParameterException(String message, Throwable cause) {
super(message, cause);
}
public InvalidParameterException(String message) {
super(message);
}
public InvalidParameterException(Throwable cause) {
super(cause);
}
}

View File

@ -0,0 +1,171 @@
/****************************************************************************
* This software is part of the gCube Project.
* Site: http://www.gcube-system.org/
****************************************************************************
* The gCube/gCore software is licensed as Free Open Source software
* conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
* The software and documentation is provided by its authors/distributors
* "as is" and no expressed or
* implied warranty is given for its use, quality or fitness for a
* particular case.
****************************************************************************
* Filename: GenericResourcePlugin.java
****************************************************************************
* @author <a href="mailto:daniele.strollo@isti.cnr.it">Daniele Strollo</a>
***************************************************************************/
package org.gcube.resourcemanagement.support.shared.plugins;
import java.io.Serializable;
import java.util.List;
import java.util.Vector;
import com.google.gwt.user.client.rpc.IsSerializable;
/**
* @author Daniele Strollo (ISTI-CNR)
*
*/
public class GenericResourcePlugin implements Serializable, IsSerializable {
public enum FieldType implements Serializable, IsSerializable {
string(),
number(),
XML();
}
public static class Field implements Serializable, IsSerializable {
private static final long serialVersionUID = 5921865866801474305L;
private FieldType type = null;
private String name = null;
private boolean required = true;
private String label = null;
private String defaultValue = "";
/**
* @deprecated for serialization only
*/
public Field() {
}
public Field(final String name, final FieldType type) {
this(name, type, true);
}
public Field(final String name, final FieldType type, final boolean required) {
this(name, null, type, required);
}
public Field(final String name, final String label, final FieldType type, final boolean required) {
this.setName(name);
this.setLabel(label);
this.type = type;
this.setIsRequired(required);
}
public final String getDefaultValue() {
return this.defaultValue;
}
public final void setDefaultValue(final String defaultValue) {
if (defaultValue != null && defaultValue.trim().length() > 0) {
this.defaultValue = defaultValue;
}
}
public final void setLabel(final String label) {
if (label != null && label.trim().length() > 0) {
this.label = label.trim();
} else {
this.label = name;
}
}
public final String getLabel() {
if (this.label == null || this.label.trim().length() == 0) {
return this.name;
} else {
return this.label;
}
}
private void setName(final String name) {
if (name != null) {
this.name = name.trim();
}
}
/**
* Corresponds to the tag name in the body
* @return
*/
public final String getName() {
return this.name;
}
public final FieldType getType() {
return this.type;
}
public final void setType(final FieldType type) {
this.type = type;
}
public final boolean isRequired() {
return this.required;
}
public final void setIsRequired(final boolean required) {
this.required = required;
}
}
private static final long serialVersionUID = 6070331744211410508L;
private String name = null;
private String description = null;
private String type = null;
private List<Field> params = new Vector<Field>();
private String namespace = "xmlns:ns4=\"http://gcube-system.org/namespaces/contentmanagement/contentmanager/oaiplugin\"";
/**
* @deprecated for serialization only
*/
public GenericResourcePlugin() {
}
public GenericResourcePlugin(final String name, final String namespace, final String description, final String type) {
super();
this.name = name;
this.description = description;
this.type = type;
if (namespace != null && namespace.trim().length() > 0) {
this.namespace = "xmlns:ns4=\"" + namespace.trim() + "\"";
}
}
public final void addParam(final Field param) {
this.params.add(param);
}
public final String getName() {
return name;
}
public final String getDescription() {
return description;
}
public final String getType() {
return type;
}
public final String getNamespace() {
return namespace;
}
public final List<Field> getParams() {
return params;
}
}

View File

@ -0,0 +1,64 @@
package org.gcube.resourcemanagement.support.shared.plugins;
import java.io.Serializable;
/**
*
* @author Massimiliano Assante, ISTI-CNR
* @version 1.0 Oct 2012
*
*/
@SuppressWarnings("serial")
public class TMPluginFormField implements Serializable {
private String label;
private String defaultValue;
private boolean required;
private boolean repeatable;
public TMPluginFormField() {
super();
}
public TMPluginFormField(String label, String defaultValue,
boolean required, boolean repeatable) {
super();
this.label = label;
this.defaultValue = defaultValue;
this.required = required;
this.repeatable = repeatable;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getDefaultValue() {
return defaultValue;
}
public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}
public boolean isRequired() {
return required;
}
public void setRequired(boolean required) {
this.required = required;
}
public boolean isRepeatable() {
return repeatable;
}
public void setRepeatable(boolean repeatable) {
this.repeatable = repeatable;
}
}

View File

@ -0,0 +1,39 @@
/****************************************************************************
* This software is part of the gCube Project.
* Site: http://www.gcube-system.org/
****************************************************************************
* The gCube/gCore software is licensed as Free Open Source software
* conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
* The software and documentation is provided by its authors/distributors
* "as is" and no expressed or
* implied warranty is given for its use, quality or fitness for a
* particular case.
****************************************************************************
* Filename: RunningMode.java
****************************************************************************
* @author <a href="mailto:daniele.strollo@isti.cnr.it">Daniele Strollo</a>
***************************************************************************/
package org.gcube.resourcemanagement.support.shared.types;
import java.io.Serializable;
/**
* @author Daniele Strollo (ISTI-CNR)
*
*/
public enum RunningMode implements Serializable {
PORTAL("PortalMode"),
STANDALONE("StandaloneMode"),
NOTDEFINED("NotDefined");
private String mode = null;
private RunningMode(final String mode) {
this.mode = mode;
}
@Override
public final String toString() {
return this.mode;
}
}

View File

@ -0,0 +1,166 @@
/****************************************************************************
* This software is part of the gCube Project.
* Site: http://www.gcube-system.org/
****************************************************************************
* The gCube/gCore software is licensed as Free Open Source software
* conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
* The software and documentation is provided by its authors/distributors
* "as is" and no expressed or
* implied warranty is given for its use, quality or fitness for a
* particular case.
****************************************************************************
* Filename: Tuple.java
****************************************************************************
* @author <a href="mailto:daniele.strollo@isti.cnr.it">Daniele Strollo</a>
***************************************************************************/
package org.gcube.resourcemanagement.support.shared.types;
import java.io.Serializable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import com.google.gwt.user.client.rpc.IsSerializable;
/**
* General purpose tuple representation.
* A tuple is a sequence (or ordered list) of finite length.
*
* <pre>
* Example:
*
* <b>1) <i>Creation</i></b>
* // single typed tuple
* Tuple&lt;Long&gt; nt = new Tuple&lt;Long&gt;(42L);
*
* // multi typed tuple
* Tuple&lt;Object&gt; ot = new Tuple&lt;Object&gt;(&quot;Lars Tackmann&quot;,
* &quot;Age&quot;, 26);
*
* <b>2) <i>Usage</i></b>
* // get single element
* Integer val = (Integer) ot.get(2);
* // iterate tuple
* for (Object o : ot)
* System.out.printf(&quot;'%s' &quot;, o.toString());
* // print all elems
* System.out.printf(&quot;Object tuple: %s\n&quot;, ot.toString());
*
*
* <b>3) <i>Operations</i></b>
* // The elements of two tuples a and b can be joined with
* // union operation that returns a new tuple.
* Tuple c = a.union (b);
* </pre>
*
*/
public class Tuple<T> implements Iterable<T>, Serializable, IsSerializable {
private static final long serialVersionUID = 5783359179069297888L;
private List<T> content = new LinkedList<T>();
/**
* @deprecated For serialization purpose use the other constructors
*/
public final List<T> getContent() {
return content;
}
/**
* @deprecated For serialization purpose use the other constructors
*/
public final void setContent(final List<T> content) {
this.content = content;
}
/**
* @deprecated For serialization purpose use the other constructors
*/
public Tuple() {
super();
}
public Tuple(final T... args) {
for (T t : args) {
content.add(t);
}
}
/**
* Appends elements inside a tuple.
*/
public final void append(final T... args) {
if (content != null) {
for (T t : args) {
content.add(t);
}
}
}
@SuppressWarnings({ "unchecked", "deprecation" })
public final Tuple<? extends T> union(final Tuple<? extends T> t) {
Tuple<T> retval = new Tuple<T>();
for (T elem : content) {
retval.append(elem);
}
for (int i = 0; i < t.size(); i++) {
retval.append(t.get(i));
}
return retval;
}
public final T get(final int index) {
return content.get(index);
}
public final Iterator<T> iterator() {
return content.iterator();
}
public final int size() {
return content.size();
}
/**
* Compares two tuples.
* The comparison is applied to all the contained elements.
*
* @param obj the {@link Tuple} element to compare
* @return true if the number of contained elements is the same and
* all the elements are equals.
*/
@SuppressWarnings("unchecked")
public final boolean equals(final Object obj) {
if (!(obj instanceof Tuple<?>)) {
return false;
}
Tuple<T> tuple = (Tuple<T>) obj;
if (tuple.size() != this.content.size()) { return false; }
Iterator<T> internalElems = this.content.iterator();
for (T elem : tuple) {
if (!elem.equals(internalElems.next())) {
return false;
}
}
return true;
}
@Override
public final int hashCode() {
int retval = 0;
Iterator<T> internalElems = this.content.iterator();
while (internalElems.hasNext()) {
retval += internalElems.next().hashCode();
}
return retval;
}
@Override
public final String toString() {
StringBuilder retval = new StringBuilder();
for (Object o : content) {
retval.append(o.toString() + "/");
}
return "(" + retval.substring(0, retval.length() - 1) + ")";
}
}

View File

@ -14,7 +14,7 @@
* @author <a href="mailto:daniele.strollo@isti.cnr.it">Daniele Strollo</a> * @author <a href="mailto:daniele.strollo@isti.cnr.it">Daniele Strollo</a>
***************************************************************************/ ***************************************************************************/
package org.gcube.resourcemanagement.support.shared; package org.gcube.resourcemanagement.support.shared.types;
import java.io.Serializable; import java.io.Serializable;
import com.google.gwt.user.client.rpc.IsSerializable; import com.google.gwt.user.client.rpc.IsSerializable;

View File

@ -0,0 +1,100 @@
/****************************************************************************
* This software is part of the gCube Project.
* Site: http://www.gcube-system.org/
****************************************************************************
* The gCube/gCore software is licensed as Free Open Source software
* conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
* The software and documentation is provided by its authors/distributors
* "as is" and no expressed or
* implied warranty is given for its use, quality or fitness for a
* particular case.
****************************************************************************
* Filename: AtomicTreeNode.java
****************************************************************************
* @author <a href="mailto:daniele.strollo@isti.cnr.it">Daniele Strollo</a>
***************************************************************************/
package org.gcube.resourcemanagement.support.shared.types.datamodel;
import com.extjs.gxt.ui.client.data.BaseTreeModel;
/**
* @author Daniele Strollo (ISTI-CNR)
*
*/
public class AtomicTreeNode extends BaseTreeModel {
private static final long serialVersionUID = 5094327834701967591L;
private static int ID = 0;
/**
* @deprecated fr serialization only
*/
public AtomicTreeNode() {
set("id", ID++);
}
public AtomicTreeNode(final String node) {
this(node, null);
}
/**
* The node is used as original node of the element useful to retrieve it from the IS.
* The name is instead used for pretty printing (aliasing).
* @param node the corresponding IS node
* @param name if null the node will be used instead
*/
public AtomicTreeNode(final String node, final String name) {
set("id", ID++);
set("node", node);
if (name == null) {
set("name", node);
} else {
set("name", name);
}
}
public AtomicTreeNode(final String node, final String name, final String icon) {
this(node, name);
set("icon", icon);
}
public AtomicTreeNode(final String node, final String name, final AtomicTreeNode[] children) {
this(node, name);
for (int i = 0; i < children.length; i++) {
add(children[i]);
}
}
public AtomicTreeNode(final String node, final String name, final String icon, final AtomicTreeNode[] children) {
this(node, name, children);
set("icon", icon);
}
public final Integer getId() {
return (Integer) get("id");
}
public final String getName() {
return (String) get("name");
}
public final String getNode() {
return (String) get("node");
}
public final String getLabel() {
return (String) get("label");
}
public final String toString() {
return getName();
}
public final String getSubType() {
if (this.isLeaf() && this.getParent() != null) {
return this.getNode();
}
return null;
}
}

View File

@ -0,0 +1,82 @@
/****************************************************************************
* This software is part of the gCube Project.
* Site: http://www.gcube-system.org/
****************************************************************************
* The gCube/gCore software is licensed as Free Open Source software
* conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
* The software and documentation is provided by its authors/distributors
* "as is" and no expressed or
* implied warranty is given for its use, quality or fitness for a
* particular case.
****************************************************************************
* Filename: ResourceProfile.java
****************************************************************************
* @author <a href="mailto:daniele.strollo@isti.cnr.it">Daniele Strollo</a>
***************************************************************************/
package org.gcube.resourcemanagement.support.shared.types.datamodel;
import java.io.Serializable;
import org.gcube.resourcemanagement.support.client.views.ResourceTypeDecorator;
import com.google.gwt.user.client.rpc.IsSerializable;
/**
* The profile of resources is represented by its
* xml and html representations and its title (the name
* or the ID) and the type (GHN, RI, ...).
* @author Daniele Strollo (ISTI-CNR)
*
*/
public class CompleteResourceProfile implements Serializable, IsSerializable {
private static final long serialVersionUID = 1L;
private String xmlRepresentation = null;
private String htmlRepresentation = null;
private ResourceTypeDecorator type = null;
private String title = null;
private String ID = null;
/**
* @deprecated for serialization only
*/
public CompleteResourceProfile() {
}
public CompleteResourceProfile(String ID, ResourceTypeDecorator type, String title, String xmlRepresentation,
String htmlRepresentation) {
super();
this.ID = ID;
this.type = type;
this.title = title;
this.xmlRepresentation = xmlRepresentation;
this.htmlRepresentation = htmlRepresentation;
}
public String getXmlRepresentation() {
return xmlRepresentation;
}
public String getHtmlRepresentation() {
return htmlRepresentation;
}
public ResourceTypeDecorator getType() {
return type;
}
public String getTitle() {
return title;
}
public String getID() {
return ID;
}
}

View File

@ -0,0 +1,113 @@
/****************************************************************************
* This software is part of the gCube Project.
* Site: http://www.gcube-system.org/
****************************************************************************
* The gCube/gCore software is licensed as Free Open Source software
* conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
* The software and documentation is provided by its authors/distributors
* "as is" and no expressed or
* implied warranty is given for its use, quality or fitness for a
* particular case.
****************************************************************************
* Filename: ResourceDescriptor.java
****************************************************************************
* @author <a href="mailto:daniele.strollo@isti.cnr.it">Daniele Strollo</a>
***************************************************************************/
package org.gcube.resourcemanagement.support.shared.types.datamodel;
import java.io.Serializable;
import org.gcube.resourcemanagement.support.shared.exceptions.InvalidParameterException;
import org.gcube.resourcemanagement.support.shared.util.Assertion;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.google.gwt.user.client.rpc.IsSerializable;
/**
* All the resources that want to access resource management
* operations must be described through this data type.
* @author Daniele Strollo (ISTI-CNR)
*/
public class ResourceDescriptor extends BaseModelData implements Serializable, IsSerializable {
private static final long serialVersionUID = 6435512868470974421L;
public ResourceDescriptor() {
super();
}
/**
* Creates a ResourceDescriptor
* @param type mandatory
* @param subtype can be null
* @param ID the identifier of the resource (mandatory).
* @param name the short name assigned to the resource (mandatory).
* @throws InvalidParameterException
*/
public ResourceDescriptor(
final String type,
final String subtype,
final String id,
final String name) throws InvalidParameterException {
super();
Assertion<InvalidParameterException> checker = new Assertion<InvalidParameterException>();
checker.validate(name != null && name.length() > 0, new InvalidParameterException("The ghnName is null or empty"));
checker.validate(id != null && id.length() > 0, new InvalidParameterException("The ID is null or empty"));
checker.validate(type != null && type.length() > 0, new InvalidParameterException("The type is null or empty"));
this.setSubtype(subtype);
this.setType(type);
this.setID(id);
this.setName(name);
}
public final String getType() {
return get("type");
}
public final String getSubtype() {
return get("subtype");
}
public final String getID() {
return get("ID");
}
public final String getName() {
return get("name");
}
public final void setType(final String type) {
if (type != null) {
set("type", type.trim());
}
}
public final void setSubtype(final String subtype) {
if (subtype != null) {
set("subtype", subtype.trim());
}
}
public final void setID(final String id) {
if (id != null) {
set("ID", id.trim());
}
}
public final void setName(final String name) {
if (name != null) {
set("name", name.trim());
}
}
public final void addProperty(final String property, final Object value) {
set(property, value);
}
public final Object getProperty(final String property) {
return get(property);
}
}

View File

@ -0,0 +1,824 @@
/****************************************************************************
* This software is part of the gCube Project.
* Site: http://www.gcube-system.org/
****************************************************************************
* The gCube/gCore software is licensed as Free Open Source software
* conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
* The software and documentation is provided by its authors/distributors
* "as is" and no expressed or
* implied warranty is given for its use, quality or fitness for a
* particular case.
****************************************************************************
* Filename: ResourceDetailDecorator.java
****************************************************************************
* @author <a href="mailto:daniele.strollo@isti.cnr.it">Daniele Strollo</a>
***************************************************************************/
package org.gcube.resourcemanagement.support.shared.types.datamodel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.gcube.resourcemanagement.support.client.views.ResourceTypeDecorator;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.NumberFormat;
/**
* @author Massimiliano Assante (ISTI-CNR)
* @author Daniele Strollo
*/
public class ResourceDetailModel {
private static boolean initialized = false;
public static final String SERVICE_INSTALL_KEY = "toDeploy";
private static HashMap<String, ColumnModel> RECORD_DEFINITION = null;
private static HashMap<String, ModelType> XML_MAPPING = null;
private static HashMap<String, String[]> REQUIRED_FIELDS = null;
private static void init() {
if (initialized) {
return;
}
initialized = true;
RECORD_DEFINITION = new HashMap<String, ColumnModel>();
XML_MAPPING = new HashMap<String, ModelType>();
/*********************************************
* GHN
********************************************/
// The column model for grid representation
List<ColumnConfig> modelColumns = new ArrayList<ColumnConfig>();
modelColumns.add(new ColumnConfig("Name", "Name", 250));
ColumnConfig status = new ColumnConfig("Status", "Status", 65);
GridCellRenderer<BaseModelData> statusRender = new GridCellRenderer<BaseModelData>() {
@Override
public String render(BaseModelData model, String property, ColumnData config,
int rowIndex, int colIndex, ListStore<BaseModelData> store, Grid<BaseModelData> grid) {
String statusToCheck = (String)model.get(property);
String style = "gray";
if (statusToCheck.compareTo("certified") == 0)
style = "green";
else if (statusToCheck.compareTo("ready") == 0)
style = "orange";
return "<span style='color:" + style + "'>" + statusToCheck + "</span>";
}
};
status.setRenderer(statusRender);
modelColumns.add(status);
modelColumns.add(new ColumnConfig("LastUpdate", "Last Updated", 130));
modelColumns.add(new ColumnConfig("gCoreVersion", "gCore v.", 50));
modelColumns.add(new ColumnConfig("ghnVersion", "ghn v.", 40));
ColumnConfig ramLeft = new ColumnConfig("VirtualAvailable", "V. Mem left", 70);
ramLeft.setAlignment(HorizontalAlignment.RIGHT);
ramLeft.setEditor(new CellEditor(new NumberField()));
final NumberFormat number = NumberFormat.getFormat("#,##0;(#,##0)");
GridCellRenderer<BaseModelData> ramRender = new GridCellRenderer<BaseModelData>() {
@Override
public String render(BaseModelData model, String property, ColumnData config,
int rowIndex, int colIndex, ListStore<BaseModelData> store, Grid<BaseModelData> grid) {
int val = Integer.parseInt((String)model.get(property));
int tot = Integer.parseInt((String) model.get("VirtualSize"));
int percentage = (val * 100) / tot;
String style = val < 100 ? "red" : "green";
String toDisplay = number.format(val).replaceAll(",", ".");
toDisplay += " MB";
return "<span style='color:" + style + "'>" + percentage + "% ("+toDisplay+")</span>";
}
};
ramLeft.setRenderer(ramRender);
modelColumns.add(ramLeft);
ColumnConfig localSpace = new ColumnConfig("LocalAvailableSpace", "HD Space left", 70);
localSpace.setAlignment(HorizontalAlignment.RIGHT);
localSpace.setEditor(new CellEditor(new NumberField()));
GridCellRenderer<BaseModelData> mbRender = new GridCellRenderer<BaseModelData>() {
@Override
public String render(BaseModelData model, String property, ColumnData config,
int rowIndex, int colIndex, ListStore<BaseModelData> store, Grid<BaseModelData> grid) {
int val = Integer.parseInt((String)model.get(property));
String style = val < 1000000 ? "red" : "green";
String toDisplay = number.format(val);
if (toDisplay.length() > 4)
toDisplay = toDisplay.substring(0, toDisplay.length()-4).replaceAll(",", ".");
toDisplay += " MB";
return "<span style='color:" + style + "'>" + toDisplay + "</span>";
}
};
localSpace.setRenderer(mbRender);
modelColumns.add(localSpace);
//Optional
ColumnConfig ramTotal = new ColumnConfig("VirtualSize", "V. Memory total", 70);
ramTotal.setAlignment(HorizontalAlignment.RIGHT);
ramTotal.setEditor(new CellEditor(new NumberField()));
GridCellRenderer<BaseModelData> ramTotRender = new GridCellRenderer<BaseModelData>() {
@Override
public String render(BaseModelData model, String property, ColumnData config,
int rowIndex, int colIndex, ListStore<BaseModelData> store, Grid<BaseModelData> grid) {
int val = Integer.parseInt((String)model.get(property));
String toDisplay = number.format(val).replaceAll(",", ".");
toDisplay += " MB";
return toDisplay;
}
};
ramTotal.setRenderer(ramTotRender);
modelColumns.add(ramTotal);
modelColumns.add(new ColumnConfig("ID", "ID", 220));
modelColumns.add(new ColumnConfig("Uptime", "Up Time", 100));
modelColumns.add(new ColumnConfig("LoadLast15Min", "Load Last 15 Min", 100));
modelColumns.add(new ColumnConfig("LoadLast1Min", "Load Last 1 Min", 100));
modelColumns.add(new ColumnConfig("LoadLast5Min", "Load Last 5 Min", 100));
modelColumns.add(new ColumnConfig("Scopes", "Scopes", 300));
modelColumns.add(new ColumnConfig("SubType", "SubType", 200));
// create the column model
ColumnModel cm = new ColumnModel(modelColumns);
// The hidden fields after the 5 column
for (int i = 7; i < modelColumns.size(); i++) {
cm.setHidden(i, true);
}
RECORD_DEFINITION.put(ResourceTypeDecorator.GHN.name(), cm);
// defines the xml structure
ModelType type = new ModelType();
type.setRoot("Resources");
type.setRecordName("Resource");
type.addField("ID");
type.addField("Status");
type.addField("Name");
type.addField("Uptime");
type.addField("LastUpdate");
type.addField("VirtualAvailable");
type.addField("VirtualSize");
type.addField("gCoreVersion", "gcf-version");
type.addField("ghnVersion", "ghn-version");
type.addField("LocalAvailableSpace");
type.addField("LoadLast15Min");
type.addField("LoadLast1Min");
type.addField("LoadLast5Min");
type.addField("Scopes");
// These fields are internally used and not showable
type.addField("SubType");
type.addField("Type");
XML_MAPPING.put(ResourceTypeDecorator.GHN.name(), type);
/*********************************************
* Collection
********************************************/
// The column model for grid representation
modelColumns = new ArrayList<ColumnConfig>();
modelColumns.add(new ColumnConfig("Name", "Name", 470));
modelColumns.add(new ColumnConfig("NumberOfMembers", "Cardinality", 70));
modelColumns.add(new ColumnConfig("LastUpdateTime", "Last Updated", 170));
modelColumns.add(new ColumnConfig("ID", "ID", 220));
//Optional
modelColumns.add(new ColumnConfig("CreationTime", "Creation Time", 170));
modelColumns.add(new ColumnConfig("Scopes", "Scopes", 300));
modelColumns.add(new ColumnConfig("SubType", "SubType", 200));
//modelColumns.add(new ColumnConfig("NumberOfMembers", "Number Of Members", 115)); //not available anymore
// create the column model
cm = new ColumnModel(modelColumns);
for (int i = 4; i < modelColumns.size(); i++) {
cm.setHidden(i, true);
}
RECORD_DEFINITION.put(ResourceTypeDecorator.Collection.name(), cm);
// defines the xml structure
type = new ModelType();
type.setRoot("Resources");
type.setRecordName("Resource");
type.addField("ID");
type.addField("Name");
type.addField("CreationTime");
type.addField("LastUpdateTime");
type.addField("NumberOfMembers");
type.addField("Scopes");
type.addField("SubType");
type.addField("Type");
XML_MAPPING.put(ResourceTypeDecorator.Collection.name(), type);
/*********************************************
* Service
********************************************/
// The column model for grid representation
modelColumns = new ArrayList<ColumnConfig>();
modelColumns.add(new ColumnConfig("ServiceClass", "Service Class", 200));
modelColumns.add(new ColumnConfig("ServiceName", "Service Name", 260));
modelColumns.add(new ColumnConfig("Version", "Main Package Version", 100));
//Optional
modelColumns.add(new ColumnConfig("Shareable", "Shareable", 100));
modelColumns.add(new ColumnConfig("Scopes", "Scopes", 300));
modelColumns.add(new ColumnConfig("ID", "ID", 220));
modelColumns.add(new ColumnConfig("SubType", "SubType", 200));
// create the column model
cm = new ColumnModel(modelColumns);
for (int i = 3; i < modelColumns.size(); i++) {
cm.setHidden(i, true);
}
RECORD_DEFINITION.put(ResourceTypeDecorator.Service.name(), cm);
// defines the xml structure
type = new ModelType();
type.setRoot("Resources");
type.setRecordName("Resource");
type.addField("ID");
type.addField("ServiceClass");
type.addField("ServiceName");
type.addField("Version");
type.addField("Shareable");
type.addField("Scopes");
// These fields are internally used and not showable
type.addField("SubType");
type.addField("Type");
XML_MAPPING.put(ResourceTypeDecorator.Service.name(), type);
/*********************************************
* InstallableSoftware
********************************************/
// The column model for grid representation
modelColumns = new ArrayList<ColumnConfig>();
// adds the checkbox to the model
CheckColumnConfig checkColumn =
new CheckColumnConfig(ResourceDetailModel.SERVICE_INSTALL_KEY, "Deploy", 60);
CellEditor checkBoxEditor = new CellEditor(new CheckBox());
checkColumn.setEditor(checkBoxEditor);
modelColumns.add(checkColumn);
modelColumns.add(new ColumnConfig("ServiceClass", "Service Class", 250));
modelColumns.add(new ColumnConfig("ServiceName", "Service Name", 250));
modelColumns.add(new ColumnConfig("Version", "Main Package Version", 100));
//Optional
modelColumns.add(new ColumnConfig("Scopes", "Scopes", 300));
modelColumns.add(new ColumnConfig("ID", "ID", 220));
modelColumns.add(new ColumnConfig("SubType", "SubType", 200));
// create the column model
cm = new ColumnModel(modelColumns);
for (int i = 3; i < modelColumns.size(); i++) {
cm.setHidden(i, true);
}
RECORD_DEFINITION.put(ResourceTypeDecorator.InstallableSoftware.name(), cm);
// defines the xml structure
type = new ModelType();
type.setRoot("Resources");
type.setRecordName("Resource");
type.addField("ID");
type.addField("ServiceClass");
type.addField("ServiceName");
type.addField("Version");
type.addField("Scopes");
// These fields are internally used and not showable
type.addField("SubType");
type.addField("Type");
XML_MAPPING.put(ResourceTypeDecorator.InstallableSoftware.name(), type);
/*********************************************
* RunningInstance
********************************************/
// The column model for grid representation
modelColumns = new ArrayList<ColumnConfig>();
modelColumns.add(new ColumnConfig("ServiceClass", "Service Class", 200));
modelColumns.add(new ColumnConfig("ServiceName", "Service Name", 260));
modelColumns.add(new ColumnConfig("Version", "Version", 100));
modelColumns.add(new ColumnConfig("Status", "Status", 65));
modelColumns.add(new ColumnConfig("GHN", "GHN", 300));
//Optional
modelColumns.add(new ColumnConfig("Scopes", "Scopes", 300));
modelColumns.add(new ColumnConfig("ID", "ID", 220));
modelColumns.add(new ColumnConfig("SubType", "SubType", 200));
// create the column model
cm = new ColumnModel(modelColumns);
for (int i = 5; i < modelColumns.size(); i++) {
cm.setHidden(i, true);
}
RECORD_DEFINITION.put(ResourceTypeDecorator.RunningInstance.name(), cm);
// defines the xml structure
type = new ModelType();
type.setRoot("Resources");
type.setRecordName("Resource");
type.addField("ID");
type.addField("ServiceClass");
type.addField("ServiceName");
type.addField("Version");
type.addField("Status");
// a) This is the GHNID type.addField("GHN", "/Profile/GHN/@UniqueID");
// b) While this is its name
type.addField("GHN", "ghn-name");
type.addField("Scopes");
// These fields are internally used and not showable
type.addField("SubType");
type.addField("Type");
XML_MAPPING.put(ResourceTypeDecorator.RunningInstance.name(), type);
/*********************************************
* VIEW
********************************************/
// The column model for grid representation
modelColumns = new ArrayList<ColumnConfig>();
modelColumns.add(new ColumnConfig("ViewName", "View Name", 200));
modelColumns.add(new ColumnConfig("SourceKey", "Source Key", 200));
modelColumns.add(new ColumnConfig("LastUpdate", "Last Update", 270));
modelColumns.add(new ColumnConfig("Cardinality", "Cardinality", 100));
//Optional
modelColumns.add(new ColumnConfig("ViewType", "View Type", 170));
modelColumns.add(new ColumnConfig("RelatedCollectionId", "Related Collection Id", 220));
modelColumns.add(new ColumnConfig("ServiceName", "Service Name", 170));
modelColumns.add(new ColumnConfig("Termination", "Termination Time", 270));
modelColumns.add(new ColumnConfig("Source", "Source", 230));
modelColumns.add(new ColumnConfig("ServiceClass", "Service Class", 170));
modelColumns.add(new ColumnConfig("Scopes", "Scopes", 300));
modelColumns.add(new ColumnConfig("RI", "RI", 220));
modelColumns.add(new ColumnConfig("SubType", "SubType", 200));
// create the column model
cm = new ColumnModel(modelColumns);
for (int i = 4; i < modelColumns.size(); i++) {
cm.setHidden(i, true);
}
RECORD_DEFINITION.put(ResourceTypeDecorator.VIEW.name(), cm);
// defines the xml structure
type = new ModelType();
type.setRoot("Resources");
type.setRecordName("Resource");
type.addField("ID");
type.addField("ViewName");
type.addField("Cardinality");
type.addField("ViewType");
type.addField("RelatedCollectionId");
type.addField("Source");
type.addField("SourceKey");
type.addField("ServiceClass");
type.addField("ServiceName");
type.addField("Termination", "TerminationTimeHuman");
type.addField("LastUpdate", "LastUpdateHuman");
type.addField("Scopes", "/scopes");
type.addField("SubType", "SubType");
type.addField("RI");
type.addField("Type");
GWT.log("VIew Name: " + ResourceTypeDecorator.VIEW.name());
XML_MAPPING.put(ResourceTypeDecorator.VIEW.name(), type);
/*********************************************
* GenericResource
********************************************/
// The column model for grid representation
modelColumns = new ArrayList<ColumnConfig>();
modelColumns.add(new ColumnConfig("Name", "Name", 500));
modelColumns.add(new ColumnConfig("Scopes", "Scopes", 300));
//Optional
modelColumns.add(new ColumnConfig("ID", "ID", 220));
modelColumns.add(new ColumnConfig("SubType", "Secondary Type", 170));
modelColumns.add(new ColumnConfig("SubType", "SubType", 200));
// create the column model
cm = new ColumnModel(modelColumns);
for (int i = 2; i < modelColumns.size(); i++) {
cm.setHidden(i, true);
}
RECORD_DEFINITION.put(ResourceTypeDecorator.GenericResource.name(), cm);
// defines the xml structure
type = new ModelType();
type.setRoot("Resources");
type.setRecordName("Resource");
type.addField("ID");
type.addField("Name");
type.addField("Scopes");
type.addField("SubType");
type.addField("Type");
XML_MAPPING.put(ResourceTypeDecorator.GenericResource.name(), type);
/*********************************************
* RuntimeResource
********************************************/
// The column model for grid representation
modelColumns = new ArrayList<ColumnConfig>();
modelColumns.add(new ColumnConfig("Name", "Name", 300));
modelColumns.add(new ColumnConfig("Scopes", "Scopes", 300));
//Optional
modelColumns.add(new ColumnConfig("ID", "ID", 220));
modelColumns.add(new ColumnConfig("SubType", "Category", 370));
// create the column model
cm = new ColumnModel(modelColumns);
for (int i = 3; i < modelColumns.size(); i++) {
cm.setHidden(i, true);
}
RECORD_DEFINITION.put(ResourceTypeDecorator.RuntimeResource.name(), cm);
// defines the xml structure
type = new ModelType();
type.setRoot("Resources");
type.setRecordName("Resource");
type.addField("ID");
type.addField("Name");
type.addField("Scopes");
type.addField("SubType");
type.addField("Type");
XML_MAPPING.put(ResourceTypeDecorator.RuntimeResource.name(), type);
/*********************************************
* WSResources
********************************************/
// The column model for grid representation
modelColumns = new ArrayList<ColumnConfig>();
modelColumns.add(new ColumnConfig("SourceKey", "Source Key", 230));
modelColumns.add(new ColumnConfig("ServiceName", "Service Name", 170));
modelColumns.add(new ColumnConfig("Termination", "Termination Time", 270));
modelColumns.add(new ColumnConfig("LastUpdate", "Last Update", 270));
//Optional
modelColumns.add(new ColumnConfig("ID", "ID", 220));
modelColumns.add(new ColumnConfig("Source", "Source", 230));
modelColumns.add(new ColumnConfig("ServiceClass", "Service Class", 170));
modelColumns.add(new ColumnConfig("Scopes", "Scopes", 300));
modelColumns.add(new ColumnConfig("RI", "RI", 220));
modelColumns.add(new ColumnConfig("SubType", "SubType", 200));
// create the column model
cm = new ColumnModel(modelColumns);
for (int i = 4; i < modelColumns.size(); i++) {
cm.setHidden(i, true);
}
RECORD_DEFINITION.put(ResourceTypeDecorator.WSResource.name(), cm);
// defines the xml structure
type = new ModelType();
type.setRoot("Resources");
type.setRecordName(ResourceTypeDecorator.WSResource.name());
type.addField("ID");
type.addField("Source");
type.addField("SourceKey");
type.addField("ServiceClass");
type.addField("ServiceName");
type.addField("Termination", "TerminationTimeHuman");
type.addField("LastUpdate", "LastUpdateHuman");
type.addField("Scopes", "/scopes");
type.addField("SubType", "SubType");
type.addField("RI");
type.addField("Type");
XML_MAPPING.put(ResourceTypeDecorator.WSResource.name(), type);
/*********************************************
* PROFILES OF RELATED RESOURCES: GHN
********************************************/
// The column model for grid representation
modelColumns = new ArrayList<ColumnConfig>();
modelColumns.add(new ColumnConfig("ServiceClass", "Service Class", 200));
modelColumns.add(new ColumnConfig("ServiceName", "Service Name", 260));
modelColumns.add(new ColumnConfig("ServiceVersion", "Service Version", 100));
modelColumns.add(new ColumnConfig("MainVersion", "Main Version", 100));
modelColumns.add(new ColumnConfig("Status", "Status", 65));
//Optional
modelColumns.add(new ColumnConfig("ID", "ID", 220));
// create the column model
cm = new ColumnModel(modelColumns);
for (int i = 5; i < modelColumns.size(); i++) {
cm.setHidden(i, true);
}
RECORD_DEFINITION.put(ResourceTypeDecorator.GHNRelated.name(), cm);
// defines the xml structure
type = new ModelType();
type.setRoot("Resources");
type.setRecordName("Resource");
type.addField("ID");
type.addField("ServiceClass");
type.addField("ServiceName");
type.addField("ServiceVersion");
type.addField("MainVersion");
type.addField("Status");
XML_MAPPING.put(ResourceTypeDecorator.GHNRelated.name(), type);
/*********************************************
* PROFILES OF RELATED RESOURCES: RunningInstance
********************************************/
// The column model for grid representation
modelColumns = new ArrayList<ColumnConfig>();
modelColumns.add(new ColumnConfig("Key", "Name", 200));
modelColumns.add(new ColumnConfig("Value", "Value", 260));
// create the column model
cm = new ColumnModel(modelColumns);
RECORD_DEFINITION.put(ResourceTypeDecorator.RunningInstanceRelated.name(), cm);
// defines the xml structure
type = new ModelType();
type.setRoot("Resources");
type.setRecordName("Resource");
type.addField("Key");
type.addField("Value");
XML_MAPPING.put(ResourceTypeDecorator.RunningInstanceRelated.name(), type);
/*********************************************
* PROFILES OF RELATED RESOURCES: Service
********************************************/
// The column model for grid representation
modelColumns = new ArrayList<ColumnConfig>();
modelColumns.add(new ColumnConfig("RIID", "RI ID", 90));
modelColumns.add(new ColumnConfig("ServiceStatus", "RI Status", 70));
modelColumns.add(new ColumnConfig("RIVersion", "Serv.Version", 70));
modelColumns.add(new ColumnConfig("ActivationTime", "RI ActivationTime", 170));
modelColumns.add(new ColumnConfig("GHNName", "GHN Name", 100));
modelColumns.add(new ColumnConfig("GHNStatus", "GHN Status", 70));
modelColumns.add(new ColumnConfig("GHNID", "GHN ID", 100));
modelColumns.add(new ColumnConfig("GHNSite", "GHN Site", 100));
modelColumns.add(new ColumnConfig("GHNLoad15Min", "GHNLoad15Min", 50));
modelColumns.add(new ColumnConfig("GHNLoad5Min", "GHNLoad5Min", 50));
modelColumns.add(new ColumnConfig("GHNLoad1Min", "GHNLoad1Min", 50));
modelColumns.add(new ColumnConfig("GHNActivationTime", "GHNActivationTime", 100));
modelColumns.add(new ColumnConfig("GHNLastUpdate", "GHNLastUpdate", 100));
// create the column model
cm = new ColumnModel(modelColumns);
for (int i = 6; i < modelColumns.size(); i++) {
cm.setHidden(i, true);
}
RECORD_DEFINITION.put(ResourceTypeDecorator.ServiceRelated.name(), cm);
// defines the xml structure
type = new ModelType();
type.setRoot("Resources");
type.setRecordName("Resource");
type.addField("RIID");
type.addField("ServiceStatus");
type.addField("ActivationTime");
type.addField("GHNID");
type.addField("RIVersion");
type.addField("GHNName");
type.addField("GHNSite");
type.addField("GHNStatus");
type.addField("GHNLoad15Min");
type.addField("GHNLoad5Min");
type.addField("GHNLoad1Min");
type.addField("GHNActivationTime");
type.addField("GHNLastUpdate");
XML_MAPPING.put(ResourceTypeDecorator.ServiceRelated.name(), type);
/*********************************************
* MODEL FOR SWEEPER GHN
********************************************/
// The column model for grid representation
modelColumns = new ArrayList<ColumnConfig>();
modelColumns.add(new ColumnConfig("Name", "Name", 130));
modelColumns.add(new ColumnConfig("Status", "Status", 50));
ColumnConfig minElapsed = (new ColumnConfig("UpdateMinutesElapsed", "Minutes from Update", 130));
minElapsed.setAlignment(HorizontalAlignment.CENTER);
modelColumns.add(minElapsed);
modelColumns.add(new ColumnConfig("AllocatedRI", "#RI", 40));
modelColumns.add(new ColumnConfig("LastUpdate", "LastUpdate", 130));
// hidden fields
modelColumns.add(new ColumnConfig("Actions", "Actions", 260));
modelColumns.add(new ColumnConfig("ID", "ID", 200));
modelColumns.add(new ColumnConfig("Type", "Type", 100));
modelColumns.add(new ColumnConfig("Location", "Location", 100));
modelColumns.add(new ColumnConfig("Domain", "Domain", 100));
modelColumns.add(new ColumnConfig("IPAddress", "IPAddress", 100));
modelColumns.add(new ColumnConfig("Scopes", "Scopes", 100));
// create the column model
cm = new ColumnModel(modelColumns);
for (int i = 5; i < modelColumns.size(); i++) {
cm.setHidden(i, true);
}
RECORD_DEFINITION.put(ResourceTypeDecorator.Sweeper_GHN.name(), cm);
// defines the xml structure
type = new ModelType();
type.setRoot("Resources");
type.setRecordName("Resource");
type.addField("ID");
type.addField("Name");
type.addField("Actions");
type.addField("Status");
type.addField("AllocatedRI");
type.addField("Type");
type.addField("Location");
type.addField("Domain");
type.addField("IPAddress");
type.addField("Scopes");
type.addField("LastUpdate");
type.addField("UpdateMinutesElapsed");
XML_MAPPING.put(ResourceTypeDecorator.Sweeper_GHN.name(), type);
/*********************************************
* MODEL FOR SWEEPER RI
********************************************/
// The column model for grid representation
modelColumns = new ArrayList<ColumnConfig>();
modelColumns.add(new ColumnConfig("ID", "ID", 120));
modelColumns.add(new ColumnConfig("ServiceClass", "ServiceClass", 100));
modelColumns.add(new ColumnConfig("ServiceName", "ServiceName", 100));
modelColumns.add(new ColumnConfig("ghnid", "GHN ID", 120));
// hidden fields
modelColumns.add(new ColumnConfig("Actions", "Actions", 260));
modelColumns.add(new ColumnConfig("ServiceStatus", "Status", 90));
modelColumns.add(new ColumnConfig("ActivationTime", "Activation Time", 140));
// create the column model
cm = new ColumnModel(modelColumns);
for (int i = 4; i < modelColumns.size(); i++) {
cm.setHidden(i, true);
}
RECORD_DEFINITION.put(ResourceTypeDecorator.Sweeper_RI.name(), cm);
// defines the xml structure
type = new ModelType();
type.setRoot("Resources");
type.setRecordName("Resource");
type.addField("ID");
type.addField("ServiceStatus");
type.addField("ServiceClass");
type.addField("ServiceName");
type.addField("ActivationTime");
type.addField("ghnid");
type.addField("Actions");
XML_MAPPING.put(ResourceTypeDecorator.Sweeper_RI.name(), type);
/*********************************************
* VALIDATORS
********************************************/
/*
* REQUIRED FIELDS
*/
REQUIRED_FIELDS = new HashMap<String, String[]>();
REQUIRED_FIELDS.put(
ResourceTypeDecorator.GHN.name(),
new String[] {
"Name",
"SubType",
"ID",
"Scopes"
});
REQUIRED_FIELDS.put(
ResourceTypeDecorator.Collection.name(),
new String[] {
"Name",
"SubType",
"ID",
"Scopes"
});
REQUIRED_FIELDS.put(
ResourceTypeDecorator.GenericResource.name(),
new String[] {
"Name",
"SubType",
"ID",
"Scopes"
});
REQUIRED_FIELDS.put(
ResourceTypeDecorator.RuntimeResource.name(),
new String[] {
"Name",
"SubType",
"ID",
"Scopes"
});
REQUIRED_FIELDS.put(
ResourceTypeDecorator.VIEW.name(),
new String[] {
"Name",
"SubType",
"ID",
"Scopes"
});
REQUIRED_FIELDS.put(
ResourceTypeDecorator.RunningInstance.name(),
new String[] {
"ServiceClass",
"ServiceName",
"ID",
"SubType",
"Scopes",
"GHN"
});
REQUIRED_FIELDS.put(
ResourceTypeDecorator.Service.name(),
new String[] {
"ServiceClass",
"ServiceName",
"ID",
"SubType",
"Scopes"
});
REQUIRED_FIELDS.put(
ResourceTypeDecorator.WSResource.name(),
new String[] {
"SourceKey",
"ServiceName",
"ID",
"SubType",
"Scopes"
});
}
public static final ColumnModel getRecordDefinition(final String nodeID) {
init();
return RECORD_DEFINITION.get(nodeID);
}
public static final ModelType getXMLMapping(final String nodeID) {
init();
return XML_MAPPING.get(nodeID);
}
public static final String[] getRequiredFields(final String type) {
init();
return REQUIRED_FIELDS.get(type);
}
}

View File

@ -0,0 +1,66 @@
/****************************************************************************
* This software is part of the gCube Project.
* Site: http://www.gcube-system.org/
****************************************************************************
* The gCube/gCore software is licensed as Free Open Source software
* conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
* The software and documentation is provided by its authors/distributors
* "as is" and no expressed or
* implied warranty is given for its use, quality or fitness for a
* particular case.
****************************************************************************
* Filename: Assertion.java
****************************************************************************
* @author <a href="mailto:daniele.strollo@isti.cnr.it">Daniele Strollo</a>
***************************************************************************/
package org.gcube.resourcemanagement.support.shared.util;
import java.io.Serializable;
import com.google.gwt.user.client.rpc.IsSerializable;
/**
* General purpose assertion handler.
* Assertion can be generalized to check a boolean expression and
* to raise an exception in correspondence to a failure happening
* during checking.
* <pre>
* <b>Example:</b>
*
* <b>Assertion</b>&lt;<i>TheExceptionType</i>&gt; assertion = new Assertion&lt;ParamException&gt; ();
* assertion.<b>validate</b> (param != null, new <i>TheExceptionType</i>("invalid parameter null"));
*
* <b>or</b>, in a more compact form:
* <i>// The exception to throw in case of failure
* // during the evaluation of the expected condition</i>
* new <b>Assertion</b>&lt;<i>TheExceptionType</i>&gt;().<b>validate</b>(
* i>5, <i>// The expected boolean <b>condition</b></i>
* new <i>TheExceptionType</i>("Parameter must be greater than 5")); <i>//The <b>error</b> message</i>
*
* </pre>
*
* @author Daniele Strollo (ISTI-CNR)
*/
public class Assertion <T extends Throwable> implements Serializable, IsSerializable {
private static final long serialVersionUID = -2007903339251667541L;
/**
* Makes an assertion and if the expression evaluation fails, throws an
* exception of type T.
* <pre>
* Example:
* new Assertion&lt;MyException&gt;().validate(whatExpected, new MyException("guard failed"));
* </pre>
* @param assertion the boolean expression to evaluate
* @param exc the exception to throw if the condition does not hold
* @throws T the exception extending {@link java.lang.Throwable}
*/
public final void validate(final boolean assertion, final T exc)
throws T {
if (!assertion) {
throw exc;
}
}
}