Search in sources :

Example 1 with XWikiRCSNodeId

use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeId in project xwiki-platform by xwiki.

the class XWikiDocumentArchive method updateArchive.

/**
 * Update history with new document version.
 *
 * @param doc - document for this version
 * @param author - author of version
 * @param date - date of version
 * @param comment - version comment
 * @param version - preferably document version in history
 * @param context - used for loading nodes content
 * @throws XWikiException in any error
 */
public void updateArchive(XWikiDocument doc, String author, Date date, String comment, Version version, XWikiContext context) throws XWikiException {
    Version oldLatestVer = getLatestVersion();
    Version newVer = version;
    if (newVer == null || oldLatestVer != null && newVer.compareVersions(oldLatestVer) <= 0) {
        newVer = createNextVersion(oldLatestVer, doc.isMinorEdit());
    }
    XWikiRCSNodeInfo newNode = new XWikiRCSNodeInfo(new XWikiRCSNodeId(getId(), newVer));
    newNode.setAuthor(author);
    newNode.setComment(comment);
    newNode.setDate(date);
    XWikiRCSNodeContent newContent = makePatch(newNode, doc, context);
    updateNode(newNode);
    this.updatedNodeInfos.add(newNode);
    this.updatedNodeContents.add(newContent);
}
Also used : XWikiRCSNodeContent(com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent) Version(org.suigeneris.jrcs.rcs.Version) XWikiRCSNodeInfo(com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo) XWikiRCSNodeId(com.xpn.xwiki.doc.rcs.XWikiRCSNodeId)

Example 2 with XWikiRCSNodeId

use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeId in project xwiki-platform by xwiki.

the class PageHistoryResourceImpl method getPageHistory.

@Override
public History getPageHistory(String wikiName, String spaceName, String pageName, Integer start, Integer number, String order, Boolean withPrettyNames) throws XWikiRestException {
    List<String> spaces = parseSpaceSegments(spaceName);
    String spaceId = Utils.getLocalSpaceId(spaces);
    History history = new History();
    try {
        // Note that the query is made to work with Oracle which treats empty strings as null.
        String query = String.format("select doc.space, doc.name, rcs.id, rcs.date, rcs.author, rcs.comment" + " from XWikiRCSNodeInfo as rcs, XWikiDocument as doc where rcs.id.docId = doc.id and" + " doc.space = :space and doc.name = :name and (doc.language = '' or doc.language is null)" + " 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("space", spaceId).bindValue("name", pageName).setLimit(number).setOffset(start).setWiki(wikiName).execute();
        for (Object object : queryResult) {
            Object[] fields = (Object[]) object;
            XWikiRCSNodeId nodeId = (XWikiRCSNodeId) fields[2];
            Timestamp timestamp = (Timestamp) fields[3];
            Date modified = new Date(timestamp.getTime());
            String modifier = (String) fields[4];
            String comment = (String) fields[5];
            HistorySummary historySummary = DomainObjectFactory.createHistorySummary(objectFactory, uriInfo.getBaseUri(), wikiName, spaces, pageName, null, nodeId.getVersion(), modifier, modified, comment, Utils.getXWikiApi(componentManager), withPrettyNames);
            history.getHistorySummaries().add(historySummary);
        }
    } catch (QueryException e) {
        throw new XWikiRestException(e);
    }
    return history;
}
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 3 with XWikiRCSNodeId

use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeId in project xwiki-platform by xwiki.

the class PageTranslationHistoryResourceImpl method getPageTranslationHistory.

@Override
public History getPageTranslationHistory(String wikiName, String spaceName, String pageName, String language, Integer start, Integer number, String order, Boolean withPrettyNames) throws XWikiRestException {
    List<String> spaces = parseSpaceSegments(spaceName);
    String spaceId = Utils.getLocalSpaceId(spaces);
    History history = new History();
    try {
        String query = String.format("select doc.space, doc.name, rcs.id, rcs.date, rcs.author, rcs.comment" + " from XWikiRCSNodeInfo as rcs, XWikiDocument as doc where rcs.id.docId = doc.id and" + " doc.space = :space and doc.name = :name and doc.language = :language" + " 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("space", spaceId).bindValue("name", pageName).setLimit(number).bindValue("language", language).setOffset(start).setWiki(wikiName).execute();
        for (Object object : queryResult) {
            Object[] fields = (Object[]) object;
            XWikiRCSNodeId nodeId = (XWikiRCSNodeId) fields[2];
            Timestamp timestamp = (Timestamp) fields[3];
            Date modified = new Date(timestamp.getTime());
            String modifier = (String) fields[4];
            String comment = (String) fields[5];
            HistorySummary historySummary = DomainObjectFactory.createHistorySummary(objectFactory, uriInfo.getBaseUri(), wikiName, spaces, pageName, language, nodeId.getVersion(), modifier, modified, comment, Utils.getXWikiApi(componentManager), withPrettyNames);
            history.getHistorySummaries().add(historySummary);
        }
    } catch (QueryException e) {
        throw new XWikiRestException(e);
    }
    return history;
}
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 4 with XWikiRCSNodeId

use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeId 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)

Aggregations

XWikiRCSNodeId (com.xpn.xwiki.doc.rcs.XWikiRCSNodeId)4 Timestamp (java.sql.Timestamp)3 Date (java.util.Date)3 QueryException (org.xwiki.query.QueryException)3 XWikiRestException (org.xwiki.rest.XWikiRestException)3 History (org.xwiki.rest.model.jaxb.History)3 HistorySummary (org.xwiki.rest.model.jaxb.HistorySummary)3 XWikiRCSNodeContent (com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent)1 XWikiRCSNodeInfo (com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo)1 Version (org.suigeneris.jrcs.rcs.Version)1