org.apache.archiva.metadata.repository.jcr
Class JcrMetadataRepository

java.lang.Object
  extended by org.apache.archiva.metadata.repository.jcr.JcrMetadataRepository
All Implemented Interfaces:
MetadataRepository

public class JcrMetadataRepository
extends Object
implements MetadataRepository

To Do:
below: revise storage format for project version metadata, revise reference storage

Field Summary
(package private) static String ARTIFACT_NODE_TYPE
           
private static String DEPENDENCY_NODE_TYPE
           
(package private) static String FACET_NODE_TYPE
           
private static String JCR_LAST_MODIFIED
           
private  javax.jcr.Session jcrSession
           
private  org.slf4j.Logger log
           
private  Map<String,MetadataFacetFactory> metadataFacetFactories
           
(package private) static String NAMESPACE_NODE_TYPE
           
(package private) static String PROJECT_NODE_TYPE
           
(package private) static String PROJECT_VERSION_NODE_TYPE
           
private  javax.jcr.Repository repository
           
 
Constructor Summary
JcrMetadataRepository(Map<String,MetadataFacetFactory> metadataFacetFactories, javax.jcr.Repository repository)
           
 
Method Summary
 void addMetadataFacet(String repositoryId, MetadataFacet metadataFacet)
           
 boolean canObtainAccess(Class<?> aClass)
           
 void close()
           
private static Calendar createCalendar(Date time)
           
private  ArtifactMetadata getArtifactFromNode(String repositoryId, javax.jcr.Node artifactNode)
           
private static String getArtifactPath(String repositoryId, String namespace, String projectId, String projectVersion, String id)
           
private static String getArtifactQuery(String repositoryId)
           
 List<ArtifactMetadata> getArtifacts(String repositoryId)
           
 Collection<ArtifactMetadata> getArtifacts(String repositoryId, String namespace, String projectId, String projectVersion)
           
 List<ArtifactMetadata> getArtifactsByChecksum(String repositoryId, String checksum)
           
 List<ArtifactMetadata> getArtifactsByDateRange(String repoId, Date startTime, Date endTime)
          if startTime or endTime are null they are not used for search
 Collection<String> getArtifactVersions(String repositoryId, String namespace, String projectId, String projectVersion)
           
private static String getFacetPath(String repositoryId, String facetId)
           
private static String getFacetPath(String repositoryId, String facetId, String name)
           
 javax.jcr.Session getJcrSession()
           
 MetadataFacet getMetadataFacet(String repositoryId, String facetId, String name)
           
 List<String> getMetadataFacets(String repositoryId, String facetId)
           
private static String getNamespacePath(String repositoryId, String namespace)
           
 Collection<String> getNamespaces(String repositoryId, String baseNamespace)
           
private  Collection<String> getNodeNames(String path, String nodeType)
           
private  javax.jcr.Node getOrAddArtifactNode(String repositoryId, String namespace, String projectId, String projectVersion, String id)
           
private  javax.jcr.Node getOrAddNamespaceNode(String repositoryId, String namespace)
           
private  javax.jcr.Node getOrAddNodeByPath(javax.jcr.Node baseNode, String name)
           
private  javax.jcr.Node getOrAddNodeByPath(javax.jcr.Node baseNode, String name, String nodeType)
           
private  javax.jcr.Node getOrAddProjectNode(String repositoryId, String namespace, String projectId)
           
private  javax.jcr.Node getOrAddProjectVersionNode(String repositoryId, String namespace, String projectId, String projectVersion)
           
private  javax.jcr.Node getOrAddRepositoryContentNode(String repositoryId)
           
private  javax.jcr.Node getOrAddRepositoryNode(String repositoryId)
           
 ProjectMetadata getProject(String repositoryId, String namespace, String projectId)
          basically just checking it exists not complete data returned
private static String getProjectPath(String repositoryId, String namespace, String projectId)
           
 Collection<ProjectVersionReference> getProjectReferences(String repositoryId, String namespace, String projectId, String projectVersion)
          Retrieve project references from the metadata repository.
 Collection<String> getProjects(String repositoryId, String namespace)
           
 ProjectVersionMetadata getProjectVersion(String repositoryId, String namespace, String projectId, String projectVersion)
           
