All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.symphony.oss.models.fundmental.canon.ObjectsObjectHashAsyncPathHandler Maven / Gradle / Ivy

/**
 * GENERATED CODE - DO NOT EDIT OR CHECK IN TO SOURCE CODE CONTROL
 *
 * Copyright 2020 Symphony Communication Services, LLC.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *----------------------------------------------------------------------------------------------------
 * Generated from
 *    Input source         file:/Users/bruce/symphony/git-SymphonyOSF/oss-models/target/checkout/fundamental-model/src/main/resources/canon/fundamental.json
 *    Template groupId     org.symphonyoss.s2.canon
 *           artifactId    canon-template-java
 *    Template name        template/java/Path/_AsyncPathHandler.java.ftl
 *    At                   2020-01-28 16:55:36 GMT
 *----------------------------------------------------------------------------------------------------
 */

package com.symphony.oss.models.fundmental.canon;

import java.io.IOException;
import java.io.StringReader;

import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.concurrent.ExecutorService;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

import javax.servlet.AsyncContext;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;

import org.symphonyoss.s2.common.dom.json.ImmutableJsonObject;
import org.symphonyoss.s2.common.dom.json.JsonValue;

import org.symphonyoss.s2.canon.runtime.AsyncPathHandler;
import org.symphonyoss.s2.canon.runtime.EmptyRequestManager;
import org.symphonyoss.s2.canon.runtime.PayloadOnlyRequestManager;
import org.symphonyoss.s2.canon.runtime.PayloadResponseRequestManager;
import org.symphonyoss.s2.canon.runtime.ResponseOnlyRequestManager;
import org.symphonyoss.s2.canon.runtime.ModelRegistry;
import org.symphonyoss.s2.canon.runtime.exception.BadRequestException;
import org.symphonyoss.s2.canon.runtime.exception.CanonException;
import org.symphonyoss.s2.canon.runtime.exception.NotFoundException;
import org.symphonyoss.s2.canon.runtime.exception.PermissionDeniedException;
import org.symphonyoss.s2.canon.runtime.exception.ServerErrorException;
import org.symphonyoss.s2.canon.runtime.http.IRequestAuthenticator;
import org.symphonyoss.s2.canon.runtime.http.ParameterLocation;
import org.symphonyoss.s2.canon.runtime.http.IAsyncRequestContext;
import org.symphonyoss.s2.fugue.pipeline.IConsumer;

import org.symphonyoss.s2.common.immutable.ImmutableByteArray;
import org.symphonyoss.s2.common.hash.Hash;
import com.symphony.oss.models.fundamental.canon.facade.*;
import com.symphony.oss.models.crypto.canon.facade.*;
import com.symphony.oss.models.crypto.canon.*;
import com.symphony.oss.models.core.canon.facade.*;
import com.symphony.oss.models.core.canon.*;

/**
 * Path name=ObjectsObjectHash
 *
 * Path					/objects/{objectHash}
 * Bind Path			objects/
 */
@Immutable
@SuppressWarnings("unused")
public abstract class ObjectsObjectHashAsyncPathHandler extends AsyncPathHandler implements IObjectsObjectHashAsyncPathHandler
{
  public ObjectsObjectHashAsyncPathHandler(
    ExecutorService processExecutor,
    ExecutorService responseExecutor,
    @Nullable IRequestAuthenticator authenticator)
  {
    super(processExecutor, responseExecutor, authenticator, 1, new String[] {
        "/object/fundamental/v1/objects/"      }
    );
  }

  @Override
  public String getPath()
  {
    return "/object/fundamental/v1/objects/{objectHash}";
  }

