use of com.cloudant.client.api.views.ViewRequestBuilder in project sw360 by eclipse.
the class ComponentRepository method getRecentComponentsSummary.
public Map<PaginationData, List<Component>> getRecentComponentsSummary(User user, PaginationData pageData) {
final int rowsPerPage = pageData.getRowsPerPage();
Map<PaginationData, List<Component>> result = Maps.newHashMap();
List<Component> components = Lists.newArrayList();
final boolean ascending = pageData.isAscending();
final int sortColumnNo = pageData.getSortColumnNumber();
ViewRequestBuilder query;
switch(sortColumnNo) {
case -1:
query = getConnector().createQuery(Component.class, "byCreatedOn");
break;
case 0:
query = getConnector().createQuery(Component.class, "byvendor");
break;
case 1:
query = getConnector().createQuery(Component.class, "byname");
break;
case 2:
query = getConnector().createQuery(Component.class, "bymainlicense");
break;
case 3:
query = getConnector().createQuery(Component.class, "bycomponenttype");
break;
default:
query = getConnector().createQuery(Component.class, "all");
break;
}
ViewRequest<String, Object> request = null;
if (rowsPerPage == -1) {
request = query.newRequest(Key.Type.STRING, Object.class).descending(!ascending).includeDocs(true).build();
} else {
request = query.newPaginatedRequest(Key.Type.STRING, Object.class).rowsPerPage(rowsPerPage).descending(!ascending).includeDocs(true).build();
}
ViewResponse<String, Object> response = null;
try {
response = request.getResponse();
int pageNo = pageData.getDisplayStart() / rowsPerPage;
int i = 1;
while (i <= pageNo) {
response = response.nextPage();
i++;
}
components = response.getDocsAs(Component.class);
} catch (Exception e) {
log.error("Error getting recent components", e);
}
components = makeSummaryWithPermissionsFromFullDocs(SummaryType.SUMMARY, components, user);
pageData.setTotalRowCount(response.getTotalRowCount());
result.put(pageData, components);
return result;
}
use of com.cloudant.client.api.views.ViewRequestBuilder in project sw360 by eclipse.
the class AttachmentContentRepository method getOnlyRemoteAttachments.
public List<AttachmentContent> getOnlyRemoteAttachments() {
ViewRequestBuilder query = getConnector().createQuery(AttachmentContent.class, "onlyRemotes");
UnpaginatedRequestBuilder req = query.newRequest(Key.Type.STRING, Object.class).includeDocs(true);
return queryView(req);
}
use of com.cloudant.client.api.views.ViewRequestBuilder in project sw360 by eclipse.
the class AttachmentUsageRepository method getAttachmentUsageCount.
public Map<Map<String, String>, Integer> getAttachmentUsageCount(Map<String, Set<String>> attachments, String filter) {
ViewRequestBuilder viewQuery = createUsagesByAttachmentQuery(filter);
List<String[]> complexKeysList = prepareKeys(attachments, filter);
Key.ComplexKey[] compexKeys = new Key.ComplexKey[complexKeysList.size()];
for (int i = 0; i < compexKeys.length; i++) {
Key.ComplexKey key = Key.complex(complexKeysList.get(i));
compexKeys[i] = key;
}
UnpaginatedRequestBuilder<com.cloudant.client.api.views.Key.ComplexKey, Object> reqBuilder = viewQuery.newRequest(Key.Type.COMPLEX, Object.class).reduce(true).group(true).keys(compexKeys);
ViewResponse<com.cloudant.client.api.views.Key.ComplexKey, Object> result = queryViewForComplexKeys(reqBuilder);
return result.getRows().stream().collect(Collectors.toMap(key -> {
String json = key.getKey().toJson();
String replace = json.replace("[", "").replace("]", "").replaceAll("\"", "");
List<String> relIdAttachmentToUsageType = new ArrayList<String>(Arrays.asList(replace.split(",")));
return ImmutableMap.of(relIdAttachmentToUsageType.get(0), relIdAttachmentToUsageType.get(1));
}, val -> ((Double) val.getValue()).intValue()));
}
use of com.cloudant.client.api.views.ViewRequestBuilder in project sw360 by eclipse.
the class AttachmentUsageRepository method getUsedAttachments.
public List<AttachmentUsage> getUsedAttachments(String usedById, String filter) {
ViewRequestBuilder viewQuery = getConnector().createQuery(AttachmentUsage.class, "usedAttachmentsUsageType");
UnpaginatedRequestBuilder reqBuilder = viewQuery.newRequest(Key.Type.COMPLEX, Object.class).includeDocs(true).reduce(false).keys(Key.complex(new String[] { usedById, filter }));
return queryView(reqBuilder);
}
use of com.cloudant.client.api.views.ViewRequestBuilder in project sw360 by eclipse.
the class AttachmentUsageRepository method getUsageForAttachment.
public List<AttachmentUsage> getUsageForAttachment(String ownerId, String attachmentContentId) {
ViewRequestBuilder viewQuery = getConnector().createQuery(AttachmentUsage.class, "usagesByAttachment");
UnpaginatedRequestBuilder reqBuilder = viewQuery.newRequest(Key.Type.COMPLEX, Object.class).keys(Key.complex(new String[] { ownerId, attachmentContentId })).includeDocs(true).reduce(false);
return queryView(reqBuilder);
}
Aggregations