Quantcast
Channel: PTC Community : Discussion List - Windchill
Viewing all articles
Browse latest Browse all 5797

Access is not permitted to advanced query capabilities

$
0
0

Hello ,

 

I'm writing advanced API Query to fetch the all parts latest version and iteration but I'm unable to execute the query. Here my code:

import wt.fc.QueryResult;
import wt.inf.library.WTLibrary;
import wt.part.WTPart;
import wt.part.WTPartMaster;
import wt.query.ClassAttribute;
import wt.query.OrderBy;
import wt.query.QueryException;
import wt.query.QuerySpec;
import wt.query.SQLFunction;
import wt.query.SearchCondition;
import wt.query.SubSelectExpression;


/**
 *
 * @author mgangappa
 */
public class Extractor {


    public static void main(String[] args) {        Extractor ex = new Extractor();               ex.getAllPartsLatestVersionAndIteration();    }          public void getAllPartsLatestVersionAndIteration() {        try {            final QuerySpec qs = new QuerySpec();            qs.setAdvancedQueryEnabled(true);                                  final int lib = qs.addClassList(WTLibrary.class, false);            final int masterIndex = qs.addClassList(WTPartMaster.class, false);            final int partIndex = qs.addClassList(WTPart.class, true);                                  final QuerySpec subSelect = new QuerySpec();            final int partSubInt = subSelect.appendClassList(WTPart.class, false);                       final SQLFunction max = SQLFunction.newSQLFunction(SQLFunction.MAXIMUM, new ClassAttribute(WTPart.class, "iterationInfo.branchId"));                                              subSelect.appendSelect(new ClassAttribute(WTPart.class, "masterReference.key.id"), new int[]{partSubInt}, true);                                                          subSelect.appendSelect(max, new int[]{partSubInt}, true);               subSelect.setAdvancedQueryEnabled(true);                       subSelect.appendGroupBy(new ClassAttribute(WTPart.class, "masterReference.key.id"), new int[]{partSubInt}, true);                                                                             qs.appendWhere(new SearchCondition(WTLibrary.class, WTLibrary.NAME, SearchCondition.NOT_LIKE, "%test%"), new int[]{lib});                       qs.appendAnd();                       qs.appendWhere(new SearchCondition(WTPartMaster.class, "containerReference.key.id", WTLibrary.class, "thePersistInfo.theObjectIdentifier.id"), new int[]{masterIndex, lib});                       qs.appendAnd();                       qs.appendWhere(new SearchCondition(WTPart.class, "masterReference.key.id", WTPartMaster.class, "thePersistInfo.theObjectIdentifier.id"), new int[]{partIndex, masterIndex});                       qs.appendAnd();                       qs.appendWhere(new SearchCondition(WTPart.class, WTPart.LATEST_ITERATION, SearchCondition.EQUAL, true), new int[]{partIndex});                       qs.appendAnd();            final SubSelectExpression inList = new SubSelectExpression(subSelect);            inList.setAccessControlRequired(false);            qs.appendWhere(new SearchCondition(new ClassAttribute(WTPart.class, "iterationInfo.branchId"), SearchCondition.IN, inList), new int[]{partIndex});                       qs.appendOrderBy(new OrderBy(new ClassAttribute(WTPartMaster.class, WTPartMaster.NUMBER), true), new int[] {masterIndex});                       QueryResult qr = ExecuteQueryInServerContext.executeAdvanceQueryInServer(qs, "executeQuery");                               } catch (QueryException ex) {            ex.printStackTrace();        }    }
}

 

I'm executing it in the RemoteMethodServer.invoke (see below code):

 

import java.lang.reflect.InvocationTargetException;
import java.rmi.RemoteException;
import wt.fc.PersistenceHelper;
import wt.fc.PersistenceServerHelper;
import wt.fc.QueryResult;
import wt.method.RemoteAccess;
import wt.method.RemoteMethodServer;
import wt.pds.StatementSpec;
import wt.query.QuerySpec;
import wt.util.WTException;


/**
 *
 * @author mgangappa
 */
public class ExecuteQueryInServerContext implements RemoteAccess {


    public static QueryResult executeAdvanceQueryInServer(QuerySpec query, String method) {        Class[] pClasses = new Class[1];        pClasses[0] = QuerySpec.class;        Object[] pObjects = new Object[1];        if (query == null) {            return null;        } else {            pObjects[0] = query;        }        try {            return (QueryResult) RemoteMethodServer.getDefault().invoke(method, ExecuteQueryInServerContext.class.getName(), null, pClasses, pObjects);        } catch (RemoteException ex) {            ex.printStackTrace();        } catch (InvocationTargetException ex) {            ex.printStackTrace();        }        return null;    }    public static QueryResult executeQuery(QuerySpec qs) throws WTException {         System.out.println("executeQuery => PersistenceServerHelper ");        QueryResult result = PersistenceServerHelper.manager.query(qs);               return result;    }       public static QueryResult executeQueryManager(QuerySpec qs) throws WTException {               QueryResult result = PersistenceHelper.manager.find((StatementSpec) qs);               return result;    }

}

 

 

But I'm keep getting the below error:

 

nServerContext, executeQuery, , 0, 0, 0.0, 0, 0.0, 0.01, 0.007444714
(wt.pds.pdsResource/23) wt.pds.AdvancedQueryAccessException:
Access is not permitted to advanced query capabilities.  at wt.pds.SQLDatabasePds.query(SQLDatabasePds.java:616)  at wt.pom.PersistentObjectManager.query(PersistentObjectManager.java:1108)  at wt.pom.PersistentObjectManager.query(PersistentObjectManager.java:1017)  at wt.fc.StandardPersistenceManager._query(StandardPersistenceManager.java:1878)  at wt.fc.StandardPersistenceManager.query(StandardPersistenceManager.java:1417)  at wt.fc.StandardPersistenceManager.query(StandardPersistenceManager.java:1301)  at com.google.extractor.ExecuteQueryInServerContext.executeQuery(ExecuteQueryInServerContext.java:50)

 

 

What I'm doing wrong? Do I need to set or change config?

 

Thanks,

Manjunath Reddy


Viewing all articles
Browse latest Browse all 5797

Latest Images

Trending Articles



Latest Images