@Test public void testGetResourceFromCategoryImageLocaleSpecific() throws Exception { context.checking(new Expectations() {{ allowing(shop).getShopId(); will(returnValue(123L)); allowing(shop).getCode(); will(returnValue("SHOP10")); oneOf(contentService).getContentBody("SHOP10_report_fop-config.image.png", "en"); will(returnValue(null)); oneOf(contentService).findContentIdBySeoUri("SHOP10_report_fop-config.image.png"); will(returnValue(123L)); oneOf(contentService).getById(123L); will(returnValue(content)); oneOf(content).getAttributeValueByCode("CATEGORY_IMAGE0_en"); will(returnValue("imageValue")); oneOf(systemService).getImageRepositoryDirectory(); will(returnValue("imageVaultPath")); oneOf(imageService).isImageInRepository("imageValue", "SHOP10_report_fop-config.image.png", "/imgvault/category/", "imageVaultPath"); will(returnValue(true)); oneOf(imageService).imageToByteArray("imageValue", "SHOP10_report_fop-config.image.png", "/imgvault/category/", "imageVaultPath"); will(returnValue(new byte[1])); }}); final FopThemeResourceResolver resolver = new FopThemeResourceResolver(shop, lang, "fop-config.image.png", "fop-config.file.xml", themeService, contentService, themeRepositoryService, systemService, imageService); assertNotNull(resolver.getResource(new URI("fop-config.xml"))); context.assertIsSatisfied(); }
@Override public Resource getResource(final URI uri) throws IOException { final Long shopId = shop != null ? shop.getShopId() : null; if (shop != null) { final String curi = shop.getCode().concat("_report_").concat(contentSuffix != null ? contentSuffix : uri.toString()); final String content = contentService.getContentBody(curi, language); if (StringUtils.isNotBlank(content)) { LOG.debug("Using shop specific report template file {}", curi); return new Resource(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))); } final Long contentObjId = contentService.findContentIdBySeoUri(curi); if (contentObjId != null && contentObjId > 0L) { final Content contentObj = contentService.getById(contentObjId); if (contentObj != null) { final byte[] localeSpecificImage = getImageAsBytes(contentObj, AttributeNamesKeys.Category.CATEGORY_IMAGE + "_" + language, curi); if (localeSpecificImage != null && localeSpecificImage.length > 0) { return new Resource(new ByteArrayInputStream(localeSpecificImage)); } final byte[] defaultImage = getImageAsBytes(contentObj, AttributeNamesKeys.Category.CATEGORY_IMAGE, curi); if (defaultImage != null && defaultImage.length > 0) { return new Resource(new ByteArrayInputStream(defaultImage)); } } } } final List<String> chain = themeService.getReportsTemplateChainByShopId(shopId); for (final String path : chain) { final String configFile = path + (fileSuffix != null ? fileSuffix : uri.toString()); try { final InputStream stream = themeRepositoryService.getSource(configFile); if (stream != null) { LOG.debug("Using theme specific report template file {}", configFile); return new Resource(stream); } } catch (Exception mue) { LOG.error("Unable to load report template file " + configFile, mue); } } LOG.debug("No report template for {}", uri); return null; }
FopThemeResourceResolver implements TempResourceResolver, ResourceResolver { @Override public Resource getResource(final URI uri) throws IOException { final Long shopId = shop != null ? shop.getShopId() : null; if (shop != null) { final String curi = shop.getCode().concat("_report_").concat(contentSuffix != null ? contentSuffix : uri.toString()); final String content = contentService.getContentBody(curi, language); if (StringUtils.isNotBlank(content)) { LOG.debug("Using shop specific report template file {}", curi); return new Resource(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))); } final Long contentObjId = contentService.findContentIdBySeoUri(curi); if (contentObjId != null && contentObjId > 0L) { final Content contentObj = contentService.getById(contentObjId); if (contentObj != null) { final byte[] localeSpecificImage = getImageAsBytes(contentObj, AttributeNamesKeys.Category.CATEGORY_IMAGE + "_" + language, curi); if (localeSpecificImage != null && localeSpecificImage.length > 0) { return new Resource(new ByteArrayInputStream(localeSpecificImage)); } final byte[] defaultImage = getImageAsBytes(contentObj, AttributeNamesKeys.Category.CATEGORY_IMAGE, curi); if (defaultImage != null && defaultImage.length > 0) { return new Resource(new ByteArrayInputStream(defaultImage)); } } } } final List<String> chain = themeService.getReportsTemplateChainByShopId(shopId); for (final String path : chain) { final String configFile = path + (fileSuffix != null ? fileSuffix : uri.toString()); try { final InputStream stream = themeRepositoryService.getSource(configFile); if (stream != null) { LOG.debug("Using theme specific report template file {}", configFile); return new Resource(stream); } } catch (Exception mue) { LOG.error("Unable to load report template file " + configFile, mue); } } LOG.debug("No report template for {}", uri); return null; } }
FopThemeResourceResolver implements TempResourceResolver, ResourceResolver { @Override public Resource getResource(final URI uri) throws IOException { final Long shopId = shop != null ? shop.getShopId() : null; if (shop != null) { final String curi = shop.getCode().concat("_report_").concat(contentSuffix != null ? contentSuffix : uri.toString()); final String content = contentService.getContentBody(curi, language); if (StringUtils.isNotBlank(content)) { LOG.debug("Using shop specific report template file {}", curi); return new Resource(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))); } final Long contentObjId = contentService.findContentIdBySeoUri(curi); if (contentObjId != null && contentObjId > 0L) { final Content contentObj = contentService.getById(contentObjId); if (contentObj != null) { final byte[] localeSpecificImage = getImageAsBytes(contentObj, AttributeNamesKeys.Category.CATEGORY_IMAGE + "_" + language, curi); if (localeSpecificImage != null && localeSpecificImage.length > 0) { return new Resource(new ByteArrayInputStream(localeSpecificImage)); } final byte[] defaultImage = getImageAsBytes(contentObj, AttributeNamesKeys.Category.CATEGORY_IMAGE, curi); if (defaultImage != null && defaultImage.length > 0) { return new Resource(new ByteArrayInputStream(defaultImage)); } } } } final List<String> chain = themeService.getReportsTemplateChainByShopId(shopId); for (final String path : chain) { final String configFile = path + (fileSuffix != null ? fileSuffix : uri.toString()); try { final InputStream stream = themeRepositoryService.getSource(configFile); if (stream != null) { LOG.debug("Using theme specific report template file {}", configFile); return new Resource(stream); } } catch (Exception mue) { LOG.error("Unable to load report template file " + configFile, mue); } } LOG.debug("No report template for {}", uri); return null; } FopThemeResourceResolver(final Shop shop,
                                    final String language,
                                    final ThemeService themeService,
                                    final ContentService contentService,
                                    final ThemeRepositoryService themeRepositoryService,
                                    final SystemService systemService,
                                    final ImageService imageService);  FopThemeResourceResolver(final Shop shop,
                                    final String language,
                                    final String contentSuffix,
                                    final String fileSuffix,
                                    final ThemeService themeService,
                                    final ContentService contentService,
                                    final ThemeRepositoryService themeRepositoryService,
                                    final SystemService systemService,
                                    final ImageService imageService); }
