Skip to Content

Using Directory API development, we can automate the creation and maintenance of ID objects in SAP PI\PO.

For example, we can build a user interface to call the API to add receivers to an ICO. This can be used by functional consultants without having to wait for a PI Consultant.

For information on how to start on the Directory API development, you can refer to William Li’s blog post on Directory API Development :

http://scn.sap.com/community/pi-and-soa-middleware/blog/2008/10/20/directory-api-development–part-1-of-3

 

In this blog, I will provide some of the common programs in API development to change\create different directory objects.

 

Code to create a Business System

 

public final void createBusinessComponent(ChangeListCreateOutType changeList,

                        String masterLanguage, String name, String party, String folderPath) {

                  try {

                        String url = “BusinessComponentInService/BusinessComponentInImplBean?wsdl=binding&mode=ws_policy”;

                        BusinessComponentInService service = new BusinessComponentInService();

                        BusinessComponentIn conf = service.getBusinessComponentIn_Port();

                        CommunicationComponentIDType compId = new CommunicationComponentIDType();

                        compId.setComponentID(name);

                        if(party != null || party != “”)

                              compId.setPartyID(party);

                        this.setupContext((javax.xml.ws.BindingProvider) conf,

                                    DirectoryAPIConfig.getUserid(), DirectoryAPIConfig

                                                .getPassword(), url);

                        //check if BC exists

                        BusinessComponentQueryInType bcQueryIn = new BusinessComponentQueryInType();

                        bcQueryIn.setBusinessComponentID(compId);

                        BusinessComponentQueryOutType bcQueryOut = conf.query(bcQueryIn);

                        //if BC does not exis, create, else revert changelist

                        if(bcQueryOut.getBusinessComponentID().size() == 0){

                              BusinessComponentCreateChangeInType create = new BusinessComponentCreateChangeInType();

                              create.setChangeListID(changeList.getChangeListID()

                                          .getChangeListID());

                              RestrictedBusinessComponentType rbc = new RestrictedBusinessComponentType();

                              rbc.setMasterLanguage(masterLanguage);

                              rbc.setBusinessComponentID(compId);

                              RestrictedObjectAdministrativeDataType adminData = new RestrictedObjectAdministrativeDataType();

                              adminData.setFolderPathID(folderPath);

                               rbc.setMasterLanguage(masterLanguage);

                               if(folderPath != null || folderPath != “”)

                                     rbc.setAdministrativeData(adminData);

                              create.getBusinessComponent().add(rbc);

                              ConfigurationObjectModifyOutType out = conf.create(create);

                        }

                        else

                              revertChangeList(changeList);

 

                  } catch (Exception Ex) {

                        System.out.println(Ex);

                  }

            }

 

Code to create a Communication Channel as copy of another

 

