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 integrity problems into administration caches. #1330

Merged
merged 1 commit into from
Mar 20, 2024
Merged
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
56 changes: 0 additions & 56 deletions core-api/src/main/java/org/silverpeas/core/util/TriConsumer.java

This file was deleted.

56 changes: 0 additions & 56 deletions core-api/src/main/java/org/silverpeas/core/util/TriFunction.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -380,21 +380,10 @@ public String addSpaceInst(String userId, SpaceInst spaceInst) throws AdminExcep
spaceManager.createSpaceInst(spaceInst);
// put new space in cache
cache.opAddSpace(getSpaceInstById(spaceInst.getLocalId()));

// Instantiate the components
List<ComponentInst> alCompoInst = spaceInst.getAllComponentsInst();
for (ComponentInst componentInst : alCompoInst) {
componentInst.setDomainFatherId(spaceInst.getId());
addComponentInst(userId, componentInst);
}

SpaceInstLight space = getSpaceInstLight(spaceInst.getLocalId());
final SpaceInstLight space = getSpaceInstLight(spaceInst.getLocalId());
mmoqui marked this conversation as resolved.
Show resolved Hide resolved
addSpaceInTreeCache(space, true);

// indexation de l'espace

createSpaceIndex(space);

return spaceInst.getId();
} catch (Exception e) {
SilverLogger.getLogger(this).error(e);
Expand Down Expand Up @@ -459,8 +448,8 @@ private void deleteEffectivelySpaceInst(final SpaceInst spaceInst, final String
}

// delete the space profiles instance
for (int nI = 0; nI < spaceInst.getNumSpaceProfileInst(); nI++) {
deleteSpaceProfileInst(spaceInst.getSpaceProfileInst(nI).getId());
for (final SpaceProfileInst spaceProfileInst : spaceInst.getAllSpaceProfilesInst()) {
deleteSpaceProfileInst(spaceProfileInst.getId());
}

// Delete the components
Expand Down Expand Up @@ -495,8 +484,8 @@ private void notifyOnSpaceLogicalDeletion(String spaceId) throws AdminException
private void deleteSpaceProfilesOnSpaceLogicalDeletion(SpaceInst spaceInst)
throws AdminException {
// delete the space profiles
for (int nI = 0; nI < spaceInst.getNumSpaceProfileInst(); nI++) {
deleteSpaceProfileInst(spaceInst.getSpaceProfileInst(nI).getId());
for (final SpaceProfileInst spaceProfileInst : spaceInst.getAllSpaceProfilesInst()) {
deleteSpaceProfileInst(spaceProfileInst.getId());
}

// delete the components profiles
Expand Down Expand Up @@ -1886,15 +1875,19 @@ public String addSpaceProfileInst(SpaceProfileInst spaceProfile, String userId)

private void spreadInheritedSpaceProfile(final SpaceProfileInst spaceProfile,
final Integer spaceId) throws AdminException {
if (!spaceProfile.isInherited()) {
// spread all the profiles with the given role (both specific and inherited) to both the
// subspaces and the component instances. The space profile here is used as a simple data to
// propagate to children.
SpaceProfileInst fullProfile = new SpaceProfileInst(spaceProfile);
if (!fullProfile.isInherited()) {
SpaceProfileInst inheritedProfile =
spaceProfileManager.getInheritedSpaceProfileInstByName(spaceId, spaceProfile.getName());
spaceProfileManager.getInheritedSpaceProfileInstByName(spaceId, fullProfile.getName());
if (inheritedProfile != null) {
spaceProfile.addGroups(inheritedProfile.getAllGroups());
spaceProfile.addUsers(inheritedProfile.getAllUsers());
fullProfile.addGroups(inheritedProfile.getAllGroups());
fullProfile.addUsers(inheritedProfile.getAllUsers());
}
}
spreadSpaceProfile(spaceId, spaceProfile);
spreadSpaceProfile(spaceId, fullProfile);
}

private void deleteSpaceProfileInst(String sSpaceProfileId) throws AdminException {
Expand Down Expand Up @@ -5457,7 +5450,7 @@ public String copyAndPasteComponent(PasteDetail pasteDetail)
// Creation
newCompo.setLocalId(-1);
newCompo.setDomainFatherId(destinationSpace.getId());
newCompo.setOrderNum(destinationSpace.getNumComponentInst());
newCompo.setOrderNum(destinationSpace.getAllComponentsInst().size());
newCompo.setCreationDate(new Date());
newCompo.setCreatorUserId(pasteDetail.getUserId());
newCompo.setLanguage(lang);
Expand Down Expand Up @@ -5531,13 +5524,21 @@ public String copyAndPasteSpace(PasteDetail pasteDetail) throws AdminException,
// paste space itself
SpaceInst oldSpace = getSpaceInstById(spaceId);
SpaceInst newSpace = createPasteSpace(pasteDetail, oldSpace, toSpaceId);

// Remove inherited profiles from cloned space
newSpace.removeInheritedProfiles();

// Remove components from cloned space
List<ComponentInst> components = newSpace.getAllComponentsInst();
newSpace.removeAllComponentsInst();
newSpace.resetData();

// Getting and copying from space to clone the specific profiles
oldSpace.getAllSpaceProfilesInst()
.stream()
.filter(not(SpaceProfileInst::isInherited))
.map(SpaceProfileInst::new)
.forEach(newSpace::addSpaceProfileInst);

// Getting from space to clone the components to copy
final List<ComponentInst> componentsToCopy = oldSpace.getAllComponentsInst().stream().map(c -> {
final ComponentInst componentInst = new ComponentInst(c);
componentInst.setLocalId(c.getLocalId());
return componentInst;
}).collect(toList());

// Add space
newSpaceId = addSpaceInst(pasteDetail.getUserId(), newSpace);
Expand All @@ -5547,10 +5548,11 @@ public String copyAndPasteSpace(PasteDetail pasteDetail) throws AdminException,

// paste components
String componentIdAsHomePage =
pasteComponentsOfSpace(pasteDetail, newSpaceId, newSpace, components);
pasteComponentsOfSpace(pasteDetail, newSpaceId, newSpace, componentsToCopy);

// paste subspaces
pasteSubspacesOfSpace(pasteDetail, newSpaceId, newSpace);
final List<SpaceInst> subSpacesToCopy = oldSpace.getSubSpaces();
pasteSubspacesOfSpace(pasteDetail, subSpacesToCopy, newSpaceId);

// update parameter of space home page if needed
String newFirstPageExtraParam = null;
Expand All @@ -5570,21 +5572,21 @@ public String copyAndPasteSpace(PasteDetail pasteDetail) throws AdminException,
return newSpaceId;
}

private void pasteSubspacesOfSpace(final PasteDetail pasteDetail, final String newSpaceId,
final SpaceInst newSpace) throws AdminException, QuotaException {
private void pasteSubspacesOfSpace(final PasteDetail pasteDetail,
final List<SpaceInst> subSpacesToCopy, final String newSpaceId)
throws AdminException, QuotaException {
PasteDetail subSpacePasteDetail = new PasteDetail(pasteDetail.getUserId());
subSpacePasteDetail.setOptions(pasteDetail.getOptions());
subSpacePasteDetail.setToSpaceId(newSpaceId);
List<SpaceInst> subSpaceInsts = newSpace.getSubSpaces();
for (SpaceInst subSpaceInst : subSpaceInsts) {
subSpacePasteDetail.setFromSpaceId(subSpaceInst.getId());
for (SpaceInst subSpaceInstToCopy : subSpacesToCopy) {
subSpacePasteDetail.setFromSpaceId(subSpaceInstToCopy.getId());
copyAndPasteSpace(subSpacePasteDetail);
}
}

@Nullable
private String pasteComponentsOfSpace(final PasteDetail pasteDetail, final String newSpaceId,
final SpaceInst newSpace, final List<ComponentInst> components)
final SpaceInst newSpace, final List<ComponentInst> componentsToCopy)
throws AdminException, QuotaException {
// verify space homepage
String componentIdAsHomePage = null;
Expand All @@ -5596,7 +5598,7 @@ private String pasteComponentsOfSpace(final PasteDetail pasteDetail, final Strin
PasteDetail componentPasteDetail = new PasteDetail(pasteDetail.getUserId());
componentPasteDetail.setOptions(pasteDetail.getOptions());
componentPasteDetail.setToSpaceId(newSpaceId);
for (ComponentInst component : components) {
for (ComponentInst component : componentsToCopy) {
componentPasteDetail.setFromComponentId(component.getId());
String componentId = copyAndPasteComponent(componentPasteDetail);
// check if new component must be used as home page of new space
Expand Down Expand Up @@ -5628,20 +5630,19 @@ private SpaceInst createPasteSpace(final PasteDetail pasteDetail, final SpaceIns
final String toSpaceId) throws AdminException {
SpaceInst newSpace = new SpaceInst(oldSpace);
newSpace.setLocalId(-1);
List<String> newBrotherIds;
final List<String> brotherSpaceIds;
if (StringUtil.isDefined(toSpaceId)) {
SpaceInst destinationSpace = getSpaceInstById(toSpaceId);
newSpace.setDomainFatherId(destinationSpace.getId());
List<SpaceInst> brothers = destinationSpace.getSubSpaces();
newBrotherIds = new ArrayList<>(brothers.size());
for (SpaceInst brother : brothers) {
newBrotherIds.add(brother.getId());
}
brotherSpaceIds = destinationSpace.getSubSpaces()
.stream()
.map(SpaceInst::getId)
.collect(toList());
} else {
newSpace.setDomainFatherId("-1");
newBrotherIds = Arrays.asList(getAllRootSpaceIds());
brotherSpaceIds = Arrays.asList(getAllRootSpaceIds());
}
newSpace.setOrderNum(newBrotherIds.size());
newSpace.setOrderNum(brotherSpaceIds.size());
newSpace.setCreationDate(new Date());
newSpace.setCreatorUserId(pasteDetail.getUserId());
String lang = oldSpace.getLanguage();
Expand All @@ -5651,11 +5652,11 @@ private SpaceInst createPasteSpace(final PasteDetail pasteDetail, final SpaceIns
newSpace.setLanguage(lang);

// Rename if spaceName already used in the destination space
List<SpaceInstLight> subSpaces = new ArrayList<>();
for (String subSpaceId : newBrotherIds) {
subSpaces.add(getSpaceInstLight(getDriverSpaceId(subSpaceId)));
List<SpaceInstLight> brotherSpaces = new ArrayList<>();
for (String subSpaceId : brotherSpaceIds) {
brotherSpaces.add(getSpaceInstLight(getDriverSpaceId(subSpaceId)));
}
String name = renameSpace(newSpace.getName(newSpace.getLanguage()), subSpaces);
String name = renameSpace(newSpace.getName(newSpace.getLanguage()), brotherSpaces);
newSpace.setName(name);

return newSpace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,8 @@ public SpaceInst copy(SpaceInst spaceInstToCopy) {
spaceInst.setInheritanceBlocked(spaceInstToCopy.isInheritanceBlocked());
spaceInst.setLook(spaceInstToCopy.getLook());

// Create a copy of array of subspaces ids
final List<SpaceInst> subSpacesToCopy = spaceInstToCopy.getSubSpaces();
// Create a copy of components
final List<ComponentInst> componentInstToCopy = spaceInstToCopy.getAllComponentsInst()
.stream()
.map(i -> componentInstManager.copy(i))
.collect(Collectors.toList());
// Create a copy of space profiles
final List<SpaceProfileInst> spaceProfilesToCopy = spaceInstToCopy.getAllSpaceProfilesInst();
// Copy above data
spaceInst.setData(spaceProfilesToCopy, subSpacesToCopy, componentInstToCopy);
// Copy data
spaceInst.copyDataFrom(spaceInstToCopy);

spaceInst.setLanguage(spaceInstToCopy.getLanguage());

Expand Down Expand Up @@ -160,8 +151,8 @@ public void createSpaceInst(SpaceInst spaceInst) throws AdminException {
}

// Create the SpaceProfile nodes
for (int nI = 0; nI < spaceInst.getNumSpaceProfileInst(); nI++) {
spaceProfileInstManager.createSpaceProfileInst(spaceInst.getSpaceProfileInst(nI),
for (final SpaceProfileInst spaceProfileInst : spaceInst.getAllSpaceProfilesInst()) {
spaceProfileInstManager.createSpaceProfileInst(spaceProfileInst,
spaceInst.getLocalId());
}
} catch (Exception e) {
Expand Down Expand Up @@ -217,20 +208,21 @@ public void loadSpaceInstData(final SpaceInst spaceInst)
final int spaceInstLocalId = spaceInst.getLocalId();
try {
// Get the sub spaces
final List<SpaceInst> subSpaces = organizationSchema.space()
final List<String> subSpaceIds = organizationSchema.space()
.getDirectSubSpaces(spaceInstLocalId)
.stream()
.map(this::spaceRow2SpaceInst)
.map(SpaceInst::getId)
.collect(Collectors.toList());
// Get the components
final String[] asCompoIds = organizationSchema.instance().getAllComponentInstanceIdsInSpace(
spaceInstLocalId);
final List<ComponentInst> components = new ArrayList<>(asCompoIds.length);
final List<String> componentIds = new ArrayList<>(asCompoIds.length);
for (String componentId : asCompoIds) {
ComponentInst componentInst =
componentInstManager.getComponentInst(idAsInt(componentId), spaceInstLocalId);
WAComponent.getByName(componentInst.getName())
.ifPresent(waComponent -> components.add(componentInst));
.ifPresent(waComponent -> componentIds.add(componentInst.getId()));
}
// Get the space profiles
String[] asProfIds = organizationSchema.spaceUserRole().getAllSpaceUserRoleIdsOfSpace(
Expand All @@ -241,7 +233,7 @@ public void loadSpaceInstData(final SpaceInst spaceInst)
spaceProfileInstManager.getSpaceProfileInst(profileId, false);
spaceProfiles.add(spaceProfileInst);
}
spaceInst.setData(spaceProfiles, subSpaces, components);
spaceInst.setData(spaceProfiles, subSpaceIds, componentIds);
} catch (SQLException e) {
throw new AdminException(failureOnGetting(SPACE, String.valueOf(spaceInstLocalId)), e);
}
Expand Down