@SuppressWarnings("unchecked") @Override public void createBeanDetails(T party) { Set<String> selectedRoles; Set<String> selectedClassiffcations; logger.info(">createBean"); selectedRoles = (Set<String>) this.rolesGroup.getValue(); for (String selectedRole : selectedRoles) { PartyRoleType partyRoleType; PartyRole partyRole; partyRoleType = this.app.getServices().getCrudServicePartyRoleType().findForDescription(selectedRole); partyRole = new PartyRole(); partyRole.setParty(party); partyRole.setPartyRoleType(partyRoleType); this.app.getServices().getCrudServicePartyRole().create(partyRole); } selectedClassiffcations = (Set<String>) this.classificationsGroup.getValue(); for (String selectedClassiffcation : selectedClassiffcations) { PartyType partyType; PartyClassification partyClassification; partyType = this.app .getServices() .getCrudServicePartyType() .findForDescription(selectedClassiffcation); partyClassification = new PartyClassification(); partyClassification.setParty(party); partyClassification.setPartyType(partyType); this.app.getServices().getCrudServicePartyClassification().create(partyClassification); } logger.info("<createBean"); }
private void resetOptionGroupClassification(Party party) { List<PartyType> partyTypes; BeanItemContainer<String> container; partyTypes = this.app.getServices().getCrudServicePartyType().findAll(); container = new BeanItemContainer<String>(String.class); for (PartyType t : partyTypes) { container.addBean(t.getDescription()); } this.classificationsGroup.setContainerDataSource(container); // set selection this.classificationsGroup.setValue(null); if (party != null) { List<PartyClassification> classifications; classifications = this.app.getServices().getCrudServicePartyClassification().findByParty(party.getId()); for (PartyClassification p : classifications) { this.classificationsGroup.select(p.getPartyType().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); } } }