mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Tagging Service: make sure that tag scopes are updated correctly when a tag array is 'set' on a node reference
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10095 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -381,6 +381,9 @@ public class TaggingServiceImpl implements TaggingService
|
|||||||
this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_TAGGABLE, null);
|
this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_TAGGABLE, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the current list of tags
|
||||||
|
List<String> oldTags = getTags(nodeRef);
|
||||||
|
|
||||||
for (String tag : tags)
|
for (String tag : tags)
|
||||||
{
|
{
|
||||||
// Lower the case of the tag
|
// Lower the case of the tag
|
||||||
@@ -394,11 +397,28 @@ public class TaggingServiceImpl implements TaggingService
|
|||||||
newTagNodeRef = this.categoryService.createRootCategory(nodeRef.getStoreRef(), ContentModel.ASPECT_TAGGABLE, tag);
|
newTagNodeRef = this.categoryService.createRootCategory(nodeRef.getStoreRef(), ContentModel.ASPECT_TAGGABLE, tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to the list
|
if (tagNodeRefs.contains(newTagNodeRef) == false)
|
||||||
tagNodeRefs.add(newTagNodeRef);
|
{
|
||||||
|
// Add to the list
|
||||||
|
tagNodeRefs.add(newTagNodeRef);
|
||||||
|
|
||||||
// Trigger scope update
|
// Trigger scope update
|
||||||
updateTagScope(nodeRef, tag, true);
|
if (oldTags.contains(tag) == false)
|
||||||
|
{
|
||||||
|
updateTagScope(nodeRef, tag, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Remove the tag from the old list
|
||||||
|
oldTags.remove(tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove the old tags from the tag scope
|
||||||
|
for (String oldTag : oldTags)
|
||||||
|
{
|
||||||
|
updateTagScope(nodeRef, oldTag, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update category property
|
// Update category property
|
||||||
|
@@ -387,6 +387,41 @@ public class TaggingServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
tx.commit();
|
tx.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void xtestTagScopeSetUpdate()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
// Set up tag scope
|
||||||
|
this.taggingService.addTagScope(this.folder);
|
||||||
|
TagScope ts1 = this.taggingService.findTagScope(this.folder);
|
||||||
|
|
||||||
|
setComplete();
|
||||||
|
endTransaction();
|
||||||
|
|
||||||
|
addTag(this.folder, TAG_1, 1, ts1.getNodeRef());
|
||||||
|
addTag(this.document, TAG_1, 2, ts1.getNodeRef());
|
||||||
|
addTag(this.document, TAG_2, 1, ts1.getNodeRef());
|
||||||
|
addTag(this.subDocument, TAG_1, 3, ts1.getNodeRef());
|
||||||
|
addTag(this.subDocument, TAG_2, 2, ts1.getNodeRef());
|
||||||
|
addTag(this.subDocument, TAG_3, 1, ts1.getNodeRef());
|
||||||
|
addTag(this.subFolder, TAG_1, 4, ts1.getNodeRef());
|
||||||
|
|
||||||
|
UserTransaction tx = this.transactionService.getUserTransaction();
|
||||||
|
tx.begin();
|
||||||
|
|
||||||
|
ts1 = this.taggingService.findTagScope(this.folder);
|
||||||
|
assertEquals(4, ts1.getTag(TAG_1).getCount());
|
||||||
|
assertEquals(2, ts1.getTag(TAG_2).getCount());
|
||||||
|
//assertEquals(1, ts1.getTag(TAG_3).getCount());
|
||||||
|
|
||||||
|
tx.commit();
|
||||||
|
|
||||||
|
List<String> tags = new ArrayList<String>(3);
|
||||||
|
tags.add(TAG_2);
|
||||||
|
tags.add(TAG_3);
|
||||||
|
|
||||||
|
setTags(this.subDocument, tags, new String[]{TAG_1,TAG_2,TAG_3}, new int[]{3,2,1}, ts1.getNodeRef());
|
||||||
|
}
|
||||||
|
|
||||||
private void addTag(NodeRef nodeRef, String tag, int tagCount, NodeRef tagScopeNodeRef)
|
private void addTag(NodeRef nodeRef, String tag, int tagCount, NodeRef tagScopeNodeRef)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
@@ -423,7 +458,7 @@ public class TaggingServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
}
|
}
|
||||||
assertNotNull(checkTagScope);
|
assertNotNull(checkTagScope);
|
||||||
|
|
||||||
// Check that tag scopes are in the correct order
|
// Check whether the tag scope has been updated
|
||||||
List<TagDetails> tagDetailsList = checkTagScope.getTags();
|
List<TagDetails> tagDetailsList = checkTagScope.getTags();
|
||||||
for (TagDetails tagDetails : tagDetailsList)
|
for (TagDetails tagDetails : tagDetailsList)
|
||||||
{
|
{
|
||||||
@@ -533,6 +568,82 @@ public class TaggingServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setTags(NodeRef nodeRef, List<String> tags, String[] expectedTags, int[] expectedTagCount, NodeRef tagScopeNodeRef)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
UserTransaction tx = this.transactionService.getUserTransaction();
|
||||||
|
tx.begin();
|
||||||
|
|
||||||
|
// Add some tags
|
||||||
|
this.taggingService.setTags(nodeRef, tags);
|
||||||
|
|
||||||
|
tx.commit();
|
||||||
|
|
||||||
|
// Wait a bit cos we want the background threads to kick in and update the tag scope
|
||||||
|
int count = 0;
|
||||||
|
boolean bCreated = true;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
UserTransaction tx2 = this.transactionService.getUserTransaction();
|
||||||
|
tx2.begin();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Get the tag scope
|
||||||
|
List<TagScope> tagScopes = this.taggingService.findAllTagScopes(nodeRef);
|
||||||
|
TagScope checkTagScope = null;
|
||||||
|
for (TagScope tagScope : tagScopes)
|
||||||
|
{
|
||||||
|
if (tagScope.getNodeRef().equals(tagScopeNodeRef) == true)
|
||||||
|
{
|
||||||
|
checkTagScope = tagScope;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertNotNull(checkTagScope);
|
||||||
|
|
||||||
|
// Check whether the tag scope has been updated
|
||||||
|
List<TagDetails> tagDetailsList = checkTagScope.getTags();
|
||||||
|
if (tagDetailsList.size() == expectedTags.length)
|
||||||
|
{
|
||||||
|
int index = 0;
|
||||||
|
for (TagDetails tagDetails : tagDetailsList)
|
||||||
|
{
|
||||||
|
if (tagDetails.getName().equals(expectedTags[index]) == false ||
|
||||||
|
tagDetails.getCount() != expectedTagCount[index])
|
||||||
|
{
|
||||||
|
bCreated = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
index ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bCreated = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bCreated == true)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait to give the threads a chance to execute
|
||||||
|
Thread.sleep(1000);
|
||||||
|
|
||||||
|
if (count == 10)
|
||||||
|
{
|
||||||
|
fail("The background task to update the tag scope after set tag failed");
|
||||||
|
}
|
||||||
|
count ++;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
tx2.commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// == Test the JavaScript API ==
|
// == Test the JavaScript API ==
|
||||||
|
|
||||||
public void testJSAPI() throws Exception
|
public void testJSAPI() throws Exception
|
||||||
|
Reference in New Issue
Block a user