mirror of https://github.com/apache/archiva.git
[MRM-1327] remove unnecessary facet node for artifacts
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1051429 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5622b1c569
commit
c82a0e6bc1
|
@ -78,6 +78,12 @@ import javax.jcr.query.QueryResult;
|
||||||
public class JcrMetadataRepository
|
public class JcrMetadataRepository
|
||||||
implements MetadataRepository
|
implements MetadataRepository
|
||||||
{
|
{
|
||||||
|
private static final String ARTIFACT_FACET_NODE_TYPE = "archiva:artifactFacet";
|
||||||
|
|
||||||
|
private static final String JCR_LAST_MODIFIED = "jcr:lastModified";
|
||||||
|
|
||||||
|
private static final String ARTIFACT_NODE_TYPE = "archiva:artifact";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @plexus.requirement role="org.apache.archiva.metadata.model.MetadataFacetFactory"
|
* @plexus.requirement role="org.apache.archiva.metadata.model.MetadataFacetFactory"
|
||||||
*/
|
*/
|
||||||
|
@ -104,13 +110,11 @@ public class JcrMetadataRepository
|
||||||
session = repository.login( new SimpleCredentials( "username", "password".toCharArray() ) );
|
session = repository.login( new SimpleCredentials( "username", "password".toCharArray() ) );
|
||||||
|
|
||||||
Workspace workspace = session.getWorkspace();
|
Workspace workspace = session.getWorkspace();
|
||||||
workspace.getNamespaceRegistry().registerNamespace( "archiva", "http://archiva.apache.org/jcr" );
|
workspace.getNamespaceRegistry().registerNamespace( "archiva", "http://archiva.apache.org/jcr/" );
|
||||||
|
|
||||||
NodeTypeManager nodeTypeManager = workspace.getNodeTypeManager();
|
NodeTypeManager nodeTypeManager = workspace.getNodeTypeManager();
|
||||||
NodeTypeTemplate nodeType = nodeTypeManager.createNodeTypeTemplate();
|
registerMixinNodeType( nodeTypeManager, ARTIFACT_NODE_TYPE );
|
||||||
nodeType.setMixin( true );
|
registerMixinNodeType( nodeTypeManager, ARTIFACT_FACET_NODE_TYPE );
|
||||||
nodeType.setName( "archiva:artifact" );
|
|
||||||
nodeTypeManager.registerNodeType( nodeType, false );
|
|
||||||
}
|
}
|
||||||
catch ( LoginException e )
|
catch ( LoginException e )
|
||||||
{
|
{
|
||||||
|
@ -124,6 +128,15 @@ public class JcrMetadataRepository
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void registerMixinNodeType( NodeTypeManager nodeTypeManager, String name )
|
||||||
|
throws RepositoryException
|
||||||
|
{
|
||||||
|
NodeTypeTemplate nodeType = nodeTypeManager.createNodeTypeTemplate();
|
||||||
|
nodeType.setMixin( true );
|
||||||
|
nodeType.setName( name );
|
||||||
|
nodeTypeManager.registerNodeType( nodeType, false );
|
||||||
|
}
|
||||||
|
|
||||||
public void updateProject( String repositoryId, ProjectMetadata project )
|
public void updateProject( String repositoryId, ProjectMetadata project )
|
||||||
{
|
{
|
||||||
updateProject( repositoryId, project.getNamespace(), project.getId() );
|
updateProject( repositoryId, project.getNamespace(), project.getId() );
|
||||||
|
@ -156,7 +169,7 @@ public class JcrMetadataRepository
|
||||||
|
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance();
|
||||||
cal.setTime( artifactMeta.getFileLastModified() );
|
cal.setTime( artifactMeta.getFileLastModified() );
|
||||||
node.setProperty( "jcr:lastModified", cal );
|
node.setProperty( JCR_LAST_MODIFIED, cal );
|
||||||
|
|
||||||
cal = Calendar.getInstance();
|
cal = Calendar.getInstance();
|
||||||
cal.setTime( artifactMeta.getWhenGathered() );
|
cal.setTime( artifactMeta.getWhenGathered() );
|
||||||
|
@ -168,18 +181,18 @@ public class JcrMetadataRepository
|
||||||
|
|
||||||
node.setProperty( "version", artifactMeta.getVersion() );
|
node.setProperty( "version", artifactMeta.getVersion() );
|
||||||
|
|
||||||
// TODO: namespaced properties instead?
|
|
||||||
Node facetNode = JcrUtils.getOrAddNode( node, "facets" );
|
|
||||||
for ( MetadataFacet facet : artifactMeta.getFacetList() )
|
for ( MetadataFacet facet : artifactMeta.getFacetList() )
|
||||||
{
|
{
|
||||||
// TODO: need to clear it?
|
// TODO: need to clear it?
|
||||||
Node n = JcrUtils.getOrAddNode( facetNode, facet.getFacetId() );
|
Node n = JcrUtils.getOrAddNode( node, facet.getFacetId() );
|
||||||
|
n.addMixin( ARTIFACT_FACET_NODE_TYPE );
|
||||||
|
|
||||||
for ( Map.Entry<String, String> entry : facet.toProperties().entrySet() )
|
for ( Map.Entry<String, String> entry : facet.toProperties().entrySet() )
|
||||||
{
|
{
|
||||||
n.setProperty( entry.getKey(), entry.getValue() );
|
n.setProperty( entry.getKey(), entry.getValue() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// TODO: need some context around this so it can be done only when needed
|
||||||
session.save();
|
session.save();
|
||||||
}
|
}
|
||||||
catch ( RepositoryException e )
|
catch ( RepositoryException e )
|
||||||
|
@ -1104,9 +1117,9 @@ public class JcrMetadataRepository
|
||||||
? artifactNode.getProperty( "version" ).getString()
|
? artifactNode.getProperty( "version" ).getString()
|
||||||
: projectVersionNode.getName() );
|
: projectVersionNode.getName() );
|
||||||
|
|
||||||
if ( artifactNode.hasProperty( "jcr:lastModified" ) )
|
if ( artifactNode.hasProperty( JCR_LAST_MODIFIED ) )
|
||||||
{
|
{
|
||||||
artifact.setFileLastModified( artifactNode.getProperty( "jcr:lastModified" ).getDate().getTimeInMillis() );
|
artifact.setFileLastModified( artifactNode.getProperty( JCR_LAST_MODIFIED ).getDate().getTimeInMillis() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( artifactNode.hasProperty( "whenGathered" ) )
|
if ( artifactNode.hasProperty( "whenGathered" ) )
|
||||||
|
@ -1129,29 +1142,27 @@ public class JcrMetadataRepository
|
||||||
artifact.setSha1( artifactNode.getProperty( "sha1" ).getString() );
|
artifact.setSha1( artifactNode.getProperty( "sha1" ).getString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( artifactNode.hasNode( "facets" ) )
|
for ( Node n : JcrUtils.getChildNodes( artifactNode ) )
|
||||||
{
|
{
|
||||||
NodeIterator j = artifactNode.getNode( "facets" ).getNodes();
|
if ( n.isNodeType( ARTIFACT_FACET_NODE_TYPE ) )
|
||||||
|
|
||||||
while ( j.hasNext() )
|
|
||||||
{
|
{
|
||||||
Node facetNode = j.nextNode();
|
String name = n.getName();
|
||||||
|
MetadataFacetFactory factory = metadataFacetFactories.get( name );
|
||||||
MetadataFacetFactory factory = metadataFacetFactories.get( facetNode.getName() );
|
|
||||||
if ( factory == null )
|
if ( factory == null )
|
||||||
{
|
{
|
||||||
log.error( "Attempted to load unknown project version metadata facet: " + facetNode.getName() );
|
log.error( "Attempted to load unknown project version metadata facet: " + name );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MetadataFacet facet = factory.createMetadataFacet();
|
MetadataFacet facet = factory.createMetadataFacet();
|
||||||
Map<String, String> map = new HashMap<String, String>();
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
PropertyIterator i = facetNode.getProperties();
|
for ( Property p : JcrUtils.getProperties( n ) )
|
||||||
while ( i.hasNext() )
|
|
||||||
{
|
{
|
||||||
Property p = i.nextProperty();
|
|
||||||
String property = p.getName();
|
String property = p.getName();
|
||||||
map.put( property, p.getString() );
|
if ( !property.startsWith( "jcr:" ) )
|
||||||
|
{
|
||||||
|
map.put( property, p.getString() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
facet.fromProperties( map );
|
facet.fromProperties( map );
|
||||||
artifact.addFacet( facet );
|
artifact.addFacet( facet );
|
||||||
|
@ -1243,7 +1254,7 @@ public class JcrMetadataRepository
|
||||||
{
|
{
|
||||||
Node versionNode = getOrAddProjectVersionNode( repositoryId, namespace, projectId, projectVersion );
|
Node versionNode = getOrAddProjectVersionNode( repositoryId, namespace, projectId, projectVersion );
|
||||||
Node node = JcrUtils.getOrAddNode( versionNode, id );
|
Node node = JcrUtils.getOrAddNode( versionNode, id );
|
||||||
node.addMixin( "archiva:artifact" );
|
node.addMixin( ARTIFACT_NODE_TYPE );
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue