From a2dd2a16b830c318b0b724398486d4206d2348d0 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Mon, 26 Aug 2019 19:12:50 +0200 Subject: [PATCH] Migrating to JCR primary types --- .../metadata/model/ArtifactMetadata.java | 6 --- .../AbstractMetadataRepositoryTest.java | 4 +- .../metadata/repository/jcr/JcrConstants.java | 3 ++ .../repository/jcr/JcrMetadataRepository.java | 44 ++++++++++--------- .../metadata/repository/jcr/jcr-schema.cnd | 26 ++++++++--- 5 files changed, 50 insertions(+), 33 deletions(-) diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ArtifactMetadata.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ArtifactMetadata.java index d8e92903f..3ee8ea894 100644 --- a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ArtifactMetadata.java +++ b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ArtifactMetadata.java @@ -21,16 +21,10 @@ package org.apache.archiva.metadata.model; import org.apache.archiva.checksum.ChecksumAlgorithm; import org.apache.commons.collections4.bidimap.DualHashBidiMap; -import sun.reflect.generics.repository.MethodRepository; import javax.xml.bind.annotation.XmlRootElement; import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneId; import java.time.ZonedDateTime; -import java.time.temporal.TemporalAccessor; -import java.util.Date; -import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; diff --git a/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java b/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java index 668f45cae..494ce8166 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java +++ b/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java @@ -924,7 +924,7 @@ public abstract class AbstractMetadataRepositoryTest for (int i=0; i<10; i++) { assertEquals(TEST_NAME + "/" + String.format("%03d",i), result.get(i).getName()); } - }, 3, 500 ); + }, 5, 500 ); } } @@ -952,7 +952,7 @@ public abstract class AbstractMetadataRepositoryTest for (int i=0; i<10; i++) { assertEquals(TEST_NAME + "/" + String.format("%03d",i+5), result.get(i).getName()); } - }, 3, 500 ); + }, 5, 500 ); } } diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrConstants.java b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrConstants.java index d0119c7ab..330c06028 100644 --- a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrConstants.java +++ b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrConstants.java @@ -46,6 +46,9 @@ public interface JcrConstants String MIXIN_META_MAILINGLIST = "archiva:meta_mailinglist"; String DEPENDENCY_NODE_TYPE = "archiva:dependency"; String CHECKSUM_NODE_TYPE = "archiva:checksum"; + String CHECKSUMS_FOLDER_TYPE = "archiva:checksums"; + String FACETS_FOLDER_TYPE = "archiva:facets"; + String FACET_ID_CONTAINER_TYPE = "archiva:facetIdContainer"; // Must be alphabetically ordered! String[] PROJECT_VERSION_VERSION_PROPERTIES = {"ci.system","ci.url", "description", "incomplete", "issue.system","issue.url", "name", "org.name", "org.url", "url", "scm.connection", "scm.developerConnection", "scm.url"}; diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java index b11d5603f..eb06b0d80 100644 --- a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java +++ b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java @@ -202,7 +202,7 @@ public class JcrMetadataRepository node.setProperty( "size", artifactMeta.getSize() ); int idx=0; - Node cslistNode = getOrAddNodeByPath( node, "checksums" ); + Node cslistNode = getOrAddNodeByPath( node, "checksums", CHECKSUMS_FOLDER_TYPE, true ); NodeIterator nit = cslistNode.getNodes("*"); while (nit.hasNext()) { Node csNode = nit.nextNode(); @@ -234,8 +234,7 @@ public class JcrMetadataRepository if ( metadataFacet != null ) { // recreate, to ensure properties are removed - Node n = node.addNode( facetId); - n.addMixin( FACET_NODE_TYPE ); + Node n = node.addNode( facetId, FACET_NODE_TYPE); n.setProperty( "facetId", facetId ); for ( Map.Entry entry : metadataFacet.toProperties().entrySet() ) @@ -368,8 +367,7 @@ public class JcrMetadataRepository { versionNode.getNode( facet.getFacetId() ).remove(); } - Node n = versionNode.addNode( facet.getFacetId() ); - n.addMixin( FACET_NODE_TYPE ); + Node n = versionNode.addNode( facet.getFacetId(), FACET_NODE_TYPE ); for ( Map.Entry entry : facet.toProperties().entrySet() ) { @@ -673,15 +671,17 @@ public class JcrMetadataRepository try { Node repo = getOrAddRepositoryNode( jcrSession, repositoryId ); - Node facets = JcrUtils.getOrAddNode( repo, "facets" ); + Node facets = JcrUtils.getOrAddNode( repo, "facets", FACETS_FOLDER_TYPE); String id = metadataFacet.getFacetId(); - Node facetNode = JcrUtils.getOrAddNode( facets, id ); + Node facetNode = JcrUtils.getOrAddNode( facets, id, FACET_ID_CONTAINER_TYPE ); + if (!facetNode.hasProperty("id")) { + facetNode.setProperty("id", id); + } - Node facetInstance = getOrAddNodeByPath( facetNode, metadataFacet.getName() ); - if (!facetInstance.isNodeType( FACET_NODE_TYPE )) + Node facetInstance = getOrAddNodeByPath( facetNode, metadataFacet.getName(), FACET_NODE_TYPE, true ); + if (!facetInstance.hasProperty( "archiva:facetId")) { - facetInstance.addMixin( FACET_NODE_TYPE ); facetInstance.setProperty( "archiva:facetId", id ); facetInstance.setProperty( "archiva:name", metadataFacet.getName( ) ); } @@ -1796,17 +1796,25 @@ public class JcrMetadataRepository return getOrAddNodeByPath( baseNode, name, null ); } - private Node getOrAddNodeByPath( Node baseNode, String name, String nodeType ) + private Node getOrAddNodeByPath( Node baseNode, String name, String nodeType ) throws RepositoryException { + return getOrAddNodeByPath(baseNode, name, nodeType, false); + } + + private Node getOrAddNodeByPath( Node baseNode, String name, String nodeType, boolean primaryType ) throws RepositoryException { log.debug( "getOrAddNodeByPath " + baseNode + " " + name + " " + nodeType ); Node node = baseNode; for ( String n : name.split( "/" ) ) { - node = JcrUtils.getOrAddNode( node, n ); - if ( nodeType != null && !node.isNodeType( nodeType )) - { - node.addMixin( nodeType ); + if (nodeType!=null && primaryType) { + node = JcrUtils.getOrAddNode( node, n, nodeType ); + } else { + node = JcrUtils.getOrAddNode( node, n); + if ( nodeType != null && !node.isNodeType( nodeType )) + { + node.addMixin( nodeType ); + } } if (!node.hasProperty( "id" )) { node.setProperty( "id", n ); @@ -1892,11 +1900,7 @@ public class JcrMetadataRepository throws RepositoryException { Node versionNode = getOrAddProjectVersionNode( jcrSession, repositoryId, namespace, projectId, projectVersion ); - Node node = JcrUtils.getOrAddNode( versionNode, id); - if (!node.isNodeType( ARTIFACT_NODE_TYPE )) - { - node.addMixin( ARTIFACT_NODE_TYPE ); - } + Node node = JcrUtils.getOrAddNode( versionNode, id, ARTIFACT_NODE_TYPE); if (!node.hasProperty( "id" )) { node.setProperty( "id", id ); } diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/resources/org/apache/archiva/metadata/repository/jcr/jcr-schema.cnd b/archiva-modules/plugins/metadata-store-jcr/src/main/resources/org/apache/archiva/metadata/repository/jcr/jcr-schema.cnd index 7fdb67869..1e7f3e7f6 100644 --- a/archiva-modules/plugins/metadata-store-jcr/src/main/resources/org/apache/archiva/metadata/repository/jcr/jcr-schema.cnd +++ b/archiva-modules/plugins/metadata-store-jcr/src/main/resources/org/apache/archiva/metadata/repository/jcr/jcr-schema.cnd @@ -17,6 +17,10 @@ * under the License. */ +/* + * JCR OAK does not support same name siblings. Which means we have to + * setup unique keys for list entries. + */ [archiva:base] abstract mixin - id (string) @@ -24,6 +28,7 @@ [archiva:repository] > archiva:base mixin + content (archiva:content) primary + + facets (nt:hierarchyNode) [archiva:content] > archiva:base mixin + * (archiva:namespace) @@ -81,7 +86,8 @@ [archiva:dependencies] mixin + * (archiva:dependency) -[archiva:checksums] +[archiva:checksums] > nt:hierarchyNode + - id (string) + * (archiva:checksum) [archiva:checksum] @@ -99,13 +105,23 @@ + * (archiva:dependencies) + * (archiva:facet) -[archiva:artifact] > archiva:base mixin + + +[archiva:artifact] > archiva:base - whenGathered (date) - size (long) - version (string) - + * (archiva:checksum) + + checksums (archiva:checksums) + * (archiva:facet) -[archiva:facet] > archiva:base mixin +[archiva:facets] > nt:hierarchyNode + + * (archiva:facetIdContainer) + +[archiva:facetIdContainer] > archiva:base + + * (archiva:facet) + +[archiva:facet] > archiva:base - archiva:facetId - - archiva:name \ No newline at end of file + - archiva:name + - * (string) + + * (archiva:facet) -- 2.39.5