public void runOrganizer()

in src/main/java/com/atlassian/uwc/ui/organizer/customorganizations/MakeParentHomePageOrganizer.java [30:89]


    public void runOrganizer() {
        Logger log = Logger.getLogger(this.getClass().getName());
        // pop up window to say 'are you sure you want to do this'?
        // it cannot be undone, backup your data!
        String message = "The parent of all parentless pages in the space \nwill have their parent set to the home page. \nPlease backup before conducting this operation. \nThis operation cannot be undone. \n\nAre you absolutely sure you want to do this?";
        JTextArea text = new JTextArea(message);
        text.setWrapStyleWord(true);
        JScrollPane scroll = new JScrollPane(text);
        scroll.setPreferredSize(new Dimension(200, 100));
        int choice = JOptionPane.showInternalConfirmDialog(UWCForm2.getInstance().getMainPanel(),
                text,
                "information",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE);
        if (choice != JOptionPane.YES_OPTION) {
            return;
        }

        // get home page info
        ConfluenceServerSettings cs = OrganizerUtils.getInstance().getConfluenceSettings();
        RemoteWikiBroker rwb = RemoteWikiBroker.getInstance();
        String homePageId = null;
		try {
			homePageId = rwb.getSpaceHomePageId(cs, cs.spaceKey);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (XmlRpcException e) {
			e.printStackTrace();
		}

        // get all pages
        Map<String, PageForXmlRpc> allPagesMap = null;
		try {
			allPagesMap = rwb.getAllServerPagesMapById(cs, cs.spaceKey);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (XmlRpcException e) {
			e.printStackTrace();
		}
        Collection pages = allPagesMap.values();
        // iterate through and point those without parents at the home page
        int totalPages = pages.size();
        int count=0;
        for (Object page : pages) {
            PageForXmlRpc pageForXmlRpc = (PageForXmlRpc) page;
            if (pageForXmlRpc.getParentId() == null || pageForXmlRpc.getParentId().equals("0")) {
                count++; log.info("re-parenting page "+count+"/"+totalPages);
                pageForXmlRpc.setParentId(homePageId);
                // send the pages to Confluence
                try {
					rwb.storeNewOrUpdatePage(cs, cs.spaceKey, pageForXmlRpc);
				} catch (IOException e) {
					e.printStackTrace();
				} catch (XmlRpcException e) {
					e.printStackTrace();
				}
            }
        }

    }