resource-management-portlet/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/QueryTest.java

56 lines
2.3 KiB
Java

package org.gcube.portlets.admin.resourcemanagement.server;
import java.util.List;
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;
public class QueryTest {
public static void main(String[] args) throws Exception {
List<XMLResult> results = null;
ISClient client = GHNContext.getImplementation(ISClient.class);
GCUBEGenericQuery isQuery = null;
isQuery = client.getQuery(GCUBEGenericQuery.class);
String query = "declare namespace gc = 'http://gcube-system.org/namespaces/common/core/porttypes/GCUBEProvider'; " +
" declare namespace wmns= 'http://gcube-system.org/namespaces/contentmanagement/viewmanager'; " +
" for $outer in collection(\"/db/Properties\")//Document, $res in $outer/Data " +
" where $res/gc:ServiceClass/string() eq 'ContentManagement' and count($res//wmns:View)>0 " +
" and $res/gc:ServiceName/string() eq 'ViewManager'" +
"return " +
" <Resource> " +
" {$outer//Document/ID} " +
" {$outer//Document/Source} " +
" {$outer//Document/SourceKey} " +
" <ServiceClass>{$outer//Document/Data/child::*[local-name()='ServiceClass']/text()}</ServiceClass> " +
" <ServiceName>{$outer//Document/Data/child::*[local-name()='ServiceName']/text()}</ServiceName> " +
" <SubType>{$outer//Document/Data/child::*[local-name()='ServiceClass']/text()}</SubType> " +
" {$outer//Document/TerminationTimeHuman} "+
" {$outer//Document/LastUpdateHuman} " +
" <RI>{$outer//Document/Data/child::*[local-name()='RI']/text()}</RI> " +
" <Type>WSResource</Type> "+
" <scopes>{$outer//Document/Data/child::*[local-name()='Scope']/text()}</scopes> "+
" </Resource>";
System.out.println(query);
isQuery.setExpression(query);
results = client.execute(isQuery, GCUBEScope.getScope("/gcube/devNext"));
for (XMLResult elem : results) {
try {
System.out.println(elem.toString());
} catch (IndexOutOfBoundsException e) {
// ignore exception
}
}
}
}