private static String getProjectVersionPath(String repositoryId, String namespace, String projectId, String projectVersion)
           
 Collection<String> getProjectVersions(String repositoryId, String namespace, String projectId)
           
private static String getPropertyString(javax.jcr.Node node, String name)
           
 Collection<String> getRepositories()
           
private static String getRepositoryContentPath(String repositoryId)
           
private static String getRepositoryPath(String repositoryId)
           
 Collection<String> getRootNamespaces(String repositoryId)
           
 boolean hasMetadataFacet(String repositoryId, String facetId)
           
(package private) static void initialize(javax.jcr.Session session)
           
private  String join(Collection<String> ids)
           
<T> T
obtainAccess(Class<T> aClass)
           
private  void recurse(List<String> facets, String prefix, javax.jcr.Node node)
           
private static void registerMixinNodeType(javax.jcr.nodetype.NodeTypeManager nodeTypeManager, String name)
           
 void removeArtifact(ArtifactMetadata artifactMetadata, String baseVersion)
          used for deleting timestamped version of SNAPSHOT artifacts
 void removeArtifact(String repositoryId, String namespace, String project, String projectVersion, MetadataFacet metadataFacet)
          Only remove MetadataFacet for the artifact
 void removeArtifact(String repositoryId, String namespace, String projectId, String projectVersion, String id)
           
 void removeMetadataFacet(String repositoryId, String facetId, String name)
           
 void removeMetadataFacets(String repositoryId, String facetId)
           
 void removeNamespace(String repositoryId, String projectId)
           
 void removeProject(String repositoryId, String namespace, String projectId)
          remove a project
 void removeProjectVersion(String repoId, String namespace, String projectId, String projectVersion)
           
 void removeRepository(String repositoryId)
          Delete a repository's metadata.
 void revert()
          implementations can throw RuntimeException
 void save()
          implementations can throw RuntimeException
 void updateArtifact(String repositoryId, String namespace, String projectId, String projectVersion, ArtifactMetadata artifactMeta)
           
 void updateNamespace(String repositoryId, String namespace)
          create the namespace in the repository.
 void updateProject(String repositoryId, ProjectMetadata project)
          Update metadata for a particular project in the metadata repository, or create it if it does not already exist.
private  void updateProject(String repositoryId, String namespace, String projectId)
           
 void updateProjectVersion(String repositoryId, String namespace, String projectId, ProjectVersionMetadata versionMetadata)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JCR_LAST_MODIFIED

private static final String JCR_LAST_MODIFIED
See Also:
Constant Field Values

NAMESPACE_NODE_TYPE

static final String NAMESPACE_NODE_TYPE
See Also:
Constant Field Values

PROJECT_NODE_TYPE

static final String PROJECT_NODE_TYPE
See Also:
Constant Field Values

PROJECT_VERSION_NODE_TYPE

static final String PROJECT_VERSION_NODE_TYPE
See Also:
Constant Field Values

ARTIFACT_NODE_TYPE

static final String ARTIFACT_NODE_TYPE
See Also:
Constant Field Values

FACET_NODE_TYPE

static final String FACET_NODE_TYPE
See Also:
Constant Field Values

DEPENDENCY_NODE_TYPE

private static final String DEPENDENCY_NODE_TYPE
See Also:
Constant Field Values

metadataFacetFactories

private final Map<String,MetadataFacetFactory> metadataFacetFactories

log

private org.slf4j.Logger log

repository

private javax.jcr.Repository repository

jcrSession

private javax.jcr.Session jcrSession
Constructor Detail

JcrMetadataRepository

public JcrMetadataRepository(Map<String,MetadataFacetFactory> metadataFacetFactories,
                             javax.jcr.Repository repository)
                      throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException
Method Detail

initialize

static void initialize(javax.jcr.Session session)
                throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

registerMixinNodeType

private static void registerMixinNodeType(javax.jcr.nodetype.NodeTypeManager nodeTypeManager,
                                          String name)
                                   throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

updateProject

public void updateProject(String repositoryId,
                          ProjectMetadata project)
                   throws MetadataRepositoryException
Description copied from interface: MetadataRepository
Update metadata for a particular project in the metadata repository, or create it if it does not already exist.

Specified by:
updateProject in interface MetadataRepository
Parameters:
repositoryId - the repository the project is in
project - the project metadata to create or update
Throws:
MetadataRepositoryException

