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;
}
};
}
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());
}
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());
}
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));
}
}
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;
}
Aggregations