Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member182534
Active Participant
0 Kudos

This guide provides instructions on how to get the Notes & Attachments Details of a Task using BPM API.


Applies to:

This Document Holds good for all CE 7.3 SP09 onwards for the Notes.

This Document Holds good for all CE 7.3 SP16 onwards for the Attachments.


Summary:

This guide describes step-by-step how to Read the Notes and Attachment Details attached using the standerd Note's and attachment functionality of a BPM Process using BPM API as a web service.


About Me:

piyaskumar.das

As a Sr. Netweaver Consultant, I've been undertaking consulting assignments leveraging on my undermentioned NetWeaver skills.

  • Business Process Management (SAP NW BPM)
  • Restful Services using BPM api to be used in UI5 Screens.
  • SAP Web Dynpro Java (SAP WD4J)
  • SAP Business Rules Management (SAP BRMS)
  • SAP Composit Application Framework (SAP CAF)
  • Master Data Management (SAP NW MDM)
  • Enterprise Portal (SAP EP)
  • Services creation using NWDS (SAP EJB)
  • Enterprise SOA

I am an SAP BPM Trainer, an Active Blogger and Document Writer in SCN.


Prerequisites:

You should have read through the document : How to Start a BPM Process using BPM API as a RESTful service.


NOTE: Please reffer to this document by andre.backofen


We will be discussing following points in detail in this document -

  1. Setting up the foundation for using BPM API.
  2. Code spinster for the BPM API usage:
  3. Creating Deploy-able Object.
  4. Configuration to be done to make the service an Authenticated one.
  5. Testing the service

Setting up the foundation for using BPM API.


Step 1 : Open the "Components properties" tab of the EJB Module DC'c.


Step 2 : Open the "Dependencies" tab inside the "Component Properties" tab. Add the "tc/bpem/facade/ear" to the DC.

Step 3 : Repeat Step 1 & 2 for the "Enterprise Application" DC as well.


Code spinster for the BPM API usage:


Step 4 : Create 3 Java Class with the following names inside a package dto:

  1. TaskAttachmants.Java
  2. TaskNotes.java
  3. Task.java


TaskAttachmants.Java


package dto;
import java.util.Date;
public class TaskAttachmants {
  private String id;
  private String displayName;
  private Date createdOn;
  private String createdBy;
  public String getId() {
  return id;
  }
  public void setId(String id) {
  this.id = id;
  }
  public String getDisplayName() {
  return displayName;
  }
  public void setDisplayName(String displayName) {
  this.displayName = displayName;
  }
  public Date getCreatedOn() {
  return createdOn;
  }
  public void setCreatedOn(Date createdOn) {
  this.createdOn = createdOn;
  }
  public String getCreatedBy() {
  return createdBy;
  }
  public void setCreatedBy(String createdBy) {
  this.createdBy = createdBy;
  }
}







TaskNotes.java


package dto;
import java.util.Date;
public class TaskNotes {
  private String id;
  private String Content;
  private Date createdOn;
  private String createdBy;
  public String getId() {
  return id;
  }
  public void setId(String id) {
  this.id = id;
  }
  public String getContent() {
  return Content;
  }
  public void setContent(String content) {
  Content = content;
  }
  public Date getCreatedOn() {
  return createdOn;
  }
  public void setCreatedOn(Date createdOn) {
  this.createdOn = createdOn;
  }
  public String getCreatedBy() {
  return createdBy;
  }
  public void setCreatedBy(String createdBy) {
  this.createdBy = createdBy;
  }
}







Task.java


package dto;
import java.util.ArrayList;
public class Task {
  private ArrayList<TaskAttachmants> taskAttachmantsList ;
  private ArrayList<TaskNotes> taskNotesList ;
  public ArrayList<TaskAttachmants> getTaskAttachmantsList() {
  return taskAttachmantsList;
  }
  public void setTaskAttachmantsList(
  ArrayList<TaskAttachmants> taskAttachmantsList) {
  this.taskAttachmantsList = taskAttachmantsList;
  }
  public ArrayList<TaskNotes> getTaskNotesList() {
  return taskNotesList;
  }
  public void setTaskNotesList(ArrayList<TaskNotes> taskNotesList) {
  this.taskNotesList = taskNotesList;
  }
}








