@RequestMapping(value = "/", method = RequestMethod.POST)
  public String homeSubmit(@ModelAttribute Form form, Model model) {
    String[] cmdArgs = {""};
    model.addAttribute("form", form);
    userForm = form;

    switch (form.getCity()) {
      case "Amarillo":
        form.setLatitude(35.1992);
        form.setLongitude(-101.8453);
        break;
      case "Austin":
        form.setLatitude(30.2500);
        form.setLongitude(-97.7500);
        break;
      case "College Station":
        form.setLatitude(30.6014);
        form.setLongitude(-96.3144);
        break;
      case "Corpus Christi":
        form.setLatitude(27.7428);
        form.setLongitude(-97.4019);
        break;
      case "Fort Worth":
        form.setLatitude(32.7574);
        form.setLongitude(-97.3332);
        break;
      case "Houston":
        form.setLatitude(29.7604);
        form.setLongitude(-95.3698);
        break;
      case "Lubbock":
        form.setLatitude(33.5667);
        form.setLongitude(-101.8833);
        break;
      case "San Antonio":
        form.setLatitude(29.4167);
        form.setLongitude(-98.5000);
        break;
      case "Waco":
        form.setLatitude(31.5514);
        form.setLongitude(-97.1558);
        break;
      default: // init to Dallas
        form.setLatitude(32.806437331493);
        form.setLongitude(-96.802432100254);
    }

    thefacade.getForm(form);

    thefacade.getYelpAPIResults(
        YelpAPI.run(
            cmdArgs, form.getActivity(), form.getCity(), form.getRadius(), form.getDeals()));

    return "map";
  }
  public static void main(String[] args) {
    System.out.println("##### Configurando subsistemas #####");
    Facade facade = new Facade();
    facade.inicializarSubsistemas();

    System.out.println("##### Utilizando subsistemas #####");
    facade.reproduzirAudio("We are the champions.mp3");
    facade.reproduzirVideo("Copa 2002.mp4");
    facade.lerInput();
  }
 public static void createEmployee() {
   try {
     if (f.hasEmployee(37)) ;
     f.removeEmployee(37);
     f.createEmployee(37, "Dave", "Baby", "Balls Avenue", "x5000", "Horse Inseminator");
   } catch (Exception e) {
     System.err.println("Failed");
   } finally {
     System.out.println("Created");
   }
 }
