/**
  * Invokes the service handler method.
  *
  * @param rq the ServiceRequest<TestConfigElementMsg>.
  * @return the ServiceResponse<TestConfigurationListMsg>.
  * @throws SearchException
  */
 protected ServiceResponse<TestConfigurationListMsg> invoke(
     ServiceRequest<TestConfigElementMsg> rq) throws SearchException {
   ServiceResponse<TestConfigurationListMsg> rs;
   TestConfigurationListMsg msg;
   try {
     this.validateRequest(rq);
     this.setContext(rq.getContext());
     msg = this.searchReferencingTestConfigurations(rq.getRequestMessage());
     if ((msg == null)) {
       super.getLogger().warning("No response message defined.");
     } else {
       super.cleanServiceMessage(msg);
     }
     rs = new ServiceResponse<TestConfigurationListMsg>(rq.getContext());
     rs.setResponseMessage(msg);
     return rs;
   } catch (SearchException e) {
     super.getLogger().error(e);
     throw e;
   } catch (NabuccoException e) {
     super.getLogger().error(e);
     SearchException wrappedException = new SearchException(e);
     throw wrappedException;
   } catch (Exception e) {
     super.getLogger().error(e);
     throw new SearchException("Error during service invocation.", e);
   }
 }
 /**
  * Invokes the service handler method.
  *
  * @param rq the ServiceRequest<CustomerProduceRq>.
  * @return the ServiceResponse<CustomerListMsg>.
  * @throws ProduceException
  */
 protected ServiceResponse<CustomerListMsg> invoke(ServiceRequest<CustomerProduceRq> rq)
     throws ProduceException {
   ServiceResponse<CustomerListMsg> rs;
   CustomerListMsg msg;
   try {
     this.validateRequest(rq);
     this.setContext(rq.getContext());
     msg = this.produceCustomer(rq.getRequestMessage());
     if ((msg == null)) {
       super.getLogger().warning("No response message defined.");
     } else {
       super.cleanServiceMessage(msg);
     }
     rs = new ServiceResponse<CustomerListMsg>(rq.getContext());
     rs.setResponseMessage(msg);
     return rs;
   } catch (ProduceException e) {
     super.getLogger().error(e);
     throw e;
   } catch (NabuccoException e) {
     super.getLogger().error(e);
     ProduceException wrappedException = new ProduceException(e);
     throw wrappedException;
   } catch (Exception e) {
     super.getLogger().error(e);
     throw new ProduceException("Error during service invocation.", e);
   }
 }
 /**
  * ImportSchema.
  *
  * @param subContexts the ServiceSubContext....
  * @param message the ImportRq.
  * @return the ImportRs.
  * @throws ClientException
  */
 public ImportRs importSchema(ImportRq message, ServiceSubContext... subContexts)
     throws ClientException {
   ServiceRequest<ImportRq> request =
       new ServiceRequest<ImportRq>(super.createServiceContext(subContexts));
   request.setRequestMessage(message);
   ServiceResponse<ImportRs> response = null;
   Exception exception = null;
   if ((service != null)) {
     super.handleRequest(request);
     long start = NabuccoSystem.getCurrentTimeMillis();
     try {
       response = service.importSchema(request);
     } catch (Exception e) {
       exception = e;
     } finally {
       long end = NabuccoSystem.getCurrentTimeMillis();
       long duration = (end - start);
       super.monitorResult(ImportSchema.class, "importSchema", duration, exception);
     }
     if ((response != null)) {
       super.handleResponse(response);
       return response.getResponseMessage();
     }
   }
   throw new ClientException("Cannot execute service operation: ImportSchema.importSchema");
 }
 /**
  * Invokes the service handler method.
  *
  * @param rq the ServiceRequest<FulltextIndexMsg>.
  * @return the ServiceResponse<EmptyServiceMessage>.
  * @throws IndexException
  */
 protected ServiceResponse<EmptyServiceMessage> invoke(ServiceRequest<FulltextIndexMsg> rq)
     throws IndexException {
   ServiceResponse<EmptyServiceMessage> rs;
   EmptyServiceMessage msg;
   try {
     this.validateRequest(rq);
     this.setContext(rq.getContext());
     msg = this.indexDocument(rq.getRequestMessage());
     if ((msg == null)) {
       super.getLogger().warning("No response message defined.");
     } else {
       super.cleanServiceMessage(msg);
     }
     rs = new ServiceResponse<EmptyServiceMessage>(rq.getContext());
     rs.setResponseMessage(msg);
     return rs;
   } catch (IndexException e) {
     super.getLogger().error(e);
     throw e;
   } catch (NabuccoException e) {
     super.getLogger().error(e);
     IndexException wrappedException = new IndexException(e);
     throw wrappedException;
   } catch (Exception e) {
     super.getLogger().error(e);
     throw new IndexException("Error during service invocation.", e);
   }
 }
 /**
  * MaintainDynamicCodeCodeGroup.
  *
  * @param subContexts the ServiceSubContext....
  * @param session the NabuccoSession.
  * @param message the DynamicCodeCodeGroupMaintainMsg.
  * @return the DynamicCodeCodeGroupMaintainMsg.
  * @throws MaintainException
  */
 public DynamicCodeCodeGroupMaintainMsg maintainDynamicCodeCodeGroup(
     DynamicCodeCodeGroupMaintainMsg message,
     NabuccoSession session,
     ServiceSubContext... subContexts)
     throws MaintainException {
   ServiceRequest<DynamicCodeCodeGroupMaintainMsg> request =
       new ServiceRequest<DynamicCodeCodeGroupMaintainMsg>(
           super.createServiceContext(session, subContexts));
   request.setRequestMessage(message);
   ServiceResponse<DynamicCodeCodeGroupMaintainMsg> response = null;
   Exception exception = null;
   if ((this.service != null)) {
     super.handleRequest(request, session);
     long start = NabuccoSystem.getCurrentTimeMillis();
     try {
       response = service.maintainDynamicCodeCodeGroup(request);
     } catch (Exception e) {
       exception = e;
     } finally {
       long end = NabuccoSystem.getCurrentTimeMillis();
       long duration = (end - start);
       super.monitorResult(
           MaintainDynamicCode.class, "maintainDynamicCodeCodeGroup", duration, exception);
     }
     if ((response != null)) {
       super.handleResponse(response, session);
       return response.getResponseMessage();
     }
   }
   throw new MaintainException(
       "Cannot execute service operation: MaintainDynamicCode.maintainDynamicCodeCodeGroup");
 }
 /**
  * Getter for the DashboardStatistic.
  *
  * @param subContexts the ServiceSubContext....
  * @param message the EmptyServiceMessage.
  * @return the DashboardStatisticMsg.
  * @throws ClientException
  */
 public DashboardStatisticMsg getDashboardStatistic(
     EmptyServiceMessage message, ServiceSubContext... subContexts) throws ClientException {
   ServiceRequest<EmptyServiceMessage> request =
       new ServiceRequest<EmptyServiceMessage>(super.createServiceContext(subContexts));
   request.setRequestMessage(message);
   ServiceResponse<DashboardStatisticMsg> response = null;
   Exception exception = null;
   if ((service != null)) {
     super.handleRequest(request);
     long start = NabuccoSystem.getCurrentTimeMillis();
     try {
       response = service.getDashboardStatistic(request);
     } catch (Exception e) {
       exception = e;
     } finally {
       long end = NabuccoSystem.getCurrentTimeMillis();
       long duration = (end - start);
       super.monitorResult(ReportScript.class, "getDashboardStatistic", duration, exception);
     }
     if ((response != null)) {
       super.handleResponse(response);
       return response.getResponseMessage();
     }
   }
   throw new ClientException(
       "Cannot execute service operation: ReportScript.getDashboardStatistic");
 }
  /**
   * Process a transition of an existing workflow instance.
   *
   * @param context the current transition context
   * @return the new current transition context
   * @throws TransitioningException when the workflow cannot be processed
   */
  protected TransitionContext processTransition(TransitionContext context)
      throws TransitioningException {

    if (context == null) {
      throw new IllegalArgumentException("Cannot process workflow for context [null].");
    }

    try {
      WorkflowServiceLocator locator = new WorkflowServiceLocator();
      WorkflowService service = locator.getService(null);

      ServiceRequest<ProcessWorkflowRq> rq =
          new ServiceRequest<ProcessWorkflowRq>(super.getContext());

      ProcessWorkflowRq requestMessage = new ProcessWorkflowRq();
      requestMessage.setInstanceId(context.getInstanceId());
      requestMessage.setSignal(context.getSignal());
      requestMessage.setComment(context.getComment());
      requestMessage.getSubInstances().addAll(context.getSubInstances());
      requestMessage.setContext(context.getWorkflowContext());
      rq.setRequestMessage(requestMessage);

      ServiceResponse<WorkflowResultRs> rs = service.processWorkflow(rq);

      if (rs == null || rs.getResponseMessage() == null) {
        throw new TransitioningException("Starting workflow did not finish successful.");
      }

      WorkflowResultRs responseMessage = rs.getResponseMessage();

      TransitionContext newContext = new TransitionContext();
      newContext.setInstanceId(responseMessage.getInstanceId());
      newContext.setName(responseMessage.getWorkflowName());
      newContext.setWorkflowContext(responseMessage.getContext());
      newContext.setSignal(context.getSignal());
      newContext.setStateName(responseMessage.getStateName());
      newContext.getNextTransitions().addAll(responseMessage.getNextTransitions());

      return newContext;

    } catch (WorkflowException we) {
      throw new TransitioningException(
          "Error processing workflow with name "
              + context.getName()
              + " and id "
              + context.getInstanceId()
              + ".",
          we);
    } catch (Exception e) {
      throw new TransitioningException(
          "Unexpected error processing workflow with name "
              + context.getName()
              + " and id "
              + context.getInstanceId()
              + ".",
          e);
    }
  }
  /**
   * Start a new workflow instance for the given workflow name.
   *
   * @param requestMessage the workflow init message
   * @return the transition context
   * @throws TransitioningException when the workflow cannot be started
   */
  protected TransitionContext startWorkflow(InitWorkflowRq requestMessage)
      throws TransitioningException {

    if (requestMessage == null) {
      throw new IllegalArgumentException("Cannot start workflow for request [null].");
    }

    Name name = requestMessage.getWorkflowName();
    Description summary = requestMessage.getSummary();

    if (name == null || name.getValue() == null || name.getValue().isEmpty()) {
      throw new IllegalArgumentException("Cannot start workflow with name [null].");
    }
    if (summary == null || summary.getValue() == null || summary.getValue().isEmpty()) {
      requestMessage.setSummary(new Description("Workflow '" + name + "'"));
    }

    try {
      WorkflowServiceLocator locator = new WorkflowServiceLocator();
      WorkflowService service = locator.getService(null);

      ServiceRequest<InitWorkflowRq> rq = new ServiceRequest<InitWorkflowRq>(super.getContext());
      rq.setRequestMessage(requestMessage);

      ServiceResponse<WorkflowResultRs> rs = service.initWorkflow(rq);

      if (rs == null || rs.getResponseMessage() == null) {
        throw new TransitioningException("Starting workflow did not finish successful.");
      }

      WorkflowResultRs responseMessage = rs.getResponseMessage();

      TransitionContext transitionContext = new TransitionContext();
      transitionContext.setInstance(responseMessage.getInstance());
      transitionContext.setInstanceId(responseMessage.getInstanceId());
      transitionContext.setName(responseMessage.getWorkflowName());
      transitionContext.setWorkflowContext(responseMessage.getContext());
      transitionContext.getNextTransitions().addAll(responseMessage.getNextTransitions());

      return transitionContext;

    } catch (WorkflowException we) {
      throw new TransitioningException("Error starting workflow with name " + name + ".", we);
    } catch (Exception e) {
      throw new TransitioningException(
          "Unexpected error starting workflow with name " + name + ".", e);
    }
  }