Download files from Oracle UCM/WebCenter

Updated: Apr 25, 2020


Oracle UCM is the Oracle’s Universal Content Management application and it is now referred as Oracle WebCenter Content Server.


This application is an integral part of Oracle HCM cloud, and is been used as its content management system. WebCenter is the preferred method of file transfer for inbound and outbound integrations i.e. data loading as well as extracts. It provides improved and secured file management capabilities.


We can access this application in two ways.


1. File Import/Export UI: From Oracle cloud application go to Navigator - Tools - File Import and Export - UI to search/download/upload files from or to WebCenter.


2. Oracle WebCenter UI: Login or navigate to WebCenter UI by simply appending /cs to your application url for ex. https://<hostname>/cs .


Now I will show you how to download a CSV file from WebCenter and zip it by invoking WebCenter SOAP services from Python.


Generic Soap Service : https://<HostName>/idcws/GenericSoapPort?wsdl


Refer to Oracle WebCenter Content Generic SOAP Web Service for more info.


To download a file from WebCenter, we need the Document Name/Document ID of the file.


Use below code to download the file using Document ID.

import requests
import zipfile
import io
import csv
from os import path
import os

url="https://<HOSTNAME>/idcws/GenericSoapPort?wsdl"

headers = {'content-type': 'text/xml','charset':'UTF-8'}

body="""<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ucm="http://www.oracle.com/UCM">
    <soapenv:Header/>
    <soapenv:Body>
    <ucm:GenericRequest webKey="cs">
        <ucm:Service IdcService="GET_FILE">
            <ucm:Document>
                <!--Zero or more repetitions:-->
                <ucm:Field name="dID">{DocID}</ucm:Field>
            </ucm:Document>
        </ucm:Service>
    </ucm:GenericRequest>
    </soapenv:Body>
</soapenv:Envelope>""".format(DocID='<DOCID>')

username = '<USERNAME>'
password = '<PASSWORD>'

response=requests.post(url, auth=(username, password),data=body,headers=headers)

os.chdir(<DIRECTORY_PATH_TO_SAVE_THE_FILE>)
zf = zipfile.ZipFile(io.BytesIO(response.content), 'r')
filename=<FILENAME>+'.csv'
zipfilename='<ZIPFILENAME>'
csv_file = open(filename, 'w')
writer = csv.writer(csv_file, dialect=csv.excel, delimiter=',',quotechar='"',lineterminator='\n', quoting=csv.QUOTE_MINIMAL)
for fileinfo in zf.infolist():
    x=zf.read(fileinfo).decode('utf-8')
    mylist=x.split('\n')
for i in range(0,len(mylist)):
    row=mylist[i].strip('"')
    if row.strip() == "":
        continue
     else:
        rowlist=row.replace("\"",'').split(',')
        writer.writerow(rowlist) 
csv_file.close()
print(filename+' File created')

get the path to the file in the current directory
src = path.realpath(filename);
# rename the original file
os.rename(src,filename)
# now put things into a ZIP archive
root_dir,tail = path.split(src)
# more fine-grained control over ZIP files
with zipfile.ZipFile(zipfilename, "w") as newzip:
   newzip.write(filename)
 print('Zip file created')

If we need to download a file using Document Name, use the below request payload.

body="""<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ucm="http://www.oracle.com/UCM">
    <soapenv:Header/>
    <soapenv:Body>
    <ucm:GenericRequest webKey="cs">
        <ucm:Service IdcService="GET_FILE">
            <ucm:Document>
                <!--Zero or more repetitions:-->
                <ucm:Field name="dDocName">{DocName}</ucm:Field>
                <ucm:Field name="RevisionSelectionMethod">Latest</ucm:Field>
                <ucm:Field name="Rendition">Primary</ucm:Field>
            </ucm:Document>
        </ucm:Service>
    </ucm:GenericRequest>
    </soapenv:Body>
</soapenv:Envelope>""".format(DocName='<DOCNAME>')

How to download all the files linked to a schedule job?


For each job a MANIFEST.MF file will be created which contains all the Document ID's generated by that job, we can use that to download all the files.


Note: to make this completely automated we need to bring the Document ID of the MANIFEST.MF file.


Thanks for reading! Check out my other posts here and share, if you liked it.

910 views1 comment

Recent Posts

See All