Monday, December 4, 2023

OIC - Create a resuable integration to write or move and delete files from AWS S3 using Rest

Usecase: Here, we will create a reusable integration for example say OIC_FILE_Handler which will do move and delete file from a specified directory of AWS S3 bucket using rest feature.

It will perform the following operations:

  1. Write file
  2. Delete file
  3. Move file (mixed option 1 and option2)
REST trigger Request JSON:
{
"base64FileRef":"",
"sourceFileName":"",
"sourceDirectory":"",
"moveFileFlag":"",
"targetDirectory":"",
"targetFileName":"",
"deleteSourceFileFlag";"",
"deleteDirectory":""
}

REST Response JSON:
{
"jobStatus":"SUCCEEDED",
"fileMoved":"Y",
"fileDeleted":"N",
"exceptionCode":"",
"exceptionReason":"",
"exceptionDetails":""

}


Implemetation logic steps:
  1. Create a AWS S3 rest connection
  2. Create a App driven orchestration pattern and configure rest to accept the base64 encoded file, source path, delete path, source and delete directories and different flags. 
  3. Assign globals:
    1. varBasePathAndFile : Concat(deleteDirectory  sourceFileName)
    2. varMovePathAndFile : concat(targetDirectory, targetFileName)
    3. varFileref: ""
    4. varMoveComplete : N
    5. varDeletecomplete: N
    6. varFileStatus : "error"
    7. varCounter : 0.0
  4. IF base64FileRef != empty, then decode base64 to file reference using decodebase64ToReference().
  5. If moveFileFlag = Y, call S3 rest service to place the file to the specified  directory and map the decoded file ref to stream reference.
    1. Resource path: /{pathAndFileName}
    2. VERB: put
    3. Request payload as Binary - application/zip
    4. Also, put a retry logic to place the files to S3 3 times
      1. Take a scope
      2. While conditon: varFileStatus ="error" and varCounter <3.0
      3. If success, assign varFileStaus ="success"
      4. Under scope > default fault handler > increment counter +1
    5. Update that varMoveComplete = Y if it is success
  6. IF deleteSourceFileFlag = Y , Call S3 rest service nad configure below:
    1. Resource path: /{pathAndFileName}
    2. Verb: Delete
    3. Map the varBasePathandFileName 
    4. If it is success,  assign deleteComplete =Y
  7. Update the response of the rest - fileMoved, fileDeleted and jobStatus.
  8. Update the exception scope fault status from main scope fault handler

Screenshots:




No comments:

Post a Comment

Featured Post

11g to 12c OSB projects migration points

1. Export 11g OSB code and import in 12c Jdeveloper. Steps to import OSB project in Jdeveloper:   File⇾Import⇾Service Bus Resources⇾ Se...