Exemple #4
0
 public static int getSkillExperience(int index) {
   Facade fac = Client.getFacade();
   if (fac != null) {
     SkillInfo[] array = fac.getSkillArray();
     if (array.length > index) {
       SkillInfo skill = array[index];
       if (skill != null) {
         return skill.getExperience();
       }
     }
   }
   return -1;
 }
 public static void printOrdersOnHoldId() {
   List<Orderr> oList = f.getOrdersOnHold(144);
   System.out.println(System.lineSeparator() + "Orders on hold for customer 144: ");
   oList
       .stream()
       .forEach(
           (o) -> {
             System.out.println("- " + o.getOrderNumber());
           });
 }
 public static void printCustomersInCity() {
   List<Customer> cList = f.getCustomersInCity("NYC");
   System.out.println(System.lineSeparator() + "NYC customers: ");
   cList
       .stream()
       .forEach(
           (s) -> {
             System.out.println("- " + s.getCustomerName());
           });
 }
  @SuppressWarnings("unchecked")
  @RequestMapping(value = "/map", method = RequestMethod.POST)
  @ResponseBody
  public JSONArray mapPost(@ModelAttribute Business biz, Model model) {
    JSONArray jsonArr = new JSONArray();
    JSONObject tmpJson = new JSONObject();

    model.addAttribute("biz", biz);
    biz.setCoordinatesGoogle();

    if (biz.isNull()) {
      thefacade.getGoogleAPIResults(businesses);
      listOfBusinesses = thefacade.getResults();

      // add businesses to array of JSONs
      for (int i = 0; i < listOfBusinesses.size(); i++) {
        // re-init tmp JSON Object
        tmpJson = new JSONObject();

        // add attributes
        tmpJson.put("name", listOfBusinesses.get(i).getName());
        tmpJson.put("address", listOfBusinesses.get(i).getAddress());
        tmpJson.put("phone", listOfBusinesses.get(i).formatPhoneNumber());
        tmpJson.put("rating", listOfBusinesses.get(i).getAverageRating());
        tmpJson.put("lat", listOfBusinesses.get(i).getCoordinates().getLatitude());
        tmpJson.put("lng", listOfBusinesses.get(i).getCoordinates().getLongitude());
        tmpJson.put("website", listOfBusinesses.get(i).getWebsite());
        tmpJson.put("openStatus", listOfBusinesses.get(i).getOpenStatus());

        // add JSON Object to array
        jsonArr.add(tmpJson);
      }

      // clear list of businesses
      businesses.clear();
      listOfBusinesses.clear();
    } else {
      businesses.add(biz);
    }

    return jsonArr;
  }
  /** @param args the command line arguments */
  public static void main(String[] args) {

    EntityManagerFactory emf = Persistence.createEntityManagerFactory("CA2_ORM_REST_AJAXPU");
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    em.getTransaction().commit();

    System.out.println(Facade.getPersons());
    try {
      System.out.println(Facade.getPerson(1));
    } catch (Exception e) {
    }

    System.out.println("Create new person: " + Facade.createPerson(new Person("Bob", "Apit")));
    try {
      System.out.println("P1s email: " + Facade.getPerson(1).getEmail());
    } catch (Exception e) {
    }

    System.out.println("Personer fra 2800: " + Facade.getPersonsByZip(2800));
    try {
      System.out.println("Cvr=123: " + Facade.getCompany(123));
    } catch (Exception e) {
    }

    //        System.out.println("All phones:"+Facade.getPhones());
    //        System.out.println("Person 1 phone list:"+Facade.getPhone(1));
  }
 public static void main(String[] args) {
   Facade tem = new Facade();
   tem.doSth();
 }
  public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    Account account = new Account();
    account.setUsername(request.getParameter("username"));
    account.setPassword(request.getParameter("password"));
    account.setEmail(request.getParameter("email"));
    account.setFirstName(request.getParameter("firstName"));
    account.setLastName(request.getParameter("lastName"));
    account.setGender("0".equals(request.getParameter("gender")) ? false : true);
    account.setTitle(request.getParameter("title"));
    account.setSubtitle(request.getParameter("subtitle"));

    // default values:
    account.setMaxPerPage(10);
    account.setSkinId(0);
    account.setCreatedDate(new Date());

    // check:
    boolean succeed = false;
    String message = null;
    String password2 = request.getParameter("password2");
    account.debug();

    if ((password2 == null) || !password2.equals(account.getPassword())) {
      message = "ÃÜÂë²»Ò»ÖÂ.";
    } else {
      try {
        facade.createAccount(account);
        succeed = true;
        System.out.println("Account created successfully!");
      } catch (Exception e) {
        message = e.getMessage();
      }
    }

    Map map = new HashMap();
    map.put("account", account);

    if (succeed) {
      // succeeded:
      if (baseDir == null) {
        synchronized (this) {
          baseDir = request.getSession().getServletContext().getRealPath("/upload/");

          if (!baseDir.endsWith("/") && !baseDir.endsWith("\\")) {
            baseDir = baseDir + "/";
          }

          System.out.println("[INFO] set account upload dir = " + baseDir);
        }
      }

      // create a dir for this account:
      new java.io.File(baseDir + account.getAccountId() + "/").mkdir();

      return new ModelAndView("register-succeed", map);
    }

    // failed, so return to the registration form:
    map.put("message", message);

    return new ModelAndView("register-form", map);
  }
 public static void printTopEmployee() {
   System.out.println(System.lineSeparator() + "Most customers: ");
   System.out.println("- " + f.getEmpMaxCustomers().getEmployeeNumber());
 }
 public static void printTotalEmployees() {
   System.out.println(System.lineSeparator() + "Total Employees: ");
   System.out.println("- " + f.getEmployeeCount());
 }
@Controller
public class MainController {

  Form userForm;
  ArrayList<Business> businesses = new ArrayList<>();
  Facade thefacade = Facade.getInstance();
  ArrayList<Business> listOfBusinesses;
  int expressLoc = 0;

  @RequestMapping(value = "/", method = RequestMethod.GET)
  public String homeForm(Model model) {
    model.addAttribute("form", new Form());
    return "index";
  }