public final void createCommunicationChannelFromTemplate(

                        ChangeListCreateOutType changeList, String templateChannelName,

                        String templateBusinessSystem, String templateParty,

                        String channelName, String businessSystem, String party,

                        HashMap propertyList, String folderPath) {

 

                  try {

                        String url = “CommunicationChannelInService/CommunicationChannelInImplBean?wsdl&mode=ws_policy”;

                        CommunicationChannelInService service = new CommunicationChannelInService();

                        CommunicationChannelIn comp = service

                                    .getCommunicationChannelIn_Port();

                        this.setupContext((javax.xml.ws.BindingProvider) comp,

                                    DirectoryAPIConfig.getUserid(), DirectoryAPIConfig

                                                .getPassword(), url);

                        CommunicationChannelCreateChangeInType create = new CommunicationChannelCreateChangeInType();

                        create.setChangeListID(changeList.getChangeListID()

                                    .getChangeListID());

                        RestrictedCommunicationChannelType channel = new RestrictedCommunicationChannelType();

 

                        // Read template channel properties

                        CommunicationChannelReadOutType commChannelReadOut = queryCommunicationChannel(templateChannelName, templateBusinessSystem, templateParty);

                        if(commChannelReadOut.getCommunicationChannel().size() < 1)

                              throw new Exception(“No template channel found”);

                        String language = commChannelReadOut.getCommunicationChannel().get(0).getMasterLanguage();

                        CommunicationChannelDirectionType direction = commChannelReadOut.getCommunicationChannel().get(0).getDirection();

                        DesignObjectIDType objectId = commChannelReadOut.getCommunicationChannel().get(0).getAdapterMetadata();

                        String transportProtocol = commChannelReadOut.getCommunicationChannel().get(0).getTransportProtocol();

                        String transportProtocolVersion = commChannelReadOut.getCommunicationChannel().get(0).getTransportProtocolVersion();

                        String messageProtocol = commChannelReadOut.getCommunicationChannel().get(0).getMessageProtocol();

                        String messageProtocolVersion = commChannelReadOut.getCommunicationChannel().get(0).getMessageProtocolVersion();

                        ModuleProcessType moduleProcess = new ModuleProcessType();

                        moduleProcess = commChannelReadOut.getCommunicationChannel().get(0).getModuleProcess();

                        List<GenericPropertyTableType> propertyTableList = commChannelReadOut.getCommunicationChannel().get(0).getAdapterSpecificTableAttribute();

                        List<GenericPropertyType> properties = commChannelReadOut.getCommunicationChannel().get(0).getAdapterSpecificAttribute();       

                        List<GenericPropertyType> newProperties = new ArrayList<GenericPropertyType>();

                        //code start to read module tab parameters

                        ModuleProcessType newModuleProcess = new ModuleProcessType();

                        List<ParameterGroupType> paramGroupList = new ArrayList<ParameterGroupType>();

                        RestrictedGenericPropertyType restrictedGenPropType = new RestrictedGenericPropertyType();

                        ParameterGroupType paramGroupType = new ParameterGroupType();

                        List<ProcessStepType> processStepList = new ArrayList<ProcessStepType>();

                        processStepList = moduleProcess.getProcessStep();

                        for(int i = 0;i < processStepList.size();i++){

                              newModuleProcess.getProcessStep().add(i, processStepList.get(i));

                        }

                        paramGroupList = moduleProcess.getParameterGroup();

                        for(int i = 0;i < paramGroupList.size();i++){

                              paramGroupType = new ParameterGroupType();

                              List<RestrictedGenericPropertyType> genericPropertyList = paramGroupList.get(i).getParameter();

                              for(int j = 0;j < genericPropertyList.size();j++){

                                    restrictedGenPropType = new RestrictedGenericPropertyType();

                                    restrictedGenPropType.setName(genericPropertyList.get(j).getName());

                                    if(genericPropertyList.get(j).getName().equals(“mtSender”))

                                          restrictedGenPropType.setValue(businessSystem);

                                    else

                                          restrictedGenPropType.setValue(genericPropertyList.get(j).getValue());

                                    paramGroupType.getParameter().add(restrictedGenPropType);

                                    paramGroupType.setParameterGroupID(paramGroupList.get(i).getParameterGroupID());

                              }

                              newModuleProcess.getParameterGroup().add(i, paramGroupType);

                        }

                        // Replace template attributes with new ones from hash map

                        Object obj = null;

                        String key = “”;

                        GenericPropertyType property = new GenericPropertyType();

                        for(int i = 0;i < properties.size();i++){

                              key = properties.get(i).getName();

                              property = new GenericPropertyType();

                              property.setName(key);

                              if(propertyList.containsKey(key))

                                    property.setValue(propertyList.get(key).toString());

                              else

                                    property.setValue(properties.get(i).getValue());

                              property.setNamespace(properties.get(i).getNamespace());

                              newProperties.add(property); 

                        }

                        CommunicationChannelIDType channelID = new CommunicationChannelIDType();

                        channelID.setChannelID(channelName);

                        channelID.setComponentID(businessSystem);

                        if(party != “”)

                              channelID.setPartyID(party);

                        channel.setMasterLanguage(language);

                        channel.setCommunicationChannelID(channelID);

                        channel.setAdapterMetadata(objectId);

                        channel.setDirection(direction);

                        channel.setTransportProtocol(transportProtocol);

                        channel.setTransportProtocolVersion(transportProtocolVersion);

                        channel.setMessageProtocol(messageProtocol);

                        channel.setMessageProtocolVersion(messageProtocolVersion);

                        channel.setModuleProcess(newModuleProcess);

                        for(int i = 0;i < propertyTableList.size();i++){

                              channel.getAdapterSpecificTableAttribute().add(propertyTableList.get(i));

                        }

                        // add channel attributes from template

                        for(int i = 0;i < newProperties.size();i++){

                              channel.getAdapterSpecificAttribute().add(newProperties.get(i));

                        }

                        RestrictedObjectAdministrativeDataType adminData = new RestrictedObjectAdministrativeDataType();

                        adminData.setFolderPathID(folderPath);

                        if(folderPath != null || folderPath != “”)

                               channel.setAdministrativeData(adminData);

                                          create.getCommunicationChannel().add(channel);

                        ConfigurationObjectModifyOutType out = comp.create(create);

 

                        LogMessageCollectionType logMsgs = out.getLogMessageCollection();

                        int size = logMsgs.getLogMessageCommunicationChannel().size();

                        for (int i = 0; i < size; i++) {

                              System.out.println(“message ->”

                                          + logMsgs.getLogMessageCommunicationChannel().get(i)

                                                      .getLogMessageItem().getClassificationCode());

                              revertChangeList(changeList);

                        }

 

                  } catch (Exception Ex) {

                        System.out.println(Ex);

                        revertChangeList(changeList);

                  }

            }

 

