Interface | Description |
---|---|
EditorFilter |
Defines the digital asset filter in the digital asset Editor.
|
Class | Description |
---|---|
EditorFilterContext |
Defines the editor filter context.
|
StorageManager |
Defines the
StorageManager to perform actions on physical files based on the drive type. |
Performing actions on media fields:
Get an instance of DigitalAssetComponentServices
:
//Provide component context with the information referring to a specific digital asset component
DigitalAssetComponentContext componentContext = new DigitalAssetComponentContext(
aUserRecord,
aMediaPath,
aSession);
DriveFactory driveFactory = DriveFactoryProvider.getDriveFactory();
//Get instance of DigitalAssetComponentServices
from 'componentContext'
DigitalAssetComponentServices componentController = driveFactory
.getDigitalAssetComponentServices(componentContext);
Upload, attach, detach assets and get digital asset keys attached in a media field:
//Upload and attach asset to records File uploadFile = new File("sampleFile.png"); FileResource fileResource = new FileResource(uploadFile); List<FileResource> fileResources = new ArrayList<FileResource>(); fileResources.add(fileResource); componentController.upload(fileResources, Action.ATTACH); //Attach digital asset to the media field of a record DigitalAssetKey assetKey = new DigitalAssetKey(PrimaryKey.parseString("assetKey")); List<DigitalAssetKey> assetKeys = new ArrayList<DigitalAssetKey>(); assetKeys.add(assetKey); componentController.attach(assetKeys); //Detach digital asset componentController.detach(assetKeys); //Get the digital asset keys attached in the media field of a user record componentController.getDigitalAssetKeys();
Performing actions on drives:
Get instance of DriveManager
:
//Provide DriveContext
with the information referring to a specific drive.
DriveContext driveContext = new DriveContext(
this.userDataset,
this.table,
this.mediaPath,
this.session);
DriveFactory driveFactory = DriveFactoryProvider.getDriveFactory();
DriveManager driveManager = driveFactory.getDriveManager(driveContext);
Actions: create, update, delete and download digital assets:
//Create a new DigitalAsset
File uploadFile = new File("sampleFile.png");
FileResource fileResource = new FileResource(uploadFile);
DigitalAssetSpec digitalAssetSpec = new DigitalAssetSpec(fileResource);
digitalAssetSpec.setLabel(UserMessage.createInfo("new label"));
digitalAssetSpec.setDescription(UserMessage.createInfo("new description"));
DigitalAsset newAsset = driveManager.create(digitalAssetSpec);
//Update a digital asset
newAsset.setState(DigitalAssetState.DEACTIVATED);
newAsset.setLabel(UserMessage.createInfo("updated label"));
newAsset.setDescription(UserMessage.createInfo("updated label"));
driveManager.update(newAsset);
//Delete a digital asset
driveManager.delete(newAsset.getKey());
//Download asset - current version of asset
MediaContent mediaContent = driveManager.getMediaContent(newAsset);
mediaContent.getInputStream();
mediaContent.getContentLength();
Actions: create, update, delete and download digital asset versions:
//Create a new version for a digital asset DigitalAssetKey assetKey = new DigitalAssetKey(PrimaryKey.parseString("assetKey")); File uploadFile = new File("sampleFile.png"); FileResource fileResource = new FileResource(uploadFile); DigitalAssetVersionSpec versionSpec = new DigitalAssetVersionSpec(assetKey, fileResource); versionSpec.setCurrentVersion(true); versionSpec.setComment("comment"); versionSpec.setVersionName("versionName"); DigitalAssetVersion newVersion = driveManager.create(versionSpec); //Update a version newVersion.setComment("new comment"); newVersion.setVersionName("new version name"); driveManager.update(newVersion); //Delete a version driveManager.delete(newVersion.getKey()); //Download version MediaContent mediaContent = driveManager.getMediaContent(newVersion); mediaContent.getInputStream(); mediaContent.getContentLength();
Browsing digital assets in a drive:
//Create a new instance ofSearchFilter
to search digital asset SearchFilter searchFilter = new SearchFilter(); searchFilter.setKeyword("anAssetName"); searchFilter.setExtension("png"); searchFilter.setType("image"); //Filter by creation and updatedDateRange
DateRange creationDateRange = new DateRange(); DateRange updatedDateRange = new DateRange(); searchFilter.setCreationDateRange(creationDateRange); searchFilter.setUpdateDateRange(updatedDateRange); //Filter by tags List<String> tags = new ArrayList<String>(); tags.add("tag"); searchFilter.setTags(tags); //Result of filter will be sorted bySortBy
SortCriteria creationDateSort = new SortCriteria(SortBy.CREATION_DATE, true); SortCriteria physicalNameSort = new SortCriteria(SortBy.PHYSICAL_NAME, true); List<SortCriteria> sortCriterias = new ArrayList<SortCriteria>(); sortCriterias.add(physicalNameSort); sortCriterias.add(creationDateSort); searchFilter.setSortCriterias(sortCriterias); //Search digital asset by 'searchFilter' List<DigitalAsset> digitalAssets = driveManager.search(searchFilter); //Get all active digital assets in Drive List<DigitalAsset> digitalAssetsInDrive = driveManager.getDigitalAssets(); //Look up asset byDigitalAssetKey
DigitalAssetKey assetKey = new DigitalAssetKey(PrimaryKey.parseString("assetKey")); DigitalAsset digitalAsset = driveManager.getDigitalAsset(assetKey);
Implement ResourceIdentifier
:
public final class GoogleResouceIdentifier implements ResourceIdentifier { private final String folderID; public GoogleResouceIdentifier(String folderID) { this.folderID = folderID; } public String format() { return this.folderID; } }
Implement a ResourceIdentifierFactory
public final class GoogleIdentifierFactory implements ResourceIdentifierFactory { public ResourceIdentifier parse(String identifier) { return new GoogleResouceIdentifier(identifier); } }
Implement a StorageManager
public final class GoogleDriveStorageManager extends StorageManager { public ResourceIdentifier upload(Resource resource, ResourceIdentifier target) { try { return this.upload(resource, target.format()); } catch (Exception ex) { TestLogger.getLoggingCategory().error("Upload failed", ex); return null; } } public boolean delete(ResourceIdentifier target) { try { Drive service = GoogleDriveAPIHelper.getInstance().getDriveService(); service.files().delete(target.format()).execute(); return true; } catch (Exception ex) { TestLogger.getLoggingCategory().error("Delete failed", ex); return false; } } public MediaContent getMediaContent(DigitalAsset asset) { Drive service; try { service = GoogleDriveAPIHelper.getInstance().getDriveService(); HttpResponse httpResponse = service.files().get(asset.getExternalID()).executeMedia(); return new MediaContentImpl( httpResponse.getContent(), httpResponse.getHeaders().getContentLength().longValue()); } catch (Exception ex) { TestLogger.getLoggingCategory().error("Failed", ex); return null; } } public MediaContent getMediaContent(DigitalAssetVersion version) { Drive service; try { service = GoogleDriveAPIHelper.getInstance().getDriveService(); HttpResponse httpResponse = service.files().get(version.getExternalId()).executeMedia(); return new MediaContentImpl( httpResponse.getContent(), httpResponse.getHeaders().getContentLength().longValue()); } catch (Exception ex) { TestLogger.getLoggingCategory().error("Failed", ex); return null; } } public ResourceIdentifierFactory getIdentifierFactory() { return new GoogleIdentifierFactory(); } private ResourceIdentifier upload(Resource resource, String folderID) throws Exception { //Build a new authorized API client service. Drive service = GoogleDriveAPIHelper.getInstance().getDriveService(); File googleFile = new File(); googleFile.setName(resource.getFile().getName()); //gooleFile.setParents(Collections.singletonList(folderID)); FileContent mediaContent = new FileContent( this.identifyFileTypeUsingMimetypesFileTypeMap(resource.getFile().getName()), resource.getFile()); File uploadedFile = service.files() .create(gooleFile, mediaContent) .setFields("id") .execute(); ResourceIdentifierFactory googleIdentifierFactory = this.getIdentifierFactory(); return googleIdentifierFactory.parse(uploadedFile.getId()); } private String identifyFileTypeUsingMimetypesFileTypeMap(String fileName) { return new MimetypesFileTypeMap().getContentType(fileName); } }
Register new StorageManager
for the GoogleDrive
DriveType
//get DriveFactory DriveFactory driveFactory = DriveFactoryProvider.getDriveFactory(); //Instance new DriveType and new GoogleDriveStorageManager DriveType googleDriveType = new DriveType("GoogleDrive"); StorageManager googleDriveStorageManager = new GoogleDriveStorageManager(); //register google drive storage manager with the google drive type driveFactory.registerStorageManager(googleDriveType, googleDriveStorageManager); //get storageManager by driveType driveFactory.getStorageManager(googleDriveType);
GoogleDriveStorageManager
implementation.
Please follow the steps below:
DriveManager
or DigitalAssetComponentServices
. Please refer to the
Performing actions on drives and
media type fields section.
Backing up the TIBCO EBX® Digital Asset Manager Add-on dataset:
//UseBackupRestoreFactory
to get an instance ofBackupService
BackupService backupService = BackupRestoreFactory.getBackupService(); //Create a new instance ofBackupSpec
with the name of the backup file, folder for the backup file and EBX® session. BackupSpec backupSpec = new BackupSpec(aSession, "aFileName", aFolder); //Backup the TIBCO EBX® Digital Asset Manager Add-on dataset and return a File as the backup File. File backupFile = backupService.backup(backupSpec);
Restoring a digital asset to a specified location:
//UseBackupRestoreFactory
to get an instance ofRestoreService
RestoreService restoreService = BackupRestoreFactory.getRestoreService(); //Create a new instance ofRestoreSpec
with the location of the backup file and EBX® session RestoreSpec restoreSpec = new RestoreSpec(backupFile, aSession); //Get an instance ofRestoreDetail
RestoreDetail restoreDetail = restoreService.getRestoreDetails(restoreSpec); //Get drives information and input new location for drives List<DriveInformation> driveInformations = restoreDetail.getDriveInformations(); driveInformations.get(0).setNewLocation(aString); //Restore the TIBCO EBX® Digital Asset Manager Add-on dataset with 'restoreDetail' //OperationExecutionStatus
will be returned as the result of the execution. OperationExecutionStatus status = restoreService.restore(restoreDetail);
Implement an EditorFilter
:
public class SampleEditorFilter implements EditorFilter
{
public boolean accept(EditorFilterContext editorFilterContext)
{
try
{
//Get the default directory. If you don't use the EBX® default directory, use DirectoryHandler
or your own implementation of custom directory.
DirectoryDefault directoryDefault = DirectoryDefault
.getInstance(Repository.getDefault());
//Get the author of the digital asset being evaluated
String profileAuthor = editorFilterContext.getDigitalAsset()
.getCurrentVersion()
.getProfileAuthor();
UserReference author = (UserReference) UserReference.parse(profileAuthor);
//Get the roles of the author
List<Role> roles = directoryDefault.getRolesForUser(author);
//Get the current user
UserReference userReference = editorFilterContext.getSession().getUserReference();
for (Role role : roles)
{
//Check whether the current user and author have the same role
if (directoryDefault.isUserInRole(userReference, role))
{
return true;
}
}
}
catch (Exception ex)
{
//Handle any exceptions
}
return false;
}
}