Search in sources :

Example 1 with PathFilterSet

use of org.apache.jackrabbit.vault.fs.api.PathFilterSet in project sling by apache.

the class VltUtilsTest method testDeepFilter.

@Test
public void testDeepFilter() throws Exception {
    DistributionRequest request = new SimpleDistributionRequest(ADD, true, "/foo");
    NavigableMap<String, List<String>> nodeFilters = new TreeMap<String, List<String>>();
    nodeFilters.put("/foo", Arrays.asList("/foo/bar", "/foo/bar1"));
    NavigableMap<String, List<String>> propFilters = new TreeMap<String, List<String>>();
    propFilters.put("/", Arrays.asList("^.*/prop1", "^.*/prop2"));
    WorkspaceFilter wsFilter = VltUtils.createFilter(request, nodeFilters, propFilters);
    assertNotNull(wsFilter);
    assertNotNull(wsFilter.getPropertyFilterSets());
    List<PathFilterSet> propFilterSet = wsFilter.getPropertyFilterSets();
    assertEquals(1, propFilterSet.size());
    PathFilterSet propFilter = propFilterSet.get(0);
    assertEquals(2, propFilter.getEntries().size());
    PathFilter filter = propFilter.getEntries().get(0).getFilter();
    assertTrue(filter.matches("/foo/bar/prop1"));
    assertTrue(filter.matches("/foo/prop1"));
}
Also used : SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) PathFilter(org.apache.jackrabbit.vault.fs.api.PathFilter) PathFilterSet(org.apache.jackrabbit.vault.fs.api.PathFilterSet) List(java.util.List) WorkspaceFilter(org.apache.jackrabbit.vault.fs.api.WorkspaceFilter) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 2 with PathFilterSet

use of org.apache.jackrabbit.vault.fs.api.PathFilterSet in project sling by apache.

the class VltUtils method getPaths.

public static String[] getPaths(MetaInf metaInf) {
    if (metaInf == null) {
        return null;
    }
    WorkspaceFilter filter = metaInf.getFilter();
    if (filter == null) {
        filter = new DefaultWorkspaceFilter();
    }
    List<PathFilterSet> filterSets = filter.getFilterSets();
    String[] paths = new String[filterSets.size()];
    for (int i = 0; i < paths.length; i++) {
        paths[i] = filterSets.get(i).getRoot();
    }
    return paths;
}
Also used : DefaultWorkspaceFilter(org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter) PathFilterSet(org.apache.jackrabbit.vault.fs.api.PathFilterSet) DefaultWorkspaceFilter(org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter) WorkspaceFilter(org.apache.jackrabbit.vault.fs.api.WorkspaceFilter)

Example 3 with PathFilterSet

use of org.apache.jackrabbit.vault.fs.api.PathFilterSet in project acs-aem-commons by Adobe-Consulting-Services.

the class PackageHelperImplTest method testGetPathFilterSetPreviewJSON.

@Test
public void testGetPathFilterSetPreviewJSON() throws Exception {
    final List<PathFilterSet> pathFilterSets = new ArrayList<PathFilterSet>();
    pathFilterSets.add(new PathFilterSet("/a/b/c"));
    pathFilterSets.add(new PathFilterSet("/d/e/f"));
    pathFilterSets.add(new PathFilterSet("/g/h/i"));
    final String actual = packageHelper.getPathFilterSetPreviewJSON(pathFilterSets);
    final JSONObject json = new JSONObject(actual);
    assertEquals("preview", json.getString("status"));
    assertEquals("Not applicable (Preview)", json.getString("path"));
    final String[] expectedFilterSets = new String[] { "/a/b/c", "/d/e/f", "/g/h/i" };
    JSONArray actualArray = json.getJSONArray("filterSets");
    for (int i = 0; i < actualArray.length(); i++) {
        JSONObject tmp = actualArray.getJSONObject(i);
        assertTrue(ArrayUtils.contains(expectedFilterSets, tmp.get("rootPath")));
    }
    assertEquals(expectedFilterSets.length, actualArray.length());
}
Also used : PathFilterSet(org.apache.jackrabbit.vault.fs.api.PathFilterSet) JSONObject(org.apache.sling.commons.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.apache.sling.commons.json.JSONArray) Test(org.junit.Test)

