Compare commits

...

8 Commits

Author SHA1 Message Date
suneet.gupta
e737daa801 Addressed review comments 2023-03-01 11:21:24 +05:30
suneet.gupta
640a1120fd Addressed review comments 2023-02-28 20:07:34 +05:30
suneet.gupta
803cea84e3 Addressed review comments 2023-02-28 17:16:54 +05:30
suneet.gupta
db2da8338a Merge branch 'master' of github.com:Alfresco/alfresco-community-repo into ACS-4636_TagCreationCountIssue 2023-02-27 20:51:22 +05:30
suneet.gupta
bb5e4d42ac Addressed review comments 2023-02-27 20:00:29 +05:30
atkumar
dbe0d75764 Addressed review comments. 2023-02-27 19:09:42 +05:30
pjoshi31
093bee9ace reverting getTags 2023-02-23 17:12:27 +05:30
pjoshi31
e1974e6b26 Setted count on create endpoint 2023-02-23 16:51:57 +05:30
3 changed files with 63 additions and 1 deletions

View File

@@ -108,6 +108,7 @@ public class TagsImpl implements Tags
List<String> tagValues = new AbstractList<String>()
{
@Override
public String get(int arg0)
{
String tag = tags.get(arg0).getTag();
@@ -124,9 +125,14 @@ public class TagsImpl implements Tags
{
List<Pair<String, NodeRef>> tagNodeRefs = taggingService.addTags(nodeRef, tagValues);
List<Tag> ret = new ArrayList<Tag>(tags.size());
List<Pair<String, Integer>> tagsCountPairList = taggingService.findTaggedNodesAndCountByTagName(nodeRef.getStoreRef());
Map<String, Integer> tagsCountMap = tagsCountPairList.stream().collect(Collectors.toMap(Pair::getFirst,Pair::getSecond));
for(Pair<String, NodeRef> pair : tagNodeRefs)
{
ret.add(new Tag(pair.getSecond(), pair.getFirst()));
Tag createdTag=new Tag(pair.getSecond(), pair.getFirst());
// The new use of the tag will not be indexed yet, so add one to whatever count we get back
createdTag.setCount(Optional.ofNullable(tagsCountMap.get(createdTag.getTag())).orElse(0) + 1);
ret.add(createdTag);
}
return ret;
}
@@ -279,6 +285,7 @@ public class TagsImpl implements Tags
.peek(tag -> {
if (parameters.getInclude().contains(PARAM_INCLUDE_COUNT))
{
// this method creates orphan tags, which are not related with any content so setting count to 0.
tag.setCount(0);
}
}).collect(Collectors.toList());

View File

@@ -130,6 +130,20 @@ public class Tag implements Comparable<Tag>
return false;
} else if (!nodeRef.equals(other.nodeRef))
return false;
if(tag==null)
{
if(other.tag != null)
return false;
}
else if (!tag.equals(other.tag))
return false;
if (count == null)
{
if (other.count != null)
return false;
}
else if (!count.equals(other.count))
return false;
return true;
}

View File

@@ -40,6 +40,7 @@ import java.util.List;
import java.util.stream.Collectors;
import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.api.model.Tag;
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
@@ -51,6 +52,7 @@ import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.cmr.tagging.TaggingService;
import org.alfresco.util.Pair;
import org.alfresco.util.TypeConstraint;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -62,17 +64,22 @@ import org.mockito.junit.MockitoJUnitRunner;
public class TagsImplTest
{
private static final String TAG_ID = "tag-node-id";
private static final String NODE_ID = "node-id";
private static final String TAG_NAME = "tag-dummy-name";
private static final NodeRef TAG_NODE_REF = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, TAG_ID);
@Mock
private Nodes nodesMock;
@Mock
private Node createdNodeMock;
@Mock
private AuthorityService authorityServiceMock;
@Mock
private TaggingService taggingServiceMock;
@Mock
private Parameters parametersMock;
@Mock
private TypeConstraint typeConstraint;
@InjectMocks
private TagsImpl objectUnderTest;
@@ -81,9 +88,14 @@ public class TagsImplTest
public void setup()
{
given(authorityServiceMock.hasAdminAuthority()).willReturn(true);
given(nodesMock.validateNode(NODE_ID)).willReturn(TAG_NODE_REF);
given(nodesMock.validateNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, TAG_ID)).willReturn(TAG_NODE_REF);
given(nodesMock.getNode(any())).willReturn(createdNodeMock);
given(createdNodeMock.getNodeId()).willReturn(NODE_ID);
given(typeConstraint.matches(any())).willReturn(true);
given(taggingServiceMock.getTagName(TAG_NODE_REF)).willReturn(TAG_NAME);
}
@Test
public void testGetTags() {
final List<String> tagNames = List.of("testTag","tag11");
@@ -302,4 +314,33 @@ public class TagsImplTest
.tag(tagName)
.create();
}
@Test
public void testAddTagsToNode()
{
final List<String> tagNames = List.of("tag1","tag2");
final List<Tag> tagsToCreate = createTags(tagNames);
given(taggingServiceMock.addTags(any(), any())).willAnswer(invocation -> createTagAndNodeRefPairs(invocation.getArgument(1)));
final List<Tag> actualCreatedTags = objectUnderTest.addTags(nodesMock.getNode(any()).getNodeId(),tagsToCreate);
then(taggingServiceMock).should().addTags(TAG_NODE_REF, tagNames);
final List<Tag> expectedTags = createTagsWithNodeRefs(tagNames).stream().peek(tag -> tag.setCount(1)).collect(Collectors.toList());;
assertThat(actualCreatedTags)
.isNotNull()
.isEqualTo(expectedTags);
}
@Test
public void testAddTagsToNodeWithResponseNotIndexed()
{
final List<String> tagNames = List.of("tag1","tag2");
final List<Tag> tagsToCreate = createTags(tagNames);
given(taggingServiceMock.addTags(any(), any())).willAnswer(invocation -> createTagAndNodeRefPairs(invocation.getArgument(1)));
final List<Tag> actualCreatedTags = objectUnderTest.addTags(nodesMock.getNode(any()).getNodeId(),tagsToCreate);
then(taggingServiceMock).should().addTags(TAG_NODE_REF, tagNames);
final List<Tag> expectedTags = createTagsWithNodeRefs(tagNames).stream().peek(tag -> tag.setCount(1)).collect(Collectors.toList());;
assertThat(actualCreatedTags)
.isNotNull()
.isEqualTo(expectedTags);
}
}