Package org.boco.seamwebappgen.info

Examples of org.boco.seamwebappgen.info.Relationship


      }
    }

    for (int i = 0; i < bean.getRelationships().size(); i++)
    {
      Relationship rel = bean.getRelationships().get(i);

      if (rel.isHelp())
      {
        String sourceFile = sourceDir + ".." + File.separator + "html" + File.separator + "help" + File.separator + "form_" + bean.getName() + "_" + rel.getName() + ".html";
        String targetFile = targetDir + "html" + File.separator + "help" + File.separator + "form_" + bean.getName() + "_" + rel.getName() + ".html";

        // Recupera il codice custom nella pagina
        LinkedList<String> yourJavaScriptCode = Utils.getYourCode(sourceFile, CustomCodeType.JAVA);
        LinkedList<String> yourCode = Utils.getYourCode(sourceFile, CustomCodeType.JSP);
View Full Code Here


      }
    }

    for (int i = 0; i < bean.getRelationships().size(); i++)
    {
      Relationship relationship = bean.getRelationships().get(i);

      if (relationship.isUsed() && relationship.isListBox())
      {
        if (relationship.isToMany())
        {
          javaScript += "\t\tif (window.opener.document.forms[\"form\"].elements[\"form:" + relationship.getName() + "\"] != null)\r\n";
          javaScript += "\t\t{\r\n";
          javaScript += "\t\t\tfor(i=0; i<window.opener.document.forms[\"form\"].elements[\"form:" + relationship.getName() + "\"].length; i++)\r\n";
          javaScript += "\t\t\t{\r\n";
          javaScript += "\t\t\t\tdocument.forms[\"form\"].elements[\"form:" + relationship.getName() + "\"].options[i].selected = window.opener.document.forms[\"form\"].elements[\"form:" + relationship.getName() + "\"].options[i].selected;\r\n";
          javaScript += "\t\t\t}\r\n";
          javaScript += "\t\t}\r\n";
        }
        else
        {
          javaScript += "\t\tif (window.opener.document.forms[\"form\"].elements[\"form:" + relationship.getName() + "\"] != null)\r\n";
          javaScript += "\t\t\tdocument.forms[\"form\"].elements[\"form:" + relationship.getName() + "\"].value = window.opener.document.forms[\"form\"].elements[\"form:" + relationship.getName() + "\"].value;\r\n";
        }
      }
    }

    javaScript += "\t}\r\n\r\n";
