Search in sources :

Example 31 with GeneralException

use of org.apache.ofbiz.base.util.GeneralException in project ofbiz-framework by apache.

the class ArtifactInfoFactory method prepareTaskForComponentAnalysis.

private Callable<Void> prepareTaskForComponentAnalysis(final ComponentConfig componentConfig) {
    return new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            String componentName = componentConfig.getGlobalName();
            String rootComponentPath = componentConfig.getRootLocation();
            List<File> screenFiles = new ArrayList<File>();
            List<File> formFiles = new ArrayList<File>();
            List<File> controllerFiles = new ArrayList<File>();
            try {
                screenFiles = FileUtil.findXmlFiles(rootComponentPath, null, "screens", "widget-screen.xsd");
            } catch (IOException ioe) {
                Debug.logWarning(ioe.getMessage(), module);
            }
            try {
                formFiles = FileUtil.findXmlFiles(rootComponentPath, null, "forms", "widget-form.xsd");
            } catch (IOException ioe) {
                Debug.logWarning(ioe.getMessage(), module);
            }
            try {
                controllerFiles = FileUtil.findXmlFiles(rootComponentPath, null, "site-conf", "site-conf.xsd");
            } catch (IOException ioe) {
                Debug.logWarning(ioe.getMessage(), module);
            }
            for (File screenFile : screenFiles) {
                String screenFilePath = screenFile.getAbsolutePath();
                screenFilePath = screenFilePath.replace('\\', '/');
                String screenFileRelativePath = screenFilePath.substring(rootComponentPath.length());
                String screenLocation = "component://" + componentName + "/" + screenFileRelativePath;
                Map<String, ModelScreen> modelScreenMap = null;
                try {
                    modelScreenMap = ScreenFactory.getScreensFromLocation(screenLocation);
                } catch (Exception exc) {
                    Debug.logWarning(exc.getMessage(), module);
                }
                for (String screenName : modelScreenMap.keySet()) {
                    getScreenWidgetArtifactInfo(screenName, screenLocation);
                }
            }
            for (File formFile : formFiles) {
                String formFilePath = formFile.getAbsolutePath();
                formFilePath = formFilePath.replace('\\', '/');
                String formFileRelativePath = formFilePath.substring(rootComponentPath.length());
                String formLocation = "component://" + componentName + "/" + formFileRelativePath;
                Map<String, ModelForm> modelFormMap = null;
                try {
                    modelFormMap = FormFactory.getFormsFromLocation(formLocation, getEntityModelReader(), getDispatchContext());
                } catch (Exception exc) {
                    Debug.logWarning(exc.getMessage(), module);
                }
                for (String formName : modelFormMap.keySet()) {
                    try {
                        getFormWidgetArtifactInfo(formName, formLocation);
                    } catch (GeneralException ge) {
                        Debug.logWarning(ge.getMessage(), module);
                    }
                }
            }
            for (File controllerFile : controllerFiles) {
                URL controllerUrl = null;
                try {
                    controllerUrl = controllerFile.toURI().toURL();
                } catch (MalformedURLException mue) {
                    Debug.logWarning(mue.getMessage(), module);
                }
                if (controllerUrl == null)
                    continue;
                ControllerConfig cc = ConfigXMLReader.getControllerConfig(controllerUrl);
                for (String requestUri : cc.getRequestMapMap().keySet()) {
                    try {
                        getControllerRequestArtifactInfo(controllerUrl, requestUri);
                    } catch (GeneralException e) {
                        Debug.logWarning(e.getMessage(), module);
                    }
                }
                for (String viewUri : cc.getViewMapMap().keySet()) {
                    try {
                        getControllerViewArtifactInfo(controllerUrl, viewUri);
                    } catch (GeneralException e) {
                        Debug.logWarning(e.getMessage(), module);
                    }
                }
            }
            return null;
        }
    };
}
Also used : MalformedURLException(java.net.MalformedURLException) ControllerConfig(org.apache.ofbiz.webapp.control.ConfigXMLReader.ControllerConfig) GeneralException(org.apache.ofbiz.base.util.GeneralException) ArrayList(java.util.ArrayList) ModelScreen(org.apache.ofbiz.widget.model.ModelScreen) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) WebAppConfigurationException(org.apache.ofbiz.webapp.control.WebAppConfigurationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) SAXException(org.xml.sax.SAXException) GeneralException(org.apache.ofbiz.base.util.GeneralException) URL(java.net.URL) File(java.io.File) ModelForm(org.apache.ofbiz.widget.model.ModelForm)