FopThemeResourceResolver implements TempResourceResolver, ResourceResolver { @Override public Resource getResource(final URI uri) throws IOException { final Long shopId = shop != null ? shop.getShopId() : null; if (shop != null) { final String curi = shop.getCode().concat("_report_").concat(contentSuffix != null ? contentSuffix : uri.toString()); final String content = contentService.getContentBody(curi, language); if (StringUtils.isNotBlank(content)) { LOG.debug("Using shop specific report template file {}", curi); return new Resource(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))); } final Long contentObjId = contentService.findContentIdBySeoUri(curi); if (contentObjId != null && contentObjId > 0L) { final Content contentObj = contentService.getById(contentObjId); if (contentObj != null) { final byte[] localeSpecificImage = getImageAsBytes(contentObj, AttributeNamesKeys.Category.CATEGORY_IMAGE + "_" + language, curi); if (localeSpecificImage != null && localeSpecificImage.length > 0) { return new Resource(new ByteArrayInputStream(localeSpecificImage)); } final byte[] defaultImage = getImageAsBytes(contentObj, AttributeNamesKeys.Category.CATEGORY_IMAGE, curi); if (defaultImage != null && defaultImage.length > 0) { return new Resource(new ByteArrayInputStream(defaultImage)); } } } } final List<String> chain = themeService.getReportsTemplateChainByShopId(shopId); for (final String path : chain) { final String configFile = path + (fileSuffix != null ? fileSuffix : uri.toString()); try { final InputStream stream = themeRepositoryService.getSource(configFile); if (stream != null) { LOG.debug("Using theme specific report template file {}", configFile); return new Resource(stream); } } catch (Exception mue) { LOG.error("Unable to load report template file " + configFile, mue); } } LOG.debug("No report template for {}", uri); return null; } FopThemeResourceResolver(final Shop shop,
                                    final String language,
                                    final ThemeService themeService,
                                    final ContentService contentService,
                                    final ThemeRepositoryService themeRepositoryService,
                                    final SystemService systemService,
                                    final ImageService imageService);  FopThemeResourceResolver(final Shop shop,
                                    final String language,
                                    final String contentSuffix,
                                    final String fileSuffix,
                                    final ThemeService themeService,
                                    final ContentService contentService,
                                    final ThemeRepositoryService themeRepositoryService,
                                    final SystemService systemService,
                                    final ImageService imageService); @Override Resource getResource(final URI uri); @Override OutputStream getOutputStream(final URI uri); @Override Resource getResource(final String id); @Override OutputStream getOutputStream(final String id); }