View Full Code Here

    }

    // Relazioni nel form
    for (int i = 0; i < bean.getRelationships().size(); i++)
    {
      Relationship rel = bean.getRelationships().get(i);

      key = "form_" + bean.getName() + "_" + rel.getName();
      if (!prop.containsKey(key))
      {
        prop.put(key, rel.getName().substring(3));
      }

      if (rel.isListBox())
      {
        ;
      }
      else
      {
        for (int j = 0; j < rel.getRelatedAttributes().size(); j++)
        {
          Attribute attr = rel.getRelatedAttributes().get(j);

          key = "form_" + bean.getName() + "_" + rel.getName();

          for (int k = 0; k < attr.getRelationships().size(); k++)
          {
            key += "_";
            key += attr.getRelationships().get(k).getName();
          }

          key += "_" + attr.getName();

          if (!prop.containsKey(key))
          {
            prop.put(key, Utils.makeFirstLetterUpperCase(attr.getName()));
          }
        }
      }
    }

    // Attributi delle relazioni da visualizzare nel form del bean
    for (int i = 0; i < bean.getShowInFormAttributes().size(); i++)
    {
      ShowAttribute attribute = bean.getShowInFormAttributes().get(i);

      key = "form_" + bean.getName() + "_" + attribute.getQualifiedName().replace(".", "_");

      if (!prop.containsKey(key))
      {
        prop.put(key, key);
      }
    }

    // Attributi del bean nella lista
    for (int i = 0; i < bean.getShowAttributes().size(); i++)
    {
      ShowAttribute attr = bean.getShowAttributes().get(i);

      if (!attr.belongsToRelationship())
      {
        key = "list_" + bean.getName() + "_" + attr.getName();
        if (!prop.containsKey(key))
        {
          prop.put(key, Utils.makeFirstLetterUpperCase(attr.getName()));
        }
      }
      else
      {
        // key = "list_" + bean.getName() + "_" + attr.getRelationship().getName() + "_" + attr.getName();

        key = "list_" + bean.getName();

        for (int k = 0; k < attr.getRelationships().size(); k++)
          key += "_" + attr.getRelationships().get(k).getName();

        key += "_" + attr.getName();

        if (!prop.containsKey(key))
        {
          prop.put(key, key);
        }
      }
    }

    // Pulsante di riferimento al master nella lista detail

    for (int i = 0; i < bean.getRelationships().size(); i++)
    {
      Relationship rel = bean.getRelationships().get(i);

      if (rel.isMasterDetail())
      {
        if (!rel.isFromMany() && !rel.isToMany() && !rel.isFromMaster())
        {
          // Relazione 1:1 Master-Detail in cui il bean e' il Detail

          key = "list_" + rel.getFromBeanName() + "_" + rel.getName() + "_OnlyOne" + rel.getFromBeanName() + "Allowed";

          if (!prop.containsKey(key))
          {
            prop.put(key, "Only one " + rel.getFromBeanName()+" allowed");
          }
        }

        // Inserisce il bottone di selezione del master o del detail a seconda del verso della relazione

        if (!rel.isFromMaster())
        {
          // Questo bean e' il Detail
          key = "list_" + rel.getFromBeanName() + "_" + rel.getToBeanName();

          if (!prop.containsKey(key))
          {
            prop.put(key, rel.getToBeanName());
          }
        }
        else
        {
          // Questo bean e' il master

          Vector<ShowList> lists = infoReader.getLists(rel.getToBeanName());

          for (ShowList list : lists)
          {
            key = "list_" + rel.getFromBeanName() + "_" + list.getName();

            if (!prop.containsKey(key))
            {
              prop.put(key, list.getName());
            }
          }
        }
      }
    }

    /** Etichette per i campi della ricerca locale **/
    for (int i = 0; i < bean.getLocalSearchAttributes().size(); i++)
    {
      ShowAttribute attr = bean.getLocalSearchAttributes().get(i);

      if (attr.getRelationship() == null)
      {
        key = "localSearch_" + bean.getName() + "_" + attr.getName();
        if (!prop.containsKey(key))
        {
          prop.put(key, Utils.makeFirstLetterUpperCase(attr.getName()));
        }
      }
      else
      {
        key = "localSearch_" + bean.getName() + "_" + attr.getRelationship().getName() + "_" + attr.getName();
        if (!prop.containsKey(key))
        {
          prop.put(key, attr.getRelationship().getName() + "_" + Utils.makeFirstLetterUpperCase(attr.getName()));
        }
      }

    }

    /** Etichette degli attributi di selezione di relazioni verso questo bean implementate come PopUp **/

    Vector<Relationship> relationships2ThisBean = infoReader.getAllRelationship2ThisBean(bean.getName());

    for (int i = 0; i < relationships2ThisBean.size(); i++)
    {
      Relationship rel = relationships2ThisBean.get(i);

      if (!rel.isListBox())
      {
        Vector<ShowAttribute> relatedAttributes = rel.getRelatedAttributes();

        for (ShowAttribute attribute : relatedAttributes)
        {
          key = "list_" + bean.getName() + "_" + attribute.getQualifiedName();

View Full Code Here

     ************************************************************************/
    Vector<Relationship> relationships2ThisBean = infoReader.getAllRelationship2ThisBean(bean.getName());

    for (int i = 0; i < relationships2ThisBean.size(); i++)
    {
      Relationship rel = relationships2ThisBean.get(i);

      if (rel.isUsed() || belongs2SearchAttribute(infoReader.getBean(rel.getFromBeanName()), rel))
      {
        if (rel.isListBox() || belongs2SearchAttribute(infoReader.getBean(rel.getFromBeanName()), rel))
        {
          String relatedAttributes = "";
          for (int k = 0; k < rel.getRelatedAttributes().size(); k++)
          {
            relatedAttributes += Utils.makeFirstLetterUpperCase(rel.getRelatedAttributes().get(k).getName());
          }

          CodeChunk tmp = new CodeChunk(0);

          tmp.addJavaCode("\tpublic HashMap<String, " + bean.getName() + "> get" + bean.getName() + "List");
          tmp.addJavaCode(relatedAttributes);
          tmp.addJavaCode("() throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;\r\n\r\n");

          if (!listMethods.getJavaCode().contains(tmp.getJavaCode()))
          {
            // listMethods.addJavaCode(tmp.getJavaCode());
          }
        }

        if (rel.isMasterDetail() && !rel.isFromMaster())
        {
          Vector<ShowList> lists = infoReader.getLists(rel.getFromBeanName());
          for (ShowList list : lists)
          {
            goToDetails += "public String goTo" + list.getName() + "();\r\n";
          }
        }
      }
    }

    /**
     * Inserimento funzione getPath se il bean e' master o detail in almeno una
     * relazione *
     */
    boolean getPath = false;
    String getPathFunction = "";
    for (int i = 0; i < bean.getRelationships().size(); i++)
    {
      Relationship relationship = bean.getRelationships().get(i);
      if (relationship.isUsed() && relationship.isMasterDetail())
        getPath = true;
    }
    if (getPath)
    {
      getPathFunction += "\r\n";
      getPathFunction += "\tpublic String getPath();\r\n";
    }

    /** Gestione della local search * */
    localSearch += "";
    localSearch += "\tpublic boolean isLocalSearch();\r\n";
    localSearch += "\tpublic void setLocalSearch(boolean search);\r\n";
    localSearch += "\tpublic void startLocalSearch();\r\n";
    localSearch += "\tpublic void stopLocalSearch();\r\n\r\n";

    // Getter e Setter per gli attributi di ricerca locale

    for (int i = 0; i < bean.getLocalSearchAttributes().size(); i++)
    {
      SearchAttribute attr = bean.getLocalSearchAttributes().get(i);

      if (attr.getImplementationType() == AttributeImplementationType.TEXT || attr.getImplementationType() == AttributeImplementationType.TEXTAREA)
      {
        localSearch += "\tpublic String getLocalSearch" + Utils.makeFirstLetterUpperCase(attr.getName()) + "();\r\n";
        localSearch += "\tpublic void setLocalSearch" + Utils.makeFirstLetterUpperCase(attr.getName()) + "(String localSearch" + Utils.makeFirstLetterUpperCase(attr.getName()) + ");\r\n";
      }
      else
      {
        if (attr.belongsToRelationship())
        {
          if (attr.getRelationship().isToMany())
          {
            localSearch += "\tpublic List<" + attr.getRelationship().getToBeanName() + "> getLocalSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + "();\r\n";
            localSearch += "\tpublic void setLocalSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + "(List<" + attr.getRelationship().getToBeanName() + "> localSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + ");\r\n";
          }
          else
          {
            localSearch += "\tpublic " + attr.getRelationship().getToBeanName() + " getLocalSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + "();\r\n";
            localSearch += "\tpublic void setLocalSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + "(" + attr.getRelationship().getToBeanName() + " localSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + ");\r\n";
          }
        }
      }
    }

    //    /** Gettere e Setter degli attributi della ricerca locale relativi a listbox e per i quali non funziona la injection **/
    //   
    //    for (int i = 0; i < bean.getLocalSearchAttributes().size(); i++)
    //    {
    //     
    //    }

    tags = new HashMap<String, String>();

    tags.put("@basePackage", basePackage);
    tags.put("@Bean", bean.getName());
    tags.put("@bean", Utils.makeFirstLetterLowerCase(bean.getName()));
    tags.put("@ListMethods", listMethods.getJavaCode());
    tags.put("@OrderingFunctions", orderingFunctions);
    tags.put("@GetPath", getPathFunction);
    tags.put("@GoToDetails", goToDetails);
    tags.put("@LocalSearch", localSearch);

    Utils.SeamReplaceTagAndSave(tags, yourCode, template, targetFile);

    /** ************** */
    /** ************** */
    /** ************** */
    /** ************** */
    /** ************** */
    /** ************** */
    /** ************** */
    /** Genera bean * */
    /** ************** */
    /** ************** */
    /** ************** */
    /** ************** */
    /** ************** */
    /** ************** */
    /** ************** */

    goToDetails = "";

    template = "." + File.separator + "templates" + File.separator + "Seam_ManagerBean.java";
    sourceFile = sourceDir + ".." + File.separator + "src" + File.separator + basePackage + File.separator + "manager" + File.separator + bean.getName() + "ManagerBean.java";
    targetFile = targetDir + "src" + File.separator + basePackage + File.separator + "manager" + File.separator + bean.getName() + "ManagerBean.java";

    yourCode = Utils.getYourCode(sourceFile, CustomCodeType.JAVA);

    findAll = generateFindAllBody(infoReader, bean, relationships2ThisBean);

    /**
     * Gestione scope del Manager
     */
    scope = bean.getScope();

    /**
     * Gestione Search
     */
    search += "@Factory(\"" + Utils.makeFirstLetterLowerCase(bean.getName()) + "SearchList\")\r\n";
    search += "\t@Begin(join = true)\r\n";
    search += "\tpublic void search() throws Exception\r\n";
    search += "\t{\r\n";

    search += "\t\tlog.info(\"search\");\r\n";

    search += "\t\tif(" + Utils.makeFirstLetterLowerCase(bean.getName()) + "Search == null)\r\n";
    search += "\t\t\treturn;\r\n\r\n";

    search += "\t\tString customFilter = \"\";\r\n";
    search += "\t\tQueryBuilder qb = new QueryBuilder(entityManager);\r\n\r\n";

    search += "\t\tqb.addSelect(\"o\");\r\n";
    search += "\t\tqb.addFrom(\"" + bean.getName() + " o\");\r\n";

    search += "\r\n";

    search += "\t\tqb.addTextWhere(customFilter,customFilter);\r\n\r\n";

    search += "\t\tswitch (order)\r\n";
    search += "\t\t{\r\n";

    int orderIndex = 1;
    String defaultOrdering = "";
    for (int i = 0; i < attrs.size(); i++)
    {
      ShowAttribute attr = attrs.get(i);

      if (!attr.isKey())
      {
        if (!attr.belongsToRelationship())
        {
          if (!attr.isTrans())
          {
            search += "\t\t\tcase " + orderIndex + ":\r\n";
            search += "\t\t\t\tqb.addOrderBy(\"o." + attr.getName() + " desc\");\r\n";
            search += "\t\t\t\tbreak;\r\n";
            orderIndex++;

            search += "\t\t\tcase " + orderIndex + ":\r\n";
            search += "\t\t\t\tqb.addOrderBy(\"o." + attr.getName() + " asc\");\r\n";
            search += "\t\t\t\tbreak;\r\n\r\n";
            orderIndex++;

            if (attr.getDefaultOrderingAttribute().equals("Asc"))
              defaultOrdering += "qb.addOrderBy(\"o." + attr.getName() + " asc\")";

            if (attr.getDefaultOrderingAttribute().equals("Desc"))
              defaultOrdering += "qb.addOrderBy(\"o." + attr.getName() + " desc\")";
          }
          else
          {
            orderIndex += 2;
          }
        }
        else
        {
          if (!attr.getRelationship().isToMany())
          {
            //            search += "\t\t\tcase " + orderIndex + ":\r\n";
            //            search += "\t\t\t\tqb.addOrderBy(\"o." + Utils.makeMethod2Field(attr.getRelationship().getName()) + "." + attr.getName() + " desc\");\r\n";
            //            search += "\t\t\t\tbreak;\r\n";
            //            orderIndex++;
            //
            //            search += "\t\t\tcase " + orderIndex + ":\r\n";
            //            search += "\t\t\t\tqb.addOrderBy(\"o." + Utils.makeMethod2Field(attr.getRelationship().getName()) + "." + attr.getName() + " asc\");\r\n";
            //            search += "\t\t\t\tbreak;\r\n\r\n";
            //            orderIndex++;
            //
            //            if (attr.getDefaultOrderingAttribute().equals("Asc"))
            //              defaultOrdering += "qb.addOrderBy(\"o." + Utils.makeMethod2Field(attr.getRelationship().getName()) + "." + attr.getName() + " asc\")";
            //
            //            if (attr.getDefaultOrderingAttribute().equals("Desc"))
            //              defaultOrdering += "qb.addOrderBy(\"o." + Utils.makeMethod2Field(attr.getRelationship().getName()) + "." + attr.getName() + " desc\")";

            search += "\t\t\tcase " + orderIndex + ":\r\n";
            search += "\t\t\t\tqb.addOrderBy(\"o.";

            for (int j = 0; j < attr.getRelationships().size(); j++)
            {
              search += Utils.makeMethod2Field(attr.getRelationships().get(j).getName()) + ".";
            }

            search += attr.getNameForOrdering() + " desc\");\r\n";
            search += "\t\t\t\tbreak;\r\n";
            orderIndex++;

            search += "\t\t\tcase " + orderIndex + ":\r\n";
            search += "\t\t\t\tqb.addOrderBy(\"o.";

            for (int j = 0; j < attr.getRelationships().size(); j++)
            {
              search += Utils.makeMethod2Field(attr.getRelationships().get(j).getName()) + ".";
            }

            search += attr.getNameForOrdering() + " asc\");\r\n";

            search += "\t\t\t\tbreak;\r\n\r\n";
            orderIndex++;

            if (attr.getDefaultOrderingAttribute().equals("Asc"))
              defaultOrdering += "qb.addOrderBy(\"o." + Utils.makeMethod2Field(attr.getRelationship().getName()) + "." + attr.getNameForOrdering() + " asc\")";

            if (attr.getDefaultOrderingAttribute().equals("Desc"))
              defaultOrdering += "qb.addOrderBy(\"o." + Utils.makeMethod2Field(attr.getRelationship().getName()) + "." + attr.getNameForOrdering() + " desc\")";
          }
        }
      }
    }

    search += "\t\t\tdefault:\r\n";
    if (defaultOrdering.equals(""))
      search += "\t\t\t\tqb.addOrderBy(\"o.id desc\");\r\n";
    else
      search += "\t\t\t\t" + defaultOrdering + ";\r\n";

    search += "\t\t}\r\n\r\n";

    /** Condizioni della ricerca **/
   
    for (int i = 0; i < bean.getSearchAttributes().size(); i++)
    {
      SearchAttribute attr = bean.getSearchAttributes().get(i);

      if (!attr.belongsToRelationship())
      {
        /** Non appartiene ad una relazione **/
        if (attr.getImplementationType().equals(AttributeImplementationType.TEXT))
        {
          if (attr.getType().equals("java.lang.String"))
          {
            search += "\t\tqb.addTextWhere(\"upper(o." + attr.getName() + ") like upper('%\"+" + Utils.makeFirstLetterLowerCase(bean.getName()) + "Search." + Utils.makeGet(attr.getName()) + "()+\"%')\", " + Utils.makeFirstLetterLowerCase(bean.getName()) + "Search." + Utils.makeGet(attr.getName()) + "());\r\n";
          }
          else
          {
            search += "\t\tqb.addTextWhere(\"o." + attr.getName() + " = ?"+i+"\", " + Utils.makeFirstLetterLowerCase(bean.getName()) + "Search." + Utils.makeGet(attr.getName()) + "());\r\n";           
          }
        }
      }
      else
      {
        /** Non appartiene ad una relazione **/
      }

    }

    search += "\r\n";
    search += "// YOUR CODE GOES HERE\r\n";
    search += "@YourCode";
    search += "// END OF YOUR CODE\r\n\r\n";

   
    /** Parametri Condizioni della ricerca **/
   
    for (int i = 0; i < bean.getSearchAttributes().size(); i++)
    {
      SearchAttribute attr = bean.getSearchAttributes().get(i);

      if (!attr.belongsToRelationship())
      {
        /** Non appartiene ad una relazione **/
        if (attr.getImplementationType().equals(AttributeImplementationType.TEXT))
        {
          if (attr.getType().equals("java.lang.String"))
          {
          }
          else
          {
            search += "\t\tqb.setParameter(\""+i+"\", " + Utils.makeFirstLetterLowerCase(bean.getName()) + "Search." + Utils.makeGet(attr.getName()) + "());\r\n";
          }
        }
      }
      else
      {
        /** Non appartiene ad una relazione **/
      }

    }
   
    search += "\r\n";
    search += "// YOUR CODE GOES HERE\r\n";
    search += "@YourCode";
    search += "// END OF YOUR CODE\r\n\r\n";
   
    search += "\t\tentityManager.clear();\r\n";
    search += "\r\n";
    search += "\t\t" + Utils.makeFirstLetterLowerCase(bean.getName()) + "SearchList = qb.getEjbQuery().getResultList();\r\n";
    search += "\r\n";

    /** Gestione dell'ordinamento dei campi transient **/

    search += "\t\tswitch (order)\r\n";
    search += "\t\t{\r\n";

    orderIndex = 1;

    for (int i = 0; i < attrs.size(); i++)
    {
      ShowAttribute attr = attrs.get(i);

      if (!attr.isKey())
      {
        if (!attr.belongsToRelationship())
        {
          // Attributo del bean

          if (attr.isTrans())
          {
            search += "\t\t\tcase " + orderIndex + ":\r\n";
            search += "\t\t\t\t" + Utils.makeFirstLetterLowerCase(bean.getName()) + "SearchList = SeamUtility.orderBy(" + Utils.makeFirstLetterLowerCase(bean.getName()) + "SearchList, \"" + attr.getNameForOrdering() + "\", GenericFieldComparator.OrderType.DESC);\r\n";
            search += "\t\t\t\tbreak;\r\n";
            orderIndex++;

            search += "\t\t\tcase " + orderIndex + ":\r\n";
            search += "\t\t\t\t" + Utils.makeFirstLetterLowerCase(bean.getName()) + "SearchList = SeamUtility.orderBy(" + Utils.makeFirstLetterLowerCase(bean.getName()) + "SearchList, \"" + attr.getNameForOrdering() + "\", GenericFieldComparator.OrderType.ASC);\r\n";
            search += "\t\t\t\tbreak;\r\n\r\n";
            orderIndex++;
          }
          else
          {
            orderIndex += 2;
          }
        }
        else
        {
          // Attributo di una relazione
          orderIndex += 2;
        }
      }
    }
    search += "\t\t}\r\n\r\n";

    if (bean.getSearchActions().size() > 0 || bean.getSearchImmediateActions().size() > 0)
    {
      search += "\t\tselections.clear();\r\n";
      search += "\t\tfor(" + bean.getName() + " item : " + Utils.makeFirstLetterLowerCase(bean.getName()) + "SearchList)\r\n";
      search += "\t\t{\r\n";
      search += "\t\t\tselections.put(item, true);\r\n";
      search += "\t\t}\r\n";
    }

    search += "\t}\r\n";

    orderingFunctions = "";
    orderIndex = 1;
    for (int i = 0; i < attrs.size(); i++)
    {
      ShowAttribute attr = attrs.get(i);

      if (!attr.isKey())
      {
        if (!attr.belongsToRelationship())
        {
          orderingFunctions += "\tpublic void orderBy" + (i + 1) + "A()\r\n";
          orderingFunctions += "\t{\r\n";
          orderingFunctions += "\t\torder = " + orderIndex + ";\r\n";
          orderingFunctions += "\t\tfindAll();\r\n";
          orderingFunctions += "\t}\r\n";
          orderIndex++;

          orderingFunctions += "\tpublic void orderBy" + (i + 1) + "D()\r\n";
          orderingFunctions += "\t{\r\n";
          orderingFunctions += "\t\torder = " + orderIndex + ";\r\n";
          orderingFunctions += "\t\tfindAll();\r\n";
          orderingFunctions += "\t}\r\n";
          orderIndex++;
        }
        else
        {
          if (!attr.getRelationship().isToMany())
          {
            orderingFunctions += "\tpublic void orderBy" + (i + 1) + "A()\r\n";
            orderingFunctions += "\t{\r\n";
            orderingFunctions += "\t\torder = " + orderIndex + ";\r\n";
            orderingFunctions += "\t\tfindAll();\r\n";
            orderingFunctions += "\t}\r\n";
            orderIndex++;

            orderingFunctions += "\tpublic void orderBy" + (i + 1) + "D()\r\n";
            orderingFunctions += "\t{\r\n";
            orderingFunctions += "\t\torder = " + orderIndex + ";\r\n";
            orderingFunctions += "\t\tfindAll();\r\n";
            orderingFunctions += "\t}\r\n";
            orderIndex++;
          }
        }
      }
    }

    /** Metodi per la alimentazione dei listbox * */
    /**
     * Sono interessate le relazioni :1 ed :n verso questo bean, implementate
     * come list box *
     */

    // listMethods = generateBeanManager_ListBoxFunctions(infoReader, bean, relationships2ThisBean);
    listMethods = new CodeChunk(0);

    /** Riferimenti ai bean che utilizzano questo bean come popup * */
    Vector<Relationship> relationshipToThisBean = infoReader.getAllRelationship2ThisBean(bean.getName());
    for (Relationship rel : relationshipToThisBean)
    {
      if (rel.isUsed() && !rel.isListBox())
      {
        String callingBean = "";

        if (rel.isFromMany())
        {
          callingBean += "\r\n\t@In(required = false, scope=ScopeType.CONVERSATION)\r\n";
          callingBean += "\tprivate " + rel.getFromBeanName() + "\t\t\t\t\t\t\t\t\t\t\t" + Utils.makeFirstLetterLowerCase(rel.getFromBeanName()) + " = null;\r\n";

          if (!callingBeans.contains(callingBean))
            callingBeans += callingBean;

          callingBean = "\r\n\t@In(required=false,create=true,value=\"" + Utils.makeFirstLetterLowerCase(rel.getFromBeanName()) + "Search\")\r\n";
          callingBean += "\tprivate " + rel.getFromBeanName() + "\t\t\t\t\t\t\t\t\t\t\t" + Utils.makeFirstLetterLowerCase(rel.getFromBeanName()) + "Search;\r\n";

          if (!callingBeans.contains(callingBean))
            callingBeans += callingBean;

          // Debbono essere aggiunti anche tutti i bean derivati
          Vector<String> derivedBeans = infoReader.getDerivedBeans(rel.getFromBeanName());

          ;
          for (String derivedBean : derivedBeans)
          {
            callingBean = "\r\n\t@In(required = false)\r\n";
            callingBean += "\tprivate " + derivedBean + "\t\t\t\t\t\t\t\t\t\t\t" + Utils.makeFirstLetterLowerCase(derivedBean) + "        = null;\r\n";

            if (!callingBeans.contains(callingBean))
              callingBeans += callingBean;
          }
        }
        else
        {
          callingBean += "\r\n\t@In(required = false, scope=ScopeType.CONVERSATION)\r\n";
          callingBean += "\tprivate " + rel.getFromBeanName() + "\t\t\t\t\t\t\t\t\t\t\t" + Utils.makeFirstLetterLowerCase(rel.getFromBeanName()) + "        = null;\r\n";

          if (!callingBeans.contains(callingBean))
            callingBeans += callingBean;

          callingBean = "\r\n\t@In(required=false,create=true,value=\"" + Utils.makeFirstLetterLowerCase(rel.getFromBeanName()) + "Search\")\r\n";
          callingBean += "\tprivate " + rel.getFromBeanName() + "\t\t\t\t\t\t\t\t\t\t\t" + Utils.makeFirstLetterLowerCase(rel.getFromBeanName()) + "Search;\r\n";

          if (!callingBeans.contains(callingBean))
            callingBeans += callingBean;
        }
      }
    }

    categorizedRelationshipToMaster = "";

    /** Gestione delle relazioni di cui questo bean non e' owner * */
    for (int i = 0; i < bean.getRelationships().size(); i++)
    {
      Relationship relationship = bean.getRelationships().get(i);
      Relationship inverseRelationship = infoReader.getInverseRelationship(bean, relationship);

      /** Gestione delle relazioni in cui questo bean e' owner e la relazione inversa e' implementata come POPUP
       */
      //      if ( (relationship.getMappedBy()==null || relationship.getMappedBy().equals("")) && inverseRelationship!=null && inverseRelationship.isUsed() && !inverseRelationship.isMasterDetail() && !inverseRelationship.isListBox() && !inverseRelationship.getName().contains("Upload"))
      //      {       
      //        ownedRelationshipCreate += Utils.makeFirstLetterLowerCase(bean.getName())+"."+Utils.switchGet2Set(relationship.getName())+"("+Utils.makeFirstLetterLowerCase(relationship.getToBeanName())+");\r\n";
      //      }
      /** Inizializzazione delle relazioni :1 implementate come listbox **/
      //      if ( !relationship.isToMany() && relationship.isListBox() )
      //      {
      //        // Inizializzazione delle relazioni lazy per la modifica !!!
      //        initilizeLazyRelationshipEdit += "\t\tHibernate.initialize(" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + relationship.getName() + "());\r\n";
      //      }
      /**
       * Inizializzazione della relazione al Master nella create e se il
       * Detail è categorizzato *
       */
      if (relationship.isMasterDetail() && !relationship.isFromMaster() && inverseRelationship.isCategorized())
      {
        categorizedRelationshipToMaster = "\tif (SeamUtility.getParameter(facesContext,\"" + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + "Id\")!=null)\r\n";
        categorizedRelationshipToMaster += "\t\t" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.switchGet2Set(relationship.getName()) + "(" + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + "Manager.find(new Long(SeamUtility.getParameter(facesContext,\"" + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + "Id\"))));\r\n";
      }

      if (relationship.isFromMany() || relationship.isToMany())
      {
        /**
         * Gestione relazioni N:M - 1:N - N:1
         *
         */

        if (!relationship.isFromMany())
        {
          // Cancellazione
          notOwnedRelationshipDelete += "\r\n\r\n";
          notOwnedRelationshipDelete += "\t\tList<" + relationship.getToBeanName() + "> " + Utils.makeMethod2Field(relationship.getName()) + " = " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + relationship.getName() + "();\r\n";
          notOwnedRelationshipDelete += "\r\n";
          notOwnedRelationshipDelete += "\t\tfor (" + relationship.getToBeanName() + " local" + relationship.getToBeanName() + " : " + Utils.makeMethod2Field(relationship.getName()) + ")\r\n";
          notOwnedRelationshipDelete += "\t\t{\r\n";
          notOwnedRelationshipDelete += "\t\t\tlocal" + relationship.getToBeanName() + "." + Utils.makeSet(relationship.getMappedBy()) + "(null);\r\n";
          notOwnedRelationshipDelete += "\t\t\tentityManager.merge(local" + relationship.getToBeanName() + ");\r\n";
          notOwnedRelationshipDelete += "\t\t}";
        }
        else
        {
          if (relationship.getMappedBy() != null && !relationship.getMappedBy().equals(""))
          {
            notOwnedRelationshipDelete += "\r\n\r\n";
            notOwnedRelationshipDelete += "\t\tList<" + relationship.getToBeanName() + "> " + Utils.makeMethod2Field(relationship.getName()) + " = " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + relationship.getName() + "();\r\n";
            notOwnedRelationshipDelete += "\r\n";
            notOwnedRelationshipDelete += "\t\tfor (" + relationship.getToBeanName() + " local" + relationship.getToBeanName() + " : " + Utils.makeMethod2Field(relationship.getName()) + ")\r\n";
            notOwnedRelationshipDelete += "\t\t{\r\n";
            notOwnedRelationshipDelete += "\t\t\tlocal" + relationship.getToBeanName() + "." + Utils.makeRemove(relationship.getMappedBy()) + "(" + Utils.makeFirstLetterLowerCase(bean.getName()) + ");\r\n";
            notOwnedRelationshipDelete += "\t\t\tentityManager.merge(local" + relationship.getToBeanName() + ");\r\n";
            notOwnedRelationshipDelete += "\t\t}";
          }
        }

        if (relationship.isUsed() && relationship.isToMany())
        {
          if (!relationship.isFromMany())
          {
            /** Relazioni :N **/

            // Creazione
            notOwnedRelationshipCreate += "\r\n";
            notOwnedRelationshipCreate += "\t\tList<" + relationship.getToBeanName() + "> " + Utils.makeMethod2Field(relationship.getName()) + " = " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + relationship.getName() + "();\r\n";
            notOwnedRelationshipCreate += "\r\n";
            notOwnedRelationshipCreate += "\t\tif (" + Utils.makeMethod2Field(relationship.getName()) + " != null)\r\n";
            notOwnedRelationshipCreate += "\t\t{\r\n";
            notOwnedRelationshipCreate += "\t\t\tfor (" + relationship.getToBeanName() + " " + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + " : " + Utils.makeMethod2Field(relationship.getName()) + ")\r\n";
            notOwnedRelationshipCreate += "\t\t\t{\r\n";

            notOwnedRelationshipCreate += "\t\t\t\t" + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + "." + Utils.switchGet2Set(inverseRelationship.getName()) + "(" + Utils.makeFirstLetterLowerCase(bean.getName()) + ");\r\n";
            notOwnedRelationshipCreate += "\t\t\t\tentityManager.merge(" + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + ");\r\n";
            notOwnedRelationshipCreate += "\t\t\t}\r\n";
            notOwnedRelationshipCreate += "\t\t}\r\n";

            // Modifica
            notOwnedRelEditRemoveExistingItems += "\r\n";
           
            if (notOwnedRelEditRemoveExistingItems.contains("\t\tList<" + relationship.getToBeanName() + "> old" + relationship.getToBeanName() + "s"))
              notOwnedRelEditRemoveExistingItems += "\t\told" + relationship.getToBeanName() + "s";
            else
              notOwnedRelEditRemoveExistingItems += "\t\tList<" + relationship.getToBeanName() + "> old" + relationship.getToBeanName() + "s";
            //notOwnedRelEditRemoveExistingItems += " = entityManager.find(" + bean.getName() + ".class," + Utils.makeFirstLetterLowerCase(bean.getName()) + ".getId())." + relationship.getName() + "();\r\n";
            notOwnedRelEditRemoveExistingItems += " = " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + relationship.getName() + "();\r\n";
            notOwnedRelEditRemoveExistingItems += "\r\n";
            notOwnedRelEditRemoveExistingItems += "\t\tfor (" + relationship.getToBeanName() + " " + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + " : old" + relationship.getToBeanName() + "s)\r\n";
            notOwnedRelEditRemoveExistingItems += "\t\t{\r\n";
            notOwnedRelEditRemoveExistingItems += "\t\t\t" + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + "." + Utils.makeSet(relationship.getMappedBy()) + "(null);\r\n";
            notOwnedRelEditRemoveExistingItems += "\t\t\tentityManager.merge(" + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + ");\r\n";
            notOwnedRelEditRemoveExistingItems += "\t\t}\r\n";

            notOwnedRelationshipEdit += "\r\n";
            notOwnedRelationshipEdit += "\t\tList<" + relationship.getToBeanName() + "> " + Utils.makeMethod2Field(relationship.getName()) + " = " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + relationship.getName() + "();\r\n";
            notOwnedRelationshipEdit += "\r\n";
            notOwnedRelationshipEdit += "\t\tfor (" + relationship.getToBeanName() + " " + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + " : " + Utils.makeMethod2Field(relationship.getName()) + ")\r\n";
            notOwnedRelationshipEdit += "\t\t{\r\n";
            notOwnedRelationshipEdit += "\t\t\t" + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + "." + Utils.makeSet(relationship.getMappedBy()) + "(" + Utils.makeFirstLetterLowerCase(bean.getName()) + ");\r\n";
            notOwnedRelationshipEdit += "\t\t\tentityManager.merge(" + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + ");\r\n";
            notOwnedRelationshipEdit += "\t\t}\r\n\r\n";
           
            notOwnedRelationshipEdit += "\t\tList<" + relationship.getToBeanName() + "> list" + relationship.getName() + " = " + Utils.makeFirstLetterLowerCase(bean.getName()) + "."+relationship.getName()+"();\r\n";
            notOwnedRelationshipEdit += "\t\t"+Utils.makeFirstLetterLowerCase(bean.getName())+"."+Utils.switchGet2Set(relationship.getName())+"(new ArrayList<" + relationship.getToBeanName() + ">(list" + relationship.getName() + "));\r\n";
           
           
            // // Inizializzazione delle relazioni lazy per la modifica
            // !!!
            // initilizeLazyRelationshipEdit +=
            // "\t\tHibernate.initialize(" +
            // Utils.makeFirstLetterLowerCase(bean.getName()) + "." +
            // relationship.getName() + "());\r\n";
          }
          else
          {
            /** Relazioni N:M **/

            if (!relationship.getMappedBy().equals(""))
            {
              notOwnedRelationshipCreate += "\r\n";
              notOwnedRelationshipCreate += "\t\tList<" + relationship.getToBeanName() + "> " + Utils.makeMethod2Field(relationship.getName()) + " = " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + relationship.getName() + "();\r\n";
              notOwnedRelationshipCreate += "\r\n";
              notOwnedRelationshipCreate += "\t\tif (" + Utils.makeMethod2Field(relationship.getName()) + " != null)\r\n";
              notOwnedRelationshipCreate += "\t\t{\r\n";
              notOwnedRelationshipCreate += "\t\tfor (" + relationship.getToBeanName() + " " + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + " : " + Utils.makeMethod2Field(relationship.getName()) + ")\r\n";
              notOwnedRelationshipCreate += "\t\t{\r\n";
              notOwnedRelationshipCreate += "\t\t\t" + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + "." + Utils.makeAdd(Utils.makeMethod2Field(inverseRelationship.getName())) + "(" + Utils.makeFirstLetterLowerCase(bean.getName()) + ");\r\n";
              notOwnedRelationshipCreate += "\t\t\tentityManager.merge(" + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + ");\r\n";
              notOwnedRelationshipCreate += "\t\t}\r\n";
              notOwnedRelationshipCreate += "\t\t}\r\n";

              notOwnedRelEditRemoveExistingItems += "\r\n";
              if (notOwnedRelEditRemoveExistingItems.contains("\t\tList<" + relationship.getToBeanName() + "> old" + relationship.getToBeanName() + "s"))
                notOwnedRelEditRemoveExistingItems += "\t\told" + relationship.getToBeanName() + "s";
              else
                notOwnedRelEditRemoveExistingItems += "\t\tList<" + relationship.getToBeanName() + "> old" + relationship.getToBeanName() + "s";
              //notOwnedRelEditRemoveExistingItems += " = entityManager.find(" + bean.getName() + ".class," + Utils.makeFirstLetterLowerCase(bean.getName()) + ".getId())." + relationship.getName() + "();\r\n";
              notOwnedRelEditRemoveExistingItems += " = " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + relationship.getName() + "();\r\n";
              notOwnedRelEditRemoveExistingItems += "\r\n";
              notOwnedRelEditRemoveExistingItems += "\t\tfor (" + relationship.getToBeanName() + " " + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + " : old" + relationship.getToBeanName() + "s)\r\n";
              notOwnedRelEditRemoveExistingItems += "\t\t{\r\n";
              notOwnedRelEditRemoveExistingItems += "\t\t\t" + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + "." + Utils.makeRemove(relationship.getMappedBy()) + "(" + Utils.makeFirstLetterLowerCase(bean.getName()) + ");\r\n";
              notOwnedRelEditRemoveExistingItems += "\t\t\tentityManager.merge(" + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + ");\r\n";
              notOwnedRelEditRemoveExistingItems += "\t\t}\r\n";

              notOwnedRelationshipEdit += "\r\n";
              notOwnedRelationshipEdit += "\t\tList<" + relationship.getToBeanName() + "> " + Utils.makeMethod2Field(relationship.getName()) + " = " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + relationship.getName() + "();\r\n";
              notOwnedRelationshipEdit += "\r\n";
              notOwnedRelationshipEdit += "\t\tfor (" + relationship.getToBeanName() + " " + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + " : " + Utils.makeMethod2Field(relationship.getName()) + ")\r\n";
              notOwnedRelationshipEdit += "\t\t{\r\n";

              notOwnedRelationshipEdit += "\t\t\t" + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + "." + Utils.makeRemoveAll(relationship.getMappedBy()) + "();\r\n";
              notOwnedRelationshipEdit += "\t\t\t" + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + "." + Utils.makeAdd(relationship.getMappedBy()) + "(" + Utils.makeFirstLetterLowerCase(bean.getName()) + ");\r\n";
              notOwnedRelationshipEdit += "\t\t\tentityManager.merge(" + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + ");\r\n";
              notOwnedRelationshipEdit += "\t\t}\r\n";
            }
          }

          // Inizializzazione delle relazioni lazy per la modifica !!!
          initilizeLazyRelationshipEdit += "\t\tHibernate.initialize(" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + relationship.getName() + "());\r\n";
        }
      }
      else
      {
        /**
         * Gestione delle relazioni 1:1
         *
         */
        if (relationship.isMasterDetail() && !relationship.isFromMaster())
        {
          // Questo e' il detail di una MASTER-DETAIL e viene inserito il
          // check per verificare l'esistenza di un solo detail

          masterDetail1To1Check += "\t\tif (" + Utils.makeFirstLetterLowerCase(bean.getName()) + "List.size()>0)\r\n";
          masterDetail1To1Check += "\t\t{\r\n";
          masterDetail1To1Check += "\t\t\tFacesMessages.instance().clear();\r\n\r\n";
          masterDetail1To1Check += "\t\t\tString msg = MessagesLoader.getMessageResourceString(facesContext.getApplication().getMessageBundle(),\"list_" + relationship.getFromBeanName() + "_" + relationship.getName() + "_OnlyOne" + relationship.getFromBeanName() + "Allowed\", null, facesContext.getViewRoot().getLocale());\r\n\r\n";
          masterDetail1To1Check += "\t\t\tFacesMessage message = new FacesMessage();\r\n";
          masterDetail1To1Check += "\t\t\tmessage.setDetail(msg);\r\n";
          masterDetail1To1Check += "\t\t\tmessage.setSummary(msg);\r\n";
          masterDetail1To1Check += "\t\t\tmessage.setSeverity(FacesMessage.SEVERITY_INFO);\r\n";
          masterDetail1To1Check += "\t\t\tFacesMessages.instance().add(message);\r\n";
          masterDetail1To1Check += "\t\t\treturn returningPage;\r\n";
          masterDetail1To1Check += "\t\t}\r\n";
        }

        if (relationship.getMappedBy().equals(""))
        {
          // Questa bean e' l'owner della relazione
        }
        else
        {
          // Questo bean non e' l'owner della relazione

          // Creazione
          notOwnedRelationshipCreate += "\r\n";
          notOwnedRelationshipCreate += "\t\t" + relationship.getToBeanName() + " local" + Utils.makeFirstLetterUpperCase(Utils.makeMethod2Field(relationship.getName())) + " = " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + relationship.getName() + "();\r\n";
          notOwnedRelationshipCreate += "\r\n";
          notOwnedRelationshipCreate += "\t\tif (local" + Utils.makeFirstLetterUpperCase(Utils.makeMethod2Field(relationship.getName())) + " != null)\r\n";
          notOwnedRelationshipCreate += "\t\t{\r\n";
          notOwnedRelationshipCreate += "\t\t\tlocal" + Utils.makeFirstLetterUpperCase(Utils.makeMethod2Field(relationship.getName())) + "." + Utils.switchGet2Set(inverseRelationship.getName()) + "(" + Utils.makeFirstLetterLowerCase(bean.getName()) + ");\r\n";
          notOwnedRelationshipCreate += "\t\t\tentityManager.merge(local" + Utils.makeFirstLetterUpperCase(Utils.makeMethod2Field(relationship.getName())) + ");\r\n";
          notOwnedRelationshipCreate += "\t\t}\r\n";

          // Modifica
          notOwnedRelEditRemoveExistingItems += "\r\n";
          if (notOwnedRelEditRemoveExistingItems.contains("\t\t" + relationship.getToBeanName() + " old" + relationship.getToBeanName()))
            notOwnedRelEditRemoveExistingItems += "\t\told" + relationship.getToBeanName();
          else
            notOwnedRelEditRemoveExistingItems += "\t\t" + relationship.getToBeanName() + " old" + relationship.getToBeanName();
          //notOwnedRelEditRemoveExistingItems += " = entityManager.find(" + bean.getName() + ".class," + Utils.makeFirstLetterLowerCase(bean.getName()) + ".getId())." + relationship.getName() + "();\r\n";
          notOwnedRelEditRemoveExistingItems += " = " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + relationship.getName() + "();\r\n";
          notOwnedRelEditRemoveExistingItems += "\r\n";
          notOwnedRelEditRemoveExistingItems += "\t\tif (old" + relationship.getToBeanName() + " != null)\r\n";
          notOwnedRelEditRemoveExistingItems += "\t\t{\r\n";
          notOwnedRelEditRemoveExistingItems += "\t\t\told" + relationship.getToBeanName() + "." + Utils.makeSet(relationship.getMappedBy()) + "(null);\r\n";
          notOwnedRelEditRemoveExistingItems += "\t\t\tentityManager.merge(old" + relationship.getToBeanName() + ");\r\n";
          notOwnedRelEditRemoveExistingItems += "\t\t}\r\n";

          notOwnedRelationshipEdit += "\r\n";
          notOwnedRelationshipEdit += "\t\t" + relationship.getToBeanName() + " local" + Utils.makeFirstLetterUpperCase(Utils.makeMethod2Field(relationship.getName())) + " = " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + relationship.getName() + "();\r\n";
          notOwnedRelationshipEdit += "\r\n";
          notOwnedRelationshipEdit += "\t\tif (local" + Utils.makeFirstLetterUpperCase(Utils.makeMethod2Field(relationship.getName())) + " != null)\r\n";
          notOwnedRelationshipEdit += "\t\t{\r\n";
          notOwnedRelationshipEdit += "\t\t\tlocal" + Utils.makeFirstLetterUpperCase(Utils.makeMethod2Field(relationship.getName())) + "." + Utils.makeSet(relationship.getMappedBy()) + "(" + Utils.makeFirstLetterLowerCase(bean.getName()) + ");\r\n";
          notOwnedRelationshipEdit += "\t\t\tentityManager.merge(local" + Utils.makeFirstLetterUpperCase(Utils.makeMethod2Field(relationship.getName())) + ");\r\n";
          notOwnedRelationshipEdit += "\t\t}\r\n";

          // Cancellazione
          notOwnedRelationshipDelete += "\r\n\r\n";
          notOwnedRelationshipDelete += "\t\t" + relationship.getToBeanName() + " local" + Utils.makeFirstLetterUpperCase(Utils.makeMethod2Field(relationship.getName())) + " = " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + relationship.getName() + "();\r\n";
          notOwnedRelationshipDelete += "\r\n";
          notOwnedRelationshipDelete += "\t\tif (local" + Utils.makeFirstLetterUpperCase(Utils.makeMethod2Field(relationship.getName())) + " != null)\r\n";
          notOwnedRelationshipDelete += "\t\t{\r\n";
          notOwnedRelationshipDelete += "\t\t\tlocal" + Utils.makeFirstLetterUpperCase(Utils.makeMethod2Field(relationship.getName())) + "." + Utils.makeSet(relationship.getMappedBy()) + "(null);\r\n";
          notOwnedRelationshipDelete += "\t\t\tentityManager.merge(local" + Utils.makeFirstLetterUpperCase(Utils.makeMethod2Field(relationship.getName())) + ");\r\n";
          notOwnedRelationshipDelete += "\t\t}\r\n";
        }
      }
    }

    /**
     * Inserimento funzione getPath se il bean e' master o detail in almeno una
     * relazione *
     */
    getPath = false;
    getPathFunction = "";
    for (int i = 0; i < bean.getRelationships().size(); i++)
    {
      Relationship relationship = bean.getRelationships().get(i);
      if (relationship.isUsed() && relationship.isMasterDetail())
        getPath = true;
    }
    if (getPath)
    {
      getPathFunction += "\r\n";
      getPathFunction += "\tpublic String getPath()\r\n";
      getPathFunction += "\t{\r\n";

      getPathFunction += "\t\tif (masterReference)\r\n";
      getPathFunction += "\t\t\treturn SeamUtility.path2String();\r\n";

      getPathFunction += "\t\treturn \"\";\r\n";
      getPathFunction += "\t}\r\n";
    }

    /** Gestione delle relazioni MASTER_DETAIL di cui questo bean e' DETAIL **/
    /** Individuazione dei bean DETAIL di questo **/
    for (int i = 0; i < bean.getRelationships().size(); i++)
    {
      Relationship relationship = bean.getRelationships().get(i);

      if (relationship.isUsed() && relationship.isMasterDetail() && !relationship.isFromMaster())
      {
        if (!referenceToMaster.contains("PathItem pathInfo"))
          referenceToMaster += "PathItem pathInfo = SeamUtility.getReferenceToMaster();\r\n\r\n";

        referenceToMaster += "\t\tif (pathInfo.getId() != null && pathInfo.getBeanName().equals(\"" + relationship.getToBeanName() + "\"))\r\n";
        if (!relationship.isToMany())
          referenceToMaster += "\t\t\t" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeSet(Utils.makeMethod2Field(relationship.getName())) + "(" + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + ");\r\n\r\n";
        else
          referenceToMaster += "\t\t\t" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeAdd(Utils.makeMethod2Field(relationship.getName())) + "(" + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + ");\r\n\r\n";
      }

      if (relationship.isMasterDetail() && relationship.isFromMaster())
      {
        /** Costruzione dei metodi di chiamata ai dettagli **/
        Vector<ShowList> lists = infoReader.getLists(relationship.getToBeanName());
        for (ShowList list : lists)
        {
          goToDetails += "\r\n";
          goToDetails += "\tpublic String goTo" + list.getName() + "()\r\n";
          goToDetails += "\t{\r\n";
          goToDetails += "\t\tString label=\"\";\r\n\r\n";

          // Gli attributi di riferimento al master sono sulla relazione
          // che va dal detail al master
          // Qui si sta generando il master per cui e' necessario ricercare
          // la relazione che dal detail
          // va al master

          Relationship relk = infoReader.getRelationshipToMaster(relationship.getToBeanName(), bean.getName());

          for (int k = 0; k < relk.getMasterAttributes().size(); k++)
          {
            if (k > 0)
              goToDetails += "\t\tlabel += \" - \";\r\n";

            if (relk.getMasterAttributes().get(k).getType().equals("java.util.Date"))
              // goToDetails += "\t\tlabel += " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(relk.getMasterAttributes().get(k).getName()) + "()DATA;\r\n";
              goToDetails += "\t\tlabel += SeamUtility.convertDate(" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(relk.getMasterAttributes().get(k).getName()) + "(),SeamUtility.getMessage(facesContext,\"Application_DateFormat\"));;\r\n";
            else
              goToDetails += "\t\tlabel += " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(relk.getMasterAttributes().get(k).getName()) + "();\r\n";
          }

          goToDetails += "\t\tSeamUtility.updateMasterDetailPath(\"" + bean.getName() + "\",label," + Utils.makeFirstLetterLowerCase(bean.getName()) + ".getId());\r\n\r\n";
          goToDetails += "\t\treturn \"/list/" + list.getName() + "List.seam?masterReference=true\";\r\n";
          goToDetails += "\t}\r\n";
View Full Code Here

  private static CodeChunk generateBeanManager_ListBoxFunctions(InfoReader infoReader, Bean bean, Vector<Relationship> relationships2ThisBean) throws Exception
  {
    CodeChunk listMethods = new CodeChunk(0);
    for (int i = 0; i < relationships2ThisBean.size(); i++)
    {
      Relationship rel = relationships2ThisBean.get(i);

      if ((rel.isUsed() && rel.isListBox()) || belongs2SearchAttribute(infoReader.getBean(rel.getFromBeanName()), rel))
      {
        // if (rel.isToMany())
        // {
        // ;
        // }
        // else
        // {
        String relatedAttributes = "";
        for (int k = 0; k < rel.getRelatedAttributes().size(); k++)
        {
          relatedAttributes += Utils.makeFirstLetterUpperCase(rel.getRelatedAttributes().get(k).getName());
        }

        CodeChunk tmp = new CodeChunk(0);

        tmp.addJavaCode("public HashMap<String, " + bean.getName() + "> get" + bean.getName() + "List");
        tmp.addJavaCode(relatedAttributes);
        tmp.addJavaCode("() throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException\r\n");
        tmp.addJavaCode("\t{\r\n");
        tmp.addJavaCode("\t\tString labels[] = {");

        for (int k = 0; k < rel.getRelatedAttributes().size(); k++)
        {
          if (k > 0)
            tmp.addJavaCode(",");

          tmp.addJavaCode("\"" + Utils.makeGet(rel.getRelatedAttributes().get(k).getName()) + "\"");
        }

        tmp.addJavaCode("};\r\n\r\n");

        tmp.addJavaCode("\t\tmakeList(labels);\r\n");
        tmp.addJavaCode("\r\n");

        // if (rel.isFromMany())
        if (!rel.isToMany())
        {
          // tmp.addJavaCode("\t\t" +
          // Utils.makeFirstLetterLowerCase(bean.getName()) + "Map.put(\"--
          // selezionare -- \", new " + bean.getName() + "());\r\n");
          // tmp.addJavaCode("\r\n");
View Full Code Here

        // "+relationship.getToBeanName()+"Manager
        // "+Utils.makeFirstLetterLowerCase(relationship.getToBeanName())+"Manager;\r\n");
      }

      InfoReader infoReader = new InfoReader(sourceDir);
      Relationship inverseRelationship = infoReader.getInverseRelationship(bean, relationship);

      if (relationship.isMasterDetail() && !relationship.isFromMaster() && inverseRelationship.isCategorized())
      {
        /** Riferimento al Master */
        ret[0].addJavaCode("@In(create = true, value = \"" + relationship.getToBeanName() + "Manager\")\r\n");
        ret[0].addJavaCode("\tprivate " + basePackage + ".manager.managerInterface." + relationship.getToBeanName() + "Manager        " + Utils.makeFirstLetterLowerCase(relationship.getToBeanName()) + "Manager;\r\n");
      }
View Full Code Here

   * Funzione per la predisposizione del codice nella create per piu' file di upload
   */
  private static String CreateNUploadManagement(Bean bean)
  {
    String ret = "";
    Relationship rel;

    /** Verifica il numero di file previsti per l'upload **/

    if ((rel = bean.getRelationship(Utils.makeGet(bean.getName() + "Uploads"))) == null)
      return ret;
View Full Code Here

     * Gestione dell'opzione relatedAndNewItemsOnlyInPop per tutte le relazioni
     * **/

    for (int i = 0; i < relationships2ThisBean.size(); i++)
    {
      Relationship camingRelationship = relationships2ThisBean.get(i);
      //Bean camingBean = infoReader.getBean(camingRelationship.getFromBeanName());

      //Relationship goingRelationship = infoReader.getInverseRelationship(camingBean, camingRelationship);

      if (camingRelationship.isRelatedAndNewItemsOnlyInPopUp())
      {
        findAll += "\r\n";
        findAll += "\t\tif (callingBean != null && callingBean instanceof " + camingRelationship.getFromBeanName() + ")\r\n";
        findAll += "\t\t{\r\n";
        findAll += "\t\t\tlocalSearchConditionAdded = true;\r\n";
        findAll += "\t\t\t// select o from Tipo o  left outer join o.documentoGenericos d where (o.nome='pippo' and d.id in (27)) or (o.nome='pippo' and o.id in (40))\r\n";
        findAll += "\t\t\t\r\n";
        findAll += "\t\t\t// Bean gia' collegati\r\n";

        Vector<KeyInfo> keyComponents = infoReader.getBeanKeyComponents(bean);

        if (camingRelationship.isToMany())
        {
          findAll += "\t\t\tif (((" + camingRelationship.getFromBeanName() + ") callingBean)." + camingRelationship.getName() + "()!=null && ((" + camingRelationship.getFromBeanName() + ") callingBean)." + camingRelationship.getName() + "().size()>0)\r\n";
          findAll += "\t\t\t{\r\n";
          findAll += "\t\t\t\tqb.addAndMultipleInCondition(((" + camingRelationship.getFromBeanName() + ")callingBean)." + camingRelationship.getName() + "());\r\n";
          findAll += "\t\t\t}\r\n";
          findAll += "\t\t\telse\r\n";
          findAll += "\t\t\t{\r\n";

          if (keyComponents.size() == 0)
          {
            findAll += "\t\t\t\tqb.addTextWhere(\"o.id = null\");\r\n";
          }
          else
          {
            for (int h = 0; h < keyComponents.size(); h++)
            {
              if (keyComponents.get(h).isString())
                findAll += "\t\t\t\tqb.addTextWhere(\"o.id." + Utils.makeMethod2Field(keyComponents.get(h).getMethod()) + " in (null)\");\r\n";
              else
                findAll += "\t\t\t\tqb.addTextWhere(\"o.id." + Utils.makeMethod2Field(keyComponents.get(h).getMethod()) + " in (null)\");\r\n";
            }
          }
          findAll += "\t\t\t}\r\n";
        }
        else
          findAll += "\t\t\t\tqb.addAndSingleInCondition(" + bean.getName() + ".class,((" + camingRelationship.getFromBeanName() + ")callingBean)." + camingRelationship.getName() + "());\r\n";

        findAll += "\t\t\t" + localSearchCondition;
        findAll += "\t\t\t\r\n";
        findAll += "\t\t\t// Bean appena creati\r\n";
        findAll += "\t\t\tif (justCreatedItems.size() > 0)\r\n";
        findAll += "\t\t\t{\r\n";
        findAll += "\t\t\t\tqb.openOrCondition();\r\n";
        findAll += "\t\t\t\tqb.addInCondition(justCreatedItems);\r\n";
        findAll += "\t\t\t\t" + localSearchCondition;
        findAll += "\t\t\t\tqb.closeOrContition();\r\n";
        findAll += "\t\t\t\t\r\n";
        findAll += "\t\t\t\tlog.debug(\"  query: \" + qb.getQuery());\r\n";
        findAll += "\t\t\t}\r\n";
        findAll += "\t\t}\r\n";
      }
    }

    /** Inserimento clausole per la local search * */

    if (bean.getLocalSearchAttributes().size() > 0)
    {
      findAll += "\r\n\t\tif (!localSearchConditionAdded && localSearch)\r\n";
      findAll += "\t\t{\r\n";
    }

    findAll += "\t\t\t" + localSearchCondition;

    if (bean.getLocalSearchAttributes().size() > 0)
    {
      findAll += "\t\t}\r\n";
    }
    else
      findAll += "\r\n";

    findAll += "// YOUR CODE GOES HERE\r\n";
    findAll += "@YourCode";
    findAll += "// END OF YOUR CODE\r\n\r\n";

    findAll += "\t\tqb.addTextWhere(customFilter,customFilter);\r\n\r\n";

    findAll += "\t\tswitch (order)\r\n";
    findAll += "\t\t{\r\n";

    int orderIndex = 1;
    String defaultOrdering = "";
    for (int i = 0; i < attrs.size(); i++)
    {
      ShowAttribute attr = attrs.get(i);

      if (!attr.isKey())
      {
        if (!attr.belongsToRelationship())
        {
          // Attributo del bean

          if (!attr.isTrans())
          {
            findAll += "\t\t\tcase " + orderIndex + ":\r\n";
            findAll += "\t\t\t\tqb.addOrderBy(\"o." + attr.getNameForOrdering() + " desc\");\r\n";
            findAll += "\t\t\t\tbreak;\r\n";
            orderIndex++;

            findAll += "\t\t\tcase " + orderIndex + ":\r\n";
            findAll += "\t\t\t\tqb.addOrderBy(\"o." + attr.getNameForOrdering() + " asc\");\r\n";
            findAll += "\t\t\t\tbreak;\r\n\r\n";
            orderIndex++;

            if (attr.getDefaultOrderingAttribute().equals("Asc"))
              defaultOrdering += "qb.addOrderBy(\"o." + attr.getNameForOrdering() + " asc\")";

            if (attr.getDefaultOrderingAttribute().equals("Desc"))
              defaultOrdering += "qb.addOrderBy(\"o." + attr.getNameForOrdering() + " desc\")";
          }
          else
          {
            orderIndex += 2;
          }
        }
        else
        {
          // Attributo di una relazione del bean

          if (!attr.getRelationship().isToMany())
          {
            findAll += "\t\t\tcase " + orderIndex + ":\r\n";
            //findAll += "\t\t\t\tqb.addOrderBy(\"o." + Utils.makeMethod2Field(attr.getRelationship().getName()) + "." + attr.getNameForOrdering() + " asc\");\r\n";           
            findAll += "\t\t\t\tqb.addOrderBy(\"o.";

            for (int j = 0; j < attr.getRelationships().size(); j++)
            {
              findAll += Utils.makeMethod2Field(attr.getRelationships().get(j).getName()) + ".";
            }

            findAll += attr.getNameForOrdering() + " desc\");\r\n";
            findAll += "\t\t\t\tbreak;\r\n";
            orderIndex++;

            findAll += "\t\t\tcase " + orderIndex + ":\r\n";
            // findAll += "\t\t\t\tqb.addOrderBy(\"o." + Utils.makeMethod2Field(attr.getRelationship().getName()) + "." + attr.getNameForOrdering() + " desc\");\r\n";
            findAll += "\t\t\t\tqb.addOrderBy(\"o.";

            for (int j = 0; j < attr.getRelationships().size(); j++)
            {
              findAll += Utils.makeMethod2Field(attr.getRelationships().get(j).getName()) + ".";
            }

            findAll += attr.getNameForOrdering() + " asc\");\r\n";

            findAll += "\t\t\t\tbreak;\r\n\r\n";
            orderIndex++;

            if (attr.getDefaultOrderingAttribute().equals("Asc"))
            {
              defaultOrdering += "qb.addOrderBy(\"o." + Utils.makeMethod2Field(attr.getRelationship().getName()) + "." + attr.getNameForOrdering() + " asc\")";
            }

            if (attr.getDefaultOrderingAttribute().equals("Desc"))
            {
              defaultOrdering += "qb.addOrderBy(\"o." + Utils.makeMethod2Field(attr.getRelationship().getName()) + "." + attr.getNameForOrdering() + " desc\")";
            }
          }
        }
      }
    }

    findAll += "// YOUR CODE GOES HERE\r\n";
    findAll += "@YourCode";
    findAll += "// END OF YOUR CODE\r\n";

    findAll += "\t\t\tdefault:\r\n";
    if (defaultOrdering.equals(""))
      findAll += "\t\t\t\tqb.addOrderBy(\"o.id desc\");\r\n";
    else
      findAll += "\t\t\t\t" + defaultOrdering + ";\r\n";

    findAll += "\t\t}\r\n\r\n";

    findAll += "\r\n";

    /** Filtro per relazione con il master * */
    String referenceToMaster = "\t\tPathItem myInfo = SeamUtility.getReferenceToMaster();\r\n";
    Relationship relToMaster = null;

    for (int i = 0; i < bean.getRelationships().size(); i++)
    {
      Relationship rel = bean.getRelationships().get(i);

      if (rel.isUsed() && rel.isMasterDetail() && !rel.isFromMaster())
      {
        relToMaster = rel;

        if (!relToMaster.isToMany())
        {
          referenceToMaster += "\r\n";
          referenceToMaster += "\r\n";
          referenceToMaster += "\t\tif (myInfo.getId()!=null && myInfo.getBeanName().equals(\"" + rel.getToBeanName() + "\"))\r\n";
          referenceToMaster += "\t\t{\r\n";
          referenceToMaster += "\t\t\tqb.addMasterReferenceWhere(\"o.\"+myInfo.getBeanField()+\".id = :masterId\",myInfo.getId());\r\n";
          referenceToMaster += "\t\t\tqb.setMasterReferenceParameter(\"masterId\",myInfo.getId());\r\n";
          referenceToMaster += "\t\t}\r\n";
          referenceToMaster += "\t\t\r\n";
        }
        else
        {
          referenceToMaster += "\r\n";
          referenceToMaster += "\r\n";
          referenceToMaster += "\t\tif (myInfo.getId()!=null && myInfo.getBeanName().equals(\"" + rel.getToBeanName() + "\"))\r\n";
          referenceToMaster += "\t\t{\r\n";

          referenceToMaster += "\t\t\tqb.addInnerJoin(\"o." + Utils.makeMethod2Field(relToMaster.getName()) + " master\");\r\n";
          referenceToMaster += "\t\t\tqb.addTextWhere(\"master.id = :masterId\");\r\n";

View Full Code Here

TOP

Related Classes of org.boco.seamwebappgen.info.Relationship

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.