Author: jacopoc
Date: Fri Dec 1 12:06:14 2006 New Revision: 481364 URL: http://svn.apache.org/viewvc?view=rev&rev=481364 Log: Added bsh script needed by the newly migrated entity reference screens from Marco Risaliti: OFBIZ-460 Added: incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/CheckDb.bsh (with props) incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRef.bsh (with props) incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRefList.bsh (with props) incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRefMain.bsh (with props) Added: incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/CheckDb.bsh URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/CheckDb.bsh?view=auto&rev=481364 ============================================================================== --- incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/CheckDb.bsh (added) +++ incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/CheckDb.bsh Fri Dec 1 12:06:14 2006 @@ -0,0 +1,129 @@ +/* + * Copyright 2001-2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +import org.ofbiz.entity.GenericDelegator; +import org.ofbiz.security.Security; +import org.ofbiz.entity.jdbc.DatabaseUtil; + +delegator = request.getAttribute("delegator"); +security = request.getAttribute("security"); + +String controlPath = (String)request.getAttribute("_CONTROL_PATH_"); + +if (security.hasPermission("ENTITY_MAINT", session)) { + boolean addMissing = "true".equals(request.getParameter("addMissing")); + boolean checkFkIdx = "true".equals(request.getParameter("checkFkIdx")); + boolean checkFks = "true".equals(request.getParameter("checkFks")); + boolean checkPks = "true".equals(request.getParameter("checkPks")); + boolean repair = "true".equals(request.getParameter("repair")); + String option = request.getParameter("option"); + String groupName = request.getParameter("groupName"); + + Iterator miter = null; + if (groupName != null && groupName.length() > 0) { + String helperName = delegator.getGroupHelperName(groupName); + + List messages = new LinkedList(); + //GenericHelper helper = GenericHelperFactory.getHelper(helperName); + DatabaseUtil dbUtil = new DatabaseUtil(helperName); + Map modelEntities = delegator.getModelEntityMapByGroup(groupName); + Set modelEntityNames = new TreeSet(modelEntities.keySet()); + + if ("checkupdatetables".equals(option)) { + List fieldsToRepair = null; + if (repair) { + fieldsToRepair = new ArrayList(); + } + dbUtil.checkDb(modelEntities, fieldsToRepair, messages, checkPks, checkFks, checkFkIdx, addMissing); + if (fieldsToRepair != null && fieldsToRepair.size() > 0) { + dbUtil.repairColumnSizeChanges(modelEntities, fieldsToRepair, messages); + } + } else if ("removetables".equals(option)) { + Iterator modelEntityNameIter = modelEntityNames.iterator(); + while (modelEntityNameIter.hasNext()) { + String modelEntityName = (String) modelEntityNameIter.next(); + ModelEntity modelEntity = (ModelEntity) modelEntities.get(modelEntityName); + dbUtil.deleteTable(modelEntity, messages); + } + } else if ("removepks".equals(option)) { + Iterator modelEntityNameIter = modelEntityNames.iterator(); + while (modelEntityNameIter.hasNext()) { + String modelEntityName = (String) modelEntityNameIter.next(); + ModelEntity modelEntity = (ModelEntity) modelEntities.get(modelEntityName); + dbUtil.deletePrimaryKey(modelEntity, messages); + } + } else if ("createpks".equals(option)) { + Iterator modelEntityNameIter = modelEntityNames.iterator(); + while (modelEntityNameIter.hasNext()) { + String modelEntityName = (String) modelEntityNameIter.next(); + ModelEntity modelEntity = (ModelEntity) modelEntities.get(modelEntityName); + dbUtil.createPrimaryKey(modelEntity, messages); + } + } else if ("createfkidxs".equals(option)) { + Iterator modelEntityNameIter = modelEntityNames.iterator(); + while (modelEntityNameIter.hasNext()) { + String modelEntityName = (String) modelEntityNameIter.next(); + ModelEntity modelEntity = (ModelEntity) modelEntities.get(modelEntityName); + dbUtil.createForeignKeyIndices(modelEntity, messages); + } + } else if ("removefkidxs".equals(option)) { + Iterator modelEntityNameIter = modelEntityNames.iterator(); + while (modelEntityNameIter.hasNext()) { + String modelEntityName = (String) modelEntityNameIter.next(); + ModelEntity modelEntity = (ModelEntity) modelEntities.get(modelEntityName); + dbUtil.deleteForeignKeyIndices(modelEntity, messages); + } + } else if ("createfks".equals(option)) { + Iterator modelEntityNameIter = modelEntityNames.iterator(); + while (modelEntityNameIter.hasNext()) { + String modelEntityName = (String) modelEntityNameIter.next(); + ModelEntity modelEntity = (ModelEntity) modelEntities.get(modelEntityName); + dbUtil.createForeignKeys(modelEntity, modelEntities, messages); + } + } else if ("removefks".equals(option)) { + Iterator modelEntityNameIter = modelEntityNames.iterator(); + while (modelEntityNameIter.hasNext()) { + String modelEntityName = (String) modelEntityNameIter.next(); + ModelEntity modelEntity = (ModelEntity) modelEntities.get(modelEntityName); + dbUtil.deleteForeignKeys(modelEntity, modelEntities, messages); + } + } else if ("createidx".equals(option)) { + Iterator modelEntityNameIter = modelEntityNames.iterator(); + while (modelEntityNameIter.hasNext()) { + String modelEntityName = (String) modelEntityNameIter.next(); + ModelEntity modelEntity = (ModelEntity) modelEntities.get(modelEntityName); + dbUtil.createDeclaredIndices(modelEntity, messages); + } + } else if ("removeidx".equals(option)) { + Iterator modelEntityNameIter = modelEntityNames.iterator(); + while (modelEntityNameIter.hasNext()) { + String modelEntityName = (String) modelEntityNameIter.next(); + ModelEntity modelEntity = (ModelEntity) modelEntities.get(modelEntityName); + dbUtil.deleteDeclaredIndices(modelEntity, messages); + } + } else if ("updateCharsetCollate".equals(option)) { + Iterator modelEntityNameIter = modelEntityNames.iterator(); + while (modelEntityNameIter.hasNext()) { + String modelEntityName = (String) modelEntityNameIter.next(); + ModelEntity modelEntity = (ModelEntity) modelEntities.get(modelEntityName); + dbUtil.updateCharacterSetAndCollation(modelEntity, messages); + } + } + miter = messages.iterator(); + context.put("miters", miter); + } + context.put("encodeURLCheckDb", response.encodeURL(controlPath + "/view/checkdb")); + context.put("groupName", (groupName != null) ? groupName : "org.ofbiz"); +} Propchange: incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/CheckDb.bsh ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/CheckDb.bsh ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/CheckDb.bsh ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRef.bsh URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRef.bsh?view=auto&rev=481364 ============================================================================== --- incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRef.bsh (added) +++ incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRef.bsh Fri Dec 1 12:06:14 2006 @@ -0,0 +1,61 @@ +/* + * Copyright 2001-2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +String controlPath = (String)request.getAttribute("_CONTROL_PATH_"); +String list = controlPath + "/view/entityref_list"; +String main = controlPath + "/view/entityref_main"; +String search = (String)request.getParameter("search"); +String forstatic = (String)request.getParameter("forstatic"); + +if (search != null) { + list = list + "?search=" + search; + main = main + "?search=" + search; +} else if (forstatic != null) { + list = list + "?forstatic=" + forstatic; + main = main + "?forstatic=" + forstatic; +} +context.put("encodeUrlList", response.encodeURL(list)); +context.put("encodeUrlMain", response.encodeURL(main)); +/* + * Copyright 2001-2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +String controlPath = (String)request.getAttribute("_CONTROL_PATH_"); +String list = controlPath + "/view/entityref_list"; +String main = controlPath + "/view/entityref_main"; +String search = (String)request.getParameter("search"); +String forstatic = (String)request.getParameter("forstatic"); + +if (search != null) { + list = list + "?search=" + search; + main = main + "?search=" + search; +} else if (forstatic != null) { + list = list + "?forstatic=" + forstatic; + main = main + "?forstatic=" + forstatic; +} +context.put("encodeUrlList", response.encodeURL(list)); +context.put("encodeUrlMain", response.encodeURL(main)); Propchange: incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRef.bsh ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRef.bsh ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRef.bsh ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRefList.bsh URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRefList.bsh?view=auto&rev=481364 ============================================================================== --- incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRefList.bsh (added) +++ incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRefList.bsh Fri Dec 1 12:06:14 2006 @@ -0,0 +1,61 @@ +/* + * Copyright 2001-2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +import org.ofbiz.entity.GenericDelegator; +import org.ofbiz.security.Security; +import org.ofbiz.entity.model.ModelReader; +import org.ofbiz.entity.model.ModelEntity; + +delegator = request.getAttribute("delegator"); +security = request.getAttribute("security"); + +String controlPath = (String)request.getAttribute("_CONTROL_PATH_"); +context.put("controlPath", controlPath); + +if (security.hasPermission("ENTITY_MAINT", session)) { + boolean forstatic = "true".equals(request.getParameter("forstatic")); + context.put("forstatic", forstatic); + + ModelReader reader = delegator.getModelReader(); + Collection ec = reader.getEntityNames(); + TreeSet entities = new TreeSet(ec); + search = (String) request.getParameter("search"); + + TreeSet packageNames = new TreeSet(); + Iterator ecIter = ec.iterator(); + while(ecIter.hasNext()) { + String eName = (String)ecIter.next(); + ModelEntity ent = reader.getModelEntity(eName); + packageNames.add(ent.getPackageName()); + } + context.put("packageNames", packageNames); + + List entitiesList = new ArrayList(); + Iterator i = entities.iterator(); + while (i.hasNext()) { + Map entityMap = new HashMap(); + + Object o = i.next(); + String entityName = (String)o; + if (search == null || entityName.toLowerCase().indexOf(search.toLowerCase()) != -1 ) { + String url = (search == null) ? "" : "?search=" + search; + entityMap.put("url", url); + } + entityMap.put("entityName", entityName); + + entitiesList.add(entityMap); + } + context.put("entitiesList", entitiesList); +} Propchange: incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRefList.bsh ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRefList.bsh ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRefList.bsh ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRefMain.bsh URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRefMain.bsh?view=auto&rev=481364 ============================================================================== --- incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRefMain.bsh (added) +++ incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRefMain.bsh Fri Dec 1 12:06:14 2006 @@ -0,0 +1,158 @@ +/* + * Copyright 2001-2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +import org.ofbiz.entity.GenericDelegator; +import org.ofbiz.security.Security; +import org.ofbiz.entity.model.ModelReader; +import org.ofbiz.entity.model.ModelEntity; +import org.ofbiz.entity.model.ModelField; +import org.ofbiz.entity.model.ModelFieldType; +import org.ofbiz.entity.model.ModelRelation; +import org.ofbiz.entity.model.ModelKeyMap; +import org.ofbiz.base.util.UtilValidate; + +delegator = request.getAttribute("delegator"); +security = request.getAttribute("security"); + +String controlPath = (String)request.getAttribute("_CONTROL_PATH_"); + +if (security.hasPermission("ENTITY_MAINT", session)) { + boolean forstatic = "true".equals(request.getParameter("forstatic")); + context.put("forstatic", forstatic); + + String search = null; + + ModelReader reader = delegator.getModelReader(); + Map packages = new HashMap(); + TreeSet packageNames = new TreeSet(); + TreeSet tableNames = new TreeSet(); + + //put the entityNames TreeSets in a HashMap by packageName + Collection ec = reader.getEntityNames(); + TreeSet entityNames = new TreeSet(ec); + Iterator ecIter = ec.iterator(); + while (ecIter.hasNext()) { + String eName = (String)ecIter.next(); + ModelEntity ent = reader.getModelEntity(eName); + + //make sure the table name is in the list of all table names, if not null + if (UtilValidate.isNotEmpty(ent.getPlainTableName())) { + tableNames.add(ent.getPlainTableName()); + } + + TreeSet entities = (TreeSet)packages.get(ent.getPackageName()); + if (entities == null) { + entities = new TreeSet(); + packages.put(ent.getPackageName(), entities); + packageNames.add(ent.getPackageName()); + } + entities.add(eName); + } + + int numberOfEntities = ec.size(); + context.put("numberOfEntities", numberOfEntities); + + int numberShowed = 0; + search = (String) request.getParameter("search"); + + List packagesList = new ArrayList(); + Iterator piter = packageNames.iterator(); + while (piter.hasNext()) { + Map packageMap = new HashMap(); + + String pName = (String) piter.next(); + TreeSet entities = (TreeSet) packages.get(pName); + + List entitiesList = new ArrayList(); + Iterator i = entities.iterator(); + while (i.hasNext()) { + Map entityMap = new HashMap(); + + String entityName = (String)i.next(); + String helperName = delegator.getEntityHelperName(entityName); + String groupName = delegator.getEntityGroupName(entityName); + if (search == null || entityName.toLowerCase().indexOf(search.toLowerCase()) != -1) { + ModelEntity entity = reader.getModelEntity(entityName); + + List javaNameList = new ArrayList(); + TreeSet ufields = new TreeSet(); + for (int y = 0; y < entity.getFieldsSize(); y++) { + Map javaNameMap = new HashMap(); + + ModelField field = entity.getField(y); + ModelFieldType type = delegator.getEntityFieldType(entity, field.getType()); + String javaName = null; + javaName = field.getIsPk() ? "<span style=\"color: red;\">" + field.getName() + "</span>" : field.getName(); + javaNameMap.put("name", javaName); + javaNameMap.put("colName", field.getColName()); + javaNameMap.put("type", field.getType()); + javaNameMap.put("javaType", (field.getType() != null) ? type.getJavaType() : null); + javaNameMap.put("sqlType", (field.getType() != null) ? type.getSqlType() : null); + + javaNameList.add(javaNameMap); + } + + List relationsList = new ArrayList(); + TreeSet relations = new TreeSet(); + for (int r = 0; r < entity.getRelationsSize(); r++) { + Map relationMap = new HashMap(); + + ModelRelation relation = entity.getRelation(r); + + List keysList = new ArrayList(); + for (int km = 0; km < relation.getKeyMapsSize(); km++) { + Map keysMap = new HashMap(); + + ModelKeyMap keyMap = relation.getKeyMap(km); + if (keyMap.getFieldName().equals(keyMap.getRelFieldName())) { + fieldName = keyMap.getFieldName(); + relFieldName = "aa"; + } else { + fieldName = keyMap.getFieldName(); + relFieldName = keyMap.getRelFieldName(); + } + keysMap.put("row", km+1); + keysMap.put("fieldName", fieldName); + keysMap.put("relFieldName", relFieldName); + + keysList.add(keysMap); + } + relationMap.put("title", relation.getTitle()); + relationMap.put("relEntity", relation.getRelEntityName()); + relationMap.put("fkName", relation.getFkName()); + relationMap.put("type", relation.getType()); + relationMap.put("length", relation.getType().length()); + relationMap.put("keysList", keysList); + + relationsList.add(relationMap); + } + + entityMap.put("entityName", entityName); + entityMap.put("helperName", helperName); + entityMap.put("groupName", groupName); + entityMap.put("plainTableName", entity.getPlainTableName()); + entityMap.put("title", entity.getTitle()); + entityMap.put("description", entity.getDescription()); + entityMap.put("javaNameList", javaNameList); + entityMap.put("relationsList", relationsList); + entitiesList.add(entityMap); + } + } + packageMap.put("packageName", pName); + packageMap.put("entitiesList", entitiesList); + packagesList.add(packageMap); + } + context.put("packagesList", packagesList); +} Propchange: incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRefMain.bsh ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRefMain.bsh ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: incubator/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityRefMain.bsh ------------------------------------------------------------------------------ svn:mime-type = text/plain |
Free forum by Nabble | Edit this page |