Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug #14015 [6.3.x]: Fixing administration services about spaces managed by a user or by a group. #1322

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -938,15 +938,23 @@ List<ComponentInstLight> getAvailCompoInSpace(String userId, String spaceId)
SpaceInstLight getRootSpace(String spaceId) throws AdminException;

/**
* Get the spaces ids manageable by given group id
* Get all the spaces ids manageable by given group id.
* <p>
* It means the direct space ids the group is indicated to and all the sub spaces ids by
* inheritance.
* </p>
* @param sGroupId the unique identifier of a group
* @return an array of space identifiers.
* @throws AdminException if an error occurs
*/
String[] getGroupManageableSpaceIds(String sGroupId) throws AdminException;

/**
* Get the spaces ids manageable by given user id
* Get all the spaces ids manageable by given user id.
* <p>
* It means the direct space ids the user is indicated to and all the sub spaces ids by
* inheritance.
* </p>
* @param sUserId the unique identifier of a user
* @return an array of space identifiers
* @throws AdminException if an error occurs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
import static java.util.Arrays.stream;
import static java.util.Collections.singletonList;
import static java.util.function.Predicate.not;
import static java.util.stream.Collectors.*;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
import static org.silverpeas.core.SilverpeasExceptionMessages.*;
import static org.silverpeas.core.admin.domain.DomainDriver.ActionConstants.ACTION_MASK_MIXED_GROUPS;
import static org.silverpeas.core.admin.service.DefaultAdministration.CheckoutGroupDescriptor.synchronizingDomainFrom;
Expand Down Expand Up @@ -3365,85 +3366,55 @@ public SpaceInstLight getRootSpace(String spaceId) throws AdminException {

@Override
public String[] getGroupManageableSpaceIds(String sGroupId) throws AdminException {
String[] asManageableSpaceIds;
ArrayList<String> alManageableSpaceIds = new ArrayList<>();
try {
// Get user manageable space ids from database
List<String> groupIds = new ArrayList<>();
groupIds.add(sGroupId);
List<Integer> manageableSpaceIds = spaceManager.getManageableSpaceIds(null, groupIds);

// Inherits manageability rights for space children
String[] childSpaceIds;
for (Integer spaceId : manageableSpaceIds) {
String asManageableSpaceId = String.valueOf(spaceId);
// add manageable space id in result
if (!alManageableSpaceIds.contains(asManageableSpaceId)) {
alManageableSpaceIds.add(asManageableSpaceId);
}

// calculate manageable space's childs
childSpaceIds = spaceManager.getAllSubSpaceIds(spaceId);
// add them in result
for (String childSpaceId : childSpaceIds) {
if (!alManageableSpaceIds.contains(childSpaceId)) {
alManageableSpaceIds.add(childSpaceId);
}
}
}

// Put user manageable space ids in cache
asManageableSpaceIds = alManageableSpaceIds.toArray(new String[0]);

return asManageableSpaceIds;
final List<String> groupIds = List.of(sGroupId);
// Get space ids on which the group is specifically indicated as manager
final List<Integer> directSpaceIds = spaceManager.getManageableSpaceIds(null, groupIds);
final List<SpaceInst> consumer = new ArrayList<>();
for (Integer directSpaceId : directSpaceIds) {
consumer.add(getSpaceInstById(String.valueOf(directSpaceId)));
}
// Identifying all managed space ids
final Set<String> allSpaces = new LinkedHashSet<>();
while (!consumer.isEmpty()) {
final SpaceInst current = consumer.remove(0);
allSpaces.add(String.valueOf(current.getLocalId()));
current.getSubSpaces().forEach(s -> consumer.add(0, s));
}
return allSpaces.toArray(new String[0]);
} catch (Exception e) {
throw new AdminException(failureOnGetting("spaces manageable by group", sGroupId), e);
}
}

@Override
public String[] getUserManageableSpaceIds(String sUserId) throws AdminException {
final Integer[] result;
ArrayList<String> alManageableSpaceIds = new ArrayList<>();
ArrayList<Integer> alDriverManageableSpaceIds = new ArrayList<>();
final String[] result;
try {
// Get user manageable space ids from cache
Optional<Integer[]> optionalSpaceIds = cache.getManageableSpaceIds(sUserId);
if (optionalSpaceIds.isEmpty()) {
// Get user manageable space ids from database

List<String> groupIds = getAllGroupsOfUser(sUserId);
final Integer[] manageableSpaceIds = userManager.getManageableSpaceIds(sUserId, groupIds);

// Inherits manageability rights for space children
String[] childSpaceIds;
for (Integer asManageableSpaceId : manageableSpaceIds) {
// add manageable space id in result
String asManageableSpaceIdAsString = String.valueOf(asManageableSpaceId);
if (!alManageableSpaceIds.contains(asManageableSpaceIdAsString)) {
alManageableSpaceIds.add(asManageableSpaceIdAsString);
alDriverManageableSpaceIds.add(asManageableSpaceId);
}

// calculate manageable space's childs
childSpaceIds = spaceManager.getAllSubSpaceIds(asManageableSpaceId);

// add them in result
for (String childSpaceId : childSpaceIds) {
if (!alManageableSpaceIds.contains(childSpaceId)) {
alManageableSpaceIds.add(childSpaceId);
alDriverManageableSpaceIds.add(getDriverSpaceId(childSpaceId));
}
}
final Optional<String[]> cachedSpaceIds = cache.getManageableSpaceIds(sUserId);
if (cachedSpaceIds.isEmpty()) {
final List<String> groupIds = getAllGroupsOfUser(sUserId);
// Get space ids on which the user is specifically indicated as manager
final Integer[] directSpaceIds = userManager.getManageableSpaceIds(sUserId, groupIds);
final List<SpaceInst> consumer = new ArrayList<>();
for (Integer directSpaceId : directSpaceIds) {
consumer.add(getSpaceInstById(String.valueOf(directSpaceId)));
}

// Put user manageable space ids in cache
result = alDriverManageableSpaceIds.toArray(new Integer[0]);
// Identifying all managed space ids
final Set<String> allSpaces = new LinkedHashSet<>();
while (!consumer.isEmpty()) {
final SpaceInst current = consumer.remove(0);
allSpaces.add(String.valueOf(current.getLocalId()));
current.getSubSpaces().forEach(s -> consumer.add(0, s));
}
result = allSpaces.toArray(new String[0]);
cache.putManageableSpaceIds(sUserId, result);
} else {
result = optionalSpaceIds.get();
result = cachedSpaceIds.get();
}
return stream(result).map(String::valueOf).toArray(String[]::new);
return result;
} catch (Exception e) {
throw new AdminException(failureOnGetting("spaces manageable by user", sUserId), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class AdminCache {
private boolean useUserDetailCache = true;
private Map<String, UserDetail> userDetailCache = new ConcurrentHashMap<>();
private boolean useManageableSpaceIdsCache = true;
private Map<String, Integer[]> manageableSpaceIdsCache = new ConcurrentHashMap<>();
private Map<String, String[]> manageableSpaceIdsCache = new ConcurrentHashMap<>();
private boolean useAvailCompoIdsCache = true;
private Map<String, Map<String, String[]>> availCompoIdsCache = new ConcurrentHashMap<>();
private boolean useProfileIdsCache = true;
Expand Down Expand Up @@ -274,7 +274,7 @@ private void resetManageableSpaceIds() {
manageableSpaceIdsCache.clear();
}

public void putManageableSpaceIds(String userId, Integer[] spaceIds) {
public void putManageableSpaceIds(String userId, String[] spaceIds) {
if (useCache && useManageableSpaceIdsCache) {
manageableSpaceIdsCache.put(userId, spaceIds);
}
Expand All @@ -286,7 +286,7 @@ private void removeManageableSpaceIds(String userId) {
}
}

public Optional<Integer[]> getManageableSpaceIds(String userId) {
public Optional<String[]> getManageableSpaceIds(String userId) {
if (useCache && useManageableSpaceIdsCache) {
return Optional.ofNullable(manageableSpaceIdsCache.get(userId));
} else {
Expand Down