/*
   * (non-Javadoc)
   * @see org.openhds.service.IndividualMergeService#mergeIndividuals(org.openhds.model.Individual, org.openhds.model.Individual)
   */
  @Transactional(rollbackFor = {ConstraintViolations.class, SQLException.class})
  public int mergeIndividuals(Individual primary, Individual toMergeFrom, List<MergeEvents> events)
      throws ConstraintViolations, SQLException {
    // this is a naive implementation and will most likely be extended/specialized in the future
    // currently, only in migrations and memberships can be merged/copied from 2 individuals
    int eventsMerged = 0;

    // grab the in migrations first
    if (events.contains(MergeEvents.IN_MIGRATION)) {
      List<InMigration> inMigs = getInMigrationEvents(primary, toMergeFrom);
      eventsMerged += inMigs.size();

      for (InMigration inMig : inMigs) {
        inMigrationService.evaluateInMigration(inMig);
        entityService.create(inMig);
      }
    }

    if (events.contains(MergeEvents.MEMBERSHIP)) {
      // now the memberships
      List<Membership> memberships = getMembershipEvents(primary, toMergeFrom);
      eventsMerged += memberships.size();

      for (Membership mem : memberships) {
        membershipService.evaluateMembership(mem);
        entityService.create(mem);
      }
    }

    return eventsMerged;
  }
  @Override
  public String edit() {
    try {
      service.evaluateInMigrationOnEdit(entityItem);
      super.edit();

      return "pretty:migrationsEdit";
    } catch (Exception e) {
      jsfService.addError(e.getMessage());
    }
    return null;
  }
 private void createInMigration() throws ConstraintViolations, SQLException, Exception {
   service.evaluateInMigration(entityItem);
   service.createInMigration(entityItem);
 }