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;
}
}
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;
}
}
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) {
}
}
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) {
}
}
Aggregations