Search in sources :

Example 1 with UnpaginatedRequestBuilder

use of com.cloudant.client.api.views.UnpaginatedRequestBuilder 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);
}
Also used : ViewRequestBuilder(com.cloudant.client.api.views.ViewRequestBuilder) UnpaginatedRequestBuilder(com.cloudant.client.api.views.UnpaginatedRequestBuilder)

Example 2 with UnpaginatedRequestBuilder

use of com.cloudant.client.api.views.UnpaginatedRequestBuilder 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()));
}
Also used : Arrays(java.util.Arrays) ImmutableMap(com.google.common.collect.ImmutableMap) Key(com.cloudant.client.api.views.Key) Set(java.util.Set) MapReduce(com.cloudant.client.api.model.DesignDocument.MapReduce) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) DatabaseConnectorCloudant(org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant) ArrayList(java.util.ArrayList) UnpaginatedRequestBuilder(com.cloudant.client.api.views.UnpaginatedRequestBuilder) ViewRequestBuilder(com.cloudant.client.api.views.ViewRequestBuilder) Strings(com.google.common.base.Strings) AttachmentUsage(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage) List(java.util.List) ViewResponse(com.cloudant.client.api.views.ViewResponse) Lists(com.google.common.collect.Lists) Map(java.util.Map) View(org.ektorp.support.View) Entry(java.util.Map.Entry) DatabaseRepositoryCloudantClient(org.eclipse.sw360.datahandler.cloudantclient.DatabaseRepositoryCloudantClient) NotNull(org.jetbrains.annotations.NotNull) MultipleRequestBuilder(com.cloudant.client.api.views.MultipleRequestBuilder) ViewRequestBuilder(com.cloudant.client.api.views.ViewRequestBuilder) ArrayList(java.util.ArrayList) List(java.util.List) Key(com.cloudant.client.api.views.Key)

Example 3 with UnpaginatedRequestBuilder

use of com.cloudant.client.api.views.UnpaginatedRequestBuilder 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);
}
Also used : ViewRequestBuilder(com.cloudant.client.api.views.ViewRequestBuilder) UnpaginatedRequestBuilder(com.cloudant.client.api.views.UnpaginatedRequestBuilder)

Example 4 with UnpaginatedRequestBuilder

use of com.cloudant.client.api.views.UnpaginatedRequestBuilder 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);
}
Also used : ViewRequestBuilder(com.cloudant.client.api.views.ViewRequestBuilder) UnpaginatedRequestBuilder(com.cloudant.client.api.views.UnpaginatedRequestBuilder)

Example 5 with UnpaginatedRequestBuilder

use of com.cloudant.client.api.views.UnpaginatedRequestBuilder in project sw360 by eclipse.

the class ReleaseRepository method getRecentReleases.

public List<Release> getRecentReleases() {
    ViewRequestBuilder query = getConnector().createQuery(Release.class, "byCreatedOn");
    // Get the 5 last documents
    UnpaginatedRequestBuilder reqBuilder = query.newRequest(Key.Type.STRING, Object.class).limit(5).descending(true).includeDocs(false);
    return makeSummary(SummaryType.SHORT, queryForIds(reqBuilder));
}
Also used : ViewRequestBuilder(com.cloudant.client.api.views.ViewRequestBuilder) UnpaginatedRequestBuilder(com.cloudant.client.api.views.UnpaginatedRequestBuilder)

Aggregations

UnpaginatedRequestBuilder (com.cloudant.client.api.views.UnpaginatedRequestBuilder)15 ViewRequestBuilder (com.cloudant.client.api.views.ViewRequestBuilder)14 Key (com.cloudant.client.api.views.Key)2 MapReduce (com.cloudant.client.api.model.DesignDocument.MapReduce)1 ComplexKey (com.cloudant.client.api.views.Key.ComplexKey)1 MultipleRequestBuilder (com.cloudant.client.api.views.MultipleRequestBuilder)1 ViewResponse (com.cloudant.client.api.views.ViewResponse)1 Strings (com.google.common.base.Strings)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 DatabaseConnectorCloudant (org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant)1 DatabaseRepositoryCloudantClient (org.eclipse.sw360.datahandler.cloudantclient.DatabaseRepositoryCloudantClient)1