Author: dulvac Date: Thu Oct 5 17:05:41 2017 New Revision: 1811219 URL: http://svn.apache.org/viewvc?rev=1811219&view=rev Log: SLING-6868 Initial content should be migrated to bundle resources
Modified: sling/trunk/contrib/extensions/hapi/core/pom.xml sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/HApiUtil.java sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/impl/HApiUtilImpl.java Modified: sling/trunk/contrib/extensions/hapi/core/pom.xml URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/hapi/core/pom.xml?rev=1811219&r1=1811218&r2=1811219&view=diff ============================================================================== --- sling/trunk/contrib/extensions/hapi/core/pom.xml (original) +++ sling/trunk/contrib/extensions/hapi/core/pom.xml Thu Oct 5 17:05:41 2017 @@ -61,7 +61,10 @@ <configuration> <instructions> <Bundle-Category>sling</Bundle-Category> - <Sling-Initial-Content>SLING-INF/libs/sling/hapi/; path:=/libs/sling/hapi; overwrite:=true; uninstall:=false</Sling-Initial-Content> + <Sling-Bundle-Resources> + /libs/sling/hapi/;path:=SLING-INF/libs/sling/hapi;propsJSON:=json + </Sling-Bundle-Resources> + <Require-Capability>osgi.extender;filter:="(&(osgi.extender=org.apache.sling.bundleresource)(version>=1.1.0)(!(version>=2.0.0)))"</Require-Capability> </instructions> </configuration> </plugin> Modified: sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/HApiUtil.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/HApiUtil.java?rev=1811219&r1=1811218&r2=1811219&view=diff ============================================================================== --- sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/HApiUtil.java (original) +++ sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/HApiUtil.java Thu Oct 5 17:05:41 2017 @@ -39,7 +39,7 @@ public interface HApiUtil { String DEFAULT_SEARCH_PATH = "/libs/sling/hapi/types"; String SEARCH_PATHS = "org.apache.sling.hapi.tools.searchpaths"; - String SEARCH_PATHS_DESC = "The path under each hapi types can be identified by their FQDN value in addition to the type path"; + String SEARCH_PATHS_DESC = "The path under which children resources can be identified as hapi types by their FQDN value in addition to the type path"; String DEFAULT_SERVER_URL = "http://localhost:8080"; String EXTERNAL_URL = "org.apache.sling.hapi.tools.externalurl"; Modified: sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/impl/HApiUtilImpl.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/impl/HApiUtilImpl.java?rev=1811219&r1=1811218&r2=1811219&view=diff ============================================================================== --- sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/impl/HApiUtilImpl.java (original) +++ sling/trunk/contrib/extensions/hapi/core/src/main/java/org/apache/sling/hapi/impl/HApiUtilImpl.java Thu Oct 5 17:05:41 2017 @@ -26,13 +26,8 @@ import java.util.List; import java.util.Map; import javax.jcr.Node; -import javax.jcr.NodeIterator; import javax.jcr.RepositoryException; -import javax.jcr.Session; import javax.jcr.Value; -import javax.jcr.query.Query; -import javax.jcr.query.QueryManager; -import javax.jcr.query.QueryResult; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; @@ -136,7 +131,7 @@ public class HApiUtilImpl implements HAp * {@inheritDoc} */ @Override - public Resource getTypeResource(ResourceResolver resolver, String type) throws RepositoryException { + public Resource getTypeResource(ResourceResolver resolver, String type) { if (!enabled) { return null; } @@ -147,7 +142,7 @@ public class HApiUtilImpl implements HAp * {@inheritDoc} */ @Override - public Resource getTypeCollectionResource(ResourceResolver resolver, String collection) throws RepositoryException { + public Resource getTypeCollectionResource(ResourceResolver resolver, String collection) { if (!enabled) { return null; } @@ -155,10 +150,10 @@ public class HApiUtilImpl implements HAp } - - private Resource getFqdnResource(ResourceResolver resolver, String fqdn, String resType) throws RepositoryException { - Session session = resolver.adaptTo(Session.class); - + /** + * Get the type resource + */ + private Resource getFqdnResource(ResourceResolver resolver, String fqdn, String resType) { // Try to resolve the resource as a path Resource res = resolver.getResource(fqdn); if (null != res) { @@ -167,32 +162,29 @@ public class HApiUtilImpl implements HAp } else { for (String path : new HashSet<String>(Arrays.asList(hApiPaths))) { // Remove trailing slash from path - path = (path.endsWith("/")) ? path.substring(0,path.length() - 1) : path; + path = (path.endsWith("/")) ? path.substring(0, path.length() - 1) : path; + return getTypeResourceFromFqdn(path, resolver, fqdn, resType); + } + } - // Get the query manager for the session - QueryManager queryManager = session.getWorkspace().getQueryManager(); + return null; + } - // Build query for the search paths - StringBuilder queryString = new StringBuilder("SELECT * FROM [nt:unstructured] WHERE "); - queryString.append(String.format("ISDESCENDANTNODE([%s]) ", path)); - queryString.append(String.format("AND [sling:resourceType]='%s' AND fqdn = '%s'", resType, fqdn)); - - // Execute query - Query query = queryManager.createQuery(queryString.toString(), Query.JCR_SQL2); - LOG.debug("Querying HApi: {}", queryString.toString()); - QueryResult result = query.execute(); - - NodeIterator nodeIter = result.getNodes(); - if (nodeIter.hasNext()) { - return resolver.getResource(nodeIter.nextNode().getPath()); - } else { - // continue + /** + * Get a type resource as direct _child_ of {{parentPath}} if the fqdn prop matches + */ + private Resource getTypeResourceFromFqdn(String parentPath, ResourceResolver resolver, String fqdn, String resType) { + if (null == fqdn) return null; + Resource searchParent = resolver.getResource(parentPath); + for (Resource tr: searchParent.getChildren()) { + if (tr.isResourceType(resType)) { + ValueMap resProps = tr.adaptTo(ValueMap.class); + if (fqdn.equals(resProps.get("fqdn", (String) null))) { + return tr; } } - - // Type has to be abstract - return null; } + return null; } @@ -346,6 +338,11 @@ class TypesCache { private HApiUtil hApiUtil; Map<String, HApiType> types; + /** + * Get the singleton instance + * @param hApiUtil + * @return + */ public static TypesCache getInstance(HApiUtil hApiUtil) { if (null == singleton) { singleton = new TypesCache(hApiUtil); @@ -363,6 +360,13 @@ class TypesCache { this.hApiUtil = hApiUtil; } + /** + * Get a type from the cache + * @param resolver + * @param typeResource + * @return + * @throws RepositoryException + */ public HApiType getType(ResourceResolver resolver, Resource typeResource) throws RepositoryException { if (null == typeResource) return new AbstractHapiTypeImpl("Abstract"); @@ -379,10 +383,18 @@ class TypesCache { } } + /** + * Add a type to the cache + * @param type + */ public void addType(HApiType type) { this.types.put(type.getPath(), type); } + /** + * Remove a type from the cache + * @param path + */ public void removeType(String path) { this.types.remove(path); }