Code to create an ICO

 

public final void createIntegratedConfiguration(

                        ChangeListCreateOutType changeList, String masterLanguage,

                        MessageHeaderIDType header, InboundProcessingType processing,

                        ReceiversType receiver, List<ReceiverInterfacesType> receiverInterfaceList,

                        List<OutboundProcessingType> outProcessList, String createChange, String folderPath,

                        List<PrefixNamespaceMappingType> prefixnamespacemap) {

                  try {

                        String url = “IntegratedConfigurationInService/IntegratedConfigurationInImplBean?wsdl&mode=ws_policy”;

                        IntegratedConfigurationInService service = new IntegratedConfigurationInService();

                        IntegratedConfigurationIn comp = service

                                    .getIntegratedConfigurationIn_Port();

 

                        this.setupContext((javax.xml.ws.BindingProvider) comp,

                                    DirectoryAPIConfig.getUserid(), DirectoryAPIConfig

                                                .getPassword(), url);

 

                        IntegratedConfigurationCreateChangeInType create = new IntegratedConfigurationCreateChangeInType();

 

                        create.setChangeListID(changeList.getChangeListID()

                                    .getChangeListID());

                        RestrictedIntegratedConfigurationType integratedConfig = new RestrictedIntegratedConfigurationType();

 

                        RestrictedObjectAdministrativeDataType adminData = new RestrictedObjectAdministrativeDataType();

                        adminData.setFolderPathID(folderPath);

                         integratedConfig.setMasterLanguage(masterLanguage);

                         if(folderPath != null || folderPath != “”)

                               integratedConfig.setAdministrativeData(adminData);

                         integratedConfig.setIntegratedConfigurationID(header);

                         integratedConfig.setInboundProcessing(processing);

                         integratedConfig.setReceivers(receiver);

                        for (int i = 0; i < receiverInterfaceList.size(); i++) {

                              integratedConfig.getReceiverInterfaces().add(

                                          receiverInterfaceList.get(i));

                        }

                        for (int i = 0; i < outProcessList.size(); i++) {

                              integratedConfig.getOutboundProcessing().add(

                                          outProcessList.get(i));

                        }

 

                        for (int i = 0; i < prefixnamespacemap.size(); i++) {

                              integratedConfig. getPrefixNamespaceMapping ().add(

                                                                        prefixnamespacemap.get(i));

 

 

                              }

 

                        create.getIntegratedConfiguration().add(integratedConfig);

                        ConfigurationObjectModifyOutType out = null;

                        if(createChange == “Y”)

                         out = comp.create(create);

                        else

                         out = comp.change(create);

                        //activateChangeList(changeList);

 

                        LogMessageCollectionType logMsgs = out.getLogMessageCollection();

                        int size = logMsgs.getLogMessageSenderAgreement().size();

                        for (int i = 0; i < size; i++) {

                              System.out.println(logMsgs.getLogMessageSenderAgreement()

                                          .get(i).getLogMessageItem().getClassificationCode());

                              revertChangeList(changeList);

                        }

 

                  } catch (Exception Ex) {

                        System.out.println(Ex);

                        revertChangeList(changeList);

                  }

            }

 

