private List<String> getAllTags() throws QueryException { String query = "select distinct elements(prop.list) from BaseObject as obj, " + "DBStringListProperty as prop where obj.className='XWiki.TagClass' " + "and obj.id=prop.id.id and prop.id.name='tags'"; List<String> tags = queryManager.createQuery(query, Query.HQL).execute(); Collections.sort(tags, String.CASE_INSENSITIVE_ORDER); return tags; } }
@Override public List<String> getSpaces(String wiki) throws WikiStreamException { try { return this.queryManager.getNamedQuery("getSpaces").setWiki(wiki).execute(); } catch (QueryException e) { throw new WikiStreamException(String.format("Failed to get the list of spaces in wiki [%s]", wiki), e); } }
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) LOG.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)
private long getLastUsedId() throws QueryException { this.logger.debug("getLastUsedId()"); long crtMaxID = 0; Query q = this.qm.createQuery("select family.identifier " + "from Document doc, " + " doc.object(PhenoTips.FamilyClass) as family " + "where family.identifier is not null " + "order by family.identifier desc", Query.XWQL).setLimit(1); List<Long> crtMaxIDList = q.execute(); if (crtMaxIDList.size() > 0 && crtMaxIDList.get(0) != null) { crtMaxID = crtMaxIDList.get(0); } crtMaxID = Math.max(crtMaxID, 0); return crtMaxID; }
groups = context.getWiki().getStore().searchDocumentsNames(where, nb, start, parameterValues, context); } else if (context.getWiki().getStore().getQueryManager().hasLanguage(Query.XPATH)) { .getStore() .getQueryManager() .createQuery( "/*/*[obj/XWiki/" + (user ? CLASS_SUFFIX_XWIKIUSERS : CLASS_SUFFIX_XWIKIGROUPS) + "]/@fullName", Query.XPATH).setLimit(nb).setOffset(start).execute();
/** * Search for all wiki macros in the current wiki. * * @param xcontext the current request context * @return a list of documents containing wiki macros, each item as a List of 3 strings: space name, document name, * last author of the document * @throws Exception if the database search fails */ private List<Object[]> getWikiMacroDocumentData(XWikiContext xcontext) throws Exception { final QueryManager qm = xcontext.getWiki().getStore().getQueryManager(); final Query q = qm.getNamedQuery("getWikiMacroDocuments"); return (List<Object[]>) (List) q.execute(); }
private List<String> getDocumentsWithTag(String tag) throws QueryException { String query = "select doc.fullName from XWikiDocument as doc, BaseObject as obj, DBStringListProperty as prop " + "where obj.name=doc.fullName and obj.className='XWiki.TagClass' and obj.id=prop.id.id " + "and prop.id.name='tags' and :tag in elements(prop.list) order by doc.name asc"; List<String> documentsWithTag = queryManager.createQuery(query, Query.HQL).bindValue("tag", tag).execute(); return documentsWithTag; } }
@Override public List<EntityReference> getReferences(EntityReference wikiReference) throws SolrIndexerException { List<EntityReference> result = new ArrayList<EntityReference>(); // Ignore the wiki reference because it is not indexable. List<String> localSpaceRefs = null; // Make sure the list of spaces is from the requested wiki. try { localSpaceRefs = this.queryManager.getNamedQuery("getSpaces").setWiki(wikiReference.getName()).execute(); } catch (QueryException e) { throw new SolrIndexerException("Failed to query wiki [" + wikiReference.getName() + "] spaces", e); } // Visit each space for (String localSpaceRef : localSpaceRefs) { EntityReference spaceReference = this.explicitEntityReferenceResolver.resolve(localSpaceRef, EntityType.SPACE, wikiReference); try { Iterables.addAll(result, this.spaceResolverProvider.get().getReferences(spaceReference)); } catch (Exception e) { this.logger.error("Failed to resolve references for space [" + spaceReference + "]", e); } } return result; }
private List<String> runQuery(String queryString, String input) { String formattedInput = String.format(PhenotipsFamilyExport.INPUT_FORMAT, input.toLowerCase()); // Query patients Query query = null; List<String> queryResults = null; try { query = this.qm.createQuery(queryString, Query.XWQL); query.bindValue(PhenotipsFamilyExport.INPUT_PARAMETER, formattedInput); queryResults = query.execute(); } catch (QueryException e) { this.logger.error("Error while performing patients/families query: [{}] ", e.getMessage()); return Collections.emptyList(); } return queryResults; }
Query jobDocumentsQuery = queryManager.getNamedQuery("getWatchlistJobDocuments");
@Override public List<String> getIconSetNames() throws IconException { try { String xwql = "SELECT obj.name FROM Document doc, doc.object(IconThemesCode.IconThemeClass) obj " + "ORDER BY obj.name"; Query query = queryManager.createQuery(xwql, Query.XWQL); return query.execute(); } catch (QueryException e) { throw new IconException("Failed to get the name of all icon sets.", e); } } }
public void refreshLinks(XWikiContext context) throws XWikiException { try { // refreshes all Links of each doc of the wiki List<String> docs = getStore().getQueryManager().getNamedQuery("getAllDocuments").execute(); for (int i = 0; i < docs.size(); i++) { XWikiDocument myDoc = this.getDocument(docs.get(i), context); myDoc.getStore().saveLinks(myDoc, context, true); } } catch (QueryException ex) { throw new XWikiException(0, 0, ex.getMessage(), ex); } }
/** * Checks whether the global configuration allows for other eids to be set arbitrarily by the user for each patient, * by looking if there is a {@code PhenoTips.LabeledIdentifierGlobalSettings} object with {@code 0} set for its * {@code allowOtherEids} property. * * @return {@code false} if custom labels are explicitly denied, {@code true} otherwise */ private boolean allowOtherEids() { Query q = null; try { q = this.qm.createQuery("select obj.allowOtherEids from Document doc, doc.object(" + "PhenoTips.LabeledIdentifierGlobalSettings) obj where doc.fullName = 'XWiki.XWikiPreferences'", Query.XWQL); List<Integer> results = q.execute(); if (results == null || results.isEmpty()) { this.logger.debug("There should be one LabeledIdentifierGlobalSettings object. None were found."); return true; } return results.get(0) != 0; } catch (QueryException ex) { this.logger.warn("Failed to query LabeledIdentifierGlobalSettings object: {}", ex.getMessage(), ex); return true; } }
public List<String> getSpaces(XWikiContext context) throws XWikiException { try { return getStore().getQueryManager().getNamedQuery("getSpaces").execute(); } catch (QueryException ex) { throw new XWikiException(0, 0, ex.getMessage(), ex); } }
@Override protected long getLastUsedId() { this.logger.debug("getLastUsedId()"); long crtMaxID = 0; try { Query q = this.qm.createQuery("select family.identifier " + "from Document doc, " + " doc.object(PhenoTips.FamilyClass) as family " + "where family.identifier is not null " + "order by family.identifier desc", Query.XWQL).setLimit(1); List<Long> crtMaxIDList = q.execute(); if (crtMaxIDList.size() > 0 && crtMaxIDList.get(0) != null) { crtMaxID = crtMaxIDList.get(0); } crtMaxID = Math.max(crtMaxID, 0); } catch (QueryException ex) { this.logger.warn("Failed to get the last used identifier: {}", ex.getMessage()); } return crtMaxID; }
@Override public List<EntityReference> getReferences(EntityReference spaceReference) throws SolrIndexerException { List<EntityReference> result = new ArrayList<EntityReference>(); EntityReference wikiReference = spaceReference.extractReference(EntityType.WIKI); String localSpaceReference = this.localEntityReferenceSerializer.serialize(spaceReference); // Ignore the space reference because it is not indexable. // Make sure the list of spaces is from the requested wiki List<String> documentNames; try { documentNames = this.queryManager.getNamedQuery("getSpaceDocsName").setWiki(wikiReference.getName()) .bindValue("space", localSpaceReference).execute(); } catch (QueryException e) { throw new SolrIndexerException("Failed to query space [" + spaceReference + "] documents", e); } for (String documentName : documentNames) { EntityReference documentReference = new EntityReference(documentName, EntityType.DOCUMENT, spaceReference); try { Iterables.addAll(result, this.documentResolverProvider.get().getReferences(documentReference)); } catch (Exception e) { this.logger.error("Failed to resolve references for document [" + documentReference + "]", e); } } return result; }
@Override protected long getLastUsedId() { long crtMaxID = 0; try { Query q = this.qm.createQuery( "select patient.identifier from Document doc, doc.object(PhenoTips.PatientClass) as patient" + " where patient.identifier is not null order by patient.identifier desc", Query.XWQL).setLimit(1); List<Long> crtMaxIDList = q.execute(); if (!crtMaxIDList.isEmpty() && crtMaxIDList.get(0) != null) { crtMaxID = crtMaxIDList.get(0); } crtMaxID = Math.max(crtMaxID, 0); } catch (QueryException ex) { this.logger.warn("Failed to get the last used identifier: {}", ex.getMessage()); } return crtMaxID; } }
public List<String> getSpaceDocsName(String spaceName, XWikiContext context) throws XWikiException { try { return getStore().getQueryManager().getNamedQuery("getSpaceDocsName").bindValue("space", spaceName) .execute(); } catch (QueryException ex) { throw new XWikiException(0, 0, ex.getMessage(), ex); } }
private Response checkForMultipleRecords(Patient patient, String eid) { try { Query q = this.qm.createQuery("where doc.object(PhenoTips.PatientClass).external_id = :eid", Query.XWQL); q.bindValue("eid", eid); List<String> results = q.execute(); if (results.size() > 1) { this.slf4Jlogger.debug("Multiple patient records ({}) with external ID [{}]: {}", results.size(), eid, results); Alternatives response = this.factory.createAlternatives(results, this.uriInfo); return Response.status(300).entity(response).build(); } } catch (QueryException ex) { this.slf4Jlogger.warn("Failed to retrieve patient with external id [{}]: {}", eid, ex.getMessage()); } if (patient == null) { this.slf4Jlogger.debug("No patient record with external ID [{}] exists yet", eid); return Response.status(Status.NOT_FOUND).build(); } return null; }
public void addAllWikiDocuments(XWikiContext context) throws XWikiException { XWiki wiki = context.getWiki(); try { List<String> documentNames = wiki.getStore().getQueryManager().getNamedQuery("getAllDocuments").execute(); for (String docName : documentNames) { add(docName, DocumentInfo.ACTION_OVERWRITE, context); } } catch (QueryException ex) { throw new PackageException(PackageException.ERROR_XWIKI_STORE_HIBERNATE_SEARCH, "Cannot retrieve the list of documents to export", ex); } }