Skip to content

Feature 10786 #901

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

Merged
merged 3 commits into from
May 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -273,7 +273,7 @@ public void deletePost(String instanceId, String postId) {
// Delete wysiwyg content
WysiwygController.deleteFileAndAttachment(instanceId, postId);
// Delete publication
publicationService.removePublication(pubPK);
publicationService.deletePublication(pubPK);
// Delete silverContent
blogContentManager.deleteSilverContent(con, pubPK);
} catch (Exception e) {
@@ -467,7 +467,7 @@ public void deleteCategory(String instanceId, String id) {
.getPK(), nodePk);
}
// suppression de la catégorie
nodeService.removeNode(nodePk);
nodeService.deleteNode(nodePk);
} catch (Exception e) {
throw new BlogRuntimeException(e);
}
Original file line number Diff line number Diff line change
@@ -225,6 +225,8 @@ CREATE TABLE IF NOT EXISTS sb_node_node
orderNumber int DEFAULT (0) NULL,
lang char(2),
rightsDependsOn int default (-1) NOT NULL,
nodeRemovalDate varchar (10) NULL,
nodeRemoverId varchar (100) NULL,
CONSTRAINT PK_Node_Node PRIMARY KEY (nodeId, instanceId)
);

@@ -274,7 +276,9 @@ CREATE TABLE IF NOT EXISTS SB_Publication_Publi
pubCloneId int DEFAULT (-1),
pubCloneStatus varchar(50) NULL,
lang char(2) NULL,
pubdraftoutdate varchar(10) NULL
pubdraftoutdate varchar(10) NULL,
pubRemovalDate varchar(10) NULL,
pubRemoverId varchar(100) NULL
);

CREATE TABLE IF NOT EXISTS SB_Publication_PubliI18N
Original file line number Diff line number Diff line change
@@ -1043,7 +1043,7 @@ public void deleteCategory(String categoryId, String instanceId) {
}
// suppression de la categorie
NodePK nodePk = new NodePK(categoryId, instanceId);
node.removeNode(nodePk);
node.deleteNode(nodePk);
} catch (Exception e) {
throw new ForumsRuntimeException(e);
}
Original file line number Diff line number Diff line change
@@ -89,5 +89,7 @@ CREATE TABLE sb_node_node
type VARCHAR(50) NULL,
orderNumber INT DEFAULT (0) NULL,
lang CHAR(2),
rightsDependsOn INT DEFAULT (-1) NOT NULL
rightsDependsOn INT DEFAULT (-1) NOT NULL,
nodeRemovalDate VARCHAR (10) NULL,
nodeRemoverId VARCHAR (100) NULL
);
Original file line number Diff line number Diff line change
@@ -325,7 +325,7 @@ public void addDeleteAlbumProcesses(final NodePK albumPk) throws Exception {
for (final NodeDetail node : childrens) {
addDeleteAlbumProcesses(node.getNodePK());
}
getNodeService().removeNode(albumPk);
getNodeService().deleteNode(albumPk);
}

