// Path: java/src/org/drupal/project/computing/exception/DNotFoundException.java
// public class DNotFoundException extends Exception {
//     public DNotFoundException() {}
// 
//     public DNotFoundException(String s) {
//         super(s);
//     }
// }
// 
// Path: java/src/org/drupal/project/computing/exception/DSiteException.java
// public class DSiteException extends Exception {
//     public DSiteException() {
//         super();
//     }
// 
//     public DSiteException(String s) {
//         super(s);
//     }
// 
//     public DSiteException(String s, Throwable throwable) {
//         super(s, throwable);
//     }
// 
//     public DSiteException(Throwable throwable) {
//         super(throwable);
//     }
// 
//     /**
//      * The error code is arbitrary by the caller which sets it.
//      */
//     private int errorCode = 0;
// 
//     public int getErrorCode() {
//         return errorCode;
//     }
// 
//     public void setErrorCode(int errorCode) {
//         this.errorCode = errorCode;
//     }
// 
// }


import com.google.gson.JsonParseException;
import com.google.gson.JsonSyntaxException;
import org.apache.commons.lang3.StringUtils;
import org.drupal.project.computing.exception.DNotFoundException;
import org.drupal.project.computing.exception.DSiteException;
import javax.script.Bindings;
            throw new DSiteException("Cannot parse JSON result: " + jsonResult, e);
        }
    }

    @Override
    public DRecord loadRecord(long id) throws DSiteException {
        String jsonResult = drush.computingCall("computing_load", id);
        try {
            return DRecord.fromJson(jsonResult);
        } catch (JsonSyntaxException | IllegalArgumentException e) {
            throw new DSiteException("Cannot parse JSON result: " + jsonResult, e);
        }
    }


    @Override
    public DRecord claimRecord(String appName) throws DSiteException, DNotFoundException {
        String jsonResult = drush.computingCall("computing_claim", appName);
        try {
            Object jsonObj = DUtils.Json.getInstance().fromJson(jsonResult);
            if (jsonObj instanceof Boolean && !((Boolean) jsonObj)) {
                // this is also expected when no item is available.
                throw new DNotFoundException("No record available to be claimed.");

            } else if (jsonObj instanceof Bindings) {
                // the most common case.
                return DRecord.fromBindings((Bindings) jsonObj);

            } else {
                // all other cases are not valid.
// Path: java/src/org/drupal/project/computing/exception/DNotFoundException.java
// public class DNotFoundException extends Exception {
//     public DNotFoundException() {}
// 
//     public DNotFoundException(String s) {
//         super(s);
//     }
// }
// 
// Path: java/src/org/drupal/project/computing/exception/DSiteException.java
// public class DSiteException extends Exception {
//     public DSiteException() {
//         super();
//     }
// 
//     public DSiteException(String s) {
//         super(s);
//     }
// 
//     public DSiteException(String s, Throwable throwable) {
//         super(s, throwable);
//     }
// 
//     public DSiteException(Throwable throwable) {
//         super(throwable);
//     }
// 
//     /**
//      * The error code is arbitrary by the caller which sets it.
//      */
//     private int errorCode = 0;
// 
//     public int getErrorCode() {
//         return errorCode;
//     }
// 
//     public void setErrorCode(int errorCode) {
//         this.errorCode = errorCode;
//     }
// 
// }


// Path: java/src/org/drupal/project/computing/DDrushSite.java
import com.google.gson.JsonParseException;
import com.google.gson.JsonSyntaxException;
import org.apache.commons.lang3.StringUtils;
import org.drupal.project.computing.exception.DNotFoundException;
import org.drupal.project.computing.exception.DSiteException;
import javax.script.Bindings;

            throw new DSiteException("Cannot parse JSON result: " + jsonResult, e);
        }
    }

    @Override
    public DRecord loadRecord(long id) throws DSiteException {
        String jsonResult = drush.computingCall("computing_load", id);
        try {
            return DRecord.fromJson(jsonResult);
        } catch (JsonSyntaxException | IllegalArgumentException e) {
            throw new DSiteException("Cannot parse JSON result: " + jsonResult, e);
        }
    }


    @Override
    public DRecord claimRecord(String appName) throws DSiteException, DNotFoundException {
        String jsonResult = drush.computingCall("computing_claim", appName);
        try {
            Object jsonObj = DUtils.Json.getInstance().fromJson(jsonResult);
            if (jsonObj instanceof Boolean && !((Boolean) jsonObj)) {
                // this is also expected when no item is available.
                throw new DNotFoundException("No record available to be claimed.");

            } else if (jsonObj instanceof Bindings) {
                // the most common case.
                return DRecord.fromBindings((Bindings) jsonObj);

            } else {
                // all other cases are not valid.
                throw new DSiteException("Unexpected result from claiming a record.");