Skip to content

Commit

Permalink
Bug #12986: fixing technical error on comment service introduced on r…
Browse files Browse the repository at this point in the history
…efactoring around ApplicationService API.
  • Loading branch information
SilverYoCha committed Apr 6, 2022
1 parent f392d4d commit 4cd3601
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
Expand Up @@ -27,7 +27,7 @@
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.silverpeas.core.ComponentResourceIdentifier;
import org.silverpeas.core.ResourceIdentifier;
import org.silverpeas.core.WAPrimaryKey;
import org.silverpeas.core.ResourceReference;
import org.silverpeas.core.contribution.ContributionLocator;
import org.silverpeas.core.util.Mutable;

Expand Down Expand Up @@ -176,9 +176,8 @@ public static ContributionIdentifier from(String instanceId, String localId,
* @param key an old and deprecated representation of an identifier of Silverpeas.
* @return an contribution identifier.
*/
public static ContributionIdentifier from(WAPrimaryKey key) {
return new ContributionIdentifier(key.getInstanceId(), key.getId(),
CoreContributionType.UNKNOWN.name());
public static ContributionIdentifier from(ResourceReference key) {
return from(key, CoreContributionType.UNKNOWN.name());
}

/**
Expand All @@ -200,7 +199,7 @@ public static ContributionIdentifier from(String instanceId, String localId, Str
* @param type the type of the contribution.
* @return an contribution identifier.
*/
public static ContributionIdentifier from(WAPrimaryKey key, String type) {
public static ContributionIdentifier from(ResourceReference key, String type) {
return new ContributionIdentifier(key.getInstanceId(), key.getId(), type);
}

Expand Down
Expand Up @@ -23,6 +23,7 @@
*/
package org.silverpeas.core.contribution.attachment.model;

import org.silverpeas.core.ResourceReference;
import org.silverpeas.core.admin.service.OrganizationController;
import org.silverpeas.core.admin.user.model.SilverpeasRole;
import org.silverpeas.core.admin.user.model.User;
Expand Down Expand Up @@ -169,7 +170,7 @@ public SimpleDocument(SimpleDocument simpleDocument) {
@Override
@SuppressWarnings("unchecked")
public ContributionIdentifier getIdentifier() {
return ContributionIdentifier.from(getPk(), getDocumentType().getName());
return ContributionIdentifier.from(new ResourceReference(getPk()), getDocumentType().getName());
}

@Override
Expand Down
Expand Up @@ -85,12 +85,11 @@ public void onCreation(final CommentEvent event) throws Exception {
.getApplicationServiceById(componentInstanceId);
mayBeService.ifPresent(service -> {
try {
ContributionIdentifier contributionId =
ContributionIdentifier.from((ResourceIdentifier) comment.getResourceReference());
ContributionIdentifier contributionId = ContributionIdentifier.from(
comment.getResourceReference(), comment.getResourceType());
Contribution commentedContent = service.getContributionById(contributionId)
.orElseThrow(
() -> new NotFoundException("No such contribution " + contributionId.asString()));

final Set<String> recipients = getInterestedUsers(comment.getCreator()
.getId(), commentedContent);
if (!recipients.isEmpty()) {
Expand Down
Expand Up @@ -457,7 +457,7 @@ public void prepareMock(MavenTestEnv mavenTestEnv) {
(Answer<SimpleDocument>) invocation -> {
SimpleDocumentPK pk = invocation.getArgument(0);
ContributionIdentifier id =
ContributionIdentifier.from(pk, DocumentType.attachment.getName());
ContributionIdentifier.from(new ResourceReference(pk), DocumentType.attachment.getName());
return getInTreeAndApply(id.asString(), n -> {
LocalizedResource doc = n.getObject();
return doc instanceof SimpleDocument ? (SimpleDocument) doc : null;
Expand Down Expand Up @@ -493,7 +493,7 @@ public void prepareMock(MavenTestEnv mavenTestEnv) {
long offset = i.getArgument(3);
long length = i.getArgument(4);
ContributionIdentifier id =
ContributionIdentifier.from(pk, DocumentType.attachment.getName());
ContributionIdentifier.from(new ResourceReference(pk), DocumentType.attachment.getName());
return getInTreeAndApply(id.asString(), n -> {
SimpleDocument doc = (SimpleDocument) n.getObject();
String fileName = doc.getAttachment().getFilename();
Expand Down

0 comments on commit 4cd3601

Please sign in to comment.