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

Bynder / bynder-java-sdk / 7116807269

06 Dec 2023 03:41PM UTC coverage: 38.562%. First build
7116807269

Pull #114

github

ahongbynder
API-1822 add System.exit(0) to terminate processes
Pull Request #114: API-1822 [BE] [SDK] Implement Sample Files for JAVA-SDK Functionality Testing

0 of 351 new or added lines in 8 files covered. (0.0%)

708 of 1836 relevant lines covered (38.56%)

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

NEW
25
public class CollectionsSample {
×
NEW
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
         */
NEW
32
        Properties appProperties = Utils.loadConfig("app");
×
33

34
        // Initialize BynderClient with OAuth
NEW
35
        OAuthSettings oAuthSettings = new OAuthSettings(appProperties.getProperty("CLIENT_ID"), appProperties.getProperty("CLIENT_SECRET"), new URI(appProperties.getProperty("REDIRECT_URI")));
×
NEW
36
        BynderClient client = BynderClient.Builder.create(
×
NEW
37
                new Configuration.Builder(new URL(appProperties.getProperty("BASE_URL")))
×
NEW
38
                        .setOAuthSettings(oAuthSettings)
×
NEW
39
                        .setHttpConnectionSettings(new HttpConnectionSettings()).build());
×
NEW
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
NEW
45
        OAuthService oauthService = client.getOAuthService();
×
NEW
46
        URL authorizationUrl = oauthService.getAuthorizationUrl("state example", scopes);
×
47

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

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

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

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

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

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

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

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

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

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

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

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

128

129
        // get info about collection that had media added
NEW
130
        CollectionInfoQuery addMediaCollectionInfoQuery = new CollectionInfoQuery(addMediaToCollectionId);
×
NEW
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
NEW
139
        String removeFromCollectionId = appProperties.getProperty("REMOVE_FROM_COLLECTION_ID");
×
NEW
140
        String mediaIdToRemove = appProperties.getProperty("REMOVE_MEDIA_ID_FROM_COLLECTION");
×
NEW
141
        String[] removeMediaIds = new String[] {mediaIdToRemove};
×
NEW
142
        LOG.info("removing media ids: " + mediaIdToRemove);
×
NEW
143
        CollectionRemoveMediaQuery collectionRemoveMediaQuery = new CollectionRemoveMediaQuery(removeFromCollectionId, removeMediaIds);
×
NEW
144
        collectionService.removeMediaFromCollection(collectionRemoveMediaQuery);
×
145

146
        // get updated media ids from collection after removal
NEW
147
        CollectionInfoQuery removeMediaCollectionInfoQuery = new CollectionInfoQuery(removeFromCollectionId);
×
NEW
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
        }
NEW
154
        System.exit(0);
×
NEW
155
    }
×
156
}
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