public void edit() { try { final NodeQuery q; final String contentType = config.contentType(); final NodeQuery qct = contentType == null ? null : NodeQueries.term(Schema.TYPE, contentType); final String id = config.contentId(); final NodeQuery qid = id == null ? null : NodeQueries.term(Schema.ID, id); if (qid != null && qct != null) { q = NodeQueries.bool().must(qct).must(qid); } else if (qid != null) { q = qid; } else if (qct != null) { q = qct; } else { q = NodeQueries.matchAll(); } final Item<Node> item = repository.getFirst(q, null, null, false, null); node = item != null ? item.getItem() : null; } catch (Exception e) { exception = e; } } }
private NodeQuery filteredQuery(final NodesFilterDTO filter) { if (filter.getQuery() != null && filter.getContentTypeId() != null) { return NodeQueries.any(NodeQueries.anyString(filter.getQuery(), fields), NodeQueries.term(Schema.TYPE, filter.getContentTypeId())); } else if (filter.getQuery() == null && filter.getContentTypeId() != null) { return NodeQueries.term(Schema.TYPE, filter.getContentTypeId()); } else if (filter.getQuery() != null && filter.getContentTypeId() == null) { return NodeQueries.anyString(filter.getQuery(), fields); } return null; }
private GroupResult doQuery(final Date start, final Date end) { if (logger.isTraceEnabled()) { logger.trace("Doing query..."); } final NodeQuery and = and(); final NodeQuery query; if (start == null) { query = and != null ? and : NodeQueries.matchAll(); } else { final NodeQuery range = NodeQueries.range(Schema.DATE, start, end, true, true); query = and != null ? NodeQueries.all(range, and) : range; } if (logger.isTraceEnabled()) { logger.trace("Query ", query.toString()); } final List<String> fields = fields(); if (logger.isTraceEnabled()) { logger.trace("Fields ", fields.toString()); } final GroupResult result = this.contentRepository.getRepository().groupBy(query, null, fields); if (logger.isTraceEnabled() && result != null) { logger.trace("Recover {} results", result.getTotalHits()); } return result; }
private NodeQuery q(String value) { final String field = config.field(); final QueryType type = config.type(); if (type.equals(QueryType.TERM_QUERY)) { return NodeQueries.term(field, value); } else if (type.equals(QueryType.WILDCARD_QUERY)) { return NodeQueries.wildcard(field, value); } else if (type.equals(QueryType.PARSE_QUERY)) { return NodeQueries.string(field, value); } return null; }
/** * Content key query. * @param key Content key to filter. * @return The requested query or {@code null} if the argument is {@code null}. */ public static NodeQuery contentKey(ContentKey key) { if (key == null) { return null; } final NRBooleanQuery q = NodeQueries.bool(); q.must(contentType(key.getContentType())); q.must(NodeQueries.term(Schema.ID, key.getContentId())); return q; } }
@Override NodeQuery and() { if (getNavigationKey() == null) { return null; } final ContentType contentType = getNavigationKey().getContentType(); if (contentType == null) { return null; } return NodeQueries.term(Schema.TYPE, contentType.getId()); }
@Transactional(rollbackFor = Throwable.class) /** Return repository summary */ public NodeRepositoryDTO getSummary(String repositoryId) throws PMSException { if (logger.isTraceEnabled()) { logger.trace("Getting summary for repository service with id {}", repositoryId); } final NodeRepositoryDTO dto = new NodeRepositoryDTO(); final NodeRepository repository = getExternalService(repositoryId); final GroupResult result = repository.groupBy(NodeQueries.matchAll(), null, Lists.newArrayList(Schema.TYPE)); final Group root = result.getGroup(); final ContentTypesObject types = loadContentTypes(); dto.setNodeCount(result.getTotalHits()); final List<ContentTypeCountDTO> contentTypes = Lists.newArrayListWithCapacity(root.getGroupNames().size()); for (String name : root.getGroupNames()) { final Group g = root.getGroup(name); final ContentTypeCountDTO count = new ContentTypeCountDTO(); count.setContentType(getContentType(types, name)); count.setCount(g.getHits()); contentTypes.add(count); } dto.setContentTypes(contentTypes); return dto; }
private void multi() { List<String> values = getValues(); if (values == null || values.isEmpty()) { return; } if (values.size() == 1) { add(values.get(0)); } else if (config.consolidate() == null) { for (String value : values) { add(value); } } else { Occur o = config.consolidate().getOccur(); NRBooleanQuery q = NodeQueries.bool(); for (String value : values) { q.add(NRBooleanClause.create(q(value), o)); } add(q); } }
/** Component execution. */ public ComponentResponse execute() { // Content query if (contentKey == null) { content = null; } else { final NodeQuery cq = contentRepository.contentKey(contentKey); // Navigation query // TODO //final NodeQuery nq = contentRepository.navigationKey(navigationKey); final NodeQuery nq = null; // Filter query final NodeQuery f; if (config == null) { f = null; } else { f = all(contentRepository.category(config.category()), contentRepository.tag(config.tag()), contentRepository.contentType(config.contentType())); } // Final query final NodeQuery q = null2All(all(cq, nq, f)); final Item<Content> item = contentRepository.getFirst(q, null, true); content = item.getItem(); } return ComponentResponse.OK; }
public ComponentResponse execute() { final ContentCriteria criteria = contentLoader.newCriteria(); pagination = loadPagination(Pagination.SIZE); if (componentConfig.navigation() && navigationKey != null) { if (navigationKey.isCategory()) { criteria.categories().apply(navigationKey.getCategory(), FilterType.REQUIRED); } if (navigationKey.isContentType()) { criteria.contentTypes().apply(navigationKey.getContentType(), FilterType.REQUIRED); } /* * if (navigationKey.isCategory() && navigationKey.isContentType()) { * criteria.category(navigationKey.getCategory()).contentType(navigationKey.getContentType()); } else if * (navigationKey.isCategory() && !navigationKey.isContentType()) { * criteria.category(navigationKey.getCategory()); } else if (!navigationKey.isCategory() && * navigationKey.isContentType()) { * * } */ } final List<String> f = fields(); if (param != null && !"".equals(param.trim()) && !f.isEmpty()) { criteria.must(NodeQueries.anyString(param, f)); } setPage(criteria.getPage(pagination)); return ComponentResponse.OK; }
/** * Reads content from content repository id by contentkey. * @see com.isotrol.impe3.api.component.Component#execute() */ public ComponentResponse execute() { if (contentKey == null) { throw new IllegalStateException(); } final NodeQuery query = NodeQueries.nodeKey(contentKey.getContentId(), contentKey.getContentType().getId()); final Item<Content> item = contentRepository.getFirst(query, null, true); content = item.getItem(); return ComponentResponse.OK; }
/** * @see com.isotrol.impe3.api.component.Component#execute() */ public ComponentResponse execute() { if (config != null && StringUtils.hasText(config.value())) { String field = config.field(); String value = config.value(); QueryType type = config.type(); ConditionalClause occurr = config.condition(); NodeQuery query = null; if (type.equals(QueryType.TERM_QUERY)) { query = NodeQueries.term(field, value); } else if (type.equals(QueryType.WILDCARD_QUERY)) { query = NodeQueries.wildcard(field, value); } else if (type.equals(QueryType.PARSE_QUERY)) { query = NodeQueries.string(field, value); } criteriaTransformer = ContentCriteriaTransformer.addQuery(query, occurr.getOccur()); } return ComponentResponse.OK; }
@Override NodeQuery and() { if (getNavigationKey() == null) { return null; } final Category category = getNavigationKey().getCategory(); if (category == null) { return null; } return NodeQueries.term(Schema.CATEGORY, category.getId()); }
final NodeRepository repository = getExternalService(repositoryId); final NodeQuery query = (filter == null || (filter.getQuery() == null && filter.getContentTypeId() == null)) ? NodeQueries .matchAll() : filteredQuery(filter); final Page<Node> nodes = repository.getPage(query, null, null, false, 0, 100, null);
/** Component execution. */ public ComponentResponse execute() { // Navigation query final NodeQuery nq = contentRepository.navigationKey(navigationKey); // Filter query final NodeQuery f; if (config == null) { f = null; } else { f = all(contentRepository.category(config.category()), contentRepository.tag(config.tag()), contentRepository.contentType(config.contentType())); } // Final query final NodeQuery q = null2All(all(nq, f)); final Pagination p = loadPagination(10); final Page<Content> page = contentRepository.getPage(q, null, false, p.getFirstRecord(), p.getSize()); setPage(page); return ComponentResponse.OK; } }
private Content loadContent(ContentCriteria criteria, String v) { String f = config.fieldName(); if (config.encode()) { v = ISO9075.encode(v); } final NodeQuery query = NodeQueries.term(f, v); final ContentCriteria c = criteria.clone(); c.must(query); final Item<Content> item = c.getFirst(); if (item != null) { return item.getItem(); } return null; }
@Override Content loadContent(ContentCriteria criteria) { if (config != null) { String f = config.fieldName(); String v = config.fieldValue(); if (config.encode()) { v = ISO9075.encode(v); } final NodeQuery query = NodeQueries.term(f, v); criteria.must(query); final Item<Content> item = criteria.getFirst(); if (item != null) { return item.getItem(); } } return null; }