Skip to content

Commit 26de461

Browse files
committed
Feature #10542
In Kmelia, removing a folder relocates it now, with all of its subfolders and publications, into the bin like the publications. A folder is then definitively deleted when the bin is purged.
1 parent e3fd80e commit 26de461

File tree

3 files changed

+106
-53
lines changed

3 files changed

+106
-53
lines changed

kmelia/kmelia-library/src/main/java/org/silverpeas/components/kmelia/service/DefaultKmeliaService.java

Lines changed: 78 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
import org.silverpeas.core.util.annotation.TargetPK;
115115
import org.silverpeas.core.util.file.FileRepositoryManager;
116116
import org.silverpeas.core.util.file.FileUtil;
117+
import org.silverpeas.kernel.annotation.NonNull;
117118
import org.silverpeas.kernel.bundle.LocalizationBundle;
118119
import org.silverpeas.kernel.bundle.ResourceLocator;
119120
import org.silverpeas.kernel.bundle.SettingBundle;
@@ -532,7 +533,7 @@ public void deleteTopic(NodePK pkToDelete) {
532533
for (PublicationDetail onePubToCheck : pubsToCheck) {
533534
final KmeliaPublication kmeliaPub = fromDetail(onePubToCheck, oneNodeToDelete);
534535
if (!kmeliaPub.isAlias()) {
535-
sendPublicationToBasket(kmeliaPub.getPk());
536+
sendPublicationInBasket(kmeliaPub.getPk());
536537
} else {
537538
// remove only the alias
538539
final Collection<Location> aliases = singletonList(kmeliaPub.getLocation());
@@ -1153,7 +1154,7 @@ public void movePublicationInSameApplication(@SourcePK PublicationPK pubPK, @Tar
11531154
private void movePublicationInSameApplication(PublicationDetail pub, NodePK to,
11541155
KmeliaPasteDetail pasteContext) {
11551156
if (to.isTrash()) {
1156-
sendPublicationToBasket(pub.getPK());
1157+
sendPublicationInBasket(pub.getPK());
11571158
} else {
11581159
// update parent
11591160
publicationService.movePublication(pub.getPK(), to, false);
@@ -1381,12 +1382,6 @@ private boolean isClone(PublicationDetail publication) {
13811382
!isDefined(publication.getCloneStatus());
13821383
}
13831384

1384-
/**
1385-
* HEAD Delete a publication If this publication is in the basket or in the DZ, it's deleted from
1386-
* the database Else it only send to the basket.
1387-
* @param pubPK the id of the publication to delete
1388-
* @see TopicDetail
1389-
*/
13901385
@Override
13911386
@Transactional(Transactional.TxType.REQUIRED)
13921387
public void deletePublication(PublicationPK pubPK) {
@@ -1410,18 +1405,7 @@ public void deletePublication(PublicationPK pubPK) {
14101405

14111406
}
14121407

1413-
/**
1414-
* Send the publication in the basket topic.
1415-
* <p>
1416-
* All aliases of the publication are deleted if exist.
1417-
* </p>
1418-
* @param pubPK the id of the publication
1419-
* @param kmaxMode true to indicate a use from kmax application
1420-
* @see TopicDetail
1421-
* @since 1.0
1422-
*/
1423-
@Override
1424-
public void sendPublicationToBasket(PublicationPK pubPK, boolean kmaxMode) {
1408+
private void sendPublicationInBasket(PublicationPK pubPK, boolean kmaxMode) {
14251409
KmeliaOperationContext.about(REMOVING);
14261410
try {
14271411
// remove coordinates for Kmax
@@ -1446,23 +1430,54 @@ public void sendPublicationToBasket(PublicationPK pubPK, boolean kmaxMode) {
14461430
// remove all links between this publication and topics
14471431
publicationService.removeAllFathers(pubPK);
14481432
// add link between this publication and the basket topic
1449-
publicationService.addFather(pubPK, new NodePK("1", pubPK));
1450-
1451-
// remove all the todos attached to the publication
1452-
removeAllTodosForPublication(pubPK);
1433+
publicationService.addFather(pubPK, new NodePK(NodePK.BIN_NODE_ID, pubPK));
14531434

1454-
// publication is no more accessible
1455-
updateSilverContentVisibility(pubPK);
1456-
1457-
unIndexExternalElementsOfPublication(pubPK);
1435+
cleanUpPublicationsInBasket(pubPK);
14581436
} catch (Exception e) {
14591437
throw new KmeliaRuntimeException(e);
14601438
}
14611439
}
14621440

1463-
@Override
1464-
public void sendPublicationToBasket(PublicationPK pubPK) {
1465-
sendPublicationToBasket(pubPK, KmeliaHelper.isKmax(pubPK.getInstanceId()));
1441+
private void cleanUpPublicationsInBasket(PublicationPK pubPK) {
1442+
// remove all the todos attached to the publication
1443+
removeAllTodosForPublication(pubPK);
1444+
1445+
// publication is no more accessible
1446+
updateSilverContentVisibility(pubPK);
1447+
1448+
unIndexExternalElementsOfPublication(pubPK);
1449+
}
1450+
1451+
private void sendPublicationInBasket(PublicationPK pubPK) {
1452+
sendPublicationInBasket(pubPK, KmeliaHelper.isKmax(pubPK.getInstanceId()));
1453+
}
1454+
1455+
private void sendTopicInBasket(NodeDetail topic) {
1456+
NodePK trash = new NodePK(NodePK.BIN_NODE_ID,
1457+
topic.getIdentifier().getComponentInstanceId());
1458+
topic.setFatherPK(trash);
1459+
1460+
// get all the tree of folders, rooted to the topic, to be sent in the basket with the topic
1461+
final Collection<NodeDetail> children = nodeService.getDescendantDetails(topic.getNodePK());
1462+
for (final NodeDetail childTopic : children) {
1463+
// get all the direct publications in the topic child (including aliases)
1464+
final Collection<PublicationDetail> publications =
1465+
publicationService.getDetailsByFatherPK(childTopic.getNodePK());
1466+
// check each publication: if it is an alias, remove it, otherwise it is moved into the trash
1467+
// with its topic
1468+
for (PublicationDetail publication : publications) {
1469+
final KmeliaPublication kmeliaPublication = fromDetail(publication, childTopic.getNodePK());
1470+
if (kmeliaPublication.isAlias()) {
1471+
// remove only the alias
1472+
final Collection<Location> aliases = singletonList(kmeliaPublication.getLocation());
1473+
publicationService.removeAliases(kmeliaPublication.getPk(), aliases);
1474+
} else {
1475+
cleanUpPublicationsInBasket(publication.getPK());
1476+
}
1477+
}
1478+
}
1479+
1480+
nodeService.setDetail(topic);
14661481
}
14671482

14681483
@Override
@@ -3879,28 +3894,28 @@ private NodeDetail find(Collection<NodeDetail> nodes, NodeDetail toFind) {
38793894
}
38803895

38813896
/**
3882-
* Removes publications according to given ids. Before a publication is removed, user priviledges
3897+
* Removes publications according to given ids. Before a publication is removed, user privileges
38833898
* are controlled. If node defines the trash, publications are definitively deleted. Otherwise,
38843899
* publications move into trash.
3885-
* @param ids the ids of publications to delete
3886-
* @param nodePK the node where the publications are
3900+
* @param publiIds the ids of publications to delete
3901+
* @param topicId the node where the publications are
38873902
* @param userId the user who wants to perform deletion
38883903
* @return the list of publication ids which has been really deleted
38893904
* @
38903905
*/
38913906
@Override
38923907
@Transactional(Transactional.TxType.REQUIRED)
3893-
public List<String> deletePublications(List<String> ids, NodePK nodePK, String userId) {
3908+
public List<String> deletePublications(List<String> publiIds, NodePK topicId, String userId) {
38943909
List<String> removedIds = new ArrayList<>();
3895-
String profile = getProfile(userId, nodePK);
3896-
for (String id : ids) {
3897-
PublicationPK pk = new PublicationPK(id, nodePK);
3898-
if (isUserCanDeletePublication(new PublicationPK(id, nodePK), profile, userId)) {
3910+
String profile = getProfile(userId, topicId);
3911+
for (String id : publiIds) {
3912+
PublicationPK pk = new PublicationPK(id, topicId);
3913+
if (isUserCanDeletePublication(new PublicationPK(id, topicId), profile, userId)) {
38993914
try {
3900-
if (nodePK.isTrash() && isPublicationInBasket(pk)) {
3915+
if (topicId.isTrash() && isPublicationInBasket(pk)) {
39013916
deletePublication(pk);
39023917
} else {
3903-
sendPublicationToBasket(pk);
3918+
sendPublicationInBasket(pk);
39043919
}
39053920
removedIds.add(id);
39063921
} catch (Exception e) {
@@ -3912,6 +3927,28 @@ public List<String> deletePublications(List<String> ids, NodePK nodePK, String u
39123927
return removedIds;
39133928
}
39143929

3930+
@Transactional(Transactional.TxType.REQUIRED)
3931+
@Override
3932+
public void deleteTopic(@NonNull NodePK topic, @NonNull NodePK parent, String userId) {
3933+
Objects.requireNonNull(topic);
3934+
Objects.requireNonNull(parent);
3935+
if (topic.isTrash() || topic.isRoot()) {
3936+
return;
3937+
}
3938+
NodeDetail folder = getNodeHeader(topic);
3939+
// check if user is allowed to delete this topic
3940+
NodePK root = new NodePK(NodePK.ROOT_NODE_ID, topic.getInstanceId());
3941+
if (SilverpeasRole.ADMIN.isInRole(getUserTopicProfile(topic, userId)) ||
3942+
SilverpeasRole.ADMIN.isInRole(getUserTopicProfile(root, userId)) ||
3943+
SilverpeasRole.ADMIN.isInRole(getUserTopicProfile(folder.getFatherPK(), userId))) {
3944+
if (parent.isTrash() && folder.getFatherPK().isTrash()) {
3945+
deleteTopic(topic);
3946+
} else {
3947+
sendTopicInBasket(folder);
3948+
}
3949+
}
3950+
}
3951+
39153952
private boolean isUserCanDeletePublication(PublicationPK pubPK, String profile, String userId) {
39163953
User owner = getPublication(pubPK).getCreator();
39173954
return KmeliaPublicationHelper.isRemovable(pubPK.getInstanceId(), userId, profile, owner);

kmelia/kmelia-library/src/main/java/org/silverpeas/components/kmelia/service/KmeliaService.java

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.silverpeas.core.pdc.pdc.model.PdcClassification;
4242
import org.silverpeas.core.reminder.Reminder;
4343
import org.silverpeas.core.silverstatistics.access.model.HistoryObjectDetail;
44+
import org.silverpeas.kernel.annotation.NonNull;
4445
import org.silverpeas.kernel.util.Pair;
4546
import org.silverpeas.core.util.ServiceProvider;
4647

@@ -234,18 +235,11 @@ String createPublicationIntoTopic(PublicationDetail pubDetail, NodePK fatherPK,
234235
void updatePublication(PublicationDetail detail, boolean forceUpdateDate);
235236

236237
/**
237-
* Delete a publication If this publication is in the basket or in the DZ, it's deleted from the
238-
* database Else it only send to the basket
239-
* @param pubPK the id of the publication to delete
240-
* @see TopicDetail
241-
* @since 1.0
238+
* Deletes definitively the specified publication.
239+
* @param pubPK the unique identifier of the publication to delete.
242240
*/
243241
void deletePublication(PublicationPK pubPK);
244242

245-
void sendPublicationToBasket(PublicationPK pubPK);
246-
247-
void sendPublicationToBasket(PublicationPK pubPK, boolean kmaxMode);
248-
249243
/**
250244
* Add a publication to a topic and send email alerts to topic subscribers
251245
* @param pubPK the id of the publication
@@ -688,7 +682,28 @@ String clonePublication(CompletePublication refPubComplete, PublicationDetail pu
688682

689683
String getUserTopicProfile(NodePK pk, String userId);
690684

691-
List<String> deletePublications(List<String> ids, NodePK nodePK, String userId);
685+
/**
686+
* Deletes the specified publications located into the given topic. Before a publication is
687+
* removed, the privileges of the specified user is checked. If the topic is the trash folder,
688+
* then the publications are definitively deleted. Otherwise, they are just moved into the bin.
689+
* @param publiIds a list of local identifier of the publications to delete.
690+
* @param topicId the node PK of the topic in which the publications are located.
691+
* @param userId the unique identifier of the user asking the deletion.
692+
* @return the list of the unique identifiers of the actually deleted publications.
693+
*/
694+
List<String> deletePublications(List<String> publiIds, NodePK topicId, String userId);
695+
696+
/**
697+
* Deletes the specified topic located into the given parent topic. Before the topic is
698+
* deleted, the privileges of the specified user is checked. If the parent topic is the trash
699+
* folder, then the topic is definitively deleted. Otherwise it is just moved into the bin.
700+
* @param topic the unique identifier of the topic
701+
* @param parent the unique identifier of the parent topic in which the topic to delete is
702+
* located. For first-level topics, the identifier of their parent is
703+
* {@link NodePK#ROOT_NODE_ID}.
704+
* @param userId the unique identifier of the user asking the deletion.
705+
*/
706+
void deleteTopic(@NonNull NodePK topic, @NonNull NodePK parent, String userId);
692707

693708
List<String> getUserIdsOfFolder(NodePK pk);
694709

kmelia/kmelia-war/src/main/java/org/silverpeas/components/kmelia/control/KmeliaSessionController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,9 @@ public synchronized String deleteTopic(String topicId) {
800800
for (NodeDetail nodeToDelete : treeview) {
801801
deleteTopicRoles(nodeToDelete);
802802
}
803-
// Then, remove the topic itself
804-
getKmeliaService().deleteTopic(getNodePK(topicId));
803+
// Then, remove the topic itself: it is moved into the bin or, if already in the bin, it is
804+
// deleted
805+
getKmeliaService().deleteTopic(getNodePK(topicId), getCurrentFolderPK(), getUserId());
805806

806807
return node.getFatherPK().getId();
807808
}

0 commit comments

Comments
 (0)