/**
   * Gets the application list response.
   *
   * @param applicationList the application list
   * @return the application list response
   * @throws Exception the exception
   */
  public static ApplicationListResponse getApplicationListResponse(
      List<edu.sga.apex.entity.Application> applicationList) throws Exception {
    ApplicationListResponse appListResponse = factory.createApplicationListResponse();

    /* check valid dao entity */
    if (applicationList != null) {
      for (edu.sga.apex.entity.Application application : applicationList) {
        /* construct application jaxb for each dao */
        Application applicationJAXB = factory.createApplication();
        applicationJAXB.setAppID(application.getAppId());
        applicationJAXB.setAppName(application.getAppName());
        applicationJAXB.setScriptPath(application.getScript_path());

        /* check valid application input */
        if (application.getInputList() != null && !application.getInputList().isEmpty()) {
          for (AppInput appInputDAO : application.getInputList()) {
            /* construct app input jaxb */
            ApplicationInput appInputJAXB = factory.createApplicationInput();
            appInputJAXB.setInput(appInputDAO.getInput());
            appInputJAXB.setDescription(appInputDAO.getDescription());

            /* add appInput jaxb to application jaxb */
            applicationJAXB.getAppInputs().add(appInputJAXB);
          }
        }

        /* add application jaxb to list response */
        appListResponse.getApplicationList().add(applicationJAXB);
      }
    } else {
      throw new Exception("Empty Application List DAO received. Cannot construct JAXB.");
    }

    return appListResponse;
  }
  /**
   * Gets the experiment jaxb.
   *
   * @param experiment the experiment
   * @return the experiment jaxb
   * @throws Exception the exception
   */
  public static edu.sga.apex.rest.jaxb.Experiment getExperimentJAXB(Experiment experiment)
      throws Exception {
    /* check valid experiment dao */
    if (experiment != null) {
      edu.sga.apex.rest.jaxb.Experiment experimentJAXB = factory.createExperiment();

      /* set basic jaxb parameters */
      experimentJAXB.setJobID(experiment.getJobId());
      experimentJAXB.setJobName(experiment.getJobName());
      experimentJAXB.setStatus(experiment.getStatus());
      experimentJAXB.setWallTime(experiment.getWallTime());
      experimentJAXB.setNumNodes(experiment.getNumOfNodes());
      experimentJAXB.setNumProcPerNode(experiment.getProcPerNode());

      /* set date parameters */
      if (experiment.getCreatedAt() != null && experiment.getUpdatedAt() != null) {
        experimentJAXB.setCreatedAt(APIUtil.getXMLGregorianCalendar(experiment.getCreatedAt()));
        experimentJAXB.setUpdatedAt(APIUtil.getXMLGregorianCalendar(experiment.getUpdatedAt()));
      }

      /* check if user entity exists */
      if (experiment.getUserName() != null) {
        experimentJAXB.setUserName(experiment.getUserName().getUsername());
      }

      /* construct the application jaxb from dao */
      if (experiment.getApplication() != null) {
        Application applicationJAXB = factory.createApplication();
        applicationJAXB.setAppID(experiment.getApplication().getAppId());
        applicationJAXB.setAppName(experiment.getApplication().getAppName());
        applicationJAXB.setScriptPath(experiment.getApplication().getScript_path());

        /* set the application jaxb */
        experimentJAXB.setApplication(applicationJAXB);
      }

      /* construct the machine jaxb from dao */
      if (experiment.getMachine() != null) {
        Machine machineJAXB = factory.createMachine();
        machineJAXB.setHostName(experiment.getMachine().getHostname());
        machineJAXB.setMachineID(experiment.getMachine().getMachineId());
        machineJAXB.setMachineName(experiment.getMachine().getMachineName());
        machineJAXB.setPortNumber(experiment.getMachine().getPortNum());
        machineJAXB.setWorkingDir(experiment.getMachine().getWorking_dir());

        /* set the machine jaxb */
        experimentJAXB.setMachine(machineJAXB);
      }

      return experimentJAXB;
    } else {
      throw new Exception("Empty Experiment DAO received. Cannot construct JAXB.");
    }
  }
  /**
   * Handle exception.
   *
   * @param exception the exception
   * @return the response
   */
  public static Response handleException(Exception exception) {
    ResponseBuilder builder = null;
    ObjectFactory factory = new ObjectFactory();

    /* Construct error response jaxb */
    ApiErrorResponse errResponse = factory.createApiErrorResponse();
    errResponse.setMessage(exception.getMessage());
    errResponse.setTrace(ExceptionUtils.getStackTrace(exception));
    errResponse.setStatus(Status.INTERNAL_SERVER_ERROR.getStatusCode());

    /* Build the error response */
    builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errResponse);

    /* Return the response */
    return builder.build();
  }
  /**
   * Gets the experiment list response.
   *
   * @param experimentList the experiment list
   * @return the experiment list response
   * @throws Exception the exception
   */
  public static ExperimentListResponse getExperimentListResponse(List<Experiment> experimentList)
      throws Exception {
    ExperimentListResponse expListResponse = factory.createExperimentListResponse();

    /* check if entity is valid */
    if (experimentList != null) {
      for (Experiment experiment : experimentList) {
        /* get experiment jaxb from dao */
        edu.sga.apex.rest.jaxb.Experiment experimentJAXB = getExperimentJAXB(experiment);

        /* add experiment jaxb to list response */
        expListResponse.getExperimentList().add(experimentJAXB);
      }
    } else {
      throw new Exception("Empty Experiment List DAO received. Cannot construct JAXB.");
    }
    return expListResponse;
  }
  /**
   * Gets the job response.
   *
   * @param bean the bean
   * @return the job response
   * @throws Exception the exception
   */
  public static JobResponse getJobResponse(JobBean bean) throws Exception {
    JobResponse response = factory.createJobResponse();

    /* check if bean is valid */
    if (bean != null) {
      response.setJobId(bean.getJobId());
      response.setJobName(bean.getJobName());
      response.setUserName(bean.getUserName());
      response.setStatus(bean.getStatus());
      response.setElapsedTime(bean.getElapsedTime());
      response.setNumNodes(bean.getNumNodes());
      response.setNumProcessors(bean.getNumProcessors());
      response.setRequiredMemory(bean.getRequiredMemory());
      response.setRequiredTime(bean.getRequiredTime());
      response.setQueue(bean.getQueue());
    } else {
      throw new Exception("Empty JobBean received. Cannot construct the response object.");
    }
    return response;
  }