Example 32 with GeneralException

use of org.apache.ofbiz.base.util.GeneralException in project ofbiz-framework by apache.

the class FormWidgetArtifactInfo method populateAll.

/**
 * note this is mean to be called after the object is created and added to the ArtifactInfoFactory.allFormInfos in ArtifactInfoFactory.getFormWidgetArtifactInfo
 */
public void populateAll() throws GeneralException {
    ArtifactInfoContext infoContext = new ArtifactInfoContext();
    ArtifactInfoGatherer infoGatherer = new ArtifactInfoGatherer(infoContext);
    try {
        if (this.modelForm instanceof ModelSingleForm) {
            infoGatherer.visit((ModelSingleForm) this.modelForm);
        } else {
            infoGatherer.visit((ModelGrid) this.modelForm);
        }
    } catch (Exception e) {
        throw new GeneralException(e);
    }
    populateEntitiesFromNameSet(infoContext.getEntityNames());
    populateServicesFromNameSet(infoContext.getServiceNames());
    this.populateFormExtended();
    this.populateLinkedRequests(infoContext.getRequestLocations());
    this.populateTargetedRequests(infoContext.getTargetLocations());
}
Also used : ArtifactInfoGatherer(org.apache.ofbiz.widget.artifact.ArtifactInfoGatherer) GeneralException(org.apache.ofbiz.base.util.GeneralException) ArtifactInfoContext(org.apache.ofbiz.widget.artifact.ArtifactInfoContext) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) GeneralException(org.apache.ofbiz.base.util.GeneralException) ModelSingleForm(org.apache.ofbiz.widget.model.ModelSingleForm)

Example 33 with GeneralException

use of org.apache.ofbiz.base.util.GeneralException in project ofbiz-framework by apache.

the class ScreenWidgetArtifactInfo method populateAll.

public void populateAll() throws GeneralException {
    ArtifactInfoContext infoContext = new ArtifactInfoContext();
    ArtifactInfoGatherer infoGatherer = new ArtifactInfoGatherer(infoContext);
    try {
        infoGatherer.visit(this.modelScreen);
    } catch (Exception e) {
        throw new GeneralException(e);
    }
    populateServicesFromNameSet(infoContext.getServiceNames());
    populateEntitiesFromNameSet(infoContext.getEntityNames());
    populateFormsFromNameSet(infoContext.getFormLocations());
    populateLinkedRequests(infoContext.getRequestLocations());
}
Also used : ArtifactInfoGatherer(org.apache.ofbiz.widget.artifact.ArtifactInfoGatherer) GeneralException(org.apache.ofbiz.base.util.GeneralException) ArtifactInfoContext(org.apache.ofbiz.widget.artifact.ArtifactInfoContext) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) GeneralException(org.apache.ofbiz.base.util.GeneralException)

Example 34 with GeneralException

use of org.apache.ofbiz.base.util.GeneralException in project ofbiz-framework by apache.

the class ModelTestSuite method parseTestElement.

