use of org.craftercms.core.service.Item in project engine by craftercms.
the class FolderToIndexItemProcessor method process.
@Override
public Item process(Context context, CachingOptions cachingOptions, Item item) throws ItemProcessingException {
if (item.isFolder()) {
String folderUrl = item.getUrl();
String indexUrl = urlTransformationEngine.transformUrl(context, cachingOptions, folderToIndexUrlTransformerName, folderUrl);
Item indexItem = storeService.findItem(context, cachingOptions, indexUrl, null);
if (indexItem != null) {
Item newFolderItem = new Item(item);
newFolderItem.setDescriptorUrl(indexItem.getDescriptorUrl());
newFolderItem.setDescriptorDom(indexItem.getDescriptorDom());
return newFolderItem;
}
}
return item;
}
use of org.craftercms.core.service.Item in project engine by craftercms.
the class ContentStoreUtils method findChildrenUrl.
public static List<String> findChildrenUrl(ContentStoreService storeService, Context context, String folderUrl) {
List<Item> children = storeService.findChildren(context, folderUrl);
List<String> childrenUrl = new ArrayList<>();
if (CollectionUtils.isNotEmpty(children)) {
for (Item child : children) {
childrenUrl.add(child.getUrl());
}
}
return childrenUrl;
}
use of org.craftercms.core.service.Item in project engine by craftercms.
the class SiteItemServiceImpl method getSiteItem.
@Override
public SiteItem getSiteItem(String url, ItemProcessor processor, Predicate<Item> predicate) {
SiteContext context = getSiteContext();
if (!storeService.exists(context.getContext(), url)) {
return null;
}
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(context.getContext(), null, url, processor);
if (item != null && (predicate == null || predicate.evaluate(item))) {
return createItemWrapper(item);
} else {
return null;
}
}
use of org.craftercms.core.service.Item in project engine by craftercms.
the class TargetedContentStoreAdapterDecoratorTest method testFindItems.
@Test
public void testFindItems() throws Exception {
Context context = new DecoratedStoreAdapterContext(mock(Context.class), storeAdapter);
CachingOptions cachingOptions = CachingOptions.DEFAULT_CACHING_OPTIONS;
List<Item> items = storeAdapter.findItems(context, cachingOptions, "/site/website/en");
assertNotNull(items);
assertEquals(2, items.size());
assertEquals("index.xml", items.get(0).getName());
assertEquals("/site/website/en/index.xml", items.get(0).getUrl());
assertEquals("about-us", items.get(1).getName());
assertEquals("/site/website/en/about-us", items.get(1).getUrl());
items = storeAdapter.findItems(context, cachingOptions, "/site/website/ja_jp_jp");
assertNotNull(items);
assertEquals(2, items.size());
assertEquals("index.xml", items.get(0).getName());
assertEquals("/site/website/ja/index.xml", items.get(0).getUrl());
assertEquals("about-us", items.get(1).getName());
assertEquals("/site/website/en/about-us", items.get(1).getUrl());
config.setProperty(SiteProperties.MERGE_FOLDERS_CONFIG_KEY, false);
items = storeAdapter.findItems(context, cachingOptions, "/site/website/ja_jp_jp");
assertNotNull(items);
assertEquals(1, items.size());
assertEquals("index.xml", items.get(0).getName());
assertEquals("/site/website/ja/index.xml", items.get(0).getUrl());
}
use of org.craftercms.core.service.Item in project engine by craftercms.
the class TargetedContentStoreAdapterDecoratorTest method createActualStoreAdapter.
private ContentStoreAdapter createActualStoreAdapter() {
ContentStoreAdapter adapter = mock(ContentStoreAdapter.class);
Item idx = new Item();
idx.setName("index.xml");
idx.setUrl("/site/website/index.xml");
Item en = new Item();
en.setName("en");
en.setUrl("/site/website/en");
Item enIdx = new Item();
enIdx.setName("index.xml");
enIdx.setUrl("/site/website/en/index.xml");
Item enAboutUs = new Item();
enAboutUs.setName("about-us");
enAboutUs.setUrl("/site/website/en/about-us");
Item mainCss = new Item();
mainCss.setName("main.css");
mainCss.setUrl("/static-assets/css/main.css");
Item frIdx = new Item();
frIdx.setName("index.xml");
frIdx.setUrl("/site/website/ja/index.xml");
when(adapter.exists(any(Context.class), any(CachingOptions.class), eq("/site/website/index.xml"))).thenReturn(true);
when(adapter.exists(any(Context.class), any(CachingOptions.class), eq("/site/website/en"))).thenReturn(true);
when(adapter.exists(any(Context.class), any(CachingOptions.class), eq("/site/website/en/index.xml"))).thenReturn(true);
when(adapter.exists(any(Context.class), any(CachingOptions.class), eq("/static-assets/css/main.css"))).thenReturn(true);
when(adapter.findContent(any(Context.class), any(CachingOptions.class), eq("/site/website/index.xml"))).thenReturn(mock(Content.class));
when(adapter.findContent(any(Context.class), any(CachingOptions.class), eq("/site/website/en/index.xml"))).thenReturn(mock(Content.class));
when(adapter.findContent(any(Context.class), any(CachingOptions.class), eq("/static-assets/css/main.css"))).thenReturn(mock(Content.class));
when(adapter.findItem(any(Context.class), any(CachingOptions.class), eq("/site/website/index.xml"), anyBoolean())).thenReturn(idx);
when(adapter.findItem(any(Context.class), any(CachingOptions.class), eq("/site/website/en"), anyBoolean())).thenReturn(en);
when(adapter.findItem(any(Context.class), any(CachingOptions.class), eq("/site/website/en/index.xml"), anyBoolean())).thenReturn(enIdx);
when(adapter.findItem(any(Context.class), any(CachingOptions.class), eq("/static-assets/css/main.css"), anyBoolean())).thenReturn(mainCss);
when(adapter.findItems(any(Context.class), any(CachingOptions.class), eq("/site/website/en"))).thenReturn(Arrays.asList(enIdx, enAboutUs));
when(adapter.findItems(any(Context.class), any(CachingOptions.class), eq("/site/website/ja"))).thenReturn(Collections.singletonList(frIdx));
return adapter;
}
Aggregations