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

Bynder / bynder-java-sdk / 23809044549

31 Mar 2026 04:48PM UTC coverage: 39.819% (-0.3%) from 40.081%
23809044549

push

github

web-flow
Edit MediaSample.java for MediaQuery with CollectionId (#154)

0 of 13 new or added lines in 1 file covered. (0.0%)

794 of 1994 relevant lines covered (39.82%)

0.4 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/MediaSample.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.Derivative;
7
import com.bynder.sdk.model.DownloadUrl;
8
import com.bynder.sdk.model.Media;
9
import com.bynder.sdk.model.MediaType;
10

11
import com.bynder.sdk.query.*;
12

13
import com.bynder.sdk.service.BynderClient;
14
import com.bynder.sdk.service.asset.AssetService;
15
import com.bynder.sdk.service.oauth.OAuthService;
16
import com.bynder.sdk.util.Utils;
17

18
import java.awt.*;
19
import java.io.IOException;
20
import java.net.URI;
21
import java.net.URISyntaxException;
22
import java.net.URL;
23

24
import java.util.Arrays;
25
import java.util.List;
26
import java.util.Properties;
27
import java.util.Scanner;
28

29
import org.slf4j.Logger;
30
import org.slf4j.LoggerFactory;
31

32
public class MediaSample {
×
33
    private static final Logger LOG = LoggerFactory.getLogger(MediaSample.class);
×
34

35
    public static void main(final String[] args) throws URISyntaxException, IOException {
36
        /**
37
         * Loads app.properties file under src/main/resources
38
         */
39
        Properties appProperties = Utils.loadConfig("app");
×
40

41
        // Initialize BynderClient with OAuth
42
        OAuthSettings oAuthSettings = new OAuthSettings(appProperties.getProperty("CLIENT_ID"), appProperties.getProperty("CLIENT_SECRET"), new URI(appProperties.getProperty("REDIRECT_URI")));
×
43
        BynderClient client = BynderClient.Builder.create(
×
44
                new Configuration.Builder(new URL(appProperties.getProperty("BASE_URL")))
×
45
                        .setOAuthSettings(oAuthSettings)
×
46
                        .setHttpConnectionSettings(new HttpConnectionSettings()).build());
×
47
        List<String> scopes = Arrays.asList("offline", "asset:read", "asset:write", "asset.usage:read",
×
48
                "asset.usage:write", "collection:read", "collection:write", "meta.assetbank:read",
49
                "meta.assetbank:write", "meta.workflow:read");
50

51
        // Initialize OAuthService
52
        OAuthService oauthService = client.getOAuthService();
×
53
        URL authorizationUrl = oauthService.getAuthorizationUrl("state example", scopes);
×
54

55
        // Open browser with authorization URL
56
        Desktop desktop = Desktop.getDesktop();
×
57
        desktop.browse(authorizationUrl.toURI());
×
58

59
        // Ask for the code returned in the redirect URI
60
        System.out.println("Insert the code: ");
×
61
        Scanner scanner = new Scanner(System.in);
×
62
        String code = scanner.nextLine();
×
63
        scanner.close();
×
64

65
        // Get the access token
66
        oauthService.getAccessToken(code, scopes).blockingSingle();
×
67

68
        // Initialize asset service
69
        AssetService assetService = client.getAssetService();
×
70

71
        // get derivatives
72
        List<Derivative> derivatives = client.getDerivatives().blockingSingle().body();
×
73
        if (derivatives != null && !derivatives.isEmpty()) {
×
74
            for (Derivative derivative : derivatives) {
×
75
                LOG.info("Derivative Prefix: " + derivative.getPrefix());
×
76
            }
×
77
        }
78

79
        // Call the API to request for media assets
80
        MediaQuery mediaQuery =  new MediaQuery().setType(MediaType.IMAGE).setOrderBy(OrderBy.NAME_DESC).setLimit(10).setPage(1);
×
81
        List<Media> mediaList = assetService.getMediaList(mediaQuery).blockingSingle().body();
×
82
        if (mediaList != null && !mediaList.isEmpty()) {
×
83
            for (Media media : mediaList) {
×
84
                LOG.info("Media ID: " + media.getId());
×
85
                LOG.info("Media Name: " + media.getName());
×
86
            }
×
87
        }
88

89
        // Call the API to request for media assets filtered by collection ID
NEW
90
        String collectionIdForFilter = appProperties.getProperty("GET_COLLECTION_INFO_ID");
×
NEW
91
        MediaQuery mediaQueryByCollection = new MediaQuery()
×
NEW
92
                .setCollectionId(collectionIdForFilter)
×
NEW
93
                .setLimit(10)
×
NEW
94
                .setPage(1);
×
NEW
95
        List<Media> mediaListFromCollection = assetService.getMediaList(mediaQueryByCollection).blockingSingle().body();
×
NEW
96
        if (mediaListFromCollection != null && !mediaListFromCollection.isEmpty()) {
×
NEW
97
            LOG.info("Media assets filtered by collection ID: " + collectionIdForFilter);
×
NEW
98
            for (Media media : mediaListFromCollection) {
×
NEW
99
                LOG.info("Media ID: " + media.getId());
×
NEW
100
                LOG.info("Media Name: " + media.getName());
×
NEW
101
            }
×
102
        } else {
NEW
103
            LOG.info("No media found in collection: " + collectionIdForFilter);
×
104
        }
105

106
        // get media info for single asset
107
        String mediaIdInfo = appProperties.getProperty("MEDIA_ID_FOR_INFO");
×
108
        MediaInfoQuery mediaInfoQuery = new MediaInfoQuery(mediaIdInfo);
×
109
        Media foundMedia = assetService.getMediaInfo(mediaInfoQuery).blockingSingle().body();
×
110
        if (foundMedia != null) {
×
111
            LOG.info("get media info result: ");
×
112
            LOG.info("Media ID: " + foundMedia.getId());
×
113
            LOG.info("Media Name: " + foundMedia.getName());
×
114
            LOG.info("Media Brand ID: " + foundMedia.getBrandId());
×
115
        }
116

117
        // get media download url
118
        MediaDownloadQuery mediaDownloadQuery = new MediaDownloadQuery(mediaIdInfo);
×
119
        DownloadUrl mediaDownloadUrl = assetService.getMediaDownloadUrl(mediaDownloadQuery).blockingSingle().body();
×
120
        if (mediaDownloadUrl != null) {
×
121
            LOG.info("Media S3 File: " + mediaDownloadUrl.getS3File().getFile());
×
122
            LOG.info("Media S3 URI: " + mediaDownloadUrl.getS3File().toURI());
×
123
        }
124

125
        // modify name of asset
126
        String mediaIdForRename = appProperties.getProperty("MEDIA_ID_FOR_RENAME");
×
127
        MediaModifyQuery modifyQuery = new MediaModifyQuery(mediaIdForRename)
×
128
                .setName("New Name Updated")
×
129
                .setDescription("Test Updated Description");
×
130
        assetService.modifyMedia(modifyQuery).blockingSingle();
×
131

132
        MediaInfoQuery mediaInfoQueryRename = new MediaInfoQuery(mediaIdForRename);
×
133
        Media updatedFoundMedia = assetService.getMediaInfo(mediaInfoQueryRename).blockingSingle().body();
×
134
        if (updatedFoundMedia != null) {
×
135
            LOG.info("get updated media info result: ");
×
136
            LOG.info(updatedFoundMedia.getId());
×
137
            LOG.info(updatedFoundMedia.getName());
×
138
            LOG.info(updatedFoundMedia.getDescription());
×
139
        }
140

141
        // remove media
142
        String mediaToRemove = appProperties.getProperty("MEDIA_ID_FOR_REMOVAL");
×
143
        MediaDeleteQuery mediaDeleteQuery = new MediaDeleteQuery(mediaToRemove);
×
144
        LOG.info("Removing media id: " + mediaToRemove);
×
145
        assetService.deleteMedia(mediaDeleteQuery).blockingSingle();
×
146
        System.exit(0);
×
147
    }
×
148
}
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