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

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


      authForRead.setAuthenticationRequired(false);
      authForRead.setQueryPrincipals(new AsnPrincipals());
      authForRead.getQueryPrincipals().add(AsnConstants.PRINCIPAL_ANY);
     
      // create the assertion set
      AsnAssertionSet asnSet = new AsnAssertionSet(name);
      String actionPfx = asnSet.getURNPrefix();
     
      // set the index reference
      asnSet.setIndexReference(indexRef.duplicate());
    
      // set the default authentication/authorization policy
      asnSet.setAuthPolicy(new AsnAuthPolicy());
      asnSet.getAuthPolicy().setAllowNonLocalResourceIds(this.allowNonLocalResourceIds);
      asnSet.getAuthPolicy().setAuthenticationRequired(true);
      asnSet.getAuthPolicy().setCreatePrincipals(new AsnPrincipals());
      asnSet.getAuthPolicy().getCreatePrincipals().add(AsnConstants.PRINCIPAL_ANY);
      asnSet.getAuthPolicy().setDeletePrincipals(new AsnPrincipals());
      asnSet.getAuthPolicy().getDeletePrincipals().add(AsnConstants.PRINCIPAL_OWNER);
      asnSet.getAuthPolicy().getDeletePrincipals().add(AsnConstants.PRINCIPAL_ADMINISTRATOR);
      asnSet.getAuthPolicy().setEnableDisablePrincipals(new AsnPrincipals());
      asnSet.getAuthPolicy().getEnableDisablePrincipals().add(AsnConstants.PRINCIPAL_ADMINISTRATOR);
      asnSet.getAuthPolicy().setUpdatePrincipals(new AsnPrincipals());
      asnSet.getAuthPolicy().getUpdatePrincipals().add(AsnConstants.PRINCIPAL_OWNER);
      asnSet.getAuthPolicy().setQueryPrincipals(new AsnPrincipals());
      asnSet.getAuthPolicy().getQueryPrincipals().add(AsnConstants.PRINCIPAL_ANY);
      asnSet.getAuthPolicy().setMultiplePerUserSubjectPredicate(false);
     
      // value type
      asnSet.setValueType(new AsnValueType());
      asnSet.getValueType().setAnalyzePriorToIndexing(true);
      asnSet.getValueType().setMaxCharacters(maxLength);
      asnSet.getValueType().setRdfPredicate(asnSet.getURNPrefix());
      asnSet.getValueType().setRdfValueField("rdf.comment.value");
      asnSet.getValueType().setRequired(true);
      asnSet.getValueType().setValueFilterClass(valueFilterClass);
      asnSet.getValueType().setValueTypeName(AsnValueType.VALUE_TYPENAME_FREE);
     
      // value
      AsnValue asnValue = new AsnValue();
      asnValue.setValueType(asnSet.getValueType().duplicate());
                 
      // query a comment by assertion id
      op = new AsnOperation(asnSet);
      op.setHandlerClass("com.esri.gpt.server.assertion.handler.AsnCommentHandler");
      op.setSubject(new AsnSubject(asnSet.getAssertionIdPrefix()));
      op.setPredicate(new AsnPredicate(actionPfx+":query"));
      op.setAuthPolicy(authForRead.duplicate());
      ops.add(op);
     
      // query comments associated with a resource
      op = new AsnOperation(asnSet);
      op.setHandlerClass("com.esri.gpt.server.assertion.handler.AsnCommentHandler");
      op.setSubject(new AsnSubject(AsnConstants.SUBJECT_PREFIX_RESOURCEID));
      op.setPredicate(new AsnPredicate(actionPfx+":query"));
      op.setAuthPolicy(authForRead.duplicate());
      ops.add(op);
     
      // create     
      op = new AsnOperation(asnSet);
      op.setHandlerClass("com.esri.gpt.server.assertion.handler.AsnCreateHandler");
      op.setSubject(new AsnSubject(AsnConstants.SUBJECT_PREFIX_RESOURCEID));
      op.setPredicate(new AsnPredicate(actionPfx+":create"));
      op.getAuthPolicy().setMultiplePerUserSubjectPredicate(true);
      op.setValue(asnValue.duplicate());
      ops.add(op);

      // update
      op = new AsnOperation(asnSet);
      op.setHandlerClass("com.esri.gpt.server.assertion.handler.AsnUpdateHandler");
      op.setSubject(new AsnSubject(asnSet.getAssertionIdPrefix()));
      op.setPredicate(new AsnPredicate(actionPfx+":update"));
      op.setValue(asnValue.duplicate());
      ops.add(op);
     
      // delete
      op = new AsnOperation(asnSet);
      op.setHandlerClass("com.esri.gpt.server.assertion.handler.AsnDeleteHandler");
      op.setSubject(new AsnSubject(asnSet.getAssertionIdPrefix()));
      op.setPredicate(new AsnPredicate(actionPfx+":delete"));
      ops.add(op);
     
      // enable
      op = new AsnOperation(asnSet);
      op.setHandlerClass("com.esri.gpt.server.assertion.handler.AsnEnableHandler");
      op.setSubject(new AsnSubject(asnSet.getAssertionIdPrefix()));
      op.setPredicate(new AsnPredicate(actionPfx+":enable"));
      ops.add(op);
     
      // disable
      op = new AsnOperation(asnSet);
      op.setHandlerClass("com.esri.gpt.server.assertion.handler.AsnDisableHandler");
      op.setSubject(new AsnSubject(asnSet.getAssertionIdPrefix()));
      op.setPredicate(new AsnPredicate(actionPfx+":disable"));
      ops.add(op);
     
      // UI resources
      op = new AsnOperation(asnSet);
      op.setHandlerClass("com.esri.gpt.server.assertion.handler.AsnUIResourcesHandler");
      op.setSubject(new AsnSubject(asnSet.getURNPrefix()));
      op.getSubject().setRequiresValuePart(false);
      op.setPredicate(new AsnPredicate(actionPfx+":uiresources"));
      op.setAuthPolicy(authForRead.duplicate());
      ops.add(op);
      AsnProperty uiResources = new AsnProperty(
          asnSet.getURNPrefix(),asnSet.getURNPrefix()+":uiresources",null);
      op.setUIResources(uiResources);
     
      String pfx = asnSet.getURNPrefix()+":uiresource";
      uiResources.getChildren().add(new AsnUIResource(
          pfx+":maxLength",null,""+maxLength));
      uiResources.getChildren().add(new AsnUIResource(
          pfx+":caption","catalog.asn.comment.caption","Comments"));
      uiResources.getChildren().add(new AsnUIResource(
View Full Code Here


    AsnOperation operation = context.getOperation();
    String userKey = Val.chkStr(operation.getUserPart().getKey());
    String username = Val.chkStr(operation.getUserPart().getName());
    boolean isAnonymous = username.equalsIgnoreCase(AsnConstants.ANONYMOUS_USERNAME);
    if (!isAnonymous && (userKey.length() > 0)) { 
      AsnAssertionSet asnSet = operation.getAssertionSet();
      AsnValueType vType = asnSet.getValueType();
      String subject = operation.getSubject().getURN();
      String predicate = vType.getRdfPredicate();
     
      // build a query to match the subject/predicate/user triple
      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 qUserKey = new TermQuery(new Term(AsnConstants.FIELD_USER_KEY,userKey));
      query.add(qSubject,BooleanClause.Occur.MUST);
      query.add(qPredicate,BooleanClause.Occur.MUST);
      query.add(qUserKey,BooleanClause.Occur.MUST);
       
      // make the reader and searcher, execute the search, return the previous assertion
      TopDocs topDocs = searcher.search(query,1);
      ScoreDoc[] scoreDocs = topDocs.scoreDocs;
      if ((scoreDocs != null) && (scoreDocs.length) > 0) {
        Document document = searcher.getIndexReader().document(scoreDocs[0].doc);
        Assertion assertion = asnSet.newAssertion(context,false);
        assertion.load(document);
        return assertion;
      }
    }
    return null;
View Full Code Here

   */
  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));
      if (nextRecord > 0) {
        rootProp.getChildren().add(new AsnProperty(null,queryPfx+":nextRecord",""+nextRecord));
      }

      // canCreate capability for the active user
      String canCreatePred = asnSet.getURNPrefix()+":activeUser:canCreate";
      String canCreateVal = ""+context.getAuthorizer().canCreate(context,asnSet.getAuthPolicy());
      rootProp.getChildren().add(new AsnProperty(null,canCreatePred,canCreateVal));
     
      // process the documents, generate the response
      AsnAssertionRenderer renderer = new AsnAssertionRenderer();
      for (int i=startRecord; i<numDocs; i++) {
        Document document = reader.document(scoreDocs[i].doc);
        Assertion assertion = asnSet.newAssertion(context,false);
        assertion.load(document);
        rootProp.getChildren().add(renderer.makeProperty(context,assertion));
      }
      context.getOperationResponse().generateResponse(context,rootProp.getChildren());
     
View Full Code Here

   */
  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));
      rootProp.getChildren().add( new AsnProperty(null,asnSet.getURNPrefix()+":count",""+(nUp+nDown)));
     
      // canCreate capability for the active user
      String canCreatePred = asnSet.getURNPrefix()+":activeUser:canCreate";
      String canCreateVal = ""+context.getAuthorizer().canCreate(context,asnSet.getAuthPolicy());
      rootProp.getChildren().add(new AsnProperty(null,canCreatePred,canCreateVal));
     
      // user's previous rating
      Assertion previous = this.getIndexAdapter().loadPreviousUserAssertion(context,searcher);
      if (previous != null) {
        String prevSubj = Val.chkStr(previous.getSystemPart().getAssertionId());
        prevSubj = asnSet.getAssertionIdPrefix()+":"+prevSubj;
        String predPred = asnSet.getURNPrefix()+":activeUser:previousValue";
        String prevVal = previous.getRdfPart().getValue();
        rootProp.getChildren().add(new AsnProperty(prevSubj,predPred,prevVal));
      }
     
      // generate the response
View Full Code Here

      authForRead.setAuthenticationRequired(false);
      authForRead.setQueryPrincipals(new AsnPrincipals());
      authForRead.getQueryPrincipals().add(AsnConstants.PRINCIPAL_ANY);
     
      // create the assertion set
      AsnAssertionSet asnSet = new AsnAssertionSet(name);
      String actionPfx = asnSet.getURNPrefix();
     
      // set the index reference
      asnSet.setIndexReference(indexRef.duplicate());
    
      // set the default authentication/authorization policy
      asnSet.setAuthPolicy(new AsnAuthPolicy());
      asnSet.getAuthPolicy().setAllowNonLocalResourceIds(this.allowNonLocalResourceIds);
      asnSet.getAuthPolicy().setAuthenticationRequired(true);
      asnSet.getAuthPolicy().setCreatePrincipals(new AsnPrincipals());
      asnSet.getAuthPolicy().getCreatePrincipals().add(AsnConstants.PRINCIPAL_ANY);
      asnSet.getAuthPolicy().setDeletePrincipals(new AsnPrincipals());
      asnSet.getAuthPolicy().getDeletePrincipals().add(AsnConstants.PRINCIPAL_OWNER);
      asnSet.getAuthPolicy().setEnableDisablePrincipals(null);
      asnSet.getAuthPolicy().setUpdatePrincipals(new AsnPrincipals());
      asnSet.getAuthPolicy().getUpdatePrincipals().add(AsnConstants.PRINCIPAL_OWNER);
      asnSet.getAuthPolicy().setQueryPrincipals(new AsnPrincipals());
      asnSet.getAuthPolicy().getQueryPrincipals().add(AsnConstants.PRINCIPAL_ANY);
      asnSet.getAuthPolicy().setMultiplePerUserSubjectPredicate(false);
     
      // value type
      asnSet.setValueType(new AsnValueType());
      asnSet.getValueType().setAnalyzePriorToIndexing(false);
      asnSet.getValueType().setRequired(true);
      asnSet.getValueType().setRdfPredicate(asnSet.getURNPrefix());
      asnSet.getValueType().setRdfValueField("rdf.rating.value");
      asnSet.getValueType().setValueTypeName(AsnValueType.VALUE_TYPENAME_CONSTRAINED);
      AsnSupportedValues supported = new AsnSupportedValues();
      supported.add("urn:esri:geoportal:rating:value:up");
      supported.add("urn:esri:geoportal:rating:value:down");
      asnSet.getValueType().setSupportedValues(supported);
     
      // value
      AsnValue asnValue = new AsnValue();
      asnValue.setValueType(asnSet.getValueType().duplicate());
           
      // query ratings associated with a resource
      op = new AsnOperation(asnSet);
      op.setHandlerClass("com.esri.gpt.server.assertion.handler.AsnRatingHandler");
      op.setSubject(new AsnSubject(AsnConstants.SUBJECT_PREFIX_RESOURCEID));
      op.setPredicate(new AsnPredicate(actionPfx+":query"));
      op.setAuthPolicy(authForRead.duplicate());
      ops.add(op);
     
      // create
      op = new AsnOperation(asnSet);
      op.setHandlerClass("com.esri.gpt.server.assertion.handler.AsnCreateHandler");
      op.setSubject(new AsnSubject(AsnConstants.SUBJECT_PREFIX_RESOURCEID));
      op.setPredicate(new AsnPredicate(actionPfx+":create"));
      op.setValue(asnValue.duplicate());
      ops.add(op);
     
      // update
      op = new AsnOperation(asnSet);
      op.setHandlerClass("com.esri.gpt.server.assertion.handler.AsnUpdateHandler");
      op.setSubject(new AsnSubject(asnSet.getAssertionIdPrefix()));
      op.setPredicate(new AsnPredicate(actionPfx+":update"));
      op.setValue(asnValue.duplicate());
      ops.add(op);
     
      // delete
      op = new AsnOperation(asnSet);
      op.setHandlerClass("com.esri.gpt.server.assertion.handler.AsnDeleteHandler");
      op.setSubject(new AsnSubject(asnSet.getAssertionIdPrefix()));
      op.setPredicate(new AsnPredicate(actionPfx+":delete"));
      ops.add(op);
     
      // UI resources
      op = new AsnOperation(asnSet);
      op.setHandlerClass("com.esri.gpt.server.assertion.handler.AsnUIResourcesHandler");
      op.setSubject(new AsnSubject(asnSet.getURNPrefix()));
      op.getSubject().setRequiresValuePart(false);
      op.setPredicate(new AsnPredicate(actionPfx+":uiresources"));
      op.setAuthPolicy(authForRead.duplicate());
      ops.add(op);
      AsnProperty uiResources = new AsnProperty(
          asnSet.getURNPrefix(),asnSet.getURNPrefix()+":uiresources",null);
      op.setUIResources(uiResources);
     
      String pfx = asnSet.getURNPrefix()+":uiresource";
      uiResources.getChildren().add(new AsnUIResource(
          pfx+":caption","catalog.asn.rating.caption","User ratings for this resource:"));
      uiResources.getChildren().add(new AsnUIResource(
          pfx+":totalUpTip","catalog.asn.rating.totalUpTip","Up votes"));
      uiResources.getChildren().add(new AsnUIResource(
View Full Code Here

TOP

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

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.