mirror of https://github.com/apache/archiva.git
[MRM-1282] avoid creating invalid facets
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@893369 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4ad4cd3ced
commit
aa6f46b121
|
@ -766,26 +766,30 @@ public class FileMetadataRepository
|
|||
i++;
|
||||
}
|
||||
|
||||
for ( String facetId : properties.getProperty( "facetIds" ).split( "," ) )
|
||||
String facetIds = properties.getProperty( "facetIds", "" );
|
||||
if ( facetIds.length() > 0 )
|
||||
{
|
||||
MetadataFacetFactory factory = metadataFacetFactories.get( facetId );
|
||||
if ( factory == null )
|
||||
for ( String facetId : facetIds.split( "," ) )
|
||||
{
|
||||
log.error( "Attempted to load unknown metadata facet: " + facetId );
|
||||
}
|
||||
else
|
||||
{
|
||||
MetadataFacet facet = factory.createMetadataFacet();
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
for ( String key : properties.stringPropertyNames() )
|
||||
MetadataFacetFactory factory = metadataFacetFactories.get( facetId );
|
||||
if ( factory == null )
|
||||
{
|
||||
if ( key.startsWith( facet.getFacetId() ) )
|
||||
{
|
||||
map.put( key, properties.getProperty( key ) );
|
||||
}
|
||||
log.error( "Attempted to load unknown metadata facet: " + facetId );
|
||||
}
|
||||
else
|
||||
{
|
||||
MetadataFacet facet = factory.createMetadataFacet();
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
for ( String key : properties.stringPropertyNames() )
|
||||
{
|
||||
if ( key.startsWith( facet.getFacetId() ) )
|
||||
{
|
||||
map.put( key, properties.getProperty( key ) );
|
||||
}
|
||||
}
|
||||
facet.fromProperties( map );
|
||||
versionMetadata.addFacet( facet );
|
||||
}
|
||||
facet.fromProperties( map );
|
||||
versionMetadata.addFacet( facet );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.Arrays;
|
|||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -75,14 +76,24 @@ public class FileMetadataRepositoryTest
|
|||
FileUtils.deleteDirectory( directory );
|
||||
repository.setDirectory( directory );
|
||||
|
||||
repository.setMetadataFacetFactories(
|
||||
Collections.<String, MetadataFacetFactory>singletonMap( TEST_FACET_ID, new MetadataFacetFactory()
|
||||
Map<String, MetadataFacetFactory> factories = new HashMap<String, MetadataFacetFactory>();
|
||||
factories.put( TEST_FACET_ID, new MetadataFacetFactory()
|
||||
{
|
||||
public MetadataFacet createMetadataFacet()
|
||||
{
|
||||
public MetadataFacet createMetadataFacet()
|
||||
{
|
||||
return new TestMetadataFacet( "test-metadata" );
|
||||
}
|
||||
} ) );
|
||||
return new TestMetadataFacet( "test-metadata" );
|
||||
}
|
||||
} );
|
||||
|
||||
// add to ensure we don't accidentally create an empty facet ID.
|
||||
factories.put( "", new MetadataFacetFactory()
|
||||
{
|
||||
public MetadataFacet createMetadataFacet()
|
||||
{
|
||||
return new TestMetadataFacet( "", "test-value" );
|
||||
}
|
||||
} );
|
||||
repository.setMetadataFacetFactories( factories );
|
||||
}
|
||||
|
||||
public void testRootNamespaceWithNoMetadataRepository()
|
||||
|
@ -123,6 +134,23 @@ public class FileMetadataRepositoryTest
|
|||
assertEquals( "baz", testFacet.getValue() );
|
||||
}
|
||||
|
||||
public void testUpdateProjectVersionMetadataWithNoExistingFacets()
|
||||
{
|
||||
ProjectVersionMetadata metadata = new ProjectVersionMetadata();
|
||||
metadata.setId( TEST_PROJECT_VERSION );
|
||||
repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
|
||||
|
||||
metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
|
||||
assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
|
||||
|
||||
metadata = new ProjectVersionMetadata();
|
||||
metadata.setId( TEST_PROJECT_VERSION );
|
||||
repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
|
||||
|
||||
metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
|
||||
assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
|
||||
}
|
||||
|
||||
public void testGetMetadataFacet()
|
||||
{
|
||||
repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
|
||||
|
@ -514,16 +542,25 @@ public class FileMetadataRepositoryTest
|
|||
private static class TestMetadataFacet
|
||||
implements MetadataFacet
|
||||
{
|
||||
private String testFacetId;
|
||||
|
||||
private TestMetadataFacet( String value )
|
||||
{
|
||||
this.value = value;
|
||||
testFacetId = TEST_FACET_ID;
|
||||
}
|
||||
|
||||
private TestMetadataFacet( String facetId, String value )
|
||||
{
|
||||
this.value = value;
|
||||
testFacetId = facetId;
|
||||
}
|
||||
|
||||
private String value;
|
||||
|
||||
public String getFacetId()
|
||||
{
|
||||
return TEST_FACET_ID;
|
||||
return testFacetId;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
|
@ -535,7 +572,7 @@ public class FileMetadataRepositoryTest
|
|||
{
|
||||
if ( value != null )
|
||||
{
|
||||
return Collections.singletonMap( TEST_FACET_ID + ":foo", value );
|
||||
return Collections.singletonMap( testFacetId + ":foo", value );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -545,7 +582,7 @@ public class FileMetadataRepositoryTest
|
|||
|
||||
public void fromProperties( Map<String, String> properties )
|
||||
{
|
||||
String value = properties.get( TEST_FACET_ID + ":foo" );
|
||||
String value = properties.get( testFacetId + ":foo" );
|
||||
if ( value != null )
|
||||
{
|
||||
this.value = value;
|
||||
|
|
Loading…
Reference in New Issue