Search in sources :

Example 1 with ItemProcessorPipeline

use of org.craftercms.core.processors.impl.ItemProcessorPipeline in project engine by craftercms.

the class SiteItemServiceImpl method getSiteTree.

@Override
public SiteItem getSiteTree(String url, int depth, ItemFilter filter, ItemProcessor processor) {
    if (CollectionUtils.isNotEmpty(defaultFilters)) {
        CompositeItemFilter compositeFilter = new CompositeItemFilter(new ArrayList<>(defaultFilters));
        if (filter != null) {
            compositeFilter.addFilter(filter);
        }
        filter = compositeFilter;
    }
    if (CollectionUtils.isNotEmpty(defaultProcessors)) {
        ItemProcessorPipeline processorPipeline = new ItemProcessorPipeline(new ArrayList<>(defaultProcessors));
        if (processor != null) {
            processorPipeline.addProcessor(processor);
        }
        processor = processorPipeline;
    }
    Tree tree = storeService.findTree(getSiteContext().getContext(), null, url, depth, filter, processor);
    if (tree != null) {
        return createItemWrapper(tree);
    } else {
        return null;
    }
}
Also used : ItemProcessorPipeline(org.craftercms.core.processors.impl.ItemProcessorPipeline) Tree(org.craftercms.core.service.Tree) CompositeItemFilter(org.craftercms.core.service.impl.CompositeItemFilter)

Example 2 with ItemProcessorPipeline

use of org.craftercms.core.processors.impl.ItemProcessorPipeline in project engine by craftercms.

the class SiteItemServiceImpl method getSiteItem.

@Override
public SiteItem getSiteItem(String url, ItemProcessor processor, Predicate<Item> predicate) {
    if (CollectionUtils.isNotEmpty(defaultPredicates)) {
        List<Predicate<Item>> predicates = new ArrayList<>(defaultPredicates);
        if (predicate != null) {
            predicates.add(predicate);
        }
        predicate = PredicateUtils.allPredicate(predicates);
    }
    if (CollectionUtils.isNotEmpty(defaultProcessors)) {
        ItemProcessorPipeline processorPipeline = new ItemProcessorPipeline(new ArrayList<>(defaultProcessors));
        if (processor != null) {
            processorPipeline.addProcessor(processor);
        }
        processor = processorPipeline;
    }
    Item item = storeService.findItem(getSiteContext().getContext(), null, url, processor);
    if (item != null && (predicate == null || predicate.evaluate(item))) {
        return createItemWrapper(item);
    } else {
        return null;
    }
}
Also used : Item(org.craftercms.core.service.Item) SiteItem(org.craftercms.engine.model.SiteItem) ItemProcessorPipeline(org.craftercms.core.processors.impl.ItemProcessorPipeline) ArrayList(java.util.ArrayList) Predicate(org.apache.commons.collections4.Predicate)

Example 3 with ItemProcessorPipeline

use of org.craftercms.core.processors.impl.ItemProcessorPipeline in project core by craftercms.

the class ContentStoreServiceImplTest method testGetChildren.

@Test
public void testGetChildren() throws Exception {
    CachingAwareList<Item> children = (CachingAwareList<Item>) contentStoreService.findChildren(context, ROOT_FOLDER_PATH);
    assertRootFolderChildren(children, false, false);
    // Sleep so that we get a different caching time in the next call if the caching is being done wrong.
    Thread.sleep(100);
    CachingAwareList<Item> cachedChildren = (CachingAwareList<Item>) contentStoreService.getChildren(context, ROOT_FOLDER_PATH);
    assertEquals(children, cachedChildren);
    assertListCaching(children, cachedChildren);
    children = (CachingAwareList<Item>) contentStoreService.findChildren(context, INVALID_PATH);
    assertNull(children);
    try {
        contentStoreService.getChildren(context, INVALID_PATH);
        fail("Expected " + PathNotFoundException.class.getName());
    } catch (PathNotFoundException e) {
    }
    ItemProcessorPipeline extractorPipeline = new ItemProcessorPipeline();
    extractorPipeline.addProcessor(new TextMetaDataCollectionExtractingProcessor("//extension"));
    extractorPipeline.addProcessor(new TextMetaDataExtractingProcessor("//size"));
    children = (CachingAwareList<Item>) contentStoreService.findChildren(context, DEFAULT_CACHING_OPTIONS, ROOT_FOLDER_PATH, OnlyNonDescriptorsFilter.instance, extractorPipeline);
    assertRootFolderChildren(children, true, true);
    // Sleep so that we get a different caching time in the next call if the caching is being done wrong.
    Thread.sleep(100);
    cachedChildren = (CachingAwareList<Item>) contentStoreService.getChildren(context, DEFAULT_CACHING_OPTIONS, ROOT_FOLDER_PATH, OnlyNonDescriptorsFilter.instance, extractorPipeline);
    assertEquals(children, cachedChildren);
    assertListCaching(children, cachedChildren);
    children = (CachingAwareList<Item>) contentStoreService.findChildren(context, DEFAULT_CACHING_OPTIONS, INVALID_PATH, OnlyNonDescriptorsFilter.instance, extractorPipeline);
    assertNull(children);
    try {
        contentStoreService.getChildren(context, DEFAULT_CACHING_OPTIONS, INVALID_PATH, OnlyNonDescriptorsFilter.instance, extractorPipeline);
        assertNull(children);
        fail("Expected " + PathNotFoundException.class.getName());
    } catch (PathNotFoundException e) {
    }
}
Also used : Item(org.craftercms.core.service.Item) ItemProcessorPipeline(org.craftercms.core.processors.impl.ItemProcessorPipeline) TextMetaDataCollectionExtractingProcessor(org.craftercms.core.processors.impl.TextMetaDataCollectionExtractingProcessor) TextMetaDataExtractingProcessor(org.craftercms.core.processors.impl.TextMetaDataExtractingProcessor) PathNotFoundException(org.craftercms.core.exception.PathNotFoundException) CachingAwareList(org.craftercms.core.util.cache.impl.CachingAwareList) Test(org.junit.Test) InheritLevelsMergeStrategyTest(org.craftercms.core.xml.mergers.impl.strategies.InheritLevelsMergeStrategyTest)

