final ArtifactMetadataModel artifactMetadataModel )
{
for ( final String facetId : metadataFacetFactories.keySet() )
{
MetadataFacet metadataFacet = facetedMetadata.getFacet( facetId );
if ( metadataFacet == null )
{
continue;
}
// clean first
final List<MetadataFacetModel> metadataFacetModels = new ArrayList<MetadataFacetModel>();
getMetadataFacetModelEntityManager().visitAll( new Function<MetadataFacetModel, Boolean>()
{
@Override
public Boolean apply( MetadataFacetModel metadataFacetModel )
{
ArtifactMetadataModel tmp = metadataFacetModel.getArtifactMetadataModel();
if ( StringUtils.equals( metadataFacetModel.getFacetId(), facetId ) && StringUtils.equals(
tmp.getRepositoryId(), artifactMetadataModel.getRepositoryId() ) && StringUtils.equals(
tmp.getNamespace(), artifactMetadataModel.getNamespace() ) && StringUtils.equals(
tmp.getProject(), artifactMetadataModel.getProject() ) )
{
metadataFacetModels.add( metadataFacetModel );
}
return Boolean.TRUE;
}
} );
getMetadataFacetModelEntityManager().remove( metadataFacetModels );
Map<String, String> properties = metadataFacet.toProperties();
final List<MetadataFacetModel> metadataFacetModelsToAdd =
new ArrayList<MetadataFacetModel>( properties.size() );
for ( Map.Entry<String, String> entry : properties.entrySet() )
{
String key = new MetadataFacetModel.KeyBuilder().withKey( entry.getKey() ).withArtifactMetadataModel(
artifactMetadataModel ).withFacetId( facetId ).withName( metadataFacet.getName() ).build();
MetadataFacetModel metadataFacetModel =
new MetadataFacetModel( key, artifactMetadataModel, facetId, entry.getKey(), entry.getValue(),
metadataFacet.getName() );
metadataFacetModelsToAdd.add( metadataFacetModel );
}
getMetadataFacetModelEntityManager().put( metadataFacetModelsToAdd );