@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); }
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()); }