Skip to content

Commit

Permalink
API-1822 add metaproperties sample, update logging for samples, setup…
Browse files Browse the repository at this point in the history
… methods for collection sample
  • Loading branch information
ahongbynder committed Nov 30, 2023
1 parent c7bb558 commit 62dadc5
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 64 deletions.
10 changes: 6 additions & 4 deletions src/main/java/com/bynder/sdk/sample/BrandsSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ public static void main(final String[] args) throws URISyntaxException, IOExcept

// Call the API to request for brands
List<Brand> brands = assetService.getBrands().blockingSingle().body();
LOG.info("brands");
for (Brand brand : brands) {
LOG.info(brand.getName());
LOG.info(brand.getDescription());
if (brands != null && !brands.isEmpty()) {
for (Brand brand : brands) {
LOG.info("Brand ID: " + brand.getId());
LOG.info("Brand Name: " + brand.getName());
LOG.info("Brand Description: " + brand.getDescription());
}
}
}
}
99 changes: 79 additions & 20 deletions src/main/java/com/bynder/sdk/sample/CollectionsSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

import com.bynder.sdk.configuration.Configuration;
import com.bynder.sdk.model.Collection;
import com.bynder.sdk.query.collection.*;
import com.bynder.sdk.service.BynderClient;
import com.bynder.sdk.service.collection.CollectionService;
import com.bynder.sdk.query.collection.CollectionQuery;
import com.bynder.sdk.query.collection.CollectionCreateQuery;
import com.bynder.sdk.util.Utils;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;

import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Random;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -37,31 +36,91 @@ public static void main(final String[] args) throws URISyntaxException, IOExcept
// Initialize collection service
CollectionService collectionService = client.getCollectionService();

