Skip to content

Commit

Permalink
Bug #10683: improving performances on workflow engine by making a laz…
Browse files Browse the repository at this point in the history
…y loading of user group identifiers instead of loading them all the time.
  • Loading branch information
SilverYoCha committed May 15, 2019
1 parent 6971172 commit 45b5863
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 51 deletions.
Expand Up @@ -65,8 +65,14 @@
import org.silverpeas.core.workflow.engine.datarecord.ProcessInstanceDataRecord;
import org.silverpeas.core.workflow.engine.datarecord.ProcessInstanceRowRecord;

import javax.persistence.*;
import javax.persistence.AttributeOverride;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -1246,7 +1252,7 @@ public Actor[] getWorkingUsers(String state, String role) throws WorkflowExcepti
/**
* Returns all the state name assigned to the user.
*/
public String[] getAssignedStates(User user, String roleName) throws WorkflowException {
public String[] getAssignedStates(User user, String roleName) {
List<String> stateNames = new ArrayList<>();
String userId = user.getUserId();

Expand All @@ -1255,7 +1261,7 @@ public String[] getAssignedStates(User user, String roleName) throws WorkflowExc
boolean usersRoleMatch =
wkUser.getUsersRole() != null && wkUser.getUsersRole().equals(roleName);
boolean userGroupsMatch = false;
if (StringUtil.isDefined(wkUser.getGroupId()) && user.getGroupIds() != null) {
if (StringUtil.isDefined(wkUser.getGroupId())) {
// check if one of userGroups matches with working group
userGroupsMatch = user.getGroupIds().contains(wkUser.getGroupId());
}
Expand Down
Expand Up @@ -23,15 +23,18 @@
*/
package org.silverpeas.core.workflow.engine.user;

import org.silverpeas.core.util.logging.SilverLogger;
import org.silverpeas.core.workflow.api.user.User;
import org.silverpeas.core.admin.service.AdminException;
import org.silverpeas.core.admin.service.AdministrationServiceProvider;
import org.silverpeas.core.admin.user.model.UserDetail;
import org.silverpeas.core.admin.user.model.UserFull;
import org.silverpeas.core.util.logging.SilverLogger;
import org.silverpeas.core.workflow.api.user.User;

import java.util.List;

import static java.util.Arrays.asList;
import static org.silverpeas.core.admin.service.OrganizationControllerProvider.getOrganisationController;

/**
* A User implementation built upon the silverpeas user management system.
*/
Expand Down Expand Up @@ -110,10 +113,9 @@ public boolean equals(Object user) {

@Override
public List<String> getGroupIds() {
if (groupIds == null) {
groupIds = asList(getOrganisationController().getAllGroupIdsOfUser(getUserId()));
}
return groupIds;
}

public void setGroupIds(List<String> groupIds) {
this.groupIds = groupIds;
}
}
Expand Up @@ -25,8 +25,6 @@

import org.silverpeas.core.admin.component.model.ComponentInst;
import org.silverpeas.core.admin.service.AdminException;
import org.silverpeas.core.admin.service.AdministrationServiceProvider;
import org.silverpeas.core.admin.service.OrganizationControllerProvider;
import org.silverpeas.core.admin.user.model.UserDetail;
import org.silverpeas.core.workflow.api.UserManager;
import org.silverpeas.core.workflow.api.WorkflowException;
Expand All @@ -36,7 +34,10 @@
import org.silverpeas.core.workflow.engine.exception.UnknownUserException;

import javax.inject.Singleton;
import java.util.Arrays;
import java.util.stream.Stream;

import static org.silverpeas.core.admin.service.AdministrationServiceProvider.getAdminService;
import static org.silverpeas.core.admin.service.OrganizationControllerProvider.getOrganisationController;

/**
* A UserManager implementation built upon the silverpeas user management system.
Expand All @@ -52,13 +53,7 @@ public class UserManagerImpl implements UserManager {
*/
@Override
public User getUser(String userId) throws WorkflowException {
UserImpl user = new UserImpl(getUserDetail(userId));
String[] groupIds = OrganizationControllerProvider.getOrganisationController()
.getAllGroupIdsOfUser(userId);
if (groupIds != null) {
user.setGroupIds(Arrays.asList(groupIds));
}
return user;
return new UserImpl(getUserDetail(userId));
}

/**
Expand All @@ -68,8 +63,9 @@ public User getUser(String userId) throws WorkflowException {
* @throws WorkflowException
* @throw WorkflowException if a userId is unknown.
*/
@Override
public User[] getUsers(String[] userIds) throws WorkflowException {
User[] users = new User[userIds.length];
final User[] users = new User[userIds.length];
for (int i = 0; i < userIds.length; i++) {
users[i] = getUser(userIds[i]);
}
Expand All @@ -85,40 +81,32 @@ public User[] getUsers(String[] userIds) throws WorkflowException {
*/
@Override
public User[] getUsersInRole(String roleName, String modelId) throws WorkflowException {
UserDetail[] userDetails = null;
UserDetail[] userDetails;
try {
// the modelId is the peasId.
ComponentInst peas = AdministrationServiceProvider.getAdminService().getComponentInst(modelId);
userDetails = OrganizationControllerProvider.getOrganisationController().getUsers(
peas.getDomainFatherId(),
modelId, roleName);
final ComponentInst peas = getAdminService().getComponentInst(modelId);
userDetails = getOrganisationController().getUsers(peas.getDomainFatherId(), modelId, roleName);
} catch (AdminException e) {
throw new WorkflowException("UserManagerImpl.getUserInRole",
"workflowEngine.EXP_UNKNOWN_ROLE", e);
}

if (userDetails == null) {
userDetails = new UserDetail[0];
}
return getUsers(userDetails);
return asUsers(userDetails);
}

@Override
public User[] getUsersInGroup(String groupId) {
UserDetail[] userDetails = OrganizationControllerProvider.getOrganisationController()
.getAllUsersOfGroup(groupId);

if (userDetails == null) {
userDetails = new UserDetail[0];
}
return getUsers(userDetails);
final UserDetail[] userDetails = getOrganisationController().getAllUsersOfGroup(groupId);
return asUsers(userDetails);
}

/**
* returns the userDetail of a userId.
*/
private UserDetail getUserDetail(String userId) throws WorkflowException {
UserDetail userDetail = UserDetail.getById(userId);
final UserDetail userDetail = UserDetail.getById(userId);
if (userDetail == null) {
throw new UnknownUserException("UserManagerImpl.getUserDetail", userId);
}
Expand All @@ -128,17 +116,8 @@ private UserDetail getUserDetail(String userId) throws WorkflowException {
/**
* Make a User[] from a UserDetail[].
*/
private User[] getUsers(UserDetail[] userDetails) {
UserImpl[] users = new UserImpl[userDetails.length];
for (int i = 0; i < userDetails.length; i++) {
users[i] = new UserImpl(userDetails[i]);
String[] groupIds = OrganizationControllerProvider.getOrganisationController()
.getAllGroupIdsOfUser(userDetails[i].getId());
if (groupIds != null) {
users[i].setGroupIds(Arrays.asList(groupIds));
}
}
return users;
private User[] asUsers(UserDetail[] userDetails) {
return Stream.of(userDetails).map(UserImpl::new).toArray(User[]::new);
}

/**
Expand All @@ -152,20 +131,17 @@ private User[] getUsers(UserDetail[] userDetails) {
@Override
public User getRelatedUser(User user, String relation, String peasId)
throws WorkflowException {
UserSettings settings = UserSettingsService.get().get(user.getUserId(), peasId);
final UserSettings settings = UserSettingsService.get().get(user.getUserId(), peasId);
if (settings == null) {
throw new WorkflowException("UserManagerImpl.getRelatedUser",
"workflowEngine.EXP_NO_USER_SETTING", "user id : " + user.getUserId());
}

UserInfo info = settings.getUserInfo(relation);
final UserInfo info = settings.getUserInfo(relation);
if (info == null) {
throw new WorkflowException("UserManagerImpl.getRelatedUser",
"workflowEngine.EXP_USERINFO_NOT_FOUND", "user id : "
+ user.getUserId() + ", info name : " + relation);
}

return getUser(info.getValue());
}

}

0 comments on commit 45b5863

Please sign in to comment.