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

Bynder / bynder-java-sdk / 7130807638

07 Dec 2023 04:07PM UTC coverage: 38.562%. First build
7130807638

push

github

web-flow
API-1822 [BE] [SDK] Implement Sample Files for JAVA-SDK Functionality Testing (#114)

* API-1822 setup sample files for java sdk api calls

* API-1822 add upload sample, smart filters sample, usage sample

* API-1822 add metaproperties sample, update logging for samples, setup methods for collection sample

* API-1822 update collections sample with share, add media, remove media

* API-1822 resolve package name

* API-1822 setup asset usage sample

* API-1822 use OAuth for client, add testasset image for upload

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

* API-1822 update readme for sample files

* API-1822 get derivatives for portal

* API-1822 update readme for derivatives method

* API-1822 cleanup

* API-1822 add System.exit(0) to terminate processes

* API-1822 cleanup

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/UsageSample.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.Usage;
7
import com.bynder.sdk.query.UsageCreateQuery;
8
import com.bynder.sdk.query.UsageDeleteQuery;
9
import com.bynder.sdk.query.UsageQuery;
10
import com.bynder.sdk.service.BynderClient;
11
import com.bynder.sdk.service.asset.AssetService;
12
import com.bynder.sdk.service.oauth.OAuthService;
13
import com.bynder.sdk.util.Utils;
14

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

21
import java.util.Arrays;
22
import java.util.List;
23
import java.util.Properties;
24
import java.util.Scanner;
25

26
import org.slf4j.Logger;
27
import org.slf4j.LoggerFactory;
NEW
28
public class UsageSample {
×
NEW
29
    private static final Logger LOG = LoggerFactory.getLogger(UsageSample.class);
×
30

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

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

48
        // Initialize OAuthService
NEW
49
        OAuthService oauthService = client.getOAuthService();
×
NEW
50
        URL authorizationUrl = oauthService.getAuthorizationUrl("state example", scopes);
×
51

52
        // Open browser with authorization URL
NEW
53
        Desktop desktop = Desktop.getDesktop();
×
NEW
54
        desktop.browse(authorizationUrl.toURI());
×
55

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

62
        // Get the access token
NEW
63
        oauthService.getAccessToken(code, scopes).blockingSingle();
×
64

65
        // Initialize asset service
NEW
66
        AssetService assetService = client.getAssetService();
×
67

68
        // create usage
NEW
69
        String mediaIdForAssetUsage = appProperties.getProperty("MEDIA_ID_FOR_ASSET_USAGE");
×
NEW
70
        String integrationIdForAssetUsage = appProperties.getProperty("INTEGRATION_ID_FOR_ASSET_USAGE");
×
71

NEW
72
        UsageCreateQuery usageCreateQuery = new UsageCreateQuery(integrationIdForAssetUsage, mediaIdForAssetUsage);
×
NEW
73
        Usage createdAssetUsage = assetService.createUsage(usageCreateQuery).blockingSingle().body();
×
NEW
74
        if (createdAssetUsage != null) {
×
NEW
75
            LOG.info("Asset Usage ID: " + createdAssetUsage.getId());
×
NEW
76
            LOG.info("Asset Usage Asset ID: " + createdAssetUsage.getAssetId());
×
77
        }
78

79
        // get asset usages
NEW
80
        UsageQuery usageQuery= new UsageQuery().setAssetId(mediaIdForAssetUsage);
×
NEW
81
        List<Usage> assetUsages = assetService.getUsage(usageQuery).blockingSingle().body();
×
82

NEW
83
        if (assetUsages != null && !assetUsages.isEmpty()) {
×
NEW
84
            String deleteAssetUsageId = "";
×
NEW
85
            for (Usage assetUsage : assetUsages) {
×
NEW
86
                LOG.info("Asset Usage ID: " + assetUsage.getId());
×
NEW
87
                deleteAssetUsageId = assetUsage.getAssetId();
×
NEW
88
                LOG.info(assetUsage.getAssetId());
×
NEW
89
            }
×
90

91
            // delete asset usage
NEW
92
            UsageDeleteQuery usageDeleteQuery = new UsageDeleteQuery(integrationIdForAssetUsage, deleteAssetUsageId);
×
NEW
93
            LOG.info("Deleting asset usage id: " + deleteAssetUsageId);
×
NEW
94
            assetService.deleteUsage(usageDeleteQuery);
×
95
        }
NEW
96
        System.exit(0);
×
NEW
97
    }
×
98
}
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