protected PortletDataContext getPortletDataContext( ExportImportConfiguration exportImportConfiguration, File file) throws PortalException { Map<String, Serializable> settingsMap = exportImportConfiguration.getSettingsMap(); Map<String, String[]> parameterMap = (Map<String, String[]>) settingsMap.get("parameterMap"); String portletId = MapUtil.getString(settingsMap, "portletId"); long targetPlid = MapUtil.getLong(settingsMap, "targetPlid"); long targetGroupId = MapUtil.getLong(settingsMap, "targetGroupId"); long userId = MapUtil.getLong(settingsMap, "userId"); Layout layout = LayoutLocalServiceUtil.getLayout(targetPlid); String userIdStrategyString = MapUtil.getString(parameterMap, PortletDataHandlerKeys.USER_ID_STRATEGY); UserIdStrategy userIdStrategy = ExportImportHelperUtil.getUserIdStrategy(userId, userIdStrategyString); ZipReader zipReader = ZipReaderFactoryUtil.getZipReader(file); PortletDataContext portletDataContext = PortletDataContextFactoryUtil.createImportPortletDataContext( layout.getCompanyId(), targetGroupId, parameterMap, userIdStrategy, zipReader); portletDataContext.setOldPlid(targetPlid); portletDataContext.setPlid(targetPlid); portletDataContext.setPortletId(portletId); portletDataContext.setPrivateLayout(layout.isPrivateLayout()); return portletDataContext; }
@Override public void importFile(ExportImportConfiguration exportImportConfiguration, File file) throws Exception { PortletDataContext portletDataContext = null; try { ExportImportThreadLocal.setPortletImportInProcess(true); portletDataContext = getPortletDataContext(exportImportConfiguration, file); _exportImportLifecycleManager.fireExportImportLifecycleEvent( EVENT_PORTLET_IMPORT_STARTED, getProcessFlag(), PortletDataContextFactoryUtil.clonePortletDataContext(portletDataContext)); Map<String, Serializable> settingsMap = exportImportConfiguration.getSettingsMap(); long userId = MapUtil.getLong(settingsMap, "userId"); doImportPortletInfo(portletDataContext, userId); ExportImportThreadLocal.setPortletImportInProcess(false); _exportImportLifecycleManager.fireExportImportLifecycleEvent( EVENT_PORTLET_IMPORT_SUCCEEDED, getProcessFlag(), PortletDataContextFactoryUtil.clonePortletDataContext(portletDataContext), userId); } catch (Throwable t) { ExportImportThreadLocal.setPortletImportInProcess(false); _exportImportLifecycleManager.fireExportImportLifecycleEvent( EVENT_PORTLET_IMPORT_FAILED, getProcessFlag(), PortletDataContextFactoryUtil.clonePortletDataContext(portletDataContext), t); throw t; } }
@Ignore @Test public void testExportLinksToUserLayouts() throws Exception { User user = TestPropsValues.getUser(); Group group = user.getGroup(); Layout privateLayout = LayoutTestUtil.addLayout(group, true); Layout publicLayout = LayoutTestUtil.addLayout(group, false); PortletDataContext portletDataContextExport = PortletDataContextFactoryUtil.createExportPortletDataContext( group.getCompanyId(), group.getGroupId(), new HashMap<String, String[]>(), new Date(System.currentTimeMillis() - Time.HOUR), new Date(), new TestReaderWriter()); JournalArticle journalArticle = JournalTestUtil.addArticle( group.getGroupId(), RandomTestUtil.randomString(), RandomTestUtil.randomString()); Element rootElement = SAXReaderUtil.createElement("root"); rootElement.addElement("entry"); String content = replaceLinksToLayoutsParameters( getContent("layout_links_user_group.txt"), privateLayout, publicLayout); content = ExportImportHelperUtil.replaceExportContentReferences( portletDataContextExport, journalArticle, content, true); assertLinksToLayouts(content, privateLayout, 0); assertLinksToLayouts(content, privateLayout, privateLayout.getGroupId()); assertLinksToLayouts(content, publicLayout, 0); assertLinksToLayouts(content, publicLayout, publicLayout.getGroupId()); }
@Before public void setUp() throws Exception { _liveGroup = GroupTestUtil.addGroup(); _stagingGroup = GroupTestUtil.addGroup(); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext( _stagingGroup.getGroupId(), TestPropsValues.getUserId()); _fileEntry = DLAppLocalServiceUtil.addFileEntry( TestPropsValues.getUserId(), _stagingGroup.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, RandomTestUtil.randomString() + ".txt", ContentTypes.TEXT_PLAIN, RandomTestUtil.randomBytes(TikaSafeRandomizerBumper.INSTANCE), serviceContext); ThumbnailCapability thumbnailCapability = _fileEntry.getRepositoryCapability(ThumbnailCapability.class); _fileEntry = thumbnailCapability.setLargeImageId(_fileEntry, _fileEntry.getFileEntryId()); TestReaderWriter testReaderWriter = new TestReaderWriter(); _portletDataContextExport = PortletDataContextFactoryUtil.createExportPortletDataContext( _stagingGroup.getCompanyId(), _stagingGroup.getGroupId(), new HashMap<String, String[]>(), new Date(System.currentTimeMillis() - Time.HOUR), new Date(), testReaderWriter); Document document = SAXReaderUtil.createDocument(); Element manifestRootElement = document.addElement("root"); manifestRootElement.addElement("header"); testReaderWriter.addEntry("/manifest.xml", document.asXML()); Element rootElement = SAXReaderUtil.createElement("root"); _portletDataContextExport.setExportDataRootElement(rootElement); _stagingPrivateLayout = LayoutTestUtil.addLayout(_stagingGroup, true); _stagingPublicLayout = LayoutTestUtil.addLayout(_stagingGroup, false); _portletDataContextExport.setPlid(_stagingPublicLayout.getPlid()); _portletDataContextImport = PortletDataContextFactoryUtil.createImportPortletDataContext( _liveGroup.getCompanyId(), _liveGroup.getGroupId(), new HashMap<String, String[]>(), new TestUserIdStrategy(), testReaderWriter); _portletDataContextImport.setImportDataRootElement(rootElement); Element missingReferencesElement = rootElement.addElement("missing-references"); _portletDataContextImport.setMissingReferencesElement(missingReferencesElement); _livePublicLayout = LayoutTestUtil.addLayout(_liveGroup, false); _portletDataContextImport.setPlid(_livePublicLayout.getPlid()); _portletDataContextImport.setSourceGroupId(_stagingGroup.getGroupId()); rootElement.addElement("entry"); _referrerStagedModel = JournalTestUtil.addArticle( _stagingGroup.getGroupId(), RandomTestUtil.randomString(), RandomTestUtil.randomString()); }