Package org.boco.seamwebappgen.info

Examples of org.boco.seamwebappgen.info.SearchAttribute


    // Prepara la lista dei campi

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

      /**
       * I campi della ricerca non sono mai required
       */
      attribute.setRequired(false);

      CodeChunk codeChunk = new CodeChunk(attribute.getOrderInForm());

      if (!attribute.isKey())
      {
        if (!attribute.belongsToRelationship())
        {
          codeChunk.addHtmlCode("\t<tr><td width=\"100%\">\r\n");
          codeChunk.addHtmlCode("\t\t<rich:panel>\r\n");

          codeChunk.addHtmlCode("\t\t\t<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\r\n");
          codeChunk.addHtmlCode("\t\t\t<tr>\r\n");
          codeChunk.addHtmlCode("\t\t\t<td class=\"formFieldLabel\" >\r\n");
          codeChunk.addHtmlCode("\t\t\t\t<h:outputLabel for=\"" + attribute.getName() + "\"  value=\"#{msgs.form_" + bean.getName() + attribute.SeamLabel() + "}\" />\r\n");
          codeChunk.addHtmlCode("\t\t\t</td>\r\n");

          if (attribute.getType().equals("java.lang.Boolean"))
          {
            codeChunk.addHtmlCode("\r\n<trh:rowLayout width=\"100%\" >\r\n");
            codeChunk.addHtmlCode("\r\n<trh:cellFormat>\r\n");
            codeChunk.addHtmlCode("\r\nBOOLEAN NON SUPPORTATO\r\n");
            codeChunk.addHtmlCode("\r\n</trh:cellFormat>\r\n");
            codeChunk.addHtmlCode("\r\n</trh:rowLayout>\r\n");
          }
          if (attribute.getType().equals("java.util.Date"))
          {
            codeChunk.addHtmlCode("\r\n<trh:rowLayout width=\"100%\" >\r\n");
            codeChunk.addHtmlCode("\r\n<trh:cellFormat>\r\n");
            codeChunk.addHtmlCode("\r\nDATE NON SUPPORTATO\r\n");
            codeChunk.addHtmlCode("\r\n</trh:cellFormat>\r\n");
            codeChunk.addHtmlCode("\r\n</trh:rowLayout>\r\n");
          }
          if (attribute.getImplementationType() == AttributeImplementationType.TEXTAREA)
          {
            codeChunk.addHtmlCode("\r\n<trh:rowLayout width=\"100%\">\r\n");
            codeChunk.addHtmlCode("\r\n<trh:cellFormat>\r\n");
            codeChunk.addHtmlCode("\r\nTEXT AREA NON SUPPORTATO\r\n");
            codeChunk.addHtmlCode("\r\n</trh:cellFormat>\r\n");
            codeChunk.addHtmlCode("\r\n</trh:rowLayout>\r\n");
          }
          if (attribute.getImplementationType() == AttributeImplementationType.FORMATTEDTEXTAREA)
          {
            codeChunk.addHtmlCode("\r\n<trh:rowLayout width=\"100%\">\r\n");
            codeChunk.addHtmlCode("\r\n<trh:cellFormat>\r\n");
            codeChunk.addHtmlCode("\r\nFORMATTEDTEXT AREA NON SUPPORTATO\r\n");
            codeChunk.addHtmlCode("\r\n</trh:cellFormat>\r\n");
            codeChunk.addHtmlCode("\r\n</trh:rowLayout>\r\n");
          }
          if (attribute.getImplementationType() == AttributeImplementationType.LISTBOX)
          {
            codeChunk.addHtmlCode("\r\n<trh:rowLayout width=\"100%\" >\r\n");
            codeChunk.addHtmlCode("\r\n<trh:cellFormat>\r\n");
            codeChunk.addHtmlCode("\r\nLIST BOX NON SUPPORTATO\r\n");
            codeChunk.addHtmlCode("\r\n</trh:cellFormat>\r\n");
            codeChunk.addHtmlCode("\r\n</trh:rowLayout>\r\n");
          }
          if (attribute.getImplementationType() == AttributeImplementationType.TEXT)
          {
            codeChunk.addHtmlCode("\t\t\t<td>\r\n");
            codeChunk.addHtmlCode("\t\t\t\t" + insertAttribute2Form(attribute, bean.getName(), true, true) + "\r\n");
            codeChunk.addHtmlCode("\t\t\t\t<br />\r\n");
            codeChunk.addHtmlCode("\t\t\t\t<h:message for=\"" + attribute.getName() + "\" errorClass=\"rich-messages-label\" />\r\n");

            codeChunk.addHtmlCode("\t\t\t</td>\r\n");
          }

          codeChunk.addHtmlCode("\t\t\t</tr>\r\n");
          codeChunk.addHtmlCode("\t\t\t</table>\r\n");
          codeChunk.addHtmlCode("\t\t</rich:panel>\r\n");
          codeChunk.addHtmlCode("\t</td></tr>\r\n");

          codeChunks.add(codeChunk);
        }
        else
        {
          // Attributo di ricerca appartenente ad una relazione
          Relationship firstRelationship = attribute.getRelationship();

          /**
           * I campi della ricerca non sono mai required
           */
          firstRelationship.setRequired(false);

          if (attribute.getRelationships().size() == 1)
          {
            // L'attributo e' nella forma relazione.attributo

            if (firstRelationship.isIgnoreImplementation())
            {
              // Gli attributi debbono essere inseriti come Text

              if (attribute.getType().equals("java.util.Date"))
              {
                codeChunk.addHtmlCode("\r\n<trh:rowLayout width=\"100%\" >\r\n");
                codeChunk.addHtmlCode("\t<trh:cellFormat styleClass=\"formFieldLabel\" ><tr:outputLabel value=\"#{msgs.form_" + bean.getName() + "_search" + attribute.SeamLabel() + "}\" /></trh:cellFormat>\r\n");

                codeChunk.addHtmlCode("\t<trh:cellFormat>\r\n");

                if (firstRelationship.isToMany())
                {
                  /** Relazione :N **/
                  String singularRelationshipName = Utils.makeMethod2SingularField(firstRelationship.getName());

                  codeChunk.addHtmlCode("\t\t<rich:dataTable id=\"tab_" + singularRelationshipName + "_" + attribute.getName() + "\" var=\"" + singularRelationshipName + "\" value=\"#{" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeMethod2Field(firstRelationship.getName()) + "}\" width=\"100%\" >\r\n");

                  codeChunk.addHtmlCode("\t\t\t<rich:column");

                  if (attribute.getType().contains("Double") || attribute.getType().contains("Integer") || attribute.getType().contains("Long"))
                  {
                    codeChunk.addHtmlCode(" align=\"right\" ");
                  }

                  if (attribute.getType().contains("String"))
                  {
                    codeChunk.addHtmlCode(" align=\"left\" ");
                  }

                  if (attribute.getType().contains("Date") || attribute.getType().contains("Boolean"))
                  {
                    codeChunk.addHtmlCode(" align=\"center\" ");
                  }

                  codeChunk.addHtmlCode(">\r\n");
                  codeChunk.addHtmlCode("\t\t\t\t<f:facet name=\"header\">\r\n");
                  codeChunk.addHtmlCode("\t\t\t\t</f:facet>\r\n");
                  codeChunk.addHtmlCode("\t\t\t\t<tr:inputDate id=\"" + attribute.getName() + "\" value=\"#{" + singularRelationshipName + "." + attribute.getName() + "}\" >\r\n");
                  codeChunk.addHtmlCode("\t\t\t\t\t<f:convertDateTime type=\"date\" pattern=\"#{msgs.Application_DateFormat}\" />\r\n");
                  codeChunk.addHtmlCode("\t\t\t\t</tr:inputDate>\r\n");
                  codeChunk.addHtmlCode("\t\t\t</rich:column>\r\n");
                  codeChunk.addHtmlCode("\t\t</rich:dataTable>\r\n");
                }
                else
                {
                  /** Relazione :1 **/
                  if (attribute.getType().equals("java.util.Date"))
                  {
                    codeChunk.addHtmlCode("\t\t<tr:inputDate id=\"" + attribute.getName() + "\" value=\"#{" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeMethod2Field(attribute.getRelationship().getName()) + "." + attribute.getName() + "}\" >\r\n");
                    codeChunk.addHtmlCode("\t\t\t<f:convertDateTime type=\"date\" pattern=\"#{msgs.Application_DateFormat}\" />\r\n");
                    codeChunk.addHtmlCode("\t\t</tr:inputDate>\r\n");
                  }
                  else
                    codeChunk.addHtmlCode("\t\t\t\tTipo non supportato nella ricerca\r\n");
                }

                codeChunk.addHtmlCode("\t</trh:cellFormat>\r\n");
                codeChunk.addHtmlCode("</trh:rowLayout>\r\n");

              }
              else
              {
                codeChunk.addHtmlCode("\r\n<trh:rowLayout width=\"100%\" >\r\n");
                codeChunk.addHtmlCode("\t<trh:cellFormat styleClass=\"formFieldLabel\" ><tr:outputLabel value=\"#{msgs.form_" + bean.getName() + "_search" + attribute.SeamLabel() + "}\" /></trh:cellFormat>\r\n");

                codeChunk.addHtmlCode("\t<trh:cellFormat width=\"100%\" >\r\n");
                codeChunk.addHtmlCode("\t\t<h:inputText id=\"" + attribute.getName() + "\" value=\"#{" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeMethod2Field(firstRelationship.getName()) + attribute.SeamField() + "}\" />\r\n");
                codeChunk.addHtmlCode("\t</trh:cellFormat>\r\n");
                codeChunk.addHtmlCode("</trh:rowLayout>\r\n");
              }
            }
            else
            {
              if (firstRelationship.isListBox())
              {
                // Gli attributi debbono essere inseriti come listbox

                if (firstRelationship.isToMany())
                {
                  codeChunk = insertMultipleSelectionListBox2Form(bean, firstRelationship, true, true);
                }
                else
                {
                  codeChunk = insertSingleSelectionListBox2Form(sourceDir, bean, firstRelationship, true, true);
                }
              }
              else
              {
                // Gli attributi debbono essere inseriti come popup
                if (firstRelationship.isToMany())
                {
                  codeChunk.addJavascriptCode("function openPopUp_" + firstRelationship.getName() + "()");
                  codeChunk.JavascriptNewLine();
                  codeChunk.addJavascriptCode("{");
                  codeChunk.JavascriptNewLine();
                  codeChunk.addJavascriptCode("\twindow.open(\"popup/" + bean.getName() + firstRelationship.getName() + "PopUp.seam?parentConversationId=\"+document.forms[\"form\"].elements['parentConversationId'].value+\"&conversationIsLongRunning=true\",\"" + firstRelationship.getToBeanName() + "Window\",\"resizable=yes,menubar=no,width=850,height=550,scrollbars=yes\");");
                  codeChunk.JavascriptNewLine();
                  codeChunk.addJavascriptCode("}");
                  codeChunk.JavascriptNewLine();

                  codeChunk.addHtmlCode("\r\n<trh:rowLayout width=\"100%\" >\r\n");

                  codeChunk.addHtmlCode("\t<trh:cellFormat styleClass=\"formFieldLabel\" >\r\n");

                  codeChunk.addHtmlCode("\t\t<tr:outputLabel for=\"" + Utils.makeFirstLetterLowerCase(bean.getName()) + "_" + Utils.makeFirstLetterLowerCase(firstRelationship.getName()) + "\" value=\"#{msgs.form_search_" + firstRelationship.ToSeamLabel() + "}\" />\r\n");
                  codeChunk.addHtmlCode("\t</trh:cellFormat>\r\n");

                  codeChunk.addHtmlCode("\t<trh:cellFormat><trh:tableLayout><trh:rowLayout width=\"100%\" ><trh:cellFormat>\r\n");

                  // BOB: Genera id sui pulsanti di selezione
                  codeChunk.addHtmlCode("\t\t<tr:goLink id=\"popup_" + firstRelationship.getName() + "\" value=\"Seleziona\" onclick=\"openPopUp_" + firstRelationship.getName() + "();\" styleClass=\"button\" rendered=\"#{(" + Utils.makeFirstLetterLowerCase(bean.getName()) + "Operation=='CREATE') or (" + Utils.makeFirstLetterLowerCase(bean.getName()) + "Operation=='EDIT') or (" + Utils.makeFirstLetterLowerCase(bean.getName()) + "Operation=='SEARCH')}\" />\r\n");

                  codeChunk.addHtmlCode("\t\t</trh:cellFormat><trh:cellFormat>\r\n");

                  codeChunk.addHtmlCode("\t\t</trh:cellFormat></trh:rowLayout></trh:tableLayout>\r\n");

                  codeChunk.addHtmlCode("\t</trh:cellFormat>\r\n");
                  codeChunk.addHtmlCode("</trh:rowLayout>\r\n");

                  codeChunk.addHtmlCode("\r\n<trh:rowLayout width=\"100%\" >\r\n");
                  codeChunk.addHtmlCode("\t<trh:cellFormat columnSpan=\"2\">\r\n");
                  codeChunk.addHtmlCode("\t\t<rich:dataTable id=\"tab_" + Utils.makeFirstLetterLowerCase(bean.getName()) + "_" + firstRelationship.getName() + "\" var=\"" + Utils.makeFirstLetterLowerCase(firstRelationship.getToBeanName()) + "\" value=\"#{" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeMethod2Field(firstRelationship.getName()) + "}\" width=\"100%\" rowBandingInterval=\"1\" verticalGridVisible=\"true\" horizontalGridVisible=\"false\" >\r\n");

                  for (int m = 0; m < firstRelationship.getRelatedAttributes().size(); m++)
                  {
                    ShowAttribute attr = firstRelationship.getRelatedAttributes().get(m);

                    codeChunk.addHtmlCode("\t\t\t<rich:column");

                    if (attr.getType().contains("Double") || attr.getType().contains("Integer") || attr.getType().contains("Long"))
                    {
                      codeChunk.addHtmlCode(" align=\"right\" ");
                    }

                    if (attr.getType().contains("String"))
                    {
                      codeChunk.addHtmlCode(" align=\"left\" ");
                    }

                    if (attr.getType().contains("Date") || attr.getType().contains("Boolean"))
                    {
                      codeChunk.addHtmlCode(" align=\"center\" ");
                    }

                    codeChunk.addHtmlCode(">\r\n");

                    codeChunk.addHtmlCode("\t\t\t\t<f:facet name=\"header\">\r\n");

                    codeChunk.addHtmlCode("\t\t\t\t\t<h:outputText value=\"#{msgs.form_" + bean.getName());

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

                    codeChunk.addHtmlCode("_" + attr.getName() + "");

                    codeChunk.addHtmlCode("}\" />\r\n");

                    codeChunk.addHtmlCode("\t\t\t\t</f:facet>\r\n");

                    if (attr.getRelationships().size() == 0)
                    {
                      codeChunk.addHtmlCode("\t\t\t\t<tr:outputText value=\"#{" + Utils.makeFirstLetterLowerCase(firstRelationship.getToBeanName()) + "." + attr.getName() + "}\" />\r\n");
                    }
                    else
                    {
                      codeChunk.addHtmlCode("\t\t\t\t<tr:outputText value=\"#{" + Utils.makeFirstLetterLowerCase(firstRelationship.getToBeanName()) + ".");

                      for (int k = 1; k < attr.getRelationships().size(); k++)
                      {
                        if (k > 1)
                          codeChunk.addHtmlCode(".");
                        codeChunk.addHtmlCode(Utils.makeMethod2Field(attr.getRelationships().get(k).getName()));
                      }

                      codeChunk.addHtmlCode("." + attr.getName());

                      codeChunk.addHtmlCode("}\" />\r\n");
                    }

                    codeChunk.addHtmlCode("\t\t\t</rich:column>\r\n");
                  }

                  codeChunk.addHtmlCode("\t\t</rich:dataTable>\r\n");
                  codeChunk.addHtmlCode("\t</trh:cellFormat>\r\n");
                  codeChunk.addHtmlCode("</trh:rowLayout>\r\n");
                }
                else
                {
                  codeChunk = insertSingleSelectionPopUp2Form(sourceDir, bean, firstRelationship, false, true);
                }
              }
            }
          }
          else
          {
            // Attributo nella forma [relazione.]*Attributo
            if (attribute.getRelationships().get(0).isIgnoreImplementation())
            {
              // Gli attributi debbono essere inseriti come Text
              codeChunk.addHtmlCode("\r\n<trh:rowLayout width=\"100%\" >\r\n");
              codeChunk.addHtmlCode("\t<trh:cellFormat styleClass=\"formFieldLabel\" >");
              codeChunk.addHtmlCode("<tr:outputLabel value=\"#{msgs.form_" + bean.getName());

              codeChunk.addHtmlCode("_" + attribute.getRelationships().get(0).getName());
              codeChunk.addHtmlCode(attribute.SeamLabel() + "}\" /></trh:cellFormat>\r\n");
              codeChunk.addHtmlCode("\t<trh:cellFormat  >\r\n");

              codeChunk.addHtmlCode("\t\t<tr:inputText value=\"#{" + Utils.makeFirstLetterLowerCase(bean.getName()));

              for (Relationship rel : attribute.getRelationships())
              {
                codeChunk.addHtmlCode("." + Utils.makeMethod2Field(rel.getName()));
              }
              codeChunk.addHtmlCode("." + attribute.getName() + "}\" />\r\n");

              codeChunk.addHtmlCode("\t</trh:cellFormat>\r\n");
              codeChunk.addHtmlCode("</trh:rowLayout>\r\n");

              codeChunk.setOrder(attribute.getOrderInForm());
            }
            else
            {
              // codeChunk.setOrder(attribute.getOrderInForm());
              // codeChunk.addHtmlCode("\r\n<trh:rowLayout>\r\n");
              // codeChunk.addHtmlCode("\t<trh:cellFormat>NON SO
              // !</trh:cellFormat>\r\n");
              // codeChunk.addHtmlCode("\t\t<trh:cellFormat>NON SO
              // !</trh:cellFormat>\r\n");
              // codeChunk.addHtmlCode("</trh:rowLayout>\r\n");
            }

          }

          // System.out.println(codeChunks.getHtmlCode());
          // System.out.println(codeChunk.getHtmlCode());

          if (!codeChunks.getHtmlCode().contains(codeChunk.getHtmlCode()))
          {
            codeChunk.setOrder(attribute.getOrderInForm());
            codeChunks.add(codeChunk);
          }
        }
      }
    }
