/** * Return the string literal in a form ready to embed in an NXQL statement. */ public static String prepareStringLiteral(String s, boolean quoteParameter, boolean escape) { if (escape) { if (quoteParameter) { return NXQL.escapeString(s); } else { return NXQL.escapeStringInner(s); } } else { if (quoteParameter) { return "'" + s + "'"; } else { return s; } } }
/** * SELECT * FROM type WHERE ecm:path STARTSWITH doc.getPathAsString AND prop = value */ public static String select(String type, DocumentModel doc, String prop, String value) { return select(type, doc) + " AND " + prop + " = " + NXQL.escapeString(value); }
protected static SQLQuery getSqlQuery(String nxql) { String query = completeQueryWithSelect(nxql); SQLQuery nxqlQuery; try { nxqlQuery = SQLQueryParser.parse(new StringReader(query)); } catch (QueryParseException e) { if (log.isDebugEnabled()) { log.debug(e.getMessage() + " for query:\n" + query); } throw e; } return nxqlQuery; }
protected List<PublishedDocument> getPublishedDocumentsFromLiveDocument(DocumentRef docRef) { List<PublishedDocument> publishedDocuments = new ArrayList<>(); List<DocumentModel> docs = coreSession.query(String.format(RENDITION_PUBLISHED_DOCUMENTS_FROM_LIVE_DOCUMENT, docRef, NXQL.escapeStringInner(rootPath))); for (DocumentModel doc : docs) { publishedDocuments.add(factory.wrapDocumentModel(doc)); } return publishedDocuments; }
public static String serializeFullText(String value) { value = sanitizeFulltextInput(value); return "= " + NXQL.escapeString(value); }
protected List<PublishedDocument> getPublishedDocumentsFromProxyDocument(DocumentRef docRef, DocumentModel sourceDocument) { List<PublishedDocument> publishedDocuments = new ArrayList<>(); List<DocumentModel> docs = coreSession.query(String.format(RENDITION_PUBLISHED_DOCUMENTS_FROM_PROXY_DOCUMENT, docRef, NXQL.escapeStringInner(rootPath))); for (DocumentModel doc : docs) { if (!doc.getRef().equals(sourceDocument.getRef())) { publishedDocuments.add(factory.wrapDocumentModel(doc)); } } return publishedDocuments; }
/** * SELECT * FROM type WHERE ecm:path STARTSWITH doc.getPathAsString() */ public static String select(String type, DocumentModel doc) { return "SELECT * FROM " + type + " WHERE " + NXQL.ECM_PATH + " STARTSWITH " + NXQL.escapeString(doc.getPathAsString()) + " AND " + NOT_DELETED; }
protected String buildTemplateSearchByNameQuery(String name) { StringBuffer sb = new StringBuffer( "select * from Document where ecm:mixinType = 'Template' AND tmpl:templateName = " + NXQL.escapeString(name)); if (Boolean.parseBoolean(Framework.getProperty(FILTER_VERSIONS_PROPERTY))) { sb.append(" AND ecm:isVersion = 0"); } return sb.toString(); }
private List<DocumentModel> fetchFromVcsChunk(final List<String> ids, CoreSession session) { StringBuilder sb = new StringBuilder(); sb.append("SELECT * FROM Document, Relation WHERE ecm:uuid IN ("); for (int i = 0; i < ids.size(); i++) { sb.append(NXQL.escapeString(ids.get(i))); if (i < ids.size() - 1) { sb.append(", "); } } sb.append(")"); return session.query(sb.toString()); }
/** * @deprecated since 6.0: page providers implement this logic instead. */ @Deprecated public static String formatStringList(List<String> actors) { StringBuffer sb = new StringBuffer(); Iterator<String> actorIterator = actors.iterator(); while (actorIterator.hasNext()) { String userName = actorIterator.next(); sb.append(NXQL.escapeString(userName)); if (actorIterator.hasNext()) { sb.append(','); } } return sb.toString(); }
public List<DocumentModel> findDocumentModelVariants(CoreSession session, DocumentationItem item) { String id = item.getId(); String type = item.getTargetType(); String query = "SELECT * FROM " + DocumentationItem.TYPE_NAME + " WHERE " + DocumentationItem.PROP_DOCUMENTATION_ID + " = " + NXQL.escapeString(id) + " AND " + DocumentationItem.PROP_TARGET_TYPE + " = " + NXQL.escapeString(type) + " AND " + QueryHelper.NOT_DELETED; query += " ORDER BY dc:created"; return session.query(query); }
private List<DocumentModel> fetchDocuments(CoreSession session, List<String> ids) { StringBuilder sb = new StringBuilder(); sb.append("SELECT * FROM Document, Relation WHERE ecm:uuid IN ("); for (int i = 0; i < ids.size(); i++) { sb.append(NXQL.escapeString(ids.get(i))); if (i < ids.size() - 1) { sb.append(", "); } } sb.append(")"); // read invalidation session.save(); return session.query(sb.toString()); }
@SuppressWarnings("unchecked") public static List<String> getListValue(DocumentModel model, PredicateFieldDefinition fieldDescriptor) { Object rawValue = getRawValue(model, fieldDescriptor); if (rawValue == null) { return null; } List<String> values = new ArrayList<>(); if (rawValue instanceof ArrayList) { rawValue = ((ArrayList<Object>) rawValue).toArray(); } for (Object element : (Object[]) rawValue) { if (element != null) { if (element instanceof Number) { values.add(element.toString()); } else { String value = element.toString().trim(); if (!value.equals("")) { values.add(NXQL.escapeString(value)); } } } } return values; }
@Override public List<DocumentModel> getSubscribedDocuments(String prefixedPrincipalName, String repositoryName) { String nxql = "SELECT * FROM Document WHERE ecm:mixinType = '" + SubscriptionAdapter.NOTIFIABLE_FACET + "' " + "AND ecm:isVersion = 0 " + "AND notif:notifications/*/subscribers/* = " + NXQL.escapeString(prefixedPrincipalName); return CoreInstance.doPrivileged(repositoryName, (CoreSession s) -> s.query(nxql).stream().map(NotificationService::detachDocumentModel).collect( toList())); }
@Override public OperationInfo getOperation(String id) { if (id.startsWith(OperationInfo.ARTIFACT_PREFIX)) { id = id.substring(OperationInfo.ARTIFACT_PREFIX.length()); } String query = QueryHelper.select(OperationInfo.TYPE_NAME, getDoc()) + " AND " + OperationInfo.PROP_NAME + " = " + NXQL.escapeString(id) + " OR " + OperationInfo.PROP_ALIASES + " = " + NXQL.escapeString(id); DocumentModelList docs = getCoreSession().query(query); return docs.isEmpty() ? null : docs.get(0).getAdapter(OperationInfo.class); }
protected boolean hasContent(DocumentModel document, String query) throws IOException { try (SessionWrapper wrapper = ctx.getSession(document)) { // Limit result set to 1 as we just want to know if there's at least one child return wrapper.getSession() .queryProjection(String.format(query, NXQL.escapeString(document.getId())), 1, 0) .size() > 0; } }
@Override public ServiceInfo getService(String id) { // Select only not overriden ticket and old imported NXService without overriden value String query = QueryHelper.select(ServiceInfo.TYPE_NAME, getDoc()) + " AND " + ServiceInfo.PROP_CLASS_NAME + " = " + NXQL.escapeString(id) + " AND (" + ServiceInfo.PROP_OVERRIDEN + " = 0 OR " + ServiceInfo.PROP_OVERRIDEN + " is NULL)"; DocumentModelList docs = getCoreSession().query(query); if (docs.size() > 1) { throw new AssertionError("Multiple services found for " + id); } return docs.get(0).getAdapter(ServiceInfo.class); }
@Override public SeamComponentInfo getSeamComponent(String id) { String name = id.replace("seam:", ""); String query = QueryHelper.select(SeamComponentInfo.TYPE_NAME, getDoc()) + " AND " + SeamComponentInfo.PROP_COMPONENT_NAME + " = " + NXQL.escapeString(name); DocumentModelList docs = getCoreSession().query(query); return docs.isEmpty() ? null : docs.get(0).getAdapter(SeamComponentInfo.class); }
protected <T> T getChild(Class<T> adapter, String docType, String idField, String id) { String query = QueryHelper.select(docType, doc) + " AND " + idField + " = " + NXQL.escapeString(id); DocumentModelList docs = getCoreSession().query(query); if (docs.isEmpty()) { log.error("Unable to find " + docType + " for id " + id); } else if (docs.size() == 1) { return docs.get(0).getAdapter(adapter); } else { log.error("multiple match for " + docType + " for id " + id); return docs.get(0).getAdapter(adapter); } return null; }
@Override public void write(JsonGenerator jg, DocumentModel document) throws IOException { if (!document.isFolder()) { jg.writeBooleanField(NAME, false); return; } try (SessionWrapper wrapper = ctx.getSession(document)) { String fetchFolderishChildQuery = "SELECT * FROM Document WHERE ecm:mixinType = 'Folderish'" + " AND ecm:mixinType != 'HiddenInNavigation' AND ecm:isTrashed = 0" + " AND ecm:parentId = " + NXQL.escapeString(document.getId()); // Limit result set to 1 as we just want to know if there's at least one Folderish child boolean hasChildren = !wrapper.getSession().queryProjection(fetchFolderishChildQuery, 1, 0).isEmpty(); jg.writeBooleanField(NAME, hasChildren); } }