-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API-1822 add metaproperties sample, update logging for samples, setup…
… methods for collection sample
- Loading branch information
1 parent
c7bb558
commit 62dadc5
Showing
8 changed files
with
205 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters