See: Description
Interface | Description |
---|---|
DigitalAssetMediaContent | Deprecated
Since 1.6.0, use
MediaContent instead. |
Class | Description |
---|---|
AbstractDigitalAssetSpec | Deprecated
Since 1.6.0.
|
Context | Deprecated
Since 1.6.0, use
DriveContext instead. |
DateRange | Deprecated
Since 1.6.0, use
DateRange instead. |
DigitalAsset | Deprecated
Since 1.6.0, use
DigitalAsset instead. |
DigitalAssetContext | Deprecated
Since 1.6.0.
|
DigitalAssetKey | Deprecated
Since 1.6.0, use
DigitalAssetKey instead. |
DigitalAssetSpec | Deprecated
Since 1.6.0, use
DigitalAssetSpec instead. |
DigitalAssetUpdateContext | Deprecated
Since 1.6.0.
|
DigitalAssetVersionContext | Deprecated
Since 1.6.0.
|
DigitalAssetVersionKey | Deprecated
Since 1.6.0, use
DigitalAssetVersionKey instead. |
DigitalAssetVersionSpec | Deprecated
Since 1.6.0, use
DigitalAssetVersionSpec instead. |
DriveFactory | Deprecated
Since 1.6.0, use
DriveFactory instead. |
DriveManager | Deprecated
Since 1.6.0, use
DriveManager instead. |
DriveType | Deprecated
Since 1.6.0, use
DriveType instead. |
MetaData | Deprecated
Since 1.6.0, use
MetaData instead. |
OperationExecutionStatus | Deprecated
Since 1.6.0, use
OperationExecutionStatus instead. |
Permission | Deprecated
Since 1.6.0, use
Permission instead. |
Permission.DrivePermissionBuilder |
A drive permission builder.
|
ResourceIdentifier | Deprecated
Since 1.6.0, use
ResourceIdentifier instead. |
ResourceIdentifierFactory | Deprecated
Since 1.6.0, use
ResourceIdentifierFactory instead. |
SearchContext | Deprecated
Since 1.6.0.
|
SearchFilter | Deprecated
Since 1.6.0, use
SearchFilter instead. |
Size | Deprecated
Since 1.6.0, use
Size instead. |
SortCriteria | Deprecated
Since 1.6.0, use
SortCriteria instead. |
StorageManager | Deprecated
Since 1.6.0, use
StorageManager instead. |
Version | Deprecated
Since 1.6.0, use
DigitalAssetVersion instead. |
Enum | Description |
---|---|
AccessPermission | Deprecated
Since 1.6.0, use
AccessPermission instead. |
DigitalAssetState | Deprecated
Since 1.6.0, use
DigitalAssetState instead. |
SortBy | Deprecated
Since 1.6.0, use
SortBy instead. |
Exception | Description |
---|---|
DAMException | Deprecated
Since 1.6.0, use
DAMException instead. |
Provides features that allow end-users to perform CRUD actions on digital assets and allows users to get the Edit asset service component.
Get the value from the 'MediaType' field:
The data model used in the following example has a table that contains a field with './Media' path, which is associated with {addon.label}'s 'MediaType' field:
Adaptation aRecord = aTable.lookUpAdaptationByPrimaryKey(recordPrimaryKey); SchemaNode schemaNode = aRecord.getSchemaNode().getNode(Path.parse("./Media")); int maxOccurs = schemaNode.getMaxOccurs(); List<MediaType> mediaTypes = new ArrayList<MediaType>(); Object value = aRecord.get(Path.parse("./Media")); if (maxOccurs <= 1) { mediaTypes.add((MediaType) value); } else { mediaTypes.addAll((List<MediaType>) value); }
Get the asset's UUID from the Java bean object 'MediaType':
String assetUUID = aMediaType.getAttachment();
From the asset's UUID, we use the add-on's API to perform operations on assets. Please see the next example for more details.
- The built-in DriveManger used in this example supports upload to the file system. You can use your own DriveManager implementation (See example below):
To use the API, you need to define an API context with parameters:
Session: current session Adaptation: current user dataset Path: field path using 'MediaType' BasedURL: a String that provide user based URL to append to the URL of asset. //Create API context Context context = new Context(session, dataset, mediaFieldPath, "http://www.abc.com");
Create a DriveManager:
DriveManager driveManager = DriveFactory.getDriveManager(aDriveType);
Uploading new asset
File file = new File("/home/ebx/file.png"); DigitalAssetSpec digitalAssetSpec = new DigitalAssetSpec(file, label, description, context); DigitalAsset digitalAsset = driveManager.create(digitalAssetSpec);
Attaching asset
//After uploading, an object DigitalAsset is returned. You can get the digital asset primary key from this. String assetUUID = digitalAsset.getDigitalAssetContext().getDigitalAssetKey().getDigitalAssetPrimaryKey().format(); //Create a new procedure to update new value to the MediaType field. //Note: The Drive of new uploaded asset and the Drive of target 'MediaType' field should be the same. int maxOccurs = aNode.getMaxOccurs(); ValueContextForUpdate contextForUpdate = pContext.getContext(aRecordName); if (maxOccurs <= 1) { MediaType mediaType = new MediaType(); mediaType.setAttachment(assetUUID); contextForUpdate.setValue(mediaType, aPath); } else { List<MediaType> mediaTypes = new ArrayList<MediaType>(); MediaType mediaType = new MediaType(); mediaType.setAttachment(assetUUID); mediaTypes.add(mediaType); contextForUpdate.setValue(mediaTypes, aPath); } aProcedure.doModifyContent(aRecord, contextForUpdate);
Detaching asset
int maxOccurs = aNode.getMaxOccurs(); ValueContextForUpdate contextForUpdate = pContext.getContext(aRecordName); if (maxOccurs <= 1){ MediaType mediaType = new MediaType(); mediaType. setAttachment("anAssetUUID"); contextForUpdate.setValue(mediaType, aPath); } else { List<MediaType> mediaTypes = new ArrayList<MediaType>(); mediaTypes.add(aMediaType); contextForUpdate.setValue(mediaTypes, aPath); } aProcedure.doModifyContent(aRecord, contextForUpdate);
Getting details of an asset
DigitalAssetKey digitalAssetKey = new DigitalAssetKey(aAssetPrimaryKey);//The asset primary key to get its details DigitalAssetContext digitalAssetContext = new DigitalAssetContext(digitalAssetKey,context); DigitalAsset digitalAsset = driveManager.getDigitalAsset(digitalAssetContext );
Importing new version of an asset
File file = new File("/home/ebx/newFile.png"); DigitalAssetKey digitalAssetKey = new DigitalAssetKey(aAssetPrimaryKey);//The asset primary key to create new version DigitalAssetContext digitalAssetContext = new DigitalAssetContext(digitalAssetKey,context); DigitalAssetVersionSpec digitalAssetVersionSpec = new DigitalAssetVersionSpec( aDigitalAssetContext, file, "aBusinessName", "aComment", isCurrentVersion);//Determine if the new version is current version Version version = driveManager.create(digitalAssetVersionSpec);//Validate file and upload new version to current asset
Physically deleting asset
DigitalAssetKey digitalAssetKey = new DigitalAssetKey(aAssetPrimaryKey);//The asset primary key to delete DigitalAssetContext digitalAssetContext = new DigitalAssetContext(digitalAssetKey,context); driveManager.delete(digitalAssetContext);
Logically deleting asset
DigitalAssetUpdateContext updateContext = new DigitalAssetUpdateContext(anAssetContext, "aLabel", "aDescription", DigitalAssetState.DEACTIVATED); driveManager.update(digitalAssetUpdateContext);
Getting asset's content (download)
DigitalAssetKey digitalAssetKey = new DigitalAssetKey(aAssetPrimaryKey); DigitalAssetMediaContent assetContent = driveManager.getDigitalAssetMediaContent(digitalAssetKey); InputStream inputStream = assetContent.getInputStream();//Get inputstream from assetContent to download
Implement DigitalAssetMediaContent
:
public class SampleDigitalAssetMediaContent implements DigitalAssetMediaContent { private final InputStream inputStream; private final long contentLength; public SampleDigitalAssetMediaContent(InputStream inputStream, long contentLength) { this.inputStream = inputStream; this.contentLength = contentLength; } public InputStream getInputStream() { return this.inputStream; } public long getContentLength() { return this.contentLength; } public void closeInputStream() throws DAMException { if (this.inputStream != null) { try { this.inputStream.close(); } catch (IOException ex) { throw new DAMException(ex); } } } }
Implement SampleInternalIdentifierFactory
:
public final class SampleIdentifierFactory extends ResourceIdentifierFactory { public ResourceIdentifier parse(String identifier) { return new SampleIdentifier(identifier); } }
Implement SampleIdentifier
:
public class SampleIdentifier extends ResourceIdentifier { private final String filePath; public SampleIdentifier(String filePath) { this.filePath = filePath; } public String format() { return this.filePath; } }
Implement StorageManager
to store/delete/get physical file:
public class SampleStorageManager extends StorageManager { public SampleStorageManager(Repository repository) { super(repository); } public ResourceIdentifier uploadResource( File uploadedFile, ResourceIdentifier resourceIdentifier) throws DAMException { File targetFile = new File(resourceIdentifier.format()); try { InputStream fileInputStream = new FileInputStream(uploadedFile); OutputStream outputStream = new FileOutputStream(targetFile); byte[] buffer = new byte[1024]; int c = 0; try { while ((c = fileInputStream.read(buffer, 0, buffer.length)) > 0) { outputStream.write(buffer, 0, c); outputStream.flush(); } } finally { outputStream.close(); fileInputStream.close(); } return this.getIdentifierFactory().parse(uploadedFile.getName()); } catch (IOException ioException) { //Log the exception throw new DAMException("Unable to save file in folder"); } } public boolean deleteResource(ResourceIdentifier identifier) throws DAMException { File file = new File(identifier.format()); return file.delete(); } private Adaptation getDAMConfigurationDataset(Repository repository) { AdaptationHome damHome = repository.lookupHome(APIConstants.CONFIGURATION.DAM_HOME); return damHome.findAdaptationOrNull(APIConstants.CONFIGURATION.DAM_DATASET_NAME); } private String buildFileName(String uuidAsset, String uuidVersion, String extension) { StringBuilder sb = new StringBuilder(); sb.append(uuidAsset) .append(APIConstants.UNDERSCORE) .append(uuidVersion) .append(APIConstants.DOT) .append(extension); return sb.toString(); } public DigitalAssetMediaContent getDigitalAssetMediaContent(DigitalAssetKey digitalAssetKey) throws DAMException { Adaptation digitalAssetRecord = this.getDAMConfigurationDataset(this.repository) .getTable(DrivePaths._DigitalAssetGroup_DigitalAsset.getPathInSchema()) .lookupAdaptationByPrimaryKey(digitalAssetKey.getDigitalAssetPrimaryKey()); String fileName = this.buildFileName( digitalAssetRecord.getString(DrivePaths._DigitalAssetGroup_DigitalAsset._Uuid), digitalAssetRecord .getString(DrivePaths._DigitalAssetGroup_DigitalAsset._FKCurrentVersion), digitalAssetRecord.getString(DrivePaths._DigitalAssetGroup_DigitalAsset._FKMimeType)); File physicalFile = new File(fileName); return this.getDigitalAssetMediaContentFromFile(physicalFile); } public DigitalAssetMediaContent getDigitalAssetMediaContent(DigitalAssetVersionKey versionKey) throws DAMException { Adaptation versionRecord = this.getDAMConfigurationDataset(this.repository) .getTable(DrivePaths._DigitalAssetGroup_DigitalAssetVersion.getPathInSchema()) .lookupAdaptationByPrimaryKey(versionKey.getPrimaryKey()); String fileName = this.buildFileName( versionRecord.getString(DrivePaths._DigitalAssetGroup_DigitalAsset._Uuid), versionRecord.getString(DrivePaths._DigitalAssetGroup_DigitalAsset._FKCurrentVersion), versionRecord.getString(DrivePaths._DigitalAssetGroup_DigitalAsset._FKMimeType)); File physicalFile = new File(fileName); return this.getDigitalAssetMediaContentFromFile(physicalFile); } private DigitalAssetMediaContent getDigitalAssetMediaContentFromFile(File physicalFile) throws DAMException { if (!physicalFile.exists()) { throw new DAMException("File not found"); } long contentLength = physicalFile.length(); InputStream inputStream; DigitalAssetMediaContent digitalAssetMediaContent; try { inputStream = new FileInputStream(physicalFile); digitalAssetMediaContent = new DigitalAssetMediaContentImpl(inputStream, contentLength); } catch (Exception ex) { throw new DAMException(ex); } return digitalAssetMediaContent; } public ResourceIdentifierFactory getIdentifierFactory() { return new SampleIdentifierFactory(); } }
Implement DriveManager
:
public class SampleDriveManager extends DriveManager { public SampleDriveManager(Repository repository) { super(repository); } public StorageManager getStorageManager(Repository repository) { return new SampleStorageManager(repository); } }
Create a new EditAssetServiceSpec
:
DigitalAssetKey digitalAssetKey = new DigitalAssetKey(anAssetPrimaryKey); Path mediaFieldPath = Path.parse("/root/aTable/aMediaField"); boolean isReadonly = false; EditAssetServiceSpec editAssetServiceSpec = new EditAssetServiceSpec(digitalAssetKey, aDataset, mediaFieldPath, isReadonly);
Get UIHttpManagerComponent
of the 'Edit digital asset' service:
UIHttpManagerComponent editServiceComponent = EditAssetServiceComponent.getEditDigitalAssetService(editAssetServiceSpec);