// Path: java/src/org/drupal/project/computing/exception/DConfigException.java
// public class DConfigException extends Exception {
//     public DConfigException() {
//     }
// 
//     public DConfigException(String s) {
//         super(s);
//     }
// 
//     public DConfigException(String s, Throwable throwable) {
//         super(s, throwable);
//     }
// 
//     public DConfigException(Throwable throwable) {
//         super(throwable);
//     }
// }
// 
// 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 org.apache.commons.lang3.StringUtils;
import org.drupal.project.computing.exception.DConfigException;
import org.drupal.project.computing.exception.DNotFoundException;
import org.drupal.project.computing.exception.DSiteException;
import javax.script.Bindings;
import javax.script.SimpleBindings;
import java.util.ArrayList;
import java.util.List;
     * @throws DSiteException
     */
    public void close() throws DSiteException {
        if (services.isAuthenticated()) {
            services.userLogout();
        }
    }

    @Override
    public DRecord claimRecord(String appName) throws DSiteException, DNotFoundException {
        connect();
        Bindings params = new SimpleBindings();
        params.put("application", appName);

        Object response = services.request("computing/claim.json", params, "POST");
        if (response instanceof ArrayList) {
            boolean found = getSingleElementFromList(response, Boolean.class);
            if (!found) {
                throw new DNotFoundException("No more READY record for application: " + appName);
            } else {
                throw new DSiteException("Illegal response from Drupal.");
            }
        } else {
            Bindings recordBindings = (Bindings) response;
            return DRecord.fromBindings(recordBindings);
        }
    }

    @Override
    public void finishRecord(DRecord record) throws DSiteException {
// Path: java/src/org/drupal/project/computing/exception/DConfigException.java
// public class DConfigException extends Exception {
//     public DConfigException() {
//     }
// 
//     public DConfigException(String s) {
//         super(s);
//     }
// 
//     public DConfigException(String s, Throwable throwable) {
//         super(s, throwable);
//     }
// 
//     public DConfigException(Throwable throwable) {
//         super(throwable);
//     }
// }
// 
// 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/DServicesSite.java
import org.apache.commons.lang3.StringUtils;
import org.drupal.project.computing.exception.DConfigException;
import org.drupal.project.computing.exception.DNotFoundException;
import org.drupal.project.computing.exception.DSiteException;
import javax.script.Bindings;
import javax.script.SimpleBindings;
import java.util.ArrayList;
import java.util.List;

     * @throws DSiteException
     */
    public void close() throws DSiteException {
        if (services.isAuthenticated()) {
            services.userLogout();
        }
    }

    @Override
    public DRecord claimRecord(String appName) throws DSiteException, DNotFoundException {
        connect();
        Bindings params = new SimpleBindings();
        params.put("application", appName);

        Object response = services.request("computing/claim.json", params, "POST");
        if (response instanceof ArrayList) {
            boolean found = getSingleElementFromList(response, Boolean.class);
            if (!found) {
                throw new DNotFoundException("No more READY record for application: " + appName);
            } else {
                throw new DSiteException("Illegal response from Drupal.");
            }
        } else {
            Bindings recordBindings = (Bindings) response;
            return DRecord.fromBindings(recordBindings);
        }
    }

    @Override
    public void finishRecord(DRecord record) throws DSiteException {
        connect();