Skip to content

Commit

Permalink
API-1822 update collections sample with share, add media, remove media
Browse files Browse the repository at this point in the history
  • Loading branch information
ahongbynder committed Nov 30, 2023
1 parent 62dadc5 commit 333d958
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/main/java/com/bynder/sdk/sample/CollectionsSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ public static void main(final String[] args) throws URISyntaxException, IOExcept
// Initialize collection service
CollectionService collectionService = client.getCollectionService();

// get collections
CollectionQuery collectionQuery = new CollectionQuery();
// get collections with limit
CollectionQuery collectionQuery = new CollectionQuery().setLimit(20);
List<Collection> collections = collectionService.getCollections(collectionQuery).blockingSingle().body();
if (collections != null && !collections.isEmpty()) {
for (Collection collectionResult : collections) {
LOG.info("collection: ");
LOG.info(collectionResult.getId());
LOG.info(collectionResult.getName());
LOG.info(collectionResult.getDescription());
LOG.info("Collection ID: " + collectionResult.getId());
LOG.info("Collection Name: " + collectionResult.getName());
LOG.info("Collection Description: " + collectionResult.getDescription());
LOG.info("Collection Media Count: " + collectionResult.getMediaCount());
LOG.info("Collection Date Created: " + collectionResult.getDateCreated());
}
}

Expand All @@ -53,8 +54,8 @@ public static void main(final String[] args) throws URISyntaxException, IOExcept
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());
LOG.info("Collection Info Name: " + collectionInfo.getName());
LOG.info("Collection Info Description: " + collectionInfo.getDescription());
}

// create collection
Expand All @@ -69,40 +70,38 @@ public static void main(final String[] args) throws URISyntaxException, IOExcept
List<Collection> updatedCollections = collectionService.getCollections(collectionQuery).blockingSingle().body();
if (updatedCollections != null && !updatedCollections.isEmpty()) {
for (Collection collectionResult : updatedCollections) {
LOG.info("collection: ");
LOG.info(collectionResult.getId());
LOG.info(collectionResult.getName());
LOG.info(collectionResult.getDescription());
LOG.info("Collection ID: " + collectionResult.getId());
LOG.info("Collection Name: " + collectionResult.getName());
LOG.info("Collection Description: " + collectionResult.getDescription());
LOG.info("Collection Media Count: " + collectionResult.getMediaCount());
LOG.info("Collection Date Created: " + collectionResult.getDateCreated());
}
}

// 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)
LOG.info("sharing collection id: " + shareCollectionId);
String collectionShareRecipient = appProperties.getProperty("COLLECTION_SHARE_RECIPIENT");
String[] shareCollectionRecipients = new String[] {collectionShareRecipient};

// allow recipient to view, login required false, send email with message "test"
CollectionShareQuery collectionShareQuery = new CollectionShareQuery(shareCollectionId, shareCollectionRecipients, CollectionRecipientRight.VIEW)
.setLoginRequired(false)
.setSendMail(true)
.setMessage("test");
collectionService.shareCollection(collectionShareQuery).blockingSingle();
collectionService.shareCollection(collectionShareQuery);

// 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);
}

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


// get info about collection that had media added
CollectionInfoQuery addMediaCollectionInfoQuery = new CollectionInfoQuery(addMediaToCollectionId);
List<String> mediaIdsFromCollection = collectionService.getCollectionMediaIds(addMediaCollectionInfoQuery).blockingSingle().body();
for (String mediaId : mediaIdsFromCollection) {
Expand All @@ -117,6 +116,7 @@ public static void main(final String[] args) throws URISyntaxException, IOExcept
CollectionRemoveMediaQuery collectionRemoveMediaQuery = new CollectionRemoveMediaQuery(removeFromCollectionId, removeMediaIds);
collectionService.removeMediaFromCollection(collectionRemoveMediaQuery).blockingSingle();

// get updated media ids from collection after removal
CollectionInfoQuery removeMediaCollectionInfoQuery = new CollectionInfoQuery(removeFromCollectionId);
List<String> mediaIdsFromCollectionAfterRemoval = collectionService.getCollectionMediaIds(removeMediaCollectionInfoQuery).blockingSingle().body();
for (String mediaId : mediaIdsFromCollectionAfterRemoval) {
Expand Down

0 comments on commit 333d958

Please sign in to comment.