  @Override
  public void handle(A auth, IAsyncRequestContext context, List pathParams) throws IOException, CanonException
  {
    switch(context.getMethod())
    {
      case Post:
      case Delete:
      case Options:
      case Head:
      case Trace:
        unsupportedMethod(auth, context);
        break;
        
      case Get:
        doGet(auth, context, pathParams);
        break;
        
      case Put:
        doPut(auth, context, pathParams);
        break;
        
    }
  }
  
  
  private void doGet(A auth, IAsyncRequestContext context, List pathParams) throws IOException, CanonException
  {
    Iterator it = pathParams.iterator();
  
    // We have already checked that there are the correct number of parameters
      
    ImmutableByteArray        objectHashValue = context.asImmutableByteArray("objectHash", it.next());
    Hash                      objectHash = null;

    try
    {
      objectHash = Hash.build(objectHashValue);
    }
    catch(NullPointerException | IllegalArgumentException e)
    {
      context.error("Parameter \"objectHash\" has invalid value \"%s\" (%s)", objectHashValue, e.getMessage());
    }
    
    
  

    Boolean                   currentVersionValue = context.getParameterAsBoolean("currentVersion", ParameterLocation.Query, false);
    Boolean                   currentVersion = null; 
    
    if(currentVersionValue != null)
    {
      currentVersion = currentVersionValue;
    }


    ImmutableByteArray        traceContextHashValue = context.getParameterAsImmutableByteArray("traceContextHash", ParameterLocation.Query, false);
    Hash                      traceContextHash = null; 
    
    if(traceContextHashValue != null)
    {
      try
      {
        traceContextHash = Hash.build(traceContextHashValue);
      }
      catch(NullPointerException | IllegalArgumentException e)
      {
        context.error("Parameter \"traceContextHash\" has invalid value \"%s\" (%s)", traceContextHashValue, e.getMessage());
      }
    }


  
    if(context.preConditionsAreMet())
    {
      ServletInputStream in = context.getInputStream();
      ServletOutputStream out = context.getOutputStream();
      AsyncContext async=context.startAsync();

        final Boolean                   finalCurrentVersion = currentVersion; 
        final Hash                      finalTraceContextHash = traceContextHash; 
        final Hash                      finalObjectHash = objectHash; 
      
      // Method has no Payload but does have a Response
      ResponseOnlyRequestManager manager =
        new ResponseOnlyRequestManager(in, out, auth, context.getTrace(), async, getProcessExecutor(), getResponseExecutor())
      {
        @Override
        public void handle(IConsumer consumer) throws CanonException
        {
          handleGet(consumer, getAuth(), getTrace(),
            finalCurrentVersion,
            finalTraceContextHash,
            finalObjectHash
          );
        }
      };
      
      out.setWriteListener(manager);
      
      manager.start();
    }
  }
  
  
  private void doPut(A auth, IAsyncRequestContext context, List pathParams) throws IOException, CanonException
  {
    Iterator it = pathParams.iterator();
  
    // We have already checked that there are the correct number of parameters
      
    ImmutableByteArray        objectHashValue = context.asImmutableByteArray("objectHash", it.next());
    Hash                      objectHash = null;

    try
    {
      objectHash = Hash.build(objectHashValue);
    }
    catch(NullPointerException | IllegalArgumentException e)
    {
      context.error("Parameter \"objectHash\" has invalid value \"%s\" (%s)", objectHashValue, e.getMessage());
    }
    
    
  

    ImmutableByteArray        traceContextHashValue = context.getParameterAsImmutableByteArray("traceContextHash", ParameterLocation.Query, false);
    Hash                      traceContextHash = null; 
    
    if(traceContextHashValue != null)
    {
      try
      {
        traceContextHash = Hash.build(traceContextHashValue);
      }
      catch(NullPointerException | IllegalArgumentException e)
      {
        context.error("Parameter \"traceContextHash\" has invalid value \"%s\" (%s)", traceContextHashValue, e.getMessage());
      }
    }


  
    if(context.preConditionsAreMet())
    {
      ServletInputStream in = context.getInputStream();
      ServletOutputStream out = context.getOutputStream();
      AsyncContext async=context.startAsync();

        final Hash                      finalTraceContextHash = traceContextHash; 
        final Hash                      finalObjectHash = objectHash; 
      
      // Method has a Payload but no Response
      PayloadOnlyRequestManager manager =
        new PayloadOnlyRequestManager(in, out, auth, context.getTrace(), async, getProcessExecutor())
      {
        @Override
        public void handle(@Nonnull IFundamentalObject payload) throws CanonException
        {
          handlePut(payload, getAuth(), getTrace(),
        finalTraceContextHash,
        finalObjectHash
          );
        }
  
        @Override
        protected IFundamentalObject parsePayload(String request)
        {
          return context.parsePayload(FundamentalObject.TYPE_ID, IFundamentalObject.class);
        }
      };
      
      in.setReadListener(manager);
    }
  }
}
/*----------------------------------------------------------------------------------------------------
 * End of template template/java/Path/_AsyncPathHandler.java.ftl
 * End of code generation
 *------------------------------------------------------------------------------------------------- */




© 2015 - 2025 Weber Informatics LLC | Privacy Policy