View Full Code Here


  {
    HashMap<String, Integer> relationshipCounts = new HashMap<String, Integer>();

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

      if (sAttr.belongsToRelationship())
      {
        String relName;

        if (sAttr.getName().contains("."))
        {
          Vector<String> items = Utils.splitRelationships(sAttr.getName());

          relName = items.get(items.size() - 2);
        }
        else
        {
          relName = sAttr.getRelationship().getName();
        }

        if (relationshipCounts.containsKey(relName))
        {
          Integer count;
View Full Code Here

   */
  public static boolean isUsedInSearch(Vector<SearchAttribute> searchAttributes, Relationship rel)
  {
    for (int i = 0; i < searchAttributes.size(); i++)
    {
      SearchAttribute attr = searchAttributes.get(i);

      if (attr.getRelationship() != null && attr.getRelationship().equals(rel))
      {
        return true;
      }
    }

View Full Code Here

    codeChunks.clear();

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

      CodeChunk chunk = new CodeChunk(attr.getOrderInForm());

      if (attr.belongsToRelationship())
      {
        if (attr.getRelationship().isToMany())
        {
          // Attributo di ricerca appartiene ad una relazione :N

          chunk.HtmlNewLine();

          chunk.addHtmlCode("\t\t\t\t\t<h:outputLabel value=\"#{msgs.localSearch_" + bean.getName() + "_" + attr.getRelationship().getName() + "_" + attr.getName() + "}\" styleClass=\"formFieldLabel\" />\r\n");
          chunk.addHtmlCode("\t\t\t\t\t<h:selectManyListbox value=\"#{" + bean.getName() + "Manager." + attr.getRelationship().getFromBeanName() + "Manager.localSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + "}\" ");

          // Inserisce gli eventuali eventi presenti
          Vector<String> events = attr.getEvents();
          Vector<String> eventFunctions = attr.getEventFunctions();

          for (int k = 0; k < events.size(); k++)
          {
            chunk.addHtmlCode(events.get(k) + "=" + "\"" + eventFunctions.get(k) + "\"");
          }

          chunk.addHtmlCode(" styleClass=\"formField\" >");

          chunk.addHtmlCode("\t\t\t\t\t\t<s:selectItems value=\"#{" + attr.getRelationship().getToBeanName() + "Manager.getSelectionItems(false," + Utils.makeFirstLetterLowerCase(bean.getName()) + ",'" + attr.getRelationship().getName() + "')}\" var=\"" + Utils.makeFirstLetterLowerCase(attr.getRelationship().getToBeanName()) + "\" ");

          chunk.addHtmlCode("label=\"");

          for (int k = 0; k < attr.getRelationship().getRelatedAttributes().size(); k++)
          {
            if (k > 0)
              chunk.addHtmlCode(" - ");

            chunk.addHtmlCode("#{" + Utils.makeFirstLetterLowerCase(attr.getRelationship().getToBeanName()) + "." + attr.getRelationship().getRelatedAttributes().get(k).getName() + "}");
          }

          chunk.addHtmlCode("\"");

          chunk.addHtmlCode("/>\r\n");

          chunk.addHtmlCode("\t\t\t\t\t</h:selectManyListbox>\r\n");
        }
        else
        {
          // Attributo di ricerca appartiene ad una relazione :1

          chunk.HtmlNewLine();

          chunk.addHtmlCode("\t\t\t\t\t<h:outputLabel value=\"#{msgs.localSearch_" + bean.getName() + "_" + attr.getRelationship().getName() + "_" + attr.getName() + "}\" styleClass=\"formFieldLabel\" />\r\n");
          chunk.addHtmlCode("\t\t\t\t\t<h:selectOneMenu  value=\"#{" + bean.getName() + "Manager.localSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + "}\" ");

          // Inserisce gli eventuali eventi presenti
          Vector<String> events = attr.getEvents();
          Vector<String> eventFunctions = attr.getEventFunctions();

          for (int k = 0; k < events.size(); k++)
          {
            chunk.addHtmlCode(events.get(k) + "=" + "\"" + eventFunctions.get(k) + "\"");
          }

          chunk.addHtmlCode(" styleClass=\"formField\" >\r\n");

          chunk.addHtmlCode("\t\t\t\t\t\t<s:selectItems value=\"#{" + attr.getRelationship().getToBeanName() + "Manager.getSelectionItems(false," + Utils.makeFirstLetterLowerCase(bean.getName()) + ",'" + attr.getRelationship().getName() + "')}\" var=\"" + Utils.makeFirstLetterLowerCase(attr.getRelationship().getToBeanName()) + "\" ");

          chunk.addHtmlCode("label=\"");

          for (int k = 0; k < attr.getRelationship().getRelatedAttributes().size(); k++)
          {
            ShowAttribute relatedAttribute = attr.getRelationship().getRelatedAttributes().get(k);

            if (relatedAttribute.getRelationships().size() == 0)
            {
              if (k > 0)
                chunk.addHtmlCode(" - ");

              chunk.addHtmlCode("#{" + Utils.makeFirstLetterLowerCase(attr.getRelationship().getToBeanName()) + "." + relatedAttribute.getName() + "}");
            }
            else
            {
              /** Debbono essere gestiti gli attributi provenienti da relazioni **/
            }
          }

          chunk.addHtmlCode("\"");

          chunk.addHtmlCode(" noSelectionLabel=\"#{msgs.Application_noSelectionLabel}\" hideNoSelectionLabel=\"false\" />\r\n");
          //chunk.addHtmlCode(" />\r\n");

          chunk.addHtmlCode("\t\t\t\t\t\t<s:convertEntity />\r\n");
          chunk.addHtmlCode("\t\t\t\t\t</h:selectOneMenu>\r\n");
        }
      }
      else
      {
        if (attr.getImplementationType() == AttributeImplementationType.TEXT || attr.getImplementationType() == AttributeImplementationType.TEXTAREA || attr.getImplementationType() == AttributeImplementationType.FORMATTEDTEXTAREA)
        {
          chunk.HtmlNewLine();
          chunk.addHtmlCode("\t\t\t\t\t<h:outputLabel value=\"#{msgs.localSearch_" + bean.getName() + "_" + attr.getName() + "}\" styleClass=\"formFieldLabel\" />\r\n");
          chunk.addHtmlCode("\t\t\t\t\t<h:inputText style=\"width:100%;\" value=\"#{" + bean.getName() + "Manager.localSearch" + Utils.makeFirstLetterUpperCase(attr.getName()) + "}\" styleClass=\"formField\" />");
          chunk.HtmlNewLine();
        }
        else
          chunk.addHtmlCode("TIPO DI DATO NON SUPPORTATO");
      }
View Full Code Here

    // 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";

        }
      }

    }

    /** Gestione della local search -- variabili **/

    localSearchFields += "";
    localSearchFields += "private boolean\t\t\t\t\t\t\t\t\tlocalSearch\t\t\t\t\t\t= false;\r\n\r\n";
    for (int i = 0; i < bean.getLocalSearchAttributes().size(); i++)
    {
      SearchAttribute attr = bean.getLocalSearchAttributes().get(i);

      if (!attr.belongsToRelationship())
      {
        //        localSearchFields += "\t@In(create = true, required = false)\r\n";
        //        localSearchFields += "\t@Out(required = false)\r\n";
        if (attr.getImplementationType() == AttributeImplementationType.TEXT || attr.getImplementationType() == AttributeImplementationType.TEXTAREA)
        {
          localSearchFields += "\tprivate String\t\t\t\t\t\t\t\t\t\tlocalSearch" + Utils.makeFirstLetterUpperCase(attr.getName()) + "\t\t\t\t\t= null;\r\n";
        }
        else
        {
          localSearchFields = "TIPO DI DATO NON SUPPORTATO IN LOCAL SEARCH: " + attr.getImplementationType();
        }
      }
      else
      {
        // Attributo che appartiene ad una relazione
        localSearchFields += "\r\n";
        if (!attr.getRelationship().isToMany())
        {
          //localSearchFields += "\t@In(create = true, required = false)\r\n";
          //localSearchFields += "\t@Out(required = false)\r\n";
          localSearchFields += "\tprivate " + attr.getRelationship().getToBeanName() + "                localSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + "  = null;\r\n";
        }
        else
        {
          //localSearchFields += "\t@In(create = true, required = false)\r\n";
          //localSearchFields += "\t@Out(required = false)\r\n";
          localSearchFields += "\tprivate List <" + attr.getRelationship().getToBeanName() + ">            localSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + "  = null;\r\n";
        }
      }
    }

    /** Gestione della local search -- funzioni ausiliarie * */
    localSearch = "";
    localSearch += "public boolean isLocalSearch()\r\n";
    localSearch += "\t{\r\n";
    localSearch += "\t\treturn localSearch;\r\n";
    localSearch += "\t}\r\n\r\n";
    localSearch += "\tpublic void setLocalSearch(boolean search)\r\n";
    localSearch += "\t{\r\n";
    localSearch += "\t\tthis.localSearch = search;\r\n";
    localSearch += "\t}\r\n\r\n";
    localSearch += "\tpublic void startLocalSearch()\r\n";
    localSearch += "\t{\r\n";
    localSearch += "\t\tlocalSearch = true;\r\n";
    localSearch += "\t}\r\n\r\n";
    // localSearch += "\t@Begin(join = true)\r\n";
    localSearch += "\tpublic void stopLocalSearch()\r\n";
    localSearch += "\t{\r\n";

    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 += "\t\tlocalSearch" + Utils.makeFirstLetterUpperCase(attr.getName()) + " = null;\r\n";
      }
      else
      {
        localSearch += "\t\tlocalSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + " = null;\r\n";
      }
    }

    localSearch += "\t\tlocalSearch = false;\r\n\r\n";
    localSearch += "\t\t" + Utils.makeFirstLetterLowerCase(bean.getName()) + "List = null;\r\n";
    localSearch += "\t}\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 += "\t{\r\n";
        localSearch += "\t\treturn localSearch" + Utils.makeFirstLetterUpperCase(attr.getName()) + ";\r\n";
        localSearch += "\t}\r\n\r\n";

        localSearch += "\tpublic void setLocalSearch" + Utils.makeFirstLetterUpperCase(attr.getName()) + "(String localSearch" + Utils.makeFirstLetterUpperCase(attr.getName()) + ")\r\n";
        localSearch += "\t{\r\n";
        localSearch += "\t\tthis.localSearch" + Utils.makeFirstLetterUpperCase(attr.getName()) + " = localSearch" + Utils.makeFirstLetterUpperCase(attr.getName()) + ";\r\n";
        localSearch += "\t}\r\n\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 += "\t{\r\n";
            localSearch += "\t\treturn localSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + ";\r\n";
            localSearch += "\t}\r\n\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";
            localSearch += "\t{\r\n";
            localSearch += "\t\tthis.localSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + " = localSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + ";\r\n";
            localSearch += "\t}\r\n\r\n";
          }
          else
          {
            localSearch += "\tpublic " + attr.getRelationship().getToBeanName() + " getLocalSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + "()\r\n";
            localSearch += "\t{\r\n";
            localSearch += "\t\treturn localSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + ";\r\n";
            localSearch += "\t}\r\n\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";
            localSearch += "\t{\r\n";
            localSearch += "\t\tthis.localSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + " = localSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + ";\r\n";
            localSearch += "\t}\r\n\r\n";
          }
        }

      }
