mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
ALF-14965: Ability to Map Extracted Metadata to Standard Tags
- Added check for invalid tag nodeRefs and empty tag names - Added test to confirm above git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@45093 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -38,6 +38,7 @@ import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
||||
@@ -174,13 +175,25 @@ public class ContentMetadataExtracter extends ActionExecuterAbstractBase
|
||||
Serializable convertedPropertyValue = (Serializable) DefaultTypeConverter.INSTANCE.convert(
|
||||
propertyDef.getDataType(),
|
||||
(String) singleValue);
|
||||
String tagName = (String) nodeService.getProperty((NodeRef) convertedPropertyValue, ContentModel.PROP_NAME);
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("found tag '" + tagName + "' from tag nodeRef '" + (String) singleValue + "', " +
|
||||
"adding to " + actionedUponNodeRef.toString());
|
||||
try {
|
||||
String tagName = (String) nodeService.getProperty((NodeRef) convertedPropertyValue, ContentModel.PROP_NAME);
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("found tag '" + tagName + "' from tag nodeRef '" + (String) singleValue + "', " +
|
||||
"adding to " + actionedUponNodeRef.toString());
|
||||
}
|
||||
if (tagName != null && !tagName.equals(""))
|
||||
{
|
||||
tags.add(tagName);
|
||||
}
|
||||
}
|
||||
catch (InvalidNodeRefException e)
|
||||
{
|
||||
if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("tag nodeRef Invalid: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
tags.add(tagName);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -190,7 +203,6 @@ public class ContentMetadataExtracter extends ActionExecuterAbstractBase
|
||||
logger.trace("adding string tag '" + (String) singleValue + "' to " + actionedUponNodeRef.toString());
|
||||
}
|
||||
tags.add((String) singleValue);
|
||||
|
||||
}
|
||||
}
|
||||
else if (singleValue instanceof NodeRef)
|
||||
|
@@ -89,6 +89,7 @@ public class ContentMetadataExtracterTagMappingTest extends TestCase
|
||||
protected static final String TAG_1 = "tag one";
|
||||
protected static final String TAG_2 = "tag two";
|
||||
protected static final String TAG_3 = "Tag Three";
|
||||
protected static final String TAG_NONEXISTENT_NODEREF = "workspace://SpacesStore/cb725c1f-4f7a-4232-8870-6c95b65407e1";
|
||||
|
||||
/** Services */
|
||||
private TaggingService taggingService;
|
||||
@@ -330,7 +331,8 @@ public class ContentMetadataExtracterTagMappingTest extends TestCase
|
||||
Map<String, Serializable> rawMap = super.extractRaw(reader);
|
||||
|
||||
// Add some test keywords to those actually extracted from the file including a nodeRef
|
||||
List<String> keywords = new ArrayList<String>(Arrays.asList(new String[] { existingTagNodeRef, TAG_2, TAG_3 }));
|
||||
List<String> keywords = new ArrayList<String>(Arrays.asList(
|
||||
new String[] { existingTagNodeRef, TAG_2, TAG_3, TAG_NONEXISTENT_NODEREF }));
|
||||
Serializable extractedKeywords = rawMap.get(Metadata.KEYWORDS);
|
||||
if (extractedKeywords != null && extractedKeywords instanceof String)
|
||||
{
|
||||
@@ -376,6 +378,10 @@ public class ContentMetadataExtracterTagMappingTest extends TestCase
|
||||
// Test manually added nodeRef keyword
|
||||
assertTrue("tags should contain '" + TAG_1 + "'",
|
||||
taggingService.getTags(document).contains(TAG_1));
|
||||
|
||||
// Test that there are no empty tags created by the non-existent nodeRef
|
||||
assertEquals("tags should contain '" + TAG_1 + "'", 4,
|
||||
taggingService.getTags(document).size() );
|
||||
|
||||
return null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user