Example 4 with ItemProcessorPipeline

use of org.craftercms.core.processors.impl.ItemProcessorPipeline in project core by craftercms.

the class ContentStoreServiceImplTest method testGetTree.

@Test
public void testGetTree() throws Exception {
    Tree tree = contentStoreService.findTree(context, ROOT_FOLDER_PATH);
    assertRootFolderTree(tree, UNLIMITED_TREE_DEPTH, false, false);
    // Sleep so that we get a different caching time in the next call if the caching is being done wrong.
    Thread.sleep(100);
    Tree cachedTree = contentStoreService.getTree(context, ROOT_FOLDER_PATH);
    assertEquals(tree, cachedTree);
    assertTreeCaching(tree, cachedTree);
    tree = contentStoreService.findTree(context, INVALID_PATH);
    assertNull(tree);
    try {
        contentStoreService.getTree(context, INVALID_PATH);
        fail("Expected " + PathNotFoundException.class.getName());
    } catch (PathNotFoundException e) {
    }
    tree = contentStoreService.findTree(context, ROOT_FOLDER_PATH, 1);
    assertRootFolderTree(tree, 1, false, false);
    // Sleep so that we get a different caching time in the next call if the caching is being done wrong.
    Thread.sleep(100);
    cachedTree = contentStoreService.getTree(context, ROOT_FOLDER_PATH, 1);
    assertEquals(tree, cachedTree);
    assertTreeCaching(tree, cachedTree);
    tree = contentStoreService.findTree(context, INVALID_PATH, 1);
    assertNull(tree);
    try {
        contentStoreService.getTree(context, INVALID_PATH, 1);
        fail("Expected " + PathNotFoundException.class.getName());
    } catch (PathNotFoundException e) {
    }
    ItemProcessorPipeline extractorPipeline = new ItemProcessorPipeline();
    extractorPipeline.addProcessor(new TextMetaDataCollectionExtractingProcessor("//extension"));
    extractorPipeline.addProcessor(new TextMetaDataExtractingProcessor("//first-quote", "//second-quote", "//third-quote", "//size"));
    tree = contentStoreService.findTree(context, DEFAULT_CACHING_OPTIONS, ROOT_FOLDER_PATH, 1, OnlyNonDescriptorsFilter.instance, extractorPipeline);
    assertRootFolderTree(tree, 1, true, true);
    // Sleep so that we get a different caching time in the next call if the caching is being done wrong.
    Thread.sleep(100);
    cachedTree = contentStoreService.getTree(context, DEFAULT_CACHING_OPTIONS, ROOT_FOLDER_PATH, 1, OnlyNonDescriptorsFilter.instance, extractorPipeline);
    assertEquals(tree, cachedTree);
    assertTreeCaching(tree, cachedTree);
    tree = contentStoreService.findTree(context, DEFAULT_CACHING_OPTIONS, INVALID_PATH, 1, OnlyNonDescriptorsFilter.instance, extractorPipeline);
    assertNull(tree);
    try {
        contentStoreService.getTree(context, DEFAULT_CACHING_OPTIONS, INVALID_PATH, 1, OnlyNonDescriptorsFilter.instance, extractorPipeline);
        fail("Expected " + PathNotFoundException.class.getName());
    } catch (PathNotFoundException e) {
    }
}
Also used : ItemProcessorPipeline(org.craftercms.core.processors.impl.ItemProcessorPipeline) TextMetaDataCollectionExtractingProcessor(org.craftercms.core.processors.impl.TextMetaDataCollectionExtractingProcessor) TextMetaDataExtractingProcessor(org.craftercms.core.processors.impl.TextMetaDataExtractingProcessor) Tree(org.craftercms.core.service.Tree) PathNotFoundException(org.craftercms.core.exception.PathNotFoundException) Test(org.junit.Test) InheritLevelsMergeStrategyTest(org.craftercms.core.xml.mergers.impl.strategies.InheritLevelsMergeStrategyTest)

Aggregations

ItemProcessorPipeline (org.craftercms.core.processors.impl.ItemProcessorPipeline)4 PathNotFoundException (org.craftercms.core.exception.PathNotFoundException)2 TextMetaDataCollectionExtractingProcessor (org.craftercms.core.processors.impl.TextMetaDataCollectionExtractingProcessor)2 TextMetaDataExtractingProcessor (org.craftercms.core.processors.impl.TextMetaDataExtractingProcessor)2 Item (org.craftercms.core.service.Item)2 Tree (org.craftercms.core.service.Tree)2 InheritLevelsMergeStrategyTest (org.craftercms.core.xml.mergers.impl.strategies.InheritLevelsMergeStrategyTest)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 Predicate (org.apache.commons.collections4.Predicate)1 CompositeItemFilter (org.craftercms.core.service.impl.CompositeItemFilter)1 CachingAwareList (org.craftercms.core.util.cache.impl.CachingAwareList)1 SiteItem (org.craftercms.engine.model.SiteItem)1