Exemplo n.º 1
0
  public EmployeeBo addEmployeeAttributes(
      EmployeeBo inEmployeeBo, AttrLookupGroupBo inAttrLookupGroupBo) {

    if (null == inEmployeeBo
        || null == inAttrLookupGroupBo
        || null == inEmployeeBo.getEmpAttributeSet()) {
      return null;
    }

    // SessionFactory session = getSessionFactory();
    Session session = getSession();
    session.beginTransaction();
    EmployeeBo employeeBo = null;
    try {
      employeeBo = getOneRecord(session, EmployeeBo.class, inEmployeeBo.getEmployeeId());
    } catch (Exception e) {
      e.printStackTrace();
    }

    System.out.println(" employeeBo ?? " + employeeBo.toString());

    AttrLookupGroupBo attrLookupGroupBo = null;
    try {
      // attrLookupGroupBo = (AttrLookupGroupBo)session.get(AttrLookupGroupBo.class,new
      // Integer(18));
      attrLookupGroupBo =
          new AttrLookupGroupDao()
              .getOneRecord(
                  session, AttrLookupGroupBo.class, inAttrLookupGroupBo.getAttrLookupGrpID());
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (null == attrLookupGroupBo) {
      System.out.println(" no record returns " + attrLookupGroupBo);
      return null;
    }

    Set<EmployeeAttributesBo> empAttributeSet = new HashSet<EmployeeAttributesBo>();

    Date expireDate = null;
    try {
      expireDate = new SimpleDateFormat("MM/dd/yyyy").parse("01/01/2099");
    } catch (ParseException e) {
      e.printStackTrace();
    }

    Set<EmployeeAttributesBo> inEmployeeAttributesBoSet = inEmployeeBo.getEmpAttributeSet();

    for (AttributeLookupBo attributeLookupLo : attrLookupGroupBo.getAttributeLookup()) {
      if (null != attributeLookupLo) {
        EmployeeAttributesBo employeeAttributes = new EmployeeAttributesBo();
        employeeAttributes.setAttributeLookup(attributeLookupLo);
        employeeAttributes.setEmployee(employeeBo);
        employeeAttributes.setUpdateBy(inEmployeeBo.getUpdateBy());
        employeeAttributes.setUpdateDate(Calendar.getInstance().getTime());
        employeeAttributes.setExpireDate(expireDate);
        employeeAttributes.setCreateBy(inEmployeeBo.getUpdateBy());

        String attrLookupStr = attributeLookupLo.getAttribute();

        for (EmployeeAttributesBo inEmployeeAttributeLo : inEmployeeAttributesBoSet) {

          if (StringUtils.isNotBlank(attrLookupStr)
              && attrLookupStr.equals(inEmployeeAttributeLo.getAttributeName())) {
            employeeAttributes.setAttributeName(attrLookupStr);
            employeeAttributes.setAttributeDesc(attrLookupStr);
            employeeAttributes.setAttributeValue(inEmployeeAttributeLo.getAttributeValue());
            break;
          }
        }
        empAttributeSet.add(employeeAttributes);
        employeeBo.setEmpAttributeSet(empAttributeSet);
        attributeLookupLo.setEmpAttributeSet(empAttributeSet);
      }
    }

    session.getTransaction().commit();
    // session.close();

    System.out.println(" new employeeBo ? " + employeeBo.toString());
    return null;
  }