/** * @deprecated since 5.0 use {@link NodeTypes.RenderableMixin#getTemplate(Node)} */ public static String getTemplate(Node node) { return getMetaData(node).getTemplate(); }
MetaDataUtil.updateMetaData(node); node.setProperty("text", text.toString()); node.setProperty("script", true);
/** * The empty area nodes are created automatically in new instances. */ private void createEmptyAreas(Node page) throws RepositoryException { String templateName = MetaDataUtil.getTemplate(page); Map<String, String> areas = this.getPersistentMapService().getCustomMap(PersistentMapConstant.DEFAULT_AREAS_MAP); if (areas.containsKey(templateName)) { String[] defaultAreas = areas.get(templateName).split(","); for (String areaName : defaultAreas) { if (!StringUtils.isBlank(areaName)) { MigrationUtil.getOrCreateNode(page, areaName.trim(), MgnlNodeType.NT_AREA); } } } } }
try MetaDataUtil.updateMetaData(newContent); MetaDataUtil.getMetaData(newContent).setUnActivated();
/** * {@inheritDoc} */ @SuppressWarnings("unchecked") @Override protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException { Criteria criteria = JCRCriteriaFactory .createCriteria() .setWorkspace(RepositoryConstants.WEBSITE) .add(Restrictions.eq("@jcr:primaryType", MgnlNodeType.NT_COMPONENT)) .add(Restrictions.eq("MetaData/mgnl:template", actualTemplate)) .addOrder(Order.desc("@jcr:score")); log.debug("Running query: {}", criteria.toXpathExpression()); AdvancedResult result = criteria.execute(); for (AdvancedResultItem page : result.getItems()) { log.warn("Replacing template {} with {} in {}", new Object[]{ MetaDataUtil.getTemplate(page), newTemplate, page.getHandle() }); MetaDataUtil.getMetaData(page).setTemplate(newTemplate); } }
@Test public void testUpdateMetaData() throws Exception { // GIVEN final String testUserName = "test"; final Context ctx = mock(Context.class); final User user = mock(User.class); MgnlContext.setInstance(ctx); when(ctx.getUser()).thenReturn(user); when(user.getName()).thenReturn(testUserName); MetaData metaData = MetaDataUtil.getMetaData(testNode); // WHEN MetaDataUtil.updateMetaData(testNode); // THEN Date lastMod = metaData.getModificationDate().getTime(); long diff = System.currentTimeMillis() - lastMod.getTime(); assertTrue("lastMod hast not been updated in the last 500ms - it was only " + diff + "ms!", diff < 500); assertEquals(testUserName, metaData.getAuthorId()); }
/** * {@inheritDoc} */ @SuppressWarnings("unchecked") @Override protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException { Criteria criteria = JCRCriteriaFactory .createCriteria() .setWorkspace(RepositoryConstants.WEBSITE) .add(Restrictions.eq("@jcr:primaryType", MgnlNodeType.NT_PAGE)) .add(Restrictions.not(Restrictions.eq("MetaData/mgnl:template", actualTemplate))) .addOrder(Order.desc("@jcr:score")); log.debug("Running query: {}", criteria.toXpathExpression()); AdvancedResult result = criteria.execute(); for (AdvancedResultItem page : result.getItems()) { log.warn("Replacing template {} with {} in {}", new Object[]{ MetaDataUtil.getTemplate(page), newTemplate, page.getHandle() }); MetaDataUtil.getMetaData(page).setTemplate(newTemplate); } } }
/** * Return iconFileName for a node. * * @param node node to read status from * @return file name for an icon */ public static String getActivationStatusIcon(Node node) { MetaData metaData = info.magnolia.jcr.util.MetaDataUtil.getMetaData(node); String iconFileName; switch (metaData.getActivationStatus()) { case MetaData.ACTIVATION_STATUS_MODIFIED: iconFileName = "indicator_yellow.gif"; break; case MetaData.ACTIVATION_STATUS_ACTIVATED: iconFileName = "indicator_green.gif"; break; default: iconFileName = "indicator_red.gif"; } return iconFileName; }
Node page = session.getNode(handle); session.removeItem(nodePath); MetaDataUtil.updateMetaData(page); session.save(); } catch (RepositoryException e) { MetaDataUtil.updateMetaData(page); session.save(); } catch (RepositoryException e) {
/** * Renames main node in "content". * @param page Page node to transform. */ private void transformMainNode(Node page) throws RepositoryException { if(page.hasNode("main")) { NodeIterator nodes = page.getNode("main").getNodes(); while (nodes.hasNext()) { Node component = nodes.nextNode(); if (this.blacklist != null) { for (String black : this.blacklist) { if (MetaDataUtil.getTemplate(component).endsWith(black)) { reportSystem("Skipping migration of " + page.getPath() + ": template " + black + " blacklisted."); //skip return; } } } } if(!page.hasNode("content")){ reportSystem("Renaming and merging from '"+page.getNode("main").getPath()+"' to 'content'"); MigrationUtil.renameAndMergeNodes(page.getNode("main"), "content", false, true); } else{ reportRequestUserAction("!! Page "+page.getPath()+" with node called 'content' already exists. Please cleanup your content first. STK now uses a node called 'content'."); } } else{ reportRequestUserAction("!! Page "+page.getPath()+" has no 'main' area. Check if migration has already been run on this page."); } }
private void updateTemplate(Node node, Map<String, String> templateIdMap) throws RepositoryException { MetaData meta = MetaDataUtil.getMetaData(node); String template = meta.getTemplate(); if (StringUtils.isNotEmpty(template) && templateIdMap.containsKey(template)) { String newTemplate = templateIdMap.get(template); meta.setTemplate(newTemplate); reportDebug("Updating " + node.getPath() + ": old template " + template + " replaced by " + newTemplate); } else if (StringUtils.isNotEmpty(template)) { reportSystem("Unknown template name (" + template + ") at " + node.getPath() + ". Leaving unchanged."); } if (savePartiallyMigratedContent()) { // save immediately to lower amount of nodes in memory that needs to be evaluated on saving single page conversions node.getSession().save(); } }
@Override public void visit(Node node) throws RepositoryException { String nodePrimaryType = node.getPrimaryNodeType().getName(); if (MgnlNodeType.NT_PAGE.equals(nodePrimaryType)) { updateTemplate(node, getPersistentMapService().getPagesMap()); } else if (MgnlNodeType.NT_COMPONENT.equals(nodePrimaryType)) { updateTemplate(node, getPersistentMapService().getComponentsMap()); } else if (MgnlNodeType.NT_AREA.equals(nodePrimaryType)) { // areas shouldnt have a template String template = MetaDataUtil.getTemplate(node); if (StringUtils.isNotEmpty(template)) { reportRequestUserAction("Area " + node.getName() + " has a template. If correct, verify this node --> " + node.getPath()); } } else { // for all the other types - this should be the case of modules that do not provide // templating updateTemplate(node, getPersistentMapService().getAllTemplatesMap()); } } };
MetaData metaData = MetaDataUtil.getMetaData(paragraph); if (StringUtils.isEmpty(metaData.getTemplate()))
/** * Returns the new type (page, component or area). * Content -> Page. * Content node -> Area (if content has no template). * Content node -> Component (if content has a template). * */ private String getNewType(Node node) throws RepositoryException { String oldType = node.getPrimaryNodeType().getName(); if(MgnlNodeType.NT_CONTENT.equals(oldType)) { return MgnlNodeType.NT_PAGE; }else { if(StringUtils.isEmpty(MetaDataUtil.getTemplate(node))){ if (isMultiselect(node)) { return MgnlNodeType.NT_CONTENTNODE; } else { return MgnlNodeType.NT_AREA; } } else{ return MgnlNodeType.NT_COMPONENT; } } }
public String save() { success = false; Node node = NodeUtilsExt.getNodeByIdOrPath(PlaylistConstants.REPO, path); if (node != null) { try { node.setProperty("title", title); node.setProperty("description", description); if (MediaEl.module().isSingleinstance()) { MetaDataUtil.getMetaData(node).setActivated(); } node.getSession().save(); success = true; } catch (RepositoryException e) { } } return VIEW_EXTJS; }
String template = MetaDataUtil.getTemplate(page);
if (MediaEl.module().isSingleinstance() && !MetaDataUtil.getMetaData(currContent).getIsActivated()) MetaDataUtil.getMetaData(currContent).setActivated();
private void updateSinglePage(Session session, Node node) throws RepositoryException { String nodePrimaryType = node.getPrimaryNodeType().getName(); if (MgnlNodeType.NT_PAGE.equals(nodePrimaryType)) { updateTemplate(node, getPersistentMapService().getPagesMap()); NodeIterator children = new FilteringNodeIterator(node.getNodes(), new NodeTypePredicate(MgnlNodeType.NT_CONTENTNODE, false)); while(children.hasNext()){ updateSinglePage(session, children.nextNode()); } } else if (MgnlNodeType.NT_COMPONENT.equals(nodePrimaryType)) { updateTemplate(node, getPersistentMapService().getComponentsMap()); } else if (MgnlNodeType.NT_AREA.equals(nodePrimaryType)) { String template = MetaDataUtil.getTemplate(node); if (StringUtils.isNotEmpty(template)) { reportRequestUserAction("Area " + node.getName() + " has a template... This is incorrect !! Verify this node --> " + node.getPath()); } } else { // for all the other types - this should be the case of modules provinding no templating updateTemplate(node, getPersistentMapService().getAllTemplatesMap()); } if (savePartiallyMigratedContent()) { // save immediately to lower amount of nodes in memory that needs to be evaluated on saving single page conversions session.save(); } } }
public String saveMedia() { success = false; Node node = NodeUtilsExt.getNodeByIdOrPath(MediaModule.REPO, mediaHandle); if (node != null) { try { node.setProperty("title", title); node.setProperty("description", description); if (MediaEl.module().isSingleinstance()) { MetaDataUtil.getMetaData(node).setActivated(); } node.getSession().save(); success = true; } catch (RepositoryException e) { } } return VIEW_EXTJS; }
/** * The transformation of the footer is not correctly handled by the default migration. It is transform as a component but must be an area. */ private void transformFooter(Node page) throws PathNotFoundException, RepositoryException{ if(page.hasNode("footer")) { Node node = page.getNode("footer"); String type = MgnlNodeType.NT_AREA; node.setPrimaryType(type); reportSystem("Changing Node Type from "+node.getPrimaryNodeType().getName()+" to "+type+" for the following node: "+node.getPath()); // Area has no template try { MetaDataUtil.getMetaData(node).removeProperty("mgnl:template"); } catch (PathNotFoundException e) { // ignore - mgnl:template could be missing in some cases. } reportRequestUserAction("The node "+node.getPath()+" was identified as a STK footer area." +"It has been transform into an area. Please double check that it is used as a STK footer area."); } }