/** * @see de.tudarmstadt.ukp.wikipedia.api.Category#Category(Wikipedia, long) */ private void createCategory(long id) throws WikiPageNotFoundException { Session session = this.wiki.__getHibernateSession(); session.beginTransaction(); hibernateCategory = catDAO.findById(id); session.getTransaction().commit(); if (hibernateCategory == null) { throw new WikiPageNotFoundException("No category with id " + id + " was found."); } }
private void fetchByPageId(int pageID) throws WikiApiException { Session session = this.wiki.__getHibernateSession(); session.beginTransaction(); hibernatePage = (de.tudarmstadt.ukp.wikipedia.api.hibernate.Page) session .createQuery("from Page where pageId = :id").setParameter("id", pageID, IntegerType.INSTANCE).uniqueResult(); session.getTransaction().commit(); if (hibernatePage == null) { throw new WikiPageNotFoundException("No page with page id " + pageID + " was found."); } }
throw new WikiPageNotFoundException("The article with the ID " + articleID + " was not found.");
throw new WikiPageNotFoundException("The article with the ID " + articleID + " was not found.");
throw new WikiPageNotFoundException("The revision with the ID " + revisionID + " was not found.");
/** * Gets the page ids for a given title with case insensitive matching.<br> * * * @param title The title of the page. * @return The ids of the pages with the given title. * @throws WikiApiException Thrown if errors occurred. */ public List<Integer> getPageIdsCaseInsensitive(String title) throws WikiApiException { title = title.toLowerCase(); title = title.replaceAll(" ", "_"); Session session = this.__getHibernateSession(); session.beginTransaction(); Iterator results = session.createQuery( "select p.pageID from PageMapLine as p where lower(p.name) = :pName").setParameter("pName", title, StringType.INSTANCE).list().iterator(); session.getTransaction().commit(); if(!results.hasNext()){ throw new WikiPageNotFoundException(); } List<Integer> resultList = new LinkedList<Integer>(); while(results.hasNext()){ resultList.add((Integer)results.next()); } return resultList; }
/** * Gets the page ids for a given title.<br> * * * @param title The title of the page. * @return The id for the page with the given title. * @throws WikiApiException Thrown if errors occurred. */ public List<Integer> getPageIds(String title) throws WikiApiException { Session session = this.__getHibernateSession(); session.beginTransaction(); Iterator results = session.createQuery( "select p.pageID from PageMapLine as p where p.name = :pName").setParameter("pName", title, StringType.INSTANCE).list().iterator(); session.getTransaction().commit(); if(!results.hasNext()){ throw new WikiPageNotFoundException(); } List<Integer> resultList = new LinkedList<Integer>(); while(results.hasNext()){ resultList.add((Integer)results.next()); } return resultList; }
/** * @throws WikiApiException Thrown if errors occurred. * @see de.tudarmstadt.ukp.wikipedia.api.Page */ private void fetchByHibernateId(long id) throws WikiApiException { Session session = this.wiki.__getHibernateSession(); session.beginTransaction(); hibernatePage = pageDAO.findById(id); session.getTransaction().commit(); if (hibernatePage == null) { throw new WikiPageNotFoundException("No page with id " + id + " was found."); } }
throw new WikiPageNotFoundException("The revision with the ID " + revisionID + " was not found.");
throw new WikiPageNotFoundException("The revision with the ID " + revisionID + " was not found.");
throw new WikiPageNotFoundException("The article with the ID " + articleID + " was not found.");
/** * Gets the {@link Category categories} for a given {@link Page} identified by its {@code pageTitle}. * @param pageTitle The title of a {@link Page}, not a category. * @return The category objects which are associated with the given {@code pageTitle}. * @throws WikiPageNotFoundException Thrown if no {@link Page} exists for the given {@code pageTitle}. */ public Set<Category> getCategories(String pageTitle) throws WikiPageNotFoundException { if (pageTitle == null || pageTitle.length() == 0) { throw new WikiPageNotFoundException(); } Session session = this.__getHibernateSession(); session.beginTransaction(); List<Integer> categoryHibernateIds = session.createQuery( "select c from Page p left join p.categories c where p.name = :pageTitle", Integer.class) .setParameter("pageTitle", pageTitle).list(); session.getTransaction().commit(); Set<Category> categorySet = new HashSet<Category>(categoryHibernateIds.size()); for (int hibernateId : categoryHibernateIds) { try { categorySet.add(new Category(this, hibernateId)); } catch (WikiPageNotFoundException e) { logger.warn("Could not load Category by it's HibernateId = '"+hibernateId+"'"); } } return categorySet; }
throw new WikiPageNotFoundException("The article with the ID " + articleID + " was not found.");
/** * Creates a category object. * @param wiki The wikipedia object. * @param pName The name of the category. * @throws WikiPageNotFoundException If the category does not exist. */ public Category(Wikipedia wiki, String pName) throws WikiApiException { if (pName == null || pName.length() == 0) { throw new WikiPageNotFoundException(); } this.wiki = wiki; catDAO = new CategoryDAO(wiki); Title catTitle = new Title(pName); createCategory(catTitle); }
throw new WikiPageNotFoundException("The article with the ID " + articleID + " was not found.");
throw new WikiPageNotFoundException("The article with the ID " + articleID + " was not found.");
/** * Creates a page object. * * @param wiki * The wikipedia object. * @param pName * The name of the page. * @param useExactTitle * Whether to use the exact title or try to guess the correct wiki-style title. * @throws WikiApiException Thrown if errors occurred. */ public Page(Wikipedia wiki, String pName, boolean useExactTitle) throws WikiApiException { if (pName == null || pName.length() == 0) { throw new WikiPageNotFoundException(); } this.wiki = wiki; this.pageDAO = new PageDAO(wiki); Title pageTitle = new Title(pName); fetchByTitle(pageTitle, useExactTitle); }
/** * Gets the title for a given pageId. * * @param pageId The id of the page. * @return The title for the given pageId. * @throws WikiApiException Thrown if errors occurred. */ public Title getTitle(int pageId) throws WikiApiException { Session session = this.__getHibernateSession(); session.beginTransaction(); Object returnValue = session.createNativeQuery( "select p.name from PageMapLine as p where p.pageId= :pId").setParameter("pId", pageId, IntegerType.INSTANCE).uniqueResult(); session.getTransaction().commit(); String title = (String)returnValue; if(title==null){ throw new WikiPageNotFoundException(); } return new Title(title); }
/** * @see de.tudarmstadt.ukp.wikipedia.api.Category#Category(Wikipedia, String) */ private void createCategory(Title title) throws WikiPageNotFoundException { String name = title.getWikiStyleTitle(); Session session = this.wiki.__getHibernateSession(); session.beginTransaction(); Object returnValue; String query = "select cat.pageId from Category as cat where cat.name = :name"; if(wiki.getDatabaseConfiguration().supportsCollation()) { query += Wikipedia.SQL_COLLATION; } returnValue = session.createNativeQuery(query) .setParameter("name", name, StringType.INSTANCE) .uniqueResult(); session.getTransaction().commit(); // if there is no category with this name, the hibernateCategory is null if (returnValue == null) { hibernateCategory = null; throw new WikiPageNotFoundException("No category with name " + name + " was found."); } else { // now cast it into an integer int pageID = (Integer) returnValue; createCategory( pageID); } }
throw new WikiPageNotFoundException("Not discussion page was available at the time of the given article revision");