This discussion is archived
2 Replies Latest reply: Feb 12, 2013 4:22 AM by 990554 RSS

Need to know how to iterate a list of field from the req xml in page servic

990554 Newbie
Currently Being Moderated
Hi All,

Please help me out with java code in which i am able to iterate a list of field coming in the request xml to my page service class under read(Pageheader header) method of mine queryPagemaintenace class.

package com.splwg.cm.domain.pageService;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import com.ibm.icu.math.BigDecimal;
import com.splwg.base.api.businessObject.BusinessObjectDispatcher;
import com.splwg.base.api.businessObject.BusinessObjectInstance;
import com.splwg.base.api.businessObject.COTSInstanceListNode;
import com.splwg.base.api.datatypes.Date;
import com.splwg.base.api.lookup.BusinessObjectActionLookup;
import com.splwg.base.api.service.DataElement;
import com.splwg.base.api.service.ItemList;
import com.splwg.base.api.service.PageHeader;
import com.splwg.shared.common.ApplicationError;
import com.splwg.shared.environ.FieldDefinition;
import com.splwg.shared.environ.ListDefinition;
import com.splwg.shared.logging.Logger;
import com.splwg.shared.logging.LoggerFactory;

/**
* @author
*
@QueryPage (program = CMUSER, service = CMUSER,
* body = @DataElement (contents = { @ListField (name = USER_GROUP_LIST)
* , @ListDataField (name = USR_GRP_ID)
* , @DataField (name = MESSAGE_TEXT)
* , @DataField (name = USER_ID)
* , @DataField (name = PASSWORD)
* , @DataField (name = LAST_NAME)
* , @DataField (name = FIRST_NAME)
* , @DataField (name = USER_TYPE_FLG)
* , @DataField (name = EMAILID)}),
* actions = { "add"
* ,"read"
* , "delete"
* , "change"},
* header = { @DataField (name = USER_TYPE_FLG)
* , @DataField (name = EMAILID)
* , @DataField (name = LAST_NAME)
* , @DataField (name = FIRST_NAME)
* , @DataField (name = PASSWORD)
* , @DataField (name = USER_ID)},
* headerFields = { @DataField (name = USER_TYPE_FLG)
* , @DataField (name = USR_GRP_ID)
* , @DataField (name = EMAILID)
* , @DataField (name = LAST_NAME)
* , @DataField (name = FIRST_NAME)
* , @DataField (name = PASSWORD)
* , @DataField (name = USER_ID)},
* lists = { @List (name = USER_GROUP_LIST, size = 100, includeLCopybook = false,
* body = @DataElement (contents = { @DataField (name = USR_GRP_ID)}))},modules = {})
*/
public class CMUSER extends CMUSER_Gen {

public static final Logger logger = LoggerFactory.getLogger(CMUSER.class);
     
     DataElement root = new DataElement();
     PageHeader page = new PageHeader();