View Full Code Here

    /** Creazione della condizione per la localSearch * */
    String localSearchCondition = "";

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

      if (!attr.belongsToRelationship())
      {
        if (localSearchCondition.equals(""))
          localSearchCondition += "\r\n";

        localSearchCondition += "\t\t\tqb.addTextWhere(\"upper(o." + attr.getName() + ") like upper('%\" + localSearch" + Utils.makeFirstLetterUpperCase(attr.getName()) + " + \"%')\", localSearch" + Utils.makeFirstLetterUpperCase(attr.getName()) + ");\r\n";
      }
      else
      {
        // Attributo di ricerca locale appartente ad una relazione

        if (!attr.getRelationship().isToMany())
        {
          // Relazione :1

          localSearchCondition += "\r\n\t\t\tif (localSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + "!=null && localSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + ".getId()!=null)\r\n";
          localSearchCondition += "\t\t\t{\r\n";

          Vector<KeyInfo> keyInfo = infoReader.getBeanKeyComponents(infoReader.getBean(attr.getRelationship().getToBeanName()));

          if (keyInfo.size() == 0)
            localSearchCondition += "\t\t\t\tqb.addSingleValueListBoxWhere(\"o." + Utils.makeMethod2Field(attr.getRelationship().getName()) + ".id = \"+localSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + ".getId(), localSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + ".getId().toString());\r\n";
          else
          {
            for (int h = 0; h < keyInfo.size(); h++)
            {
              KeyInfo ki = keyInfo.get(h);

              if (ki.isString())
                localSearchCondition += "\t\t\t\tqb.addSingleValueListBoxWhere(\"o." + Utils.makeMethod2Field(attr.getRelationship().getName()) + ".id." + ki.getField() + " ='\"+localSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + ".getId()." + ki.getMethod() + "()+\"'\", localSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + ".getId().toString());\r\n";
              else
                localSearchCondition += "\t\t\t\tqb.addSingleValueListBoxWhere(\"o." + Utils.makeMethod2Field(attr.getRelationship().getName()) + ".id." + ki.getField() + " = \"+localSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + ".getId()." + ki.getMethod() + "(), localSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + ".getId().toString());\r\n";
            }
          }
          localSearchCondition += "\t\t\t}\r\n";
        }
        else
        {
          // Relazione :N

          localSearchCondition += "\r\n\t\t\tif (localSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + "!=null && !localSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + ".isEmpty())\r\n";
          localSearchCondition += "\t\t\t{\r\n";
          localSearchCondition += "\t\t\t\tqb.addMultipleValueListBoxWhere(\"o." + Utils.makeMethod2Field(attr.getRelationship().getName()) + " \",\"" + Utils.makeMethod2SingularField(attr.getRelationship().getName()) + "\",localSearch" + attr.getRelationship().getName() + Utils.makeFirstLetterUpperCase(attr.getName()) + ");\r\n";
          localSearchCondition += "\t\t\t}\r\n";
        }
      }
    }

    /**
     * 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";

          referenceToMaster += "\t\t\tqb.setMasterReferenceParameter(\"masterId\",myInfo.getId());\r\n";
          referenceToMaster += "\t\t}\r\n";
          referenceToMaster += "\t\t\r\n";
        }
      }
    }

    findAll += referenceToMaster;

    //    if (isDetail)
    //    {
    //      if (!relToMaster.isToMany())
    //      {
    //        findAll += "\r\n";
    //        findAll += "\r\n";
    //        findAll += "\t\tPathItem myInfo = SeamUtility.getReferenceToMaster();\r\n";
    //        findAll += "\t\tif (myInfo.getId()!=null)\r\n";
    //        findAll += "\t\t{\r\n";
    //        findAll += "\t\t\tqb.addMasterReferenceWhere(\"o.\"+myInfo.getBeanField()+\".id = :masterId\",myInfo.getId());\r\n";
    //        findAll += "\t\t\tqb.setMasterReferenceParameter(\"masterId\",myInfo.getId());\r\n";
    //        findAll += "\t\t}\r\n";
    //        findAll += "\t\t\r\n";
    //      }
    //      else
    //      {
    //        findAll += "\r\n";
    //        findAll += "\r\n";
    //        findAll += "\t\tPathItem myInfo = SeamUtility.getReferenceToMaster();\r\n";
    //        findAll += "\t\tif (myInfo.getId()!=null)\r\n";
    //        findAll += "\t\t{\r\n";
    //
    //        findAll += "\t\t\tqb.addInnerJoin(\"o." + Utils.makeMethod2Field(relToMaster.getName()) + " master\");\r\n";
    //        findAll += "\t\t\tqb.addTextWhere(\"master.id = :masterId\");\r\n";
    //
    //        findAll += "\t\t\tqb.setMasterReferenceParameter(\"masterId\",myInfo.getId());\r\n";
    //        findAll += "\t\t}\r\n";
    //        findAll += "\t\t\r\n";
    //      }
    // /** Filtro per la relazione con il master nel caso di relazione
    // categorizzata **/
    // findAll +=
    // "\t\tif("+Utils.makeFirstLetterLowerCase(masterBeanName)+" !=
    // null)\r\n";
    // findAll += "\t\t{\r\n";
    // findAll +=
    // "\t\t\tqb.addMasterReferenceWhere(\"o."+Utils.makeFirstLetterLowerCase(masterBeanName)+".id
    // = :masterId\",
    // "+Utils.makeFirstLetterLowerCase(masterBeanName)+".getId());\r\n";
    // findAll += "\t\t\tqb.setMasterReferenceParameter(\"masterId\",
    // "+Utils.makeFirstLetterLowerCase(masterBeanName)+".getId());\r\n";
    // findAll += "\t\t}\r\n";
    //    }

    findAll += "\t\tlog.debug(\"\tquery: \"+qb.getQuery());\r\n";
    findAll += "\t\tlong startTime = System.currentTimeMillis();\r\n";

    findAll += "\r\n";
    findAll += "\t\tentityManager.clear();\r\n";
    findAll += "\r\n";

    findAll += "\t\tListOrderedSet tmp = new ListOrderedSet();\r\n";
    findAll += "\t\ttmp.addAll(qb.getEjbQuery().getResultList());\r\n";

    findAll += "\t\tVector<" + bean.getName() + "> tmp1 = new Vector<" + bean.getName() + ">(tmp.asList());\r\n";
    findAll += "\t\t" + Utils.makeFirstLetterLowerCase(bean.getName()) + "List = tmp1;\r\n";

    findAll += "\r\n";

    /** Gestione della lista delle selezione per le PopUp - FRAMMENTO CODICE 2* */

    String popUpManagementTemplate = "." + File.separator + "templates" + File.separator + "Seam_FindAllPopUpManagement_2.java";

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

    tags.put("@Bean", bean.getName());
    tags.put("@bean", Utils.makeFirstLetterLowerCase(bean.getName()));

    String popUpManagement = Utils.SeamReplaceTag2String(tags, null, null, popUpManagementTemplate);

    findAll += popUpManagement;

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

    findAll += "\r\n\t\t// Gestione ordinamento dei campi transient\r\n";

    findAll += "\t\tswitch (order)\r\n";
    findAll += "\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())
          {
            findAll += "\t\t\tcase " + orderIndex + ":\r\n";
            findAll += "\t\t\t\t" + Utils.makeFirstLetterLowerCase(bean.getName()) + "List = SeamUtility.orderBy(" + Utils.makeFirstLetterLowerCase(bean.getName()) + "List, \"" + attr.getNameForOrdering() + "\", GenericFieldComparator.OrderType.DESC);\r\n";
            findAll += "\t\t\t\tbreak;\r\n";
            orderIndex++;

            findAll += "\t\t\tcase " + orderIndex + ":\r\n";
            findAll += "\t\t\t\t" + Utils.makeFirstLetterLowerCase(bean.getName()) + "List = SeamUtility.orderBy(" + Utils.makeFirstLetterLowerCase(bean.getName()) + "List, \"" + attr.getNameForOrdering() + "\", GenericFieldComparator.OrderType.ASC);\r\n";
            findAll += "\t\t\t\tbreak;\r\n\r\n";
            orderIndex++;
          }
          else
          {
View Full Code Here

TOP

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

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.