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)
{