DocumentService
.See: Description
Interface | Description |
---|---|
ConnectionContext |
Represents contextual information for the connection established with
ConnectionService . |
ConnectionService |
Provides methods to build a new connection context for use with
DocumentService . |
Enum | Description |
---|---|
ConnectionUser |
Valid users to establish a connection to at least one vault.
|
DocumentService
.
Learn more about connections in Vault Help.
The following example uses ConnectionService
,
DocumentService
, and FileReference
to set set the source file, get new version information, and create a new attachment and rendition.
@DocumentActionInfo(label = "testCode")
public class DeepCopyDocument implements DocumentAction {
@Override
public boolean isExecutable(DocumentActionContext documentActionContext) { return true; }
@Override
public void execute(DocumentActionContext documentActionContext) {
ConnectionService connectionService = ServiceLocator.locate(ConnectionService.class);
ConnectionContext connectionContext = connectionService.newConnectionContext("connectionApiName", ConnectionUser.CONNECTION_AUTHORIZED_USER);
DocumentService documentService = ServiceLocator.locate(DocumentService.class);
DocumentSourceFileReference documentSourceFileReference = documentService.newDocumentSourceFileReference(connectionContext, "1_0_1");
DocumentVersion documentVersion = documentService.newDocument();
documentVersion.setValue("type__v", VaultCollections.asList("Claims"));
documentVersion.setValue("subtype__v", VaultCollections.asList("Core Message Map"));
documentVersion.setValue("lifecycle__v", VaultCollections.asList("Claims"));
documentVersion.setValue("name__v", "file name");
documentVersion.setSourceFile(documentSourceFileReference);
documentVersion.suppressRendition();
SaveDocumentVersionsResponse response = documentService.createDocuments(VaultCollections.asList(documentVersion));
String newDocVersionId = response.getSuccesses().get(0).getDocumentVersionId();
//Get new version info
String[] parts = StringUtils.split(newDocVersionId, "_");
String docId = parts[0];
Integer major = Integer.valueOf(parts[1]);
Integer newMinor = Integer.valueOf(parts[2]) + 1;
DocumentSourceFileReference secondVersionSourceFileReference = documentService.newDocumentSourceFileReference(connectionContext, "1_0_2");
DocumentVersion newVersion = documentService.newVersion(docId);
newVersion.setValue("type__v", VaultCollections.asList("Claims"));
newVersion.setValue("subtype__v", VaultCollections.asList("Core Message Map"));
newVersion.setValue("lifecycle__v", VaultCollections.asList("Claims"));
newVersion.setValue("status__v", VaultCollections.asList("Draft"));
newVersion.setValue("name__v", "1-17-2 v2");
newVersion.setValue("major_version_number__v", BigDecimal.valueOf(major));
newVersion.setValue("minor_version_number__v", BigDecimal.valueOf(newMinor));
newVersion.setSourceFile(secondVersionSourceFileReference);
documentService.migrateDocumentVersions(VaultCollections.asList(newVersion));
//create attachment
DocumentAttachmentFileReference documentAttachmentFileReference = documentService.newDocumentAttachmentFileReference(connectionContext, "1");
DocumentAttachment documentAttachment = documentService.newDocumentAttachment(documentAttachmentFileReference, docId);
documentService.createAttachments(VaultCollections.asList(documentAttachment));
//create rendition
DocumentRenditionFileReference documentRenditionFileReference = documentService.newDocumentRenditionFileReference(connectionContext, "1_0_1", "viewable_rendition__v");
DocumentRendition rendition = documentService.newDocumentRendition(documentRenditionFileReference, "1_0_1", "viewable_rendition__v");
documentService.createRenditions(VaultCollections.asList(rendition));
}
}
Copyright © Veeva Systems 2017–2021. All rights reserved.