Package com.veeva.vault.sdk.api.document
package com.veeva.vault.sdk.api.document
This package provides interfaces to manage documents and binders. The interfaces in this package allow you to:
- Update fields on the latest version of a document
- Create and delete documents
- Create and delete document versions
- Add attachments and renditions
Updating and Deleting Documents
UseDocumentService to create a DocumentVersion
object, which is an instance of an existing document. You can then update field values or delete the document.
After updating or deleting a DocumentVersion, you need to execute a batch operation to commit the operation. For
example, after updating a document, you need to execute DocumentService.saveDocumentVersions(java.util.List) (java.util.List)}
to save your changes.
In the following example, we update fields on the existing document ID 320, delete document ID 310, and delete a specific version of document ID 330.
DocumentService documentService = ServiceLocator.locate(DocumentService.class);
DocumentVersion documentVersion = documentService.newDocumentWithId("320");
LocalDateTime ldt = LocalDateTime.of(2016, Month.AUGUST, 22, 14, 30);
documentVersion.setValue("expiration_date__vs", LocalDate.now());
List languageList = VaultCollections.newList();
languageList.add("en_US");
documentVersion.setValue("language__v", languageList);
documentVersion.setValue("approved__c", Boolean.FALSE);
documentVersion.setValue("datetime__c", ldt.atZone(ZoneId.of("Asia/Kuala_Lumpur")));
DocumentVersion documentVersion2 = documentService.newDocumentWithId("310");
DocumentVersion documentVersion3 = documentService.newDocumentVersion("330_0_1");
List versionsToUpdate = VaultCollections.newList();
versionsToUpdate.add(documentVersion);
List versionsToDelete = VaultCollections.newList();
versionsToDelete.add(documentVersion2);
versionsToDelete.add(documentVersion3);
documentService.deleteDocumentVersions(versionsToDelete);
documentService.saveDocumentVersions(versionsToUpdate);
Creating Documents, Renditions, and Versions
The following example usesConnectionService,
DocumentService, and FileReference
to 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));
}
}
-
ClassDescriptionResponse from a call to
DocumentService.deleteDocumentVersions(List)(List)}.Represents the target attachment.Represents an attachment file from the current or from another Vault.Provides methods to retrieve common metadata information of the specified document field.Retrieves a List of all fields in theDocumentFieldcollection once a request is built for the given document type.Creates an instance ofDocumentFieldCollectionRequest.Holds aDocumentFieldcollection.Provides methods to retrieve required, unique, all, or a specific subset of document fields.Creates an instance ofDocumentFieldFilter.A list of all of the possible field types that a document field can be.Represents a document file from the current or from another Vault.Provides methods to retrieve document type and document field metadata.Represents the target document-version rendition.Represents a document-version rendition file from the current or from another Vault.Provides methods to update and delete documents.Represents a document-version source file from the current or from another Vault.Provides methods to retrieve common metadata information of the specified document type.A list of all possible levels aDocumentTypecan be.Retrieves an instance ofDocumentTypeto build the request for retrieving document type metadata.Creates an instance ofDocumentTypeRequest.Represents a document version.Represents a successful result of processing a document in a batch operation, such as a save or delete.Response from a call toDocumentService.saveDocumentVersions(List).