public EndpointResponse removeMediaChannel(RemoveMediaChannelRequest request) {
    try {
      mediaChannelDao.remove(request.getMediaChannelId());
      return EndpointHelper.createResponse(EndpointResponse.class, request);

    } catch (Exception e) {
      return EndpointHelper.createErrorResponse(EndpointResponse.class, request, e);
    }
  }
  public EndpointResponse updateTransformationRule(UpdateTransformationRuleRequest request) {
    try {
      transformationRuleDao.update(request.getTransformationRule());
      return EndpointHelper.createResponse(EndpointResponse.class, request);

    } catch (Exception e) {
      return EndpointHelper.createErrorResponse(EndpointResponse.class, request, e);
    }
  }
  public EndpointResponse updateWorkflow(UpdateWorkflowRequest request) {
    try {
      workflowDao.update(request.getWorkflow());
      return EndpointHelper.createResponse(EndpointResponse.class, request);

    } catch (Exception e) {
      return EndpointHelper.createErrorResponse(EndpointResponse.class, request, e);
    }
  }
  public EndpointResponse removeWorkflowClass(RemoveWorkflowClassRequest request) {
    try {
      workflowClassDao.remove(request.getWorkflowClassId());
      return EndpointHelper.createResponse(EndpointResponse.class, request);

    } catch (Exception e) {
      return EndpointHelper.createErrorResponse(EndpointResponse.class, request, e);
    }
  }
  public EndpointResponse removeJob(RemoveJobRequest request) {
    try {
      jobDao.remove(request.getJobId());
      return EndpointHelper.createResponse(EndpointResponse.class, request);

    } catch (Exception e) {
      return EndpointHelper.createErrorResponse(EndpointResponse.class, request, e);
    }
  }
  public ListWorkflowsResponse listWorkflows(ListWorkflowsRequest request) {
    try {
      ListWorkflowsResponse r = EndpointHelper.createResponse(ListWorkflowsResponse.class, request);
      r.setWorkflows(workflowDao.findWorkflowsInState(request.getWorkflowState()));
      return r;

    } catch (Exception e) {
      return EndpointHelper.createErrorResponse(ListWorkflowsResponse.class, request, e);
    }
  }
  public ListJobsResponse listJobs(ListJobsRequest request) {
    try {
      ListJobsResponse r = EndpointHelper.createResponse(ListJobsResponse.class, request);
      r.setJobs(jobDao.findJobs(request.getWorkflowId(), request.getJobState()));
      return r;

    } catch (Exception e) {
      return EndpointHelper.createErrorResponse(ListJobsResponse.class, request, e);
    }
  }
  public FindWorkflowResponse findWorkflow(FindWorkflowRequest request) {
    try {
      FindWorkflowResponse r = EndpointHelper.createResponse(FindWorkflowResponse.class, request);
      r.setWorkflow(workflowDao.get(request.getWorkflowId()));
      return r;

    } catch (Exception e) {
      return EndpointHelper.createErrorResponse(FindWorkflowResponse.class, request, e);
    }
  }
  public EndpointResponse submitEvent(SubmitEventRequest request) {

    try {
      workflowEngine.submitEvent(request.getEvent());
      return EndpointHelper.createResponse(EndpointResponse.class, request);

    } catch (Exception e) {
      return EndpointHelper.createErrorResponse(EndpointResponse.class, request, e);
    }
  }
  public FindMediaChannelResponse findMediaChannel(FindMediaChannelRequest request) {
    try {
      FindMediaChannelResponse r =
          EndpointHelper.createResponse(FindMediaChannelResponse.class, request);
      r.setMediaChannel(mediaChannelDao.get(request.getMediaChannelId()));
      return r;

    } catch (Exception e) {
      return EndpointHelper.createErrorResponse(FindMediaChannelResponse.class, request, e);
    }
  }
  public FindJobResponse findJob(FindJobRequest request) {

    try {
      FindJobResponse r = EndpointHelper.createResponse(FindJobResponse.class, request);
      r.setJob(jobDao.get(request.getJobId()));
      return r;

    } catch (Exception e) {
      return EndpointHelper.createErrorResponse(FindJobResponse.class, request, e);
    }
  }
  public EndpointResponse submitJob(SubmitJobRequest request) {

    try {
      jobDao.add(request.getJob());
      jobDispatcher.notifyNewJobAdded();
      return EndpointHelper.createResponse(EndpointResponse.class, request);

    } catch (Exception e) {
      return EndpointHelper.createErrorResponse(EndpointResponse.class, request, e);
    }
  }
  public ListTransformationRulesResponse listTransformationRules(EndpointRequest request) {
    try {
      ListTransformationRulesResponse r =
          EndpointHelper.createResponse(ListTransformationRulesResponse.class, request);
      r.setTransformationRules(transformationRuleDao.findAll());
      return r;

    } catch (Exception e) {
      return EndpointHelper.createErrorResponse(ListTransformationRulesResponse.class, request, e);
    }
  }
  public ListWorkflowClassesResponse listWorkflowClasses(ListWorkflowClassesRequest request) {
    try {
      ListWorkflowClassesResponse r =
          EndpointHelper.createResponse(ListWorkflowClassesResponse.class, request);
      r.setWorkflowClasses(workflowClassDao.findAll()); // todo more criteria
      return r;

    } catch (Exception e) {
      return EndpointHelper.createErrorResponse(ListWorkflowsResponse.class, request, e);
    }
  }
  public CreateMediaChannelResponse createMediaChannel(CreateMediaChannelRequest request) {
    try {
      CreateMediaChannelResponse response =
          EndpointHelper.createResponse(CreateMediaChannelResponse.class, request);
      response.setMediaChannel(mediaChannelDao.add(request.getMediaChannel()));
      return response;

    } catch (Exception e) {
      return EndpointHelper.createErrorResponse(CreateMediaChannelResponse.class, request, e);
    }
  }
  public ListMediaChannelsResponse listMediaChannels(ListMediaChannelsRequest request) {
    try {
      ListMediaChannelsResponse r =
          EndpointHelper.createResponse(ListMediaChannelsResponse.class, request);
      r.setMediaChannels(mediaChannelDao.findAll());
      return r;

    } catch (Exception e) {
      return EndpointHelper.createErrorResponse(FindMediaChannelResponse.class, request, e);
    }
  }
  public CreateWorkflowClassResponse createWorkflowClass(CreateWorkflowClassRequest request) {
    try {
      CreateWorkflowClassResponse response =
          EndpointHelper.createResponse(CreateWorkflowClassResponse.class, request);
      response.setWorkflowClass(workflowClassDao.add(request.getWorkflowClass()));
      return response;

    } catch (Exception e) {
      return EndpointHelper.createErrorResponse(CreateWorkflowClassResponse.class, request, e);
    }
  }
  public FindTransformationRuleResponse findTransformationRule(
      FindTransformationRuleRequest request) {
    try {
      FindTransformationRuleResponse r =
          EndpointHelper.createResponse(FindTransformationRuleResponse.class, request);
      r.setTransformationRule(transformationRuleDao.get(request.getTransformationRuleId()));
      return r;

    } catch (Exception e) {
      return EndpointHelper.createErrorResponse(FindTransformationRuleResponse.class, request, e);
    }
  }
  public CreateTransformationRuleResponse createTransformationRule(
      CreateTransformationRuleRequest request) {
    try {
      CreateTransformationRuleResponse response =
          EndpointHelper.createResponse(CreateTransformationRuleResponse.class, request);
      response.setTransformationRule(transformationRuleDao.add(request.getTransformationRule()));
      return response;

    } catch (Exception e) {
      return EndpointHelper.createErrorResponse(CreateTransformationRuleResponse.class, request, e);
    }
  }
  public EndpointResponse removeWorkflow(RemoveWorkflowRequest request) {
    try {
      workflowDao.remove(request.getWorkflowId());

      for (Job j : jobDao.findJobs(request.getWorkflowId(), null)) {
        jobDao.remove(j.get_id());
      }

      return EndpointHelper.createResponse(EndpointResponse.class, request);

    } catch (Exception e) {
      return EndpointHelper.createErrorResponse(EndpointResponse.class, request, e);
    }
  }