private void parseTestElement(String caseName, Element testElement) {
    String nodeName = testElement.getNodeName();
    if ("junit-test-suite".equals(nodeName)) {
        String className = testElement.getAttribute("class-name");
        try {
            @SuppressWarnings("unchecked") Class<? extends TestCase> clz = (Class<? extends TestCase>) ObjectType.loadClass(className);
            TestSuite suite = new TestSuite();
            suite.addTestSuite(clz);
            Enumeration<?> testEnum = suite.tests();
            int testsAdded = 0;
            int casesAdded = 0;
            while (testEnum.hasMoreElements()) {
                Test tst = (Test) testEnum.nextElement();
                this.testList.add(tst);
                casesAdded += tst.countTestCases();
                testsAdded++;
            }
            Debug.logInfo("Added " + testsAdded + " tests [" + casesAdded + " cases] from the class: " + className, module);
        } catch (Exception e) {
            String errMsg = "Unable to load test suite class : " + className;
            Debug.logError(e, errMsg, module);
        }
    } else if ("groovy-test-suite".equals(nodeName)) {
        try {
            Class testClass = GroovyUtil.getScriptClassFromLocation(testElement.getAttribute("location"));
            TestCase groovyTestCase = (GroovyScriptTestCase) testClass.newInstance();
            this.testList.add(new TestSuite(testClass, testElement.getAttribute("name")));
        } catch (GeneralException | InstantiationException | IllegalAccessException e) {
            Debug.logError(e, module);
        }
    } else if ("service-test".equals(nodeName)) {
        this.testList.add(new ServiceTest(caseName, testElement));
    } else if ("simple-method-test".equals(nodeName)) {
        if (UtilValidate.isNotEmpty(testElement.getAttribute("name"))) {
            this.testList.add(new SimpleMethodTest(caseName, testElement));
        } else {
            String methodLocation = testElement.getAttribute("location");
            List<SimpleMethod> simpleMethods;
            try {
                simpleMethods = SimpleMethod.getSimpleMethodsList(methodLocation, null);
                for (SimpleMethod simpleMethod : simpleMethods) {
                    String methodName = simpleMethod.getMethodName();
                    if (methodName.startsWith("test")) {
                        this.testList.add(new SimpleMethodTest(caseName + "." + methodName, methodLocation, methodName));
                    }
                }
            } catch (MiniLangException e) {
                Debug.logError(e, module);
            }
        }
    } else if ("webdriver-test".equals(nodeName)) {
        try {
            String className = "org.apache.ofbiz.testtools.WebDriverTest";
            Class<?> cl;
            cl = Class.forName(className);
            Constructor<?> con = cl.getConstructor(String.class, Element.class);
            this.testList.add((Test) con.newInstance(caseName, testElement));
        } catch (Exception e) {
            Debug.logError(e, module);
        }
    } else if ("entity-xml".equals(nodeName)) {
        this.testList.add(new EntityXmlAssertTest(caseName, testElement));
    } else if ("entity-xml-assert".equals(nodeName)) {
        // this is the old, deprecated name for the element, changed because it now does assert or load
        this.testList.add(new EntityXmlAssertTest(caseName, testElement));
    }
}
Also used : SimpleMethod(org.apache.ofbiz.minilang.SimpleMethod) MiniLangException(org.apache.ofbiz.minilang.MiniLangException) GeneralException(org.apache.ofbiz.base.util.GeneralException) TestSuite(junit.framework.TestSuite) EntityTestCase(org.apache.ofbiz.entity.testtools.EntityTestCase) TestCase(junit.framework.TestCase) OFBizTestCase(org.apache.ofbiz.service.testtools.OFBizTestCase) Test(junit.framework.Test) MiniLangException(org.apache.ofbiz.minilang.MiniLangException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 35 with GeneralException

use of org.apache.ofbiz.base.util.GeneralException in project ofbiz-framework by apache.

the class GiftCertificateServices method addFundsToGiftCertificate.

public static Map<String, Object> addFundsToGiftCertificate(DispatchContext dctx, Map<String, ? extends Object> context) {
    LocalDispatcher dispatcher = dctx.getDispatcher();
    Delegator delegator = dctx.getDelegator();
    Locale locale = (Locale) context.get("locale");
    final String deposit = "DEPOSIT";
    GenericValue userLogin = (GenericValue) context.get("userLogin");
    String productStoreId = (String) context.get("productStoreId");
    String cardNumber = (String) context.get("cardNumber");
    String pinNumber = (String) context.get("pinNumber");
    BigDecimal amount = (BigDecimal) context.get("amount");
    String partyId = (String) context.get("partyId");
    if (UtilValidate.isEmpty(partyId)) {
        partyId = "_NA_";
    }
    String currencyUom = (String) context.get("currency");
    if (UtilValidate.isEmpty(currencyUom)) {
        currencyUom = EntityUtilProperties.getPropertyValue("general", "currency.uom.id.default", "USD", delegator);
    }
    String finAccountId = null;
    GenericValue finAccount = null;
    // validate the pin if the store requires it and figure out the finAccountId from card number
    try {
        GenericValue giftCertSettings = EntityQuery.use(delegator).from("ProductStoreFinActSetting").where("productStoreId", productStoreId, "finAccountTypeId", FinAccountHelper.giftCertFinAccountTypeId).cache().queryOne();
        if ("Y".equals(giftCertSettings.getString("requirePinCode"))) {
            if (!validatePin(delegator, cardNumber, pinNumber)) {
                return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "AccountingGiftCerticateNumberPinNotValid", locale));
            }
            finAccountId = cardNumber;
        } else {
            finAccount = FinAccountHelper.getFinAccountFromCode(cardNumber, delegator);
            if (finAccount != null) {
                finAccountId = finAccount.getString("finAccountId");
            }
        }
    } catch (GenericEntityException e) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "AccountingFinAccountSetting", UtilMisc.toMap("productStoreId", productStoreId, "finAccountTypeId", FinAccountHelper.giftCertFinAccountTypeId), locale));
    }
    if (finAccountId == null) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "AccountingFinAccountNotFound", UtilMisc.toMap("finAccountId", ""), locale));
    }
    if (finAccount == null) {
        try {
            finAccount = EntityQuery.use(delegator).from("FinAccount").where("finAccountId", finAccountId).queryOne();
        } catch (GenericEntityException e) {
            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "AccountingFinAccountNotFound", UtilMisc.toMap("finAccountId", finAccountId), locale));
        }
    }
    // get the previous balance
    BigDecimal previousBalance = BigDecimal.ZERO;
    if (finAccount.get("availableBalance") != null) {
        previousBalance = finAccount.getBigDecimal("availableBalance");
    }
    // create the transaction
    BigDecimal balance = BigDecimal.ZERO;
    String refNum = null;
    try {
        refNum = GiftCertificateServices.createTransaction(delegator, dispatcher, userLogin, amount, productStoreId, partyId, currencyUom, deposit, finAccountId, locale);
        finAccount.refresh();
        balance = finAccount.getBigDecimal("availableBalance");
    } catch (GeneralException e) {
        Debug.logError(e, module);
        return ServiceUtil.returnError(e.getMessage());
    }
    Map<String, Object> result = ServiceUtil.returnSuccess();
    result.put("previousBalance", previousBalance);
    result.put("balance", balance);
    result.put("amount", amount);
    result.put("processResult", Boolean.TRUE);
    result.put("responseCode", "1");
    result.put("referenceNum", refNum);
    Debug.logInfo("Add Funds GC Result - " + result, module);
    return result;
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) LocalDispatcher(org.apache.ofbiz.service.LocalDispatcher) GeneralException(org.apache.ofbiz.base.util.GeneralException) Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) BigDecimal(java.math.BigDecimal)

Aggregations

GeneralException (org.apache.ofbiz.base.util.GeneralException)216 GenericValue (org.apache.ofbiz.entity.GenericValue)133 Delegator (org.apache.ofbiz.entity.Delegator)101 Locale (java.util.Locale)81 HashMap (java.util.HashMap)71 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)68 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)68 IOException (java.io.IOException)65 BigDecimal (java.math.BigDecimal)55 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)54 Writer (java.io.Writer)29 LinkedList (java.util.LinkedList)29 Map (java.util.Map)29 Timestamp (java.sql.Timestamp)26 StringWriter (java.io.StringWriter)19 Environment (freemarker.core.Environment)15 HttpServletRequest (javax.servlet.http.HttpServletRequest)14 ShoppingCart (org.apache.ofbiz.order.shoppingcart.ShoppingCart)14 HttpSession (javax.servlet.http.HttpSession)13 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)13