/**
   * @param updateName
   * @param user
   */
  public User handleNames(
      User user,
      String firstName,
      String middleName,
      String lastName,
      String preferredNameIndex,
      boolean store) {
    boolean updateName = false;

    if (firstName == null || firstName.trim().equals("")) {
      if (user.getFirstName() != null) {
        firstName = user.getFirstName();
      } else {
        firstName = "";
      }
    }
    /*
     * Setting middleName as "", required for the rest of the code
     */
    if (middleName != null && !middleName.equals("")) {
      firstName = firstName + " " + middleName;
      middleName = "";
    } else {
      middleName = "";
    }

    if (lastName == null || lastName.trim().equals("")) {
      if (user.getLastName() != null) {
        lastName = user.getLastName();
      } else {
        lastName = "";
      }
    }

    if (preferredNameIndex == null) {
      preferredNameIndex = "10";
    }

    StringBuffer fullname = new StringBuffer();
    /*
     * Preferred name handling.
     */
    if (preferredNameIndex != null) {

      fullname.append(firstName).append(" ").append(middleName).append(" ").append(lastName);

      int index = Integer.parseInt(preferredNameIndex);
      int refName1 = index / 10;
      int refName2 = index % 10;

      if (refName2 > 0) {
        String fullName = fullname.toString();

        String preferredName1 = getValueAtIndexFromNameString(refName1, fullName);
        String preferredName2 = getValueAtIndexFromNameString(refName2, fullName);

        firstName = preferredName1 + " " + preferredName2;
        firstName = TextSoap.findAndReplace(firstName, "  ", " ");

        /*
         * Remember MIDDLE NAME is always "" in the beginning. Removing
         * lastName since last name should only be changed when moving
         * name to firstName
         */
        middleName = TextSoap.findAndCut(fullName, lastName);
        middleName = TextSoap.findAndCut(middleName, preferredName1);
        middleName = TextSoap.findAndCut(middleName, preferredName2);
        middleName = TextSoap.findAndReplace(middleName, "  ", " ");

        lastName = TextSoap.findAndCut(lastName, preferredName2);
        lastName = TextSoap.findAndReplace(lastName, "  ", " ");

        updateName = true;
      } else if (refName1 > 0) {
        String fullName = fullname.toString();

        String preferredName = getValueAtIndexFromNameString(refName1, fullName);
        if (middleName.equals("")) {
          middleName = firstName;
        } else {
          if (middleName.startsWith(" ")) {
            middleName = firstName + middleName;
          } else {
            middleName = firstName + " " + middleName;
          }
        }

        firstName = preferredName;
        middleName = TextSoap.findAndCut(middleName, preferredName);
        middleName = TextSoap.findAndReplace(middleName, "  ", " ");
        if (refName1 > 1 && !lastName.equals(preferredName)) {
          lastName = TextSoap.findAndCut(lastName, preferredName);
          lastName = TextSoap.findAndReplace(lastName, "  ", " ");
        }

        updateName = true;
      }
    }

    if (lastName.startsWith("Van ") && !updateName) {
      StringBuffer half = new StringBuffer();
      half.append(firstName).append(" ").append(middleName);
      String halfName = half.toString();
      firstName = getValueAtIndexFromNameString(1, halfName);
      middleName =
          halfName.substring(
              Math.min(halfName.indexOf(" ") + 1, halfName.length()), halfName.length());
      middleName = TextSoap.findAndReplace(middleName, "  ", " ");

      updateName = true;
    }

    /*
     * Needed because createUser uses the method setFullName that splits the
     * name with it's own rules
     */
    if (updateName) {
      if (firstName != null) {
        if (firstName.endsWith(" ")) {
          firstName = firstName.substring(0, firstName.length() - 1);
        }
      }

      if (middleName != null) {
        if (middleName.startsWith(" ")) {
          middleName = middleName.substring(1, middleName.length());
        }
        if (middleName.endsWith(" ")) {
          middleName = middleName.substring(0, middleName.length() - 1);
        }
      }

      if (lastName != null) {
        if (lastName.startsWith(" ")) {
          lastName = lastName.substring(1, lastName.length());
        }
        if (lastName.endsWith(" ")) {
          lastName = lastName.substring(0, lastName.length() - 1);
        }
      }

      user.setFirstName(firstName);
      user.setMiddleName(middleName);
      user.setLastName(lastName);
    }

    if (store) {
      try {
        user.store();
      } catch (IDOStoreException e) {
        throw e;
      }
    }
    return user;
  }
  public Table getPupilTable(IWContext iwc, User pupil) {
    // *** Search Table *** START - the uppermost table
    Table table = new Table();
    table.setWidth("100%");
    table.setBorder(0);
    table.setCellpadding(2);
    table.setCellspacing(0);
    this.transGIF.setHeight("1");
    this.transGIF.setWidth("1");

    int row = 1;
    int col = 1;
    // add empty space row
    table.add(this.transGIF, col++, row);
    table.add(this.transGIF, col++, row);
    table.add(this.transGIF, col++, row);
    table.add(this.transGIF, col++, row);
    table.add(this.transGIF, col++, row);
    // Set COLUMN WIDTH for column 1 to 5
    table.setWidth(1, row, "100");
    // table.setWidth(2, row, "70");
    // table.setWidth(3, row, "70");
    // table.setWidth(4, row, "70");
    // table.setWidth(5, row, "104");

    row++;
    col = 1;

    // *** HEADING Pupil ***
    Text pupilTxt = new Text(localize(KEY_PUPIL_HEADING, "Pupil"));
    pupilTxt.setFontStyle(STYLE_UNDERLINED_SMALL_HEADER);
    table.add(pupilTxt, col++, row);
    table.setRowHeight(row, "20");
    table.setRowVerticalAlignment(row, Table.VERTICAL_ALIGN_BOTTOM);
    row++;
    col = 1;

    // empty space row
    table.add(this.transGIF, col, row);
    table.setRowHeight(row, "5");
    col = 1;
    row++;

    // Personal Id Number
    table.add(getSmallHeader(localize(KEY_PERSONAL_ID_LABEL, "Personal id: ")), col++, row);
    if (pupil != null) {
      table.add(getSmallText(pupil.getPersonalID()), col++, row);
    }
    row++;
    col = 1;
    // Last Name
    table.add(getSmallHeader(localize(KEY_LAST_NAME_LABEL, "Last name: ")), col++, row);

    Table nameTable = new Table();
    col = 1;
    nameTable.setCellpadding(0);
    nameTable.setCellspacing(0);
    if (pupil != null) {
      nameTable.add(getSmallText(pupil.getLastName()), col++, 1);
    }
    // First Name
    nameTable.add(getSmallHeader(localize(KEY_FIRST_NAME_LABEL, "First name: ")), col++, 1);
    if (pupil != null) {
      nameTable.add(getSmallText(pupil.getFirstName()), col++, 1);
    }
    nameTable.setWidth(1, 1, "100");
    nameTable.setWidth(2, 1, "100");
    nameTable.setWidth(3, 1, "100");
    table.add(nameTable, 2, row);
    table.mergeCells(2, row, 5, row);
    row++;
    col = 1;

    // Address and Phone
    table.add(getSmallHeader(localize(KEY_ADDRESS_LABEL, "Address: ")), col++, row);
    row++;
    col = 1;
    table.add(getSmallHeader(localize(KEY_PHONE_LABEL, "Phone: ")), col++, row);
    if (pupil != null) {
      try {
        // pupil address
        Address address = getUserBusiness(iwc).getUsersMainAddress(pupil);
        StringBuffer aBuf = new StringBuffer(address.getStreetAddress());
        aBuf.append(", ");
        aBuf.append(address.getPostalCode().getPostalAddress());
        row--;
        table.add(getSmallText(aBuf.toString()), col, row);
        row++;
        // Get pupil phones
        Collection phones = pupil.getPhones();
        int i = 0;
        int phonesSize = phones.size();
        StringBuffer pBuf = new StringBuffer();
        for (Iterator iter = phones.iterator(); iter.hasNext(); i++) {
          Phone phone = (Phone) iter.next();
          pBuf.append(phone.getNumber());
          if (i < phonesSize - 1) {
            pBuf.append(", ");
          }
        }
        pBuf.append("&nbsp;");
        table.add(getSmallText(pBuf.toString()), col, row);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    row++;
    col = 1;

    return table;
  }
  private Table getPlacementTable(IWContext iwc) throws RemoteException {
    Table table = new Table();
    // table.setColor("#DDDDDD");
    table.setBorder(0);
    table.setWidth(Table.HUNDRED_PERCENT);
    table.setCellpadding(1);
    table.setCellspacing(2);
    int col = 1;
    int row = 1;

    // *** HEADING Placements ***
    Text pupilTxt = new Text(localize(KEY_PLACEMENTS_HEADING, "Placements"));
    pupilTxt.setFontStyle(STYLE_UNDERLINED_SMALL_HEADER);
    table.add(pupilTxt, col++, row);
    table.setRowHeight(row, "40");
    table.setRowVerticalAlignment(row, Table.VERTICAL_ALIGN_BOTTOM);
    table.mergeCells(col, row, table.getColumns(), row);
    col = 1;
    row++;

    // empty space row
    table.add(this.transGIF, col, row);
    table.setRowHeight(row, "10");
    col = 1;
    row++;

    //  *** Column headings ***
    table.add(getLocalizedSmallHeader(KEY_NUMBER, "No."), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(getLocalizedSmallHeader(KEY_SCHOOL_TYPE, "School type"), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(getLocalizedSmallHeader(KEY_PROVIDER, "Provider"), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(getLocalizedSmallHeader(KEY_SCHOOL_YEAR, "School year"), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(getLocalizedSmallHeader(KEY_STUDY_PATH, "Study path"), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(getLocalizedSmallHeader(KEY_SCHOOL_GROUP, "School group"), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(getLocalizedSmallHeader(KEY_START_DATE, "Start date"), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(getLocalizedSmallHeader(KEY_END_DATE, "End date"), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(getLocalizedSmallHeader(KEY_REGISTRATOR, "Registrator"), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(getLocalizedSmallHeader(KEY_REGISTRATION_CREATED_DATE, "Created date"), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(getLocalizedSmallHeader(KEY_PLACEMENT_PARAGRAPH_SHORT, "Par"), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(getLocalizedSmallHeader(KEY_NOTES, "Notes"), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(Text.getNonBrakingSpace(), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(Text.getNonBrakingSpace(), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);

    table.setRowColor(row, getHeaderColor());

    table.setRowHeight(row, "18");
    row++;

    // Loop placements
    Collection placements = null;
    try {
      if (this.pupil != null) {
        placements =
            getSchoolBusiness(iwc)
                .getSchoolClassMemberHome()
                .findAllOrderedByRegisterDate(this.pupil);
      }
    } catch (FinderException e) {
    }

    if (placements != null && placements.size() > 0) {
      int zebra = 0;
      int rowNum = 0;
      table.add(new HiddenInput(PARAM_REMOVE_PLACEMENT, "-1"), 1, 1);
      for (Iterator iter = placements.iterator(); iter.hasNext(); ) {
        rowNum++;
        SchoolClassMember plc = (SchoolClassMember) iter.next();
        col = 1;

        // Row number
        table.add(getSmallText(String.valueOf(rowNum)), col++, row);
        // School type
        try {
          table.add(getSmallText(plc.getSchoolType().getName()), col++, row);
        } catch (Exception e) {
          col++;
        }
        // Provider
        try {
          table.add(getSmallText(plc.getSchoolClass().getSchool().getName()), col++, row);
        } catch (Exception e) {
          col++;
        }
        // School year
        try {
          table.add(getSmallText(plc.getSchoolYear().getName()), col++, row);
        } catch (Exception e) {
          col++;
        }
        // Study path
        try {
          if (plc.getStudyPathId() != -1) {
            SchoolStudyPathHome home =
                (SchoolStudyPathHome) IDOLookup.getHome(SchoolStudyPath.class);
            SchoolStudyPath sp = home.findByPrimaryKey(new Integer(plc.getStudyPathId()));
            table.add(getSmallText(sp.getCode()), col, row);
          }
        } catch (Exception e) {
        }
        col++;
        // School type
        try {
          table.add(getSmallText(plc.getSchoolClass().getSchoolClassName()), col++, row);
        } catch (Exception e) {
          col++;
        }
        // Start date
        try {
          String dateStr =
              getCentralPlacementBusiness(iwc).getDateString(plc.getRegisterDate(), "yyyy-MM-dd");
          table.add(getSmallText(dateStr), col++, row);
        } catch (Exception e) {
          col++;
        }
        // End date
        try {
          String dateStr =
              getCentralPlacementBusiness(iwc).getDateString(plc.getRemovedDate(), "yyyy-MM-dd");
          table.add(getSmallText(dateStr), col++, row);
        } catch (Exception e) {
          col++;
        }
        // Registrator
        try {
          int registratorID = plc.getRegistratorId();
          User registrator = getUserBusiness(iwc).getUser(registratorID);
          if (registrator != null) {
            Name name =
                new Name(
                    registrator.getFirstName(),
                    registrator.getMiddleName(),
                    registrator.getLastName());
            table.add(
                getSmallText(name.getName(iwc.getApplicationSettings().getDefaultLocale(), false)),
                col++,
                row);
          }
        } catch (Exception e) {
          col++;
        }
        // Created date
        try {
          String dateStr =
              getCentralPlacementBusiness(iwc)
                  .getDateString(plc.getRegistrationCreatedDate(), "yyyy-MM-dd");
          table.add(getSmallText(dateStr), col++, row);
        } catch (Exception e) {
          col++;
        }
        // Placement paragraph
        try {
          if (plc.getPlacementParagraph() != null) {
            table.add(getSmallText(plc.getPlacementParagraph()), col++, row);
          } else {
            col++;
          }
        } catch (Exception e) {
          col++;
        }
        // Notes
        try {
          if (plc.getNotes() != null) {
            table.add(getSmallText(plc.getNotes()), col++, row);
          } else {
            col++;
          }
        } catch (Exception e) {
          col++;
        }
        // Pupil overview button
        try {
          // Get Pupil overview button
          String plcId = ((Integer) plc.getPrimaryKey()).toString();
          String schClassId = String.valueOf(plc.getSchoolClassId());

          Link editButt =
              new Link(this.getEditIcon(localize(KEY_TOOLTIP_PUPIL_OVERVIEW, "Pupil overview")));
          editButt.setWindowToOpen(PlacementHistoryEditPlacement.class);
          editButt.setParameter(
              SchoolAdminOverview.PARAMETER_METHOD,
              String.valueOf(SchoolAdminOverview.METHOD_OVERVIEW));
          editButt.addParameter(
              SchoolAdminOverview.PARAMETER_METHOD,
              String.valueOf(SchoolAdminOverview.METHOD_OVERVIEW));
          editButt.addParameter(SchoolAdminOverview.PARAMETER_SHOW_ONLY_OVERVIEW, "true");
          editButt.addParameter(SchoolAdminOverview.PARAMETER_SHOW_NO_CHOICES, "true");
          editButt.addParameter(SchoolAdminOverview.PARAMETER_PAGE_ID, getParentPage().getPageID());
          editButt.addParameter(
              SchoolAdminOverview.PARAMETER_USER_ID, String.valueOf(plc.getClassMemberId()));
          editButt.addParameter(SchoolAdminOverview.PARAMETER_SCHOOL_CLASS_ID, schClassId);
          editButt.addParameter(SchoolAdminOverview.PARAMETER_SCHOOL_CLASS_MEMBER_ID, plcId);
          editButt.addParameter(
              SchoolAdminOverview.PARAMETER_RESOURCE_PERMISSION,
              SchoolAdminOverview.PARAMETER_RESOURCE_PERM_VALUE_CENTRAL_ADMIN);
          editButt.addParameter(
              SchoolAdminOverview.PARAMETER_FROM_CENTRAL_PLACEMENT_EDITOR, "true");
          if (plc.getRemovedDate() != null) {
            editButt.addParameter(
                SchoolAdminOverview.PARAMETER_SCHOOL_CLASS_MEMBER_REMOVED_DATE,
                plc.getRemovedDate().toString());
          }

          table.add(editButt, col, row);
          table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
        } catch (Exception e) {
          col++;
        }
        // Remove button
        try {
          // Get remove button
          Image delImg = getDeleteIcon(localize(KEY_TOOLTIP_REMOVE_PLC, "Delete placement"));
          int plcID = ((Integer) plc.getPrimaryKey()).intValue();

          SubmitButton delButt = new SubmitButton(delImg);
          delButt.setValueOnClick(PARAM_REMOVE_PLACEMENT, String.valueOf(plcID));
          delButt.setSubmitConfirm(
              localize(
                  KEY_CONFIRM_REMOVE_PLC_MSG,
                  "Do you really want to erase this school placement and its resource placements?"));
          delButt.setToolTip(localize(KEY_TOOLTIP_REMOVE_PLC, "Delete school placement"));
          table.add(delButt, col, row);
          table.setAlignment(col, row, Table.HORIZONTAL_ALIGN_CENTER);
        } catch (Exception e) {
        }

        String zebraColor = zebra % 2 == 0 ? getZebraColor2() : getZebraColor1();
        table.setRowColor(row, zebraColor);
        col = 2;
        row++;

        // Resources
        String rscStr = getResourceBusiness(iwc).getResourcesStringXtraInfo(plc);
        if (!("".equals(rscStr))) {
          table.add(
              getSmallText("<i>" + localize(KEY_RESOURCES, "Resources") + ":</i> "), col, row);
          table.add(getSmallText("<i>" + rscStr + "</i>"), col, row);
          table.setRowColor(row, zebraColor);
          table.mergeCells(col, row, table.getColumns(), row);
          row++;
        }

        zebra++;
      }
    }

    col = 1;

    // empty space row
    table.add(this.transGIF, col, row);
    table.setRowHeight(row, "20");

    return table;
  }
Exemplo n.º 4
0
  /* (non-Javadoc)
   * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
   */
  public int compare(User user1, User user2) {
    Name name1 = new Name(user1.getFirstName(), user1.getMiddleName(), user1.getLastName());
    Name name2 = new Name(user2.getFirstName(), user2.getMiddleName(), user2.getLastName());

    return collator.compare(name1.getName(iLocale), name2.getName(iLocale));
  }