Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
prasanna_prabhu2
Explorer

Overview

The SAP HANA Cloud Platform document service (document service) provides an on-demand content repository for unstructured or semi-structured content. Applications access it using the OASIS standard protocol Content Management Interoperability Services (CMIS).

Features of Document Service

  • The storage and retrieval of files, which the file system often handles on traditional platforms
  • The organization of files in a hierarchical folder structure
  • Files are always encrypted (AES-128) before they are stored in the document service.
  • Versioning of content
  • A virus scanner can be activated to scan files for viruses during file upload (write accesses).

Document service can also be integrated with the standard Fiori file upload control provided the applications are running on the HANA cloud platform which will enable users to store contents in the document service repository.

To achieve this OData service can be created with an entity as “Media Type” by using apache Olingo libraries.

But by default (Olingo V2 2.0.3) doesn’t support handling of the media type entities rather can be achieved by creating own JPA processor and overriding the implementation of the below method.


@Override


public ODataResponse createEntity(PostUriInfo uriInfo, InputStream content, String requestContentType, String contentType) throws ODataException { ... }






The uploaded documents can be read or streamed out by overriding the below method..


@Override


       public ODataResponse readEntityMedia(GetMediaResourceUriInfo uriInfo,


                     String contentType) throws ODataException {…}






For more information about the implementation of CRUD operations on document service refer Blog.

Document service also supports versioning of the file contents which will enable user to store the document with the different version. Below is the code snippet which can be used to achieve the versioning during the creation of the document.


public void addDocumentwithVersion(File file) throws IOException {




// create a new file in the root folder


              Map<String, Object> properties = new HashMap<String, Object>();


              properties.put(PropertyIds.OBJECT_TYPE_ID, "sap:versioned");


                          properties.put(PropertyIds.NAME, file.getName());



                          // Try to identify the mime type of the file


             String mimeType = URLConnection.guessContentTypeFromName(file.getName());


              if (mimeType == null || mimeType.length() == 0) {


                                  mimeType = "application/octet-stream";}


                


                                   if (file != null && file.isFile()) {


                     InputStream stream = new FileInputStream(file);


                     InputStream stream2 = new FileInputStream(file);


                     Session session = getRepositorySession();


                     ContentStream contentStream = session.getObjectFactory()


                                  .createContentStream(file.getName(), file.length(),


                                                mimeType, stream);


                     try {


                  Folder yourFolder = getFolderOfYourApp(REPO_APPFOLDER);


                 Document versionedDocument1 = yourFolder.createDocument(


                                         properties, contentStream, VersioningState.MAJOR);


                 }catch (CmisNameConstraintViolationException e) {


                           // Document exists already, nothing to do


                     }


                     stream.close();


              } else {


                     System.out.println("Can't read-in folders, just files!");


                        }


      }







In the above example a document was created with Object type : sap:versioned and versioning state as MAJOR. The above file can be now updated with the new contents and a new version of the file can be created. Below is the code snippet to create an version above the parent version.


//Check out the parent document which will return the objectID of the private working copy                         


              ObjectId pwcObjectId = parentDocument.checkOut();


              Document pwc = (Document) session.getObject(pwcObjectId);





//create a new content stream for the updated contents or the new content that needs to be updated and set the content stream to the private working copy




            ContentStream newcontentStream = session.getObjectFactory()


                                 .createContentStream(file.getName(), file.length(), mimeType, stream);


                                          pwc.setContentStream(newcontentStream, true);



           //Check in the new contents to the private working copy and get the file Id of the latest version


            ObjectId idOfNewLastVersion = pwc.checkIn(true, null, null,null);





In the above example a new version of the parent document is being created. At any point of time the latest version of the document is shown to the user.

All the versions of the document will have the common versionSeriesId. Method getAllVersions() can be used to fetch all the versions of the document based on the updated timestamp.


Regards,

Prasanna.