Package com.esri.gpt.server.assertion.components

Examples of com.esri.gpt.server.assertion.components.AsnOperation


   * @throws Exception if an exception occurs
   */
  private void query(AsnContext context) throws Exception {
   
    // initialize
    AsnOperation operation = context.getOperation();
    AsnAssertionSet asnSet = operation.getAssertionSet();
    AsnValueType vType = asnSet.getValueType();
    String subject = operation.getSubject().getURN();
    String predicate = vType.getRdfPredicate();   
   
    // build a query to match all occurrences of the subject/predicate pair
    BooleanQuery query = new BooleanQuery();
    Query qSubject = new TermQuery(new Term(AsnConstants.FIELD_RDF_SUBJECT,subject));
    Query qPredicate = new TermQuery(new Term(AsnConstants.FIELD_RDF_PREDICATE,predicate));
    query.add(qSubject,BooleanClause.Occur.MUST);
    query.add(qPredicate,BooleanClause.Occur.MUST);
   
    // sort on descending timestamp
    String tsField = AsnConstants.FIELD_SYS_TIMESTAMP;
    Sort sortOption = new Sort(new SortField(tsField,SortField.STRING,true));
   
    // determine the start and end positions
    int startRecord = context.getRequestOptions().getStartRecord() - 1;
    int maxRecords = context.getRequestOptions().getMaxRecords();
    if (startRecord < 0) startRecord = 0;
    int recordsPerPage = maxRecords;
    if (recordsPerPage <= 0) recordsPerPage = 1;
    int hitsToReturn = startRecord + recordsPerPage;
    int nextRecord = 0;
    int numDocs = 0;
   
    IndexReader reader = null;
    IndexSearcher searcher = null;
    try {
     
      // make the reader and searcher, execute the search
      reader = this.getIndexAdapter().makeIndexReader();
      searcher = new IndexSearcher(reader);
      TopDocs topDocs = searcher.search(query,null,hitsToReturn,sortOption);
      ScoreDoc[] scoreDocs = null;
      int totalHits = topDocs.totalHits;
      if (maxRecords > 0) {
        scoreDocs = topDocs.scoreDocs;
        if ((scoreDocs != null) && (scoreDocs.length) > 0) {
          numDocs = scoreDocs.length;
          if (totalHits > numDocs) {
            nextRecord = numDocs + 1;
          }
        }
      }
     
      // root property for the response
      String rootSubject = subject;
      String roorPredicate = operation.getPredicate().getURN()+"response";
      AsnProperty rootProp = new AsnProperty(rootSubject,roorPredicate,null);
     
      // hit count and next record
      String queryPfx = asnSet.getURNPrefix()+":query";
      rootProp.getChildren().add(new AsnProperty(null,queryPfx+":hits",""+totalHits));
View Full Code Here


   * @throws Exception if a processing exception occurs
   */
  public void handle(AsnContext context) throws Exception {
       
    // initialize
    AsnOperation operation = context.getOperation();
    AsnAuthorizer authorizer = context.getAuthorizer();
    String predicate = operation.getPredicate().getURN();
   
    // query ratings for a resource
    if (predicate.equals("urn:esri:geoportal:rating:query")) {
      if (!operation.getSubject().isType(AsnConstants.SUBJECT_PREFIX_RESOURCEID)) {
        throw new AsnInvalidOperationException();
      }
      authorizer.authorizeQuery(context);
      this.query(context);
    }
View Full Code Here

   * @throws Exception if an exception occurs
   */
  private void query(AsnContext context) throws Exception {
   
    // initialize
    AsnOperation operation = context.getOperation();
    AsnAssertionSet asnSet = operation.getAssertionSet();
    AsnValueType vType = asnSet.getValueType();
    String subject = operation.getSubject().getURN();
    String predicate = vType.getRdfPredicate();
    String valueField = vType.getRdfValueField();
    String upValue = "urn:esri:geoportal:rating:value:up";
    String downValue = "urn:esri:geoportal:rating:value:down";
   
    IndexReader reader = null;
    IndexSearcher searcher = null;
    try {
     
      // make the reader and searcher
      reader = this.getIndexAdapter().makeIndexReader();
      searcher = new IndexSearcher(reader);
     
      // count up votes
     long nUp = this.getIndexAdapter().count(
          context,searcher,valueField,subject,predicate,upValue);
     
      // count down votes
      long nDown = this.getIndexAdapter().count(
          context,searcher,valueField,subject,predicate,downValue);
     
      // root property for the response
      String rootSubject = subject;
      String roorPredicate = operation.getPredicate().getURN()+"response";
      AsnProperty rootProp = new AsnProperty(rootSubject,roorPredicate,null);
       
      // up, down and total counts
      rootProp.getChildren().add(new AsnProperty(null,upValue+":count",""+nUp));
      rootProp.getChildren().add(new AsnProperty(null,downValue+":count",""+nDown));
View Full Code Here

   */
  public AsnOperationHandler makeOperationHandler(AsnContext context) throws Exception {
       
    // determine the operation, make the operation handler
    AsnConfig config = this.getConfiguration();
    AsnOperation operation = config.getOperations().makeOperation(context);
    context.setOperation(operation);
    AsnOperationHandler opHandler = operation.makeHandler(context);
    if (operation.getIndexReference() != null) {
      if (!operation.getIndexReference().getEnabled()) {
        String msg = "This index is disabled: "+operation.getIndexReference().getName();
        throw new AsnInvalidOperationException(msg);
      }
      opHandler.setIndexAdapter(operation.getIndexReference().makeIndexAdapter(context));
    }
   
    // establish the system part
    if (operation.getSystemPart() == null) {
      operation.setSystemPart(new AsnSystemPart());
    }
    AsnSubject subject = operation.getSubject();
    String subjectPfx = Val.chkStr(subject.getURNPrefix());
    if (subjectPfx.equals(AsnConstants.SUBJECT_PREFIX_RESOURCEID)) {
      operation.getSystemPart().setResourceId(subject.getValuePart());
    }
   
    // establish the user part
    context.getAuthorizer().establishUser(context);
     
View Full Code Here

TOP

Related Classes of com.esri.gpt.server.assertion.components.AsnOperation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.