updateProject

private void updateProject(String repositoryId,
                           String namespace,
                           String projectId)
                    throws MetadataRepositoryException
Throws:
MetadataRepositoryException

updateArtifact

public void updateArtifact(String repositoryId,
                           String namespace,
                           String projectId,
                           String projectVersion,
                           ArtifactMetadata artifactMeta)
                    throws MetadataRepositoryException
Specified by:
updateArtifact in interface MetadataRepository
Throws:
MetadataRepositoryException

updateProjectVersion

public void updateProjectVersion(String repositoryId,
                                 String namespace,
                                 String projectId,
                                 ProjectVersionMetadata versionMetadata)
                          throws MetadataRepositoryException
Specified by:
updateProjectVersion in interface MetadataRepository
Throws:
MetadataRepositoryException

updateNamespace

public void updateNamespace(String repositoryId,
                            String namespace)
                     throws MetadataRepositoryException
Description copied from interface: MetadataRepository
create the namespace in the repository. (if not exist)

Specified by:
updateNamespace in interface MetadataRepository
Throws:
MetadataRepositoryException

removeProject

public void removeProject(String repositoryId,
                          String namespace,
                          String projectId)
                   throws MetadataRepositoryException
Description copied from interface: MetadataRepository
remove a project

Specified by:
removeProject in interface MetadataRepository
Throws:
MetadataRepositoryException

hasMetadataFacet

public boolean hasMetadataFacet(String repositoryId,
                                String facetId)
                         throws MetadataRepositoryException
Specified by:
hasMetadataFacet in interface MetadataRepository
Returns:
true if the repository datas for this facetId
Throws:
MetadataRepositoryException

getMetadataFacets

public List<String> getMetadataFacets(String repositoryId,
                                      String facetId)
                               throws MetadataRepositoryException
Specified by:
getMetadataFacets in interface MetadataRepository
Throws:
MetadataRepositoryException

recurse

private void recurse(List<String> facets,
                     String prefix,
                     javax.jcr.Node node)
              throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

getMetadataFacet

public MetadataFacet getMetadataFacet(String repositoryId,
                                      String facetId,
                                      String name)
                               throws MetadataRepositoryException
Specified by:
getMetadataFacet in interface MetadataRepository
Throws:
MetadataRepositoryException

addMetadataFacet

public void addMetadataFacet(String repositoryId,
                             MetadataFacet metadataFacet)
                      throws MetadataRepositoryException
Specified by:
addMetadataFacet in interface MetadataRepository
Throws:
MetadataRepositoryException

removeNamespace

public void removeNamespace(String repositoryId,
                            String projectId)
                     throws MetadataRepositoryException
Specified by:
removeNamespace in interface MetadataRepository
projectId - (groupId for maven )
Throws:
MetadataRepositoryException

removeMetadataFacets

public void removeMetadataFacets(String repositoryId,
                                 String facetId)
                          throws MetadataRepositoryException
Specified by:
removeMetadataFacets in interface MetadataRepository
Throws:
MetadataRepositoryException

removeMetadataFacet

public void removeMetadataFacet(String repositoryId,
                                String facetId,
                                String name)
                         throws MetadataRepositoryException
Specified by:
removeMetadataFacet in interface MetadataRepository
Throws:
MetadataRepositoryException

getArtifactsByDateRange

public List<ArtifactMetadata> getArtifactsByDateRange(String repoId,
                                                      Date startTime,
                                                      Date endTime)
                                               throws MetadataRepositoryException
Description copied from interface: MetadataRepository
if startTime or endTime are null they are not used for search

Specified by:
getArtifactsByDateRange in interface MetadataRepository
startTime - can be null
endTime - can be null
Returns:
Throws:
MetadataRepositoryException

getRepositories

public Collection<String> getRepositories()
                                   throws MetadataRepositoryException
Specified by:
getRepositories in interface MetadataRepository
Throws:
MetadataRepositoryException

getArtifactsByChecksum

public List<ArtifactMetadata> getArtifactsByChecksum(String repositoryId,
                                                     String checksum)
                                              throws MetadataRepositoryException
Specified by:
getArtifactsByChecksum in interface MetadataRepository
Throws:
MetadataRepositoryException

removeRepository

public void removeRepository(String repositoryId)
                      throws MetadataRepositoryException
