Package de.zib.scalaris.examples.wikipedia.data

Examples of de.zib.scalaris.examples.wikipedia.data.Page


        Revision curRev = null;
        if (!revisions.isEmpty()) {
            curRev = revisions.lastEntry().getValue();
            curRev.setUnpackedText(lastRevText);
        }
        final_page = new Page(title,
                Integer.parseInt(id), redirect, restrictions_map, curRev);
    }
View Full Code Here


                    + getRevListKey(title, nsObject) + "\" from Scalaris: "
                    + e.getMessage(), e instanceof ConnectionException,
                    statName, System.currentTimeMillis() - timeAtStart);
        }
       
        Page page;
        try {
            page = results.processReadAt(0).jsonValue(Page.class);
        } catch (NotFoundException e) {
            PageHistoryResult result = new PageHistoryResult(
                    false,
View Full Code Here

     * @return a result object with the page and revision on success
     */
    public static RevisionResult getRevision(Connection connection,
            String title, int id, final MyNamespace nsObject) {
        final long timeAtStart = System.currentTimeMillis();
        Page page = null;
        Revision revision = null;
        if (connection == null) {
            return new RevisionResult(false, "no connection to Scalaris", true,
                    page, revision, false, false, title,
                    System.currentTimeMillis() - timeAtStart);
        }
       
        TransactionSingleOp scalaris_single;
        String scalaris_key;
       
        scalaris_single = new TransactionSingleOp(connection);

        scalaris_key = getPageKey(title, nsObject);
        try {
            page = scalaris_single.read(scalaris_key).jsonValue(Page.class);
        } catch (NotFoundException e) {
            return new RevisionResult(false, "page not found at \""
                    + scalaris_key + "\"", false, page, revision, true, false,
                    title, System.currentTimeMillis() - timeAtStart);
        } catch (Exception e) {
            return new RevisionResult(false, "unknown exception reading \""
                    + scalaris_key + "\" from Scalaris: " + e.getMessage(),
                    e instanceof ConnectionException, page, revision, false,
                    false, title, System.currentTimeMillis() - timeAtStart);
        }

        // load requested version if it is not the current one cached in the Page object
        if (id != page.getCurRev().getId() && id >= 0) {
            scalaris_key = getRevKey(title, id, nsObject);
            try {
                revision = scalaris_single.read(scalaris_key).jsonValue(Revision.class);
            } catch (NotFoundException e) {
                return new RevisionResult(false, "revision not found at \""
                        + scalaris_key + "\"", false, page, revision, false,
                        true, title, System.currentTimeMillis() - timeAtStart);
            } catch (Exception e) {
                return new RevisionResult(false, "unknown exception reading \""
                        + scalaris_key + "\" from Scalaris: " + e.getMessage(),
                        e instanceof ConnectionException, page, revision,
                        false, false, title, System.currentTimeMillis() - timeAtStart);
            }
        } else {
            revision = page.getCurRev();
        }

        return new RevisionResult(page, revision, title,
                System.currentTimeMillis() - timeAtStart);
    }
View Full Code Here

    public static SavePageResult savePage(final Connection connection, final String title0,
            final Revision newRev, final int prevRevId, final Map<String, String> restrictions,
            final SiteInfo siteinfo, final String username, final MyNamespace nsObject) {
        long timeAtStart = System.currentTimeMillis();
        final String statName = "saving " + title0;
        Page oldPage = null;
        Page newPage = null;
        List<ShortRevision> newShortRevs = null;
        BigInteger pageEdits = null;
        if (connection == null) {
            return new SavePageResult(false, "no connection to Scalaris", true,
                    oldPage, newPage, newShortRevs, pageEdits, statName,
                    System.currentTimeMillis() - timeAtStart);
        }
       
        String title = MyWikiModel.normalisePageTitle(title0, nsObject);
        Transaction scalaris_tx = new Transaction(connection);

        // check that the current version is still up-to-date:
        // read old version first, then write
        int oldRevId = -1;
        String pageInfoKey = getPageKey(title0, nsObject);
       
        Transaction.RequestList requests = new Transaction.RequestList();
        requests.addRead(pageInfoKey);
       
        Transaction.ResultList results;
        try {
            results = scalaris_tx.req_list(requests);
        } catch (Exception e) {
            return new SavePageResult(false,
                    "unknown exception getting page info (" + pageInfoKey
                            + ") from Scalaris: " + e.getMessage(),
                    e instanceof ConnectionException, oldPage, newPage,
                    newShortRevs, pageEdits, statName,
                    System.currentTimeMillis() - timeAtStart);
        }
       
        try {
            oldPage = results.processReadAt(0).jsonValue(Page.class);
            newPage = new Page(oldPage.getTitle(),
                    oldPage.getId(), oldPage.isRedirect(),
                    new LinkedHashMap<String, String>(
                            oldPage.getRestrictions()), newRev);
            oldRevId = oldPage.getCurRev().getId();
        } catch (NotFoundException e) {
            // this is ok and means that the page did not exist yet
            newPage = new Page();
            newPage.setTitle(title0);
            newPage.setCurRev(newRev);
        } catch (Exception e) {
            return new SavePageResult(false, "unknown exception reading \""
                    + pageInfoKey + "\" from Scalaris: " + e.getMessage(),
                    e instanceof ConnectionException, oldPage, newPage,
                    newShortRevs, pageEdits, statName,
                    System.currentTimeMillis() - timeAtStart);
        }
       
        if (!newPage.checkEditAllowed(username)) {
            return new SavePageResult(false,
                    "operation not allowed: edit is restricted", false,
                    oldPage, newPage, newShortRevs, pageEdits, statName,
                    System.currentTimeMillis() - timeAtStart);
        }
       
        if (prevRevId != oldRevId) {
            return new SavePageResult(false, "curRev(" + oldRevId
                    + ") != oldRev(" + prevRevId + ")", false, oldPage,
                    newPage, newShortRevs, pageEdits, statName,
                    System.currentTimeMillis() - timeAtStart);
        }

        // write:
        // get previous categories, templates and backlinks:
        final MyWikiModel wikiModel = new MyWikiModel("", "", new MyNamespace(siteinfo));
        wikiModel.setPageName(title0);
        Set<String> oldCats;
        Set<String> oldTpls;
        Set<String> oldLnks;
        if (oldRevId != -1 && oldPage != null && oldPage.getCurRev() != null) {
            // get a list of previous categories and templates:
            wikiModel.setUp();
            final long timeAtRenderStart = System.currentTimeMillis();
            wikiModel.render(null, oldPage.getCurRev().unpackedText());
            timeAtStart -= (System.currentTimeMillis() - timeAtRenderStart);
            // note: no need to normalise the pages, we will do so during the write/read key generation
            oldCats = wikiModel.getCategories().keySet();
            oldTpls = wikiModel.getTemplates();
            if (Options.WIKI_USE_BACKLINKS) {
                oldLnks = wikiModel.getLinks();
            } else {
                // use empty link lists to turn back-links off
                oldLnks = new HashSet<String>();
            }
            wikiModel.tearDown();
        } else {
            oldCats = new HashSet<String>();
            oldTpls = new HashSet<String>();
            oldLnks = new HashSet<String>();
        }
        // get new categories and templates
        wikiModel.setUp();
        do {
            final long timeAtRenderStart = System.currentTimeMillis();
            wikiModel.render(null, newRev.unpackedText());
            timeAtStart -= (System.currentTimeMillis() - timeAtRenderStart);
        } while (false);
        if (wikiModel.getRedirectLink() != null) {
            newPage.setRedirect(true);
        }
        if (restrictions != null) {
            newPage.setRestrictions(restrictions);
        }
       
        // note: do not tear down the wiki model - the following statements
        // still need it and it will be removed at the end of the method anyway
        // note: no need to normalise the pages, we will do so during the write/read key generation
View Full Code Here

     * @param page_xml
     *            the page object extracted from XML
     */
    @Override
    protected void export(XmlPage page_xml) {
        Page page = page_xml.getPage();
        ++pageCount;
       
        if (page.getCurRev() != null) {
            List<Revision> revisions = page_xml.getRevisions();
            List<ShortRevision> revisions_short = ShortRevision.fromRevisions(revisions);
            Collections.sort(revisions, Collections.reverseOrder(new byRevId()));
            Collections.sort(revisions_short, Collections.reverseOrder(new byShortRevId()));
   
            if (!revisions.isEmpty() && wikiModel != null) {
                wikiModel.setUp();
                wikiModel.setPageName(page.getTitle());
                wikiModel.render(null, revisions.get(0).unpackedText());
                for (String cat_raw: wikiModel.getCategories().keySet()) {
                    String category = wikiModel.getCategoryNamespace() + ":" + cat_raw;
                    List<String> catPages = newCategories.get(category);
                    if (catPages == null) {
                        catPages = new ArrayList<String>(UPDATE_PAGELIST_EVERY / 4);
                    }
                    catPages.add(page.getTitle());
                    newCategories.put(category, catPages);
                }
                for (String tpl_raw: wikiModel.getTemplates()) {
                    String template = wikiModel.getTemplateNamespace() + ":" + tpl_raw;
                    List<String> templatePages = newTemplates.get(template);
                    if (templatePages == null) {
                        templatePages = new ArrayList<String>(UPDATE_PAGELIST_EVERY / 4);
                    }
                    templatePages.add(page.getTitle());
                    newTemplates.put(template, templatePages);
                }
                for (String link: wikiModel.getLinks()) {
                    List<String> backLinks = newBackLinks.get(link);
                    if (backLinks == null) {
                        backLinks = new ArrayList<String>(UPDATE_PAGELIST_EVERY / 4);
                    }
                    backLinks.add(page.getTitle());
                    newBackLinks.put(link, backLinks);
                }
                wikiModel.tearDown();
            }
   
View Full Code Here

            while (true) {
                result = savePage(connection, title, newRev, oldVersion, null, siteinfo, "", namespace);
                page.addStats(result.stats);
                if (!result.success && retries < Options.WIKI_SAVEPAGE_RETRIES) {
                    // check for conflicting edit on same page, do not retry in this case
                    final Page oldPage = result.oldPage;
                    if (oldPage != null && oldPage.getCurRev().getId() != oldVersion) {
                        break;
                    }
                    try {
                        Thread.sleep(Options.WIKI_SAVEPAGE_RETRY_DELAY);
                    } catch (InterruptedException e) {
View Full Code Here

     * @param page_xml
     *            the page object extracted from XML
     */
    @Override
    protected void export(XmlPage page_xml) {
        Page page = page_xml.getPage();

        if (page.getCurRev() != null && wikiModel != null) {
            wikiModel.setUp();
            final String pageTitle = page.getTitle();
            wikiModel.setPageName(pageTitle);
            wikiModel.render(null, page.getCurRev().unpackedText());
           
            // categories:
            do {
                final Set<String> pageCategories_raw = wikiModel.getCategories().keySet();
                ArrayList<String> pageCategories = new ArrayList<String>(pageCategories_raw.size());
View Full Code Here

TOP

Related Classes of de.zib.scalaris.examples.wikipedia.data.Page

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.