EventExpectation createOrFindPermittableGroup()

in service/src/main/java/org/apache/fineract/cn/provisioner/internal/service/applications/IdentityServiceInitializer.java [258:291]


  EventExpectation createOrFindPermittableGroup(
          final @Nonnull IdentityManager identityService,
          final @Nonnull PermittableGroup permittableGroup) {
    final EventExpectation eventExpectation = identityListener.expectPermittableGroupCreation(TenantContextHolder.checkedGetIdentifier(), permittableGroup.getIdentifier());
    try {
      identityService.createPermittableGroup(permittableGroup);
      logger.info("Group '{}' creation successfully requested in identity service for tenant {}.", permittableGroup.getIdentifier(), TenantContextHolder.checkedGetIdentifier());
    }
    catch (final PermittableGroupAlreadyExistsException groupAlreadyExistsException)
    {
      identityListener.withdrawExpectation(eventExpectation);
      //if the group already exists, read out and compare.  If the group is the same, there is nothing left to do.
      final PermittableGroup existingGroup = identityService.getPermittableGroup(permittableGroup.getIdentifier());
      if (!existingGroup.getIdentifier().equals(permittableGroup.getIdentifier())) {
        logger.error("Group '{}' already exists for tenant {}, but has a different name {} (strange).", permittableGroup.getIdentifier(), TenantContextHolder.checkedGetIdentifier(), existingGroup.getIdentifier());
      }

      //Compare as sets because I'm not going to get into a hissy fit over order.
      final Set<PermittableEndpoint> existingGroupPermittables = new HashSet<>(existingGroup.getPermittables());
      final Set<PermittableEndpoint> newGroupPermittables = new HashSet<>(permittableGroup.getPermittables());
      if (!existingGroupPermittables.equals(newGroupPermittables)) {
        logger.warn("Group '{}' already exists for tenant {}, but has different contents. " +
            "Needed contents are '{}', existing contents are '{}'",
            permittableGroup.getIdentifier(), TenantContextHolder.checkedGetIdentifier(),
            newGroupPermittables, existingGroupPermittables);
      }
    }
    catch (final RuntimeException unexpected)
    {
      identityListener.withdrawExpectation(eventExpectation);
      logger.error("Creating group '{}' for tenant {} failed.", permittableGroup.getIdentifier(), TenantContextHolder.checkedGetIdentifier(), unexpected);
    }
    return eventExpectation;
  }