[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:
Brett Porter 2009-12-23 01:02:15 +00:00
parent 4ad4cd3ced
commit aa6f46b121
2 changed files with 67 additions and 26 deletions

View File

@ -766,7 +766,10 @@ public class FileMetadataRepository
i++; i++;
} }
for ( String facetId : properties.getProperty( "facetIds" ).split( "," ) ) String facetIds = properties.getProperty( "facetIds", "" );
if ( facetIds.length() > 0 )
{
for ( String facetId : facetIds.split( "," ) )
{ {
MetadataFacetFactory factory = metadataFacetFactories.get( facetId ); MetadataFacetFactory factory = metadataFacetFactories.get( facetId );
if ( factory == null ) if ( factory == null )
@ -788,6 +791,7 @@ public class FileMetadataRepository
versionMetadata.addFacet( facet ); versionMetadata.addFacet( facet );
} }
} }
}
for ( MetadataFacet facet : versionMetadata.getFacetList() ) for ( MetadataFacet facet : versionMetadata.getFacetList() )
{ {

View File

@ -25,6 +25,7 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -75,14 +76,24 @@ public class FileMetadataRepositoryTest
FileUtils.deleteDirectory( directory ); FileUtils.deleteDirectory( directory );
repository.setDirectory( directory ); repository.setDirectory( directory );
repository.setMetadataFacetFactories( Map<String, MetadataFacetFactory> factories = new HashMap<String, MetadataFacetFactory>();
Collections.<String, MetadataFacetFactory>singletonMap( TEST_FACET_ID, new 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() public void testRootNamespaceWithNoMetadataRepository()
@ -123,6 +134,23 @@ public class FileMetadataRepositoryTest
assertEquals( "baz", testFacet.getValue() ); 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() public void testGetMetadataFacet()
{ {
repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) ); repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
@ -514,16 +542,25 @@ public class FileMetadataRepositoryTest
private static class TestMetadataFacet private static class TestMetadataFacet
implements MetadataFacet implements MetadataFacet
{ {
private String testFacetId;
private TestMetadataFacet( String value ) private TestMetadataFacet( String value )
{ {
this.value = value; this.value = value;
testFacetId = TEST_FACET_ID;
}
private TestMetadataFacet( String facetId, String value )
{
this.value = value;
testFacetId = facetId;
} }
private String value; private String value;
public String getFacetId() public String getFacetId()
{ {
return TEST_FACET_ID; return testFacetId;
} }
public String getName() public String getName()
@ -535,7 +572,7 @@ public class FileMetadataRepositoryTest
{ {
if ( value != null ) if ( value != null )
{ {
return Collections.singletonMap( TEST_FACET_ID + ":foo", value ); return Collections.singletonMap( testFacetId + ":foo", value );
} }
else else
{ {
@ -545,7 +582,7 @@ public class FileMetadataRepositoryTest
public void fromProperties( Map<String, String> properties ) public void fromProperties( Map<String, String> properties )
{ {
String value = properties.get( TEST_FACET_ID + ":foo" ); String value = properties.get( testFacetId + ":foo" );
if ( value != null ) if ( value != null )
{ {
this.value = value; this.value = value;