FopThemeResourceResolver implements TempResourceResolver, ResourceResolver { @Override public Resource getResource(final URI uri) throws IOException { final Long shopId = shop != null ? shop.getShopId() : null; if (shop != null) { final String curi = shop.getCode().concat("_report_").concat(contentSuffix != null ? contentSuffix : uri.toString()); final String content = contentService.getContentBody(curi, language); if (StringUtils.isNotBlank(content)) { LOG.debug("Using shop specific report template file {}", curi); return new Resource(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))); } final Long contentObjId = contentService.findContentIdBySeoUri(curi); if (contentObjId != null && contentObjId > 0L) { final Content contentObj = contentService.getById(contentObjId); if (contentObj != null) { final byte[] localeSpecificImage = getImageAsBytes(contentObj, AttributeNamesKeys.Category.CATEGORY_IMAGE + "_" + language, curi); if (localeSpecificImage != null && localeSpecificImage.length > 0) { return new Resource(new ByteArrayInputStream(localeSpecificImage)); } final byte[] defaultImage = getImageAsBytes(contentObj, AttributeNamesKeys.Category.CATEGORY_IMAGE, curi); if (defaultImage != null && defaultImage.length > 0) { return new Resource(new ByteArrayInputStream(defaultImage)); } } } } final List<String> chain = themeService.getReportsTemplateChainByShopId(shopId); for (final String path : chain) { final String configFile = path + (fileSuffix != null ? fileSuffix : uri.toString()); try { final InputStream stream = themeRepositoryService.getSource(configFile); if (stream != null) { LOG.debug("Using theme specific report template file {}", configFile); return new Resource(stream); } } catch (Exception mue) { LOG.error("Unable to load report template file " + configFile, mue); } } LOG.debug("No report template for {}", uri); return null; } FopThemeResourceResolver(final Shop shop,
                                    final String language,
                                    final ThemeService themeService,
                                    final ContentService contentService,
                                    final ThemeRepositoryService themeRepositoryService,
                                    final SystemService systemService,
                                    final ImageService imageService);  FopThemeResourceResolver(final Shop shop,
                                    final String language,
                                    final String contentSuffix,
                                    final String fileSuffix,
                                    final ThemeService themeService,
                                    final ContentService contentService,
                                    final ThemeRepositoryService themeRepositoryService,
                                    final SystemService systemService,
                                    final ImageService imageService); @Override Resource getResource(final URI uri); @Override OutputStream getOutputStream(final URI uri); @Override Resource getResource(final String id); @Override OutputStream getOutputStream(final String id);  }