Search in sources :

Example 6 with HistorySummary

use of org.xwiki.rest.model.jaxb.HistorySummary in project xwiki-platform by xwiki.

the class ModificationsResourceImpl method getModifications.

@Override
public History getModifications(String wikiName, Integer start, Integer number, String order, Long ts, Boolean withPrettyNames) throws XWikiRestException {
    try {
        History history = new History();
        String query = String.format("select doc.space, doc.name, doc.language, rcs.id, rcs.date, rcs.author," + " rcs.comment from XWikiRCSNodeInfo as rcs, XWikiDocument as doc where rcs.id.docId = doc.id and" + " rcs.date > :date order by rcs.date %s, rcs.id.version1 %s, rcs.id.version2 %s", order, order, order);
        List<Object> queryResult = null;
        queryResult = queryManager.createQuery(query, Query.XWQL).bindValue("date", new Date(ts)).setLimit(number).setOffset(start).setWiki(wikiName).execute();
        for (Object object : queryResult) {
            Object[] fields = (Object[]) object;
            String spaceId = (String) fields[0];
            List<String> spaces = Utils.getSpacesFromSpaceId(spaceId);
            String pageName = (String) fields[1];
            String language = (String) fields[2];
            if (language.equals("")) {
                language = null;
            }
            XWikiRCSNodeId nodeId = (XWikiRCSNodeId) fields[3];
            Timestamp timestamp = (Timestamp) fields[4];
            Date modified = new Date(timestamp.getTime());
            String modifier = (String) fields[5];
            String comment = (String) fields[6];
            HistorySummary historySummary = DomainObjectFactory.createHistorySummary(objectFactory, uriInfo.getBaseUri(), wikiName, spaces, pageName, language, nodeId.getVersion(), modifier, modified, comment, Utils.getXWikiApi(componentManager), withPrettyNames);
            history.getHistorySummaries().add(historySummary);
        }
        return history;
    } catch (QueryException e) {
        throw new XWikiRestException(e);
    }
}
Also used : QueryException(org.xwiki.query.QueryException) XWikiRestException(org.xwiki.rest.XWikiRestException) HistorySummary(org.xwiki.rest.model.jaxb.HistorySummary) XWikiRCSNodeId(com.xpn.xwiki.doc.rcs.XWikiRCSNodeId) History(org.xwiki.rest.model.jaxb.History) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Example 7 with HistorySummary

use of org.xwiki.rest.model.jaxb.HistorySummary in project xwiki-platform by xwiki.

the class DomainObjectFactory method createHistorySummary.

public static HistorySummary createHistorySummary(ObjectFactory objectFactory, URI baseUri, String wikiName, List<String> spaces, String pageName, String language, Version version, String modifier, Date modified, String comment, XWiki xwikiApi, Boolean withPrettyNames) {
    HistorySummary historySummary = objectFactory.createHistorySummary();
    String pageId = Utils.getPageId(wikiName, spaces, pageName);
    historySummary.setPageId(pageId);
    historySummary.setWiki(wikiName);
    historySummary.setSpace(Utils.getLocalSpaceId(spaces));
    historySummary.setName(pageName);
    historySummary.setVersion(version.toString());
    historySummary.setMajorVersion(version.at(0));
    historySummary.setMinorVersion(version.at(1));
    historySummary.setComment(comment);
    historySummary.setModifier(modifier);
    if (withPrettyNames) {
        historySummary.setModifierName(xwikiApi.getUserName(modifier, false));
    }
    historySummary.setLanguage(language);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(modified);
    historySummary.setModified(calendar);
    if (language == null) {
        String pageUri = uri(baseUri, PageVersionResource.class, wikiName, spaces, pageName, version);
        Link pageLink = objectFactory.createLink();
        pageLink.setHref(pageUri);
        pageLink.setRel(Relations.PAGE);
        historySummary.getLinks().add(pageLink);
    } else {
        String pageUri = uri(baseUri, PageTranslationVersionResource.class, wikiName, spaces, pageName, language, version);
        Link pageLink = objectFactory.createLink();
        pageLink.setHref(pageUri);
        pageLink.setRel(Relations.PAGE);
        historySummary.getLinks().add(pageLink);
    }
    return historySummary;
}
Also used : Calendar(java.util.Calendar) HistorySummary(org.xwiki.rest.model.jaxb.HistorySummary) Link(org.xwiki.rest.model.jaxb.Link)

Aggregations

HistorySummary (org.xwiki.rest.model.jaxb.HistorySummary)7 History (org.xwiki.rest.model.jaxb.History)6 XWikiRCSNodeId (com.xpn.xwiki.doc.rcs.XWikiRCSNodeId)3 Timestamp (java.sql.Timestamp)3 Date (java.util.Date)3 GetMethod (org.apache.commons.httpclient.methods.GetMethod)3 Test (org.junit.Test)3 QueryException (org.xwiki.query.QueryException)3 XWikiRestException (org.xwiki.rest.XWikiRestException)3 Page (org.xwiki.rest.model.jaxb.Page)3 PageHistoryResource (org.xwiki.rest.resources.pages.PageHistoryResource)3 AbstractHttpTest (org.xwiki.test.rest.framework.AbstractHttpTest)3 Calendar (java.util.Calendar)1 Link (org.xwiki.rest.model.jaxb.Link)1 Translation (org.xwiki.rest.model.jaxb.Translation)1