private void resetOptionGroupRoles(Party party) { List<PartyRoleType> partyRoleTypes; partyRoleTypes = this.app.getServices().getCrudServicePartyRoleType().findAll(); for (PartyRoleType partyRoleType : partyRoleTypes) { this.rolesGroup.addItem(partyRoleType.getDescription()); } // set selection this.rolesGroup.setValue(null); if (party != null) { List<PartyRole> partyRoles; partyRoles = this.app.getServices().getCrudServicePartyRole().findByParty(party.getId()); for (PartyRole p : partyRoles) { this.rolesGroup.select(p.getPartyRoleType().getDescription()); } } }
@SuppressWarnings("unchecked") @Override public void updateBeanDetails(T party) { List<PartyRole> partyRoles; List<PartyClassification> classifications; Set<String> selectedRoles; Set<String> selectedClassifications; logger.info(">updateBean"); selectedRoles = (Set<String>) this.rolesGroup.getValue(); // remove all unselected roles partyRoles = this.app.getServices().getCrudServicePartyRole().findByParty(party.getId()); for (PartyRole partyRole : partyRoles) { if (!selectedRoles.contains(partyRole.getPartyRoleType().getDescription())) { this.app.getServices().getCrudServicePartyRole().delete(partyRole.getId()); } } // add all selected items to the party for (String selectedRole : selectedRoles) { PartyRole partyRole; partyRole = this.app .getServices() .getCrudServicePartyRole() .findByPartyAndPartyRoleType(party.getId(), selectedRole); if (partyRole == null) { PartyRoleType partyRoleType; partyRoleType = this.app.getServices().getCrudServicePartyRoleType().findForDescription(selectedRole); partyRole = new PartyRole(); partyRole.setParty(party); partyRole.setPartyRoleType(partyRoleType); this.app.getServices().getCrudServicePartyRole().create(partyRole); } else { this.app.getServices().getCrudServicePartyRole().update(partyRole); } } selectedClassifications = (Set<String>) this.classificationsGroup.getValue(); // remove all unselected classifications classifications = this.app.getServices().getCrudServicePartyClassification().findByParty(party.getId()); for (PartyClassification classification : classifications) { if (!selectedClassifications.contains(classification.getPartyType().getDescription())) { this.app.getServices().getCrudServicePartyClassification().delete(classification.getId()); } } // add selected items for (String selectedClass : selectedClassifications) { PartyClassification partyClass; partyClass = this.app .getServices() .getCrudServicePartyClassification() .findByPartyType(party.getId(), selectedClass); if (partyClass == null) { PartyType partyType; partyType = this.app.getServices().getCrudServicePartyType().findForDescription(selectedClass); partyClass = new PartyClassification(); partyClass.setParty(party); partyClass.setPartyType(partyType); this.app.getServices().getCrudServicePartyClassification().create(partyClass); } else { this.app.getServices().getCrudServicePartyClassification().update(partyClass); } } }