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

Bynder / bynder-java-sdk / 7064590536

01 Dec 2023 07:59PM UTC coverage: 38.837% (-0.1%) from 38.965%
7064590536

push

github

ahongbynder
API-1822 add media removal, add README, add null checks for collections

0 of 14 new or added lines in 2 files covered. (0.0%)

1 existing line in 1 file now uncovered.

708 of 1823 relevant lines covered (38.84%)

0.39 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.configuration.HttpConnectionSettings;
5
import com.bynder.sdk.configuration.OAuthSettings;
6
import com.bynder.sdk.model.Collection;
7
import com.bynder.sdk.query.collection.*;
8
import com.bynder.sdk.service.BynderClient;
9
import com.bynder.sdk.service.collection.CollectionService;
10
import com.bynder.sdk.service.oauth.OAuthService;
11
import com.bynder.sdk.util.Utils;
12

13
import java.awt.*;
14
import java.io.IOException;
15
import java.net.URI;
16
import java.net.URISyntaxException;
17
import java.net.URL;
18

19
import java.util.*;
20
import java.util.List;
21

22
import org.slf4j.Logger;
23
import org.slf4j.LoggerFactory;
24

25
public class CollectionsSample {
×
26
    private static final Logger LOG = LoggerFactory.getLogger(CollectionsSample.class);
×
27

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

34
        // Initialize BynderClient with OAuth
35
        OAuthSettings oAuthSettings = new OAuthSettings(appProperties.getProperty("CLIENT_ID"), appProperties.getProperty("CLIENT_SECRET"), new URI(appProperties.getProperty("REDIRECT_URI")));
×
36
        BynderClient client = BynderClient.Builder.create(
×
37
                new Configuration.Builder(new URL(appProperties.getProperty("BASE_URL")))
×
38
                        .setOAuthSettings(oAuthSettings)
×
39
                        .setHttpConnectionSettings(new HttpConnectionSettings()).build());
×
40
        List<String> scopes = Arrays.asList("offline", "asset:read", "asset:write", "asset.usage:read",
×
41
                "asset.usage:write", "collection:read", "collection:write", "meta.assetbank:read",
42
                "meta.assetbank:write", "meta.workflow:read");
43

44
        // Initialize OAuthService
45
        OAuthService oauthService = client.getOAuthService();
×
46
        URL authorizationUrl = oauthService.getAuthorizationUrl("state example", scopes);
×
47

48
        // Open browser with authorization URL
49
        Desktop desktop = Desktop.getDesktop();
×
50
        desktop.browse(authorizationUrl.toURI());
×
51

52
        // Ask for the code returned in the redirect URI
53
        System.out.println("Insert the code: ");
×
54
        Scanner scanner = new Scanner(System.in);
×
55
        String code = scanner.nextLine();
×
56
        scanner.close();
×
57

58
        // Get the access token
59
        oauthService.getAccessToken(code, scopes).blockingSingle();
×
60

61
        // Initialize collection service
62
        CollectionService collectionService = client.getCollectionService();
×
63

64
        // get collections with limit
65
        CollectionQuery collectionQuery = new CollectionQuery().setLimit(20);
×
66
        List<Collection> collections = collectionService.getCollections(collectionQuery).blockingSingle().body();
×
67
        if (collections != null && !collections.isEmpty()) {
×
68
            for (Collection collectionResult : collections) {
×
69
                LOG.info("Collection ID: " + collectionResult.getId());
×
70
                LOG.info("Collection Name: " + collectionResult.getName());
×
71
                LOG.info("Collection Description: " + collectionResult.getDescription());
×
72
                LOG.info("Collection Media Count: " + collectionResult.getMediaCount());
×
73
                LOG.info("Collection Date Created: " + collectionResult.getDateCreated());
×
74
            }
×
75
        }
76

77
        // get collection info
78
        String collectionInfoId = appProperties.getProperty("GET_COLLECTION_INFO_ID");
×
79
        CollectionInfoQuery collectionInfoQuery = new CollectionInfoQuery(collectionInfoId);
×
80
        Collection collectionInfo = collectionService.getCollectionInfo(collectionInfoQuery).blockingSingle().body();
×
81
        if (collectionInfo != null) {
×
82
            LOG.info("Collection Info Name: " + collectionInfo.getName());
×
83
            LOG.info("Collection Info Description: " + collectionInfo.getDescription());
×
84
        }
85

86
        // create collection
87
        Random random = new Random();
×
88
        int randomInt = random.nextInt(100);
×
89
        String newCollectionName = "New Collection" + randomInt;
×
90
        LOG.info("new collection name: " + newCollectionName);
×
91
        CollectionCreateQuery createCollectionQuery = new CollectionCreateQuery(newCollectionName);
×
92
        collectionService.createCollection(createCollectionQuery).blockingSingle();
×
93

94
        // get collections with added collection
95
        List<Collection> updatedCollections = collectionService.getCollections(collectionQuery).blockingSingle().body();
×
96
        if (updatedCollections != null && !updatedCollections.isEmpty()) {
×
97
            for (Collection collectionResult : updatedCollections) {
×
98
                LOG.info("Collection ID: " + collectionResult.getId());
×
99
                LOG.info("Collection Name: " + collectionResult.getName());
×
100
                LOG.info("Collection Description: " + collectionResult.getDescription());
×
101
                LOG.info("Collection Media Count: " + collectionResult.getMediaCount());
×
102
                LOG.info("Collection Date Created: " + collectionResult.getDateCreated());
×
103
            }
×
104
        }
105

106
        // share collection to recipients
107
        String shareCollectionId = appProperties.getProperty("SHARE_COLLECTION_ID");
×
108
        LOG.info("sharing collection id: " + shareCollectionId);
×
109
        String collectionShareRecipient = appProperties.getProperty("COLLECTION_SHARE_RECIPIENT");
×
110
        String[] shareCollectionRecipients = new String[] {collectionShareRecipient};
×
111

112
        // allow recipient to view, login required false, send email with message "test"
113
        CollectionShareQuery collectionShareQuery = new CollectionShareQuery(shareCollectionId, shareCollectionRecipients, CollectionRecipientRight.VIEW)
×
114
                .setLoginRequired(false)
×
115
                .setSendMail(true)
×
116
                .setMessage("test");
×
NEW
117
        collectionService.shareCollection(collectionShareQuery).blockingSingle();
×
118

119
        // addMediaToCollection
120
        String addMediaToCollectionId = appProperties.getProperty("ADD_MEDIA_TO_COLLECTION_COLLECTION_ID");
×
121
        String mediaIdToAdd = appProperties.getProperty("ADD_MEDIA_TO_COLLECTION_MEDIA_ID");
×
122
        String[] addMediaIds = new String[] {mediaIdToAdd};
×
123

124
        LOG.info("adding media ids: " + mediaIdToAdd);
×
125
        CollectionAddMediaQuery collectionAddMediaQuery = new CollectionAddMediaQuery(addMediaToCollectionId, addMediaIds);
×
126
        collectionService.addMediaToCollection(collectionAddMediaQuery).blockingSingle();
×
127

128

129
        // get info about collection that had media added
130
        CollectionInfoQuery addMediaCollectionInfoQuery = new CollectionInfoQuery(addMediaToCollectionId);
×
131
        List<String> mediaIdsFromCollection = collectionService.getCollectionMediaIds(addMediaCollectionInfoQuery).blockingSingle().body();
×
NEW
132
        if (mediaIdsFromCollection != null && !mediaIdsFromCollection.isEmpty()) {
×
NEW
133
            for (String mediaId : mediaIdsFromCollection) {
×
NEW
134
                LOG.info("media id: " + mediaId);
×
NEW
135
            }
×
136
        }
137

138
        // removeMediaFromCollection
139
        String removeFromCollectionId = appProperties.getProperty("REMOVE_FROM_COLLECTION_ID");
×
140
        String mediaIdToRemove = appProperties.getProperty("REMOVE_MEDIA_ID_FROM_COLLECTION");
×
141
        String[] removeMediaIds = new String[] {mediaIdToRemove};
×
142
        LOG.info("removing media ids: " + mediaIdToRemove);
×
143
        CollectionRemoveMediaQuery collectionRemoveMediaQuery = new CollectionRemoveMediaQuery(removeFromCollectionId, removeMediaIds);
×
NEW
144
        collectionService.removeMediaFromCollection(collectionRemoveMediaQuery);
×
145

146
        // get updated media ids from collection after removal
147
        CollectionInfoQuery removeMediaCollectionInfoQuery = new CollectionInfoQuery(removeFromCollectionId);
×
148
        List<String> mediaIdsFromCollectionAfterRemoval = collectionService.getCollectionMediaIds(removeMediaCollectionInfoQuery).blockingSingle().body();
×
NEW
149
        if (mediaIdsFromCollectionAfterRemoval != null && !mediaIdsFromCollectionAfterRemoval.isEmpty()) {
×
NEW
150
            for (String mediaId : mediaIdsFromCollectionAfterRemoval) {
×
NEW
151
                LOG.info("media id: " + mediaId);
×
NEW
152
            }
×
153
        }
154
    }
×
155
}
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