public void addEmployeeAttributes() { // SessionFactory session = getSessionFactory(); Session session = getSession(); session.beginTransaction(); // EmployeeBo employeeBo = new EmployeeDao(getSessionFactory()).retrieveOne(new // EmployeeBo(6),session); EmployeeBo employeeBo = null; try { employeeBo = (EmployeeBo) session.get(EmployeeBo.class, new Integer(6)); } catch (Exception e) { e.printStackTrace(); } // System.out.println(" employeeBo ?? " + employeeBo.toString()); AttrLookupGroupBo attrLookupGroupBo = null; try { attrLookupGroupBo = (AttrLookupGroupBo) session.get(AttrLookupGroupBo.class, new Integer(18)); } catch (Exception e) { e.printStackTrace(); } if (null == attrLookupGroupBo) { System.out.println(" no record returns " + attrLookupGroupBo); return; } Set<EmployeeAttributesBo> empAttributeSet = new HashSet<EmployeeAttributesBo>(); // Set<EmployeeAttributesBo> empAttributeSet = employeeBo.getEmpAttributeSet(); Date expireDate = null; try { expireDate = new SimpleDateFormat("MM/dd/yyyy").parse("01/01/2099"); } catch (ParseException e) { e.printStackTrace(); } for (AttributeLookupBo attributeLookupLo : attrLookupGroupBo.getAttributeLookup()) { if (null != attributeLookupLo) { EmployeeAttributesBo employeeAttributes = new EmployeeAttributesBo(); employeeAttributes.setAttributeLookup(attributeLookupLo); employeeAttributes.setEmployee(employeeBo); employeeAttributes.setUpdateBy("PG"); employeeAttributes.setUpdateDate(Calendar.getInstance().getTime()); employeeAttributes.setExpireDate(expireDate); employeeAttributes.setCreateBy("PG"); if ("ADDRESS1".equals(attributeLookupLo.getAttribute())) { employeeAttributes.setAttributeDesc("ADDRESS1"); employeeAttributes.setAttributeValue("9700 NW 112th Ave"); } else if ("ADDRESS2".equals(attributeLookupLo.getAttribute())) { employeeAttributes.setAttributeDesc("ADDRESS2"); employeeAttributes.setAttributeValue(""); } else if ("CITY".equals(attributeLookupLo.getAttribute())) { employeeAttributes.setAttributeDesc("CITY"); employeeAttributes.setAttributeValue("Miami"); } else if ("STATE".equals(attributeLookupLo.getAttribute())) { employeeAttributes.setAttributeDesc("STATE"); employeeAttributes.setAttributeValue("Florida"); } else if ("ZIP".equals(attributeLookupLo.getAttribute())) { employeeAttributes.setAttributeDesc("ZIP"); employeeAttributes.setAttributeValue("33178"); } empAttributeSet.add(employeeAttributes); employeeBo.setEmpAttributeSet(empAttributeSet); attributeLookupLo.setEmpAttributeSet(empAttributeSet); } } /*//employeeBo.setDocuments(null); //employeeBo.setEmpAttributeSet(empAttributeSet); System.out.println(" employee ? " + employeeBo.toString()); try{ //employeeBo = new EmployeeDao(getSessionFactory()).create(employeeBo,session); }catch(Exception e){ log.error("EXCEPTION: creating employee failed " + e.getMessage()); session.getTransaction().rollback(); session.close(); return; }*/ session.getTransaction().commit(); // session.close(); System.out.println(" new employeeBo ? " + employeeBo.toString()); return; }
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; }