Package com.mockey.model

Examples of com.mockey.model.ServicePlan


        } else if (serviceId != null) {
          Service service = store.getServiceById(new Long(serviceId));
          service.setLastVisit(null);
          store.saveOrUpdateService(service);
        } else if (servicePlanId != null) {
          ServicePlan servicePlan = store
              .getServicePlanById(new Long(servicePlanId));
          servicePlan.setLastVisit(null);
          store.saveOrUpdateServicePlan(servicePlan);
        }

        jsonObject.put("success", "Last visit was cleared.");
      }else {
View Full Code Here


  public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    try {
      // API BUSINESS LOGIC
      // log.debug("Service Plan setup/delete");
      ServicePlan servicePlan = null;
      Long servicePlanId = null;
      String servicePlanIdAsString = req.getParameter(API_SETPLAN_PARAMETER_PLAN_ID);
      List<Service> allServices = store.getServices();
      // *********************
      // BEST EFFORT HERE.
      // We try to find the service by ID.
      // If not found, we try by NAME.
      // Otherwise, let the rest of the logic do its thing.
      // *********************

      try {
        servicePlanId = new Long(servicePlanIdAsString);
        servicePlan = store.getServicePlanById(servicePlanId);
      } catch (Exception e) {
        if (req.getParameter(API_SETPLAN_PARAMETER_PLAN_ID) != null) {
          log.debug("No service plan with ID '" + req.getParameter(API_SETPLAN_PARAMETER_PLAN_ID)
              + "' found.", e);
        }
      }
      if (servicePlan == null) {
        try {
          String servicePlanName = req.getParameter(API_SET_SAVE_OR_UPDATE_PARAMETER_PLAN_NAME);
         
          servicePlan = store.getServicePlanByName(servicePlanName.trim());
        } catch (Exception e) {
          if (req.getParameter(API_SET_SAVE_OR_UPDATE_PARAMETER_PLAN_NAME) != null) {
            log.debug(
                "No service plan with NAME '"
                    + req.getParameter(API_SET_SAVE_OR_UPDATE_PARAMETER_PLAN_NAME) + "' found.", e);
          }
        }
      }

      JSONObject jsonResultObject = new JSONObject();

      String action = req.getParameter(API_SETPLAN_PARAMETER_ACTION);
      String transientState = req.getParameter(API_TRANSIENT_STATE);
      try {
        if (transientState != null) {
          servicePlan.setTransientState(new Boolean(transientState));
        }
      } catch (Exception e) {
        log.debug("ServicePlan not set to transient state but a value was given as: " + transientState);

      }
      if (API_SETPLAN_PARAMETER_ACTION_VALUE_DELETE_PLAN.equals(action)) {
        JSONObject jsonObject = new JSONObject();

        try {
          store.deleteServicePlan(servicePlan);
          jsonObject.put("success", "Service plan '" + servicePlan.getName() + "' deleted");
          jsonObject.put("planId", "" + servicePlan.getId());
          jsonObject.put("planName", "" + servicePlan.getName());
        } catch (Exception e) {

          jsonObject.put("fail", "Service plan not deleted. Please check your logs for insight.");

        }
        resp.setContentType("application/json");
        PrintWriter out = resp.getWriter();
        jsonResultObject.put("result", jsonObject);
        out.println(jsonResultObject.toString());
        out.flush();
        out.close();
        return;
      } else if (API_SETPLAN_PARAMETER_ACTION_VALUE_SET_PLAN.equals(action) && servicePlan != null) {
        JSONObject jsonObject = new JSONObject();

        try {
         
          store.setServicePlan(servicePlan);
          String msg = "Service plan " + servicePlan.getName() + " set";
          jsonObject.put("success", msg);
          jsonObject.put("planid", "" + servicePlan.getId());
          jsonObject.put("planName", "" + servicePlan.getName());

          Util.saveSuccessMessage(msg, req); // For redirect
        } catch (Exception e) {
          jsonObject.put("fail", "Service plan not set. Please check your logs for insight.");
        }
        resp.setContentType("application/json");
        PrintWriter out = resp.getWriter();
        jsonResultObject.put("result", jsonObject);
        out.println(jsonResultObject.toString());
        out.flush();
        out.close();
        return;
       
      }
      else if(API_SETPLAN_PARAMETER_ACTION_VALUE_SET_AS_DEFAULT_PLAN.equals(action)){
        PrintWriter out = resp.getWriter();
        JSONObject jsonObject = new JSONObject();
        if("none".equalsIgnoreCase(servicePlanIdAsString)){
          store.setDefaultServicePlanId(null);
          // JSON response
          jsonObject.put("success", "Removed default plan.");
        }
        else if(servicePlan!=null && servicePlan.getId()!=null){
          store.setDefaultServicePlanId(servicePlan.getId().toString());
          // JSON response
          jsonObject.put("success", "Set as Default Service Plan");
          jsonObject.put("planid", "" + servicePlan.getId());
          jsonObject.put("planName", "" + servicePlan.getName());
         
        }else {
          jsonObject.put("fail", "Unable to set Default Service Plan. Unknown Service Plan ID.");
        }
        jsonResultObject.put("result", jsonObject);
        out.println(jsonResultObject.toString());
        out.flush();
        out.close();
        return;
       
      }
      else if (API_SETPLAN_PARAMETER_ACTION_VALUE_SAVE_PLAN.equals(action)) {

        if (servicePlan == null) {
          servicePlan = new ServicePlan();
        }

        String[] serviceIds = req.getParameterValues("service_ids[]");

        // ***************************
        // LET'S PREVENT EMPTY PLAN NAMES
        // ***************************

        String servicePlanName = req.getParameter(API_SET_SAVE_OR_UPDATE_PARAMETER_PLAN_NAME);
        String servicePlanTag = req.getParameter(API_SET_SAVE_OR_UPDATE_PARAMETER_PLAN_TAG);
        if (servicePlanName == null) {
          // If possible, carry over the name from an existing Plan.
          servicePlanName = servicePlan.getName();
        }
        // If all fails, inject a name.
        if (servicePlanName == null || servicePlanName.trim().length() == 0) {
          servicePlanName = "Plan (auto-generated-name)";
        }
        servicePlan.setName(servicePlanName.trim());

        if (servicePlanTag != null) {
          servicePlan.setTag(servicePlanTag);
        }
        // ***************************
        // SAVE/UPDATE THE PLAN
        // ***************************
        ServicePlan savedServicePlan = createOrUpdatePlan(servicePlan, serviceIds);

        // ***************************
        // SAVE/UPDATE THE PLAN
        // ***************************
        resp.setContentType("application/json");
        PrintWriter out = resp.getWriter();
        String msg = "Service plan " + servicePlan.getName() + " saved";

        // HACK: For redirect IF JavaScript decides to (if type is not
        // JSON)
        if (!"json".equalsIgnoreCase(req.getParameter(API_SETPLAN_PARAMETER_TYPE))) {
          Util.saveSuccessMessage(msg, req);
        }
        // JSON response
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("success", msg);
        jsonObject.put("planid", "" + savedServicePlan.getId());
        jsonObject.put("planName", "" + savedServicePlan.getName());
        jsonResultObject.put("result", jsonObject);
        out.println(jsonResultObject.toString());
        out.flush();
        out.close();
        return;
View Full Code Here

    Service a = new Service();
    a.setServiceName("Service A");
    a.setTag("   tagCC");
    store.saveOrUpdateService(a);
   
    ServicePlan servicePlan = new ServicePlan();
    servicePlan.setName("ServicePlan A");
    servicePlan.setTag("service_plan_tag_123");
    store.saveOrUpdateServicePlan(servicePlan);
   
    String term = "cats";
    SearchResultBuilder resultBuilder = new SearchResultBuilder();
    List<SearchResult> resultList = resultBuilder.buildSearchResults(term,
View Full Code Here

        service.removeTagFromList(tag);
        store.saveOrUpdateService(service);
        jsonObject.put("success", "Deleted tag from Service.");

      } else if ("delete_tag_from_service_plan".equals(action)) {
        ServicePlan servicePlan = store.getServicePlanById(new Long(
            servicePlanId));

        servicePlan.removeTagFromList(tag);
        store.saveOrUpdateServicePlan(servicePlan);

        jsonObject.put("success", "Deleted tag from Service Plan.");

      } else if ("delete_tag_from_scenario".equals(action)) {
View Full Code Here

    // highlight the Services (provide a visual cue) to the
    // user for which Services are included in the plan.
    String servicePlanId = req.getParameter("plan_id");
    if (servicePlanId != null) {
      try {
        ServicePlan sp = store.getServicePlanById(new Long(servicePlanId));
        req.setAttribute("servicePlan", sp);

      } catch (Exception e) {
        logger.debug("Service Plan with ID '" + servicePlanId + "' does not exist.", e);
      }
View Full Code Here

    String SERVICENAME_A = "happy path";
    String SCENARIO_A = "123";
    String SCENARIO_B = "456";
    List<ServicePlan> planList = new ArrayList<ServicePlan>();
    ServicePlan servicePlan = new ServicePlan();
    servicePlan.setId(new Long(1));
    servicePlan.setName(SERVICENAME_A);
    servicePlan
        .setDescription("Lorem ipsum dolor sit amet, consectetur adipiscing elit. ");
    PlanItem planItem = new PlanItem();
    planItem.setServiceResponseType(Service.SERVICE_RESPONSE_TYPE_PROXY);
    planItem.setScenarioName(SCENARIO_A);
    planItem.setServiceName(SERVICENAME_A);
    servicePlan.addPlanItem(planItem);

    planItem = new PlanItem();
    planItem.setServiceResponseType(Service.SERVICE_RESPONSE_TYPE_PROXY);
    planItem.setScenarioName(SCENARIO_B);
    planItem.setServiceName(SERVICENAME_A);
    servicePlan.addPlanItem(planItem);
    planList.add(servicePlan);

    return planList;
  }
View Full Code Here

    }

    // STEP #8. DEFAULT Service Plan ID
    // Only set a default service plan ID from the incoming XML file
    // if one is not already set in the current store.
    ServicePlan servicePlan = mockServiceStoreTemporary.getServicePlanById(mockServiceStoreTemporary
        .getDefaultServicePlanIdAsLong());
    if (servicePlan != null && store.getDefaultServicePlanIdAsLong() == null) {
      // OK, we have a 'default' service plan from the incoming file AND
      // the current store does not. Let's update the current store.
      store.setDefaultServicePlanId(mockServiceStoreTemporary.getDefaultServicePlanId());
View Full Code Here

  public ServicePlan getServicePlanById(Long servicePlanId) {
    return servicePlanStore.get(servicePlanId);
  }

  public ServicePlan getServicePlanByName(String servicePlanName) {
    ServicePlan sp = null;
    for (ServicePlan servicePlan : this.getServicePlans()) {
      if (servicePlan.getName() != null && servicePlan.getName().equalsIgnoreCase(servicePlanName)) {
        sp = servicePlan;
        break;
      }
View Full Code Here

TOP

Related Classes of com.mockey.model.ServicePlan

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.