Search in sources :

Example 96 with XWikiException

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

the class StatsUtil method findVisitByField.

/**
 * Search visit statistics object in the database based on cookie name.
 *
 * @param fieldName the field name.
 * @param fieldValue the field value.
 * @param context the XWiki context.
 * @return the visit object, null if no object was found.
 * @throws XWikiException error when searching for visit object.
 * @since 1.4M1
 */
protected static VisitStats findVisitByField(String fieldName, String fieldValue, XWikiContext context) throws XWikiException {
    VisitStats visitStats = null;
    Date currentDate = new Date(new Date().getTime() - 30 * 60 * 1000);
    QueryManager qm = context.getWiki().getStore().getQueryManager();
    List<VisitStats> solist = null;
    final String sfieldValue = "fieldValue";
    final String sdate = "date";
    if (qm.hasLanguage(Query.XPATH)) {
        try {
            solist = qm.createQuery("//element(*, xwiki:object)[@:{fieldName}=:{fieldValue}" + " and @endDate>:{date}]  order by @endDate descending", Query.XPATH).bindValue("fieldName", fieldName).bindValue(sfieldValue, fieldValue).bindValue(sdate, currentDate).execute();
        } catch (Exception e) {
            LOGGER.error("Failed to search visit object in the jcr store from cookie name", e);
        }
    } else if (qm.hasLanguage(Query.HQL)) {
        try {
            solist = qm.createQuery("from VisitStats as obj " + "where obj." + fieldName + "=:fieldValue and obj.endDate > :date" + " order by obj.endDate desc", Query.HQL).bindValue(sfieldValue, fieldValue).bindValue(sdate, currentDate).execute();
        } catch (Exception e) {
            LOGGER.error("Failed to search visit object in the database from " + fieldName, e);
        }
    } else {
        throw new UnsupportedOperationException("The current storage engine does not support querying statistics");
    }
    if (solist != null && solist.size() > 0) {
        visitStats = solist.get(0);
    }
    return visitStats;
}
Also used : QueryManager(org.xwiki.query.QueryManager) Date(java.util.Date) XWikiException(com.xpn.xwiki.XWikiException) MalformedURLException(java.net.MalformedURLException)

Example 97 with XWikiException

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

the class RightsManagerListener method onEvent.

@Override
public void onEvent(Event event, Object source, Object data) {
    // Only take into account local events
    if (!Utils.getComponent(RemoteObservationManagerContext.class).isRemoteState()) {
        XWikiDocument document = ((XWikiDocument) source).getOriginalDocument();
        XWikiContext context = (XWikiContext) data;
        String userOrGroupWiki = document.getDatabase();
        String userOrGroupSpace = document.getSpace();
        String userOrGroupName = document.getName();
        if (document.getObject("XWiki.XWikiUsers") != null) {
            try {
                cleanDeletedUserOrGroup(userOrGroupWiki, userOrGroupSpace, userOrGroupName, true, context);
            } catch (XWikiException e) {
                LOGGER.warn("Error when cleaning for deleted user", e);
            }
        } else if (document.getObject("XWiki.XWikiGroups") != null) {
            try {
                cleanDeletedUserOrGroup(userOrGroupWiki, userOrGroupSpace, userOrGroupName, false, context);
            } catch (XWikiException e) {
                LOGGER.warn("Error when cleaning for deleted group", e);
            }
        }
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException)

Example 98 with XWikiException

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

the class HibernateAttachmentRecycleBinStore method resolveDeletedAttachmentContent.

private DeletedAttachment resolveDeletedAttachmentContent(DeletedAttachment deletedAttachment, boolean bTransaction, boolean failIfNoContent) throws XWikiException {
    AttachmentRecycleBinContentStore contentStore = getAttachmentRecycleBinContentStore(deletedAttachment.getContentStore());
    if (contentStore != null) {
        AttachmentReference reference = deletedAttachment.getAttachmentReference();
        DeletedAttachmentContent content = contentStore.get(reference, deletedAttachment.getDate(), deletedAttachment.getId(), bTransaction);
        if (content == null) {
            if (failIfNoContent) {
                throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_UNKNOWN, "Can't find any content for deleted attachment [" + reference + "] with id [" + deletedAttachment.getId() + "]");
            } else {
                this.logger.warn("Can't find any content for deleted attachment [{}] with id [{}]", reference, deletedAttachment.getId());
            }
        }
        try {
            FieldUtils.writeDeclaredField(deletedAttachment, "content", content, true);
        } catch (IllegalAccessException e) {
            throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_UNKNOWN, "Failed to set deleted document content", e);
        }
    }
    return deletedAttachment;
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) DeletedAttachmentContent(com.xpn.xwiki.doc.DeletedAttachmentContent) HibernateDeletedAttachmentContent(com.xpn.xwiki.internal.store.hibernate.HibernateDeletedAttachmentContent) AttachmentRecycleBinContentStore(com.xpn.xwiki.store.AttachmentRecycleBinContentStore) XWikiException(com.xpn.xwiki.XWikiException)

