protected DDMTemplate addTemplate( long userId, long groupId, DDMTemplate template, long classPK, File smallFile, ServiceContext serviceContext) throws Exception { DDMTemplate newTemplate = null; try { return DDMTemplateLocalServiceUtil.addTemplate( userId, groupId, template.getClassNameId(), classPK, template.getTemplateKey(), template.getNameMap(), template.getDescriptionMap(), template.getType(), template.getMode(), template.getLanguage(), template.getScript(), template.isCacheable(), template.isSmallImage(), template.getSmallImageURL(), smallFile, serviceContext); } catch (TemplateDuplicateTemplateKeyException tdtke) { newTemplate = DDMTemplateLocalServiceUtil.addTemplate( userId, groupId, template.getClassNameId(), classPK, null, template.getNameMap(), template.getDescriptionMap(), template.getType(), template.getMode(), template.getLanguage(), template.getScript(), template.isCacheable(), template.isSmallImage(), template.getSmallImageURL(), smallFile, serviceContext); if (_log.isWarnEnabled()) { _log.warn( "A template with the key " + template.getTemplateKey() + " already exists. The new generated key is " + newTemplate.getTemplateKey()); } } return newTemplate; }
public DDMTemplate fetchDDMTemplate(long groupId, String displayStyle) { try { Group group = GroupLocalServiceUtil.getGroup(groupId); Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(group.getCompanyId()); if (!displayStyle.startsWith("ddmTemplate_")) { return null; } String uuid = displayStyle.substring(12); if (Validator.isNull(uuid)) { return null; } try { return DDMTemplateLocalServiceUtil.getDDMTemplateByUuidAndGroupId(uuid, groupId); } catch (NoSuchTemplateException nste) { } try { return DDMTemplateLocalServiceUtil.getDDMTemplateByUuidAndGroupId( uuid, companyGroup.getGroupId()); } catch (NoSuchTemplateException nste) { } } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn(e, e); } } return null; }
public static Resource getResource( WebDAVRequest webDAVRequest, String rootPath, String token, long classNameId) throws WebDAVException { try { String[] pathArray = webDAVRequest.getPathArray(); if (pathArray.length == 2) { String path = rootPath + webDAVRequest.getPath(); return new BaseResourceImpl(path, StringPool.BLANK, token); } else if (pathArray.length == 3) { String type = pathArray[2]; return toResource(webDAVRequest, type, rootPath, false); } else if (pathArray.length == 4) { String type = pathArray[2]; String typeId = pathArray[3]; if (type.equals(TYPE_STRUCTURES)) { try { DDMStructure structure = null; try { structure = DDMStructureLocalServiceUtil.getStructure(GetterUtil.getLong(typeId)); } catch (NumberFormatException nfe) { structure = DDMStructureLocalServiceUtil.getStructure( webDAVRequest.getGroupId(), classNameId, typeId); } return DDMWebDavUtil.toResource(webDAVRequest, structure, rootPath, false); } catch (NoSuchStructureException nsse) { return null; } } else if (type.equals(TYPE_TEMPLATES)) { try { DDMTemplate template = null; try { template = DDMTemplateLocalServiceUtil.getTemplate(GetterUtil.getLong(typeId)); } catch (NumberFormatException nfe) { template = DDMTemplateLocalServiceUtil.getTemplate( webDAVRequest.getGroupId(), classNameId, typeId); } return DDMWebDavUtil.toResource(webDAVRequest, template, rootPath, false); } catch (NoSuchTemplateException nste) { return null; } } } return null; } catch (Exception e) { throw new WebDAVException(e); } }
protected DDMTemplate addTemplate( long classNameId, long classPK, long sourceClassNameId, String templateKey, String name, String description, String type, String mode, String language, String script) throws Exception { return DDMTemplateLocalServiceUtil.addTemplate( TestPropsValues.getUserId(), group.getGroupId(), classNameId, classPK, sourceClassNameId, templateKey, getDefaultLocaleMap(name), getDefaultLocaleMap(description), type, mode, language, script, false, false, null, null, ServiceContextTestUtil.getServiceContext()); }
protected DDMTemplate getTemplate(long templateId) { try { return DDMTemplateLocalServiceUtil.getTemplate(templateId); } catch (Exception e) { return null; } }
@Override public DDMTemplate getPortletDisplayTemplateDDMTemplate( long groupId, long classNameId, String displayStyle, boolean useDefault) { long portletDisplayDDMTemplateGroupId = getDDMTemplateGroupId(groupId); DDMTemplate portletDisplayDDMTemplate = null; if (displayStyle.startsWith(DISPLAY_STYLE_PREFIX)) { String ddmTemplateKey = getDDMTemplateKey(displayStyle); if (Validator.isNotNull(ddmTemplateKey)) { try { portletDisplayDDMTemplate = DDMTemplateLocalServiceUtil.fetchTemplate( portletDisplayDDMTemplateGroupId, classNameId, ddmTemplateKey, true); } catch (PortalException e) { } } } if ((portletDisplayDDMTemplate == null) && useDefault) { portletDisplayDDMTemplate = getDefaultPortletDisplayTemplateDDMTemplate(groupId, classNameId); } return portletDisplayDDMTemplate; }
public String renderDDMTemplate( PageContext pageContext, long ddmTemplateId, List<?> entries, Map<String, Object> contextObjects) throws Exception { contextObjects.put(PortletDisplayTemplateConstants.DDM_TEMPLATE_ID, ddmTemplateId); contextObjects.put(PortletDisplayTemplateConstants.ENTRIES, entries); if (entries.size() == 1) { contextObjects.put(PortletDisplayTemplateConstants.ENTRY, entries.get(0)); } HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); contextObjects.put(PortletDisplayTemplateConstants.LOCALE, request.getLocale()); contextObjects.put(PortletDisplayTemplateConstants.REQUEST, request); RenderRequest renderRequest = (RenderRequest) request.getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST); contextObjects.put(PortletDisplayTemplateConstants.RENDER_REQUEST, renderRequest); RenderResponse renderResponse = (RenderResponse) request.getAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE); contextObjects.put(PortletDisplayTemplateConstants.RENDER_RESPONSE, renderResponse); PortletURL currentURL = PortletURLUtil.getCurrent(renderRequest, renderResponse); contextObjects.put(PortletDisplayTemplateConstants.CURRENT_URL, currentURL.toString()); ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY); contextObjects.put(PortletDisplayTemplateConstants.THEME_DISPLAY, themeDisplay); // Taglibs DDMTemplate ddmTemplate = DDMTemplateLocalServiceUtil.getTemplate(ddmTemplateId); String language = ddmTemplate.getLanguage(); if (language.equals(TemplateConstants.LANG_TYPE_FTL)) { _addTaglibSupportFTL(contextObjects, pageContext); } else if (language.equals(TemplateConstants.LANG_TYPE_VM)) { _addTaglibSupportVM(contextObjects, pageContext); } contextObjects.putAll(_getPortletPreferences(renderRequest)); return _transformer.transform(themeDisplay, contextObjects, ddmTemplate.getScript(), language); }
@Override public String renderDDMTemplate( HttpServletRequest request, HttpServletResponse response, long ddmTemplateId, List<?> entries, Map<String, Object> contextObjects) throws Exception { DDMTemplate ddmTemplate = DDMTemplateLocalServiceUtil.getTemplate(ddmTemplateId); return renderDDMTemplate(request, response, ddmTemplate, entries, contextObjects); }
@Override protected PortletPreferences doDeleteData( PortletDataContext portletDataContext, String portletId, PortletPreferences portletPreferences) throws Exception { if (portletDataContext.addPrimaryKey(DDMPortletDataHandler.class, "deleteData")) { return portletPreferences; } DDMTemplateLocalServiceUtil.deleteTemplates(portletDataContext.getScopeGroupId()); DDMStructureLocalServiceUtil.deleteStructures(portletDataContext.getScopeGroupId()); return portletPreferences; }
protected List<Resource> getTemplates(WebDAVRequest webDAVRequest) throws Exception { List<Resource> resources = new ArrayList<>(); List<DDMTemplate> ddmTemplates = DDMTemplateLocalServiceUtil.getTemplatesByStructureClassNameId( webDAVRequest.getGroupId(), PortalUtil.getClassNameId(JournalArticle.class), QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); for (DDMTemplate ddmTemplate : ddmTemplates) { Resource resource = DDMWebDavUtil.toResource(webDAVRequest, ddmTemplate, getRootPath(), true); resources.add(resource); } return resources; }
@Override protected void doImportStagedModel(PortletDataContext portletDataContext, DDMTemplate template) throws Exception { long userId = portletDataContext.getUserId(template.getUserUuid()); Map<Long, Long> structureIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(DDMStructure.class); long classPK = MapUtil.getLong(structureIds, template.getClassPK(), template.getClassPK()); File smallFile = null; if (template.isSmallImage()) { Element element = portletDataContext.getImportDataStagedModelElement(template); String smallImagePath = element.attributeValue("small-image-path"); if (Validator.isNotNull(template.getSmallImageURL())) { String smallImageURL = JournalPortletDataHandler.importReferencedContent( portletDataContext, element, template.getSmallImageURL()); template.setSmallImageURL(smallImageURL); } else if (Validator.isNotNull(smallImagePath)) { byte[] bytes = portletDataContext.getZipEntryAsByteArray(smallImagePath); if (bytes != null) { smallFile = FileUtil.createTempFile(template.getSmallImageType()); FileUtil.write(smallFile, bytes); } } } ServiceContext serviceContext = portletDataContext.createServiceContext(template, DDMPortletDataHandler.NAMESPACE); DDMTemplate importedTemplate = null; if (portletDataContext.isDataStrategyMirror()) { DDMTemplate existingTemplate = DDMTemplateUtil.fetchByUUID_G(template.getUuid(), portletDataContext.getScopeGroupId()); if (existingTemplate == null) { serviceContext.setUuid(template.getUuid()); importedTemplate = addTemplate( userId, portletDataContext.getScopeGroupId(), template, classPK, smallFile, serviceContext); } else { importedTemplate = DDMTemplateLocalServiceUtil.updateTemplate( existingTemplate.getTemplateId(), template.getNameMap(), template.getDescriptionMap(), template.getType(), template.getMode(), template.getLanguage(), template.getScript(), template.isCacheable(), template.isSmallImage(), template.getSmallImageURL(), smallFile, serviceContext); } } else { importedTemplate = addTemplate( userId, portletDataContext.getScopeGroupId(), template, classPK, smallFile, serviceContext); } portletDataContext.importClassedModel( template, importedTemplate, DDMPortletDataHandler.NAMESPACE); }
@Override public List<DDMTemplate> getTemplates() throws SystemException { return DDMTemplateLocalServiceUtil.getTemplates(getStructureId()); }
protected void exportImportJournalArticle(boolean companyScopeDependencies) throws Exception { JournalArticle article = null; DDMStructure ddmStructure = null; DDMTemplate ddmTemplate = null; long groupId = group.getGroupId(); Company company = CompanyLocalServiceUtil.fetchCompany(group.getCompanyId()); Group companyGroup = company.getGroup(); if (companyScopeDependencies) { groupId = companyGroup.getGroupId(); } ddmStructure = DDMStructureTestUtil.addStructure(groupId, JournalArticle.class.getName()); ddmTemplate = DDMTemplateTestUtil.addTemplate(groupId, ddmStructure.getStructureId()); String content = DDMStructureTestUtil.getSampleStructuredContent(); article = JournalTestUtil.addArticleWithXMLContent( group.getGroupId(), content, ddmStructure.getStructureKey(), ddmTemplate.getTemplateKey()); exportImportPortlet(PortletKeys.JOURNAL); int articlesCount = JournalArticleLocalServiceUtil.getArticlesCount(importedGroup.getGroupId()); Assert.assertEquals(1, articlesCount); JournalArticle groupArticle = JournalArticleLocalServiceUtil.fetchJournalArticleByUuidAndGroupId( article.getUuid(), importedGroup.getGroupId()); Assert.assertNotNull(groupArticle); groupId = importedGroup.getGroupId(); if (companyScopeDependencies) { DDMStructure importedDDMStructure = DDMStructureLocalServiceUtil.fetchDDMStructureByUuidAndGroupId( ddmStructure.getUuid(), groupId); Assert.assertNull(importedDDMStructure); DDMTemplate importedDDMTemplate = DDMTemplateLocalServiceUtil.fetchDDMTemplateByUuidAndGroupId( ddmTemplate.getUuid(), groupId); Assert.assertNull(importedDDMTemplate); groupId = companyGroup.getGroupId(); } DDMStructure dependentDDMStructure = DDMStructureLocalServiceUtil.fetchDDMStructureByUuidAndGroupId( ddmStructure.getUuid(), groupId); Assert.assertNotNull(dependentDDMStructure); DDMTemplate dependentDDMTemplate = DDMTemplateLocalServiceUtil.fetchDDMTemplateByUuidAndGroupId( ddmTemplate.getUuid(), groupId); Assert.assertNotNull(dependentDDMTemplate); Assert.assertEquals(article.getDDMStructureKey(), dependentDDMStructure.getStructureKey()); Assert.assertEquals(article.getDDMTemplateKey(), dependentDDMTemplate.getTemplateKey()); Assert.assertEquals(dependentDDMTemplate.getClassPK(), dependentDDMStructure.getStructureId()); }