  @RequestMapping(value = "/", method = RequestMethod.POST)
  public String homeSubmit(@ModelAttribute Form form, Model model) {
    String[] cmdArgs = {""};
    model.addAttribute("form", form);
    userForm = form;

    switch (form.getCity()) {
      case "Amarillo":
        form.setLatitude(35.1992);
        form.setLongitude(-101.8453);
        break;
      case "Austin":
        form.setLatitude(30.2500);
        form.setLongitude(-97.7500);
        break;
      case "College Station":
        form.setLatitude(30.6014);
        form.setLongitude(-96.3144);
        break;
      case "Corpus Christi":
        form.setLatitude(27.7428);
        form.setLongitude(-97.4019);
        break;
      case "Fort Worth":
        form.setLatitude(32.7574);
        form.setLongitude(-97.3332);
        break;
      case "Houston":
        form.setLatitude(29.7604);
        form.setLongitude(-95.3698);
        break;
      case "Lubbock":
        form.setLatitude(33.5667);
        form.setLongitude(-101.8833);
        break;
      case "San Antonio":
        form.setLatitude(29.4167);
        form.setLongitude(-98.5000);
        break;
      case "Waco":
        form.setLatitude(31.5514);
        form.setLongitude(-97.1558);
        break;
      default: // init to Dallas
        form.setLatitude(32.806437331493);
        form.setLongitude(-96.802432100254);
    }

    thefacade.getForm(form);

    thefacade.getYelpAPIResults(
        YelpAPI.run(
            cmdArgs, form.getActivity(), form.getCity(), form.getRadius(), form.getDeals()));

    return "map";
  }

  @RequestMapping(value = "/express1", method = RequestMethod.GET)
  public String express1Get(Model model) {
    // set location to first option
    expressLoc = 1;
    return "express";
  }

  @RequestMapping(value = "/express2", method = RequestMethod.GET)
  public String express2Get(Model model) {
    // set location to second option
    expressLoc = 2;
    return "express";
  }

  @RequestMapping(value = "/express3", method = RequestMethod.GET)
  public String express3Get(Model model) {
    // set location to third option
    expressLoc = 3;
    return "express";
  }

  @RequestMapping(value = "/express", method = RequestMethod.POST)
  @ResponseBody
  public int expressPost(Model model) {
    // return express location chosen by user
    return expressLoc;
  }

  @RequestMapping(value = "/map", method = RequestMethod.GET)
  public void mapGet(Model model) {
    model.addAttribute("biz", new Business());
  }

  @SuppressWarnings("unchecked")
  @RequestMapping(value = "/map", method = RequestMethod.POST)
  @ResponseBody
  public JSONArray mapPost(@ModelAttribute Business biz, Model model) {
    JSONArray jsonArr = new JSONArray();
    JSONObject tmpJson = new JSONObject();

    model.addAttribute("biz", biz);
    biz.setCoordinatesGoogle();

    if (biz.isNull()) {
      thefacade.getGoogleAPIResults(businesses);
      listOfBusinesses = thefacade.getResults();

      // add businesses to array of JSONs
      for (int i = 0; i < listOfBusinesses.size(); i++) {
        // re-init tmp JSON Object
        tmpJson = new JSONObject();

        // add attributes
        tmpJson.put("name", listOfBusinesses.get(i).getName());
        tmpJson.put("address", listOfBusinesses.get(i).getAddress());
        tmpJson.put("phone", listOfBusinesses.get(i).formatPhoneNumber());
        tmpJson.put("rating", listOfBusinesses.get(i).getAverageRating());
        tmpJson.put("lat", listOfBusinesses.get(i).getCoordinates().getLatitude());
        tmpJson.put("lng", listOfBusinesses.get(i).getCoordinates().getLongitude());
        tmpJson.put("website", listOfBusinesses.get(i).getWebsite());
        tmpJson.put("openStatus", listOfBusinesses.get(i).getOpenStatus());

        // add JSON Object to array
        jsonArr.add(tmpJson);
      }

      // clear list of businesses
      businesses.clear();
      listOfBusinesses.clear();
    } else {
      businesses.add(biz);
    }

    return jsonArr;
  }

  @SuppressWarnings("unchecked")
  @RequestMapping(value = "/getCriteria", method = RequestMethod.POST)
  @ResponseBody
  public JSONObject sendCriteria() {
    JSONObject json = new JSONObject();
    json.put("city", userForm.getCity());
    json.put("radius", userForm.getRadius());
    json.put("type", userForm.getActivity());
    json.put("openStatus", userForm.getOpenStatus());

    return json;
  }
}