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;
}
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);
}
}
}
}
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;
}
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);
}
}
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);
}
}
}
Aggregations