Description copied from interface: MetadataRepository
Delete a repository's metadata. This includes all associated metadata facets.

Specified by:
removeRepository in interface MetadataRepository
Parameters:
repositoryId - the repository to delete
Throws:
MetadataRepositoryException

getArtifacts

public List<ArtifactMetadata> getArtifacts(String repositoryId)
                                    throws MetadataRepositoryException
Specified by:
getArtifacts in interface MetadataRepository
Throws:
MetadataRepositoryException

getArtifactQuery

private static String getArtifactQuery(String repositoryId)

getProject

public ProjectMetadata getProject(String repositoryId,
                                  String namespace,
                                  String projectId)
                           throws MetadataResolutionException
Description copied from interface: MetadataRepository
basically just checking it exists not complete data returned

Specified by:
getProject in interface MetadataRepository
Returns:
Throws:
MetadataResolutionException

getProjectVersion

public ProjectVersionMetadata getProjectVersion(String repositoryId,
                                                String namespace,
                                                String projectId,
                                                String projectVersion)
                                         throws MetadataResolutionException
Specified by:
getProjectVersion in interface MetadataRepository
Throws:
MetadataResolutionException

getArtifactVersions

public Collection<String> getArtifactVersions(String repositoryId,
                                              String namespace,
                                              String projectId,
                                              String projectVersion)
                                       throws MetadataResolutionException
Specified by:
getArtifactVersions in interface MetadataRepository
Throws:
MetadataResolutionException

getProjectReferences

public Collection<ProjectVersionReference> getProjectReferences(String repositoryId,
                                                                String namespace,
                                                                String projectId,
                                                                String projectVersion)
                                                         throws MetadataResolutionException
Description copied from interface: MetadataRepository
Retrieve project references from the metadata repository. Note that this is not built into the content model for a project version as a reference may be present (due to reverse-lookup of dependencies) before the actual project is, and we want to avoid adding a stub model to the content repository.

Specified by:
getProjectReferences in interface MetadataRepository
Parameters:
repositoryId - the repository ID to look within
namespace - the namespace of the project to get references to
projectId - the identifier of the project to get references to
projectVersion - the version of the project to get references to
Returns:
a list of project references
Throws:
MetadataResolutionException

getRootNamespaces

public Collection<String> getRootNamespaces(String repositoryId)
                                     throws MetadataResolutionException
Specified by:
getRootNamespaces in interface MetadataRepository
Throws:
MetadataResolutionException

getNamespaces

public Collection<String> getNamespaces(String repositoryId,
                                        String baseNamespace)
                                 throws MetadataResolutionException
Specified by:
getNamespaces in interface MetadataRepository
Throws:
MetadataResolutionException

getProjects

public Collection<String> getProjects(String repositoryId,
                                      String namespace)
                               throws MetadataResolutionException
Specified by:
getProjects in interface MetadataRepository
Throws:
MetadataResolutionException

getProjectVersions

public Collection<String> getProjectVersions(String repositoryId,
                                             String namespace,
                                             String projectId)
                                      throws MetadataResolutionException
Specified by:
getProjectVersions in interface MetadataRepository
Throws:
MetadataResolutionException

removeArtifact

public void removeArtifact(ArtifactMetadata artifactMetadata,
                           String baseVersion)
                    throws MetadataRepositoryException
Description copied from interface: MetadataRepository
used for deleting timestamped version of SNAPSHOT artifacts

Specified by:
removeArtifact in interface MetadataRepository
Parameters:
artifactMetadata - the artifactMetadata with the timestamped version (2.0-20120618.214135-2)
baseVersion - the base version of the snapshot (2.0-SNAPSHOT)
Throws:
MetadataRepositoryException

removeProjectVersion

public void removeProjectVersion(String repoId,
                                 String namespace,
                                 String projectId,
                                 String projectVersion)
                          throws MetadataRepositoryException
Specified by:
removeProjectVersion in interface MetadataRepository
Throws:
MetadataRepositoryException

removeArtifact

public void removeArtifact(String repositoryId,
                           String namespace,
                           String projectId,
                           String projectVersion,
                           String id)
                    throws MetadataRepositoryException
Specified by:
removeArtifact in interface MetadataRepository
Throws:
MetadataRepositoryException

removeArtifact

