The Document service exhibits all the operations available around DOCUMENT type components.
Document recovery
The examples below show how to retrieve documents using the various operations of get.
Document recovery
# <CORE_HOST>: FlowerDocs Core base URL
# <TOKEN>: authentication token
# <IDS>: identifier of the documents to be retrieved
curl -X GET "<CORE_HOST>/rest/documents/<IDS>" \
-H "token: <TOKEN>"
@Autowired
private DocumentService service;
public List<Document> get() throws FunctionalException, TechnicalException
{
List<Id> ids = Lists.newArrayList(new Id("documentId"));
return service.get(ids);
}
Version recovery
This service allows you to retrieve a specific version of a document:
# <CORE_HOST>: FlowerDocs Core base URL
# <TOKEN>: authentication token
# <DOCUMENT_ID>: identifier of the document to be retrieved
# <VERSION_ID>: identifier of the version to be retrieved
curl -X GET "<CORE_HOST>/rest/documents/<DOCUMENT_ID>/versions/<VERSION_ID>" \
-H "token: <TOKEN>"
@Autowired
private VersionService service;
public Document getVersion() throws FunctionalException, TechnicalException
{
Id documentId = new Id("documentId"));
Id versionId = new Id("versionId"));
return service.getVersion(documentId, versionId);
}
Retrieving associated files
This service retrieves the files associated with the document whose identifier is passed as input:
- the content:
includeContent= true - files:
includeContent= false
# <CORE_HOST>: FlowerDocs Core base URL
# <TOKEN>: authentication token
# <ID>: document identifier
# <INCLUDE_CONTENT>: true or false for content retrieval
curl -X GET "<CORE_HOST>/rest/documents/<ID>/files?includeContent=<INCLUDE_CONTENT>" \
-H "token: <TOKEN>"
@Autowired
private DocumentService service;
public List<DocumentFile> get() throws FunctionalException, TechnicalException
{
Boolean includeContent = false;
return service.getFiles(new Id("documentId"), includeContent);
}
Document creation
The examples below show how to create documents using the following operation.
# <CORE_HOST>: FlowerDocs Core base URL
# <TOKEN>: authentication token
curl -X POST "<CORE_HOST>/rest/documents/" \
-H "token: <TOKEN>" \
-H "Content-Type: application/json" \
-d '[
{
"data": {
"classId": "Document"
},
"category": "DOCUMENT",
"name": "D1"
}
]'
@Autowired
private DocumentService service;
public List<Document> create() throws FunctionalException, TechnicalException
{
List<Document> documents = new ArrayList();
Document document = new Document();
document.setId(new Id("testId"));
ComponentData data = new ComponentData();
data.setClassId(new Id("ENV_Document"));
document.setData(data);
Tags tags = new Tags();
tags.getTags().add(new Tag(Arrays.asList("C0012")), "B_RefClient", false));
tags.getTags().add(new Tag(Arrays.asList("Supplier 12"), "B_ClientName", false));
tags.getTags().add(new Tag(Arrays.asList("RIB"), "B_TypeDocument", false));
document.setTags(tags);
documents.add(document);
return service.create(documents);
}
Document creation with a content
The examples below show how to create a document with its content using the following operation.
# <CORE_HOST>: FlowerDocs Core base URL
# <TOKEN>: authentication token
curl -X POST "<CORE_HOST>/rest/documents/unique" \
-H "token: <TOKEN>" \
-F "file=@/path/to/file" \
-F 'document=[
{
"data": {
"classId": "Document"
},
"category": "DOCUMENT",
"name": "D1"
}
];type=application/json'
Document modification
The examples below show how to update documents.
Document modification with content replacement
This operation allows to modify the data of a document (class identifier, document name, ACL, etc.) as well as modifying its content in the same call.
# <CORE_HOST>: FlowerDocs Core base URL
# <TOKEN>: authentication token
# <ID>: document identifier
curl -X POST "<CORE_HOST>/rest/documents/<ID>/unique" \
-H "token: <TOKEN>" \
-F "file=@/path/to/file" \
-F 'document=[
{
"data": {
"classId": "Document"
},
"category": "DOCUMENT",
"name": "D1"
}
];type=application/json'
Data modification
This operation updates a document’s tags and data (class identifier, document name, ACL, etc.) but also its content.
# <CORE_HOST>: FlowerDocs Core base URL
# <TOKEN>: authentication token
# <ID>: document identifier
curl -X POST "<CORE_HOST>/rest/documents/<ID>" \
-H "token: <TOKEN>" \
-H "Content-Type: application/json" \
-d '[
{
"files": [
{
"id": "98c1f765-7595-46c3-8f4a-b75bd7c25ff7",
"size": 0
}
],
"data": {
"classId": "Document"
},
"category": "DOCUMENT",
"name": "D2"
}
]'
@Autowired
private DocumentService service;
public List<Document> update(Document document) throws FunctionalException, TechnicalException
{
List<Document> documents = new ArrayList();
tags.getTags().add(new Tag(Arrays.asList("Contract"), "B_TypeDocument", false));
document.setTags(tags);
documents.add(document);
return service.update(documents);
}
Add file
This operation adds content to a document
replace: replaces the existing file with the new content
# <CORE_HOST>: FlowerDocs Core base URL
# <TOKEN>: authentication token
# <ID>: document identifier
# <REPLACE>: true or false to replace content
curl -X POST "<CORE_HOST>/rest/documents/<ID>/files?replace=<REPLACE>" \
-H "token: <TOKEN>" \
-F "file=@/path/to/file"
@Autowired
private DocumentService service;
public List<Document> addContent(Document document) throws FunctionalException, TechnicalException
{
List<DocumentFile> files = new ArrayList<DocumentFile>();
DocumentFile file = new DocumentFile();
file.setId(new Id("MyFile"));
file.setContent(new DataHandler(new FileDataSource(File.createTempFile("/tmp", ".txt"))));
files.add(file);
return service.addFiles(new Id("sampleDoc"), files, false);
}
Rename file
This operation allows you to rename a file associated with a document:
# <CORE_HOST>: FlowerDocs Core base URL
# <TOKEN>: authentication token
# <ID>: document identifier
# <FILE_ID>: file identifier
curl -X POST "<CORE_HOST>/rest/documents/<ID>/files/<FILE_ID>/name" \
-H "token: <TOKEN>" \
-d "<NEW_FILE_NAME>"
Search document
The search operations all work on the same model as described here.
Document deletion
The examples below show how to delete documents.
Document deletion
This operation allows to delete the document and its associated files.
# <CORE_HOST>: FlowerDocs Core base URL
# <TOKEN>: authentication token
# <IDS>: identifiers of documents to be deleted
curl -X DELETE "<CORE_HOST>/rest/documents/<IDS>" \
-H "token: <TOKEN>"
@Autowired
private DocumentService service;
public void delete() throws FunctionalException, TechnicalException
{
List<Id> ids = Lists.newArrayList(new Id("sample_doc"));
service.delete(ids);
}
File deletion
This operation allows you to delete a file.
# <CORE_HOST>: FlowerDocs Core base URL
# <TOKEN>: authentication token
# <DOCUMENT_ID>: document identifier
# <FILE_ID>: content identifier to be deleted
curl -X DELETE "<CORE_HOST>/rest/documents/<DOCUMENT_ID>/files/<FILE_ID>" \
-H "token: <TOKEN>"
@Autowired
private DocumentService service;
public void delete() throws FunctionalException, TechnicalException
{
List<Id> fileIds = Lists.newArrayList(new Id("sample_doc"));
service.deleteFiles(documentId, fileIds);
}
Content
Content recovery
This service retrieves the content associated with the file whose identifier is passed as input:
- with or without obfuscations, depending on the parameter
includeObfuscations
# <CORE_HOST>: FlowerDocs Core base URL
# <TOKEN>: authentication token
# <DOCUMENT_ID>: document identifier
# <FILE_ID>: content identifier
# <INCLUDE_OBFUSCATIONS>: true or false to include obfuscations
curl -X GET "<CORE_HOST>/rest/documents/<DOCUMENT_ID>/files/<FILE_ID>/content?includeObfuscations=<INCLUDE_OBFUSCATIONS>" \
-H "token: <TOKEN>"
@Autowired
private DocumentService service;
public List<DocumentFile> get() throws FunctionalException, TechnicalException
{
Boolean includeContent = false;
return service.getFile(new Id("documentId"), new Id("fileId"), includeContent);
}
Index document content
This service indexes the content passed in parameter and associated with the file identifier.
# <CORE_HOST>: FlowerDocs Core base URL
# <TOKEN>: authentication token
# <DOCUMENT_ID>: document identifier
# <FILE_ID>: content identifier
curl -X POST "<CORE_HOST>/rest/documents/<DOCUMENT_ID>/files/<FILE_ID>/content/index" \
-H "token: <TOKEN>" \
-H "Content-Type: application/json" \
-d "document content"
@Autowired
private DocumentContentService service;
public Id addContent() throws FunctionalException, TechnicalException
{
return service.index(new Id("documentId"), new Id("fileId"), "File contents");
}
Remove content indexing from a document
This service removes the indexing of content associated with a document.
# <CORE_HOST>: FlowerDocs Core base URL
# <TOKEN>: authentication token
# <DOCUMENT_ID>: document identifier
# <FILE_ID>: content identifier
curl -X DELETE "<CORE_HOST>/rest/documents/<DOCUMENT_ID>/files/<FILE_ID>/content/index" \
-H "token: <TOKEN>"
@Autowired
private DocumentContentService service;
public void removeContent() throws FunctionalException, TechnicalException
{
service.deindex(new Id("documentId"), new Id("fileId"));
}