diff --git a/src/main/java/org/gcube/resources/discovery/icclient/Helper.java b/src/main/java/org/gcube/resources/discovery/icclient/Helper.java index b3ea262..7e49d2f 100644 --- a/src/main/java/org/gcube/resources/discovery/icclient/Helper.java +++ b/src/main/java/org/gcube/resources/discovery/icclient/Helper.java @@ -25,16 +25,17 @@ public class Helper { { String scope = ScopeProvider.instance.get(); + System.out.println("inside filter"); if (scope==null || !new ScopeBean(scope).is(VRE)) return expression; - + System.out.println("filtering"); int wherePathIndex=0; int returnPathIndex=0; int collIndexEnd=0; int collIndexStart=0; - boolean whereFinded=false; + boolean whereFound=false; String forInsertFinal=""; String whereInsertFinal=""; String temp=""; @@ -44,8 +45,8 @@ public class Helper { String forPropertiesString="\n *VAR* in *COLLECTION*/Data \n"; ///child::*[local-name()='Scope'] String forString=" *VAR* in *COLLECTION*/Scopes \n"; - String authString=" (*VAR*/child::*[local-name()='Scope']/text() eq '"+scope+"' or *VAR*/child::*[local-name()='Scope']/text() eq '"+scope.substring(0,scope.lastIndexOf("/"))+"') "; - String authStringNormal=" (*VAR*//Scope/text() eq '"+scope+"') "; + String authString=" (functx:is-value-in-sequence('"+scope+"',*VAR*/child::*[local-name()='Scope']/text()) or functx:is-value-in-sequence('"+scope.substring(0,scope.lastIndexOf("/"))+"',*VAR*/child::*[local-name()='Scope']/text())) "; + String authStringNormal=" (functx:is-value-in-sequence('"+scope+"',*VAR*//Scope/text())) "; String queryFiltered; List collInsert= new ArrayList(); @@ -134,7 +135,7 @@ public class Helper { Matcher returnMat=returnPattern.matcher(expression); whereMat.reset(); returnMat.reset(); - whereFinded=whereMat.find(); + whereFound=whereMat.find(); returnMat.find(); try{ @@ -148,7 +149,7 @@ public class Helper { returnPathIndex=returnMat.start(); }catch(IllegalStateException e){ log.error("error parsing return statement"); throw new MalformedQueryException("error parsing return statement");} - if (whereFinded) + if (whereFound) queryFiltered=expression.substring(0,wherePathIndex)+"\nwhere "+whereInsertFinal +" and ("+expression.substring(wherePathIndex+5, returnPathIndex)+" ) \n"+expression.substring(returnPathIndex); else @@ -162,16 +163,22 @@ public class Helper { whereMat.reset(); whereMat.find(); - boolean letFinded=letMat.find(collIndexStart); + boolean letFound=letMat.find(collIndexStart); int letPathIndex=0; try{ wherePathIndex=whereMat.start(); - if (letFinded) letPathIndex=letMat.start(); + if (letFound) letPathIndex=letMat.start(); }catch(IllegalStateException e){ log.error("error parsing let statement"); throw new MalformedQueryException("error parsing let statement");} + int indexOfFor = queryFiltered.indexOf("for "); - if (!letFinded) { + String functionContainsDeclaration =" declare namespace functx = \"http://www.functx.com\"; declare function functx:is-value-in-sequence "+ + " ( $value as xs:anyAtomicType? , $seq as xs:anyAtomicType* ) as xs:boolean { $value = $seq } ; \n"; + + queryFiltered = queryFiltered.substring(0,indexOfFor)+functionContainsDeclaration+queryFiltered.substring(indexOfFor); + + if (!letFound) { queryFiltered=queryFiltered.substring(0,wherePathIndex)+forInsertFinal +queryFiltered.substring(wherePathIndex); } else { @@ -202,7 +209,7 @@ public class Helper { */ log.trace("submitting filtered query: {}",queryFiltered); - + System.out.println("filtering "+queryFiltered); return queryFiltered; } diff --git a/src/test/java/org/acme/StubClient.java b/src/test/java/org/acme/StubClient.java index 1ddc07b..638ed03 100644 --- a/src/test/java/org/acme/StubClient.java +++ b/src/test/java/org/acme/StubClient.java @@ -9,10 +9,14 @@ import java.net.URI; import javax.xml.ws.soap.SOAPFaultException; import org.gcube.common.clients.stubs.jaxws.JAXWSUtils; +import org.gcube.common.resources.gcore.GCoreEndpoint; import org.gcube.common.resources.gcore.ServiceEndpoint; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ServiceMap; +import org.gcube.resources.discovery.client.queries.api.Query; import org.gcube.resources.discovery.client.queries.api.SimpleQuery; +import org.gcube.resources.discovery.client.queries.impl.QueryBox; +import org.gcube.resources.discovery.icclient.Helper; import org.gcube.resources.discovery.icclient.stubs.CollectorStub; public class StubClient { @@ -23,18 +27,31 @@ public class StubClient { //when needed, setup tcpmon and decomment to see messages on the wire for debugging purposes //StubFactory.setProxy("localhost", 8081); - ScopeProvider.instance.set("/gcube/devsec"); + ScopeProvider.instance.set("/gcube/devNext/NextNext"); String address = ServiceMap.instance.endpoint(localname); CollectorStub proxy = stubFor(collector).at(URI.create(address)); - SimpleQuery query = queryFor(ServiceEndpoint.class); - + SimpleQuery query = queryFor(GCoreEndpoint.class); + /* + String queryString ="declare namespace ic = 'http://gcube-system.org/namespaces/informationsystem/registry'; declare namespace functx = \"http://www.functx.com\"; "+ + "declare function functx:is-value-in-sequence "+ + " ( $value as xs:anyAtomicType? , $seq as xs:anyAtomicType* ) as xs:boolean { $value = $seq } ;"; + + queryString+=" for $entry0ValueAuth in collection('/db/Profiles/RunningInstance')//Document/Data/ic:Profile/Resource/Scopes "+ + " where functx:is-value-in-sequence('/gcube/devNext/NextNext',$entry0ValueAuth/child::*[local-name()='Scope']/text()) or functx:is-value-in-sequence('/gcube/devNext',$entry0ValueAuth/child::*[local-name()='Scope']/text()) and ( ($entry0ValueAuth/../Profile/ServiceClass/text() eq 'DataAccess') and ($entry0ValueAuth/../Profile/DeploymentData/Status/text() eq 'ready') and ($entry0ValueAuth/../Profile/ServiceName/text() eq 'CkanConnector') ) "+ + " return $entry0ValueAuth/../Profile/AccessPoint/RunningInstanceInterfaces//Endpoint[@EntryName/string() eq \"org.gcube.data.access.ckanconnector.CkanConnector\"]/text()"; + */ + + //Query query = new QueryBox(queryString); + + + try { System.out.println(query.expression()); - String response = proxy.execute(query.expression()); + String response = proxy.execute(Helper.queryAddAuthenticationControl(query.expression())); System.err.println(response); } catch(SOAPFaultException e) {