Ejemplo n.º 1
0
 @Test
 public void List_Keys() {
   User u =
       where(user.firstName.eq("Jaakko")).list(user.firstName, user.mainAddress().street).get(0);
   assertEquals("Jaakko", u.getFirstName());
   assertNull(u.getLastName());
   assertEquals("Aakatu", u.getMainAddress().street);
   assertNull(u.getMainAddress().postCode);
 }
Ejemplo n.º 2
0
 public void save(OutputStream outputStream) throws Exception {
   PrintWriter pw = new PrintWriter(outputStream);
   for (User us : users) {
     pw.println(us.getFirstName());
     pw.println(us.getLastName());
     pw.println(us.getBirthDate().getTime());
     pw.println(us.isMale());
     pw.println(us.getCountry().toString());
   }
   pw.close();
 }
Ejemplo n.º 3
0
  /**
   * Process the specified HTTP request, and create the corresponding HTTP response (or forward to
   * another web component that will create it). Return an <code>ActionForward</code> instance
   * describing where and how control should be forwarded, or <code>null</code> if the response has
   * already been completed.
   *
   * @param mapping The ActionMapping used to select this instance
   * @param form The optional ActionForm bean for this request (if any)
   * @param request The HTTP request we are processing
   * @param response The HTTP response we are creating
   * @exception Exception if business logic throws an exception
   */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    // Extract attributes we will need
    MessageResources messages = getResources(request);

    // save errors
    ActionMessages errors = new ActionMessages();

    // START check for login (security)
    if (!SecurityService.getInstance().checkForLogin(request.getSession(false))) {
      return (mapping.findForward("welcome"));
    }
    // END check for login (security)

    // get the current user for displaying personal info, such as "My Projects"
    User u =
        UserService.getInstance()
            .getSingleUser((String) request.getSession(false).getAttribute("username"));
    System.out.println(
        "local addresss sssssssssssssss"
            + request.getLocalAddr()
            + "          "
            + request.getLocalName());
    long startProjects = System.currentTimeMillis();
    String myName = u.getFirstName() + " " + u.getLastName();
    List myHr = HrHelper.getAllEmployeesFormer(u);
    long endProjects = System.currentTimeMillis();
    System.out.println("GetMyHrAction took:" + ((endProjects - startProjects) / 1000.0));
    response.setContentType("text/html");
    response.setHeader("Cache-Control", "no-cache");
    // System.out.println(actResponse.toXML());
    PrintWriter out = response.getWriter();
    out.println(new JSONArray(myHr.toArray()));
    out.flush();

    // Forward control to the specified success URI
    return (null);
  }
Ejemplo n.º 4
0
  /**
   * @param userList
   * @return Student Register new student by prompting them for user info
   */
  public static Student registerStudentAccount(LinkedList<User> userList) {
    String username = "";
    String password = "";
    String first = "";
    String last = "";
    String GNum = "";
    String phoneNum = "";
    String email = "";
    String address = "";
    User aStudent = null;

    // prompt for username until available username is entered
    do {
      username = JOptionPane.showInputDialog("Please enter desired username");
      aStudent = validateUsername(username, userList);
      if (aStudent != null) {
        JOptionPane.showMessageDialog(null, "This username is already in use!\nPlease try again");
      }
    } while (aStudent != null);

    // create student object
    aStudent = new Student(username);

    // prompt for password until valid entry is given
    do {
      password = JOptionPane.showInputDialog("Please enter desired password");
      if (!aStudent.setPassword(password)) {
        JOptionPane.showMessageDialog(
            null,
            "Password does not meet requirements. Minimum 8 characters\nTry Again.",
            "Error",
            JOptionPane.ERROR_MESSAGE);
      }
    } while (!aStudent.setPassword(password));

    // prompt for first name until valid entry is made
    do {
      first = JOptionPane.showInputDialog("Please enter your first name");
      if (!aStudent.setFirstName(first)) {
        JOptionPane.showMessageDialog(null, "Invalid entry \nPlease try again.");
      }
    } while (!aStudent.setFirstName(first));

    // prompt for last name until valid entry is made
    do {
      last = (JOptionPane.showInputDialog("Please enter your last name"));
      if (!aStudent.setLastName(last)) {
        JOptionPane.showMessageDialog(null, "Invalid entry \nPlease try again");
      }
    } while (!aStudent.setLastName(last));

    // prompt for G-Number until valid entry is made
    do {
      GNum = (JOptionPane.showInputDialog("Please enter your G-number"));
      if (!aStudent.setgNumber(GNum)) {
        JOptionPane.showMessageDialog(
            null,
            "Invalid entry! Please write your GNumber in this format 00XXXXXX \nPlease try again",
            "Error",
            JOptionPane.ERROR_MESSAGE);
      }
    } while (!aStudent.setgNumber(GNum));

    // prompt for phone number until valid entry is made
    do {
      phoneNum = (JOptionPane.showInputDialog("Please enter your phone number"));
      if (!aStudent.setPhoneNumber(phoneNum)) {
        JOptionPane.showMessageDialog(
            null,
            "Invalid entry. Please write your phone number in XXXXXXXXXX format \nPlease try again",
            "Error",
            JOptionPane.ERROR_MESSAGE);
      }
    } while (!aStudent.setPhoneNumber(phoneNum));

    // prompt for email until valid entry is made
    do {
      email = (JOptionPane.showInputDialog("Please enter your Email address"));
      if (!aStudent.setEmail(email)) {
        JOptionPane.showMessageDialog(
            null,
            "Invalid entry, correct format: [email protected] \nPlease try again",
            "Error",
            JOptionPane.ERROR_MESSAGE);
      }
    } while (!aStudent.setEmail(email));

    // prompt for address until valid entry is made
    Student nStudent = (Student) aStudent;

    do {
      address = (JOptionPane.showInputDialog("Please enter your shipping address"));
      if (!nStudent.setShippingAddress(address)) {
        JOptionPane.showMessageDialog(null, "Invalid entry \nPlease try again");
      }
    } while (!nStudent.setShippingAddress(address));

    JOptionPane.showMessageDialog(null, "Your account has been created");
    try {
      PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("accounts.txt", true)));

      pw.println(
          "\r\n-"
              + aStudent.getFirstName()
              + ","
              + aStudent.getLastName()
              + ","
              + aStudent.getgNumber()
              + ","
              + aStudent.getPassword()
              + ","
              + aStudent.getPhoneNumber()
              + ","
              + aStudent.getEmail()
              + ","
              + aStudent.getUsername()
              + ","
              + nStudent.getShippingAddress());
      pw.close();

    } catch (IOException e) {
      e.printStackTrace();
    }

    userList.add(aStudent);
    return nStudent;
  }
Ejemplo n.º 5
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.openiam.idm.srvc.user.service.UserDataService#getUserAsMap(java.lang
   * .String)
   */
  @Transactional(readOnly = true)
  public Map<String, UserAttribute> getUserAsMap(String userId) {
    User usr = getUser(userId);
    if (usr == null) {
      return null;
    }

    Map<String, UserAttribute> attrMap = getAllAttributes(userId);
    if (attrMap == null) {
      attrMap = new HashMap<String, UserAttribute>();
    }
    // assign the predefined properties

    attrMap.put("USER_ID", new UserAttribute(null, userId, null, "USER_ID", userId));
    attrMap.put(
        "FIRST_NAME", new UserAttribute(null, userId, null, "FIRST_NAME", usr.getFirstName()));
    attrMap.put("LAST_NAME", new UserAttribute(null, userId, null, "LAST_NAME", usr.getLastName()));
    attrMap.put(
        "MIDDLE_INIT",
        new UserAttribute(null, userId, null, "MIDDLE_INIT", String.valueOf(usr.getMiddleInit())));
    attrMap.put("TITLE", new UserAttribute(null, userId, null, "TITLE", usr.getTitle()));
    attrMap.put("DEPT", new UserAttribute(null, userId, null, "DEPT", usr.getDeptCd()));
    attrMap.put(
        "STATUS", new UserAttribute(null, userId, null, "STATUS", usr.getStatus().toString()));
    if (usr.getBirthdate() != null) {
      attrMap.put(
          "BIRTHDATE",
          new UserAttribute(null, userId, null, "BIRTHDATE", usr.getBirthdate().toString()));
    } else {
      attrMap.put("BIRTHDATE", new UserAttribute(null, userId, null, "BIRTHDATE", null));
    }
    attrMap.put("SEX", new UserAttribute(null, userId, null, "SEX", String.valueOf(usr.getSex())));
    if (usr.getCreateDate() != null) {
      attrMap.put(
          "CREATE_DATE",
          new UserAttribute(null, userId, null, "CREATE_DATE", usr.getCreateDate().toString()));
    } else {
      attrMap.put("CREATE_DATE", new UserAttribute(null, userId, null, "CREATE_DATE", null));
    }
    attrMap.put(
        "CREATED_BY", new UserAttribute(null, userId, null, "CREATED_BY", usr.getCreatedBy()));
    if (usr.getLastUpdate() != null) {
      attrMap.put(
          "LAST_UPDATE",
          new UserAttribute(null, userId, null, "LAST_UPDATE", usr.getLastUpdate().toString()));
    } else {
      attrMap.put("LAST_UPDATE", new UserAttribute(null, userId, null, "LAST_UPDATE", null));
    }
    attrMap.put(
        "LAST_UPDATEDBY",
        new UserAttribute(null, userId, null, "LAST_UPDATEDBY", usr.getLastUpdatedBy()));
    attrMap.put("PREFIX", new UserAttribute(null, userId, null, "PREFIX", usr.getPrefix()));
    attrMap.put("SUFFIX", new UserAttribute(null, userId, null, "SUFFIX", usr.getSuffix()));
    attrMap.put(
        "USER_TYPE_IND",
        new UserAttribute(null, userId, null, "USER_TYPE_IND", usr.getUserTypeInd()));
    attrMap.put(
        "EMPLOYEE_ID", new UserAttribute(null, userId, null, "EMPLOYEE_ID", usr.getEmployeeId()));
    attrMap.put(
        "EMPLOYEE_TYPE",
        new UserAttribute(null, userId, null, "EMPLOYEE_TYPE", usr.getEmployeeType()));
    attrMap.put(
        "LOCATION_ID", new UserAttribute(null, userId, null, "LOCATION_ID", usr.getLocationCd()));
    attrMap.put(
        "ORGANIZATION_ID",
        new UserAttribute(null, userId, null, "ORGANIZATION_ID", usr.getCompanyId()));
    attrMap.put(
        "COMPANY_OWNER_ID",
        new UserAttribute(null, userId, null, "COMPANY_OWNER_ID", usr.getCompanyOwnerId()));

    attrMap.put(
        "MANAGER_ID", new UserAttribute(null, userId, null, "MANAGER_ID", usr.getManagerId()));
    attrMap.put("JOB_CODE", new UserAttribute(null, userId, null, "JOB_CODE", usr.getJobCode()));

    return attrMap;
  }
Ejemplo n.º 6
0
 @Test
 public void SingleResult_Keys() {
   User u = where(user.firstName.eq("Jaakko")).singleResult(user.firstName);
   assertEquals("Jaakko", u.getFirstName());
   assertNull(u.getLastName());
 }