Skip to content

Commit 3d5d3a9

Browse files
committed
As with KmeliaService#sendPublicationInBasket, the method
KmeliaService#deletePublication is now private to the implementor. Add a new method in KmeliaService: deletePublication(PublicationPK pubPK, String userId). This business method is dedicated to be used by SendInKmelia workflow action handlers to remove a publication that was published by a workflow in a Kmelia instance. But this method can be also used by others business services. The method now checks the user for which the deletion is invoked has the right to perform the action. Then, if the publication is already in the trash, it is definitively deleted, otherwise it is moved into the trash. By doing so, this business behaviour is well encapsulated by KmeliaService and doesn't require to spill it over others business services.
1 parent 54b7880 commit 3d5d3a9

File tree

2 files changed

+44
-17
lines changed

2 files changed

+44
-17
lines changed

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

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,11 +1377,12 @@ private boolean isClone(PublicationDetail publication) {
13771377
!isDefined(publication.getCloneStatus());
13781378
}
13791379

1380-
@Override
1381-
@Transactional(Transactional.TxType.REQUIRED)
1382-
public void deletePublication(PublicationPK pubPK) {
1383-
// if the publication is in the basket or in the DZ
1384-
// this publication is deleted from the database
1380+
/**
1381+
* Deletes definitively the specified publication.
1382+
*
1383+
* @param pubPK the unique identifier of the publication to delete.
1384+
*/
1385+
private void deletePublication(PublicationPK pubPK) {
13851386
KmeliaOperationContext.about(DELETION);
13861387
try {
13871388
// remove form content
@@ -3921,6 +3922,26 @@ public List<String> deletePublications(List<String> publiIds, NodePK topicId, St
39213922
return removedIds;
39223923
}
39233924

3925+
@Override
3926+
@Transactional(Transactional.TxType.REQUIRED)
3927+
public void deletePublication(PublicationPK pubPK, String userId) {
3928+
NodePK topicId = publicationService.getMainLocation(pubPK)
3929+
.orElse(null);
3930+
String profile = topicId != null ? getProfile(userId, topicId) : null;
3931+
if (profile != null && isUserCanDeletePublication(pubPK, profile, userId)) {
3932+
try {
3933+
if (topicId.isTrash()) {
3934+
deletePublication(pubPK);
3935+
} else {
3936+
sendPublicationInBasket(pubPK);
3937+
}
3938+
} catch (Exception e) {
3939+
SilverLogger.getLogger(this)
3940+
.error("Deletion of publication {0} failed", new String[]{pubPK.getId()}, e);
3941+
}
3942+
}
3943+
}
3944+
39243945
@Transactional(Transactional.TxType.REQUIRED)
39253946
@Override
39263947
public void deleteTopic(@NonNull NodePK topic, String userId) {

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

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,6 @@ String createPublicationIntoTopic(PublicationDetail pubDetail, NodePK fatherPK,
249249

250250
void updatePublication(PublicationDetail detail, boolean forceUpdateDate);
251251

252-
/**
253-
* Deletes definitively the specified publication.
254-
*
255-
* @param pubPK the unique identifier of the publication to delete.
256-
*/
257-
void deletePublication(PublicationPK pubPK);
258-
259252
/**
260253
* Add a publication to a topic and send email alerts to topic subscribers
261254
*
@@ -739,20 +732,33 @@ String clonePublication(CompletePublication refPubComplete, PublicationDetail pu
739732

740733
/**
741734
* Deletes the specified publications located into the given topic. Before a publication is
742-
* removed, the privileges of the specified user is checked. If the topic is the trash folder,
743-
* then the publications are definitively deleted. Otherwise, they are just moved into the bin.
735+
* removed, the privileges of the specified user is checked. This user can be the requester or
736+
* another user endorsing the deletion for the requester. If the topic is the trash folder, then
737+
* the publications are definitively deleted. Otherwise, they are just moved into the bin.
744738
*
745739
* @param publiIds a list of local identifier of the publications to delete.
746740
* @param topicId the node PK of the topic in which the publications are located.
747-
* @param userId the unique identifier of the user asking the deletion.
741+
* @param userId the unique identifier of the user for which the deletion is performed.
748742
* @return the list of the unique identifiers of the actually deleted publications.
749743
*/
750744
List<String> deletePublications(List<String> publiIds, NodePK topicId, String userId);
751745

746+
/**
747+
* Deletes the specified publication. Before the publication is removed, the privileges of the
748+
* given user is checked. This user can be the requester or another user endorsing the deletion
749+
* for the requester. For doing, the profile of the user is checked against the topic in which the
750+
* publication is originally located. If the topic is the trash folder, then the publication is
751+
* definitively deleted. Otherwise, it is just moved into the bin.
752+
*
753+
* @param pubPK the unique identifier of the publication.
754+
* @param userId the unique identifier of the user for which the deletion is performed.
755+
*/
756+
void deletePublication(PublicationPK pubPK, String userId);
757+
752758
/**
753759
* Deletes the specified topic located into the given parent topic. Before the topic is deleted,
754-
* the privileges of the specified user is checked. If topic is in the trash folder, then
755-
* the topic is definitively deleted. Otherwise it is just moved into the bin.
760+
* the privileges of the specified user is checked. If topic is in the trash folder, then the
761+
* topic is definitively deleted. Otherwise it is just moved into the bin.
756762
*
757763
* @param topic the unique identifier of the topic
758764
* @param userId the unique identifier of the user asking the deletion.

0 commit comments

Comments
 (0)