/**
Original file line number Diff line number Diff line change
@@ -111,3 +111,16 @@ publications.sort.default = 2
kmelia.stats.enable=false
# The maximum number of elements retrieve for statistics purpose
kmelia.stats.most.interested.query.limit=10

# The delay in days after which the topics and the publications in the bin of each kmelia instances
# are definitively deleted. 0 to disable. If greater than 0, the automatic deletion has to be
# then enabled for the bins to be clean out; for doing set a CRON value to the below property
# kmelia.autoDeletionCron.
kmelia.autoDeletionDelay = 0

# Cron to schedule the automatic deletion of old topics and publications in the bin of each
# Kmelia instances. Empty to disable the scheduling (and hence the automatic deletion of older
# items in the bins). If scheduling, the automatic deletion will be performed only if the property
# kmelia.autoDeletionDelay is greater than 0.
# If DeleteRemovedApplicationsDelay=0, the JOB is deactivated.
kmelia.autoDeletionCron =
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
public class KmeliaPasteDetail {

private String userId;
private NodePK toPK;
private final NodePK toPK;
private NodePK fromPK;
private String targetValidatorIds;
private String status;
Original file line number Diff line number Diff line change
@@ -21,18 +21,8 @@
package org.silverpeas.components.kmelia.service;

import org.apache.commons.io.FilenameUtils;
import org.silverpeas.components.kmelia.InstanceParameters;
import org.silverpeas.components.kmelia.KmeliaContentManager;
import org.silverpeas.components.kmelia.KmeliaCopyDetail;
import org.silverpeas.components.kmelia.KmeliaPasteDetail;
import org.silverpeas.components.kmelia.KmeliaPublicationHelper;
import org.silverpeas.components.kmelia.PublicationImport;
import org.silverpeas.components.kmelia.model.KmaxRuntimeException;
import org.silverpeas.components.kmelia.model.KmeliaPublication;
import org.silverpeas.components.kmelia.model.KmeliaRuntimeException;
import org.silverpeas.components.kmelia.model.TopicComparator;
import org.silverpeas.components.kmelia.model.TopicDetail;
import org.silverpeas.components.kmelia.model.ValidatorsList;
import org.silverpeas.components.kmelia.*;
import org.silverpeas.components.kmelia.model.*;
import org.silverpeas.components.kmelia.notification.*;
import org.silverpeas.core.ActionType;
import org.silverpeas.core.ResourceReference;
@@ -47,11 +37,7 @@
import org.silverpeas.core.annotation.Service;
import org.silverpeas.core.comment.service.CommentService;
import org.silverpeas.core.contribution.attachment.AttachmentException;
import org.silverpeas.core.contribution.attachment.model.DocumentType;
import org.silverpeas.core.contribution.attachment.model.HistorisedDocument;
import org.silverpeas.core.contribution.attachment.model.SimpleAttachment;
import org.silverpeas.core.contribution.attachment.model.SimpleDocument;
import org.silverpeas.core.contribution.attachment.model.SimpleDocumentPK;
import org.silverpeas.core.contribution.attachment.model.*;
import org.silverpeas.core.contribution.attachment.notification.AttachmentRef;
import org.silverpeas.core.contribution.content.form.FormException;
import org.silverpeas.core.contribution.content.form.RecordSet;
@@ -62,12 +48,7 @@
import org.silverpeas.core.contribution.model.ContributionIdentifier;
import org.silverpeas.core.contribution.publication.dao.DistributionTreeCriteria;
import org.silverpeas.core.contribution.publication.dao.PublicationCriteria;
import org.silverpeas.core.contribution.publication.model.CompletePublication;
import org.silverpeas.core.contribution.publication.model.Location;
import org.silverpeas.core.contribution.publication.model.PublicationDetail;
import org.silverpeas.core.contribution.publication.model.PublicationLink;
import org.silverpeas.core.contribution.publication.model.PublicationPK;
import org.silverpeas.core.contribution.publication.model.ValidationStep;
import org.silverpeas.core.contribution.publication.model.*;
import org.silverpeas.core.contribution.publication.service.PublicationService;
import org.silverpeas.core.contribution.template.form.dao.ModelDAO;
import org.silverpeas.core.contribution.template.publication.PublicationTemplate;
@@ -173,7 +154,7 @@
@Singleton
@Named("kmeliaService")
@Transactional(Transactional.TxType.SUPPORTS)
public class DefaultKmeliaService implements KmeliaService {
public class DefaultKmeliaService implements KmeliaService, KmeliaDeleter {

private static final String MESSAGES_PATH = "org.silverpeas.kmelia.multilang.kmeliaBundle";
private static final String SETTINGS_PATH = "org.silverpeas.kmelia.settings.kmeliaSettings";
@@ -538,7 +519,7 @@ public void deleteTopic(NodePK pkToDelete) {
}

// Delete the topic
nodeService.removeNode(pkToDelete);
nodeService.deleteNode(pkToDelete);
} catch (Exception e) {
throw new KmeliaRuntimeException(e);
}
@@ -824,6 +805,9 @@ private String createPublicationIntoTopicWithoutNotifications(PublicationDetail
PublicationPK pubPK;
try {
PublicationDetail detail = changePublicationStatusOnCreation(pubDetail, fatherPK);
if (isInTrash(fatherPK)) {
detail.setRemovalStatus(detail.getCreationDate(), detail.getCreatorId());
}
// create the publication
pubPK = publicationService.createPublication(detail);
detail.getPK().setId(pubPK.getId());
@@ -1151,8 +1135,14 @@ private void movePublicationInSameApplication(PublicationDetail pub, NodePK to,
if (to.isTrash()) {
sendPublicationInBasket(pub.getPK());
} else {
boolean isInTrash = isInTrash(to);
// update parent
publicationService.movePublication(pub.getPK(), to, false);
if (pub.isRemoved() && !isInTrash) {
publicationService.restorePublication(pub.getPK());
} else if (isInTrash) {
publicationService.removePublication(pub.getPK());
}
pub.setTargetValidatorId(pasteContext.getTargetValidatorIds());
processPublicationAfterMove(pub, to, pasteContext.getUserId());
}
@@ -1249,6 +1239,14 @@ private void movePublicationInAnotherApplication(PublicationDetail pub, NodePK t
int toSilverObjectId = getSilverObjectId(pub.getPK());
// add original positions to pasted publication
pdcManager.addPositions(positions, toSilverObjectId, to.getInstanceId());

if (to.isTrash()) {
sendPublicationInBasket(pub.getPK());
} else if (isInTrash(to)) {
publicationService.removePublication(pub.getPK());
} else if (pub.isRemoved()) {
publicationService.restorePublication(pub.getPK());
}
} catch (Exception e) {
throw new KmeliaRuntimeException(e);
}
@@ -1382,7 +1380,9 @@ private boolean isClone(PublicationDetail publication) {
*
* @param pubPK the unique identifier of the publication to delete.
*/
private void deletePublication(PublicationPK pubPK) {
@Override
@Transactional
public void deletePublication(PublicationPK pubPK) {
KmeliaOperationContext.about(DELETION);
try {
// remove form content
@@ -1392,7 +1392,7 @@ private void deletePublication(PublicationPK pubPK) {
// delete all links
publicationService.removeAllFathers(pubPK);
// delete the publication
publicationService.removePublication(pubPK);
publicationService.deletePublication(pubPK);
// delete reference to contentManager
deleteSilverContent(pubPK);
} catch (Exception e) {
@@ -1427,6 +1427,8 @@ private void sendPublicationInBasket(PublicationPK pubPK, boolean kmaxMode) {
publicationService.removeAllFathers(pubPK);
// add link between this publication and the basket topic
publicationService.addFather(pubPK, new NodePK(NodePK.BIN_NODE_ID, pubPK));
// set removal status
publicationService.removePublication(pubPK);

cleanUpPublicationsInBasket(pubPK);
} catch (Exception e) {
@@ -1442,6 +1444,8 @@ private void cleanUpPublicationsInBasket(PublicationPK pubPK) {
updateSilverContentVisibility(pubPK);

unIndexExternalElementsOfPublication(pubPK);

publicationService.removePublication(pubPK);
}

private void sendPublicationInBasket(PublicationPK pubPK) {
@@ -1453,15 +1457,19 @@ private void sendTopicInBasket(NodeDetail topic) {
topic.getIdentifier().getComponentInstanceId());

// get all the tree of folders, rooted to the topic, to be sent in the basket with the topic
final Collection<NodeDetail> children = nodeService.getDescendantDetails(topic.getNodePK());
for (final NodeDetail childTopic : children) {
List<NodeDetail> nodes = new ArrayList<>();
nodes.add(topic);
nodes.addAll(nodeService.getDescendantDetails(topic.getNodePK()));
for (final NodeDetail node : nodes) {
// set the removal status of the child
nodeService.removeNode(node);
// get all the direct publications in the topic child (including aliases)
final Collection<PublicationDetail> publications =
publicationService.getDetailsByFatherPK(childTopic.getNodePK());
publicationService.getDetailsByFatherPK(node.getNodePK());
// check each publication: if it is an alias, remove it, otherwise it is moved into the trash
// with its topic
for (PublicationDetail publication : publications) {
final KmeliaPublication kmeliaPublication = fromDetail(publication, childTopic.getNodePK());
final KmeliaPublication kmeliaPublication = fromDetail(publication, node.getNodePK());
if (kmeliaPublication.isAlias()) {
// remove only the alias
final Collection<Location> aliases = singletonList(kmeliaPublication.getLocation());
@@ -2975,7 +2983,7 @@ public void deleteAxis(String axisId, String componentId) {
}
removeCoordinatesByPoints(points, componentId);
// delete axis
nodeService.removeNode(pkToDelete);
nodeService.deleteNode(pkToDelete);
} catch (Exception e) {
throw new KmaxRuntimeException(e);
}
@@ -3052,7 +3060,7 @@ public void deletePosition(String positionId, String componentId) {
}
removeCoordinatesByPoints(points, componentId);
// delete component
nodeService.removeNode(pkToDelete);
nodeService.deleteNode(pkToDelete);
} catch (Exception e) {
throw new KmaxRuntimeException(e);
}
@@ -3950,7 +3958,7 @@ public void deleteTopic(@NonNull NodePK topic, String userId) {
return;
}
NodeDetail folder = getNodeHeader(topic);
boolean isInTrash = nodeService.getPath(topic).get(1).getId().equals(NodePK.BIN_NODE_ID);
boolean isInTrash = isInTrash(topic);
// check if user is allowed to delete this topic
NodePK root = new NodePK(NodePK.ROOT_NODE_ID, topic.getInstanceId());
if (SilverpeasRole.ADMIN.isInRole(getUserTopicProfile(topic, userId)) ||
@@ -3991,13 +3999,33 @@ public boolean isRelatedTo(final String instanceId) {
instanceId.startsWith("toolbox");
}

private void removeOrRestoreNode(NodeDetail node, boolean isRemoval) {
if (node.isRemoved() && !isRemoval) {
nodeService.restoreNode(node);
} else if (!node.isRemoved() && isRemoval) {
nodeService.removeNode(node);
}
}

private boolean isInTrash(NodePK nodePK) {
if (nodePK.isTrash()) {
return true;
} else if (nodePK.isRoot() || nodePK.isUnclassed()) {
return false;
}
var destinationPath = nodeService.getPath(nodePK);
return destinationPath.stream().anyMatch(NodeDetail::isBin);
}

@SimulationActionProcess(elementLister = KmeliaNodeSimulationElementLister.class)
@Action(ActionType.MOVE)
@Transactional
@Override
public void moveNode(@SourcePK NodePK nodePK, @TargetPK NodePK to,
KmeliaPasteDetail pasteContext) {
List<NodeDetail> treeToPaste = nodeService.getSubTree(nodePK);

boolean inTrash = isInTrash(to);
boolean movedToAnotherApp = !nodePK.getInstanceId().equals(to.getInstanceId());
boolean rightsOnTopicsEnabled = isRightsOnTopicsEnabled(to.getInstanceId());

// move node and subtree
@@ -4006,18 +4034,20 @@ public void moveNode(@SourcePK NodePK nodePK, @TargetPK NodePK to,
for (NodeDetail fromNode : treeToPaste) {
if (fromNode != null) {
NodePK toNodePK = new NodePK(fromNode.getNodePK().getId(), to);
boolean movedToAnotherApp = !nodePK.getInstanceId().equals(to.getInstanceId());

NodeDetail toNode;
if (movedToAnotherApp) {
NodeDetail toNode = nodeService.getDetail(toNodePK);
toNode = nodeService.getDetail(toNodePK);

checkNodeRights(fromNode, toNode, rightsOnTopicsEnabled);
// move rich description of node
if (!nodePK.getInstanceId().equals(to.getInstanceId())) {
WysiwygController.move(fromNode.getNodePK().getInstanceId(),
NODE_PREFIX + fromNode.getId(), to.getInstanceId(), NODE_PREFIX + toNodePK.getId());
}
} else {
toNode = fromNode;
}
removeOrRestoreNode(toNode, inTrash);

// move publications of node
movePublicationsOfTopic(fromNode.getNodePK(), toNodePK, pasteContext);
@@ -4078,6 +4108,7 @@ private NodeDetail copyNode(KmeliaCopyDetail copyDetail, HashMap<String, String>
NodeDetail nodeToCopy = nodeService.getDetail(nodePKToCopy);
NodeDetail father = getNodeHeader(targetPK);
boolean rightsOnTopicsEnabled = isRightsOnTopicsEnabled(targetPK.getInstanceId());
boolean inTrash = isInTrash(targetPK);

// paste topic
NodePK nodePK = new NodePK(UNKNOWN, targetPK);
@@ -4086,6 +4117,11 @@ private NodeDetail copyNode(KmeliaCopyDetail copyDetail, HashMap<String, String>
node.setCreatorId(userId);
node.setRightsDependsOn(NodeDetail.NO_RIGHTS_DEPENDENCY);
node.setCreationDate(new Date());
if (inTrash) {
node.setRemovalStatus(new Date(), userId);
} else {
node.setRemovalStatus(null, null);
}
nodePK = nodeService.createNode(node, father);

// duplicate the predefined classification on the PdC if any
@@ -4261,6 +4297,7 @@ private PublicationDetail copyPublication(final PublicationDetail publiToCopy, f
newPubli.setTranslations(publiToCopy.getClonedTranslations());
newPubli.setAuthor(publiToCopy.getAuthor());
newPubli.setCreatorId(userId);
newPubli.setCreationDate(new Date());
if (copyDetail.isPublicationContentMustBeCopied()) {
newPubli.setInfoId(publiToCopy.getInfoId());
}
Loading
Oops, something went wrong.