public void removeArtifact(String repositoryId,
                           String namespace,
                           String project,
                           String projectVersion,
                           MetadataFacet metadataFacet)
                    throws MetadataRepositoryException
Description copied from interface: MetadataRepository
Only remove MetadataFacet for the artifact

Specified by:
removeArtifact in interface MetadataRepository
Throws:
MetadataRepositoryException

getArtifacts

public Collection<ArtifactMetadata> getArtifacts(String repositoryId,
                                                 String namespace,
                                                 String projectId,
                                                 String projectVersion)
                                          throws MetadataResolutionException
Specified by:
getArtifacts in interface MetadataRepository
Throws:
MetadataResolutionException

save

public void save()
Description copied from interface: MetadataRepository
implementations can throw RuntimeException

Specified by:
save in interface MetadataRepository

revert

public void revert()
Description copied from interface: MetadataRepository
implementations can throw RuntimeException

Specified by:
revert in interface MetadataRepository

canObtainAccess

public boolean canObtainAccess(Class<?> aClass)
Specified by:
canObtainAccess in interface MetadataRepository

obtainAccess

public <T> T obtainAccess(Class<T> aClass)
               throws MetadataRepositoryException
Specified by:
obtainAccess in interface MetadataRepository
Throws:
MetadataRepositoryException

close

public void close()
           throws MetadataRepositoryException
Specified by:
close in interface MetadataRepository
Throws:
MetadataRepositoryException

getArtifactFromNode

private ArtifactMetadata getArtifactFromNode(String repositoryId,
                                             javax.jcr.Node artifactNode)
                                      throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

getPropertyString

private static String getPropertyString(javax.jcr.Node node,
                                        String name)
                                 throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

getNodeNames

private Collection<String> getNodeNames(String path,
                                        String nodeType)
                                 throws MetadataResolutionException
Throws:
MetadataResolutionException

getRepositoryPath

private static String getRepositoryPath(String repositoryId)

getRepositoryContentPath

private static String getRepositoryContentPath(String repositoryId)

getFacetPath

private static String getFacetPath(String repositoryId,
                                   String facetId)

getNamespacePath

private static String getNamespacePath(String repositoryId,
                                       String namespace)

getProjectPath

private static String getProjectPath(String repositoryId,
                                     String namespace,
                                     String projectId)

getProjectVersionPath

private static String getProjectVersionPath(String repositoryId,
                                            String namespace,
                                            String projectId,
                                            String projectVersion)

getArtifactPath

private static String getArtifactPath(String repositoryId,
                                      String namespace,
                                      String projectId,
                                      String projectVersion,
                                      String id)

getOrAddNodeByPath

private javax.jcr.Node getOrAddNodeByPath(javax.jcr.Node baseNode,
                                          String name)
                                   throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

getOrAddNodeByPath

private javax.jcr.Node getOrAddNodeByPath(javax.jcr.Node baseNode,
                                          String name,
                                          String nodeType)
                                   throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

getFacetPath

private static String getFacetPath(String repositoryId,
                                   String facetId,
                                   String name)

getOrAddRepositoryNode

private javax.jcr.Node getOrAddRepositoryNode(String repositoryId)
                                       throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

getOrAddRepositoryContentNode

private javax.jcr.Node getOrAddRepositoryContentNode(String repositoryId)
                                              throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

getOrAddNamespaceNode

private javax.jcr.Node getOrAddNamespaceNode(String repositoryId,
                                             String namespace)
                                      throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

getOrAddProjectNode

private javax.jcr.Node getOrAddProjectNode(String repositoryId,
                                           String namespace,
                                           String projectId)
                                    throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

getOrAddProjectVersionNode

private javax.jcr.Node getOrAddProjectVersionNode(String repositoryId,
                                                  String namespace,
                                                  String projectId,
                                                  String projectVersion)
                                           throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

getOrAddArtifactNode

private javax.jcr.Node getOrAddArtifactNode(String repositoryId,
                                            String namespace,
                                            String projectId,
                                            String projectVersion,
                                            String id)
                                     throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

createCalendar

private static Calendar createCalendar(Date time)

join

private String join(Collection<String> ids)

getJcrSession

public javax.jcr.Session getJcrSession()
                                throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException


Copyright © 2006-2013 The Apache Software Foundation. All Rights Reserved.