Skip to content
Permalink
Browse files
fix storing MetadataFacet at repository level with empty values
git-svn-id: https://svn.apache.org/repos/asf/archiva/sandbox/trunk@1491196 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
olamy committed Jun 9, 2013
1 parent 6ece420 commit 7a2743858a54800c9deb5d451a54fec049877ec1
Showing 1 changed file with 44 additions and 14 deletions.
@@ -1080,30 +1080,28 @@ public void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet )
throws MetadataRepositoryException
{

if ( metadataFacet == null || metadataFacet.toProperties() == null || metadataFacet.toProperties().isEmpty() )
if ( metadataFacet == null )
{
return;
}
for ( Map.Entry<String, String> entry : metadataFacet.toProperties().entrySet() )
{

if ( metadataFacet.toProperties().isEmpty() )
{
String key = new MetadataFacetModel.KeyBuilder().withRepositoryId( repositoryId ).withFacetId(
metadataFacet.getFacetId() ).withName( metadataFacet.getName() ).withKey( entry.getKey() ).build();

metadataFacet.getFacetId() ).withName( metadataFacet.getName() ).build();
MetadataFacetModel metadataFacetModel = metadataFacetModelEntityManager.get( key );
if ( metadataFacetModel == null )
{
metadataFacetModel = new MetadataFacetModel();
// we need to store the repositoryId
ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
artifactMetadataModel.setRepositoryId( repositoryId );
metadataFacetModel.setArtifactMetadataModel( artifactMetadataModel );
metadataFacetModel.setId( key );
metadataFacetModel.setKey( entry.getKey() );
metadataFacetModel.setFacetId( metadataFacet.getFacetId() );
metadataFacetModel.setName( metadataFacetModel.getName() );
}
metadataFacetModel.setValue( entry.getValue() );
// we need to store the repositoryId
ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
artifactMetadataModel.setRepositoryId( repositoryId );
metadataFacetModel.setArtifactMetadataModel( artifactMetadataModel );
metadataFacetModel.setId( key );
metadataFacetModel.setFacetId( metadataFacet.getFacetId() );
metadataFacetModel.setName( metadataFacetModel.getName() );

try
{
metadataFacetModelEntityManager.put( metadataFacetModel );
@@ -1112,7 +1110,39 @@ public void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet )
{
throw new MetadataRepositoryException( e.getMessage(), e );
}
}
else
{
for ( Map.Entry<String, String> entry : metadataFacet.toProperties().entrySet() )
{

String key = new MetadataFacetModel.KeyBuilder().withRepositoryId( repositoryId ).withFacetId(
metadataFacet.getFacetId() ).withName( metadataFacet.getName() ).withKey( entry.getKey() ).build();

MetadataFacetModel metadataFacetModel = metadataFacetModelEntityManager.get( key );
if ( metadataFacetModel == null )
{
metadataFacetModel = new MetadataFacetModel();
// we need to store the repositoryId
ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
artifactMetadataModel.setRepositoryId( repositoryId );
metadataFacetModel.setArtifactMetadataModel( artifactMetadataModel );
metadataFacetModel.setId( key );
metadataFacetModel.setKey( entry.getKey() );
metadataFacetModel.setFacetId( metadataFacet.getFacetId() );
metadataFacetModel.setName( metadataFacetModel.getName() );
}
metadataFacetModel.setValue( entry.getValue() );
try
{
metadataFacetModelEntityManager.put( metadataFacetModel );
}
catch ( PersistenceException e )
{
throw new MetadataRepositoryException( e.getMessage(), e );
}

}
}
}

0 comments on commit 7a27438

Please sign in to comment.