@Transactional public String addFunction() { String returnString = ""; try { if (roleSysHome.isLoaded()) { // delete permission if (!roleSysHome.getInstance().getPermissions().isEmpty()) { for (Permission p : roleSysHome.getInstance().getPermissions()) { if (p != null && p.getFunction() != null) { Boolean selectedFunction = false; for (Function f : roleSysHome.getInstance().getFunctions()) { if (f != null && p.getFunction().equals(f)) { selectedFunction = true; } } if (!selectedFunction) { p.setDeleted(true); p.setUpdateDate(new Date()); } } } } // add permission if (!roleSysHome.getInstance().getFunctions().isEmpty()) { for (Function f : roleSysHome.getInstance().getFunctions()) { if (f != null) { Boolean functionExist = false; for (Permission p : roleSysHome.getInstance().getPermissions()) { if (p != null && !p.getDeleted() && p.getFunction() != null && p.getFunction().equals(f)) { functionExist = true; } } if (!functionExist) { Permission permission = new Permission(); permission.setFunction(f); permission.setRole(roleSysHome.getInstance()); roleSysHome.getInstance().addPermission(permission); } } } } roleSysHome.getInstance().setUpdateDate(new Date()); String entityAction = roleSysHome.update(); if (entityAction.equalsIgnoreCase("updated")) { facesMessages.clear(); facesMessages.clearGlobalMessages(); init(); } } } catch (Exception e) { log.error(e.getMessage()); System.out.println(e.getMessage()); } return returnString; }