/** * 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); } } } } }
/** * 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."); } }
@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()); } } };
/** * 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; } } }
String template = MetaDataUtil.getTemplate(page);
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(); } } }
/** * {@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); } }
/** * {@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); } } }