• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Bynder / bynder-java-sdk / 7053396997

30 Nov 2023 11:13PM UTC coverage: 41.549% (-3.8%) from 45.356%
7053396997

push

github

ahongbynder
API-1822 resolve package name

708 of 1704 relevant lines covered (41.55%)

0.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/com/bynder/sdk/sample/CollectionsSample.java
1
package com.bynder.sdk.sample;
2

3
import com.bynder.sdk.configuration.Configuration;
4
import com.bynder.sdk.model.Collection;
5
import com.bynder.sdk.query.collection.*;
6
import com.bynder.sdk.service.BynderClient;
7
import com.bynder.sdk.service.collection.CollectionService;
8
import com.bynder.sdk.util.Utils;
9

10
import java.io.IOException;
11
import java.net.URISyntaxException;
12
import java.net.URL;
13

14
import java.util.List;
15
import java.util.Properties;
16
import java.util.Random;
17

18
import org.slf4j.Logger;
19
import org.slf4j.LoggerFactory;
20

21
public class CollectionsSample {
×
22
    private static final Logger LOG = LoggerFactory.getLogger(CollectionsSample.class);
×
23

24
    public static void main(final String[] args) throws URISyntaxException, IOException {
25
        /**
26
         * Loads app.properties file under src/main/resources
27
         */
28
        Properties appProperties = Utils.loadConfig("app");
×
29

30

31
        // Initialize BynderClient with a permanent token
32
        BynderClient client = BynderClient.Builder.create(
×
33
                new Configuration.Builder(new URL(appProperties.getProperty("BASE_URL")))
×
34
                        .setPermanentToken(appProperties.getProperty("PERMANENT_TOKEN")).build());
×
35

36
        // Initialize collection service
37
        CollectionService collectionService = client.getCollectionService();
×
38

39
        // get collections with limit
40
        CollectionQuery collectionQuery = new CollectionQuery().setLimit(20);
×
41
        List<Collection> collections = collectionService.getCollections(collectionQuery).blockingSingle().body();
×
42
        if (collections != null && !collections.isEmpty()) {
×
43
            for (Collection collectionResult : collections) {
×
44
                LOG.info("Collection ID: " + collectionResult.getId());
×
45
                LOG.info("Collection Name: " + collectionResult.getName());
×
46
                LOG.info("Collection Description: " + collectionResult.getDescription());
×
47
                LOG.info("Collection Media Count: " + collectionResult.getMediaCount());
×
48
                LOG.info("Collection Date Created: " + collectionResult.getDateCreated());
×
49
            }
×
50
        }
51

52
        // get collection info
53
        String collectionInfoId = appProperties.getProperty("GET_COLLECTION_INFO_ID");
×
54
        CollectionInfoQuery collectionInfoQuery = new CollectionInfoQuery(collectionInfoId);
×
55
        Collection collectionInfo = collectionService.getCollectionInfo(collectionInfoQuery).blockingSingle().body();
×
56
        if (collectionInfo != null) {
×
57
            LOG.info("Collection Info Name: " + collectionInfo.getName());
×
58
            LOG.info("Collection Info Description: " + collectionInfo.getDescription());
×
59
        }
60

61
        // create collection
62
        Random random = new Random();
×
63
        int randomInt = random.nextInt(100);
×
64
        String newCollectionName = "New Collection" + randomInt;
×
65
        LOG.info("new collection name: " + newCollectionName);
×
66
        CollectionCreateQuery createCollectionQuery = new CollectionCreateQuery(newCollectionName);
×
67
        collectionService.createCollection(createCollectionQuery).blockingSingle();
×
68

69
        // get collections with added collection
70
        List<Collection> updatedCollections = collectionService.getCollections(collectionQuery).blockingSingle().body();
×
71
        if (updatedCollections != null && !updatedCollections.isEmpty()) {
×
72
            for (Collection collectionResult : updatedCollections) {
×
73
                LOG.info("Collection ID: " + collectionResult.getId());
×
74
                LOG.info("Collection Name: " + collectionResult.getName());
×
75
                LOG.info("Collection Description: " + collectionResult.getDescription());
×
76
                LOG.info("Collection Media Count: " + collectionResult.getMediaCount());
×
77
                LOG.info("Collection Date Created: " + collectionResult.getDateCreated());
×
78
            }
×
79
        }
80

81
        // share collection to recipients
82
        String shareCollectionId = appProperties.getProperty("SHARE_COLLECTION_ID");
×
83
        LOG.info("sharing collection id: " + shareCollectionId);
×
84
        String collectionShareRecipient = appProperties.getProperty("COLLECTION_SHARE_RECIPIENT");
×
85
        String[] shareCollectionRecipients = new String[] {collectionShareRecipient};
×
86

87
        // allow recipient to view, login required false, send email with message "test"
88
        CollectionShareQuery collectionShareQuery = new CollectionShareQuery(shareCollectionId, shareCollectionRecipients, CollectionRecipientRight.VIEW)
×
89
                .setLoginRequired(false)
×
90
                .setSendMail(true)
×
91
                .setMessage("test");
×
92
        collectionService.shareCollection(collectionShareQuery);
×
93

94
        // addMediaToCollection
95
        String addMediaToCollectionId = appProperties.getProperty("ADD_MEDIA_TO_COLLECTION_COLLECTION_ID");
×
96
        String mediaIdToAdd = appProperties.getProperty("ADD_MEDIA_TO_COLLECTION_MEDIA_ID");
×
97
        String[] addMediaIds = new String[] {mediaIdToAdd};
×
98

99
        LOG.info("adding media ids: " + mediaIdToAdd);
×
100
        CollectionAddMediaQuery collectionAddMediaQuery = new CollectionAddMediaQuery(addMediaToCollectionId, addMediaIds);
×
101
        collectionService.addMediaToCollection(collectionAddMediaQuery).blockingSingle();
×
102

103

104
        // get info about collection that had media added
105
        CollectionInfoQuery addMediaCollectionInfoQuery = new CollectionInfoQuery(addMediaToCollectionId);
×
106
        List<String> mediaIdsFromCollection = collectionService.getCollectionMediaIds(addMediaCollectionInfoQuery).blockingSingle().body();
×
107
        for (String mediaId : mediaIdsFromCollection) {
×
108
            LOG.info("media id: " + mediaId);
×
109
        }
×
110

111
        // removeMediaFromCollection
112
        String removeFromCollectionId = appProperties.getProperty("REMOVE_FROM_COLLECTION_ID");
×
113
        String mediaIdToRemove = appProperties.getProperty("REMOVE_MEDIA_ID_FROM_COLLECTION");
×
114
        String[] removeMediaIds = new String[] {mediaIdToRemove};
×
115
        LOG.info("removing media ids: " + mediaIdToRemove);
×
116
        CollectionRemoveMediaQuery collectionRemoveMediaQuery = new CollectionRemoveMediaQuery(removeFromCollectionId, removeMediaIds);
×
117
        collectionService.removeMediaFromCollection(collectionRemoveMediaQuery).blockingSingle();
×
118

119
        // get updated media ids from collection after removal
120
        CollectionInfoQuery removeMediaCollectionInfoQuery = new CollectionInfoQuery(removeFromCollectionId);
×
121
        List<String> mediaIdsFromCollectionAfterRemoval = collectionService.getCollectionMediaIds(removeMediaCollectionInfoQuery).blockingSingle().body();
×
122
        for (String mediaId : mediaIdsFromCollectionAfterRemoval) {
×
123
            LOG.info("media id: " + mediaId);
×
124
        }
×
125
    }
×
126
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc