/** * 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); }
/** * 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; } } }
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; }
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; }
/** * @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(); }
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(); }
public static String serializeFullText(String value) { value = sanitizeFulltextInput(value); return "= " + NXQL.escapeString(value); }
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()); }
/** * 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; }
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()); }
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); }
@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())); }
@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 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); }
if (values.size() == 1) { sb.append(" = "); sb.append(NXQL.escapeString(values.get(0))); } else { sb.append(" IN ("); for (Iterator<String> it = values.iterator(); it.hasNext();) { sb.append(NXQL.escapeString(it.next())); if (it.hasNext()) { sb.append(", ");
public static String getStringValue(DocumentModel model, PredicateFieldDefinition fieldDescriptor) { Object rawValue = getRawValue(model, fieldDescriptor); if (rawValue == null) { return null; } String value; if (rawValue instanceof GregorianCalendar) { GregorianCalendar gc = (GregorianCalendar) rawValue; value = "TIMESTAMP '" + getDateFormat().format(gc.getTime()) + "'"; } else if (rawValue instanceof Date) { Date date = (Date) rawValue; value = "TIMESTAMP '" + getDateFormat().format(date) + "'"; } else if (rawValue instanceof Integer || rawValue instanceof Long || rawValue instanceof Double) { value = rawValue.toString(); // no quotes } else if (rawValue instanceof Boolean) { value = ((Boolean) rawValue).booleanValue() ? "1" : "0"; } else { value = rawValue.toString().trim(); if (value.equals("")) { return null; } String fieldType = getFieldType(model, fieldDescriptor); if ("long".equals(fieldType) || "integer".equals(fieldType) || "double".equals(fieldType)) { return value; } else { return NXQL.escapeString(value); } } return value; }
query += " AND " + DocumentationItem.PROP_TYPE + " = " + NXQL.escapeString(category); query += " AND " + DocumentationItem.PROP_TARGET_TYPE + " = " + NXQL.escapeString(targetType);
@Override public List<DocumentationItem> findDocumentItems(CoreSession session, NuxeoArtifact nxItem) { String id = nxItem.getId(); String type = nxItem.getArtifactType(); String query = "SELECT * FROM " + DocumentationItem.TYPE_NAME + " WHERE " + DocumentationItem.PROP_TARGET + " = " + NXQL.escapeString(id) + " AND " + DocumentationItem.PROP_TARGET_TYPE + " = " + NXQL.escapeString(type) + " AND " + QueryHelper.NOT_DELETED + " ORDER BY " + DocumentationItem.PROP_DOCUMENTATION_ID + ", dc:modified"; List<DocumentModel> docs = session.query(query); Map<String, List<DocumentationItem>> sortMap = new HashMap<>(); for (DocumentModel doc : docs) { DocumentationItem item = doc.getAdapter(DocumentationItem.class); List<DocumentationItem> alternatives = sortMap.get(item.getId()); if (alternatives == null) { alternatives = new ArrayList<>(); alternatives.add(item); sortMap.put(item.getId(), alternatives); } else { alternatives.add(item); } } List<DocumentationItem> result = new ArrayList<>(); for (String documentationId : sortMap.keySet()) { DocumentationItem bestDoc = findBestMatch(nxItem, sortMap.get(documentationId)); result.add(bestDoc); } return result; }
@Override public String getRouteModelDocIdWithId(CoreSession session, String id) { if (modelsChache != null) { String routeDocId = modelsChache.getIfPresent(id); if (routeDocId != null) { return routeDocId; } } String query = String.format(ROUTE_MODEL_DOC_ID_WITH_ID_QUERY, NXQL.escapeString(id)); List<String> routeIds = new ArrayList<>(); try (IterableQueryResult results = session.queryAndFetch(query, "NXQL")) { if (results.size() == 0) { throw new NuxeoException("No route found for id: " + id); } if (results.size() != 1) { throw new NuxeoException("More than one route model found with id: " + id); } for (Map<String, Serializable> map : results) { routeIds.add(map.get("ecm:uuid").toString()); } } String routeDocId = routeIds.get(0); if (modelsChache == null) { modelsChache = CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(10, TimeUnit.MINUTES).build(); } modelsChache.put(id, routeDocId); return routeDocId; }
if (principal != null) { for (String actor : TaskActorsHelper.getTaskActors(principal)) { actors.add(NXQL.escapeString(actor)); actors.add(NXQL.escapeString(actorId)); query.append(String.format(" AND nt:processId = %s", NXQL.escapeString(workflowInstanceId)));