@Override protected void doImportStagedModel(PortletDataContext portletDataContext, WikiNode node) throws Exception { long userId = portletDataContext.getUserId(node.getUserUuid()); ServiceContext serviceContext = portletDataContext.createServiceContext(node); WikiNode importedNode = null; if (portletDataContext.isDataStrategyMirror()) { WikiNode existingNode = WikiNodeLocalServiceUtil.fetchNodeByUuidAndGroupId( node.getUuid(), portletDataContext.getScopeGroupId()); String initialNodeName = PropsValues.WIKI_INITIAL_NODE_NAME; if ((existingNode == null) && initialNodeName.equals(node.getName())) { WikiNode initialNode = WikiNodeLocalServiceUtil.fetchNode( portletDataContext.getScopeGroupId(), node.getName()); if (initialNode != null) { WikiNodeLocalServiceUtil.deleteWikiNode(initialNode); } } if (existingNode == null) { serviceContext.setUuid(node.getUuid()); importedNode = WikiNodeLocalServiceUtil.addNode( userId, node.getName(), node.getDescription(), serviceContext); } else { importedNode = WikiNodeLocalServiceUtil.updateNode( existingNode.getNodeId(), node.getName(), node.getDescription(), serviceContext); } } else { String initialNodeName = PropsValues.WIKI_INITIAL_NODE_NAME; if (initialNodeName.equals(node.getName())) { WikiNode initialNode = WikiNodeLocalServiceUtil.fetchNode( portletDataContext.getScopeGroupId(), node.getName()); if (initialNode != null) { WikiNodeLocalServiceUtil.deleteWikiNode(initialNode); } } String nodeName = getNodeName(portletDataContext, node, node.getName(), 2); importedNode = WikiNodeLocalServiceUtil.addNode(userId, nodeName, node.getDescription(), serviceContext); } portletDataContext.importClassedModel(node, importedNode); }
protected String getNodeName( PortletDataContext portletDataContext, WikiNode node, String name, int count) throws Exception { WikiNode existingNode = WikiNodeLocalServiceUtil.fetchNode(portletDataContext.getScopeGroupId(), name); if (existingNode == null) { return name; } String nodeName = node.getName(); return getNodeName( portletDataContext, node, nodeName.concat(StringPool.SPACE).concat(String.valueOf(count)), ++count); }