Package com.caringo.enumerator

Examples of com.caringo.enumerator.ObjectEnumeratorException


    public ObjectEnumerator(String publisherHost, int publisherPort, EnumeratorType enumType) throws IOException, ObjectEnumeratorException {
     
      this(publisherHost, publisherPort);
     
      if (enumType == null) {
        throw new ObjectEnumeratorException("EnumeratorType argument cannot be null");
      }
      this.enumType = enumType;
      this.startScspQueryArgs.setValue(EnumeratorQueryArgs.TYPE.getName(), this.enumType.getName());
    }
View Full Code Here


    public ObjectEnumerator(String publisherHost, int publisherPort, EnumeratorType enumType, String enumUuid) throws IOException, ObjectEnumeratorException {
     
      this(publisherHost, publisherPort, enumType);
     
      if (enumUuid == null) {
        throw new ObjectEnumeratorException("UUID argument cannot be null");
      }
        this.enumUuid = enumUuid;
    }
View Full Code Here

     */
    public EnumeratorResponse start(String channelName) throws ObjectEnumeratorException, ScspExecutionException {
     
      // Throw exception if Object Enumerator session already started
      if (this.enumUuid != null){
        throw new ObjectEnumeratorException("Enumerator session already in progress");
      }
     
      if (this.startScspQueryArgs == null) {
        this.startScspQueryArgs = new ScspQueryArgs();
      }
     
      if (channelName == null) {
        if (this.channelName == null) {
          throw new ObjectEnumeratorException("Channel name cannot be null");
        }
      }
      else {
        this.channelName = channelName;
      }
     
      // Set default timeout in query args if not already there
      if (! startScspQueryArgs.containsName(EnumeratorQueryArgs.TIMEOUT.getName())) {
        this.timeout = ObjectEnumerator.DEFAULT_TIMEOUT;
        startScspQueryArgs.setValue(EnumeratorQueryArgs.TIMEOUT.getName(), timeout.toString());
      }
     
      // Set enumerator type to METADATA if not already set
      // (The Publisher will create a metadata type unless otherwise specified.)
      if (this.enumType == null) {
        this.enumType = EnumeratorType.ENUM_TYPE_METADATA;
        this.startScspQueryArgs.setValue(EnumeratorQueryArgs.TYPE.getName(), EnumeratorType.ENUM_TYPE_METADATA.getName());
      }
      else {
        if (! this.startScspQueryArgs.containsName(EnumeratorQueryArgs.TYPE.getName())) {
          this.startScspQueryArgs.setValue(EnumeratorQueryArgs.TYPE.getName(), EnumeratorType.ENUM_TYPE_METADATA.getName());
        }
        else {
          this.startScspQueryArgs.remove(EnumeratorQueryArgs.TYPE.getName());
          this.startScspQueryArgs.setValue(EnumeratorQueryArgs.TYPE.getName(), this.enumType.getName());
        }
      }
     
        // Empty headers for POST (write) method
        ScspHeaders headers = new ScspHeaders();
        // InputStream - this can be empty but the write method does not accept a null argument
        String emptyString = "";
        ByteArrayInputStream bais = new ByteArrayInputStream(emptyString.getBytes());
       
        // Do the POST
        ScspResponse response = this.scspClient.write(this.channelName, bais, 0L, startScspQueryArgs, headers);
       
        // Check the response code
        if (response.getHttpStatusCode() != 201) {
          throw new ObjectEnumeratorException("Object Enumerator start returned unexpected response code: " + response.getHttpStatusCode()
              + "\nResponse body: " + response.getResponseBody());
        }
       
        // Set the UUID of this Object Enumerator
        if (response.getResponseHeaders().getHeaderValues(ObjectEnumerator.CONTENT_UUID).get(0).toString().length() > 0) {
          this.enumUuid = response.getResponseHeaders().getHeaderValues(ObjectEnumerator.CONTENT_UUID).get(0).toString();
        }
        else {
          throw new ObjectEnumeratorException("Object enumerator start did not return a UUID for the enumerator."
              + "\nResponse headers: " + response.getResponseHeaders().getHeaderMap().toString());
        }
       
        return new EnumeratorResponse(response, this.enumType, EnumeratorAction.ENUM_ACTION_START);
     
View Full Code Here

    public EnumeratorResponse start(String channelName, EnumeratorType enumType, Date startDate, Date endDate,
        Long timeout, String enumName, HashMap<String, String> queryArgs) throws ObjectEnumeratorException, ScspExecutionException {
     
      // Throw exception if Object Enumerator session already started
      if (this.enumUuid != null){
        throw new ObjectEnumeratorException("Enumerator session already in progress");
      }
     
      if (this.startScspQueryArgs == null) {
        this.startScspQueryArgs = new ScspQueryArgs();
      }
     
      if (channelName == null) {
        if (this.channelName == null) {
          throw new ObjectEnumeratorException("Channel name cannot be null");
        }
      }
      else {
        this.channelName = channelName;
      }
     
      // The Publisher defaults to type METADATA
      if (enumType == null) {
        if (! startScspQueryArgs.containsName(EnumeratorQueryArgs.TYPE.getName())){
          this.enumType = EnumeratorType.ENUM_TYPE_METADATA;
          startScspQueryArgs.setValue(EnumeratorQueryArgs.TYPE.getName(), this.enumType.getName());
       
      }
      else {
        this.enumType = enumType;
        if (startScspQueryArgs.containsName(EnumeratorQueryArgs.TYPE.getName())){
          startScspQueryArgs.remove(EnumeratorQueryArgs.TYPE.getName());
        }
        startScspQueryArgs.setValue(EnumeratorQueryArgs.TYPE.getName(), this.enumType.getName());
      }

        if (startDate != null) {
          if (this.enumType.equals(EnumeratorType.ENUM_TYPE_EVENT)) {
            throw new ObjectEnumeratorException("Start and end dates cannot be used with Event type object enumerators");
          }
          else {
            this.startDate= startDate;
            if (startScspQueryArgs.containsName(EnumeratorQueryArgs.START_DATE.getName())){
              startScspQueryArgs.remove(EnumeratorQueryArgs.START_DATE.getName());
            }
            startScspQueryArgs.setValue(EnumeratorQueryArgs.START_DATE.getName(), getDateAsISO8601(this.startDate));
          }
        }
       
        if (endDate != null) {
          if (this.enumType.equals(EnumeratorType.ENUM_TYPE_EVENT)) {
            throw new ObjectEnumeratorException("Start and end dates cannot be used with Event type object enumerators");
          }
          else {
            this.endDate = endDate;
            if (startScspQueryArgs.containsName(EnumeratorQueryArgs.END_DATE.getName())){
              startScspQueryArgs.remove(EnumeratorQueryArgs.END_DATE.getName());
            }
            startScspQueryArgs.setValue(EnumeratorQueryArgs.END_DATE.getName(), getDateAsISO8601(this.endDate));
          }
        }
       
        if (timeout == null) {
          if (! startScspQueryArgs.containsName(EnumeratorQueryArgs.TIMEOUT.getName())){
            this.timeout = ObjectEnumerator.DEFAULT_TIMEOUT;
            startScspQueryArgs.setValue(EnumeratorQueryArgs.TIMEOUT.getName(), this.timeout.toString());
          }
        }
        else {
          this.timeout = timeout;
          if (startScspQueryArgs.containsName(EnumeratorQueryArgs.TIMEOUT.getName())){
            startScspQueryArgs.remove(EnumeratorQueryArgs.TIMEOUT.getName());
          }
          startScspQueryArgs.setValue(EnumeratorQueryArgs.TIMEOUT.getName(), this.timeout.toString());
        }      
       
        if (enumName != null) {
          this.enumName = enumName;
          if (startScspQueryArgs.containsName(EnumeratorQueryArgs.CONTEXT.getName())){
            startScspQueryArgs.remove(EnumeratorQueryArgs.CONTEXT.getName());
          }
          startScspQueryArgs.setValue(EnumeratorQueryArgs.CONTEXT.getName(), this.enumName);
        }
       
        // If there are additional query arguments, add them at the end.
        if (queryArgs != null && queryArgs.size() > 0){
         
          // Validate additional query arguments
          Set<Map.Entry<String, String>> mapSet = queryArgs.entrySet();
         
          for (Iterator<Map.Entry<String, String>> mapSetIter = mapSet.iterator(); mapSetIter.hasNext();){
            Map.Entry<String, String> mapEntry = mapSetIter.next();
            if (! EnumeratorQueryArgs.isValidQueryArgForStart(mapEntry.getKey())){
             
              throw new ObjectEnumeratorException("Invalid query argument passed to start: " + mapEntry.getKey());
            }
          }
         
          startScspQueryArgs.addAll(queryArgs);
        }
View Full Code Here

     */
    public EnumeratorResponse next(Long maxItems, HashMap<String, String> queryArgs) throws ObjectEnumeratorException, ScspExecutionException{
     
      // Get out of here if the enumerator session has not been started
      if (this.enumUuid == null) {
        throw new ObjectEnumeratorException("The Object Enumerator must be started before calling next.");
      }
     
      // Reset scspQueryArgs
      nextScspQueryArgs = new ScspQueryArgs();
     
        // Add maxItems to query arguments
      if (maxItems != null && !(this.enumType.equals(EnumeratorType.ENUM_TYPE_METADATA))) {
       
        // Throw exception if maxItem exceeds the hard limit
        if (maxItems > MAX_ITEMS_LIMIT) {
          throw new ObjectEnumeratorException("The maximum number of items that can be returned by the next method is 10,000.");
        }
        nextScspQueryArgs.setValue(EnumeratorQueryArgs.MAX_ITEMS.getName(), maxItems.toString());
      }
     
      // If there are additional query arguments, add them at the end.
        if (queryArgs != null && queryArgs.size() > 0){
         
          // Validate additional query arguments
          Set<Map.Entry<String, String>> mapSet = queryArgs.entrySet();
         
          for (Iterator<Map.Entry<String, String>> mapSetIter = mapSet.iterator(); mapSetIter.hasNext();){
            Map.Entry<String, String> mapEntry = mapSetIter.next();
            if (! EnumeratorQueryArgs.isValidQueryArgForNext(mapEntry.getKey())){
             
              throw new ObjectEnumeratorException("Invalid query argument passed to next: " + mapEntry.getKey());
            }
          }
                   
          nextScspQueryArgs.addAll(queryArgs);
        }
     
      // Empty ScspHeaders object for GET (read) method
      ScspHeaders headers = new ScspHeaders();
     
      // Do the GET
      // According to Pat the null arguments should work here.
      ScspResponse response = this.scspClient.read(this.enumUuid.toString(), null, null, nextScspQueryArgs, headers);
     
      if (response.getHttpStatusCode() != 200){       
        if (response.getHttpStatusCode() == 404) {        
          throw new ObjectEnumeratorException("Object Enumerator next did not find enumerator with this UUID: " + this.enumUuid.toString());
        }
        else {         
          throw new ObjectEnumeratorException("Object Enumerator next returned an unexpected response code: " + response.getHttpStatusCode()
              + "\nResponse body: " + response.getResponseBody());
        }
      }
     
      return new EnumeratorResponse(response, this.getType(), EnumeratorAction.ENUM_ACTION_NEXT);
View Full Code Here

     * @throws ScspExecutionException
     */
    public EnumeratorResponse end() throws ObjectEnumeratorException, ScspExecutionException {
     
      if (this.enumUuid == null) {
        throw new ObjectEnumeratorException("Cannot end an Object Enumerator session that is not established.");
      }
    
      // Empty query args object for DELETE
      ScspQueryArgs queryArgs = new ScspQueryArgs();
     
      // Empty headers object for DELETE
      ScspHeaders headers = new ScspHeaders();
     
      // Do the DELETE
      ScspResponse response = this.scspClient.delete(this.enumUuid.toString(), null, queryArgs, headers);
     
      if (response.getHttpStatusCode() != 200) {
        throw new ObjectEnumeratorException("Object Enumerator end returned an unexpected response code: " + response.getHttpStatusCode());
      }
     
      // Reset the Object Enumerator properties to their initial state
      this.enumUuid = null;
      this.channelName = null;
View Full Code Here

TOP

Related Classes of com.caringo.enumerator.ObjectEnumeratorException

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.