Example 99 with XWikiException

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

the class HibernateAttachmentVersioningStore method loadArchive.

@Override
public XWikiAttachmentArchive loadArchive(final XWikiAttachment attachment, XWikiContext context, boolean bTransaction) throws XWikiException {
    try {
        final XWikiAttachmentArchive archive = new XWikiAttachmentArchive();
        archive.setAttachment(attachment);
        executeRead(context, bTransaction, new HibernateCallback<Object>() {

            @Override
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.load(archive, archive.getId());
                } catch (ObjectNotFoundException e) {
                // if none found then return empty created archive
                }
                return null;
            }
        });
        attachment.setAttachment_archive(archive);
        return archive;
    } catch (Exception e) {
        Object[] args = { attachment.getFilename(), attachment.getDoc() };
        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_LOADING_ATTACHMENT, "Exception while loading attachment archive {0} of document {1}", e, args);
    }
}
Also used : XWikiAttachmentArchive(com.xpn.xwiki.doc.XWikiAttachmentArchive) HibernateException(org.hibernate.HibernateException) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) XWikiException(com.xpn.xwiki.XWikiException) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) HibernateException(org.hibernate.HibernateException) XWikiException(com.xpn.xwiki.XWikiException) Session(org.hibernate.Session)

Example 100 with XWikiException

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

the class DocumentInfo method testInstall.

public int testInstall(boolean isAdmin, XWikiContext context) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Package test install document " + ((this.doc == null) ? "" : getFullName()) + " " + ((this.doc == null) ? "" : getLanguage()));
    }
    this.installable = INSTALL_IMPOSSIBLE;
    try {
        if (this.doc == null) {
            return this.installable;
        }
        try {
            if ((!isAdmin) && (!context.getWiki().checkAccess("edit", this.doc, context))) {
                return this.installable;
            }
            XWikiDocument doc1 = context.getWiki().getDocument(this.doc.getFullName(), context);
            boolean isNew = doc1.isNew();
            if (!isNew) {
                if ((this.doc.getLanguage() != null) && (!this.doc.getLanguage().equals(""))) {
                    isNew = !doc1.getTranslationList(context).contains(this.doc.getLanguage());
                }
            }
            if (!isNew) {
                this.installable = INSTALL_ALREADY_EXIST;
                return this.installable;
            }
        } catch (XWikiException e) {
            this.installable = INSTALL_IMPOSSIBLE;
            return this.installable;
        }
        this.installable = INSTALL_OK;
        return this.installable;
    } finally {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Package test install document " + ((this.doc == null) ? "" : getFullName()) + " " + ((this.doc == null) ? "" : getLanguage()) + " result " + this.installable);
        }
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiException(com.xpn.xwiki.XWikiException)

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