/***************************************************************************
* Copyright (c) 2004 - 2008 Fabrizio Boco fabboco@users.sourceforge.net *
* *
* *
* This is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License (version 2.1) as published by the Free Software Foundation *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
/**
- $Header: /usr/local/cvslocalrepository/SeamWebAppGenerator/src/org/boco/seamwebappgen/seamGeneration/Attic/BeanManagerGenerator.java,v 1.1.2.11 2008/06/03 15:48:30 fab Exp $
- $Author: fab $
- $Revision: 1.1.2.11 $
- $Date: 2008/06/03 15:48:30 $
- $Log: BeanManagerGenerator.java,v $
- Revision 1.1.2.11 2008/06/03 15:48:30 fab
- *** empty log message ***
-
- Revision 1.1.2.10 2008/05/27 17:00:49 fab
- Reingegnerizzazione delle CRUD in Poup
-
- Revision 1.1.2.9 2008/05/18 11:57:31 fab
- Fix nella edit delle relazioni not owned - Spostata la rimozione degli item esistenti nella initEdit
-
- Revision 1.1.2.8 2008/05/17 07:08:58 fab
- Fix generazione delle condizioni di ricerca
-
- Revision 1.1.2.7 2008/05/15 10:14:18 fab
- Generazione delle condizioni di ricerca - solo sui campi del bean
-
- Revision 1.1.2.6 2008/05/15 09:30:12 fab
- Gestione di azioni su tutti i bean risultato di una ricerca
-
- Revision 1.1.2.5 2008/05/15 05:21:02 fab
- Generazione condizione di ricerca per i campi text
-
- Revision 1.1.2.4 2008/05/05 14:29:54 fab
- Modifiche alla procedura di installazione
- Modifiche per gestione entity home
-
- Revision 1.1.2.3.2.3 2008/05/04 13:43:55 fab
- *** empty log message ***
-
- Revision 1.1.2.3.2.2 2008/05/04 06:39:23 fab
- *** empty log message ***
-
- Revision 1.1.2.3.2.1 2008/04/27 20:59:31 fab
- *** empty log message ***
-
- Revision 1.1.2.3 2008/04/25 08:26:15 fab
- Fix 0799/B
- Fix 0783/B
-
- Revision 1.1.2.2 2008/04/22 05:37:56 fab
- Aggiornamento indirizzo di posta
-
- Revision 1.1.2.1 2008/04/19 13:12:39 fab
- Modifiche varie per rafactoring
-
- Revision 1.1.2.1 2008/04/19 11:18:33 fab
- Refactoring
-
- Revision 1.17.4.11 2008/04/19 10:07:02 fab
- Aggiornamento riferimenti licenza
-
- Revision 1.17.4.10 2008/04/17 06:06:57 fab
- *** empty log message ***
-
- Revision 1.17.4.9 2008/04/10 18:23:45 fab
- Fix gestione ordinamento su campi transient nel risultato della global search
-
- Revision 1.17.4.8 2008/04/05 12:38:22 fab
- *** empty log message ***
-
- Revision 1.17.4.7 2008/04/02 13:25:05 fab
- Implementazione 0626/C
-
- Revision 1.17.4.6 2008/04/01 08:22:14 fab
- *** empty log message ***
-
- Revision 1.17.4.5 2008/03/27 20:11:16 fab
- Inserita security sulla ricercca globale
-
- Revision 1.17.4.4 2008/03/26 08:36:49 fab
- Implementazione 0627/C
-
- Revision 1.17.4.3 2008/03/22 16:51:58 fab
- *** empty log message ***
-
- Revision 1.17.4.2 2008/03/05 21:38:41 fab
- *** empty log message ***
-
- Revision 1.17.4.1 2008/03/04 08:45:24 fab
- *** empty log message ***
-
- Revision 1.17 2008/01/27 18:49:25 fab
- Inserita gestione versione generatore
-
- Revision 1.16 2008/01/22 12:49:44 fab
- Fix corretta gestione dell'ordinamento dei campi transient
-
- Revision 1.15 2008/01/09 18:15:35 fab
- Fix in codice custom della findAll
-
- Revision 1.14 2008/01/09 08:44:28 fab
- Fix gestione localsearch per bean con chiave a componenti multiple
-
- Revision 1.13 2008/01/07 19:46:25 bob
- Aggiunta codice custom
-
- Revision 1.12 2008/01/05 09:21:46 fab
- Fix vari
-
- Revision 1.11 2007/12/28 11:12:53 fab
- Modifca per creare direttamente in una popup gli item di una relazione implementata come PopUp
-
- Revision 1.10 2007/12/27 17:08:44 fab
- Fix vari per la corretta gestione di MASTER-DETAIL che coinvolgono bean figli
-
- Revision 1.9 2007/12/23 13:44:10 fab
- Implementazione 0174/C
-
- Revision 1.8 2007/12/23 13:20:14 fab
- Fix per la corretta gestione delle relazioni da e verso bean padre
- Fix per relazioni MASTER-DETAIL in cui nel form del DETAIL c'e' il riferimento al MASTER
-
- Revision 1.7 2007/12/21 11:07:04 fab
- Dopo merge per supporto jboss 4.2.2
-
- Revision 1.6.2.1 2007/12/10 10:23:30 fab
- Fix per supportare JBOSS 4.2.2.GA
-
- Revision 1.6 2007/12/02 07:34:14 fab
- *** empty log message ***
-
- Revision 1.5 2007/11/28 10:55:06 fab
- Fix 0348/C
-
- Revision 1.4 2007/10/26 10:20:51 fab
- Fix ed ottimizzazioni localSearch
-
- Revision 1.3 2007/10/25 09:54:25 fab
- Dopo merge TRINIDAD_1.2.2
-
- Revision 1.1.2.1 2007/10/24 06:51:07 fab
- Fix vari dal ramo head
-
- Revision 1.2 2007/10/24 06:42:21 fab
- Fix per codice custom nella makeList e mantenimento ordinamento items
-
- Revision 1.1 2007/09/29 13:17:20 fab
- Nuova versione iniziale del 29/09/2007
-
- Revision 1.22.2.61 2007/09/26 06:34:56 fab
- Fix per l'ordinamento dei campi transient
-
- Revision 1.22.2.60 2007/09/25 09:22:38 fab
- *** empty log message ***
-
- Revision 1.22.2.59 2007/09/17 14:06:36 fab
- Fix gestione popup
-
- Revision 1.22.2.58 2007/09/10 07:13:03 fab
- Fix ordinamento colonne
-
- Revision 1.22.2.57 2007/09/09 10:06:58 fab
- Fix gestione transazioni per processEdit
- Reformatting
-
- Revision 1.22.2.56 2007/09/05 07:12:51 fab
- Separato il codice di generazione della findAll nella funzione generateFindAllBody
-
- Revision 1.22.2.55 2007/09/05 06:15:04 fab
- Indicata fine funzione di generazione della findAll
-
- Revision 1.22.2.54 2007/09/04 10:34:22 fab
- Fix per la corretta gestione del formato delle date nel path
-
- Revision 1.22.2.53 2007/09/03 20:04:05 fab
- Fix per ordinamento su attributi di relazione nella forma [relationship.]*attribute
-
- Revision 1.22.2.52 2007/08/29 12:49:53 bob
- Tolte 'i', 'o' ed 'u' accentate
-
- Revision 1.22.2.51 2007/08/29 12:46:22 bob
- Tolta 'a' ed 'e' accentate
-
- Revision 1.22.2.50 2007/08/20 21:39:46 fab
- Fix gestione popup
-
- Revision 1.22.2.49 2007/07/29 17:52:20 fab
- Eliminata classe TreeMap per la gestione delle listbox e sostituita con HashMap per evitare errori strani con seam
-
- Revision 1.22.2.48 2007/07/29 17:20:13 fab
- Ulteriore fix per recuperare gli oggetti correlati al bean che chiama la popup dal callingBean nella conversazione
-
- Revision 1.22.2.47 2007/07/28 10:11:04 fab
- Fix per recuperare gli oggetti correlati al bean che chiama la popup dal callingBean nella conversazione
-
- Revision 1.22.2.46 2007/07/26 11:07:46 fab
- Eliminato fix per la gestione delle popup di cui il bean è owner - Non funziona
-
- Revision 1.22.2.45 2007/07/24 06:21:26 fab
- Fix per la corretta gestione delle popup nel caso in cui il bean nella popup sia l'owner della relazione
-
- Revision 1.22.2.44 2007/07/23 21:52:00 fab
- Fix per la corretta gestione delle popup nel caso in cui il bean nella popup sia l'owner della relazione
-
- Revision 1.22.2.43 2007/07/23 08:11:06 fab
- Fix ricerca
-
- Revision 1.22.2.42 2007/07/20 18:41:22 fab
- Fix per SEAM 2
-
- Revision 1.22.2.41 2007/07/18 06:58:17 fab
- *** empty log message ***
-
- Revision 1.22.2.40 2007/07/17 21:10:21 fab
- Fix gestione di più file allegati nello stesso form
-
- Revision 1.22.2.39 2007/07/17 20:22:05 fab
- Gestione di più file allegati nello stesso form
-
- Revision 1.22.2.38 2007/07/17 13:40:24 fab
- Fix gestione allegati in upload
-
- Revision 1.22.2.37 2007/07/13 07:44:29 fab
- Fix local search con relazioni
-
- Revision 1.22.2.36 2007/07/11 19:02:35 fab
- Fix per la corretta impostazione della relazione al MASTER nel caso il DETAIL possa avere più MASTER
-
- Revision 1.22.2.35 2007/07/10 16:34:31 fab
- Fix per il corretto riferimento al bean MASTER quando un bean è DETAIL in più relazioni MASTER-DETAIL
-
- Revision 1.22.2.34 2007/07/08 11:21:33 fab
- Eliminata chiamata a Referrer nella findAll
-
- Revision 1.22.2.33 2007/06/26 15:28:33 fab
- Fix nella findAll per bean con chiave a più componenti
-
- Revision 1.22.2.32 2007/06/26 08:40:20 fab
- Fix nella findAll per bean con chiave a più componenti
-
- Revision 1.22.2.31 2007/06/26 07:45:37 fab
- Fix nella findAll per bean con chiave a più componenti
-
- Revision 1.22.2.30 2007/06/23 12:25:28 fab
- Fix per ricerca locale sun relazioni :1 con chiavi a campi multipli
- Fix per la generazione della funzione di generazione degli items delle ListBox se le relative relazioni non sono implementate ListBox ma i campi appartengono alla ricerca locale
-
- Revision 1.22.2.29 2007/06/23 11:44:04 fab
- *** empty log message ***
-
- Revision 1.22.2.28 2007/06/23 09:15:47 fab
- Fix per la gestione di relatedAndNewItemsOnlyInPopUp con chiavi a componenti multiple
-
- Revision 1.22.2.27 2007/06/21 09:24:48 fab
- Modifiche per inserire controllo unicità detail nel caso di MASTER-DETAIL 1:1
-
- Revision 1.22.2.26 2007/06/18 10:28:11 fab
- Fix per gestione upload
-
- Revision 1.22.2.25 2007/06/16 12:25:10 fab
- Modifiche per supportare l'upload dei files con Trinidad - La versione esistente con Seam non funzionava
-
- Revision 1.22.2.24 2007/06/14 14:34:53 fab
- Fix nella generazione delle operazioni di cancellazione
-
- Revision 1.22.2.23 2007/06/10 07:07:29 fab
- Ulteriore fix per editing di relazioni LAZY !!!!
-
- Revision 1.22.2.22 2007/06/09 12:14:04 fab
- Modifiche per generare anche l'interfaccia Remote dei ManagerBean
-
- Revision 1.22.2.21 2007/05/31 20:21:46 fab
- Supporto per la gestione delle relazioni 1:1
-
- Revision 1.22.2.20 2007/05/30 14:16:41 fab
- Corretto mispelling referer in referrer
-
- Revision 1.22.2.19 2007/05/19 09:33:28 dev
- Moltissime modifiche
-
- Revision 1.22.2.18 2007/04/30 16:34:55 dev
- Rinominato relatedAndNewItemsOnlyInPop in relatedAndNewItemsOnlyInPopUp
-
- Revision 1.22.2.17 2007/04/30 16:07:43 dev
- Modifiche nella generazione per supportare il parametro relatedAndNewItemsOnlyInPop nelle relazioni
-
- Revision 1.22.2.16 2007/04/24 09:01:13 dev
- Fix vari
-
- Revision 1.22.2.15 2007/04/21 13:36:10 dev
- Modifiche varie alla generazione
- Modifiche per compatibilità con il nuovo jboss as 4.2.0.CR2
-
- Revision 1.22.2.14 2007/04/02 16:05:30 dev
- Modificata tipologia listbox per localsearch di relazioni :1
- Inserita opzione seleziona
-
- Revision 1.22.2.13 2007/03/27 10:09:39 dev
- Modifiche per gestire liste mutiple in relazioni Master-Detail
-
- Revision 1.22.2.12 2007/03/25 09:31:38 dev
- Modifiche per la gestione della sicurezza sulle azioni
-
- Revision 1.22.2.11 2007/03/24 17:26:00 dev
- Modifiche per generare più liste per il bean e gestione della sicurezza di ciascuna lista
-
- Revision 1.22.2.10 2007/03/06 11:36:32 dev
- Modifiche per logging
-
- Revision 1.22.2.9 2007/02/24 16:04:09 dev
- Modifiche per supportare le conditional validation
-
- Revision 1.22.2.8 2007/02/13 10:45:30 dev
- Modifiche alla gestione delle ListBox
-
- Revision 1.22.2.7 2007/02/09 11:20:49 dev
- Modifiche per la gestione delle viste categorizzate
-
- Revision 1.22.2.6 2007/02/03 13:10:33 dev
- Fix Vari
-
- Revision 1.22.2.5 2007/01/30 13:42:37 dev
- Modifica per supportare l'annotazione @AlternateOrderingAttribute
-
- Revision 1.22.2.4 2007/01/27 17:33:30 dev
- Gestione liste di ricerca
-
- Revision 1.22.2.3 2007/01/27 10:23:07 dev
- Generazione della pagina di ricerca
-
- Revision 1.22.2.2 2007/01/24 09:11:25 dev
- Fix per la localsearch
-
- Revision 1.22.2.1 2007/01/20 09:11:06 dev
- Tante modifiche che non sono descrivibili
-
- Revision 1.22 2007/01/07 14:35:08 dev
- Modifiche Dicembre 2006
-
- Revision 1.21 2007/01/03 11:32:22 dev
- Inseriti disclaymer e tag cvs
-
- Revision 1.20 2007/01/03 10:36:53 dev
- I Bean sono nella CONVERSATION
- Spostati i BeanManager nella SESSION
- Fix per la ricerca
-
- Revision 1.19 2007/01/02 20:25:10 dev
- Fix per la cancellazione delle relazioni lato not owned
-
- Revision 1.18 2007/01/02 16:05:29 dev
- Fix per la gestione delle popup
-
- Revision 1.17 2006/12/28 18:32:30 dev
- Modifiche per gestione della search
-
- Revision 1.16 2006/12/24 15:50:03 dev
- Fix per le relazioni N:M nell'uso corretto della relazione inversa
-
- Revision 1.15 2006/12/23 23:05:39 dev
- Fix per supportare correttamente la localSearch nella conversazione
-
- Revision 1.14 2006/12/17 20:44:06 dev
- Fix per supportare relazioni con nome non standard
-
- Revision 1.13 2006/12/10 16:40:05 dev
- Reingegnerizzazione del generatore per funzionare con le conversazioni anzichè la sessione
-
- Revision 1.12 2006/12/06 15:32:07 dev
- Fix per la gestione delle MASTER-DETAIL (non funziona bene !)
-
- Revision 1.11 2006/12/03 19:11:48 dev
- Fix per supportare bean ereditati
- Inserito filtro custom nella findAll
- Inseriti nuovi punti per codice custom
-
- Revision 1.10 2006/12/01 09:31:17 dev
- *** empty log message ***
-
- Revision 1.9 2006/11/30 20:52:55 dev
- Fix per consentire la selezione degli oggetti ricercati con la localSearch
-
- Revision 1.8 2006/11/24 19:17:04 dev
- Fix nella findAll per i localSearch
-
- Revision 1.7 2006/11/24 17:33:56 dev
- Fix per la localSearch
-
- Revision 1.6 2006/11/19 11:30:19 dev
- Modifica per attributi di ricerca locale derivanti da relazioni :N
-
- Revision 1.5 2006/11/18 11:46:21 dev
- Fix per la generazione dei riferimenti al master
-
- Revision 1.4 2006/11/12 12:26:38 dev
- Fix per gestire correttamente il lato owner delle relazioni nel caso di relazioni N:M
-
- Revision 1.3 2006/11/05 18:38:37 dev
- Modifiche per supportare dataScroller
-
- Revision 1.2 2006/11/01 11:07:26 dev
- Modifica per supportare dataScroller
-
- Revision 1.1 2006/10/23 08:25:32 dev
- Prima versione separata dal generatore struts
-
- Revision 1.20 2006/10/14 06:46:43 dev
- Fix per le localSearch con attributi di relazione
-
- Revision 1.19 2006/10/07 15:12:34 dev
- Change per la MakeList
-
- Revision 1.18 2006/10/05 14:30:35 dev
- Eliminata clausola Distinct dalla query nella findAll altrimenti si genera un errore nel sort delle colonne [relazione.]*attributo
-
- Revision 1.17 2006/10/01 14:13:13 dev
- Inizio supporto local search
-
- Revision 1.16 2006/09/28 09:13:47 dev
- Fix per l'accesso ai bean detail senza errori
-
- Revision 1.15 2006/09/16 16:41:49 dev
- Generazione delle relazioni Master-Detail
-
- Revision 1.14 2006/09/03 14:29:58 dev
- Modifiche per le relazioni MASTER_DETAIL
-
- Revision 1.13 2006/09/01 13:23:37 dev
- Fix per evitare la generazione multipla dei converter per le relazioni :1
-
- Revision 1.12 2006/09/01 12:40:54 dev
- Fix procesEdit per le relazioni notOwned
-
- Revision 1.11 2006/09/01 11:22:55 dev
- Fix procesEdit per le relazioni notOwned
-
- Revision 1.10 2006/08/30 17:40:00 dev
- Fix per evitale che lo stesso callingBean sia inserito più volte nel manager
-
- Revision 1.9 2006/08/29 14:04:25 dev
- Manager con PopUp relazione :1
- Fix al Manager per la gestione delle azioni sui singoli item della PopUp
-
- Revision 1.8 2006/08/25 10:10:37 dev
- Modifiche per la gestione delle PopUp
-
- Revision 1.7 2006/07/28 19:25:34 dev
- Supporto per relazioni :n come ListBox anche nella list
-
- Revision 1.6 2006/07/27 13:12:18 dev
- Supporto per relazioni :n come ListBox
-
- Revision 1.5 2006/07/27 07:17:37 dev
- Supporto per le relazioni :1 nelle list
-
- Revision 1.4 2006/07/26 11:46:07 dev
- Gestione relazioni :1 con ListBox
-
- Revision 1.3 2006/07/13 09:51:27 dev
- *** empty log message ***
-
- Revision 1.2 2006/07/12 06:18:51 dev
- Modifiche per inserire i riferimenti qualificati ai Bean
-
- Revision 1.1 2006/07/09 17:09:27 dev
- Versione iniziale della generazione del BeanManager
-
**/
package org.boco.seamwebappgen.seamGeneration;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;
import org.boco.seamwebappgen.annotations.AttributeImplementationType;
import org.boco.seamwebappgen.gui.Messages;
import org.boco.seamwebappgen.info.Attribute;
import org.boco.seamwebappgen.info.Bean;
import org.boco.seamwebappgen.info.InfoReader;
import org.boco.seamwebappgen.info.KeyInfo;
import org.boco.seamwebappgen.info.Relationship;
import org.boco.seamwebappgen.info.SearchAttribute;
import org.boco.seamwebappgen.info.ShowAttribute;
import org.boco.seamwebappgen.info.ShowList;
import org.boco.seamwebappgen.utils.CodeChunk;
import org.boco.seamwebappgen.utils.CustomCodeType;
import org.boco.seamwebappgen.utils.Utils;
/**
* Generatore della Manager di ciascun bean
*
* @author Fabrizio Boco
*/
public class BeanManagerGenerator
{
public static void generateManager(String sourceDir, String targetDir, String basePackage, Bean bean) throws Exception
{
String scope = "";
String orderingFunctions = "";
String findAll = "";
String notOwnedRelationshipCreate = "";
String notOwnedRelEditRemoveExistingItems = "";
String notOwnedRelationshipEdit = "";
String notOwnedRelationshipDelete = "";
String initilizeLazyRelationshipEdit = "";
String referenceToMaster = "";
String ownedRelationshipCreate = "";
String callingBeans = "";
String goToDetails = "";
String localSearch = "";
String localSearchFields = "";
String search = "";
String securityCreate = "";
String securityEdit = "";
String securityDelete = "";
String securitySearch = "";
CodeChunk detailsReference[];
String categorizedRelationshipToMaster = "";
String editDerivateBeans = "";
String displayDerivateBeans = "";
String deleteDerivateBeans = "";
String masterDetail1To1Check = "";
String sons = "";
InfoReader infoReader = new InfoReader(sourceDir);
CodeChunk listMethods = new CodeChunk(0);
Vector<ShowAttribute> attrs = bean.getShowAttributes();
attrs.add(bean.getKey());
/** **************************** */
/** Genera interfaccia Remota * */
/** **************************** */
String template = "." + File.separator + "templates" + File.separator + "Seam_ManagerInterfaceRemote.java";
String sourceFile = sourceDir + ".." + File.separator + "src" + File.separator + basePackage + File.separator + "manager/managerInterface" + File.separator + "remote" + File.separator + bean.getName() + "ManagerRemote.java";
String targetFile = targetDir + "src" + File.separator + basePackage + File.separator + "manager/managerInterface" + File.separator + "remote" + File.separator + bean.getName() + "ManagerRemote.java";
LinkedList<String> yourCode = Utils.getYourCode(sourceFile, CustomCodeType.JAVA);
HashMap<String, String> tags = new HashMap<String, String>();
tags.put("@basePackage", basePackage);
tags.put("@Bean", bean.getName());
tags.put("@bean", Utils.makeFirstLetterLowerCase(bean.getName()));
Utils.SeamReplaceTagAndSave(tags, yourCode, template, targetFile);
/** **************************** */
/** Genera interfaccia Locale * */
/** **************************** */
template = "." + File.separator + "templates" + File.separator + "Seam_ManagerInterface.java";
sourceFile = sourceDir + ".." + File.separator + "src" + File.separator + basePackage + File.separator + "manager/managerInterface" + File.separator + bean.getName() + "Manager.java";
targetFile = targetDir + "src" + File.separator + basePackage + File.separator + "manager/managerInterface" + File.separator + bean.getName() + "Manager.java";
yourCode = Utils.getYourCode(sourceFile, CustomCodeType.JAVA);
/** Metodi per ordinamento **/
orderingFunctions = generateBeanManagerInterface_OrderingFunctions(attrs);
/** Metodi per la alimentazione dei listbox * */
/*************************************************************************
* Sono interessate le relazioni :1 ed :n verso questo bean, implementate
* come list box i campi di ricerca implementati come listBox
*
************************************************************************/
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";
}
}
}
/** 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";
}
}
}
}
/** Gestione relazioni categorizzate **/
detailsReference = generateMasterDetailsReference(bean, sourceDir, basePackage);
/** Gestione della sicurezza sulle azioni **/
if (bean.getCreateCondition() != null)
securityCreate = securityCondition(bean.getCreateCondition());
else
securityCreate = roleCheck(bean.getRolesEnabledToCreate());
if (bean.getEditCondition() != null)
securityEdit = securityCondition(bean.getEditCondition());
else
securityEdit = roleCheck(bean.getRolesEnabledToEdit());
if (bean.getDeleteCondition() != null)
securityDelete = securityCondition(bean.getDeleteCondition());
else
securityDelete = roleCheck(bean.getRolesEnabledToDelete());
if (bean.getSearchCondition() != null)
securitySearch = securityCondition(bean.getSearchCondition());
else
securitySearch = roleCheck(bean.getRolesEnabledToSearch());
/** Gestione dei bean derivati **/
String derivateBeans = InsertDerivateBeansVariables(infoReader, bean);
displayDerivateBeans = InsertForwardToDerivateBean(infoReader, bean, "DISPLAY");
editDerivateBeans = InsertForwardToDerivateBean(infoReader, bean, "EDIT");
deleteDerivateBeans = InsertForwardToDerivateBean(infoReader, bean, "DELETE");
Vector<String> beans = infoReader.getDerivedBeans(bean.getName());
for (String derivateBean : beans)
{
sons += "|| referrer.contains(\"/" + derivateBean + "\")";
}
tags = new HashMap<String, String>();
tags.put("@generatorVersion", Messages.getString("WebAppGen.applicationVersion"));
tags.put("@ManagerScope", scope);
tags.put("@basePackage", basePackage);
tags.put("@Bean", bean.getName());
tags.put("@bean", Utils.makeFirstLetterLowerCase(bean.getName()));
tags.put("@FindAll", findAll);
tags.put("@OrderingFunctions", orderingFunctions);
tags.put("@ListMethods", listMethods.getJavaCode());
tags.put("@MasterDetail1To1Check", masterDetail1To1Check);
tags.put("@OwnedRelationshipCreate", ownedRelationshipCreate);
tags.put("@NotOwnedRelationshipCreate", notOwnedRelationshipCreate);
tags.put("@ReferenceToMaster", referenceToMaster);
tags.put("@NotOwnedRelEditRemoveExistingItems", notOwnedRelEditRemoveExistingItems);
tags.put("@NotOwnedRelationshipEdit", notOwnedRelationshipEdit);
tags.put("@NotOwnedRelationshipDelete", notOwnedRelationshipDelete);
tags.put("@InitilizeLazyRelationshipEdit", initilizeLazyRelationshipEdit);
tags.put("@CallingBeans", callingBeans);
tags.put("@GetPath", getPathFunction);
tags.put("@GoToDetails", goToDetails);
tags.put("@LocalSearch", localSearch);
tags.put("@FieldsLocalSearch", localSearchFields);
tags.put("@Search", search);
tags.put("@DetailsReference", detailsReference[0].getJavaCode());
tags.put("@CategorizedRelationshipToMaster", categorizedRelationshipToMaster);
tags.put("@SecurityCreate", securityCreate);
tags.put("@SecurityEdit", securityEdit);
tags.put("@SecurityDelete", securityDelete);
tags.put("@SecuritySearch", securitySearch);
tags.put("@DerivateBeans", derivateBeans);
tags.put("@EditDerivateBeans", editDerivateBeans);
tags.put("@DisplayDerivateBeans", displayDerivateBeans);
tags.put("@DeleteDerivateBeans", deleteDerivateBeans);
tags.put("@Create1UploadManagement", Create1UploadManagement(bean));
tags.put("@CreateNUploadManagement", CreateNUploadManagement(bean));
tags.put("@Edit1UploadManagement", edit1UploadManagement(bean));
tags.put("@EditNUploadManagement", editNUploadManagement(bean));
tags.put("@Sons", sons);
Utils.SeamReplaceTagAndSave(tags, yourCode, template, targetFile);
}
/**
* Generazione metodi per ordinamento
*/
private static String generateBeanManagerInterface_OrderingFunctions(Vector<ShowAttribute> attrs)
{
String orderingFunctions = "";
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 += "\tpublic void orderBy" + (i + 1) + "D();\r\n\r\n";
}
else
{
if (!attr.getRelationship().isToMany())
{
orderingFunctions += "\tpublic void orderBy" + (i + 1) + "A();\r\n";
orderingFunctions += "\tpublic void orderBy" + (i + 1) + "D();\r\n\r\n";
}
}
}
}
return orderingFunctions;
}
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");
}
tmp.addJavaCode("\t\treturn " + Utils.makeFirstLetterLowerCase(bean.getName()) + "Map;\r\n");
tmp.addJavaCode("\t}\r\n\r\n");
if (!listMethods.getJavaCode().contains(tmp.getJavaCode()))
{
listMethods.addJavaCode(tmp.getJavaCode());
}
}
}
return listMethods;
}
private static boolean belongs2SearchAttribute(Bean bean, Relationship rel)
{
Vector<SearchAttribute> attrs = bean.getLocalSearchAttributes();
for (SearchAttribute attribute : attrs)
{
if (attribute.belongsToRelationship() && attribute.getRelationship().getName().equals(rel.getName()))
return true;
}
return false;
}
private static CodeChunk[] generateMasterDetailsReference(Bean bean, String sourceDir, String basePackage) throws Exception
{
CodeChunk ret[] = new CodeChunk[2];
ret[0] = new CodeChunk(0);
ret[1] = new CodeChunk(0);
Vector<Relationship> relationships = bean.getRelationships();
for (Relationship relationship : relationships)
{
if (relationship.isMasterDetail() && relationship.isFromMaster() && relationship.isCategorized())
{
/** Riferimenti ai Details * */
// ret[0].addJavaCode("@EJB\r\n");
// ret[0].addJavaCode("\tprivate
// "+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");
}
}
return ret;
}
private static String securityCondition(String condition)
{
String ret = "";
ret += "@Restrict(\"" + condition + "\")";
return ret;
}
private static String roleCheck(Vector<String> roles)
{
String ret = "";
if (roles.size() > 0)
{
ret += "@Restrict(\"" + Utils.makeRolesCheckCondition(roles) + "\")";
}
return ret;
}
private static String InsertDerivateBeansVariables(InfoReader infoReader, Bean bean)
{
String ret = "";
Vector<String> derivateBeans = infoReader.getDerivedBeans(bean.getName());
for (String beanName : derivateBeans)
{
ret += "\t@In(value = \"" + beanName + "Manager\", create = true)\r\n";
ret += "\tprivate " + beanName + "Manager " + Utils.makeFirstLetterLowerCase(beanName) + "Manager;\r\n\r\n";
ret += "\t@In(value = \"" + Utils.makeFirstLetterLowerCase(beanName) + "\", create = true)\r\n";
ret += "\t@Out(value = \"" + Utils.makeFirstLetterLowerCase(beanName) + "\")\r\n";
ret += "\tprivate " + beanName + " " + Utils.makeFirstLetterLowerCase(beanName) + ";\r\n\r\n";
}
return ret;
}
private static String InsertForwardToDerivateBean(InfoReader infoReader, Bean bean, String Operation)
{
String ret = "";
Vector<String> derivateBeans = infoReader.getDerivedBeans(bean.getName());
for (String beanName : derivateBeans)
{
ret += "\t\tif (" + Utils.makeFirstLetterLowerCase(bean.getName()) + " instanceof " + beanName + ")\r\n";
ret += "\t\t{\r\n";
//ret += "\t\t\t" + Utils.makeFirstLetterLowerCase(beanName) + "Manager.set" + beanName + "Operation(\"" + Operation + "\");\r\n";
ret += "\t\t\t" + Utils.makeFirstLetterLowerCase(beanName) + "Manager.setOperation(\"" + Operation + "\");\r\n";
ret += "\t\t\t" + Utils.makeFirstLetterLowerCase(beanName) + "Manager.setReturningPage(returningPage);\r\n";
ret += "\t\t\t" + Utils.makeFirstLetterLowerCase(beanName) + " = (" + beanName + ") " + Utils.makeFirstLetterLowerCase(bean.getName()) + ";\r\n";
ret += "\t\t\treturn \"/" + beanName + ".xhtml\";\r\n";
ret += "\t\t}\r\n";
}
return ret;
}
/**
* Funzione per la predisposizione del codice nella create per un file di upload
*/
private static String Create1UploadManagement(Bean bean)
{
String ret = "";
/** Verifica il numero di file previsti per l'upload **/
if (bean.getRelationship(Utils.makeGet(bean.getName() + "Upload")) == null)
{
for (Attribute attr : bean.getAttributes())
{
if (attr.getType().equals("org.boco.seamUtility.upload.UploadedFile") || attr.getType().equals("UploadedFile"))
{
ret += "org.boco.seamUtility.upload.UploadedFile " + Utils.makeFirstLetterLowerCase(attr.getName()) + " = " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "();\t\r\n";
}
}
return ret;
}
for (Attribute attr : bean.getAttributes())
{
if (attr.getType().equals("org.boco.seamUtility.upload.UploadedFile") || attr.getType().equals("UploadedFile"))
{
ret += "if (" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "() != null && " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "().getLength() > 0)\r\n";
ret += "\t\t{\r\n";
ret += "\t\t\ttry\r\n";
ret += "\t\t\t{\r\n";
ret += "\t\t\t\torg.boco.seamUtility.upload.FileManagement fm = new org.boco.seamUtility.upload.FileManagement();\r\n\r\n";
ret += "\t\t\t\tfm.setContentType(" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "().getContentType());\r\n";
ret += "\t\t\t\tfm.setFileName(" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "().getFilename());\r\n\r\n";
ret += "\t\t\t\tjava.io.DataInputStream dis = new java.io.DataInputStream(" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "().getInputStream());\r\n";
ret += "\t\t\t\tbyte buffer[] = new byte[(int) " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "().getLength()];\r\n";
ret += "\t\t\t\tdis.readFully(buffer);\r\n";
ret += "\t\t\t\tfm.setData(buffer);\r\n";
ret += "\t\t\t\t\r\n";
ret += "\t\t\t\tnewUpload" + bean.getName() + "." + Utils.makeSet(attr.getName()) + "Fm(fm);\r\n";
ret += "\t\t\t\tnewUpload" + bean.getName() + " = entityManager.merge(newUpload" + bean.getName() + ");\r\n\r\n";
ret += "\t\t\t\t" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeSet(bean.getName()) + "Upload(newUpload" + bean.getName() + ");\r\n";
ret += "\t\t\t}\r\n";
ret += "\t\t\tcatch(java.io.IOException e)\r\n";
ret += "\t\t\t{\r\n";
ret += "\t\t\t\te.printStackTrace();\r\n";
ret += "\t\t\t}\r\n";
ret += "\t\t}\r\n";
}
}
return ret;
}
/**
* 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;
/** Individua la relaizione inversa **/
for (Attribute attr : bean.getAttributes())
{
if (attr.getType().equals("org.boco.seamUtility.upload.UploadedFile") || attr.getType().equals("UploadedFile"))
{
ret += "if (" + Utils.makeFirstLetterLowerCase(attr.getName()) + " != null && " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "().getLength() > 0)\r\n";
ret += "\t\t{\r\n";
ret += "\t\t\ttry\r\n";
ret += "\t\t\t{\r\n";
ret += "\t\t\t\torg.boco.seamUtility.upload.FileManagement fm = new org.boco.seamUtility.upload.FileManagement();\r\n\r\n";
ret += "\t\t\t\tfm.setContentType(" + Utils.makeFirstLetterLowerCase(attr.getName()) + ".getContentType());\r\n";
ret += "\t\t\t\tfm.setFileName(" + Utils.makeFirstLetterLowerCase(attr.getName()) + ".getFilename());\r\n\r\n";
ret += "\t\t\t\tjava.io.DataInputStream dis = new java.io.DataInputStream(" + Utils.makeFirstLetterLowerCase(attr.getName()) + ".getInputStream());\r\n";
ret += "\t\t\t\tbyte buffer[] = new byte[(int) " + Utils.makeFirstLetterLowerCase(attr.getName()) + ".getLength()];\r\n";
ret += "\t\t\t\tdis.readFully(buffer);\r\n";
ret += "\t\t\t\tfm.setData(buffer);\r\n";
ret += "\t\t\t\t\r\n";
ret += "\t\t\t\tupload." + Utils.makeSet(bean.getName()) + "(" + Utils.makeFirstLetterLowerCase(bean.getName()) + ");\r\n";
ret += "\t\t\t\tupload." + Utils.makeSet(attr.getName()) + "Fm(fm);\r\n";
ret += "\t\t\t\tupload = entityManager.merge(upload);\r\n\r\n";
//ret += "\t\t\t\t" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeSet(bean.getName()) + "Upload(upload);\r\n";
ret += "\t\t\t}\r\n";
ret += "\t\t\tcatch(java.io.IOException e)\r\n";
ret += "\t\t\t{\r\n";
ret += "\t\t\t\te.printStackTrace();\r\n";
ret += "\t\t\t}\r\n";
ret += "\t\t}\r\n";
}
}
return ret;
}
private static String edit1UploadManagement(Bean bean)
{
String ret = "";
/** Verifica il numero di file previsti per l'upload **/
if (bean.getRelationship(Utils.makeGet(bean.getName() + "Upload")) == null)
return ret;
for (Attribute attr : bean.getAttributes())
{
if (attr.getType().equals("org.boco.seamUtility.upload.UploadedFile") || attr.getType().equals("UploadedFile"))
{
ret += "if(" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(bean.getName()) + "Upload()!=null && " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(bean.getName()) + "Upload()." + Utils.makeGet(attr.getName()) + "Fm()!=null && " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(bean.getName()) + "Upload()." + Utils.makeGet(attr.getName()) + "Fm().getCheckDelete())\r\n";
ret += "\t\t{\r\n";
ret += "\t\t\t" + bean.getName() + "Upload tmp = entityManager.find(" + bean.getName() + "Upload.class, " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(bean.getName()) + "Upload().getId());\r\n";
ret += "\t\t\ttmp." + Utils.makeSet(bean.getName()) + "(null);\r\n";
ret += "\t\t\tentityManager.remove(tmp);\r\n";
ret += "\t\t\t" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeSet(bean.getName()) + "Upload(null);\r\n";
ret += "\t\t}\r\n\r\n";
ret += "\t\tif (" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "() != null && " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "().getLength() > 0)\r\n";
ret += "\t\t{\r\n";
ret += "\t\t\ttry\r\n";
ret += "\t\t\t{\r\n";
ret += "\t\t\t\torg.boco.seamUtility.upload.FileManagement fm = new org.boco.seamUtility.upload.FileManagement();\r\n\r\n";
ret += "\t\t\t\tfm.setContentType(" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "().getContentType());\r\n";
ret += "\t\t\t\tfm.setFileName(" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "().getFilename());\r\n\r\n";
ret += "\t\t\t\tjava.io.DataInputStream dis = new java.io.DataInputStream(" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "().getInputStream());\r\n";
ret += "\t\t\t\tbyte buffer[] = new byte[(int) " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "().getLength()];\r\n";
ret += "\t\t\t\tdis.readFully(buffer);\r\n";
ret += "\t\t\t\tfm.setData(buffer);\r\n";
ret += "\t\t\t\t\r\n";
ret += "\t\t\t\t" + bean.getName() + "Upload upload = " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(bean.getName()) + "Upload();\r\n\r\n";
ret += "\t\t\t\tif (upload==null)\r\n";
ret += "\t\t\t\t{\r\n";
ret += "\t\t\t\t\tupload = new" + bean.getName() + "Upload;\r\n";
ret += "\t\t\t\t}\r\n";
ret += "\t\t\t\tupload." + Utils.makeSet(attr.getName()) + "Fm(fm);\r\n\r\n";
ret += "\t\t\t\tupload = entityManager.merge(upload);\r\n\r\n";
ret += "\t\t\t\t" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeSet(bean.getName()) + "Upload(upload);\r\n";
ret += "\t\t\t}\r\n";
ret += "\t\t\tcatch(java.io.IOException e)\r\n";
ret += "\t\t\t{\r\n";
ret += "\t\t\t\te.printStackTrace();\r\n";
ret += "\t\t\t}\r\n";
ret += "\t\t}\r\n";
}
}
return ret;
}
private static String editNUploadManagement(Bean bean)
{
String ret = "";
/** Verifica il numero di file previsti per l'upload **/
if (bean.getRelationship(Utils.makeGet(bean.getName() + "Uploads")) == null)
return ret;
for (Attribute attr : bean.getAttributes())
{
if (attr.getType().equals("org.boco.seamUtility.upload.UploadedFile") || attr.getType().equals("UploadedFile"))
{
ret += "if (" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(bean.getName()) + "Uploads()!=null)\r\n";
ret += "\t\t{\r\n";
ret += "\t\t\tfor(" + bean.getName() + "Upload " + Utils.makeFirstLetterLowerCase(bean.getName()) + "Upload : " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(bean.getName()) + "Uploads())\r\n";
ret += "\t\t\t{\r\n";
ret += "\t\t\t\tif (" + Utils.makeFirstLetterLowerCase(bean.getName()) + "Upload." + Utils.makeGet(attr.getName()) + "Fm()!=null && " + Utils.makeFirstLetterLowerCase(bean.getName()) + "Upload." + Utils.makeGet(attr.getName()) + "Fm().getCheckDelete())\r\n";
ret += "\t\t\t\t{\r\n";
ret += "\t\t\t\t\t" + bean.getName() + "Upload tmp = entityManager.find(" + bean.getName() + "Upload.class, " + Utils.makeFirstLetterLowerCase(bean.getName()) + "Upload.getId());\r\n";
ret += "\t\t\t\t\ttmp." + Utils.makeSet(bean.getName()) + "(null);\r\n";
ret += "\t\t\t\t\tentityManager.remove(tmp);\r\n\r\n";
ret += "\t\t\t\t}\r\n";
ret += "\t\t\t\tif (" + Utils.makeFirstLetterLowerCase(bean.getName()) + "Upload." + Utils.makeGet(attr.getName()) + "Fm()!=null && " + Utils.makeFirstLetterLowerCase(bean.getName()) + "Upload." + Utils.makeGet(attr.getName()) + "Fm().getCheckUpdate() && " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "() != null)\r\n";
ret += "\t\t\t\t{\r\n";
ret += "\t\t\t\t\t" + bean.getName() + "Upload upload = entityManager.find(" + bean.getName() + "Upload.class, " + Utils.makeFirstLetterLowerCase(bean.getName()) + "Upload.getId());\r\n";
ret += "\t\t\t\t\ttry\r\n";
ret += "\t\t\t\t\t{\r\n";
ret += "\t\t\t\t\t\torg.boco.seamUtility.upload.FileManagement fm = new org.boco.seamUtility.upload.FileManagement();\r\n";
ret += "\t\t\t\t\t\tfm.setContentType(" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "().getContentType());\r\n";
ret += "\t\t\t\t\t\tfm.setFileName(" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "().getFilename());\r\n\r\n";
ret += "\t\t\t\t\t\tjava.io.DataInputStream dis = new java.io.DataInputStream(" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "().getInputStream());\r\n";
ret += "\t\t\t\t\t\tbyte buffer[] = new byte[(int) " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "().getLength()];\r\n\r\n";
ret += "\t\t\t\t\t\tdis.readFully(buffer);\r\n";
ret += "\t\t\t\t\t\tfm.setData(buffer);\r\n\r\n";
ret += "\t\t\t\t\t\tupload." + Utils.makeSet(attr.getName()) + "Fm(fm);\r\n";
ret += "\t\t\t\t\t\tentityManager.merge(upload);\r\n";
ret += "\t\t\t\t\t}\r\n";
ret += "\t\t\t\t\tcatch(java.io.IOException e)\r\n";
ret += "\t\t\t\t\t{\r\n";
ret += "\t\t\t\t\t\te.printStackTrace();\r\n";
ret += "\t\t\t\t\t}\r\n\r\n";
ret += "\t\t\t\t\t" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeSet(attr.getName()) + "(null);\r\n";
ret += "\t\t\t\t}\r\n";
ret += "\t\t\t}\r\n";
ret += "\t\t}\r\n\r\n";
ret += "\t\tif (" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "() != null && " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "().getLength() > 0)\r\n";
ret += "\t\t{\r\n";
ret += "\t\t\ttry\r\n";
ret += "\t\t\t{\r\n";
ret += "\t\t\t\torg.boco.seamUtility.upload.FileManagement fm = new org.boco.seamUtility.upload.FileManagement();\r\n\r\n";
ret += "\t\t\t\tfm.setContentType(" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "().getContentType());\r\n";
ret += "\t\t\t\tfm.setFileName(" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "().getFilename());\r\n\r\n";
ret += "\t\t\t\tjava.io.DataInputStream dis = new java.io.DataInputStream(" + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "().getInputStream());\r\n";
ret += "\t\t\t\tbyte buffer[] = new byte[(int) " + Utils.makeFirstLetterLowerCase(bean.getName()) + "." + Utils.makeGet(attr.getName()) + "().getLength()];\r\n";
ret += "\t\t\t\tdis.readFully(buffer);\r\n";
ret += "\t\t\t\tfm.setData(buffer);\r\n";
ret += "\t\t\t\t\r\n";
ret += "\t\t\t\t" + bean.getName() + "Upload upload = new " + bean.getName() + "Upload();\r\n\r\n";
ret += "\t\t\t\tupload." + Utils.makeSet(bean.getName()) + "(" + Utils.makeFirstLetterLowerCase(bean.getName()) + ");\r\n";
ret += "\t\t\t\tupload." + Utils.makeSet(attr.getName()) + "Fm(fm);\r\n\r\n";
ret += "\t\t\t\tupload = entityManager.merge(upload);\r\n\r\n";
ret += "\t\t\t}\r\n";
ret += "\t\t\tcatch(java.io.IOException e)\r\n";
ret += "\t\t\t{\r\n";
ret += "\t\t\t\t\t\te.printStackTrace();\r\n";
// ret += "\t\t\tlog.debug(\"Upload File \"+e);\r\n";
// ret += "\t\t\tFacesMessages.instance().clear();\r\n";
// ret += "\t\t\tString msg = MessagesLoader.getMessageResourceString(facesContext.getApplication().getMessageBundle(),\"Application_maxUploadFileSizeError\", null, facesContext.getViewRoot().getLocale());\r\n";
// ret += "\t\t\tmessage.setDetail(msg);\r\n";
// ret += "\t\t\tmessage.setSummary(msg);\r\n";
// ret += "\t\t\tmessage.setSeverity(FacesMessage.SEVERITY_ERROR);\r\n";
// ret += "\t\t\tFacesMessages.instance().add(message);\r\n";
// ret += "\t\t\treturn \"/"+bean.getName()+".xhtml\";\r\n";
ret += "\t\t\t}\r\n";
ret += "\t\t}\r\n";
}
}
return ret;
}
/**
* Genera il corpo della funzione findAll()
*/
private static String generateFindAllBody(InfoReader infoReader, Bean bean, Vector<Relationship> relationships2ThisBean) throws Exception
{
String findAll = "";
Vector<ShowAttribute> attrs = new Vector<ShowAttribute>(bean.getShowAttributes());
attrs.add(bean.getKey());
findAll += "@Factory(\"" + Utils.makeFirstLetterLowerCase(bean.getName()) + "List\")\r\n";
findAll += "\t@Begin(join = true)\r\n";
findAll += "\tpublic void findAll()\r\n";
findAll += "\t{\r\n";
findAll += "\t\tlog.info(\"------------------------------------------------\");\r\n";
findAll += "\t\tlog.info(\"findAll\");\r\n";
findAll += "\t\tlog.debug(\"Conversation id \"+conversation.getId());\r\n";
findAll += "\t\tlog.debug(\"Conversation view id \"+conversation.getViewId());\r\n";
findAll += "\t\tlog.debug(\"Conversation nested \"+conversation.isNested());\r\n";
findAll += "\t\tlog.debug(\"Conversation parent id \"+conversation.getParentId());\r\n";
findAll += "\t\tlog.debug(\"Is long running \" + conversation.isLongRunning());\r\n";
findAll += "\t\tlog.debug(\"User #{user.username}\");\r\n";
findAll += "\t\tlog.info(\"------------------------------------------------\");\r\n";
findAll += "\t\tboolean localSearchConditionAdded = false;\r\n";
findAll += "\t\tString customFilter = \"\";\r\n";
findAll += "\t\tQueryBuilder qb = new QueryBuilder(entityManager);\r\n\r\n";
findAll += "//\t\tString referrer = SeamUtility.getReferrer(facesContext);\r\n\r\n";
/** Gestione dei filtri per le diverse viste * */
findAll += "\t\tString viewId = facesContext.getViewRoot().getViewId();\r\n";
Vector<ShowList> showList = bean.getLists();
for (ShowList list : showList)
{
if (!list.getFilter().equals(""))
{
findAll += "\t\tif (viewId.equals(\"/list/" + list.getName() + "List.xhtml\"))\r\n";
findAll += "\t\t{\r\n";
findAll += "\t\t\tif (!customFilter.equals(\"\"))\r\n";
findAll += "\t\t\t\tcustomFilter += \" and (" + list.getFilter() + ")\";\r\n";
findAll += "\t\t\telse\r\n";
findAll += "\t\t\t\tcustomFilter += \" " + list.getFilter() + "\";\r\n";
findAll += "\t\t}\r\n";
}
}
/** NON VIENE PIU' UTILIZZATO **/
/** Gestione della lista delle selezione per le PopUp - FRAMMENTO CODICE 1 **/
// String popUpManagementTemplate = "." + File.separator + "templates" + File.separator + "Seam_FindAllPopUpManagement_1.java";
//
// 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;
findAll += "\t\tqb.addSelect(\"o\");\r\n";
findAll += "\t\tqb.addFrom(\"" + bean.getName() + " o\");\r\n";
/** 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
{
orderIndex += 2;
}
}
else
{
// Attributo di una relazione
orderIndex += 2;
}
}
}
findAll += "\t\t}\r\n\r\n";
findAll += "\r\n";
findAll += "\r\n\t\tlong endTime = System.currentTimeMillis();\r\n";
findAll += "\r\n\t\tlog.debug(\"Query Time: \"+(endTime-startTime)+\" ms \"+(endTime-startTime)/1000+\" s\" );\r\n";
findAll += "\r\n";
findAll += "\t}\r\n";
/**
* Fine gestione find All
*/
return findAll;
}
}