// get collections with limit and page
CollectionQuery collectionQuery = new CollectionQuery().setLimit(10).setPage(1);
// get collections
CollectionQuery collectionQuery = new CollectionQuery();
List<Collection> collections = collectionService.getCollections(collectionQuery).blockingSingle().body();
for (Collection collectionResult : collections) {
LOG.info("collection: ");
LOG.info(collectionResult.getId());
LOG.info(collectionResult.getName());
LOG.info(collectionResult.getDescription());
if (collections != null && !collections.isEmpty()) {
for (Collection collectionResult : collections) {
LOG.info("collection: ");
LOG.info(collectionResult.getId());
LOG.info(collectionResult.getName());
LOG.info(collectionResult.getDescription());
}
}

// add collection
CollectionCreateQuery createCollectionQuery = new CollectionCreateQuery("New Collection 1234");
// get collection info
String collectionInfoId = appProperties.getProperty("GET_COLLECTION_INFO_ID");
CollectionInfoQuery collectionInfoQuery = new CollectionInfoQuery(collectionInfoId);
Collection collectionInfo = collectionService.getCollectionInfo(collectionInfoQuery).blockingSingle().body();
if (collectionInfo != null) {
LOG.info("collection info name: " + collectionInfo.getName());
LOG.info("collection description: " + collectionInfo.getDescription());
}

// create collection
Random random = new Random();
int randomInt = random.nextInt(100);
String newCollectionName = "New Collection" + randomInt;
LOG.info("new collection name: " + newCollectionName);
CollectionCreateQuery createCollectionQuery = new CollectionCreateQuery(newCollectionName);
collectionService.createCollection(createCollectionQuery).blockingSingle();

// get collections with added collection
List<Collection> updatedCollections = collectionService.getCollections(collectionQuery).blockingSingle().body();
for (Collection collectionResult : collections) {
LOG.info("collection: ");
LOG.info(collectionResult.getId());
LOG.info(collectionResult.getName());
LOG.info(collectionResult.getDescription());
if (updatedCollections != null && !updatedCollections.isEmpty()) {
for (Collection collectionResult : updatedCollections) {
LOG.info("collection: ");
LOG.info(collectionResult.getId());
LOG.info(collectionResult.getName());
LOG.info(collectionResult.getDescription());
}
}

// TODO resolve collection methods

// share collection to recipients
String shareCollectionId = appProperties.getProperty("SHARE_COLLECTION_ID");
LOG.info("trying to share collection id: " + shareCollectionId);
String[] shareCollectionRecipients = new String[] {"[email protected]"};
CollectionRecipientRight recipientRight = CollectionRecipientRight.EDIT;
CollectionShareQuery collectionShareQuery = new CollectionShareQuery(shareCollectionId, shareCollectionRecipients, recipientRight)
.setLoginRequired(false)
.setSendMail(true)
.setMessage("test");
collectionService.shareCollection(collectionShareQuery).blockingSingle();

// addMediaToCollection
String addMediaToCollectionId = appProperties.getProperty("ADD_MEDIA_TO_COLLECTION_COLLECTION_ID");
String mediaIdToAdd = appProperties.getProperty("ADD_MEDIA_TO_COLLECTION_MEDIA_ID");
String[] addMediaIds = new String[] {mediaIdToAdd};

for (String mediaId : addMediaIds) {
LOG.info("test: " + mediaId);
}

// TODO addMediaToCollection
// TODO removeMediaFromCollection
// TODO shareCollection
LOG.info("adding media ids: " + mediaIdToAdd);
CollectionAddMediaQuery collectionAddMediaQuery = new CollectionAddMediaQuery(addMediaToCollectionId, addMediaIds);
collectionService.addMediaToCollection(collectionAddMediaQuery).blockingSingle();


CollectionInfoQuery addMediaCollectionInfoQuery = new CollectionInfoQuery(addMediaToCollectionId);
List<String> mediaIdsFromCollection = collectionService.getCollectionMediaIds(addMediaCollectionInfoQuery).blockingSingle().body();
for (String mediaId : mediaIdsFromCollection) {
LOG.info("media id: " + mediaId);
}

// removeMediaFromCollection
String removeFromCollectionId = appProperties.getProperty("REMOVE_FROM_COLLECTION_ID");
String mediaIdToRemove = appProperties.getProperty("REMOVE_MEDIA_ID_FROM_COLLECTION");
String[] removeMediaIds = new String[] {mediaIdToRemove};
LOG.info("removing media ids: " + mediaIdToRemove);
CollectionRemoveMediaQuery collectionRemoveMediaQuery = new CollectionRemoveMediaQuery(removeFromCollectionId, removeMediaIds);
collectionService.removeMediaFromCollection(collectionRemoveMediaQuery).blockingSingle();

CollectionInfoQuery removeMediaCollectionInfoQuery = new CollectionInfoQuery(removeFromCollectionId);
List<String> mediaIdsFromCollectionAfterRemoval = collectionService.getCollectionMediaIds(removeMediaCollectionInfoQuery).blockingSingle().body();
for (String mediaId : mediaIdsFromCollectionAfterRemoval) {
LOG.info("media id: " + mediaId);
}
}
}
38 changes: 24 additions & 14 deletions src/main/java/com/bynder/sdk/sample/MediaSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,38 @@ public static void main(final String[] args) throws URISyntaxException, IOExcept
// Call the API to request for media assets
MediaQuery mediaQuery = new MediaQuery().setType(MediaType.IMAGE).setOrderBy(OrderBy.NAME_DESC).setLimit(10).setPage(1);
List<Media> mediaList = assetService.getMediaList(mediaQuery).blockingSingle().body();
for (Media media : mediaList) {
LOG.info(media.getId());
LOG.info(media.getName());
if (mediaList != null && !mediaList.isEmpty()) {
for (Media media : mediaList) {
LOG.info(media.getId());
LOG.info(media.getName());
}
}

if (!mediaList.isEmpty()) {
// get media info for single asset
String mediaId = mediaList.get(0).getId();
MediaInfoQuery mediaInfoQuery = new MediaInfoQuery(mediaId);
Media foundMedia = assetService.getMediaInfo(mediaInfoQuery).blockingSingle().body();
// get media info for single asset
String mediaIdInfo = appProperties.getProperty("MEDIA_ID_FOR_INFO");
MediaInfoQuery mediaInfoQuery = new MediaInfoQuery(mediaIdInfo);
Media foundMedia = assetService.getMediaInfo(mediaInfoQuery).blockingSingle().body();
if (foundMedia != null) {
LOG.info("get media info result: ");
LOG.info(foundMedia.getId());
LOG.info(foundMedia.getName());
LOG.info("Media ID: " + foundMedia.getId());
LOG.info("Media Name: " + foundMedia.getName());
LOG.info("Media Brand ID: " + foundMedia.getBrandId());
}

// modify name of asset
MediaModifyQuery modifyQuery = new MediaModifyQuery(mediaId).setName("New Name");
assetService.modifyMedia(modifyQuery).blockingSingle();
// modify name of asset
String mediaIdForRename = appProperties.getProperty("MEDIA_ID_FOR_RENAME");
MediaModifyQuery modifyQuery = new MediaModifyQuery(mediaIdForRename)
.setName("New Name Updated")
.setDescription("Test Updated Description");
assetService.modifyMedia(modifyQuery).blockingSingle();

Media updatedFoundMedia = assetService.getMediaInfo(mediaInfoQuery).blockingSingle().body();
MediaInfoQuery mediaInfoQueryRename = new MediaInfoQuery(mediaIdForRename);
Media updatedFoundMedia = assetService.getMediaInfo(mediaInfoQueryRename).blockingSingle().body();
if (updatedFoundMedia != null) {
LOG.info("get updated media info result: ");
LOG.info(updatedFoundMedia.getId());
LOG.info(updatedFoundMedia.getName());
LOG.info(updatedFoundMedia.getDescription());
}
}
}
66 changes: 66 additions & 0 deletions src/main/java/com/bynder/sdk/sample/MetapropertiesSample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.bynder.sdk.sample;

