1 Reply Latest reply: Jan 16, 2013 11:09 PM by Vijay Nimmakuri RSS

    Fetching all the options in an option class in Configurator extension CIO

    Vijay Nimmakuri
      Hi All,

      I have a requirement to fetch all the options in a given option class and conditionally make them to FALSE based on the values retrieved by my SQL query.

      Example:
      MN-HARDDRIVE (MY option class in configurator developer below are options)
      - 1
      - 2
      - 3
      - 4

      My sql query fetches 1,2 options i need to compare the options which are fetched by my sql query with my configurator options and make the remaining options ISTATE to FALSE. i.e 3,4 options should be false(excluded in my configurator).

      I am getting the option class by
      IRuntimeNode compo = irn.getChildByName(SalesOptionClass);
      List czItemNode =compo.getChildrenByType(IRuntimeNode.OPTION_FEATU RE);
      ListIterator Oclist = czItemNode.listIterator();

      --here iam getting the resultset by my SQL Query(fetching 1,2 values) (just wondering how to compare sql vlues with configurator nodes)

      while (Oclist.hasNext())
      {--getting options classes
      IRuntimeNode nodeTemp = (IRuntimeNode) Oclist.next();
      com.sun.java.util.collections.List childComponents1 = nodeTemp.getChildren();
      ListIterator childrenList1 = childComponents1.listIterator();
           while (childrenList1.hasNext()) -- getting options of the option class
           {
           IRuntimeNode nodeTemp1 = (IRuntimeNode) childrenList1.next();
           while (rs.next())
           {
                OPTION_NAME = rs.getString(1);
                if (nodeTemp1 != OPTION_NAME) <<<< ERROR : I could not compare here cos one is Iruntime node and other value is result set val)
                     {
                          IOption czItemNode2 = (IOption)this.getDescendantByName(compo,OPTION_NAME);
                          czItemNode2.setState(IState.FALSE);
                     }
           }
      }
      }
      On top of this my sql fetches 1,2 options and i need to compare them with config options classe and make unmatched values (options to false i.e make 3,4 to false)

      Seeking help on this

      Thanks in advance,
      vijay.
        • 1. Re: Fetching all the options in an option class in Configurator extension CIO
          Vijay Nimmakuri
          Hi All,

          I got the logic here is the code.

          try{
          Connection conn = irn.getConfiguration().getContext().getJDBCConnection();
          PreparedStatement pStmt = null;
          ResultSet rs;

          String OPTION_NAME=null;
          String sqlop = "SELECT d.OPTION_NAME FROM XXO2C_OE_CAT_MODEL_SEGS etc...

          // Deriving Sales option class
          String SalesOptionClass = "SLSASISEATPROTOTYPE"; //option class name(in my case its a reference model plug into my product model
          IRuntimeNode compo = irn.getChildByName(SalesOptionClass);
          List czItemNode =compo.getChildrenByType(IRuntimeNode.OPTION_FEATURE);
               
          ListIterator Oclist = czItemNode.listIterator();

               try
               {
               pStmt = conn.prepareStatement(sqlop);
               rs = pStmt.executeQuery();
               while (Oclist.hasNext())
                    {
                         IRuntimeNode nodeTemp = (IRuntimeNode) Oclist.next();
                         com.sun.java.util.collections.List childComponents1 = nodeTemp.getChildren();
               ListIterator childrenList1 = childComponents1.listIterator();
               while (childrenList1.hasNext())
               {
                    Object optionv= childrenList1.next();
                    
               //While loop to compare the fetched nodes with the model nodes and make them to false     
               while (rs.next())
                              {
                    OPTION_NAME = rs.getString(1);
                              if ((Boolean) (optionv != OPTION_NAME))
                              {
                              IOption czItemNode2 = (IOption)this.getDescendantByName(compo,OPTION_NAME);
                              czItemNode2.setState(IState.FALSE);
                              }
                              }
               }

                    }
                    
                    rs.close();
                    pStmt.close();
                    }
                    catch(Exception el){
                         
                    }     
               }
               catch(Exception e)
                    {
                    Configuration conf = irn.getConfiguration();
                    ConfigTransaction trans = conf.beginConfigTransaction();
                    InformationalMessage iMsg = new InformationalMessage("Exception Fetching all the in eligible options", irn);
                    config.addInformationalMessage(iMsg);
                    try{
                         config.commitConfigTransaction(trans);
                    }
                         catch(Exception ee){
                                        
                                   }
                                   
                    }// END : Fetching all the in eligible options

          Regards,
          vijay.nimmakuri@gmail.com