Commit 19f21fdd authored by Brian Long's avatar Brian Long
Browse files

fixed group multi-match snafu on startup

parent df37818f
Loading
Loading
Loading
Loading
+20 −11
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@ package com.inteligr8.activiti;
import java.util.Arrays;
import java.util.List;

import javax.persistence.NonUniqueResultException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -65,22 +67,29 @@ public class ActivitiAppAdminMembersFixer implements DataFixer {
			return;

    	Long tenantId = this.tenantFinderService.findTenantId();
    	List<Group> groups;
    	List<Group> groups = null;
    	try {
			Group group1 = this.groupService.getGroupByExternalIdAndTenantId(this.adminGroupExternalId, tenantId);
		if (group1 != null) {
			if (group1 != null)
				groups = Arrays.asList(group1);
		} else {
			groups = this.groupService.getGroupByNameAndTenantId(this.adminGroupName, tenantId);
    	} catch (NonUniqueResultException nure) {
    		// suppress
    	}
		if (groups == null)
			groups = this.groupService.getGroupByNameAndTenantId(this.adminGroupName, tenantId);
		
		this.logger.debug("Found {} admin group(s)", groups.size());
		
		for (String email : adminUsers) {
    		User user = this.userService.findUserByEmail(email);

    		User user = this.userService.findUserByEmailAndTenantId(email, tenantId);
    		if (user == null) {
    			this.logger.info("The user with email '{}' does not exist, so they cannot be added as an administrator", email);
    		} else {
	    		this.logger.debug("Adding {} to admin group(s)", user.getEmail());
	    		for (Group group : groups)
	    			this.groupService.addUserToGroup(group, user);
    		}
		}
	}

}