import com.bynder.sdk.configuration.Configuration;
import com.bynder.sdk.model.Metaproperty;
import com.bynder.sdk.model.MetapropertyOption;
import com.bynder.sdk.query.MetapropertyQuery;
import com.bynder.sdk.service.BynderClient;
import com.bynder.sdk.service.asset.AssetService;
import com.bynder.sdk.util.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.Properties;

public class MetapropertiesSample {
private static final Logger LOG = LoggerFactory.getLogger(MetapropertiesSample.class);

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

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


// Initialize asset service
AssetService assetService = client.getAssetService();

// get metaproperties
MetapropertyQuery metapropertyQuery = new MetapropertyQuery();

Map<String, Metaproperty> metapropertiesMap = assetService.getMetaproperties(metapropertyQuery).blockingSingle().body();

if (metapropertiesMap != null) {
for (Map.Entry<String, Metaproperty> metapropertyEntry : metapropertiesMap.entrySet()) {
LOG.info("current metaproperty");
LOG.info("Key: " + metapropertyEntry.getKey());
Metaproperty currentMetaproperty = metapropertyEntry.getValue();

LOG.info("ID: " + currentMetaproperty.getId());
LOG.info("Name: " + currentMetaproperty.getName());
LOG.info("Label: " + currentMetaproperty.getLabel());
LOG.info("Type: " + currentMetaproperty.getType());
List<MetapropertyOption> metapropertyOptionList = currentMetaproperty.getOptions();

// metaproperty options if found
if (metapropertyOptionList != null && !metapropertyOptionList.isEmpty()) {
for (MetapropertyOption metapropertyOption : metapropertyOptionList) {
LOG.info("Metaproperty Option ID: " + metapropertyOption.getId());
LOG.info("Metaproperty Option Label: " + metapropertyOption.getLabel());
LOG.info("Metaproperty Name: " + metapropertyOption.getName());
}
}
}
}
}
}
29 changes: 15 additions & 14 deletions src/main/java/com/bynder/sdk/sample/SmartFiltersSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,23 @@ public static void main(final String[] args) throws URISyntaxException, IOExcept
AssetService assetService = client.getAssetService();

