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

org.jclouds.rackspace.clouddns.v1.domain.Job Maven / Gradle / Ivy

There is a newer version: 2.6.0
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.
 */
package org.jclouds.rackspace.clouddns.v1.domain;

import static com.google.common.base.Objects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;

import java.beans.ConstructorProperties;


import com.google.common.base.Optional;

/**
 * @see CloudDNSApi#getJob(String)
 */
public class Job {
   private final String id;
   private final Status status;
   private final Optional error;
   private final Optional resource;
   
   private Job(String id, Status status, Optional error, Optional resource) {
      this.id = id;
      this.status = status;
      this.error = error;
      this.resource = resource;
   }

   public String getId() {
      return id;
   }

   public Status getStatus() {
      return status;
   }

   public Optional getError() {
      return error;
   }

   public Optional getResource() {
      return resource;
   }

   public enum Status {
      /**
       * INITIALIZED is the status that immediately precedes RUNNING and is the first possible state of a job. 
       * It indicates acceptance of the job.
       */
      INITIALIZED,

      RUNNING, COMPLETED, ERROR, UNRECOGNIZED;

      public static Status fromValue(String status) {
         try {
            return valueOf(checkNotNull(status, "status").toUpperCase());
         }
         catch (IllegalArgumentException e) {
            return UNRECOGNIZED;
         }
      }
   }
   
   public static  Builder builder() {
      return new Builder();
   }

   public static class Builder {
      private String id;
      private Status status;
      private Optional error = Optional.absent();
      private Optional resource = Optional.absent();

      public Builder id(String id) {
         this.id = id;
         return this;
      }

      public Builder status(Status status) {
         this.status = status;
         return this;
      }

      public Builder error(Error error) {
         this.error = Optional.fromNullable(error);
         return this;
      }

      public Builder resource(T resource) {
         this.resource = Optional.fromNullable(resource);
         return this;
      }
      
      public Job build() {
         return new Job(id, status, error, resource);
      }
   }

   public static final class Error {

      private final int code;
      private final String message;
      private final String details;

      @ConstructorProperties({ "code", "message", "details" })
      protected Error(int code, String message, String details) {
         this.code = code;
         this.message = message;
         this.details = details;
      }

      public int getCode() {
         return code;
      }

      public String getMessage() {
         return message;
      }

      public String getDetails() {
         return details;
      }

      @Override
      public String toString() {
         return toStringHelper(this).add("code", code).add("message", message).add("details", details).toString();
      }
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy