Search in sources :

Example 11 with XWikiException

use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.

the class WikiSkinUtils method getSkinDocument.

public XWikiDocument getSkinDocument(String skin) {
    XWikiContext xcontext = this.xcontextProvider.get();
    if (xcontext != null) {
        DocumentReference skinReference = this.currentMixedDocumentReferenceResolver.resolve(skin);
        XWiki xwiki = xcontext.getWiki();
        if (xwiki != null && xwiki.getStore() != null) {
            XWikiDocument doc;
            try {
                doc = xwiki.getDocument(skinReference, xcontext);
            } catch (XWikiException e) {
                this.logger.error("Faied to get document [{}]", skinReference, e);
                return null;
            }
            if (!doc.isNew()) {
                return doc;
            }
        }
    }
    return null;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiException(com.xpn.xwiki.XWikiException)

Example 12 with XWikiException

use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.

the class XClassMigratorListener method migrate.

private void migrate(PropertyClass newPropertyClass) throws QueryException {
    ClassPropertyReference propertyReference = newPropertyClass.getReference();
    EntityReference classReference = propertyReference.extractReference(EntityType.DOCUMENT);
    EntityReference wikiReference = propertyReference.extractReference(EntityType.WIKI);
    // Get all document containing object of modified class
    Query query = this.queryManager.createQuery("from doc.object(" + this.localSerializer.serialize(classReference) + ") as obj", Query.XWQL);
    query.setWiki(wikiReference.getName());
    List<String> documents = query.execute();
    if (!documents.isEmpty()) {
        XWikiContext xcontext = this.xcontextProvider.get();
        String currentWikiId = xcontext.getWikiId();
        try {
            // Switch to class wiki to be safer
            xcontext.setWikiId(wikiReference.getName());
            for (String documentName : documents) {
                try {
                    migrate(newPropertyClass, documentName, xcontext);
                } catch (XWikiException e) {
                    this.logger.error("Failed to migrate property [{}] in document [{}]", propertyReference, documentName, xcontext);
                }
            }
        } finally {
            // Restore context wiki
            xcontext.setWikiId(currentWikiId);
        }
    }
}
Also used : Query(org.xwiki.query.Query) EntityReference(org.xwiki.model.reference.EntityReference) XWikiContext(com.xpn.xwiki.XWikiContext) ClassPropertyReference(org.xwiki.model.reference.ClassPropertyReference) XWikiException(com.xpn.xwiki.XWikiException)

Example 13 with XWikiException

use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.

the class ActionExecutionEventConverter method fromRemote.

@Override
public boolean fromRemote(RemoteEventData remoteEvent, LocalEventData localEvent) {
    if (remoteEvent.getEvent() instanceof ActionExecutedEvent || remoteEvent.getEvent() instanceof ActionExecutingEvent) {
        // fill the local event
        XWikiContext xcontext = unserializeXWikiContext(remoteEvent.getData());
        try {
            if (xcontext != null) {
                localEvent.setSource(unserializeDocument(remoteEvent.getSource()));
                localEvent.setData(xcontext);
                localEvent.setEvent((Event) remoteEvent.getEvent());
            }
        } catch (XWikiException e) {
            this.logger.error("Failed to convert remote event [{}]", remoteEvent, e);
        }
        return true;
    }
    return false;
}
Also used : ActionExecutedEvent(org.xwiki.bridge.event.ActionExecutedEvent) XWikiContext(com.xpn.xwiki.XWikiContext) ActionExecutingEvent(org.xwiki.bridge.event.ActionExecutingEvent) XWikiException(com.xpn.xwiki.XWikiException)

Example 14 with XWikiException

use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.

the class DocumentEventConverter method fromRemote.

@Override
public boolean fromRemote(RemoteEventData remoteEvent, LocalEventData localEvent) {
    if (EVENTS.contains(remoteEvent.getEvent().getClass())) {
        // fill the local event
        XWikiContext xcontext = unserializeXWikiContext(remoteEvent.getData());
        try {
            if (xcontext != null) {
                localEvent.setData(xcontext);
                localEvent.setEvent((Event) remoteEvent.getEvent());
                if (remoteEvent.getEvent() instanceof DocumentDeletedEvent) {
                    localEvent.setSource(unserializeDeletdDocument(remoteEvent.getSource(), xcontext));
                } else {
                    localEvent.setSource(unserializeDocument(remoteEvent.getSource()));
                }
            }
        } catch (XWikiException e) {
            this.logger.error("Failed to convert remote event [{}]", remoteEvent, e);
        }
        return true;
    }
    return false;
}
Also used : DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException)

Example 15 with XWikiException

use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.

the class AbstractSheetBinder method bind.

private boolean bind(DocumentModelBridge document, String sheetReferenceString) {
    EntityReference sheetBindingClassReference = this.relativeReferenceResolver.resolve(getSheetBindingClass(), EntityType.DOCUMENT);
    List<BaseObject> sheetBindingObjects = ((XWikiDocument) document).getXObjects(sheetBindingClassReference);
    if (sheetBindingObjects != null) {
        for (BaseObject sheetBindingObject : sheetBindingObjects) {
            // The list of XWiki objects can contain null values due to a design flaw in the old XWiki core.
            if (sheetBindingObject != null) {
                String boundSheetStringRef = sheetBindingObject.getStringValue(SHEET_PROPERTY);
                if (StringUtils.equals(boundSheetStringRef, sheetReferenceString)) {
                    return false;
                }
            }
        }
    }
    try {
        BaseObject sheetBindingObject = ((XWikiDocument) document).newXObject(sheetBindingClassReference, getXWikiContext());
        sheetBindingObject.setStringValue(SHEET_PROPERTY, sheetReferenceString);
    } catch (XWikiException e) {
        String docStringReference = this.defaultEntityReferenceSerializer.serialize(document.getDocumentReference());
        this.logger.warn("Failed to bind sheet [{}] to document [{}].", sheetReferenceString, docStringReference);
        return false;
    }
    return true;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) EntityReference(org.xwiki.model.reference.EntityReference) XWikiException(com.xpn.xwiki.XWikiException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Aggregations

XWikiException (com.xpn.xwiki.XWikiException)442 XWikiContext (com.xpn.xwiki.XWikiContext)156 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)147 DocumentReference (org.xwiki.model.reference.DocumentReference)98 BaseObject (com.xpn.xwiki.objects.BaseObject)88 IOException (java.io.IOException)57 QueryException (org.xwiki.query.QueryException)57 ArrayList (java.util.ArrayList)56 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)51 XWiki (com.xpn.xwiki.XWiki)48 XWikiRestException (org.xwiki.rest.XWikiRestException)44 Session (org.hibernate.Session)42 Document (com.xpn.xwiki.api.Document)38 InitializationException (org.xwiki.component.phase.InitializationException)36 WebApplicationException (javax.ws.rs.WebApplicationException)32 SQLException (java.sql.SQLException)31 ObjectNotFoundException (org.hibernate.ObjectNotFoundException)30 MigrationRequiredException (com.xpn.xwiki.store.migration.MigrationRequiredException)29 UnexpectedException (org.xwiki.store.UnexpectedException)29 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)25