List<Smartfilter> smartFilters = assetService.getSmartfilters().blockingSingle().body();
for (Smartfilter smartFilter : smartFilters) {
LOG.info(smartFilter.getId());
// smart filter metaproperties
List<String> smartFilterMetaproperties = smartFilter.getMetaproperties();
if (!smartFilterMetaproperties.isEmpty()) {
LOG.info("smart filter metaproperty ids:");
for (String metaproperty : smartFilterMetaproperties) {
LOG.info(metaproperty);
if (smartFilters != null && !smartFilters.isEmpty()) {
for (Smartfilter smartFilter : smartFilters) {
LOG.info("Smart Filter ID: " + smartFilter.getId());
// smart filter metaproperties
List<String> smartFilterMetaproperties = smartFilter.getMetaproperties();
if (!smartFilterMetaproperties.isEmpty()) {
LOG.info("smart filter metaproperty ids:");
for (String metaproperty : smartFilterMetaproperties) {
LOG.info("Smart Filter Metaproperty ID: " + metaproperty);
}
}
}

// labels
Map<String, String> smartFilterLabels = smartFilter.getLabels();
for (Map.Entry<String, String> entry : smartFilterLabels.entrySet()) {
LOG.info("smart filter label: ");
LOG.info(entry.getKey() + " " + entry.getValue());
// smart filter labels
Map<String, String> smartFilterLabels = smartFilter.getLabels();
for (Map.Entry<String, String> entry : smartFilterLabels.entrySet()) {
LOG.info("smart filter label: " + entry.getKey() + " " + entry.getValue());
}
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/bynder/sdk/sample/TagsSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ public static void main(final String[] args) throws URISyntaxException, IOExcept

// get tags and media count for each tag
List<Tag> assetTags = assetService.getTags().blockingSingle().body();
for (Tag assetTag : assetTags) {
LOG.info(assetTag.getId());
LOG.info(assetTag.getTag());
LOG.info(String.valueOf(assetTag.getMediaCount()));
if (assetTags != null && !assetTags.isEmpty()) {
for (Tag assetTag : assetTags) {
LOG.info("Asset Tag ID: " + assetTag.getId());
LOG.info("Asset Tag: " + assetTag.getTag());
LOG.info("Asset Tag Media Count: " + assetTag.getMediaCount());
}
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/bynder/sdk/sample/UploadSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public static void main(final String[] args) throws URISyntaxException, IOExcept
// Call the API to request for brands
String brandId = "";
List<Brand> brands = assetService.getBrands().blockingSingle().body();
if (!brands.isEmpty()) {
if (brands != null && !brands.isEmpty()) {
brandId = brands.get(0).getId();
}

String filePath = "src/main/java/com/bynder/sdk/sample/testasset.png";
LOG.info(filePath);
UploadQuery uploadQuery = new UploadQuery(filePath, brandId);
// Add the filename you want specify in this manner
// Add the filename you want to specify in this manner
uploadQuery.setFileName("testasset.png");
SaveMediaResponse saveMediaResponse = assetService.uploadFile(uploadQuery).blockingSingle();
LOG.info(saveMediaResponse.getMediaId());
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/bynder/sdk/sample/UsageSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
import com.bynder.sdk.util.Utils;

import java.io.IOException;
import java.lang.Integer;
import java.net.URISyntaxException;
import java.net.URL;

import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.slf4j.Logger;
Expand All @@ -35,12 +33,15 @@ public static void main(final String[] args) throws URISyntaxException, IOExcept
// Initialize asset service
AssetService assetService = client.getAssetService();

UsageQuery usageQuery= new UsageQuery();
String mediaIdForAssetUsage = appProperties.getProperty("MEDIA_ID_FOR_ASSET_USAGE");
UsageQuery usageQuery= new UsageQuery().setAssetId(mediaIdForAssetUsage);
List<Usage> assetUsages = assetService.getUsage(usageQuery).blockingSingle().body();

// TODO use asset usage
for (Usage assetUsage : assetUsages) {
LOG.info(assetUsage.getAssetId());
if (assetUsages != null && !assetUsages.isEmpty()) {
for (Usage assetUsage : assetUsages) {
LOG.info("Asset Usage ID: " + assetUsage.getId());
LOG.info(assetUsage.getAssetId());
}
}
}
}

0 comments on commit 62dadc5

Please sign in to comment.