114
114
import org .silverpeas .core .util .annotation .TargetPK ;
115
115
import org .silverpeas .core .util .file .FileRepositoryManager ;
116
116
import org .silverpeas .core .util .file .FileUtil ;
117
+ import org .silverpeas .kernel .annotation .NonNull ;
117
118
import org .silverpeas .kernel .bundle .LocalizationBundle ;
118
119
import org .silverpeas .kernel .bundle .ResourceLocator ;
119
120
import org .silverpeas .kernel .bundle .SettingBundle ;
@@ -532,7 +533,7 @@ public void deleteTopic(NodePK pkToDelete) {
532
533
for (PublicationDetail onePubToCheck : pubsToCheck ) {
533
534
final KmeliaPublication kmeliaPub = fromDetail (onePubToCheck , oneNodeToDelete );
534
535
if (!kmeliaPub .isAlias ()) {
535
- sendPublicationToBasket (kmeliaPub .getPk ());
536
+ sendPublicationInBasket (kmeliaPub .getPk ());
536
537
} else {
537
538
// remove only the alias
538
539
final Collection <Location > aliases = singletonList (kmeliaPub .getLocation ());
@@ -1153,7 +1154,7 @@ public void movePublicationInSameApplication(@SourcePK PublicationPK pubPK, @Tar
1153
1154
private void movePublicationInSameApplication (PublicationDetail pub , NodePK to ,
1154
1155
KmeliaPasteDetail pasteContext ) {
1155
1156
if (to .isTrash ()) {
1156
- sendPublicationToBasket (pub .getPK ());
1157
+ sendPublicationInBasket (pub .getPK ());
1157
1158
} else {
1158
1159
// update parent
1159
1160
publicationService .movePublication (pub .getPK (), to , false );
@@ -1381,12 +1382,6 @@ private boolean isClone(PublicationDetail publication) {
1381
1382
!isDefined (publication .getCloneStatus ());
1382
1383
}
1383
1384
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
- */
1390
1385
@ Override
1391
1386
@ Transactional (Transactional .TxType .REQUIRED )
1392
1387
public void deletePublication (PublicationPK pubPK ) {
@@ -1410,18 +1405,7 @@ public void deletePublication(PublicationPK pubPK) {
1410
1405
1411
1406
}
1412
1407
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 ) {
1425
1409
KmeliaOperationContext .about (REMOVING );
1426
1410
try {
1427
1411
// remove coordinates for Kmax
@@ -1446,23 +1430,54 @@ public void sendPublicationToBasket(PublicationPK pubPK, boolean kmaxMode) {
1446
1430
// remove all links between this publication and topics
1447
1431
publicationService .removeAllFathers (pubPK );
1448
1432
// 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 ));
1453
1434
1454
- // publication is no more accessible
1455
- updateSilverContentVisibility (pubPK );
1456
-
1457
- unIndexExternalElementsOfPublication (pubPK );
1435
+ cleanUpPublicationsInBasket (pubPK );
1458
1436
} catch (Exception e ) {
1459
1437
throw new KmeliaRuntimeException (e );
1460
1438
}
1461
1439
}
1462
1440
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 );
1466
1481
}
1467
1482
1468
1483
@ Override
@@ -3879,28 +3894,28 @@ private NodeDetail find(Collection<NodeDetail> nodes, NodeDetail toFind) {
3879
3894
}
3880
3895
3881
3896
/**
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
3883
3898
* are controlled. If node defines the trash, publications are definitively deleted. Otherwise,
3884
3899
* 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
3887
3902
* @param userId the user who wants to perform deletion
3888
3903
* @return the list of publication ids which has been really deleted
3889
3904
* @
3890
3905
*/
3891
3906
@ Override
3892
3907
@ 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 ) {
3894
3909
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 )) {
3899
3914
try {
3900
- if (nodePK .isTrash () && isPublicationInBasket (pk )) {
3915
+ if (topicId .isTrash () && isPublicationInBasket (pk )) {
3901
3916
deletePublication (pk );
3902
3917
} else {
3903
- sendPublicationToBasket (pk );
3918
+ sendPublicationInBasket (pk );
3904
3919
}
3905
3920
removedIds .add (id );
3906
3921
} catch (Exception e ) {
@@ -3912,6 +3927,28 @@ public List<String> deletePublications(List<String> ids, NodePK nodePK, String u
3912
3927
return removedIds ;
3913
3928
}
3914
3929
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
+
3915
3952
private boolean isUserCanDeletePublication (PublicationPK pubPK , String profile , String userId ) {
3916
3953
User owner = getPublication (pubPK ).getCreator ();
3917
3954
return KmeliaPublicationHelper .isRemovable (pubPK .getInstanceId (), userId , profile , owner );
0 commit comments