mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merged BRANCHES/DEV/V4.1-BUG-FIX to HEAD:
46383: ALF-17893: CLONE - Mappings for Metadata Extractors Should be Defined in Config - Added support for new alfresco/metadata location will preserving backwards compatibility with the old location - Added tests for support of properties in the new location, the old location, and that on missing properties the error thrown indicates the new location - Updated JavaDoc for new alfresco/metadata location git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@46392 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1534,10 +1534,12 @@ abstract public class AbstractMappingMetadataExtracter implements MetadataExtrac
|
|||||||
* The default implementation looks for the default mapping file in the location
|
* The default implementation looks for the default mapping file in the location
|
||||||
* given by the class name and <i>.properties</i>. If the extracter's class is
|
* given by the class name and <i>.properties</i>. If the extracter's class is
|
||||||
* <b>x.y.z.MyExtracter</b> then the default properties will be picked up at
|
* <b>x.y.z.MyExtracter</b> then the default properties will be picked up at
|
||||||
* <b>classpath:/x/y/z/MyExtracter.properties</b>.
|
* <b>classpath:/alfresco/metadata/MyExtracter.properties</b>.
|
||||||
|
* The previous location of <b>classpath:/x/y/z/MyExtracter.properties</b> is
|
||||||
|
* still supported but may be removed in a future release.
|
||||||
* Inner classes are supported, but the '$' in the class name is replaced with '-', so
|
* Inner classes are supported, but the '$' in the class name is replaced with '-', so
|
||||||
* default properties for <b>x.y.z.MyStuff$MyExtracter</b> will be located using
|
* default properties for <b>x.y.z.MyStuff$MyExtracter</b> will be located using
|
||||||
* <b>x.y.z.MyStuff-MyExtracter.properties</b>.
|
* <b>classpath:/alfresco/metadata/MyStuff-MyExtracter.properties</b>.
|
||||||
* <p>
|
* <p>
|
||||||
* The default mapping implementation should include thorough Javadocs so that the
|
* The default mapping implementation should include thorough Javadocs so that the
|
||||||
* system administrators can accurately determine how to best enhance or override the
|
* system administrators can accurately determine how to best enhance or override the
|
||||||
@@ -1560,15 +1562,42 @@ abstract public class AbstractMappingMetadataExtracter implements MetadataExtrac
|
|||||||
*/
|
*/
|
||||||
protected Map<String, Set<QName>> getDefaultMapping()
|
protected Map<String, Set<QName>> getDefaultMapping()
|
||||||
{
|
{
|
||||||
String className = this.getClass().getName();
|
AlfrescoRuntimeException metadataLocationReadException = null;
|
||||||
// Replace $
|
try
|
||||||
className = className.replace('$', '-');
|
{
|
||||||
// Replace .
|
// Can't use getSimpleName here because we lose inner class $ processing
|
||||||
className = className.replace('.', '/');
|
String className = this.getClass().getName();
|
||||||
// Append .properties
|
String shortClassName = className.split("\\.")[className.split("\\.").length - 1];
|
||||||
String propertiesUrl = className + ".properties";
|
// Replace $
|
||||||
// Attempt to load the properties
|
shortClassName = shortClassName.replace('$', '-');
|
||||||
return readMappingProperties(propertiesUrl);
|
// Append .properties
|
||||||
|
String metadataPropertiesUrl = "alfresco/metadata/" + shortClassName + ".properties";
|
||||||
|
// Attempt to load the properties
|
||||||
|
return readMappingProperties(metadataPropertiesUrl);
|
||||||
|
}
|
||||||
|
catch (AlfrescoRuntimeException e)
|
||||||
|
{
|
||||||
|
// We'll save this to throw at someone later
|
||||||
|
metadataLocationReadException = e;
|
||||||
|
}
|
||||||
|
// Try package location
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String canonicalClassName = this.getClass().getName();
|
||||||
|
// Replace $
|
||||||
|
canonicalClassName = canonicalClassName.replace('$', '-');
|
||||||
|
// Replace .
|
||||||
|
canonicalClassName = canonicalClassName.replace('.', '/');
|
||||||
|
// Append .properties
|
||||||
|
String packagePropertiesUrl = canonicalClassName + ".properties";
|
||||||
|
// Attempt to load the properties
|
||||||
|
return readMappingProperties(packagePropertiesUrl);
|
||||||
|
}
|
||||||
|
catch (AlfrescoRuntimeException e)
|
||||||
|
{
|
||||||
|
// Not found in either location, but we want to throw the error for the new metadata location
|
||||||
|
throw metadataLocationReadException;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -28,6 +28,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.alfresco.repo.content.MimetypeMap;
|
import org.alfresco.repo.content.MimetypeMap;
|
||||||
import org.alfresco.repo.content.filestore.FileContentReader;
|
import org.alfresco.repo.content.filestore.FileContentReader;
|
||||||
import org.alfresco.repo.content.metadata.MetadataExtracter.OverwritePolicy;
|
import org.alfresco.repo.content.metadata.MetadataExtracter.OverwritePolicy;
|
||||||
@@ -68,6 +69,42 @@ public class MappingMetadataExtracterTest extends TestCase
|
|||||||
assertTrue("Extracter not initialized.", extracter.initCheck);
|
assertTrue("Extracter not initialized.", extracter.initCheck);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Test the new alfresco/metadata properties location */
|
||||||
|
public void testSetUpPropertiesLocationMetadata()
|
||||||
|
{
|
||||||
|
DummyPropertiesInMetadataLocationMappingMetadataExtracter metadataLocationExtracter =
|
||||||
|
new DummyPropertiesInMetadataLocationMappingMetadataExtracter();
|
||||||
|
metadataLocationExtracter.register();
|
||||||
|
assertNotNull("Extracter not initialized.", metadataLocationExtracter.getMapping());
|
||||||
|
assertNotNull("Mapping not found",
|
||||||
|
metadataLocationExtracter.getMapping().get(DummyMappingMetadataExtracter.PROP_A));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Test that the old package-based properties location still works */
|
||||||
|
public void testSetUpPropertiesLocationPackage()
|
||||||
|
{
|
||||||
|
DummyPropertiesInPackageLocationMappingMetadataExtracter packageLocationExtracter =
|
||||||
|
new DummyPropertiesInPackageLocationMappingMetadataExtracter();
|
||||||
|
packageLocationExtracter.register();
|
||||||
|
assertNotNull("Extracter not initialized.", packageLocationExtracter.getMapping());
|
||||||
|
assertNotNull("Mapping not found",
|
||||||
|
packageLocationExtracter.getMapping().get(DummyMappingMetadataExtracter.PROP_A));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Test that an extract with missing location throws the correct error */
|
||||||
|
public void testSetUpPropertiesMissing()
|
||||||
|
{
|
||||||
|
DummyPropertiesMissingMappingMetadataExtracter propertiesMissingExtracter =
|
||||||
|
new DummyPropertiesMissingMappingMetadataExtracter();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
propertiesMissingExtracter.register();
|
||||||
|
} catch (AlfrescoRuntimeException e)
|
||||||
|
{
|
||||||
|
assertTrue(e.getMessage().contains("alfresco/metadata/"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testDefaultExtract() throws Exception
|
public void testDefaultExtract() throws Exception
|
||||||
{
|
{
|
||||||
destination.clear();
|
destination.clear();
|
||||||
@@ -277,6 +314,33 @@ public class MappingMetadataExtracterTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class DummyPropertiesInPackageLocationMappingMetadataExtracter extends AbstractMappingMetadataExtracter
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected Map<String, Serializable> extractRaw(ContentReader reader) throws Throwable
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DummyPropertiesInMetadataLocationMappingMetadataExtracter extends AbstractMappingMetadataExtracter
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected Map<String, Serializable> extractRaw(ContentReader reader) throws Throwable
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DummyPropertiesMissingMappingMetadataExtracter extends AbstractMappingMetadataExtracter
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected Map<String, Serializable> extractRaw(ContentReader reader) throws Throwable
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class JunkValue implements Serializable
|
private static class JunkValue implements Serializable
|
||||||
{
|
{
|
||||||
private static final JunkValue INSTANCE = new JunkValue();
|
private static final JunkValue INSTANCE = new JunkValue();
|
||||||
|
@@ -0,0 +1,9 @@
|
|||||||
|
#
|
||||||
|
# Dummy - default mapping
|
||||||
|
#
|
||||||
|
# Namespaces
|
||||||
|
namespace.prefix.cm=http://www.alfresco.org/model/content/1.0
|
||||||
|
namespace.prefix.dum=http://DummyMappingMetadataExtracter
|
||||||
|
|
||||||
|
# Mappings
|
||||||
|
a=dum:a1,dum:a2,dum:a3
|
@@ -0,0 +1,9 @@
|
|||||||
|
#
|
||||||
|
# Dummy - default mapping
|
||||||
|
#
|
||||||
|
# Namespaces
|
||||||
|
namespace.prefix.cm=http://www.alfresco.org/model/content/1.0
|
||||||
|
namespace.prefix.dum=http://DummyMappingMetadataExtracter
|
||||||
|
|
||||||
|
# Mappings
|
||||||
|
a=dum:a1,dum:a2,dum:a3
|
Reference in New Issue
Block a user