public void testIsCheckedOut() throws Exception { // create versionable subnode and checkin its versionable parent // testRoot - versionable ancestor testRoot.checkout(); Node subNode = testRoot.addNode("node1").addNode("node2").addNode("subNode"); testRoot.save(); subNode.addMixin("mix:versionable"); testRoot.save(); subNode.checkin(); subNode.checkout(); subNode.setProperty("property1", "property1 v1"); subNode.save(); subNode.checkin(); subNode.checkout(); // test testRoot.checkin(); // make subtree checked-in try { assertTrue("subNode should be checked-out as it's a mix:versionable", subNode.isCheckedOut()); } catch (RepositoryException e) { } }
public void testRemoveMixLockableFromLockedNode() throws RepositoryException, NotExecutableException { try { lockedNode.removeMixin(mixLockable); lockedNode.save(); // the mixin got removed -> the lock should implicitely be released // as well in order not to have inconsistencies String msg = "Lock should have been released."; assertFalse(msg, lock.isLive()); assertFalse(msg, lockedNode.isLocked()); assertFalse(msg, lockMgr.isLocked(lockedNode.getPath())); assertFalse(msg, lockedNode.hasProperty(jcrLockOwner)); assertFalse(msg, lockedNode.hasProperty(jcrlockIsDeep)); } catch (ConstraintViolationException e) { // cannot remove the mixin -> ok // consequently the node must still be locked, the lock still live... String msg = "Lock must still be live."; assertTrue(msg, lock.isLive()); assertTrue(msg, lockedNode.isLocked()); assertTrue(msg, lockMgr.isLocked(lockedNode.getPath())); assertTrue(msg, lockedNode.hasProperty(jcrLockOwner)); assertTrue(msg, lockedNode.hasProperty(jcrlockIsDeep)); } finally { // ev. re-add the mixin in order to be able to unlock the node if (lockedNode.isLocked()) { ensureMixinType(lockedNode, mixLockable); lockedNode.save(); } } }
/** {@inheritDoc} */ public void watchDocument(Node documentNode, String userName, int notifyType) throws Exception { Session session = documentNode.getSession(); Value newWatcher = session.getValueFactory().createValue(userName); if (!documentNode.isNodeType(EXO_WATCHABLE_MIXIN)) { documentNode.addMixin(EXO_WATCHABLE_MIXIN); if (notifyType == NOTIFICATION_BY_EMAIL) { documentNode.setProperty(EMAIL_WATCHERS_PROP, new Value[] {newWatcher}); documentNode.save(); session.save(); EmailNotifyListener listener = new EmailNotifyListener(documentNode); observeNode(documentNode, listener); } session.save(); } else { List<Value> watcherList = new ArrayList<Value>(); if (notifyType == NOTIFICATION_BY_EMAIL) { if (documentNode.hasProperty(EMAIL_WATCHERS_PROP)) { for (Value watcher : documentNode.getProperty(EMAIL_WATCHERS_PROP).getValues()) { watcherList.add(watcher); } watcherList.add(newWatcher); } documentNode.setProperty( EMAIL_WATCHERS_PROP, watcherList.toArray(new Value[watcherList.size()])); documentNode.save(); } session.save(); } }
/** * Recursive method to make all children visible or not * * @param node * @param visible */ private void propagateVisibility(Node node, boolean visible) throws RepositoryException { if (node.hasNodes()) { // loop over child nodes... NodeIterator itChildNodes = node.getNodes(); while (itChildNodes.hasNext()) { Node childNode = itChildNodes.nextNode(); boolean hasNavigableMixinType = childNode.isNodeType("exo:navigable"); if (visible) { boolean folderType = childNode.isNodeType("nt:folder") || childNode.isNodeType("exo:taxonomy"); boolean navigableType = folderType || childNode.isNodeType("exo:webContent") || childNode.isNodeType("exo:product") || childNode.isNodeType("exo:taxonomyLink"); if (!hasNavigableMixinType && navigableType) { if (childNode.canAddMixin("exo:navigable")) { childNode.addMixin("exo:navigable"); } else { // uiApp.addMessage(new // ApplicationMessage("UISingleExternalMetadataForm.msg.can-not-add", null)); // event.getRequestContext().addUIComponentToUpdateByAjax(uiApp.getUIPopupMessages()); return; } childNode.setProperty("exo:navigationNode", ""); childNode.setProperty("exo:index", 1000); childNode.setProperty("exo:clickable", true); childNode.setProperty("exo:page", ""); childNode.setProperty("exo:pageParamId", ""); childNode.setProperty("exo:childrenPage", ""); childNode.setProperty("exo:childrenPageParamId", ""); childNode.save(); if (folderType) { propagateVisibility(childNode, visible); } } } else { if (hasNavigableMixinType) { childNode.removeMixin("exo:navigable"); childNode.save(); } propagateVisibility(childNode, visible); } } } }
private void removeProperty(Session session, String path, String property, String value) { final boolean stats = NotificationContextFactory.getInstance().getStatistics().isStatisticsEnabled(); try { Node node = (Node) session.getItem(path); List<String> values = NotificationUtils.valuesToList(node.getProperty(property).getValues()); if (values.contains(value)) { values.remove(value); if (values.isEmpty()) { values.add(""); } node.setProperty(property, values.toArray(new String[values.size()])); node.save(); // record entity update here if (stats) { NotificationContextFactory.getInstance() .getStatisticsCollector() .updateEntity(NTF_MESSAGE); } } } catch (Exception e) { LOG.warn(String.format("Failed to remove property %s of value %s on node ", property, value)); } }
/** * Test the assignment of an empty property by assigning it a null array, saved from the parent * Node */ public void testEmptyMultiStringParent() throws RepositoryException { String[] emptyStringArray = new String[] {null}; property2.setValue(emptyStringArray); node.save(); assertEquals( "Property.setValue(emptyStringArray) did not set the property to an empty array", 0, property2.getValues().length); }
private void addTab(Node view, String tabName, String buttons) throws Exception { Node tab; if (view.hasNode(tabName)) { tab = view.getNode(tabName); } else { tab = view.addNode(tabName, "exo:tab"); } tab.setProperty("exo:buttons", buttons); view.save(); }
/** Test the deletion of a property by assigning it a null value, saved from the parent Node */ public void testRemoveMultiStringParent() throws RepositoryException { property2.setValue((String[]) null); node.save(); try { node.getProperty(propertyName2); fail("The property should not exist anymore, as a null Value has been assigned"); } catch (PathNotFoundException e) { // success : the property has been deleted by assigning it a null value } }
/** * This will use the give node (which must be lockable) as a container for a unique id. The id * will be stored in a property. Before accessing it, the node will be locked or it will wait for * taking the lock. After a successful lock, it will return the latest id + 1, this will also be * stored as the new value in the property of the node. */ private long atomicLockNodeAndGetNextID(Session session, Node node, String jcrPath) throws IDException { // we need to synchronize the access to the node which holds the // unique id; thus we lock it before reading and modifying it; if // locking is not possible because the node is locked, // loop until node.lock() was successful while (true) { try { // the lock must be session scoped (2nd arg == true) so that it // does not persist if something fails before we manually // unlock it (eg. JVM crash or fatal RepositoryException) node.lock(false, true); break; } catch (LockException e) { try { Thread.sleep(LOCK_SLEEP_MILLIS); } catch (InterruptedException e1) { // just ignore and go to the beginning of the loop } } catch (RepositoryException e) { // forward any exception throw new IDException("Cannot lock unique id node for " + jcrPath, e); } } // the node is now locked long resultID; try { // atomic increment access due to lock Property idProp = node.getProperty(ID_PROPERTY); resultID = idProp.getLong(); resultID++; idProp.setValue(resultID); // persist id value changes node.save(); } catch (RepositoryException e) { // forward any exception throw new IDException("Cannot modify unique id for " + jcrPath, e); } finally { // ensure the lock is removed try { node.unlock(); } catch (RepositoryException e) { // forward any exception throw new IDException("Cannot unlock unique id node for " + jcrPath, e); } } return resultID; }
/** * Test the persistence of a property modified with an multi-value String parameter and saved from * the parent Node Requires a multi-value String (mv) */ public void testMultiStringParent() throws RepositoryException { String[] mv = new String[] {PROP_VALUE_1, PROP_VALUE_2}; property2.setValue(mv); node.save(); Value[] values = property2.getValues(); List<String> strValues = new ArrayList<String>(); for (int i = 0; i < values.length; i++) { strValues.add(values[i].getString()); } assertEquals("Node property not saved", Arrays.asList(mv), strValues); }
/* (non-Javadoc) * @see org.exoplatform.services.wcm.link.LiveLinkManagerService#updateLinks(javax.jcr.Node, java.util.List) */ public void updateLinkDataForNode(Node webContent, List<String> newLinks) throws Exception { ValueFactory valueFactory = webContent.getSession().getValueFactory(); if (webContent.canAddMixin("exo:linkable")) { webContent.addMixin("exo:linkable"); } // get old link from exo:links property List<String> listExtractedLink = new ArrayList<String>(); if (webContent.hasProperty("exo:links")) { Property property = webContent.getProperty("exo:links"); for (Value value : property.getValues()) { listExtractedLink.add(value.getString()); } } // compare, remove old link, add new link, create new List List<String> listResult = new ArrayList<String>(); for (String extractedLink : listExtractedLink) { for (String newUrl : newLinks) { if (LinkBean.parse(extractedLink).getUrl().equals(newUrl)) { listResult.add(extractedLink); } } } List<String> listTemp = new ArrayList<String>(); listTemp.addAll(newLinks); for (String newUrl : newLinks) { for (String extractedLink : listExtractedLink) { if (newUrl.equals(LinkBean.parse(extractedLink).getUrl())) { listTemp.set(newLinks.indexOf(newUrl), ""); } } } for (String strTemp : listTemp) { if (!strTemp.equals("")) { listResult.add(strTemp); } } // Create an array of value to add to exo:links property Value[] values = new Value[listResult.size()]; for (String url : listResult) { if (url.indexOf(LinkBean.STATUS) < 0) { LinkBean linkBean = new LinkBean(url, LinkBean.STATUS_UNCHECKED); values[listResult.indexOf(url)] = valueFactory.createValue(linkBean.toString()); } else { values[listResult.indexOf(url)] = valueFactory.createValue(url); } } webContent.setProperty("exo:links", values); webContent.save(); }
/** Test the deletion of a property by assigning it a null value, saved from the parent Node */ public void testRemoveStringParent() throws RepositoryException { String sv = null; property1.setValue(sv); node.save(); try { node.getProperty(propertyName1); fail("The property should not exist anymore, as a null String has been assigned"); } catch (PathNotFoundException e) { // success : the property has been deleted by assigning it a null value } }
public void testRemoveMixVersionable() throws Exception { testRoot.checkout(); try { testRoot.removeMixin("mix:versionable"); testRoot.save(); } catch (RepositoryException e) { e.printStackTrace(); fail("removeMixin(\"mix:versionable\") impossible due to error " + e.getMessage()); } }
public void testJCR1438_Simple() throws Exception { Node testRoot = root.addNode("testRoot"); root.save(); Node l1Node = testRoot.addNode("l1"); l1Node.addMixin("mix:versionable"); Node folder = l1Node.addNode("folder", "nt:folder"); root.save(); l1Node.checkin(); l1Node.checkout(); root.save(); Node testImage = folder.addNode("test_image", "nt:file"); testImage.addMixin("mix:versionable"); Node contentTestImage = testImage.addNode("jcr:content", "nt:resource"); contentTestImage.setProperty("jcr:data", "content_test_image_data"); contentTestImage.setProperty("jcr:encoding", "UTF-8"); contentTestImage.setProperty("jcr:lastModified", Calendar.getInstance()); contentTestImage.setProperty("jcr:mimeType", "text/jpeg"); root.save(); Version tImageV1 = testImage.checkin(); testImage.checkout(); testImage.save(); Version v2 = l1Node.checkin(); l1Node.checkout(); root.save(); Node rTestImage = testRoot.getNode("l1").getNode("folder").getNode("test_image"); assertNotNull(rTestImage); Node rTestImageContent = rTestImage.getNode("jcr:content"); assertNotNull(rTestImageContent); assertNotNull(rTestImageContent.getProperty("jcr:data")); assertEquals("content_test_image_data", rTestImageContent.getProperty("jcr:data").getString()); /*testImage.remove(); root.save();*/ l1Node.restore("2", true); rTestImage = testRoot.getNode("l1").getNode("folder").getNode("test_image"); assertNotNull(rTestImage); rTestImageContent = rTestImage.getNode("jcr:content"); assertNotNull(rTestImageContent); assertNotNull(rTestImageContent.getProperty("jcr:data")); assertEquals("content_test_image_data", rTestImageContent.getProperty("jcr:data").getString()); }
public void testRemoveMixVersionableTwice() throws Exception { testRoot.checkout(); testRoot.removeMixin("mix:versionable"); testRoot.save(); try { testRoot.removeMixin("mix:versionable"); fail("removeMixin(\"mix:versionable\") should throw NoSuchNodeTypeException exception"); } catch (NoSuchNodeTypeException e) { // ok } }
@Override public void setUp() throws Exception { super.setUp(); testRoot = root.addNode("testRemoveVersionable"); root.save(); testRoot.addMixin("mix:versionable"); root.save(); testRoot.checkin(); testRoot.checkout(); testRoot.addNode("node1"); testRoot.addNode("node2").setProperty("prop1", "a property #1"); testRoot.save(); testRoot.checkin(); testRoot.checkout(); testRoot.getNode("node1").remove(); testRoot.save(); testRoot.checkin(); }
private Node addView( Node viewManager, String viewName, String permissions, boolean hideExplorerPanel, String template) throws Exception { Node contentNode = viewManager.addNode(viewName, "exo:view"); contentNode.setProperty("exo:accessPermissions", permissions); contentNode.setProperty("exo:template", template); if (contentNode.hasProperty("exo:hideExplorerPanel")) { contentNode.setProperty("exo:hideExplorerPanel", hideExplorerPanel); } viewManager.save(); return contentNode; }
/** {@inheritDoc} */ public void unwatchDocument(Node documentNode, String userName, int notificationType) throws Exception { if (!documentNode.isNodeType(EXO_WATCHABLE_MIXIN)) return; Session session = documentNode.getSession(); if (notificationType == NOTIFICATION_BY_EMAIL) { Value[] watchers = documentNode.getProperty(EMAIL_WATCHERS_PROP).getValues(); List<Value> watcherList = new ArrayList<Value>(); for (Value watcher : watchers) { if (!watcher.getString().equals(userName)) { watcherList.add(watcher); } } documentNode.setProperty( EMAIL_WATCHERS_PROP, watcherList.toArray(new Value[watcherList.size()])); } documentNode.save(); session.save(); }
public void saveFeed(SyndFeed feed, String rssNodeType) { try { boolean isNew = false; try { itemNode.getNode(RSS_NODE_NAME); } catch (PathNotFoundException pnfe) { LOG.debug("Feed node not found for " + itemNode.getName() + " creating..."); itemNode.addNode(RSS_NODE_NAME, rssNodeType); isNew = true; } SyndFeedOutput output = new SyndFeedOutput(); setContent(new ByteArrayInputStream(output.outputString(feed).getBytes())); if (isNew) itemNode.getSession().save(); else itemNode.save(); } catch (Exception e) { LOG.error("Failed to save feed content", e); } }
/** {@inheritDoc} */ public void addTemplate(Node portletTemplateHome, PortletTemplateConfig config) throws Exception { Node category = null; try { category = portletTemplateHome.getNode(config.getCategory()); } catch (Exception e) { category = portletTemplateHome.addNode(config.getCategory(), "nt:unstructured"); portletTemplateHome.save(); } if (!category.hasNode(config.getTemplateName())) { templateService.createTemplate( category, config.getTemplateName(), new ByteArrayInputStream(config.getTemplateData().getBytes()), new String[] {"*"}); } Set<String> templateSet = configuredTemplates_.get(portletTemplateHome.getName()); if (templateSet == null) { templateSet = new HashSet<String>(); } templateSet.add(category.getName() + "/" + config.getTemplateName()); configuredTemplates_.put(portletTemplateHome.getName(), templateSet); }
public void setUp() throws Exception { super.setUp(); ExoContainer myContainer = ExoContainerContext.getCurrentContainer(); favoriteService = (FavoriteService) myContainer.getComponentInstanceOfType(FavoriteService.class); SessionProviderService sessionProviderService = (SessionProviderService) myContainer.getComponentInstanceOfType(SessionProviderService.class); SessionProvider sessionProvider = sessionProviderService.getSystemSessionProvider(null); ManageableRepository manageableRepository = repositoryService.getRepository("repository"); Session session = sessionProvider.getSession(COLLABORATION_WS, manageableRepository); Node rootNode = session.getRootNode(); String[] names = new String[] {"root", "demo", "james", "john", "marry"}; for (String name : names) if (rootNode.hasNode(name)) { rootNode.getNode(name).remove(); rootNode.save(); } }
@org.junit.After public void shutdown() throws Exception { // delete all child nodes to get a clean repository again final Node rootNode = (Node) session.getItem(this.handler.repositoryPath); final NodeIterator iter = rootNode.getNodes(); while (iter.hasNext()) { final Node child = iter.nextNode(); child.remove(); } rootNode.save(); // lets set up the bundle context with the sling id final BundleContext bundleContext = this.getMockery().mock(BundleContext.class); final ComponentContext componentContext = this.getMockery().mock(ComponentContext.class); this.getMockery() .checking( new Expectations() { { allowing(componentContext).getBundleContext(); will(returnValue(bundleContext)); } }); this.handler.deactivate(componentContext); }
protected void tearDown() throws Exception { try { // remove all versionable nodes below the test versionableNode2.remove(); wVersionableNode.remove(); wVersionableNode2.remove(); wTestRoot.save(); } finally { if (wSuperuser != null) { wSuperuser.logout(); wSuperuser = null; } version = null; version2 = null; rootVersion = null; versionableNode2 = null; wTestRoot = null; wVersionableNode = null; wVersionableNode2 = null; wVersionableChildNode = null; wChildVersion = null; super.tearDown(); } }
private ExoSocialActivity saveActivity( Map<String, String> activityParams, ActivityManager activityManager, IdentityManager identityManager, Identity ownerIdentity, String remoteUser) throws ActivityStorageException, RepositoryException { Node node = getDocNode( activityParams.get(UIDocActivity.REPOSITORY), activityParams.get(UIDocActivity.WORKSPACE), activityParams.get(UIDocActivity.DOCPATH)); String activity_type = UIDocActivity.ACTIVITY_TYPE; if (node.getPrimaryNodeType().getName().equals(NodetypeConstant.NT_FILE)) { activity_type = FILE_SPACES; } Identity userIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, remoteUser, true); String title = activityParams.get(UIDocActivity.MESSAGE); if (title == null || title.length() == 0) { title = docActivityTitle; } ExoSocialActivity activity = new ExoSocialActivityImpl(userIdentity.getId(), activity_type, title, null); activity.setTemplateParams(activityParams); activityManager.saveActivityNoReturn(ownerIdentity, activity); String activityId = activity.getId(); if (!StringUtils.isEmpty(activityId)) { ActivityTypeUtils.attachActivityId(node, activityId); node.save(); } return activityManager.getActivity(activity.getId()); }
/** * Import predefined template to db. * * @param storedTemplateHomeNode the stored template home node * @see Node * @throws Exception the exception */ private void importPredefinedTemplateToDB(Node storedTemplateHomeNode) throws Exception { HashMap<String, List<PortletTemplateConfig>> map = new HashMap<String, List<PortletTemplateConfig>>(); String repository = ((ManageableRepository) storedTemplateHomeNode.getSession().getRepository()) .getConfiguration() .getName(); List<String> managedApplicationsPerRepo = managedApplicationNames.get(repository); if (managedApplicationsPerRepo == null) { managedApplicationsPerRepo = new ArrayList<String>(); } for (PortletTemplatePlugin plugin : portletTemplatePlugins) { String portletName = plugin.getPortletName(); if (!managedApplicationsPerRepo.contains(portletName)) { managedApplicationsPerRepo.add(portletName); } List<PortletTemplateConfig> list = map.get(portletName); if (list == null) { list = new ArrayList<PortletTemplateConfig>(); } list.addAll(plugin.getPortletTemplateConfigs()); map.put(portletName, list); } for (String portletName : managedApplicationsPerRepo) { Node templateNode = storedTemplateHomeNode.hasNode(portletName) ? storedTemplateHomeNode.getNode(portletName) : storedTemplateHomeNode.addNode(portletName, "nt:unstructured"); storedTemplateHomeNode.save(); for (PortletTemplateConfig config : map.get(portletName)) { addTemplate(templateNode, config); } } managedApplicationNames.put(repository, managedApplicationsPerRepo); storedTemplateHomeNode.getSession().save(); }
public void execute(Event<UINavigationForm> event) throws Exception { UINavigationForm uiNavigationForm = event.getSource(); UIJCRExplorer uiExplorer = uiNavigationForm.getAncestorOfType(UIJCRExplorer.class); UIApplication uiApp = uiNavigationForm.getAncestorOfType(UIApplication.class); // retrieve current node Node node = uiExplorer.getCurrentNode(); // if current node is locked... if (uiExplorer.nodeIsLocked(node)) { uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.node-locked", null)); event.getRequestContext().addUIComponentToUpdateByAjax(uiApp.getUIPopupMessages()); return; } boolean isVisible = (Boolean) uiNavigationForm.<UIFormCheckBoxInput<Boolean>>getUIInput(IS_VISIBLE).getValue(); boolean hasNavigableMixinType = node.isNodeType("exo:navigable"); if (isVisible) { if (!hasNavigableMixinType) { if (node.canAddMixin("exo:navigable")) { node.addMixin("exo:navigable"); } else { uiApp.addMessage( new ApplicationMessage("UISingleExternalMetadataForm.msg.can-not-add", null)); event.getRequestContext().addUIComponentToUpdateByAjax(uiApp.getUIPopupMessages()); return; } } String navigationNode = uiNavigationForm.getUIStringInput(NAVIGATION_NODE_STRING_INPUT).getValue(); node.setProperty("exo:navigationNode", navigationNode); // if navigation node is selected, default values of // "index and clickable" are saved long index = 1000; boolean isClickable = false; String listTargetPage = uiNavigationForm.getUIStringInput(LIST_TARGET_PAGE_STRING_INPUT).getValue(); if (navigationNode.equals("")) { if (uiNavigationForm.getUIStringInput(INDEX) != null) { index = Long.parseLong(uiNavigationForm.getUIStringInput(INDEX).getValue()); } isClickable = (Boolean) uiNavigationForm .<UIFormCheckBoxInput<Boolean>>getUIInput(IS_CLICKABLE) .getValue(); } node.setProperty("exo:index", index); node.setProperty("exo:clickable", isClickable); node.setProperty("exo:page", listTargetPage); node.setProperty("exo:pageParamId", "folder-id"); String detailTargetPage = uiNavigationForm.getUIStringInput(DETAIL_TARGET_PAGE_STRING_INPUT).getValue(); node.setProperty("exo:childrenPage", detailTargetPage); node.setProperty("exo:childrenPageParamId", "content-id"); } else { if (hasNavigableMixinType) { node.removeMixin("exo:navigable"); } } node.save(); propagateVisibility(node, isVisible); node.getSession().save(); // close window uiExplorer.cancelAction(); }
/** * Test the persistence of a property modified with a String parameter and saved from the parent * Node Requires a single-value String (PROP_VALUE_2) */ public void testStringParent() throws RepositoryException { property1.setValue(PROP_VALUE_2); node.save(); assertEquals("String node property not saved", PROP_VALUE_2, property1.getString()); }
public void start() { if (ProductVersions.getCurrentVersionAsInt() == ProductVersions.WCM_2_1_2_NUM) { SessionProvider sessionProvider = SessionProvider.createSystemProvider(); try { ManageableRepository repository = repositoryService.getCurrentRepository(); Session session = sessionProvider.getSession("dms-system", repository); Node rootNode = session.getRootNode(); /** CHECK IF WE USE THE OLD STRUCTURE (PRE 2.1.2) OR IF IT'S A POST 2.1.2 WEBSITE */ if (rootNode.hasNode("exo:ecm/views/templates/Content List Viewer")) { /** CREATE NEW STRUCTURE IF IT DOESN'T EXIST */ if (!rootNode.hasNode("exo:ecm/views/templates/content-list-viewer")) { rootNode.addNode("exo:ecm/views/templates/content-list-viewer", "nt:unstructured"); if (LOG.isInfoEnabled()) LOG.info("CREATE :: content-list-viewer"); rootNode.save(); } if (!rootNode.hasNode("exo:ecm/views/templates/content-list-viewer/paginators")) { rootNode.addNode( "exo:ecm/views/templates/content-list-viewer/paginators", "nt:unstructured"); if (LOG.isInfoEnabled()) LOG.info("CREATE :: paginators"); rootNode.save(); } if (!rootNode.hasNode("exo:ecm/views/templates/content-list-viewer/list")) { rootNode.addNode("exo:ecm/views/templates/content-list-viewer/list", "nt:unstructured"); if (LOG.isInfoEnabled()) LOG.info("CREATE :: list"); rootNode.save(); } if (!rootNode.hasNode("exo:ecm/views/templates/content-list-viewer/navigation")) { rootNode.addNode( "exo:ecm/views/templates/content-list-viewer/navigation", "nt:unstructured"); if (LOG.isInfoEnabled()) LOG.info("CREATE :: navigation"); rootNode.save(); } /** CHECK IF PAGINATORS ARE IN THE NEW PLACE */ Node oldPaginatorsNode = rootNode.getNode("exo:ecm/views/templates/Content List Viewer/paginators"); Node newPaginatorsNode = rootNode.getNode("exo:ecm/views/templates/content-list-viewer/paginators"); NodeIterator oldPaginatorsNodes = oldPaginatorsNode.getNodes(); while (oldPaginatorsNodes.hasNext()) { Node paginatorNode = oldPaginatorsNodes.nextNode(); if (!newPaginatorsNode.hasNode(paginatorNode.getName())) { /** NODE NOT MIGRATED, WE DO IT */ session .getWorkspace() .copy( "/exo:ecm/views/templates/Content List Viewer/paginators/" + paginatorNode.getName(), "/exo:ecm/views/templates/content-list-viewer/paginators/" + paginatorNode.getName()); if (LOG.isInfoEnabled()) LOG.info("CLONE :: " + paginatorNode.getName()); } } session.save(); /** CHECK IF VIEWS ARE IN THE NEW PLACE */ Node oldViewNode = rootNode.getNode("exo:ecm/views/templates/Content List Viewer/list-by-folder"); Node newViewListNode = rootNode.getNode("exo:ecm/views/templates/content-list-viewer/list"); Node newViewNavNode = rootNode.getNode("exo:ecm/views/templates/content-list-viewer/navigation"); NodeIterator oldViewNodes = oldViewNode.getNodes(); while (oldViewNodes.hasNext()) { Node viewNode = oldViewNodes.nextNode(); if (!newViewListNode.hasNode(viewNode.getName()) && !newViewNavNode.hasNode(viewNode.getName())) { Node content = viewNode.getNode("jcr:content"); InputStream data = content.getProperty("jcr:data").getStream(); String sdata = inputStreamAsString(data); String targetFolder = "list"; if (sdata.contains("public void renderCategories")) { targetFolder = "navigation"; } /** NODE NOT MIGRATED, WE DO IT */ session .getWorkspace() .copy( "/exo:ecm/views/templates/Content List Viewer/list-by-folder/" + viewNode.getName(), "/exo:ecm/views/templates/content-list-viewer/" + targetFolder + "/" + viewNode.getName()); if (LOG.isInfoEnabled()) LOG.info("CLONE :: " + targetFolder + " :: " + viewNode.getName()); } } session.save(); session.logout(); /** UPDATE OLD PORTLET PREFERENCES */ session = sessionProvider.getSession("portal-system", repository); QueryManager manager = session.getWorkspace().getQueryManager(); String statement = "SELECT * from mop:portletpreference where mop:value LIKE '/exo:ecm/views/templates/Content List Viewer/%'"; Query query = manager.createQuery(statement.toString(), Query.SQL); NodeIterator nodes = query.execute().getNodes(); while (nodes.hasNext()) { Node node = (Node) nodes.next(); String value = node.getProperty("mop:value").getValues()[0].getString(); String newValue = MigrationUtil.checkAndUpdateViewerTemplate(value); if (!value.equals(newValue)) { if (LOG.isInfoEnabled()) LOG.info( "CONVERT :: mop:portletpreference :: " + value + " :: " + newValue + " :: " + node.getPath()); node.setProperty("mop:value", new String[] {newValue}); node.save(); } } if (LOG.isWarnEnabled()) { LOG.warn( "IMPORTANT NOTE ABOUT WCM 2.1.2 :\n" + "All CLV templates have been copied to a new storage place. " + "We keep your old templates in the old structure but they won't be used anymore.\n" + "Storage place goes from dms-system:/exo:ecm/views/templates/Content List Viewer to " + "dms-system:/exo:ecm/views/templates/content-list-viewer\n" + "Please, read the WCM 2.1.2 Upgrade Notice or contact the eXo Support for more info."); } } } catch (Exception e) { if (LOG.isErrorEnabled()) LOG.error("An unexpected problem occurs when migrating templates to new structure", e); } finally { sessionProvider.close(); } } }
public void testTopic() throws Exception { Category cat = createCategory(getId(Utils.CATEGORY)); forumService_.saveCategory(cat, true); Forum forum = createdForum(); forumService_.saveForum(cat.getId(), forum, true); List<String> listTopicId = new ArrayList<String>(); // add 10 Topics List<Topic> list = new ArrayList<Topic>(); Topic topic; for (int i = 0; i < 10; i++) { topic = createdTopic("Owner"); list.add(topic); listTopicId.add(topic.getId()); forumService_.saveTopic(cat.getId(), forum.getId(), topic, true, false, new MessageBuilder()); } topic = list.get(8); // get Topic - topic in position 8 Topic topica = forumService_.getTopic(cat.getId(), forum.getId(), topic.getId(), ""); assertNotNull(topica); // get Topic by path topica = forumService_.getTopicByPath( cat.getId() + "/" + forum.getId() + "/" + topic.getId(), false); assertNotNull(topica); // update Topic topica.setIsSticky(true); topica.setTopicName("topic 8"); forumService_.saveTopic(cat.getId(), forum.getId(), topica, false, false, new MessageBuilder()); assertEquals( "This topic name not is 'topic 8'", "topic 8", forumService_.getTopic(cat.getId(), forum.getId(), topic.getId(), "").getTopicName()); // modifyTopic topica.setIsLock(true); list.clear(); list.add(topica); forumService_.modifyTopic(list, 2); topica = forumService_.getTopic(cat.getId(), forum.getId(), topic.getId(), ""); assertEquals("This topic is open.", topica.getIsLock(), true); // get PageList Topic JCRPageList pagelist = forumService_.getPageTopic(cat.getId(), forum.getId(), "", ""); assertEquals("Available all topics not equals 10.", pagelist.getAvailable(), 10); pagelist.setPageSize(5); List<Topic> listTopic = pagelist.getPage(1); assertEquals("Available page not equals 5", listTopic.size(), 5); assertEquals(pagelist.getAvailablePage(), 2); // get Topic By User topic = createdTopic("demo"); forumService_.saveTopic(cat.getId(), forum.getId(), topic, true, false, new MessageBuilder()); // We have 11 topic: 10 by Owner and 1 by demo pagelist = forumService_.getPageTopicByUser("Owner", true, ""); assertEquals(pagelist.getAvailable(), 10); // auto prune // set 5 topics for old Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(cal.getTimeInMillis() - 2 * 86400000); Node topicNode; for (Topic topic2 : listTopic) { topicNode = root_.getNode(topic2.getPath().replaceFirst("/", "")); topicNode.setProperty(ForumNodeTypes.EXO_LAST_POST_DATE, cal); topicNode.save(); } listTopic = forumService_.getAllTopicsOld(1, forum.getPath()); assertEquals( "Failed to run auto prune. List topic has size not equals 5.", listTopic.size(), 5); // move Topic // move topic from forum to forum 1 Forum forum1 = createdForum(); forumService_.saveForum(cat.getId(), forum1, true); forum1 = forumService_.getForum(cat.getId(), forum1.getId()); List<Topic> topics = new ArrayList<Topic>(); topics.add(topica); forumService_.moveTopic(topics, forum1.getPath(), "", ""); assertNotNull( "Failed to moved topic, topic is null.", forumService_.getTopic(cat.getId(), forum1.getId(), topica.getId(), "")); // test remove Topic return Topic // remove id topic moved in list topicIds. if (listTopicId.contains(topica.getId())) listTopicId.remove(topica.getId()); for (String topicId : listTopicId) { forumService_.removeTopic(cat.getId(), forum.getId(), topicId); } List<Topic> topics2 = forumService_.getTopics(cat.getId(), forum.getId()); assertEquals( "Topics in forum failed to remove. List topic has size more than 1.", topics2.size(), 1); }
/** * Test the persistence of a property modified with an multi-value Value parameter and saved from * the parent Node Requires a multi-value Value (mv2) */ public void testMultiValueParent() throws RepositoryException { property2.setValue(mv2); node.save(); assertEquals( "Node property not saved", Arrays.asList(mv2), Arrays.asList(property2.getValues())); }