Example 4 with PathFilterSet

use of org.apache.jackrabbit.vault.fs.api.PathFilterSet in project acs-aem-commons by Adobe-Consulting-Services.

the class AuthorizablePackagerServletImpl method findPaths.

private List<PathFilterSet> findPaths(final ResourceResolver resourceResolver, final String[] authorizableIds) throws RepositoryException {
    final UserManager userManager = resourceResolver.adaptTo(UserManager.class);
    final List<PathFilterSet> pathFilterSets = new ArrayList<PathFilterSet>();
    for (final String authorizableId : authorizableIds) {
        try {
            final Authorizable authorizable = userManager.getAuthorizable(authorizableId);
            if (authorizable != null) {
                final String path = authorizable.getPath();
                final PathFilterSet principal = new PathFilterSet(path);
                // Exclude tokens as they are not vlt installable in AEM6/Oak
                principal.addExclude(new DefaultPathFilter(path + "/\\.tokens"));
                pathFilterSets.add(principal);
            }
        } catch (RepositoryException e) {
            log.warn("Unable to find path for authorizable " + authorizableId, e);
        }
    }
    return pathFilterSets;
}
Also used : PathFilterSet(org.apache.jackrabbit.vault.fs.api.PathFilterSet) UserManager(org.apache.jackrabbit.api.security.user.UserManager) ArrayList(java.util.ArrayList) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) DefaultPathFilter(org.apache.jackrabbit.vault.fs.filter.DefaultPathFilter)

Example 5 with PathFilterSet

use of org.apache.jackrabbit.vault.fs.api.PathFilterSet in project acs-aem-commons by Adobe-Consulting-Services.

the class PackageHelperImpl method getSuccessJSON.

/**
 * {@inheritDoc}
 */
public String getSuccessJSON(final JcrPackage jcrPackage) throws JSONException, RepositoryException {
    final JSONObject json = new JSONObject();
    json.put(KEY_STATUS, "success");
    json.put(KEY_PATH, jcrPackage.getNode().getPath());
    json.put(KEY_FILTER_SETS, new JSONArray());
    final List<PathFilterSet> filterSets = jcrPackage.getDefinition().getMetaInf().getFilter().getFilterSets();
    for (final PathFilterSet filterSet : filterSets) {
        final JSONObject jsonFilterSet = new JSONObject();
        jsonFilterSet.put(KEY_IMPORT_MODE, filterSet.getImportMode().name());
        jsonFilterSet.put(KEY_ROOT_PATH, filterSet.getRoot());
        json.accumulate(KEY_FILTER_SETS, jsonFilterSet);
    }
    return json.toString();
}
Also used : JSONObject(org.apache.sling.commons.json.JSONObject) PathFilterSet(org.apache.jackrabbit.vault.fs.api.PathFilterSet) JSONArray(org.apache.sling.commons.json.JSONArray)

Aggregations

PathFilterSet (org.apache.jackrabbit.vault.fs.api.PathFilterSet)18 ArrayList (java.util.ArrayList)7 RepositoryException (javax.jcr.RepositoryException)4 WorkspaceFilter (org.apache.jackrabbit.vault.fs.api.WorkspaceFilter)4 DefaultWorkspaceFilter (org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter)4 Test (org.junit.Test)4 DefaultPathFilter (org.apache.jackrabbit.vault.fs.filter.DefaultPathFilter)3 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)3 ValueMap (org.apache.sling.api.resource.ValueMap)3 JSONArray (org.apache.sling.commons.json.JSONArray)3 JSONObject (org.apache.sling.commons.json.JSONObject)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)2 UserManager (org.apache.jackrabbit.api.security.user.UserManager)2 JcrPackage (org.apache.jackrabbit.vault.packaging.JcrPackage)2 Resource (org.apache.sling.api.resource.Resource)2 JSONException (org.apache.sling.commons.json.JSONException)2