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

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


    CatalogConfiguration catCfg = appCfg.getCatalogConfiguration();
    StringAttributeMap catParams = catCfg.getParameters();
    LuceneConfig luceneCfg = catCfg.getLuceneConfig();
   
    // API operations
    AsnOperation op = new AsnOperation();
    op.setHandlerClass("com.esri.gpt.server.assertion.handler.AsnApiHandler");
    op.setSubject(new AsnSubject(AsnConstants.APP_URN_PREFIX));
    op.getSubject().setRequiresValuePart(false);
    op.setPredicate(new AsnPredicate(AsnConstants.APP_URN_PREFIX+":assertion:operations"));
    op.setAuthPolicy(new AsnAuthPolicy());
    op.getAuthPolicy().setAuthenticationRequired(false);
    op.getAuthPolicy().setQueryPrincipals(new AsnPrincipals());
    op.getAuthPolicy().getQueryPrincipals().add(AsnConstants.PRINCIPAL_ANY);
    this.operations.add(op);
   
    // root index reference
    String val = Val.chkStr(catParams.getValue("assertion.index.allowNonLocalResourceIds"));
    this.allowNonLocalResourceIds = val.equalsIgnoreCase("true");
View Full Code Here


  private void configureComments(CatalogConfiguration catCfg,
                                 AsnIndexReference indexRef,
                                 String name) {
    StringAttributeMap catParams = catCfg.getParameters();
    AsnOperations ops =  this.operations;
    AsnOperation op;
   
    if (indexRef.getEnabled()) {
     
      int maxLength = Val.chkInt(catParams.getValue("assertion."+name+".maxLength"),4000);
      String valueFilterClass = Val.chkStr(catParams.getValue("assertion."+name+".valueFilterClass"));
      if (valueFilterClass.length() == 0) {
        valueFilterClass = null;
      }
     
      AsnAuthPolicy authForRead = new AsnAuthPolicy();
      authForRead.setAllowNonLocalResourceIds(this.allowNonLocalResourceIds);
      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(
View Full Code Here

   */
  private void configureRatings(CatalogConfiguration catCfg,
                                AsnIndexReference indexRef,
                                String name) {
    AsnOperations ops =  this.operations;
    AsnOperation op;
   
    if (indexRef.getEnabled()) {
     
      AsnAuthPolicy authForRead = new AsnAuthPolicy();
      authForRead.setAllowNonLocalResourceIds(this.allowNonLocalResourceIds);
      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(
View Full Code Here

   */
  public Assertion loadAssertionById(AsnContext context, boolean mustExist)
    throws CorruptIndexException, IOException, AsnInvalidOperationException {
    TermDocs termDocs = null;
    IndexReader reader = null;
    AsnOperation operation = context.getOperation();
    try {
      String assertionId = Val.chkStr(operation.getSubject().getValuePart());
      if (assertionId.length() > 0) {
        reader = this.makeIndexReader();
        termDocs = reader.termDocs();
        termDocs.seek(new Term(AsnConstants.FIELD_SYS_ASSERTIONID,assertionId));
        if (termDocs.next()) {
          Document document = reader.document(termDocs.doc());
          Assertion assertion = operation.getAssertionSet().newAssertion(context,false);
          assertion.load(document);
          return assertion;
        }
      }
    } finally {
      try {if (termDocs != null) termDocs.close();} catch (Exception ef) {}
      this.closeReader(reader);
    }
    if (mustExist) {
      String msg = "This assertion id was not found - "+operation.getSubject().getURN();
      throw new AsnInvalidOperationException(msg);
    }
    return null;
  }
View Full Code Here

   * @param context the assertion operation context
   * @return the previously cast assertion (can be null)
   * @throws Exception if an exception occurs
   */
  public Assertion loadPreviousUserAssertion(AsnContext context) throws Exception {
    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)) {       
      IndexReader reader = null;
      IndexSearcher searcher = null;
      try {
View Full Code Here

   * @return the previously cast assertion (can be null)
   * @throws Exception if an exception occurs
   */
  public Assertion loadPreviousUserAssertion(AsnContext context, IndexSearcher searcher)
    throws Exception {
    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));
View Full Code Here

   * @throws Exception if a processing exception occurs
   */
  public void handle(AsnContext context) throws Exception {
       
    // initialize
    AsnOperation operation = context.getOperation();
    AsnProperty property = operation.getUIResources();
    context.getAuthorizer().authorizeQuery(context);
     
    // get the message broker
    MessageBroker msgBroker = context.getMessageBroker();
    if (msgBroker == null) {
View Full Code Here

   */
  public void handle(AsnContext context) throws Exception {
                
    // if multiple assertions per user per user/subject/predicate are not allowed,
    // throw an exception if a previous assertion exists
    AsnOperation operation = context.getOperation();
    boolean multipleAllowed = operation.getAuthPolicy().getMultiplePerUserSubjectPredicate();
    if (!multipleAllowed) {
      Assertion existing = this.getIndexAdapter().loadPreviousUserAssertion(context);
      if (existing != null) {
        String msg = "An assertion for this subject, predicate and user already exists.";
        throw new AsnInvalidOperationException(msg);
      }
    }
       
    // index the assertion
    Assertion assertion = operation.getAssertionSet().newAssertion(context,true);
    context.getAuthorizer().authorizeCreate(context,assertion);
    this.getIndexAdapter().index(context,assertion);
   
    // return the new assertion subject ID
    String asnPfx = operation.getAssertionSet().getAssertionIdPrefix();
    String msg = asnPfx+":"+assertion.getSystemPart().getAssertionId();
    context.getOperationResponse().generateOkResponse(context,msg);
  }
View Full Code Here

   * @throws Exception if a processing exception occurs
   */
  public void handle(AsnContext context) throws Exception {
   
    // update the assertion
    AsnOperation operation = context.getOperation();
    Assertion assertion = this.getIndexAdapter().loadAssertionById(context,true);
    context.getAuthorizer().authorizeUpdate(context,assertion);
    if (!assertion.getSystemPart().getEnabled()) {
      context.getOperationResponse().generateFailedResponse(context,"The assertion is disabled.");
    } else {
     
      // the user performing the update takes over ownership,
      // update modification timestamp and modification user
      assertion.setUserPart(operation.getUserPart());
      assertion.getSystemPart().setEditTimestamp(new Timestamp(System.currentTimeMillis()));
      assertion.getRdfPart().setValue(operation.getValue().getTextValue());
      this.getIndexAdapter().index(context,assertion);
      context.getOperationResponse().generateOkResponse(context,(String)null);
    }
  }
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 subjectPfx = operation.getSubject().getURNPrefix();
    String predicate = operation.getPredicate().getURN();
   
    // query comments
    if (subjectPfx.endsWith(":assertionid") &&
        predicate.equals("urn:esri:geoportal:comment:query")) {
      Assertion assertion = this.getIndexAdapter().loadAssertionById(context,true);
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.