Index: ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorPagedefsEditAssocXml.java diff -u /dev/null ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorPagedefsEditAssocXml.java:1.1 --- /dev/null Tue Jul 6 15:05:10 2004 +++ ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorPagedefsEditAssocXml.java Tue Jul 6 15:05:04 2004 @@ -0,0 +1,60 @@ +package org.ofbiz.neogia.generators; + +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.codelutin.generator.ObjectModelGenerator; +import org.codelutin.generator.models.object.ObjectModelAttribute; +import org.codelutin.generator.models.object.ObjectModelClass; + +public class GeneratorPagedefsEditAssocXml extends ObjectModelGenerator { + + public String getFilenameForClass(ObjectModelClass clazz){ + Map nameMap = Util.initPackageName(clazz); + return ((String)nameMap.get("packageName"))+"/webapp/"+((String)nameMap.get("packageName"))+"/WEB-INF/pagedefs/"+((String)nameMap.get("subpackageName"))+"/generated/EditAssoc"+clazz.getName()+"G.xml"; + } + + public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException { + if(! Util.isEntity(clazz)) return; + //System.out.println("start of class=" + clazz.getName()); + if(! Util.hasGuiEditAssoc(clazz) ) return; + List associationList = Util.getAssocList(clazz); + Map nameMap = Util.initPackageName(clazz); + String packageName =Util.toUpperCaseFirstLetter((String) nameMap.get("packageName")); + String subpackageName=(String) nameMap.get("subpackageName"); + + +/*{ + + + <%=packageName%>EditAssoc<%=clazz.getName()%> + <%=subpackageName%> + /<%=subpackageName%>/developed/TabBarSubMenu.ftl +}*/ + if (associationList.size() == 1){ + String associationName = ((ObjectModelAttribute) associationList.get(0) ).getName(); +/*{ <%=associationName%> +}*/ + } else { + for (Iterator iter=associationList.iterator(); iter.hasNext(); ){ + String associationName = ((ObjectModelAttribute) iter.next() ).getName(); +/*{ <%=associationName%> +}*/ + } + } +/*{ 20 + <%=packageName.toUpperCase()%> + _UPDATE + simple + + + + +}*/ + } +} + + Index: ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorPagedefsShowXml.java diff -u /dev/null ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorPagedefsShowXml.java:1.1 --- /dev/null Tue Jul 6 15:05:10 2004 +++ ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorPagedefsShowXml.java Tue Jul 6 15:05:04 2004 @@ -0,0 +1,47 @@ +package org.ofbiz.neogia.generators; + +import java.io.IOException; +import java.io.Writer; +import java.util.Map; + +import org.codelutin.generator.ObjectModelGenerator; +import org.codelutin.generator.models.object.ObjectModelClass; + +public class GeneratorPagedefsShowXml extends ObjectModelGenerator { + + public String getFilenameForClass(ObjectModelClass clazz){ + Map nameMap = Util.initPackageName(clazz); + return ((String)nameMap.get("packageName"))+"/webapp/"+((String)nameMap.get("packageName"))+"/WEB-INF/pagedefs/"+((String)nameMap.get("subpackageName"))+"/generated/Show"+clazz.getName()+"G.xml"; + } + + public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException { + if(! Util.isEntity(clazz)) return; + + if(! Util.hasGuiShow(clazz) ) return; + Map nameMap = Util.initPackageName(clazz); + String packageName =Util.toUpperCaseFirstLetter((String) nameMap.get("packageName")); + String subpackageName=(String) nameMap.get("subpackageName"); + + +/*{ + + + <%=packageName%>Show<%=clazz.getName()%> + /<%=subpackageName%>/generated/Forms<%=clazz.getName()%>.xml + show<%=clazz.getName()%> + <%=subpackageName%> + /<%=subpackageName%>/developed/TabBarSubMenu.ftl + show + <%=clazz.getName()%> + <%=packageName.toUpperCase()%> + _VIEW + simple + + + + +}*/ + } +} + + Index: ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorPagedefsEditXml.java diff -u /dev/null ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorPagedefsEditXml.java:1.1 --- /dev/null Tue Jul 6 15:05:10 2004 +++ ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorPagedefsEditXml.java Tue Jul 6 15:05:04 2004 @@ -0,0 +1,46 @@ +package org.ofbiz.neogia.generators; + +import java.io.IOException; +import java.io.Writer; +import java.util.Map; + +import org.codelutin.generator.ObjectModelGenerator; +import org.codelutin.generator.models.object.ObjectModelClass; + +public class GeneratorPagedefsEditXml extends ObjectModelGenerator { + + public String getFilenameForClass(ObjectModelClass clazz){ + Map nameMap = Util.initPackageName(clazz); + return ((String)nameMap.get("packageName"))+"/webapp/"+((String)nameMap.get("packageName"))+"/WEB-INF/pagedefs/"+((String)nameMap.get("subpackageName"))+"/generated/Edit"+clazz.getName()+"G.xml"; + } + + public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException { + if(! Util.isEntity(clazz)) return; + if(! Util.hasGuiEdit(clazz) ) return; + Map nameMap = Util.initPackageName(clazz); + String packageName =Util.toUpperCaseFirstLetter((String) nameMap.get("packageName")); + String subpackageName=(String) nameMap.get("subpackageName"); + + +/*{ + + + <%=packageName%>Edit<%=clazz.getName()%> + /<%=subpackageName%>/generated/Forms<%=clazz.getName()%>.xml + edit<%=clazz.getName()%> + <%=subpackageName%> + /<%=subpackageName%>/developed/TabBarSubMenu.ftl + edit + <%=clazz.getName()%> + <%=packageName.toUpperCase()%> + _UPDATE + simple + + + + +}*/ + } +} + + Index: ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/package.html diff -u /dev/null ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/package.html:1.1 --- /dev/null Tue Jul 6 15:05:10 2004 +++ ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/package.html Tue Jul 6 15:05:04 2004 @@ -0,0 +1,7 @@ + + +

ofbiz-neogia-generators

+ +Ces fichiers correspondent au générateur nécessaire à la gestion de l'interface utilisateur dans OFBiz, avec neogia. + + Index: ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorShowFtl.java diff -u /dev/null ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorShowFtl.java:1.1 --- /dev/null Tue Jul 6 15:05:10 2004 +++ ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorShowFtl.java Tue Jul 6 15:05:04 2004 @@ -0,0 +1,88 @@ +package org.ofbiz.neogia.generators; + +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.codelutin.generator.ObjectModelGenerator; +import org.codelutin.generator.models.object.ObjectModelClass; + +public class GeneratorShowFtl extends ObjectModelGenerator { + + + public String getFilenameForClass(ObjectModelClass clazz){ + Map nameMap = Util.initPackageName(clazz); + return ((String)nameMap.get("packageName"))+"/webapp/"+((String)nameMap.get("packageName"))+"/"+((String)nameMap.get("subpackageName"))+"/generated/Show"+clazz.getName()+".ftl"; + } + + public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException { + if(! Util.isEntity(clazz)) return; + boolean guiListAll = Util.hasGuiListAll(clazz); + if (! Util.hasGuiShow(clazz) ) return; + Map nameMap = Util.initPackageName(clazz); + String packageName= Util.toUpperCaseFirstLetter((String) nameMap.get("packageName") ); + List listPrimaryKeyName = new ArrayList(), listPrimaryKeyType = new ArrayList(); + Util.getListPrimaryKeyAttr(model, clazz, listPrimaryKeyName, listPrimaryKeyType); + String primaryKeys = ""; + for(int j=0; j +<#assign uiLabelMap = requestAttributes.uiLabelMap> +${pages.get(page.getProperty("subMenu"))} + + +<#if hasPermission> + <#if actionForm?has_content > + + + +
+ + + + +
${uiLabelMap.CommonShow} ${uiLabelMap.<%=packageName%><%=clazz.getName()%>Id} : <%=primaryKeys%>
+
+ ${singleWrapper.renderFormString()} +
+ +<#else> +

${uiLabelMap.CommonPermissionError}

+ + +}*/ + } +} + + Index: ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorEntityServicesJava.java diff -u /dev/null ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorEntityServicesJava.java:1.1 --- /dev/null Tue Jul 6 15:05:10 2004 +++ ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorEntityServicesJava.java Tue Jul 6 15:05:04 2004 @@ -0,0 +1,270 @@ +package org.ofbiz.neogia.generators; + +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.codelutin.generator.ObjectModelGenerator; +import org.codelutin.generator.models.object.ObjectModelAttribute; +import org.codelutin.generator.models.object.ObjectModelClass; + +public class GeneratorEntityServicesJava extends ObjectModelGenerator { + + + // ---------------------------------------------------------------------- + // method for generation Retreiving operation + // ---------------------------------------------------------------------- + private void generateRetreiveObject(Writer output, ObjectModelClass clazz, ObjectModelAttribute AttrComposite, String ident) throws IOException { + String entityName = clazz.getName(); + ObjectModelClass classComposite = null; + if (AttrComposite != null){ + classComposite = (ObjectModelClass) AttrComposite.getDeclaringElement(); + String classCompositeName = classComposite.getName(); + String primaryKeyAsParam="", primaryKeyNotNull=""; + ListPkAttribute listPrimaryKey = new ListPkAttribute(model, classComposite, false); + for (int j=0; j <%=attributeKeyType%> <%=fieldName%>= (<%=attributeKeyType%>) context.get("<%=fieldName%>"); +}*/ + if (j <%=classCompositeName%> <%=Util.toLowerCaseFirstLetter(classCompositeName)%> = null; +<%=ident%> if (<%=primaryKeyNotNull%> ){ +<%=ident%> <%=Util.toLowerCaseFirstLetter(classCompositeName)%> = new <%=classCompositeName%>(delegator, <%=primaryKeyAsParam%>); +<%=ident%> } +}*/ + } + + // initialisation of the primaryKeyList + String primaryKeyAsParam="", primaryKeyAsMap="", primaryKeyNotNull=""; + if (AttrComposite != null ){ + primaryKeyNotNull = Util.toLowerCaseFirstLetter(classComposite.getName())+".isAlreadyPersistant() && "; + primaryKeyAsParam = Util.toLowerCaseFirstLetter(classComposite.getName()) + ", "; + } + ListPkAttribute listPrimaryKey = new ListPkAttribute(model, clazz, false, classComposite); + for(int j=0; j <%=attributeKeyType%> <%=attributeKeyName%> = (<%=attributeKeyType%>) context.get("<%=attributeKeyName%>"); +}*/ + if (j if (<%=primaryKeyNotNull%> ){ +<%=ident%> <%=entityName%> <%=Util.toLowerCaseFirstLetter(entityName)%> = new <%=entityName%>(delegator, <%=primaryKeyAsParam%>); + +}*/ + } + + public String getFilenameForClass(ObjectModelClass clazz){ + Map nameMap = Util.initPackageName(clazz); + String packageName = (String) nameMap.get("packageName"); + return packageName+"/src/org/ofbiz/"+packageName+"/"+((String)nameMap.get("subpackageName"))+"/generated/"+clazz.getName()+"Services.java"; + } + + // --------------------------------------------- + // Main method for generation + // --------------------------------------------- + public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException { + if (! Util.isEntity(clazz) ) return; + if (! Util.hasGuiEdit(clazz) && ! Util.isEditViaAssoc(model, clazz) ) return; + Map nameMap = Util.initPackageName(clazz); + String packageName = (String) nameMap.get("packageName"); + String subpackageName = (String)nameMap.get("subpackageName"); + String entityName = clazz.getName(); + ObjectModelAttribute AttrComposite = Util.isComposition(model, clazz); + ObjectModelClass classComposite = null; + if (AttrComposite != null){ + classComposite = (ObjectModelClass) AttrComposite.getDeclaringElement(); + } + +/*{// +// Copyright (c) 2004 Olivier Heintz - olivier.heintz@nereide.biz +// Copyright (c) 2004 Nereide - www.nereide.biz +// Copyright (c) 2004 Neogia - www.neogia.org +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program 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 General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// @author Olivier.Heintz@nereide.biz +// @version $Revision: 1.1 $ +// @since 3.1 +// +// This file has been generated, and will be re-generated, +// so no modification must be done whitout copying it with a other name. +// + + +package org.ofbiz.<%=packageName%>.<%=subpackageName%>.generated; + +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilDateTime; +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilProperties; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.entity.GenericDelegator; +import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.condition.EntityExpr; +import org.ofbiz.entity.condition.EntityOperator; +import org.ofbiz.entity.util.EntityUtil; +import org.ofbiz.security.Security; +import org.ofbiz.service.DispatchContext; +import org.ofbiz.service.ModelService; +import org.ofbiz.service.ServiceUtil; + +}*/ + if (AttrComposite != null){ + nameMap = Util.initPackageName(classComposite); + String classCompositeName = classComposite.getName(); +/*{import org.ofbiz.<%=(String) nameMap.get("packageName")%>.<%=(String)nameMap.get("subpackageName")%>.developed.<%=classCompositeName%>; +}*/ + } +/*{import org.ofbiz.<%=(String) nameMap.get("packageName")%>.<%=(String)nameMap.get("subpackageName")%>.developed.<%=entityName%>; + + +public class <%=entityName%>Services { + + public static final String module = <%=entityName%>Services.class.getName(); + public static final String resource = "<%=Util.toUpperCaseFirstLetter(packageName)%>UiLabels"; + + // + // Create a <%=entityName%> record + // + // @param ctx + // @param context: a map containing in paramaters + // @return result: a map containing out parameters + // + public static Map edit<%=entityName%>(DispatchContext ctx, Map context) { + GenericDelegator delegator = ctx.getDelegator(); +// GenericValue userLogin = (GenericValue) context.get("userLogin"); +// Security security = ctx.getSecurity(); currently security is manage in the user interface + Map result = new HashMap(); + + Locale locale = (Locale) context.get("locale"); + String actionForm = (String) context.get("actionForm"); + + if (actionForm.startsWith("commit") ){ + actionForm = actionForm.substring(6); +}*/ + String ident = " "; + // code generation for retreiving objetc + generateRetreiveObject(output, clazz, AttrComposite, ident); + // +/*{ if (actionForm.equals("add") ){ + if (<%=Util.toLowerCaseFirstLetter(entityName)%>.isAlreadyPersistant() ){ + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonIdAlreadyExist", locale)); + } + } +}*/ + for (Iterator iter=clazz.getAttributes().iterator(); iter.hasNext(); ){ + ObjectModelAttribute attribute = (ObjectModelAttribute) iter.next(); + if (! Util.isPrimaryKey(attribute) ){ + if (attribute.referenceClassifier() ){ + if (attribute.getMaxMultiplicity() == 1){ + if (! (attribute.getReverseAttribute() != null && attribute.getReverseAttribute().isComposite() ) ){ // so this attribute is in the primaryKey so already defined + Map relationKeyName = Util.getRelationOneFieldName(model, attribute, clazz); + List listName = (List) relationKeyName.get("listName"); + ObjectModelClass classAssociated = (ObjectModelClass) ((Map) relationKeyName ).get("clazzAssociated"); + String primaryKeyAsParam = "", primaryKeyNotNull = ""; +/*{ +}*/ + for(Iterator iterList=listName.iterator(); iterList.hasNext(); ){ + Map fieldNameMap = (Map) iterList.next(); + String fieldName = (String) fieldNameMap.get("fieldName"); + primaryKeyAsParam += fieldName + ( iterList.hasNext() ? ", " : " " ); + primaryKeyNotNull += fieldName + ( iterList.hasNext() ? " != null && " : " != null " ); + String fieldType = (String) fieldNameMap.get("fieldType"); +/*{ <%=fieldType%> <%=fieldName%> = (<%=fieldType%>) context.get("<%=fieldName%>"); +}*/ + } +/*{ if (<%=primaryKeyNotNull%> ) <%=Util.toLowerCaseFirstLetter(entityName)%>.set<%=classAssociated.getName()%>(<%=primaryKeyAsParam%>); +}*/ + } + }else{ + // TODO : methode get add remove for item of the list + } + } else { // it's a standard attribute + String attOfbizJavaType = Util.getOfbizJavaType(attribute); + String attributeName = attribute.getName(); +/*{ + <%=attOfbizJavaType%> <%=attributeName%> = (<%=attOfbizJavaType%>) context.get("<%=attributeName%>"); + if (<%=attributeName%> != null ) <%=Util.toLowerCaseFirstLetter(entityName)%>.set<%=Util.toUpperCaseFirstLetter(attributeName)%>(<%=attributeName%>); +}*/ + } + } + } +/*{ + if (<%=Util.toLowerCaseFirstLetter(entityName)%>.store() ) result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); + else return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonDatabaseProblem", locale)); + } + } + return result; + } + + // + // Remove a <%=entityName%> record + // + // @param ctx + // @param context: a map containing in paramaters + // @return result: a map containing out parameters + // + public static Map remove<%=entityName%>(DispatchContext ctx, Map context) { + GenericDelegator delegator = ctx.getDelegator(); +// GenericValue userLogin = (GenericValue) context.get("userLogin"); +// Security security = ctx.getSecurity(); currently security is manage in the user interface + Map result = new HashMap(); + + Locale locale = (Locale) context.get("locale"); +}*/ + ident = " "; + generateRetreiveObject(output, clazz, AttrComposite, ident); +/*{ if (! <%=Util.toLowerCaseFirstLetter(entityName)%>.isAlreadyPersistant() ){ + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonIdDoesNotExist", locale)); + } + if (<%=Util.toLowerCaseFirstLetter(entityName)%>.remove() ) result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); + else return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonDatabaseProblem", locale)); + } + return result; + } +} + +}*/ + } +} Index: ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorFindBsh.java diff -u /dev/null ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorFindBsh.java:1.1 --- /dev/null Tue Jul 6 15:05:10 2004 +++ ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorFindBsh.java Tue Jul 6 15:05:04 2004 @@ -0,0 +1,236 @@ +package org.ofbiz.neogia.generators; + +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.codelutin.generator.ObjectModelGenerator; +import org.codelutin.generator.models.object.ObjectModelAttribute; +import org.codelutin.generator.models.object.ObjectModelClass; + +public class GeneratorFindBsh extends ObjectModelGenerator { + + + public String getFilenameForClass(ObjectModelClass clazz){ + Map nameMap = Util.initPackageName(clazz); + return ((String)nameMap.get("packageName"))+"/webapp/"+((String)nameMap.get("packageName"))+"/WEB-INF/actions/"+((String)nameMap.get("subpackageName"))+"/generated/Find"+clazz.getName()+".bsh"; + } + + public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException { + if(! Util.isEntity(clazz)) return; + if (! Util.hasGuiList(clazz) && ! Util.hasGuiListAll(clazz) ) return; + Map nameMap = Util.initPackageName(clazz); + String packageName=(String) nameMap.get("packageName"); + //System.out.println("XXXXXXXX1Debug clazz.getName="+clazz.getName()); + +/*{ +// $Id: GeneratorFindBsh.java,v 1.1 2004/07/06 15:05:04 holivier Exp $ +// Copyright (c) 2004 Olivier Heintz - olivier.heintz@nereide.biz +// Copyright (c) 2004 Nereide - www.nereide.biz +// Copyright (c) 2004 Neogia - www.neogia.org +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program 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 General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// @author Olivier.Heintz@nereide.biz +// @version $Revision: 1.1 $ +// @since 3.1 +// +// Calls Find on a dynamiqueView to return an EntityListIterator of the +// entities found from the parameter map selection criteria. +// +// This file has been generated, and will be re-generated, +// so no modification must be done whitout copying it with a other name. +// + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.ofbiz.base.util.*; +import org.ofbiz.common.FindServices; +import org.ofbiz.entity.*; +import org.ofbiz.entity.util.*; +import org.ofbiz.entity.condition.EntityConditionList; +import org.ofbiz.entity.condition.EntityJoinOperator; +import org.ofbiz.entity.condition.EntityOperator; +import org.ofbiz.entity.model.DynamicViewEntity; +import org.ofbiz.entity.model.ModelKeyMap; +import org.ofbiz.base.util.BshUtil; +import bsh.EvalError; + +import java.util.ListIterator; + +delegator = request.getAttribute("delegator"); +// field from the user query +Map inputFields = UtilHttp.getParameterMap(request); +//preload the query +staticConditionsStr = page.getProperty("staticConditions"); +if (staticConditionsStr != null && staticConditionsStr.length() > 0) { + String [] staticConditions = BshUtil.eval("String [] cond=" + + staticConditionsStr + "; return cond;",new HashMap()); + for(int i=0; i < staticConditions.length; i += 2) { + inputFields.put(staticConditions[i], staticConditions[i+1]); + } +} +String hideSearch = inputFields.get("hideSearch"); +if (UtilValidate.isEmpty(hideSearch)) hideSearch = page.getProperty("hideSearch"); +context.put("hideSearch",hideSearch); + +String showListIfSelection = page.getProperty("showListIfSelection"); +if (UtilValidate.isEmpty(showListIfSelection) || showListIfSelection.equals("Y") || (UtilValidate.isNotEmpty(hideSearch) && hideSearch.equals("Y"))) { + context.put("showList", "Y"); + + // create the dynamic view entity + DynamicViewEntity dynamicView = new DynamicViewEntity(); + + // default view settings <%=clazz.getName()%> + dynamicView.addMemberEntity("EE", "<%=clazz.getName()%>"); + +}*/ + List listAssoc = new ArrayList(); + List attributesListOrIndexed = Util.getAttributesList(clazz); + List attributesIndexed = new ArrayList(); + // add attributes with gui indexed if there are not already in the list + for (Iterator iter=clazz.getAttributes().iterator(); iter.hasNext(); ){ + ObjectModelAttribute attribute = (ObjectModelAttribute) iter.next(); + //System.out.println("XXXXXXXX2Debug attribute.getName="+attribute.getName()); + if (Util.hasGuiIndexed(attribute)){ + if (! attribute.referenceClassifier()) attributesIndexed.add(attribute.getName()); + if (attributesListOrIndexed.indexOf(attribute) == -1) attributesListOrIndexed.add(attribute); + } + } + List listAttributeName = new ArrayList(); + for (Iterator iter=attributesListOrIndexed.iterator(); iter.hasNext(); ){ + ObjectModelAttribute attribute = (ObjectModelAttribute) iter.next(); + if ( attribute.referenceClassifier() ){ + if ( attribute.getMaxMultiplicity() == 1 ) listAssoc.add(attribute); + } else{ + listAttributeName.add(attribute.getName()); +/*{ + dynamicView.addAlias("EE", "<%=attribute.getName()%>"); +}*/ + } + } + + // add in the dynamicView all the associated entity + int nbAssoc = 1; + for (Iterator iter=listAssoc.iterator(); iter.hasNext(); ){ + ObjectModelAttribute attribute = (ObjectModelAttribute) iter.next(); + Map relationKeyName = Util.getRelationOneFieldName(model, attribute); + ObjectModelClass clazzAssoc = (ObjectModelClass) relationKeyName.get("clazzAssociated"); + String relationName = clazzAssoc.getName(); +/*{ + + // Associated entities + dynamicView.addMemberEntity("E<%=String.valueOf(nbAssoc)%>", "<%=relationName%>"); + dynamicView.addAlias("E<%=String.valueOf(nbAssoc)%>", "<%=attribute.getName()%>Name","<%=Util.getAttributeName(clazzAssoc)%>",null,null,null,null); + dynamicView.addAlias("E<%=String.valueOf(nbAssoc)%>", "<%=attribute.getName()%>Description","<%=Util.getAttributeDescription(clazzAssoc)%>",null,null,null,null); + +}*/ + if (Util.hasGuiIndexed(attribute) ){ + attributesIndexed.add(attribute.getName()+"Name"); + attributesIndexed.add(attribute.getName()+"Description"); + } + + // check and add if necessary, the field relation maker + List listName = (List) relationKeyName.get("listName"); + for(Iterator iterList=listName.iterator(); iterList.hasNext(); ){ + Map relationItem = (Map) iterList.next(); + String fieldName = (String) relationItem.get("fieldName"); + if (listAttributeName.indexOf(fieldName) == -1){ // adding the field in the dynamicView + listAttributeName.add(fieldName); +/*{ + dynamicView.addAlias("EE", "<%=fieldName%>"); +}*/ + } + } + // Add the classAssoc attributes with the tag gui listInAssoc + for (Iterator iterAssoc=clazzAssoc.getAttributes().iterator(); iterAssoc.hasNext(); ){ + ObjectModelAttribute attributeAssoc = (ObjectModelAttribute) iterAssoc.next(); + if ( Util.hasGuiListInAssoc(attributeAssoc) ){ +/*{ + dynamicView.addAlias("E<%=String.valueOf(nbAssoc)%>", "<%=Util.toLowerCaseFirstLetter(relationName)%><%=Util.toUpperCaseFirstLetter(attributeAssoc.getName())%>","<%=attributeAssoc.getName()%>",null,null,null,null); +}*/ + } + } +/*{ + dynamicView.addViewLink("EE", "E<%=String.valueOf(nbAssoc)%>", Boolean.TRUE, ModelKeyMap.makeKeyMapList( +}*/ + boolean first = true; + for(Iterator iterList=listName.iterator(); iterList.hasNext(); ){ + Map relationItem = (Map) iterList.next(); + if ( ! first ){ +/*{, }*/ + } +/*{ + "<%=(String) relationItem.get("fieldName")%>","<%=(String) relationItem.get("relFieldName")%>"}*/ + first = false; + } +/*{ )); +}*/ + nbAssoc += 1; + } +/*{ + + // read and analyse the inputFields + Map queryStringMap = new HashMap(); + Map origValueMap = new HashMap(); + HashMap normalizedFields = FindServices.prepareField((Map) inputFields,(Map) queryStringMap,(Map) origValueMap); + + // compare the normalizedFields with the field the user can query on + List keys = new ArrayList(); +}*/ + for (Iterator iter=attributesIndexed.iterator(); iter.hasNext(); ){ + String attributeName = (String) iter.next(); +/*{ + keys.add("<%=attributeName%>"); +}*/ + } +/*{ + ArrayList tmpList = FindServices.createCondition(keys, normalizedFields, queryStringMap, origValueMap); + + //create the entity condition + EntityOperator entOp = EntityOperator.AND; + EntityConditionList mainCond = new EntityConditionList(tmpList, (EntityJoinOperator) entOp); + + // create the orderBy + List orderByList = null; + String orderBy = page.getProperty("orderBy"); + if (UtilValidate.isNotEmpty(orderBy)) { + orderByList = StringUtil.split(orderBy,"|"); + } + + // set entityFindOptions + EntityFindOptions findOpts = new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, true); + + // using list iterator + EntityListIterator listIt = delegator.findListIteratorByCondition(dynamicView, mainCond, null, null, orderByList, findOpts); + request.setAttribute("listIt", listIt); + + String queryString = UtilHttp.urlEncodeArgs(inputFields); + context.put("queryString", queryString); +} +else context.put("showList", "N"); +}*/ + } +} + + Index: ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorEntityObjectJava.java diff -u /dev/null ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorEntityObjectJava.java:1.1 --- /dev/null Tue Jul 6 15:05:10 2004 +++ ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorEntityObjectJava.java Tue Jul 6 15:05:04 2004 @@ -0,0 +1,131 @@ +package org.ofbiz.neogia.generators; + +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; +import java.util.Map; + +import org.codelutin.generator.ObjectModelGenerator; +import org.codelutin.generator.models.object.ObjectModelAttribute; +import org.codelutin.generator.models.object.ObjectModelClass; +import org.codelutin.generator.models.object.ObjectModelOperation; +import org.codelutin.generator.models.object.ObjectModelParameter; + +public class GeneratorEntityObjectJava extends ObjectModelGenerator { + + + public String getFilenameForClass(ObjectModelClass clazz){ + Map nameMap = Util.initPackageName(clazz); + String packageName = (String) nameMap.get("packageName"); + return packageName+"/src/org/ofbiz/"+packageName+"/"+((String)nameMap.get("subpackageName"))+"/developed/"+clazz.getName()+"G.java"; + } + + public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException { + if (! Util.isEntity(clazz) ) return; + Map nameMap = Util.initPackageName(clazz); + String packageName = (String) nameMap.get("packageName"); + String subpackageName = (String)nameMap.get("subpackageName"); + String entityName = clazz.getName(); + String varEntityName = Util.toLowerCaseFirstLetter(entityName); + ObjectModelAttribute AttrComposite = Util.isComposition(model, clazz); + ObjectModelClass classComposite = null; + if (AttrComposite != null){ + classComposite = (ObjectModelClass) AttrComposite.getDeclaringElement(); + } + + // initialisation of the primaryKeyList + String primaryKeyAsParam="", primaryKeyAsParamCall=""; + if (AttrComposite != null ){ + primaryKeyAsParam = classComposite.getName() + " " + Util.toLowerCaseFirstLetter(classComposite.getName()) + ", "; + primaryKeyAsParamCall = Util.toLowerCaseFirstLetter(classComposite.getName() ) + ", "; + } + ListPkAttribute listPrimaryKey = new ListPkAttribute(model, clazz, false, classComposite); + for(int j=0; j.<%=subpackageName%>.developed; + +import java.sql.Timestamp; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilDateTime; +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.entity.GenericDelegator; +import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.entity.GenericValue; + + +public class <%=entityName%> extends org.ofbiz.<%=packageName%>.<%=subpackageName%>.generated.<%=entityName%>Base { + + public static final String module = <%=entityName%>.class.getName(); + public static final String resource = "<%=Util.toUpperCaseFirstLetter(packageName)%>UiLabels"; + + + public <%=entityName%>(GenericValue <%=varEntityName%>){ + super(<%=varEntityName%>); + } + + public <%=entityName%>(GenericDelegator delegator, <%=primaryKeyAsParam%>){ + super(delegator, <%=primaryKeyAsParamCall%>); + } +}*/ + if (clazz.getOperations().size() > 0 ){ + for (Iterator iterColl = clazz.getOperations().iterator(); iterColl.hasNext(); ){ + ObjectModelOperation operation = (ObjectModelOperation) iterColl.next(); + String operationParam = ""; + for (Iterator iterParam=operation.getParameters().iterator(); iterParam.hasNext(); ){ + ObjectModelParameter parameter = (ObjectModelParameter) iterParam.next(); + operationParam += parameter.getType() + " " + parameter.getName(); + if (iterParam.hasNext() ) operationParam += ", "; + } +/*{ + public <%=operation.getReturnType()%> <%=operation.getName()%>(<%=operationParam%>){ + <%=operation.getReturnType()%> result = null; + return result; + } +}*/ + } + } + +/*{ +} +}*/ + } +} Index: ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorEditAssocFtl.java diff -u /dev/null ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorEditAssocFtl.java:1.1 --- /dev/null Tue Jul 6 15:05:10 2004 +++ ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorEditAssocFtl.java Tue Jul 6 15:05:04 2004 @@ -0,0 +1,187 @@ +package org.ofbiz.neogia.generators; + +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.codelutin.generator.ObjectModelGenerator; +import org.codelutin.generator.models.object.ObjectModelAttribute; +import org.codelutin.generator.models.object.ObjectModelClass; + +public class GeneratorEditAssocFtl extends ObjectModelGenerator { + + + public String getFilenameForClass(ObjectModelClass clazz){ + Map nameMap = Util.initPackageName(clazz); + return ((String)nameMap.get("packageName"))+"/webapp/"+((String)nameMap.get("packageName"))+"/"+((String)nameMap.get("subpackageName"))+"/generated/EditAssoc"+clazz.getName()+".ftl"; + } + + public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException { + if(! Util.isEntity(clazz)) return; + if (! Util.hasGuiEditAssoc(clazz) ) return; + List associationList = Util.getAssocList(clazz); + Map nameMap = Util.initPackageName(clazz); + String packageName= Util.toUpperCaseFirstLetter((String) nameMap.get("packageName") ); + + ListPkAttribute listPrimaryKey = new ListPkAttribute(model, clazz, false); + + String primaryKeys = "", pkHasContent = ""; + for(int i=0; i +<#assign uiLabelMap = requestAttributes.uiLabelMap> +${pages.get(page.getProperty("subMenu"))} + +<#if hasCreatePermission> + + <#-- TODO : Add a select field to choose the instance of the entity the user want to edit --> + + +<#if hasPermission> + <#if <%=pkHasContent%>> + + + +}*/ + for (Iterator iter=associationList.iterator(); iter.hasNext(); ){ + ObjectModelAttribute association = (ObjectModelAttribute) iter.next(); + ObjectModelClass classAssociated = Util.getClassAssociated( association ); + nameMap = Util.initPackageName(classAssociated); + String packageNameAssoc = Util.toUpperCaseFirstLetter((String) nameMap.get("packageName") ); + + ListPkAttribute listPrimaryKeyAssoc = new ListPkAttribute(model, classAssociated, false, clazz); + String primaryKeysAssoc = ""; + for(int i=0; i"> <#-- <%=Util.toUpperCaseFirstLetter(association.getName())%> sub-screen Update or Add --> + + + +}*/ + } +/*{ + +
<#-- <%=clazz.getName()%> Show sub-screen --> + + +
+ + + + +
${uiLabelMap.<%=packageName%><%=clazz.getName()%>Id} : <%=primaryKeys%>
+ ${singleWrapper.renderFormString()} +
+
  + <#if actionForm?has_content > + + + +
+ + + <#if actionForm=="add"> + + <#elseif actionForm=="edit"> + + <#else> + + + +
${uiLabelMap.<%=packageNameAssoc%><%=Util.toUpperCaseFirstLetter(association.getName())%>Creation}
${uiLabelMap.CommonEdit} ${uiLabelMap.<%=packageNameAssoc%><%=Util.toUpperCaseFirstLetter(association.getName())%>Id} : <%=primaryKeysAssoc%>
${uiLabelMap.CommonShow} ${uiLabelMap.<%=packageNameAssoc%><%=Util.toUpperCaseFirstLetter(association.getName())%>Id} : <%=primaryKeysAssoc%>
+
+ ${<%=association.getName()%>Wrapper.renderFormString()} +
+ +
+
+ +}*/ + for (Iterator iter=associationList.iterator(); iter.hasNext(); ){ + ObjectModelAttribute association = (ObjectModelAttribute) iter.next(); + ObjectModelClass classAssociated = Util.getClassAssociated( association ); + nameMap = Util.initPackageName(classAssociated); + String packageNameAssoc = Util.toUpperCaseFirstLetter((String) nameMap.get("packageName") ); + + ListPkAttribute listPrimaryKeyAssoc = new ListPkAttribute(model, classAssociated, false, clazz); + String primaryKeysAssoc = ""; + for(int i=0; i"> <#-- <%=Util.toUpperCaseFirstLetter(association.getName())%> subList, only for one <%=clazz.getName()%> --> + + +
+ + + + + +
${uiLabelMap.<%=packageName%>ListOf<%=clazz.getName()%><%=Util.toUpperCaseFirstLetter(association.getName())%>}
+ ${listWrapper.renderFormString()} +
+ +}*/ + } +/*{ + + <#-- idName?hasContent TODO : Add the <#else> to put a message to be able to select a <%=clazz.getName()%>--> +<#else> +

${uiLabelMap.CommonPermissionError}

+ +}*/ + } +} + + Index: ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorControlerXml.java diff -u /dev/null ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorControlerXml.java:1.1 --- /dev/null Tue Jul 6 15:05:10 2004 +++ ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorControlerXml.java Tue Jul 6 15:05:04 2004 @@ -0,0 +1,193 @@ +package org.ofbiz.neogia.generators; + +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; +import java.util.List; + +import org.codelutin.generator.ObjectModelGenerator; +import org.codelutin.generator.models.object.ObjectModel; +import org.codelutin.generator.models.object.ObjectModelAttribute; +import org.codelutin.generator.models.object.ObjectModelClass; + +public class GeneratorControlerXml extends ObjectModelGenerator { + + private String packageParam = null; + private String packageName = null; + + + public String getFilenameForModel(ObjectModel model){ + if (packageName == null) { + String[] packageParams = new String[2]; + if (! Util.initPackageParam(packageParams)) packageName="error"; + else{ + packageParam = packageParams[0]; + packageName = packageParams[1]; + } + } + return packageName+"/webapp/"+packageName+"/WEB-INF/controlerG.xml"; + } + + public void generateFromModel(Writer output, ObjectModel model) throws IOException { + +/*{ + + +}*/ + if (packageParam == null){ + String[] packageParams = new String[2]; + if (! Util.initPackageParam(packageParams)) return; + else{ + packageParam = packageParams[0]; + packageName = packageParams[1]; + } + } + ObjectModelClass clazz; + String entityName, subpackageName; + for( Iterator iterClazz = model.getClasses().iterator(); iterClazz.hasNext(); ){ + clazz = (ObjectModelClass) iterClazz.next(); + if(Util.isEntity(clazz) && clazz.getPackageName().startsWith(packageParam)){ + entityName = clazz.getName(); + subpackageName = Util.getLastWord(Util.getParentPackageName(clazz.getPackageName())); + if (Util.hasGuiList(clazz) || Util.hasGuiListAll(clazz)){ + /*{ + + + + + +}*/ + } + if (Util.hasGuiEdit(clazz)){ +/*{ + + + + + + + + + + + + + + + + +}*/ + } + if(Util.hasGuiEditAssoc(clazz) ) { + List associationList = Util.getAssocList(clazz); +/*{ + + + + + +}*/ + for (Iterator iter=associationList.iterator(); iter.hasNext(); ){ + ObjectModelAttribute attribute = (ObjectModelAttribute) iter.next(); + String associationName = (attribute.hasAssociationClass() ) ? + attribute.getAssociationClass().getName() : + attribute.getClassifier().getName(); + String fromEntityName = (attribute.getName().equals(Util.toLowerCaseFirstLetter(attribute.getClassifier().getName() ) ) ) ? + clazz.getName() : + Util.toUpperCaseFirstLetter(attribute.getName()); +/*{ + + + + + + + + + + + + +}*/ + } + } + if (Util.hasGuiLookup(clazz)){ +/*{ + + + + + + +}*/ + } + if (Util.hasGuiShow(clazz)){ +/*{ + + + + + +}*/ + } + } + } +/*{ + + + + +}*/ + for( Iterator iterClazz = model.getClasses().iterator(); iterClazz.hasNext(); ){ + clazz = (ObjectModelClass) iterClazz.next(); + if(Util.isEntity(clazz) && clazz.getPackageName().startsWith(packageParam) ){ + entityName = clazz.getName(); + subpackageName = Util.getLastWord(Util.getParentPackageName(clazz.getPackageName())); + if (Util.hasGuiList(clazz) || Util.hasGuiListAll(clazz)){ +/*{ + +}*/ + } + if (Util.hasGuiEdit(clazz)){ +/*{ +}*/ + } + if (Util.hasGuiEditAssoc(clazz)){ +/*{ +}*/ + } + if (Util.hasGuiShow(clazz)){ +/*{ +}*/ + } + } + } + } +} + + Index: ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorEditBsh.java diff -u /dev/null ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorEditBsh.java:1.1 --- /dev/null Tue Jul 6 15:05:10 2004 +++ ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorEditBsh.java Tue Jul 6 15:05:04 2004 @@ -0,0 +1,195 @@ +package org.ofbiz.neogia.generators; + +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.codelutin.generator.ObjectModelGenerator; +import org.codelutin.generator.models.object.ObjectModelAttribute; +import org.codelutin.generator.models.object.ObjectModelClass; + +public class GeneratorEditBsh extends ObjectModelGenerator { + + + public String getFilenameForClass(ObjectModelClass clazz){ + Map nameMap = Util.initPackageName(clazz); + return ((String)nameMap.get("packageName"))+"/webapp/"+((String)nameMap.get("packageName"))+"/WEB-INF/actions/"+((String)nameMap.get("subpackageName"))+"/generated/Edit"+clazz.getName()+".bsh"; + } + + public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException { + if(! Util.isEntity(clazz)) return; + if (! Util.hasGuiEdit(clazz) && ! Util.hasGuiShow(clazz) ) return; + Map nameMap = Util.initPackageName(clazz); + String packageName=(String) nameMap.get("packageName"); + String entityName = clazz.getName(); + //System.out.println("XXXXXXXX1Debug clazz.getName="+clazz.getName()); + +/*{ +// $Id: GeneratorEditBsh.java,v 1.1 2004/07/06 15:05:04 holivier Exp $ +// Copyright (c) 2004 Olivier Heintz - olivier.heintz@nereide.biz +// Copyright (c) 2004 Nereide - www.nereide.biz +// Copyright (c) 2004 Neogia - www.neogia.org +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program 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 General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// @author Olivier.Heintz@nereide.biz +// @version $Revision: 1.1 $ +// @since 3.1 +// +// +// This file has been generated, and will be re-generated, +// so no modification must be done whitout copying it with a other name. +// +import java.util.*; +import org.ofbiz.entity.*; +import org.ofbiz.entity.util.EntityUtil; +import org.ofbiz.base.util.*; +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilValidate; + +GenericDelegator delegator=request.getAttribute("delegator"); +HashMap formsData= new HashMap(); + +actionForm = request.getParameter("actionForm"); +if (UtilValidate.isEmpty(actionForm)) actionForm = "beforeAction"; +if (actionForm.startsWith("commit") ) actionForm = actionForm.substring(6); +context.put("actionForm",actionForm); + +}*/ + // same code are in the GeneratorEditAssocBsh + List listAttributeName = new ArrayList(); // list of all attribute which must be declare or read + List listAttCalculated = new ArrayList(); // list of read only attribute + List listAttAssoc = new ArrayList(); // list of the association with MaxMultiplicity() == 1 + + // initialisation of the three lists + for (Iterator iter=clazz.getAttributes().iterator(); iter.hasNext(); ){ + ObjectModelAttribute attribute = (ObjectModelAttribute) iter.next(); + if (! Util.hasGuiHidden(attribute) && ! Util.isPrimaryKey(attribute)){ + if (Util.hasGuiCalculated(attribute)){ + listAttCalculated.add(attribute.getName()); + } else { + if (attribute.referenceClassifier() ){ + if (attribute.getMaxMultiplicity() == 1){ + Map relationKeyName = Util.getRelationOneFieldName(model, attribute); + listAttAssoc.add(attribute); + List listName = (List) relationKeyName.get("listName"); + for(Iterator iterList=listName.iterator(); iterList.hasNext(); ){ + Map fieldNameMap = (Map) iterList.next(); + String attributeKeyName = (String) fieldNameMap.get("fieldName"); + listAttributeName.add(attributeKeyName); + } + } + } else listAttributeName.add(attribute.getName() ); + } + } + } + // end of same code + + // initialisation of the primaryList + ListPkAttribute listPrimaryKey = new ListPkAttribute(model, clazz, false); + String primaryKeysEmpty = "! UtilValidate.isEmpty("; + String primaryKeysMap = "\""; + for(int j=0; j = request.getParameter("<%=attributeKeyName%>"); +}*/ + primaryKeysEmpty = primaryKeysEmpty + attributeKeyName; + primaryKeysMap = primaryKeysMap + attributeKeyName + "\"," + attributeKeyName; + if (j < listPrimaryKey.getName().size()-1){ + primaryKeysEmpty = primaryKeysEmpty + ") && ! UtilValidate.isEmpty("; + primaryKeysMap = primaryKeysMap + ",\""; + } + } + primaryKeysEmpty = primaryKeysEmpty + ")"; +/*{ +if (<%=primaryKeysEmpty%>) { + GenericValue <%=Util.toLowerCaseFirstLetter(entityName)%> = delegator.findByPrimaryKey("<%=entityName%>", UtilMisc.toMap(<%=primaryKeysMap%>)); + + String }*/ + for (int i=0; i}*/ + if (i = request.getParameter("<%=attributeName%>"); +}*/ + } +/*{ + + if (<%=Util.toLowerCaseFirstLetter(entityName)%> != null){ + if (actionForm.equals("add") ) actionForm = "edit"; +}*/ + for(int j=0; j", <%=attributeKeyName%>); + formsData.put("<%=attributeKeyName%>",<%=attributeKeyName%>); + +}*/ + } +/*{ + // FOR attribue with calculated + // formsData.put("%attribue%",<%=Util.toLowerCaseFirstLetter(entityName)%>.get("%attribue%")); + // + +}*/ + for (int i=0; i != null) formsData.put("<%=attributeName%>",<%=attributeName%>); + else formsData.put("<%=attributeName%>",<%=Util.toLowerCaseFirstLetter(entityName)%>.get("<%=attributeName%>" )); + +}*/ + } + for (int i=0; i",<%=Util.toLowerCaseFirstLetter(entityName)%>.get("<%=attributeName%>" )); +}*/ + } + for (int i=0; i = <%=Util.toLowerCaseFirstLetter(entityName)%>.getRelatedOne("<%=relationName%>"); + if (<%=attributeName%> != null){ + formsData.put("<%=attributeName%>Description", <%=attributeName%>.get("<%=descriptionFieldName%>") ); + formsData.put("<%=attributeName%>Name", <%=attributeName%>.get("<%=idNameFieldName%>") ); + } + +}*/ + } +/*{ + request.setAttribute("formsData",formsData); + } +} +request.setAttribute("actionForm",actionForm); + +}*/ + } +} Index: ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorEntitygroupXml.java diff -u /dev/null ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorEntitygroupXml.java:1.1 --- /dev/null Tue Jul 6 15:05:10 2004 +++ ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorEntitygroupXml.java Tue Jul 6 15:05:04 2004 @@ -0,0 +1,89 @@ +package org.ofbiz.neogia.generators; + +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; + +import org.codelutin.generator.ObjectModelGenerator; +import org.codelutin.generator.models.object.ObjectModel; +import org.codelutin.generator.models.object.ObjectModelClass; + +public class GeneratorEntitygroupXml extends ObjectModelGenerator { + + private String packageParam = null; + private String packageName = null; + + + public String getFilenameForModel(ObjectModel model){ + if (packageName == null) { + String[] packageParams = new String[2]; + if (! Util.initPackageParam(packageParams)) packageName="error"; + else{ + packageParam = packageParams[0]; + packageName = packageParams[1]; + } + } + return packageName +File.separatorChar +"entitydef" + File.separatorChar +"entitygroup.xml"; + } + + public void generateFromModel(Writer output, ObjectModel model) throws IOException { + +/*{ + + + + + +}*/ + if (packageParam == null){ + String[] packageParams = new String[2]; + if (! Util.initPackageParam(packageParams)) return; + else{ + packageParam = packageParams[0]; + packageName = packageParams[1]; + } + } + ObjectModelClass clazz; + String entityName; + for( Iterator iterClazz = model.getClasses().iterator(); iterClazz.hasNext(); ){ + clazz = (ObjectModelClass) iterClazz.next(); + if(Util.isEntity(clazz) && clazz.getPackageName().startsWith(packageParam)){ + entityName = clazz.getName(); +/*{ +}*/ + } + } +/*{ + +}*/ + } +} + + Index: ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/App.java diff -u /dev/null ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/App.java:1.1 --- /dev/null Tue Jul 6 15:05:10 2004 +++ ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/App.java Tue Jul 6 15:05:04 2004 @@ -0,0 +1,35 @@ +/* *##%% +* Copyright (C) 2002, 2003 Code Lutin +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program 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 General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +USA. +*##%%**/ +package org.ofbiz.neogia.generators; + +/** +* @author +* Copyright Code Lutin +* @version $Revision: 1.1 $ +* +* Mise a jour: $Date: 2004/07/06 15:05:04 $ +* par : $Author: holivier $ +*/ +public class App { + + public static void main(final String[] args) { + System.out.println("Starting ofbiz-generators..."); + } + +} Index: ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorServicesXml.java diff -u /dev/null ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorServicesXml.java:1.1 --- /dev/null Tue Jul 6 15:05:10 2004 +++ ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorServicesXml.java Tue Jul 6 15:05:04 2004 @@ -0,0 +1,95 @@ +package org.ofbiz.neogia.generators; + +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; + +import org.codelutin.generator.ObjectModelGenerator; +import org.codelutin.generator.models.object.ObjectModel; +import org.codelutin.generator.models.object.ObjectModelClass; + +public class GeneratorServicesXml extends ObjectModelGenerator { + + private String packageParam = null; + private String packageName = null; + + + public String getFilenameForModel(ObjectModel model){ + if (packageName == null) { + String[] packageParams = new String[2]; + if (! Util.initPackageParam(packageParams)) packageName="error"; + else{ + packageParam = packageParams[0]; + packageName = packageParams[1]; + } + } + return packageName+"/servicedef/servicesG.xml"; + } + + public void generateFromModel(Writer output, ObjectModel model) throws IOException { + +/*{ + + +}*/ + if (packageParam == null){ + String[] packageParams = new String[2]; + if (! Util.initPackageParam(packageParams)) return; + else{ + packageParam = packageParams[0]; + packageName = packageParams[1]; + } + } + ObjectModelClass clazz; + String entityName, subpackageName; + for( Iterator iterClazz = model.getClasses().iterator(); iterClazz.hasNext(); ){ + clazz = (ObjectModelClass) iterClazz.next(); + if(Util.isEntity(clazz) && clazz.getPackageName().startsWith(packageParam)){ + entityName = clazz.getName(); + subpackageName = Util.getLastWord(Util.getParentPackageName(clazz.getPackageName())); + if (Util.hasGuiEdit(clazz) || Util.isEditViaAssoc(model, clazz) ){ +/*{ + + Create or Update a <%=entityName%> + + + + + Remove a <%=entityName%> + + +}*/ + } + } + } + } +} + + Index: ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/Util.java diff -u /dev/null ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/Util.java:1.1 --- /dev/null Tue Jul 6 15:05:10 2004 +++ ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/Util.java Tue Jul 6 15:05:04 2004 @@ -0,0 +1,888 @@ +/* *##% +* Copyright (C) 2002, 2003, 2004 Code Lutin +* Copyright (c) 2004 Nereide - www.nereide.biz +* Copyright (c) 2004 Neogia - www.neogia.org +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program 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 General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*##%*/ + +/* * +* Util.java +* +* Created: 13 mai 2004 +* +* @author Cédric Pineau +* @author Olivier Heintz +* Copyright Code Lutin +* Copyright Nereide +* Copyright Neogia +* @version $Revision: 1.1 $ +* +* Last update : $Date: 2004/07/06 15:05:04 $ +* by : $Author: holivier $ +*/ +package org.ofbiz.neogia.generators; + +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.StringTokenizer; + +import org.codelutin.generator.models.object.ObjectModel; +import org.codelutin.generator.models.object.ObjectModelAssociationClass; +import org.codelutin.generator.models.object.ObjectModelAttribute; +import org.codelutin.generator.models.object.ObjectModelClass; +import org.codelutin.generator.models.object.ObjectModelElement; + +/** + * + */ +public class Util extends org.codelutin.topia.generators.Util { + + static private final String tagSeparator = ", "; + static private final String valueSeparator = ": "; + + /** + * Return a List with all the clazz attribute which have the tag gui - listLookup. + * This method is call by attributesList. + */ + public static List attributesWithGuiLookup(ObjectModelClass clazz){ + List attributesWithGuiLookup = new ArrayList(); + for (Iterator iter=clazz.getAttributes().iterator(); iter.hasNext(); ){ + ObjectModelAttribute attribute = (ObjectModelAttribute) iter.next(); + if (Util.hasGuiListLookup(attribute)) attributesWithGuiLookup.add(attribute); + } + return attributesWithGuiLookup; + } + + + /** + * Re-organize the getParticipants result to be able to access by index the class and the attributeName. + * This methode is used to build field name so the attribute are in reverse mode. + * This metod put sort the association class depending on the tag setDefaultAssoc. + * @param clazz + * @return a Map with two ArrayList, one with key "classParticipants" and one with "attributeParticipants". + */ + public static Map getParticipantsWithName(ObjectModelClass clazz){ + List tmpClassParticipants = new ArrayList(2); + int id = 0; + if (clazz instanceof ObjectModelAssociationClass) { + Map listMapParticipant =((ObjectModelAssociationClass) clazz).getParticipants(); + //System.out.println("XXXXXXX-getParticipantsWithName2-Debug associationClass listMapParticipant.size="+listMapParticipant.size()); + for (Iterator iterPart=listMapParticipant.keySet().iterator(); iterPart.hasNext(); ){ + tmpClassParticipants.add(id,iterPart.next()); + id += 1; + } + // find which class put in first + String classAName = ((ObjectModelClass) tmpClassParticipants.get(0)).getName(); + String classBName = ((ObjectModelClass) tmpClassParticipants.get(1)).getName(); + boolean find = false; + int firstClass = 0, secondClass = 1; + List attrAssociationRank = new ArrayList(); + List attrAssociation = getSetDefaultAssoc(clazz, attrAssociationRank); + for (int iAssoc=0; iAssoc 1 || attribute.getMaxMultiplicity() == -1) ){ + //System.out.println("XXXXXXX-getClassAssocWithoutNav1-Debug one found classAsso="+classAssociated.getName()+" attribute.getName="+attribute.getName()+" "); + classAssocWithoutNav.add(attribute); + } + } + } + } + } + return classAssocWithoutNav; + } + + /** + * Give the name of the attribute of the clazz used as description attribute, with tag gui description or named "description". + * @param clazz + * @return String + */ + public static String getAttributeDescription( ObjectModelClass clazz ){ + String attributeDescription=null; + for (Iterator iter=clazz.getAttributes().iterator(); iter.hasNext(); ){ + ObjectModelAttribute attribute = (ObjectModelAttribute) iter.next(); + if ( Util.hasGuiDescription(attribute) ) return attribute.getName(); + if ( attribute.getName().equals("description") ) attributeDescription = attribute.getName(); + } + if (attributeDescription == null){ + System.out.println("UML MODEL ERROR Entity with no description attribute defined; entity="+clazz.getName()); + return "description"; + } else return attributeDescription; + } + + /** + * Give the name of the attribute of the clazz used as idName attribute, with tag gui name or named "idName". + * @param clazz + * @return String + */ + public static String getAttributeName( ObjectModelClass clazz ){ + String attributeName=null; + for (Iterator iter=clazz.getAttributes().iterator(); iter.hasNext(); ){ + ObjectModelAttribute attribute = (ObjectModelAttribute) iter.next(); + if (Util.hasGuiIdName(attribute)) return attribute.getName(); + if (attribute.getName().equals("idName")) attributeName = attribute.getName(); + } + if (attributeName == null){ + System.out.println("UML MODEL ERROR Entity with no name attribute defined entity="+clazz.getName()); + return "idName"; + } else return attributeName; + } + + /** + * Return a List with all the clazz attribute which must be list in a List. + * This collection is attributesWithGuiLookup and attributes with tag gui - list, + * if the previous result is empty it's all the class attribues execpt which with Tag hidden. + */ + public static List getAttributesList(ObjectModelClass clazz){ + List attributesList = attributesWithGuiLookup(clazz); + List classAttExecptHidden = new ArrayList(); + for (Iterator iter=clazz.getAttributes().iterator(); iter.hasNext(); ){ + ObjectModelAttribute attribute = (ObjectModelAttribute) iter.next(); + if (Util.hasGuiList(attribute)) attributesList.add(attribute); + if (! Util.hasGuiHidden(attribute) && + (! attribute.referenceClassifier() || attribute.getMaxMultiplicity()==1) ) + classAttExecptHidden.add(attribute); + } + if (attributesList.size() == 0){ + attributesList.addAll(classAttExecptHidden); + } + return attributesList; + } + + /** + * Return the List of all the association with the rank definied in the Tag setDefaultAssoc. + * @param assocRank the out parameters list which contain the rank + * @return the list of the association, the rank is in the assocRank list. + */ + public static List getSetDefaultAssoc(ObjectModelClass clazz, List assocRank){ + List listAssoc = new ArrayList(); + if (clazz.getTagValue("setDefaultAssoc") != null ){ + StringTokenizer guiTag = new StringTokenizer( clazz.getTagValue( "setDefaultAssoc" ) , tagSeparator ); + for( ; guiTag.hasMoreTokens(); ){ + StringTokenizer attributeRank = new StringTokenizer( guiTag.nextToken() , valueSeparator ); + listAssoc.add(attributeRank.nextToken() ); + if (attributeRank.hasMoreTokens() ) assocRank.add( new Integer( attributeRank.nextToken() ) ); + else assocRank.add(new Integer(999) ); + } + } + return listAssoc; + } + + /** + * Return a List with all the clazz attribute with the association in the correct Order. + */ + public static List getAttributes(ObjectModelClass clazz){ + Collection attributesList = clazz.getAttributes(); + List attrAssociationRank = new ArrayList(); + List attrAssociation = getSetDefaultAssoc(clazz, attrAssociationRank); + int k =0; + for (int i =0; i 0 ){ + for (Iterator iterClass=classAssocWithoutNav.iterator(); iterClass.hasNext(); ){ + ObjectModelAttribute attrAssociated = (ObjectModelAttribute) iterClass.next(); + if (attrAssociated.isComposite()){ + ObjectModelClass classAssociated = (ObjectModelClass) attrAssociated.getDeclaringElement(); + String relationName = (attrAssociated.getName().equals(Util.toLowerCaseFirstLetter(clazz.getName())) ) ? + Util.getClassShortName(classAssociated) : + Util.toUpperCaseFirstLetter(attrAssociated.getName()); + List listCompositePrimaryKeyName=new ArrayList(), listCompositePrimaryKeyType=new ArrayList(); + Util.getListPrimaryKeyAttr(model, classAssociated, listCompositePrimaryKeyName, listCompositePrimaryKeyType, entity); + for(int i=0; i"listName" : a list of map, in each map three key "fieldName", "relFieldName" and "fieldType" (OfbizJavaType). + * + */ + public static Map getRelationOneFieldName(ObjectModel model, ObjectModelAttribute attribute, ObjectModelClass _classOrigin){ + List relationOneFieldNames = new ArrayList(); + ObjectModelClass clazzAssociated; + // test if there are an association class for this atribute + String prefix=null; + boolean thereIsAssociationClass = false; + + if (attribute.hasAssociationClass() ){ + clazzAssociated = attribute.getAssociationClass(); + prefix = attribute.getReverseAttribute().getName(); + ObjectModelClass clazz = (ObjectModelClass) attribute.getDeclaringElement(); + if (Util.toUpperCaseFirstLetter(prefix).equals(clazz.getName()) ) prefix = Util.getClassShortName(clazz); + thereIsAssociationClass = true; + } else + clazzAssociated = (ObjectModelClass) attribute.getClassifier(); + + if (attribute.getMaxMultiplicity() == 1){ + ListPkAttribute listPrimaryKey = new ListPkAttribute(model, clazzAssociated, false, _classOrigin); + for(int i=0; i), for an _attribute which is classifer. + */ + public static String getRelationNameForGetRelatedOne( ObjectModelAttribute _attribute, ObjectModelClass _associatedClass){ + return (_attribute.getName().equals(Util.toLowerCaseFirstLetter(_attribute.getClassifier().getName() ) ) ) ? + _associatedClass.getName() : + Util.toUpperCaseFirstLetter(_attribute.getName()) + _associatedClass.getName(); + } + + /** + * return toLowerCaseFirstLetter for ( the tag value "shortName" if it exist, getName() otherwise ). + * @param clazz + * @return the shortName + */ + public static String getClassShortName(ObjectModelClass clazz){ + return Util.toLowerCaseFirstLetter((clazz.getTagValue("shortName")!=null) ? clazz.getTagValue("shortName") : clazz.getName()); + } + + /** + * return attribute.getName execpt when attribute.getName == attribute.getClassifier.getName, + * then return Util.getClassShortName(attribute.getClassifier()). + * @param attribute + * @return + */ + public static String getAttributeShortName(ObjectModelAttribute attribute){ + if (! attribute.referenceClassifier()) return attribute.getName(); + ObjectModelClass classAssociated = (ObjectModelClass)attribute.getClassifier(); + if (Util.toLowerCaseFirstLetter(classAssociated.getName()).equals(attribute.getName())) + return Util.getClassShortName((ObjectModelClass)attribute.getClassifier()); + return attribute.getName(); + } + + /** + * useable to test if the _att has a tagvalue=="gui" and if its value contain the word "calculated". + * @param _att + * @return true if _att has a tagvalue=="gui" and if its value contain the word "calculated". + */ + public static boolean hasGuiCalculated( ObjectModelAttribute _att ){ + StringTokenizer guiTag = new StringTokenizer( _att.getTagValue( "gui" ) != null ? _att.getTagValue( "gui" ) : "" , tagSeparator); + for( ; guiTag.hasMoreTokens(); ) + if( guiTag.nextToken().equals( "calculated" )) + return true; + return false; + } + + /** + * useable to test if the _att has a tagvalue=="gui" and if its value contain the word "description". + * @param _att + * @return true if _att has a tagvalue=="gui" and if its value contain the word "description". + */ + public static boolean hasGuiDescription( ObjectModelAttribute _att ){ + StringTokenizer guiTag = new StringTokenizer( _att.getTagValue( "gui" ) != null ? _att.getTagValue( "gui" ) : "", tagSeparator ); + for( ; guiTag.hasMoreTokens(); ) + if( guiTag.nextToken().equals( "description" )) + return true; + return false; + } + + /** + * useable to test if the _att has a tagvalue=="gui" and if its value contain the word "dropDown". + * @param _att + * @return true if _att has a tagvalue=="gui" and if its value contain the word "dropDown". + */ + public static boolean hasGuiDropDown( ObjectModelClass _clazz ){ + StringTokenizer guiTag = new StringTokenizer( _clazz.getTagValue( "gui" ) != null ? _clazz.getTagValue( "gui" ) : "", tagSeparator ); + for( ; guiTag.hasMoreTokens(); ) + if( guiTag.nextToken().equals( "drop-down" )) + return true; + return false; + } + + /** + * useable to test if the clazz has a tagvalue=="gui" and if its value contain the word "edit". + * @param clazz + * @return true if clazz has a tagvalue=="gui" and if its value contain the word "edit". + */ + public static boolean hasGuiEdit( ObjectModelClass clazz ){ + StringTokenizer guiTag = new StringTokenizer( clazz.getTagValue( "gui" ) != null ? clazz.getTagValue( "gui" ) : "", tagSeparator ); + for( ; guiTag.hasMoreTokens(); ) + if( guiTag.nextToken().equals( "edit" )) + return true; + return false; + } + + /** + * useable to test if the _att has a tagvalue=="gui" and if its value contain the word "hidden". + * @param _att + * @return true if _att has a tagvalue=="gui" and if its value contain the word "hidden". + */ + public static boolean hasGuiHidden( ObjectModelAttribute _att ){ + StringTokenizer guiTag = new StringTokenizer( _att.getTagValue( "gui" ) != null ? _att.getTagValue( "gui" ) : "", tagSeparator ); + for( ; guiTag.hasMoreTokens(); ) + if( guiTag.nextToken().equals( "hidden" )) + return true; + return false; + } + + /** + * useable to test if the _att has a tagvalue=="gui" and if its value contain the word "indexed". + * @param _att + * @return true if _att has a tagvalue=="gui" and if its value contain the word "indexed". + */ + public static boolean hasGuiIndexed( ObjectModelAttribute _att ){ + StringTokenizer guiTag = new StringTokenizer( _att.getTagValue( "gui" ) != null ? _att.getTagValue( "gui" ) : "", tagSeparator ); + for( ; guiTag.hasMoreTokens(); ) + if( guiTag.nextToken().equals( "indexed" )) + return true; + return false; + } + + /** + * useable to test if the element has a tagvalue=="gui" and if its value contain the word "list". + * @param element + * @return true if element has a tagvalue=="gui" and if its value contain the word "list". + */ + public static boolean hasGuiList( ObjectModelElement element ){ + StringTokenizer guiTag = new StringTokenizer( element.getTagValue( "gui" ) != null ? element.getTagValue( "gui" ) : "", tagSeparator ); + for( ; guiTag.hasMoreTokens(); ) + if( guiTag.nextToken().equals( "list" )) + return true; + return false; + } + + /** + * useable to test if the clazz has a tagvalue=="gui" and if its value contain the word "listAll". + * @param clazz + * @return true if clazz has a tagvalue=="gui" and if its value contain the word "listAll". + */ + public static boolean hasGuiListAll( ObjectModelClass clazz ){ + StringTokenizer guiTag = new StringTokenizer(clazz.getTagValue("gui")!=null?clazz.getTagValue("gui"):"", tagSeparator); + for (;guiTag.hasMoreTokens();) + if (guiTag.nextToken().equals("listAll")) return true; + return false; + } + + /** + * useable to test if the clazz has a tagvalue=="gui" and if its value contain the word "showList". + * @param clazz + * @return true if clazz has a tagvalue=="gui" and if its value contain the word "showList". + */ + public static boolean hasGuiShowList( ObjectModelClass clazz ){ + StringTokenizer guiTag = new StringTokenizer(clazz.getTagValue("gui")!=null?clazz.getTagValue("gui"):"", tagSeparator); + for (;guiTag.hasMoreTokens();) + if (guiTag.nextToken().equals("showList")) return true; + return false; + } + + /** + * useable to test if the _att has a tagvalue=="gui" and if its value contain the word "editAssoc". + * @param _att + * @return true if _att has a tagvalue=="gui" and if its value contain the word "editAssoc". + */ + public static boolean hasGuiEditAssoc( ObjectModelAttribute _att ){ + StringTokenizer guiTag = new StringTokenizer( _att.getTagValue( "gui" ) != null ? _att.getTagValue( "gui" ) : "", tagSeparator ); + for( ; guiTag.hasMoreTokens(); ) + if( guiTag.nextToken().equals( "editAssoc" ) ) + return true; + return false; + } + + /** + * useable to test if the _clazz has one or more association with a tagvalue=="gui" and if its value contain the word "editAssoc". + * @param _clazz + * @return true if _clazz has at least one association with a tagvalue=="gui" and if its value contain the word "editAssoc". + */ + public static boolean hasGuiEditAssoc( ObjectModelClass _clazz ){ + for (Iterator iter=_clazz.getAttributes().iterator(); iter.hasNext(); ){ + ObjectModelAttribute attribute = (ObjectModelAttribute) iter.next(); + if (attribute.referenceClassifier() && hasGuiEditAssoc(attribute) ) return true; + } + return false; + } + + /** + * Give the list of all the attribute-association with a tag editAsssoc + * @param _clazz + * @return a List of attribute which are an association and have a tagvalue=="gui" and if its value contain the word "editAssoc". + */ + public static List getAssocList( ObjectModelClass _clazz ){ + List associationList = new ArrayList(); + for (Iterator iter=_clazz.getAttributes().iterator(); iter.hasNext(); ){ + ObjectModelAttribute attribute = (ObjectModelAttribute) iter.next(); + if (attribute.referenceClassifier() && hasGuiEditAssoc(attribute) ) associationList.add(attribute ); + } + return associationList; + } + + /** + * Give the Association class if exist, otherwise the _attribute.getClassifier. + * @param _attribute + * @return the Association class if exist, or the _attribute.getClassifier otherwise. + */ + public static ObjectModelClass getClassAssociated( ObjectModelAttribute _attribute ){ + if ( _attribute.hasAssociationClass() ) return _attribute.getAssociationClass(); + return (ObjectModelClass) _attribute.getClassifier(); + } + + /** + * Give the list of all the attribute in the other association which are associated with class with a tag editAsssoc. + * @param model + * @param _clazz + * @return a List of attribute which are an association and have a tagvalue=="gui" and if its value contain the word "editAssoc" and point on _clazz. + */ + public static List getEditAssocList( ObjectModel model, ObjectModelClass _clazz ){ + List associationList = new ArrayList(); + for (Iterator iter=_clazz.getAttributes().iterator(); iter.hasNext(); ){ + ObjectModelAttribute attribute = (ObjectModelAttribute) iter.next(); + if (attribute.referenceClassifier()){ + ObjectModelAttribute reverseAttribute = attribute.getReverseAttribute(); + if (reverseAttribute != null && hasGuiEditAssoc(reverseAttribute) ) associationList.add(reverseAttribute ); + } + } + if (_clazz instanceof ObjectModelAssociationClass ){ + Map listMapParticipant =((ObjectModelAssociationClass) _clazz).getParticipants(); + for (Iterator iterPart=listMapParticipant.keySet().iterator(); iterPart.hasNext(); ){ + ObjectModelAttribute attribute = (ObjectModelAttribute) listMapParticipant.get( iterPart.next() ); + if ( hasGuiEditAssoc(attribute ) ) associationList.add(attribute ); + } + } + List nonNavAttribute = getClassAssocWithoutNav(model, _clazz); + if (nonNavAttribute.size() > 0 ){ + for (Iterator iter=nonNavAttribute.iterator(); iter.hasNext(); ){ + ObjectModelAttribute attribute = (ObjectModelAttribute) iter.next(); + if ( hasGuiEditAssoc(attribute) ) associationList.add(attribute ); + } + } + return associationList; + } + + /** + * Test if there is (at least) an association from an other class with gui editAssoc, useable to know if the subEdit screen, is used or not. + * @param model + * @param _clazz + * @return true if _clazz has at least one association with a tagvalue=="gui" and if its value contain the word "editAssoc" from an other class. + */ + public static boolean isEditViaAssoc( ObjectModel model, ObjectModelClass _clazz ){ + for (Iterator iter=_clazz.getAttributes().iterator(); iter.hasNext(); ){ + ObjectModelAttribute attribute = (ObjectModelAttribute) iter.next(); + if (attribute.referenceClassifier() ){ + ObjectModelAttribute reverseAttribute = attribute.getReverseAttribute(); + if ( reverseAttribute != null && hasGuiEditAssoc( reverseAttribute ) ) return true; + } + } + if (_clazz instanceof ObjectModelAssociationClass ){ + Map listMapParticipant =((ObjectModelAssociationClass) _clazz).getParticipants(); + for (Iterator iterPart=listMapParticipant.keySet().iterator(); iterPart.hasNext(); ){ + if ( hasGuiEditAssoc( (ObjectModelAttribute) listMapParticipant.get( iterPart.next() ) ) ) return true; + } + } + List nonNavAttribute = getClassAssocWithoutNav(model, _clazz); + if (nonNavAttribute.size() > 0 ){ + for (Iterator iter=nonNavAttribute.iterator(); iter.hasNext(); ){ + if ( hasGuiEditAssoc((ObjectModelAttribute) iter.next() ) ) return true; + } + } + return false; + } + + /** + * give if there is one association from an other class which is composite() the attribute composite. + * @param model + * @param _clazz + * @return attributeAssoc if _clazz has one association from an other class (for ex : clazzA.attributeAssoc) with clazzA.attributeAssoc.iscomposite() == true, + * null otherwise. + */ + public static ObjectModelAttribute isComposition( ObjectModel model, ObjectModelClass _clazz ){ + for (Iterator iter=_clazz.getAttributes().iterator(); iter.hasNext(); ){ + ObjectModelAttribute attribute = (ObjectModelAttribute) iter.next(); + if (attribute.referenceClassifier() ){ + ObjectModelAttribute reverseAttribute = attribute.getReverseAttribute(); + if ( reverseAttribute != null && reverseAttribute.isComposite() ) return reverseAttribute; + } + } + List nonNavAttribute = getClassAssocWithoutNav(model, _clazz); + if (nonNavAttribute.size() > 0 ){ + for (Iterator iter=nonNavAttribute.iterator(); iter.hasNext(); ){ + ObjectModelAttribute attribute = (ObjectModelAttribute) iter.next(); + if ( attribute.isComposite() ) return attribute; + } + } + return null; + } + + /** + * useable to test if the _att has a tagvalue=="gui" and if its value contain the word "listInAssoc". + * @param _att + * @return true if _att has a tagvalue=="gui" and if its value contain the word "listInAssoc". + */ + public static boolean hasGuiListInAssoc( ObjectModelAttribute _att ){ + StringTokenizer guiTag = new StringTokenizer( _att.getTagValue( "gui" ) != null ? _att.getTagValue( "gui" ) : "", tagSeparator ); + for( ; guiTag.hasMoreTokens(); ) + if( guiTag.nextToken().equals( "listInAssoc" )) + return true; + return false; + } + + /** + * useable to test if the _att has a tagvalue=="gui" and if its value contain the word "listLookup". + * @param _att + * @return true if _att has a tagvalue=="gui" and if its value contain the word "listLookup". + */ + public static boolean hasGuiListLookup( ObjectModelAttribute _att ){ + StringTokenizer guiTag = new StringTokenizer( _att.getTagValue( "gui" ) != null ? _att.getTagValue( "gui" ) : "", tagSeparator ); + for( ; guiTag.hasMoreTokens(); ) + if( guiTag.nextToken().equals( "listLookup" )) + return true; + return false; + } + + /** + * useable to test if the clazz has a tagvalue=="gui" and if its value contain the word "lookup". + * @param clazz + * @return true if clazz has a tagvalue=="gui" and if its value contain the word "lookup". + */ + public static boolean hasGuiLookup( ObjectModelClass clazz ){ + StringTokenizer guiTag = new StringTokenizer( clazz.getTagValue( "gui" ) != null ? clazz.getTagValue( "gui" ) : "", tagSeparator ); + for( ; guiTag.hasMoreTokens(); ) + if( guiTag.nextToken().equals( "lookup" )) + return true; + return false; + } + + /** + * useable to test if the _att has a tagvalue=="gui" and if its value contain the word "name". + * @param _att + * @return true if _att has a tagvalue=="gui" and if its value contain the word "name". + */ + public static boolean hasGuiIdName( ObjectModelAttribute _att ){ + StringTokenizer guiTag = new StringTokenizer( _att.getTagValue( "gui" ) != null ? _att.getTagValue( "gui" ) : "", tagSeparator ); + for( ; guiTag.hasMoreTokens(); ) + if( guiTag.nextToken().equals( "idName" )) + return true; + return false; + } + + /** + * useable to test if the clazz has a tagvalue=="gui" and if its value contain the word "show". + * @param clazz + * @return true if clazz has a tagvalue=="gui" and if its value contain the word "show". + */ + public static boolean hasGuiShow( ObjectModelClass clazz ){ + StringTokenizer guiTag = new StringTokenizer( clazz.getTagValue( "gui" ) != null ? clazz.getTagValue( "gui" ) : "", tagSeparator ); + for( ; guiTag.hasMoreTokens(); ) + if( guiTag.nextToken().equals( "show" )) + return true; + return false; + } + + /** + * initialize the String packageName and subpackageName using the neogia package naming convention. + * The neogia package naming convention is : all the entities class are in + * org.neogia.packageName.subpackageName.entities. + * @param clazz : In param, the class for which you want the packageName and subpackageName + * @return Map with two elements one with key=="packageName" and one with key=="subpackageName" + */ + public static Map initPackageName(ObjectModelClass clazz){ + Map result = new HashMap(); + String subpackage = Util.getParentPackageName(clazz.getPackageName()); + result.put("subpackageName", Util.getLastWord(subpackage)); + result.put("packageName", Util.getLastWord(Util.getParentPackageName(subpackage))); + return result; + } + + /** + * return the available entity type in OFBiz for an attribute. + * print a message if the type does'nt exist. + * @param attribute + * @return a String with the Ofbiz type or "name" if there is non corresponding type. + */ + public static String getOfbizType(ObjectModelAttribute attribute){ + Map typeOfbiz = new HashMap(); + typeOfbiz.put("java.lang.String","name"); + typeOfbiz.put("java.lang.Long","numeric"); + typeOfbiz.put("double","floating-point"); + typeOfbiz.put("float","floating-point"); + typeOfbiz.put("java.util.Date","date-time"); + typeOfbiz.put("int","numeric"); + typeOfbiz.put("boolean","indicator"); + String attributeType = (String) typeOfbiz.get(attribute.getType()); + if (attributeType == null){ + System.out.println("UML MODEL ERROR Ofbiz type not define for type="+attribute.getType()+" in entity="+attribute.getDeclaringElement().getName()); + attributeType = "name"; + } + return attributeType; + } + + /** + * return the available java type in OFBiz for an attribute. + * print a message if the type does'nt exist. + * @param attribute + * @return a String with the Ofbiz type or "String" if there is non corresponding type. + */ + public static String getOfbizJavaType(ObjectModelAttribute attribute){ + Map typeOfbiz = new HashMap(); + typeOfbiz.put("java.lang.String","String"); + typeOfbiz.put("java.lang.Long","Long"); + typeOfbiz.put("double","Double"); + typeOfbiz.put("float","Double"); + typeOfbiz.put("java.util.Date","Timestamp"); + typeOfbiz.put("int","Long"); + typeOfbiz.put("boolean","Boolean"); + String attributeType = (String) typeOfbiz.get(attribute.getType()); + if (attributeType == null){ + System.out.println("UML MODEL ERROR Ofbiz type not define for type="+attribute.getType()+" in entity="+attribute.getDeclaringElement().getName()); + attributeType = "String"; + } + return attributeType; + } + + /** + * use to test if the attribute.getType == java.util.Date + * @param type + * @return type.equals("java.util.Date" ); + */ + public static boolean isDate(String type){ + return type.equals("java.util.Date" ); + } + + /** + * retreive from the packageParams.properties file the two parameters. + * @param packageParam out parameter + * @param packageName out parameter + * @return false if there is an IOException true otherwise + */ + public static boolean initPackageParam(String[] packageParam){ + Properties packageParamFile=new Properties(); + String paramFileName = "packageParams.properties"; + try { packageParamFile.load(new FileInputStream(paramFileName)); + } + catch (IOException e) { + System.out.println("ERROR IOException e=" + e); + System.out.println("ERROR File not found :" + paramFileName); + return false; + } + packageParam[0] = packageParamFile.getProperty("packageParam"); + packageParam[1] = packageParamFile.getProperty("packageName"); + return true; + } +} Index: ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorEditAssocBsh.java diff -u /dev/null ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorEditAssocBsh.java:1.1 --- /dev/null Tue Jul 6 15:05:10 2004 +++ ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/GeneratorEditAssocBsh.java Tue Jul 6 15:05:04 2004 @@ -0,0 +1,575 @@ +package org.ofbiz.neogia.generators; + +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.codelutin.generator.ObjectModelGenerator; +import org.codelutin.generator.models.object.ObjectModelAssociationClass; +import org.codelutin.generator.models.object.ObjectModelAttribute; +import org.codelutin.generator.models.object.ObjectModelClass; + + +public class GeneratorEditAssocBsh extends ObjectModelGenerator { + + + public String getFilenameForClass(ObjectModelClass clazz){ + Map nameMap = Util.initPackageName(clazz); + return ((String)nameMap.get("packageName"))+"/webapp/"+((String)nameMap.get("packageName"))+"/WEB-INF/actions/"+((String)nameMap.get("subpackageName"))+"/generated/EditAssoc"+clazz.getName()+".bsh"; + } + + public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException { + if(! Util.isEntity(clazz)) return; + if (! Util.hasGuiEditAssoc(clazz)) return; + Map nameMap = Util.initPackageName(clazz); + String packageName=(String) nameMap.get("packageName"); + String subPackageName=(String) nameMap.get("subpackageName"); + List associationList = Util.getAssocList(clazz); + String entityName = clazz.getName(); + + //System.out.println("XXXXXXXX1Debug clazz.getName="+entityName); + + // same code are in the GeneratorEditBsh + List listAttributeName = new ArrayList(); // list of all attribute which must be declare or read + List listAttCalculated = new ArrayList(); // list of read only attribute + List listAttAssoc = new ArrayList(); // list of the association with MaxMultiplicity() == 1 + + // initialisation of the three lists + for (Iterator iter=clazz.getAttributes().iterator(); iter.hasNext(); ){ + ObjectModelAttribute attribute = (ObjectModelAttribute) iter.next(); + if (! Util.hasGuiHidden(attribute) && ! Util.isPrimaryKey(attribute)){ + if (Util.hasGuiCalculated(attribute)){ + listAttCalculated.add(attribute.getName()); + } else { + if (attribute.referenceClassifier() ){ + if (attribute.getMaxMultiplicity() == 1){ + Map relationKeyName = Util.getRelationOneFieldName(model, attribute); + listAttAssoc.add(attribute); + List listName = (List) relationKeyName.get("listName"); + for(Iterator iterList=listName.iterator(); iterList.hasNext(); ){ + Map fieldNameMap = (Map) iterList.next(); + String attributeKeyName = (String) fieldNameMap.get("fieldName"); + listAttributeName.add(attributeKeyName); + } + } + } else listAttributeName.add(attribute.getName() ); + } + } + } + // end of same code + + +/*{ +// $Id: GeneratorEditAssocBsh.java,v 1.1 2004/07/06 15:05:04 holivier Exp $ +// Copyright (c) 2004 Olivier Heintz - olivier.heintz@nereide.biz +// Copyright (c) 2004 Nereide - www.nereide.biz +// Copyright (c) 2004 Neogia - www.neogia.org +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program 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 General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// @author Olivier.Heintz@nereide.biz +// @version $Revision: 1.1 $ +// @since 3.1 +// +// Calls Find on a dynamiqueView to return an EntityListIterator of the +// entities found from the parameter map selection criteria. +// +// This file has been generated, and will be re-generated, +// so no modification must be done whitout copying it with a other name. +// + +import java.util.*; +import org.ofbiz.common.FindServices; +import org.ofbiz.base.util.*; +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.content.widget.html.HtmlFormWrapper; +import org.ofbiz.entity.condition.EntityConditionList; +import org.ofbiz.entity.condition.EntityJoinOperator; +import org.ofbiz.entity.condition.EntityOperator; +import org.ofbiz.entity.GenericDelegator; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.model.DynamicViewEntity; +import org.ofbiz.entity.model.ModelKeyMap; +import org.ofbiz.entity.util.EntityUtil; +import org.ofbiz.entity.util.EntityFindOptions; +import org.ofbiz.entity.util.EntityListIterator; +import org.ofbiz.manufacturing.NsingleHtmlFormWrapper; + +delegator = request.getAttribute("delegator"); +HashMap formsData= new HashMap(); + +String actionForm = request.getParameter("actionForm"); + +String association = request.getParameter("association"); +if (UtilValidate.isEmpty(association)) association = "<%=( (ObjectModelAttribute) associationList.get(0)).getName()%>"; +}*/ + if (associationList.size() > 1){ + for (Iterator iter=associationList.iterator(); iter.hasNext(); ){ + ObjectModelAttribute association = (ObjectModelAttribute) iter.next(); +/*{if (association.equals("<%=association.getName()%>") ) { + page.setProperty("tabButtonItem", page.getProperty("tabButtonItem<%=Util.toUpperCaseFirstLetter(association.getName())%>") ); +} +}*/ + } + } +/*{context.put("association",association); + +}*/ + ListPkAttribute listPrimaryKey = new ListPkAttribute(model, clazz, false); + String primaryKeysEmpty = " UtilValidate.isEmpty("; + String primaryKeysMap = "\""; + for(int i=0; i = null; +}*/ + } + primaryKeysEmpty += ")"; + for (Iterator iter=associationList.iterator(); iter.hasNext(); ){ + ObjectModelAttribute association = (ObjectModelAttribute) iter.next(); +/*{ +if (association.equals("<%=association.getName()%>") ){ +}*/ + String reverseAttributeName = ( association.getReverseAttribute() != null ) ? + Util.getAttributeShortName(association.getReverseAttribute()) : + Util.getClassShortName(clazz); + for(int i=0; i = request.getParameter("<%=reverseAttributeName%><%=Util.toUpperCaseFirstLetter(attributeKeyName)%>"); +}*/ + } +/*{} +}*/ + } +/*{ +if (<%=primaryKeysEmpty%>) { +}*/ + for(int i=0; i = request.getParameter("<%=attributeKeyName%>"); +}*/ + } +/*{} +}*/ + for (Iterator iter=associationList.iterator(); iter.hasNext(); ){ + ObjectModelAttribute association = (ObjectModelAttribute) iter.next(); + String reverseAttributeName = ( association.getReverseAttribute() != null ) ? + Util.getAttributeShortName(association.getReverseAttribute()) : + Util.getClassShortName(clazz); + String assocPkParameters = "\""; + for(int i=0; iPkParameters",<%=assocPkParameters%>); +}*/ + } +/*{ +if ( ! ( <%=primaryKeysEmpty%> ) ) { + // TODO : use the <%=entityName%> object and its methods to access the attributes + GenericValue <%=Util.toLowerCaseFirstLetter(entityName)%> = delegator.findByPrimaryKey("<%=entityName%>", UtilMisc.toMap(<%=primaryKeysMap%>)); + + String }*/ + for (int i=0; i}*/ + if (i = request.getParameter("<%=attributeName%>"); +}*/ + } +/*{ + if (<%=Util.toLowerCaseFirstLetter(entityName)%> != null){ +}*/ + for(int j=0; j", <%=attributeKeyName%>); + formsData.put("<%=attributeKeyName%>",<%=attributeKeyName%>); + +}*/ + } +/*{ // FOR attribue with calculated + // formsData.put("%attribue%",<%=Util.toLowerCaseFirstLetter(entityName)%>.get("%attribue%")); + // + +}*/ + for (int i=0; i != null) formsData.put("<%=attributeName%>",<%=attributeName%>); + else formsData.put("<%=attributeName%>",<%=Util.toLowerCaseFirstLetter(entityName)%>.get("<%=attributeName%>" )); + +}*/ + } + for (int i=0; i",<%=Util.toLowerCaseFirstLetter(entityName)%>.get("<%=attributeName%>" )); +}*/ + } + for (int i=0; i = <%=Util.toLowerCaseFirstLetter(entityName)%>.getRelatedOne("<%=relationName%>"); + if (<%=attributeName%> != null){ + formsData.put("<%=attributeName%>Description", <%=attributeName%>.get("<%=descriptionFieldName%>") ); + formsData.put("<%=attributeName%>Name", <%=attributeName%>.get("<%=idNameFieldName%>") ); + } + +}*/ + } +/*{ HtmlFormWrapper singleWrapper = new NsingleHtmlFormWrapper("/<%=subPackageName%>/generated/Forms<%=entityName%>.xml", "show<%=entityName%>", request, response, formsData); + context.put("singleWrapper", singleWrapper); +}*/ + for (Iterator iterAssoc=associationList.iterator(); iterAssoc.hasNext(); ){ + ObjectModelAttribute association = (ObjectModelAttribute) iterAssoc.next(); + ObjectModelClass classAssociated = Util.getClassAssociated( association ); + // initialisation of the primaryList + ListPkAttribute listPrimaryKeyB = new ListPkAttribute(model, classAssociated, false); + // initialisation Names + String subPackageAssoc = (String) Util.initPackageName(classAssociated).get("subpackageName"); + String fromEntityName = (association.getName().equals(Util.toLowerCaseFirstLetter(association.getClassifier().getName() ) ) ) ? + entityName : + Util.toUpperCaseFirstLetter(association.getName() ); + String reverseAttributeName = ( association.getReverseAttribute() != null ) ? + Util.getAttributeShortName(association.getReverseAttribute()) : + Util.getClassShortName(clazz); +/*{ + // ************************************************************************************************ + // prepare <%=Util.toUpperCaseFirstLetter(association.getName())%> List & edit or add depending of the actionForm value + // ************************************************************************************************ + if (association.equals("<%=association.getName()%>") ){ + // ============== + // List Preparation + // ============== + page.setProperty("formDefFile","/<%=subPackageAssoc%>/generated/Forms<%=classAssociated.getName()%>.xml"); + page.setProperty("listFormName","subList<%=classAssociated.getName()%><%=fromEntityName%>"); + page.setProperty("entityName","<%=classAssociated.getName()%>"); + request.setAttribute("association",association); + + // Static field from the main entity + Map inputFields = new HashMap(); +}*/ + for(int j=0; j<%=Util.toUpperCaseFirstLetter(attributeKeyName)%>", <%=attributeKeyName%>); +}*/ + } +/*{ + // create the dynamic view entity + DynamicViewEntity dynamicView = new DynamicViewEntity(); + + // default view settings <%=classAssociated.getName()%> + dynamicView.addMemberEntity("EE", "<%=classAssociated.getName()%>"); + +}*/ + for(int j=0; j"); +}*/ + } + List listAssoc = new ArrayList(); + List attributesListOrIndexed = Util.getAttributesList(classAssociated); + List attributesIndexed = new ArrayList(); + List listAttNameAssoc = new ArrayList(); + for (Iterator iter=attributesListOrIndexed.iterator(); iter.hasNext(); ){ + ObjectModelAttribute attribute = (ObjectModelAttribute) iter.next(); + if ( attribute.referenceClassifier() ){ + if ( attribute.getMaxMultiplicity() == 1 ) listAssoc.add(attribute); + } else if (! Util.isPrimaryKey(attribute) ){ + listAttNameAssoc.add(attribute.getName()); +/*{ dynamicView.addAlias("EE", "<%=attribute.getName()%>"); +}*/ + } + } + + // if there is an association class add in the dynamicView for the other association Class participant + int nbAssoc = 1; + if (classAssociated instanceof ObjectModelAssociationClass && Util.hasGuiShow((ObjectModelClass)association.getClassifier() ) ) { + ObjectModelClass clazzAssoc = (ObjectModelClass)association.getClassifier(); + ObjectModelAttribute attribute = association; + String relationName = attribute.getName(); + if (Util.toUpperCaseFirstLetter(relationName).equals(clazzAssoc.getName())) relationName = Util.getClassShortName(clazzAssoc ); +/*{ + // Association Class member associated entities + dynamicView.addMemberEntity("E<%=String.valueOf(nbAssoc)%>", "<%=Util.toUpperCaseFirstLetter(relationName)%>"); + dynamicView.addAlias("E<%=String.valueOf(nbAssoc)%>", "<%=relationName%>Name","<%=Util.getAttributeName(clazzAssoc)%>",null,null,null,null); + dynamicView.addAlias("E<%=String.valueOf(nbAssoc)%>", "<%=relationName%>Description","<%=Util.getAttributeDescription(clazzAssoc)%>",null,null,null,null); + +}*/ + if (Util.hasGuiIndexed(attribute) ){ + attributesIndexed.add(relationName+"Name"); + attributesIndexed.add(relationName+"Description"); + } + + // Add the classAssoc attributes with the tag gui listInAssoc + for (Iterator iterAssocB=clazzAssoc.getAttributes().iterator(); iterAssocB.hasNext(); ){ + ObjectModelAttribute attributeAssoc = (ObjectModelAttribute) iterAssocB.next(); + if ( Util.hasGuiListInAssoc(attributeAssoc) ){ +/*{ dynamicView.addAlias("E<%=String.valueOf(nbAssoc)%>", "<%=relationName%><%=Util.toUpperCaseFirstLetter(attributeAssoc.getName())%>","<%=attributeAssoc.getName()%>",null,null,null,null); +}*/ + } + } +/*{ dynamicView.addViewLink("EE", "E<%=String.valueOf(nbAssoc)%>", Boolean.TRUE, ModelKeyMap.makeKeyMapList( }*/ + boolean first = true; + ListPkAttribute listPrimaryKeyClazzAssoc = new ListPkAttribute(model, clazzAssoc, true); + for (int iCassoc=0; iCassoc", "<%=relFieldName%>"}*/ + first = false; + } +/*{ )); +}*/ + nbAssoc += 1; + } + + // add in the dynamicView all the associated entity + for (Iterator iter=listAssoc.iterator(); iter.hasNext(); ){ + ObjectModelAttribute attribute = (ObjectModelAttribute) iter.next(); + Map relationKeyName = Util.getRelationOneFieldName(model, attribute); + ObjectModelClass clazzAssoc = (ObjectModelClass) relationKeyName.get("clazzAssociated"); + String relationName = clazzAssoc.getName(); +/*{ + // Associated entities + dynamicView.addMemberEntity("E<%=String.valueOf(nbAssoc)%>", "<%=relationName%>"); + dynamicView.addAlias("E<%=String.valueOf(nbAssoc)%>", "<%=attribute.getName()%>Name","<%=Util.getAttributeName(clazzAssoc)%>",null,null,null,null); + dynamicView.addAlias("E<%=String.valueOf(nbAssoc)%>", "<%=attribute.getName()%>Description","<%=Util.getAttributeDescription(clazzAssoc)%>",null,null,null,null); + +}*/ + if (Util.hasGuiIndexed(attribute) ){ + attributesIndexed.add(attribute.getName()+"Name"); + attributesIndexed.add(attribute.getName()+"Description"); + } + + // check and add if necessary, the field relation maker + List listName = (List) relationKeyName.get("listName"); + for(Iterator iterList=listName.iterator(); iterList.hasNext(); ){ + Map relationItem = (Map) iterList.next(); + String fieldName = (String) relationItem.get("fieldName"); + if (listAttributeName.indexOf(fieldName) == -1){ // adding the field in the dynamicView + listAttributeName.add(fieldName); +/*{ dynamicView.addAlias("EE", "<%=fieldName%>"); +}*/ + } + } + // Add the classAssoc attributes with the tag gui listInAssoc + for (Iterator iterAssocB=clazzAssoc.getAttributes().iterator(); iterAssocB.hasNext(); ){ + ObjectModelAttribute attributeAssoc = (ObjectModelAttribute) iterAssocB.next(); + if ( Util.hasGuiListInAssoc(attributeAssoc) ){ +/*{ dynamicView.addAlias("E<%=String.valueOf(nbAssoc)%>", "<%=Util.toLowerCaseFirstLetter(relationName)%><%=Util.toUpperCaseFirstLetter(attributeAssoc.getName())%>","<%=attributeAssoc.getName()%>",null,null,null,null); +}*/ + } + } +/*{ dynamicView.addViewLink("EE", "E<%=String.valueOf(nbAssoc)%>", Boolean.TRUE, ModelKeyMap.makeKeyMapList( }*/ + boolean first = true; + for(Iterator iterList=listName.iterator(); iterList.hasNext(); ){ + Map relationItem = (Map) iterList.next(); + if ( ! first ){ +/*{, }*/ + } +/*{"<%=(String) relationItem.get("fieldName")%>", "<%=(String) relationItem.get("relFieldName")%>"}*/ + first = false; + } +/*{ )); +}*/ + nbAssoc += 1; + } +/*{ + // read and analyse the inputFields + Map queryStringMap = new HashMap(); + Map origValueMap = new HashMap(); + HashMap normalizedFields = FindServices.prepareField((Map) inputFields,(Map) queryStringMap,(Map) origValueMap); + + // compare the normalizedFields with the field the user can query on + List keys = new ArrayList(); +}*/ + for (Iterator iter=attributesIndexed.iterator(); iter.hasNext(); ){ + String attributeName = (String) iter.next(); +/*{ keys.add("<%=attributeName%>"); +}*/ + } + for(int j=0; j<%=Util.toUpperCaseFirstLetter(attributeKeyName)%>"); +}*/ + } + // +/*{ ArrayList tmpList = FindServices.createCondition(keys, normalizedFields, queryStringMap, origValueMap); + + //create the entity condition + EntityOperator entOp = EntityOperator.AND; + EntityConditionList mainCond = new EntityConditionList(tmpList, (EntityJoinOperator) entOp); + + // create the orderBy + List orderByList = null; + + // set entityFindOptions + EntityFindOptions findOpts = new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, true); + + // using list iterator + EntityListIterator listIt = delegator.findListIteratorByCondition(dynamicView, mainCond, null, null, orderByList, findOpts); + request.setAttribute("listIt", listIt); + + String queryString = UtilHttp.urlEncodeArgs(inputFields); + context.put("queryString", queryString); + + // ================= + // Edit or Add preparation + // ================== + if (! UtilValidate.isEmpty(actionForm)){ + if (actionForm.startsWith("commit") ) actionForm = actionForm.substring(6); + Map <%=association.getName()%>FD = new HashMap(); + +}*/ + // same code are in the GeneratorEditBsh + List listAttributeNameB = new ArrayList(); // list of all attribute which must be declare or read + List listAttCalculatedB = new ArrayList(); // list of read only attribute + List listAttAssocB = new ArrayList(); // list of the association with MaxMultiplicity() == 1 + + // initialisation of the three lists + for (Iterator iter=classAssociated.getAttributes().iterator(); iter.hasNext(); ){ + ObjectModelAttribute attribute = (ObjectModelAttribute) iter.next(); + if (! Util.hasGuiHidden(attribute) && ! Util.isPrimaryKey(attribute)){ + if (Util.hasGuiCalculated(attribute)){ + listAttCalculatedB.add(attribute.getName()); + } else { + if (attribute.referenceClassifier() ){ + if (attribute.getMaxMultiplicity() == 1){ + Map relationKeyName = Util.getRelationOneFieldName(model, attribute); + listAttAssocB.add(attribute); + List listName = (List) relationKeyName.get("listName"); + for(Iterator iterList=listName.iterator(); iterList.hasNext(); ){ + Map fieldNameMap = (Map) iterList.next(); + String attributeKeyName = (String) fieldNameMap.get("fieldName"); + listAttributeNameB.add(attributeKeyName); + } + } + } else listAttributeNameB.add(attribute.getName() ); + } + } + } + // end of same code + + String primaryKeysEmptyB = "! UtilValidate.isEmpty("; + String primaryKeysMapB = "\""; + for(int j=0; j = request.getParameter("<%=attributeKeyName%>"); + context.put("<%=association.getName()%><%=attributeKeyName%>", <%=attributeKeyName%>); + <%=association.getName()%>FD.put("<%=attributeKeyName%>",<%=attributeKeyName%>); + +}*/ + primaryKeysEmptyB = primaryKeysEmptyB + attributeKeyName; + primaryKeysMapB = primaryKeysMapB + attributeKeyName + "\"," + attributeKeyName; + if (j < listPrimaryKeyB.getName().size()-1){ + primaryKeysEmptyB += ") && ! UtilValidate.isEmpty("; + primaryKeysMapB += ",\""; + } + } + primaryKeysEmptyB += ")"; +/*{ if (<%=primaryKeysEmptyB%>) { + GenericValue <%=Util.toLowerCaseFirstLetter(classAssociated.getName())%> = delegator.findByPrimaryKey("<%=classAssociated.getName()%>", UtilMisc.toMap(<%=primaryKeysMapB%>)); + + String }*/ + for (int i=0; i}*/ + if (i = request.getParameter("<%=attributeName%>"); +}*/ + } +/*{ + if (<%=Util.toLowerCaseFirstLetter(classAssociated.getName())%> != null){ + if (actionForm.equals("add") ) actionForm = "edit"; + // FOR attribue with calculated + // <%=association.getName()%>FD.put("%attribue%",<%=Util.toLowerCaseFirstLetter(entityName)%>.get("%attribue%")); + // + +}*/ + for (int i=0; i != null) <%=association.getName()%>FD.put("<%=attributeName%>",<%=attributeName%>); + else <%=association.getName()%>FD.put("<%=attributeName%>",<%=Util.toLowerCaseFirstLetter(classAssociated.getName())%>.get("<%=attributeName%>" )); + +}*/ + } + for (int i=0; iFD.put("<%=attributeName%>",<%=Util.toLowerCaseFirstLetter(classAssociated.getName())%>.get("<%=attributeName%>" )); +}*/ + } + for (int i=0; i = <%=Util.toLowerCaseFirstLetter(classAssociated.getName())%>.getRelatedOne("<%=relationName%>"); + if (<%=attributeName%> != null){ + <%=association.getName()%>FD.put("<%=attributeName%>Description", <%=attributeName%>.get("<%=descriptionFieldName%>") ); + <%=association.getName()%>FD.put("<%=attributeName%>Name", <%=attributeName%>.get("<%=idNameFieldName%>") ); + } + +}*/ + } +/*{ } + } + request.setAttribute("actionForm",actionForm); + HtmlFormWrapper <%=association.getName()%>Wrapper = new NsingleHtmlFormWrapper("/<%=subPackageAssoc%>/generated/Forms<%=classAssociated.getName()%>.xml", "subEdit<%=classAssociated.getName()%><%=fromEntityName%>", request, response, <%=association.getName()%>FD); + <%=association.getName()%>Wrapper.putInContext("association",association); + context.put("<%=association.getName()%>Wrapper", <%=association.getName()%>Wrapper); + } + } +}*/ + } +/*{ + } +} +request.setAttribute("actionForm",actionForm); +context.put("actionForm",actionForm); + +}*/ + } +} + + Index: ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/ListPkAttribute.java diff -u /dev/null ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/ListPkAttribute.java:1.1 --- /dev/null Tue Jul 6 15:05:10 2004 +++ ofbiz-neogia-generators/src/java/org/ofbiz/neogia/generators/ListPkAttribute.java Tue Jul 6 15:05:04 2004 @@ -0,0 +1,150 @@ +/* *##% + * Copyright (c) 2004 Nereide - www.nereide.biz + * Copyright (c) 2004 Neogia - www.neogia.org +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program 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 General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*##%*/ + +package org.ofbiz.neogia.generators; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.codelutin.generator.models.object.ObjectModel; +import org.codelutin.generator.models.object.ObjectModelAttribute; +import org.codelutin.generator.models.object.ObjectModelClass; + +/** + * @author Olivier Heintz + * + * return the name and type of all the primaryKey. + * Read the primaryKey list for the superClass if it exist, read the participant primaryKeys list if clazz + * is an association class + * (replacement of the Util.getListPrimaryKeyAttr methode) + * @param model to be able to search in all class the association no navigable + * @param clazz + * @param boolean to say if the ofbizType is an entity OfbizType (true) or java OfbizType (false) + * @param _classAssoc to be able to test for not retreiving primaryKey when they coming from _classAssoc. + * @version $Revision: 1.1 $ + * + * Last update : $Date: 2004/07/06 15:05:04 $ + * by : $Author: holivier $ + */ +public class ListPkAttribute { + protected List name = new ArrayList(), type = new ArrayList(); + + public ListPkAttribute(ObjectModel model, ObjectModelClass clazz, boolean entity ){ + ObjectModelClass classAssoc = null; + listPkAttribute(model, clazz, entity, classAssoc); + } + public ListPkAttribute(ObjectModel model, ObjectModelClass clazz, boolean entity, ObjectModelClass _classAssoc ){ + listPkAttribute(model, clazz, entity, _classAssoc); + } + private void listPkAttribute(ObjectModel model, ObjectModelClass clazz, boolean entity, ObjectModelClass _classAssoc){ + // search for non navigable association and composite + List classAssocWithoutNav = Util.getClassAssocWithoutNav(model, clazz); + if (classAssocWithoutNav.size() > 0 ){ + for (Iterator iterClass=classAssocWithoutNav.iterator(); iterClass.hasNext(); ){ + ObjectModelAttribute attrAssociated = (ObjectModelAttribute) iterClass.next(); + //System.out.println("XXXXXX-DebugUtil in iterator classAssocWithoutNav attrAssociated=" + attrAssociated.getName()); + if (attrAssociated.isComposite()){ + ObjectModelClass classAssociated = (ObjectModelClass) attrAssociated.getDeclaringElement(); + if (! classAssociated.equals(_classAssoc) ){ + String relationName = (attrAssociated.getName().equals(Util.toLowerCaseFirstLetter(clazz.getName())) ) ? + Util.getClassShortName(classAssociated) : + Util.toUpperCaseFirstLetter(attrAssociated.getName()); + ListPkAttribute listCompositePrimaryKey = new ListPkAttribute(model, classAssociated, entity); + for(int i=0; i