Query a config scenario

 

public final List<ConfigurationScenarioType> queryConfigScenario(String configScenarioName) {

                  try {

 

                        String url = “ConfigurationScenarioInService/ConfigurationScenarioInImplBean?wsdl&mode=ws_policy”;

                        ConfigurationScenarioInService service = new ConfigurationScenarioInService();

                        ConfigurationScenarioIn conf = service

                                    .getConfigurationScenarioIn_Port();

 

                        this.setupContext((javax.xml.ws.BindingProvider) conf,

                                    DirectoryAPIConfig.getUserid(), DirectoryAPIConfig

                                                .getPassword(), url);

                        //ConfigurationScenarioQueryIn configScenarioQIn = new ConfigurationScenarioQueryIn();

                        //String scenarioId = configScenarioQIn.getConfigurationScenarioID();

                        ConfigurationScenarioReadInType configScenarioReadIn = new ConfigurationScenarioReadInType();

                        configScenarioReadIn.getConfigurationScenarioID().add(configScenarioName);

                        ConfigurationScenarioReadOutType configScenarioReadout = conf.read(configScenarioReadIn);

                        List<ConfigurationScenarioType> scenarioList = configScenarioReadout.getConfigurationScenario();

                        return scenarioList;

 

                  } catch (Exception Ex) {

                        System.out.println(Ex);

                        return null;

                  }

            }

 

Query Communication Channel

 

public final CommunicationChannelReadOutType queryCommunicationChannel(String channelName, String system, String partyName) {

                  try {

                        String url = “CommunicationChannelInService/CommunicationChannelInImplBean?wsdl&mode=ws_policy”;

                        CommunicationChannelInService service = new CommunicationChannelInService();

                        CommunicationChannelIn comp = service

                                    .getCommunicationChannelIn_Port();

                        this.setupContext((javax.xml.ws.BindingProvider) comp,

                                    DirectoryAPIConfig.getUserid(), DirectoryAPIConfig

                                                .getPassword(), url);

                        CommunicationChannelQueryInType queryIn = new CommunicationChannelQueryInType();

                        CommunicationChannelIDType channelID = new CommunicationChannelIDType();

                        channelID.setChannelID(channelName);

                        channelID.setComponentID(system);

                        if(partyName != “”)

                              channelID.setPartyID(partyName);

                        /*queryIn.setCommunicationChannelID(channelID);

                        CommunicationChannelQueryOut queryOut = comp.query(queryIn);

                        List<CommunicationChannelID> channelCollection = new ArrayList<CommunicationChannelID>();

                        channelCollection = queryOut.getCommunicationChannelID();*/

                        CommunicationChannelReadInType commChannelReadIn = new CommunicationChannelReadInType();

                        commChannelReadIn.getCommunicationChannelID().add(channelID);

                        CommunicationChannelReadOutType commChannelReadOut = comp.read(commChannelReadIn);

                        return commChannelReadOut;

                  } catch (Exception Ex) {

                        System.out.println(Ex);

                        return null;

                  }

            }

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply