List of usage examples for org.apache.commons.beanutils DynaBean get
public Object get(String name);
From source file:org.jaffa.ria.finder.apis.ExcelExportService.java
/** * Formats the input object based on the layout specified in the * ColumnModel./*from ww w . j av a 2 s . c o m*/ */ private static String format(Object value, DynaBean columnModel) { try { String layout = (String) columnModel.get("layout"); if (value != null && value instanceof Double) { return Formatter.format((Double) value); } else { if ("[hh:mm]".equals(layout)) { return decimal2hmm(value); } } } catch (Exception e) { } return value != null ? value.toString() : ""; }
From source file:org.jwebsocket.dynamicsql.SupportUtils.java
/** * Convert a DynaBean object to Map./*from ww w . ja va 2s . c o m*/ * * @param aDynaBean The DynaBean object. * @return The Map<String, Object> */ public static Map<String, Object> convertToMap(DynaBean aDynaBean) { Map<String, Object> lMap = new FastMap<String, Object>(); for (DynaProperty lDynaProperty : aDynaBean.getDynaClass().getDynaProperties()) { lMap.put(lDynaProperty.getName(), aDynaBean.get(lDynaProperty.getName())); } return lMap; }
From source file:org.openbravo.erpCommon.modules.ImportModule.java
/** * Checks whether the given .obx InputStream contains an update to an already installed version. * /*from ww w .j av a2s . c o m*/ * @param is * an InputStream to the module .obx file * @return true if the .obx represents an update to the module * @throws Exception * if an error occurs performing the comparison */ public boolean isModuleUpdate(InputStream is) throws Exception { boolean isUpdate = false; final Vector<DynaBean> modulesInObx = new Vector<DynaBean>(); getModulesFromObx(modulesInObx, dependencies, dbprefix, is, new HashMap<String, String>()); // don't care about merges at this stage for (final DynaBean module : modulesInObx) { String moduleId = (String) module.get("AD_MODULE_ID"); String moduleName = (String) module.get("NAME"); String version = (String) module.get("VERSION"); if (ImportModuleData.moduleInstalled(pool, moduleId)) { String installedVersion = ImportModuleData.selectVersion(pool, moduleId); VersionUtility.VersionComparator comparator = new VersionUtility.VersionComparator(); if (comparator.compare(version, installedVersion) > 0) { isUpdate = true; } else { addLog(moduleName + " " + version + " is not an update to " + " already installed version " + installedVersion, MSG_WARN); } } else { return true; } } return isUpdate; }
From source file:org.openbravo.erpCommon.modules.ImportModule.java
/** * Check the dependencies for a file. Used only for local installation from obx file. * //from w w w .j a v a 2 s. co m * @see #checkDependenciesId(String[], String[], HashMap) */ public boolean checkDependenciesFile(InputStream file) throws Exception { final Vector<DynaBean> modulesInObx = new Vector<DynaBean>(); Map<String, String> merges = new HashMap<String, String>(); getModulesFromObx(modulesInObx, dependencies, dbprefix, file, merges); for (final DynaBean module : modulesInObx) { String moduleId = (String) module.get("AD_MODULE_ID"); String version = (String) module.get("VERSION"); if (ImportModuleData.moduleInstalled(pool, moduleId)) { String installedVersion = ImportModuleData.selectVersion(pool, moduleId); VersionUtility.VersionComparator comparator = new VersionUtility.VersionComparator(); if (comparator.compare(version, installedVersion) > 0) { dynModulesToUpdate.add(module); } } else { dynModulesToInstall.add(module); } } modulesToInstall = dyanaBeanToModules(dynModulesToInstall, dependencies); modulesToUpdate = dyanaBeanToModules(dynModulesToUpdate, dependencies); // Check merges List<Module> mergesList = new ArrayList<Module>(); for (Entry<String, String> merge : merges.entrySet()) { org.openbravo.model.ad.module.Module mergedDALModule = OBDal.getInstance() .get(org.openbravo.model.ad.module.Module.class, merge.getKey()); if (mergedDALModule != null) { // Merged module is installed locally, add it as merge to uninstall. In case it is not // installed, it does not make sense to show any message to user. Module mergedModule = getWsModuleFromDalModule(mergedDALModule); HashMap<String, String> additionalInfo = new HashMap<String, String>(); additionalInfo.put("remove", "true"); additionalInfo.put("mergedWith", getMergedWith(merge.getValue())); mergedModule.setAdditionalInfo(additionalInfo); mergesList.add(mergedModule); } } modulesToMerge = mergesList.toArray(new Module[0]); errors = new OBError(); checked = VersionUtility.checkLocal(vars, modulesToInstall, modulesToUpdate, modulesToMerge, errors); if (antInstall) { printAntDependenciesLog(); } if (!checked) { try { ImportModuleData.insertLog(pool, (vars == null ? "0" : vars.getUser()), "", "", "", "Cannot perform installation correctly: " + errors.getMessage() + (force ? ". Forced anyway" : ""), "E"); } catch (final ServletException ex) { log4j.error("Error inserting log", ex); } } return checked; }
From source file:org.openbravo.erpCommon.modules.ImportModule.java
/** * Receives a Vector<DynaBean> and tranforms it to a Module[] *//*from w ww. j a va 2 s . com*/ private Module[] dyanaBeanToModules(Vector<DynaBean> dModulesToInstall, Vector<DynaBean> dynDependencies) { final Module[] rt = new Module[dModulesToInstall.size()]; int i = 0; for (final DynaBean dynModule : dModulesToInstall) { rt[i] = new Module(); rt[i].setModuleID((String) dynModule.get("AD_MODULE_ID")); rt[i].setVersionNo((String) dynModule.get("VERSION")); rt[i].setName((String) dynModule.get("NAME")); rt[i].setLicenseAgreement((String) dynModule.get("LICENSE")); rt[i].setLicenseType((String) dynModule.get("LICENSETYPE")); rt[i].setPackageName((String) dynModule.get("JAVAPACKAGE")); rt[i].setType((String) dynModule.get("TYPE")); rt[i].setDescription((String) dynModule.get("DESCRIPTION")); rt[i].setHelp((String) dynModule.get("HELP")); HashMap<String, String> enforcements = new HashMap<String, String>(); rt[i].setDependencies(dyanaBeanToDependencies(dynDependencies, rt[i].getModuleID(), enforcements)); // old modules don't have iscommercial column String commercial = (String) dynModule.get("ISCOMMERCIAL"); boolean isCommercial = commercial != null && commercial.equals("Y"); rt[i].setIsCommercial(isCommercial); // To show details in local ad_module_id is used rt[i].setModuleVersionID((String) dynModule.get("AD_MODULE_ID")); // use this for information that is not contained in standard fields HashMap<String, Object> additionalInfo = new HashMap<String, Object>(); if (isCommercial) { String tier = (String) dynModule.get("COMMERCIAL_TIER"); if (tier == null || tier.isEmpty()) { // If tier is not set in the obx, assume tier 2 to show a more restrictive error message tier = "2"; } additionalInfo.put("tier", tier); } additionalInfo.put("enforcements", enforcements); rt[i].setAdditionalInfo(additionalInfo); i++; } return rt; }
From source file:org.openbravo.erpCommon.modules.ImportModule.java
/** * Returns the dependencies in Vector<DynaBean> dynDependencies for the ad_module_id module as a * ModuleDependency[], used by dyanaBeanToModules method * //from ww w . j ava 2 s . c om */ private ModuleDependency[] dyanaBeanToDependencies(Vector<DynaBean> dynDependencies, String ad_module_id, HashMap<String, String> enforcements) { final ArrayList<ModuleDependency> dep = new ArrayList<ModuleDependency>(); try { OBContext.setAdminMode(); for (final DynaBean dynModule : dynDependencies) { if (((String) dynModule.get("AD_MODULE_ID")).equals(ad_module_id)) { final ModuleDependency md = new ModuleDependency(); String modId = (String) dynModule.get("AD_DEPENDENT_MODULE_ID"); md.setModuleID(modId); md.setVersionStart((String) dynModule.get("STARTVERSION")); md.setVersionEnd((String) dynModule.get("ENDVERSION")); md.setModuleName((String) dynModule.get("DEPENDANT_MODULE_NAME")); // calculate enforcements, set the local one in case is editable and there is one, other // case set the defined in the obx OBCriteria<org.openbravo.model.ad.module.ModuleDependency> qDependentMod = OBDal.getInstance() .createCriteria(org.openbravo.model.ad.module.ModuleDependency.class); qDependentMod.add(Restrictions.eq( org.openbravo.model.ad.module.ModuleDependency.PROPERTY_MODULE + ".id", ad_module_id)); qDependentMod.add(Restrictions.eq( org.openbravo.model.ad.module.ModuleDependency.PROPERTY_DEPENDENTMODULE + ".id", modId)); String enforcement = null; if (!qDependentMod.list().isEmpty() && qDependentMod.list().get(0).isUserEditableEnforcement() && qDependentMod.list().get(0).getInstanceEnforcement() != null) { enforcement = qDependentMod.list().get(0).getInstanceEnforcement(); } else { enforcement = (String) dynModule.get("DEPENDENCY_ENFORCEMENT"); } if (enforcement == null || enforcement.isEmpty()) { enforcement = "MAJOR"; } enforcements.put(modId, enforcement); dep.add(md); } } final ModuleDependency rt[] = new ModuleDependency[dep.size()]; for (int i = 0; i < rt.length; i++) { rt[i] = dep.get(i); } return rt; } finally { OBContext.restorePreviousMode(); } }
From source file:org.openbravo.erpCommon.modules.ImportModule.java
/** * Adds the classpath entries to .classpath file from the modules in the Vector<DynaBean> * /*from w ww . j a va 2s .c om*/ */ private void addDynaClasspathEntries(Vector<DynaBean> dModulesToInstall) throws Exception { if (!(new File(obDir + "/.classpath").exists())) { log4j.info("No " + obDir + "/.classpath file"); return; } log4j.info("Adding .claspath entries"); final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); final DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); final Document doc = docBuilder.parse(obDir + "/.classpath"); for (final DynaBean module : dModulesToInstall) { final String dir = "modules/" + (String) module.get("JAVAPACKAGE") + "/src"; if (new File(obDir + "/" + dir).exists()) { addClassPathEntry(doc, dir); } else { log4j.info(dir + " does not exist, no claspath entry added"); } } // Save the modified xml file to .classpath file final Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); final FileOutputStream fout = new FileOutputStream(obDir + "/.classpath"); final StreamResult result = new StreamResult(fout); final DOMSource source = new DOMSource(doc); transformer.transform(source, result); fout.close(); }
From source file:org.openbravo.erpCommon.modules.ImportModule.java
/** * Inserts in database the Vector<DynaBean> with its dependencies * /*from w ww . j a v a2 s . c o m*/ * @param dModulesToInstall * @param dependencies1 * @param newModule * @throws Exception */ private void insertDynaModulesInDB(Vector<DynaBean> dModulesToInstall, Vector<DynaBean> dependencies1, Vector<DynaBean> dbPrefix, boolean newModule) throws Exception { final Properties obProperties = new Properties(); obProperties.load(new FileInputStream(obDir + "/config/Openbravo.properties")); final String url = obProperties.getProperty("bbdd.url") + (obProperties.getProperty("bbdd.rdbms").equals("POSTGRE") ? "/" + obProperties.getProperty("bbdd.sid") : ""); final BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(obProperties.getProperty("bbdd.driver")); ds.setUrl(url); ds.setUsername(obProperties.getProperty("bbdd.user")); ds.setPassword(obProperties.getProperty("bbdd.password")); final Connection conn = ds.getConnection(); Integer seqNo = new Integer(ImportModuleData.selectSeqNo(pool)); for (final DynaBean module : dModulesToInstall) { seqNo += 10; module.set("ISDEFAULT", "N"); module.set("STATUS", "I"); module.set("SEQNO", seqNo); module.set("UPDATE_AVAILABLE", null); module.set("UPGRADE_AVAILABLE", null); log4j.info("Inserting in DB info for module: " + module.get("NAME")); String moduleId = (String) module.get("AD_MODULE_ID"); // Clean temporary tables ImportModuleData.cleanModuleInstall(pool, moduleId); ImportModuleData.cleanModuleDBPrefixInstall(pool, moduleId); ImportModuleData.cleanModuleDependencyInstall(pool, moduleId); String type = (String) module.get("TYPE"); String applyConfigScript = "Y"; if ("T".equals(type)) { if (newModule && V3_TEMPLATE_ID.equals(moduleId)) { // When installing V3 template do not apply its config script applyConfigScript = "N"; } else { org.openbravo.model.ad.module.Module template = OBDal.getInstance() .get(org.openbravo.model.ad.module.Module.class, moduleId); applyConfigScript = template == null ? "Y" : template.isApplyConfigurationScript() ? "Y" : "N"; } } // Insert data in temporary tables ImportModuleData.insertModuleInstall(pool, moduleId, (String) module.get("NAME"), (String) module.get("VERSION"), (String) module.get("DESCRIPTION"), (String) module.get("HELP"), (String) module.get("URL"), type, (String) module.get("LICENSE"), (String) module.get("ISINDEVELOPMENT"), (String) module.get("ISDEFAULT"), seqNo.toString(), (String) module.get("JAVAPACKAGE"), (String) module.get("LICENSETYPE"), (String) module.get("AUTHOR"), (String) module.get("STATUS"), (String) module.get("UPDATE_AVAILABLE"), (String) module.get("ISTRANSLATIONREQUIRED"), (String) module.get("AD_LANGUAGE"), (String) module.get("HASCHARTOFACCOUNTS"), (String) module.get("ISTRANSLATIONMODULE"), (String) module.get("HASREFERENCEDATA"), (String) module.get("ISREGISTERED"), (String) module.get("UPDATEINFO"), (String) module.get("UPDATE_VER_ID"), (String) module.get("REFERENCEDATAINFO"), applyConfigScript); // Set installed for modules being updated ImportModuleData.setModuleUpdated(pool, (String) module.get("AD_MODULE_ID")); addLog("@ModuleInstalled@ " + module.get("NAME") + " - " + module.get("VERSION"), MSG_SUCCESS); } for (final DynaBean module : dependencies1) { ImportModuleData.insertModuleDependencyInstall(pool, (String) module.get("AD_MODULE_DEPENDENCY_ID"), (String) module.get("AD_MODULE_ID"), (String) module.get("AD_DEPENDENT_MODULE_ID"), (String) module.get("STARTVERSION"), (String) module.get("ENDVERSION"), (String) module.get("ISINCLUDED"), (String) module.get("DEPENDANT_MODULE_NAME")); } for (final DynaBean module : dbPrefix) { ImportModuleData.insertModuleDBPrefixInstall(pool, (String) module.get("AD_MODULE_DBPREFIX_ID"), (String) module.get("AD_MODULE_ID"), (String) module.get("NAME")); } conn.close(); }
From source file:org.openbravo.erpCommon.modules.ImportModule.java
/** * Returns all the modules and dependencies described within the obx file (as InputStream) * /* ww w . j a v a 2 s. co m*/ * Used to check dependencies in local installation * * @param dModulesToInstall * @param dDependencies * @param obx * @param merges * (output param) It contains all the merges defines in the obx as * (MergedModuleId,MergedBy) * @throws Exception */ private void getModulesFromObx(Vector<DynaBean> dModulesToInstall, Vector<DynaBean> dDependencies, Vector<DynaBean> dDBprefix, InputStream obx, Map<String, String> merges) throws Exception { final ZipInputStream obxInputStream = new ZipInputStream(obx); ZipEntry entry = null; boolean foundAll = false; boolean foundModule = false; boolean foundDependency = false; boolean foundPrefix = false; boolean foundMerge = false; while (((entry = obxInputStream.getNextEntry()) != null) && !foundAll) { if (entry.getName().endsWith(".obx")) { // If it is a new module, install it final ByteArrayInputStream ba = getCurrentEntryStream(obxInputStream); obxInputStream.closeEntry(); getModulesFromObx(dModulesToInstall, dDependencies, dDBprefix, ba, merges); } else if (entry.getName().replace("\\", "/").endsWith("src-db/database/sourcedata/AD_MODULE.xml")) { final Vector<DynaBean> module = getEntryDynaBeans(getBytesCurrentEntryStream(obxInputStream)); boolean isPackage = false; if (module != null && module.size() > 0) { isPackage = !((String) module.get(0).get("TYPE")).equals("M"); } dModulesToInstall.addAll(module); obxInputStream.closeEntry(); foundModule = true && !isPackage; } else if (entry.getName().replace("\\", "/") .endsWith("src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml")) { dDependencies.addAll(getEntryDynaBeans(getBytesCurrentEntryStream(obxInputStream))); obxInputStream.closeEntry(); foundDependency = true; } else if (entry.getName().replace("\\", "/") .endsWith("src-db/database/sourcedata/AD_MODULE_DBPREFIX.xml")) { dDBprefix.addAll(getEntryDynaBeans(getBytesCurrentEntryStream(obxInputStream))); obxInputStream.closeEntry(); foundPrefix = true; } else if (entry.getName().replace("\\", "/") .endsWith("/src-db/database/sourcedata/AD_MODULE_MERGE.xml")) { Vector<DynaBean> dynMerges = getEntryDynaBeans(getBytesCurrentEntryStream(obxInputStream)); for (DynaBean merge : dynMerges) { merges.put((String) merge.get("MERGED_MODULE_UUID"), (String) merge.get("AD_MODULE_ID")); } obxInputStream.closeEntry(); foundMerge = true; } else { obxInputStream.closeEntry(); } foundAll = foundModule && foundDependency && foundPrefix && foundMerge; } obxInputStream.close(); }
From source file:org.oscarehr.common.web.BillingreferralEditAction.java
public ActionForward searchByNo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {//from w w w . j ava 2 s . c o m DynaBean lazyForm = (DynaBean) form; String referralNo = (String) lazyForm.get("search"); List<Billingreferral> referrals = bDao.getBillingreferral(referralNo); request.setAttribute("referrals", referrals); request.setAttribute("searchBy", "searchByNo"); return mapping.findForward("list"); }