Step 5 : Create a Session Bean(Test.java) inside a package called "services" copy past the following code


package services;
import java.net.URI;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.ejb.Stateless;
import com.sap.bpm.api.BPMFactory;
import com.sap.bpm.tm.api.Attachment;
import com.sap.bpm.tm.api.Note;
import com.sap.bpm.tm.api.TaskInstanceManager;
import dto.Task;
import dto.TaskAttachmants;
import dto.TaskNotes;
@Stateless
public class Test implements TestLocal {
    public Test() {
    }
public Task getNoteNAttachment(String taskId) throws Exception
    {
//     Convert the Task Id into an URI Format
    URI taskInstanceId;
    taskInstanceId = new URI("bpm://bpm.sap.com/task-instance/"+taskId);
    //Retrieve the TaskInstanceManager
    TaskInstanceManager taskInstanceManager = BPMFactory.getTaskInstanceManager();
// Create an Object of the return type
    Task task = new Task();
    ArrayList<TaskAttachmants> taskAttachmantsList = new ArrayList<TaskAttachmants>();
    ArrayList<TaskNotes> taskNotesList = new ArrayList<TaskNotes>();
//     Retrieve the attachments Details based on the task ID
    List<Attachment> attachments = taskInstanceManager.getAttachments(taskInstanceId);
    Attachment attachment;
    TaskAttachmants taskAttachmants ;
  for (Iterator iterator = attachments.iterator(); iterator.hasNext();) {
  attachment = (Attachment) iterator.next();
  taskAttachmants = new TaskAttachmants();
  taskAttachmants.setId(attachment.getId().toString());
  taskAttachmants.setDisplayName(attachment.getDisplayName());
  taskAttachmants.setCreatedOn(attachment.getCreatedOn());
  taskAttachmants.setCreatedBy(attachment.getCreatedBy().getDisplayName());
  taskAttachmantsList.add(taskAttachmants);
  }
  task.setTaskAttachmantsList(taskAttachmantsList);
  TaskNotes taskNotes ;
//     Retrieve the Notes Details based on the task ID
  List<Note> notes = taskInstanceManager.getNotes(taskInstanceId);
  for (Iterator iterator = notes.iterator(); iterator.hasNext();) {
  Note note = (Note) iterator.next();
  taskNotes = new TaskNotes();
  taskNotes.setContent(note.getContent());
  taskNotes.setCreatedBy(note.getCreatedBy().getDisplayName());
  taskNotes.setCreatedOn(note.getCreatedOn());
  taskNotes.setId(note.getId().toString());
  taskNotesList.add(taskNotes);
  }
  task.setTaskNotesList(taskNotesList);
  return task ;
  }
}

Creating Deploy-able Object.


Step 6 : Create/Generate a web service for the Session Bean.

Step 7 : Once the web service is generated/created we need to deploy the EJB Service created.

So we deploy the "Enterprise Application" DC


Configuration to be done to make the service an Authenticated one.


Step 8 : Open the Net Weaver Administrator using the link http://<server>:<Port>/nwa


Step 9 : Search for "Single Service Administration" click on "Service Definition".


Step 10 : Go to the "Browse" tab select the "SoftwareComonents" from the drop down "Select Classification".

Step 11 : Search for the "Enterprise Application" DC expand the arrow's and find the Service Definition and click it.

Step 12 : Go to the "Configuration" Tab check if you are in the "Run time" or not select the service end point. Click on "Edit" go to "Security" Tab. set up the security level to as shown in the image bellow:

Testing the service


Step 13 : Go to  Web Service Navigator using the following link http://<server>:<Port>/wsnavigator.


Step 14 : While Testing enter a credentials by Clicking on the "Invocation Parameters". The Task Id can be picked up from the Task Manager.

3 Comments
Labels in this area