     protected DataElement read(PageHeader header) throws ApplicationError{


I want to know how can i iterate this USER_GROUP_LIST in my read method and get the USR_GRP_ID field data from it.

A Prompt reply from your end will help me to resolve this issue
  • 1. Re: Need to know how to iterate a list of field from the req xml in page servic
    Gurumoorthy Explorer
    Currently Being Moderated
    The PageHeader object can't hold any lists, only page body will have lists.
    Override the change method which contains page body where you can hold lists.
  • 2. Re: Need to know how to iterate a list of field from the req xml in page servic
    990554 Newbie
    Currently Being Moderated
    Guru Sir,

    i tried to override the add() method of the framework in that i was able to iterate the field from the list. But now the i am facing there is that i am not able to send back the response to the external system in XML format. I am getting a blank response in my SOAP UI Tool while testing here is the code:

    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.Iterator;
    import java.util.List;

    import com.ibm.icu.math.BigDecimal;
    import com.splwg.base.api.businessObject.BusinessObjectDispatcher;
    import com.splwg.base.api.businessObject.BusinessObjectInstance;
    import com.splwg.base.api.businessObject.COTSInstanceListNode;
    import com.splwg.base.api.datatypes.Date;
    import com.splwg.base.api.lookup.BusinessObjectActionLookup;
    import com.splwg.base.api.service.DataElement;
    import com.splwg.base.api.service.ItemList;
    import com.splwg.base.api.service.PageHeader;
    import com.splwg.shared.common.ApplicationError;
    import com.splwg.shared.logging.Logger;
    import com.splwg.shared.logging.LoggerFactory;

    /**
    * @author
    *
    @QueryPage (program = CMUSER4, service = CMUSER4,
    * body = @DataElement (contents = { @DataField (name = MESSAGE_TEXT)
    * , @DataField (name = PASSWORD)
    * , @DataField (name = USER_ID)
    * , @DataField (name = LAST_NAME)
    * , @DataField (name = FIRST_NAME)
    * , @DataField (name = USER_TYPE_FLG)
    * , @DataField (name = EMAILID)
    * , @ListDataField (name = USR_GRP_ID)
    * , @ListField (name = USER_GROUP_LIST)}),
    * actions = { "add"
    * , "delete"
    * , "change"
    * , "read"},
    * header = { @DataField (name = USER_ID)
    * , @DataField (name = MESSAGE_TEXT)},
    * headerFields = { @DataField (name = USER_ID)
    * , @DataField (name = MESSAGE_TEXT)},
    * lists = { @List (name = USER_GROUP_LIST, size = 100,
    * body = @DataElement (contents = { @DataField (name = USR_GRP_ID)}))}, modules = {})
    */
    public class CMUSER4 extends CMUSER4_Gen {
         
         public static final Logger logger = LoggerFactory.getLogger(CMUSER4.class);
         
         DataElement root = new DataElement();
         PageHeader page = new PageHeader();
         
         protected PageHeader add(DataElement item) throws ApplicationError{
              
              BusinessObjectInstance boInstance = BusinessObjectInstance.create("CM-USER");
              String USR_GRP_ID = null;
              try{
              logger.info("Data coming from the Service into the Application is :"+item.get(STRUCTURE.USER_ID));
              logger.info("Data coming from the Service into the Application is :"+item.get(STRUCTURE.FIRST_NAME));
              logger.info("Data coming from the Service into the Application is :"+item.get(STRUCTURE.LAST_NAME));
              logger.info("Data coming from the Service into the Application is :"+item.get(STRUCTURE.EMAILID));
              // logger.info("Data coming from the Service into the Application is :"+getInputHeader().getString(STRUCTURE.list_USER_GROUP_LIST.USR_GRP_ID));
              // Iterator it = STRUCTURE.
              ItemList sourceList = item.getList(STRUCTURE.list_USER_GROUP_LIST.name);
              List userGrpID = new ArrayList();
              logger.info("The Size of the User Group List here is :"+sourceList.size());
              Iterator iter;
              if ((sourceList != null) &&
              (sourceList.size() > 0)) {
              for (iter = sourceList.iterator(); iter.hasNext(); ) {
              DataElement myItem = (DataElement)iter.next();
              USR_GRP_ID = myItem.get(STRUCTURE.list_USER_GROUP_LIST.USR_GRP_ID);
              logger.info("The User Group Id coming in the List here is :"+USR_GRP_ID);
              }
              }
              
              
              logger.info("Data coming from the Service into the Application is :"+item.get(STRUCTURE.PASSWORD));
              
              boInstance.set("user", item.get(STRUCTURE.USER_ID));
              boInstance.set("firstName", item.get(STRUCTURE.FIRST_NAME));
              boInstance.set("lastName", item.get(STRUCTURE.LAST_NAME));
              boInstance.set("emailAddress", item.get(STRUCTURE.EMAILID));
              // COTSInstanceList userGrpList = boInstance.getList("userGroupUser");
              // COTSInstanceListNode userGroupList = userGrpList.newChild();
              COTSInstanceListNode userGroupList = boInstance.getList("userGroupUser").newChild();
              userGroupList.set("userGroup", USR_GRP_ID);
              logger.info("Data coming from the Service into the Application is :"+userGroupList.toString());
              /*boInstance.set
              boInstance.set("userGroup", getInputHeader().getString(STRUCTURE.HEADER.USR_GRP_ID));*/
              // UserTypeLookup.constants.TEMPLATE_USER
              //if(element.get(STRUCTURE.USER_TYPE_FLG))
              //boInstance.set("user", element.get(STRUCTURE.));
              boInstance.set("dashboardWidth","200");
              boInstance.set("homeNavigationOption","CI0000000574");
              boInstance.set("language","ENG");
              boInstance.set("toDoEntriesAge1", new BigDecimal(50));
              boInstance.set("toDoEntriesAge2",new BigDecimal(100));
              boInstance.set("displayProfileCode", "NORTHAM");
              String expirationDate = "2100-12-31";
              String[] array = expirationDate.split("-");
              userGroupList.set("expirationDate",new Date(Integer
                             .parseInt(array[0]), Integer
                             .parseInt(array[1]), Integer
                             .parseInt(array[2])));
              //boInstance.set("userGroupUser", userGroupList);
              COTSInstanceListNode roleUserList = boInstance.getList("roleUser").newChild();
              roleUserList.set("toDoRole","F1_DFLT");
              COTSInstanceListNode dataAccessList = boInstance.getList("dataAccessUser").newChild();
              dataAccessList.set("dataAccessRole","***");
              String expiryDate = "2100-01-01";
              String[] array1 = expiryDate.split("-");
              dataAccessList.set("expireDate",new Date(Integer
                             .parseInt(array1[0]), Integer
                             .parseInt(array1[1]), Integer
                             .parseInt(array1[2])));
              BusinessObjectDispatcher.execute(boInstance,
                             BusinessObjectActionLookup.constants.FAST_ADD);
              page.put(STRUCTURE.HEADER.MESSAGE_TEXT, "User Added Successfully");
              page.put(STRUCTURE.HEADER.USER_ID,item.get(STRUCTURE.USER_ID));
              
              }catch(Exception e){
                   e.printStackTrace();
                   page.put(STRUCTURE.HEADER.MESSAGE_TEXT, "Caught Exception in the ORMB System. Please reach out to the Admin"+e.getMessage());
                   page.put(STRUCTURE.HEADER.USER_ID,item.get(STRUCTURE.USER_ID));
              }
              
              return page;
         }


    If you can help me to find out what went wrong here while sending the response back it can close my issue.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points