use of org.apache.ofbiz.minilang.MiniLangException 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.minilang.MiniLangException in project ofbiz-framework by apache.
the class UploadContentAndImage method processContentUpload.
public static String processContentUpload(Map<String, Object> passedParams, String suffix, HttpServletRequest request) throws GenericServiceException {
LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
Delegator delegator = (Delegator) request.getAttribute("delegator");
HttpSession session = request.getSession();
GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");
Map<String, Object> ftlContext = new HashMap<String, Object>();
String contentPurposeString = (String) passedParams.get("contentPurposeString" + suffix);
if (UtilValidate.isEmpty(contentPurposeString)) {
contentPurposeString = (String) passedParams.get("contentPurposeString");
}
List<String> contentPurposeList = StringUtil.split(contentPurposeString, "|");
ftlContext.put("contentPurposeList", contentPurposeList);
String targetOperationString = (String) passedParams.get("targetOperationString" + suffix);
if (UtilValidate.isEmpty(targetOperationString)) {
targetOperationString = (String) passedParams.get("targetOperationString");
}
List<String> targetOperationList = StringUtil.split(targetOperationString, "|");
ftlContext.put("targetOperationList", targetOperationList);
ftlContext.put("userLogin", userLogin);
Object objSequenceNum = passedParams.get("caSequenceNum");
if (objSequenceNum != null) {
if (objSequenceNum instanceof String) {
Long sequenceNum = null;
try {
sequenceNum = Long.valueOf((String) objSequenceNum);
} catch (NumberFormatException e) {
String msg = "Caught an exception : " + e.toString();
Debug.logError(e, msg);
request.setAttribute("_ERROR_MESSAGE_", msg);
List<String> errorMsgList = UtilGenerics.checkList(request.getAttribute("_EVENT_MESSAGE_LIST_"));
if (errorMsgList == null) {
errorMsgList = new LinkedList<String>();
request.setAttribute("errorMessageList", errorMsgList);
}
errorMsgList.add(msg);
return "error";
}
passedParams.put("caSequenceNum", sequenceNum);
}
}
ModelEntity modelEntity = delegator.getModelEntity("ContentAssocDataResourceViewFrom");
List<String> fieldNames = modelEntity.getAllFieldNames();
Map<String, Object> ftlContext2 = new HashMap<String, Object>();
Map<String, Object> ftlContext3 = new HashMap<String, Object>();
for (String keyName : fieldNames) {
Object obj = passedParams.get(keyName + suffix);
ftlContext2.put(keyName, obj);
}
if (Debug.infoOn()) {
Debug.logInfo("[UploadContentStuff]ftlContext2:" + ftlContext2, module);
}
List<Object> errorMessages = new LinkedList<Object>();
Locale loc = Locale.getDefault();
try {
SimpleMapProcessor.runSimpleMapProcessor("component://content/minilang/ContentManagementMapProcessors.xml", "contentIn", ftlContext2, ftlContext3, errorMessages, loc);
SimpleMapProcessor.runSimpleMapProcessor("component://content/minilang/ContentManagementMapProcessors.xml", "contentOut", ftlContext3, ftlContext, errorMessages, loc);
ftlContext3 = new HashMap<String, Object>();
SimpleMapProcessor.runSimpleMapProcessor("component://content/minilang/ContentManagementMapProcessors.xml", "dataResourceIn", ftlContext2, ftlContext3, errorMessages, loc);
SimpleMapProcessor.runSimpleMapProcessor("component://content/minilang/ContentManagementMapProcessors.xml", "dataResourceOut", ftlContext3, ftlContext, errorMessages, loc);
ftlContext3 = new HashMap<String, Object>();
SimpleMapProcessor.runSimpleMapProcessor("component://content/minilang/ContentManagementMapProcessors.xml", "contentAssocIn", ftlContext2, ftlContext3, errorMessages, loc);
SimpleMapProcessor.runSimpleMapProcessor("component://content/minilang/ContentManagementMapProcessors.xml", "contentAssocOut", ftlContext3, ftlContext, errorMessages, loc);
} catch (MiniLangException e) {
throw new GenericServiceException(e.getMessage());
}
ftlContext.put("textData", passedParams.get("textData" + suffix));
byte[] bytes = (byte[]) passedParams.get("imageData" + suffix);
ftlContext.put("imageData", bytes);
if (Debug.infoOn()) {
Debug.logInfo("[UploadContentStuff]ftlContext:" + ftlContext, module);
}
Map<String, Object> ftlResults = null;
try {
ftlResults = dispatcher.runSync("persistContentAndAssoc", ftlContext);
} catch (ServiceAuthException e) {
String msg = e.getMessage();
request.setAttribute("_ERROR_MESSAGE_", msg);
List<String> errorMsgList = UtilGenerics.checkList(request.getAttribute("_EVENT_MESSAGE_LIST_"));
if (Debug.infoOn()) {
Debug.logInfo("[UploadContentStuff]errorMsgList:" + errorMsgList, module);
}
if (Debug.infoOn()) {
Debug.logInfo("[UploadContentStuff]msg:" + msg, module);
}
if (errorMsgList == null) {
errorMsgList = new LinkedList<String>();
request.setAttribute("errorMessageList", errorMsgList);
}
errorMsgList.add(msg);
return "error";
}
if (ServiceUtil.isError(ftlResults)) {
String msg = ServiceUtil.getErrorMessage(ftlResults);
request.setAttribute("_ERROR_MESSAGE_", msg);
List<String> errorMsgList = UtilGenerics.checkList(request.getAttribute("_EVENT_MESSAGE_LIST_"));
if (errorMsgList == null) {
errorMsgList = new LinkedList<String>();
request.setAttribute("errorMessageList", errorMsgList);
}
errorMsgList.add(msg);
return "error";
}
String returnedContentId = (String) ftlResults.get("contentId");
if (Debug.infoOn()) {
Debug.logInfo("returnedContentId:" + returnedContentId, module);
}
request.setAttribute("contentId" + suffix, ftlResults.get("contentId"));
request.setAttribute("caContentIdTo" + suffix, ftlResults.get("contentIdTo"));
request.setAttribute("caContentIdStart" + suffix, ftlResults.get("contentIdTo"));
request.setAttribute("caContentAssocTypeId" + suffix, ftlResults.get("contentAssocTypeId"));
request.setAttribute("caFromDate" + suffix, ftlResults.get("fromDate"));
request.setAttribute("drDataResourceId" + suffix, ftlResults.get("dataResourceId"));
request.setAttribute("caContentId" + suffix, ftlResults.get("contentId"));
String caContentIdTo = (String) passedParams.get("caContentIdTo");
if (UtilValidate.isNotEmpty(caContentIdTo)) {
Map<String, Object> resequenceContext = new HashMap<String, Object>();
resequenceContext.put("contentIdTo", caContentIdTo);
resequenceContext.put("userLogin", userLogin);
try {
ftlResults = dispatcher.runSync("resequence", resequenceContext);
if (ServiceUtil.isError(ftlResults)) {
String errorMessage = ServiceUtil.getErrorMessage(ftlResults);
request.setAttribute("_ERROR_MESSAGE_", errorMessage);
Debug.logError(errorMessage, module);
return "error";
}
} catch (ServiceAuthException e) {
String msg = e.getMessage();
request.setAttribute("_ERROR_MESSAGE_", msg);
List<String> errorMsgList = UtilGenerics.checkList(request.getAttribute("_EVENT_MESSAGE_LIST_"));
if (Debug.infoOn()) {
Debug.logInfo("[UploadContentStuff]errorMsgList:" + errorMsgList, module);
}
if (Debug.infoOn()) {
Debug.logInfo("[UploadContentStuff]msg:" + msg, module);
}
if (errorMsgList == null) {
errorMsgList = new LinkedList<String>();
request.setAttribute("errorMessageList", errorMsgList);
}
errorMsgList.add(msg);
return "error";
}
}
return "success";
}
use of org.apache.ofbiz.minilang.MiniLangException in project ofbiz-framework by apache.
the class ContentWorker method selectKids.
public static void selectKids(Map<String, Object> currentNode, Map<String, Object> ctx) {
Delegator delegator = (Delegator) ctx.get("delegator");
GenericValue parentContent = (GenericValue) currentNode.get("value");
String contentAssocTypeId = (String) ctx.get("contentAssocTypeId");
String contentTypeId = (String) ctx.get("contentTypeId");
String mapKey = (String) ctx.get("mapKey");
String parentContentId = (String) parentContent.get("contentId");
Map<String, Object> whenMap = UtilGenerics.checkMap(ctx.get("whenMap"));
List<Map<String, Object>> kids = new LinkedList<Map<String, Object>>();
currentNode.put("kids", kids);
String direction = (String) ctx.get("direction");
if (UtilValidate.isEmpty(direction)) {
direction = "From";
}
List<String> assocTypeList = StringUtil.split(contentAssocTypeId, " ");
List<String> contentTypeList = StringUtil.split(contentTypeId, " ");
String contentAssocPredicateId = null;
Boolean nullThruDatesOnly = Boolean.TRUE;
Map<String, Object> results = null;
try {
results = ContentServicesComplex.getAssocAndContentAndDataResourceCacheMethod(delegator, parentContentId, mapKey, direction, null, null, assocTypeList, contentTypeList, nullThruDatesOnly, contentAssocPredicateId, null);
} catch (GenericEntityException e) {
throw new RuntimeException(e.getMessage());
} catch (MiniLangException e2) {
throw new RuntimeException(e2.getMessage());
}
List<GenericValue> relatedViews = UtilGenerics.checkList(results.get("entityList"));
for (GenericValue assocValue : relatedViews) {
Map<String, Object> thisNode = ContentWorker.makeNode(assocValue);
checkConditions(delegator, thisNode, null, whenMap);
boolean isPick = booleanDataType(thisNode.get("isPick"));
kids.add(thisNode);
if (isPick) {
Integer count = (Integer) currentNode.get("count");
if (count == null) {
count = Integer.valueOf(1);
} else {
count = Integer.valueOf(count.intValue() + 1);
}
currentNode.put("count", count);
}
}
}
use of org.apache.ofbiz.minilang.MiniLangException in project ofbiz-framework by apache.
the class ContentWorker method checkConditions.
public static void checkConditions(Delegator delegator, Map<String, Object> trailNode, Map<String, Object> contentAssoc, Map<String, Object> whenMap) {
Map<String, Object> context = new HashMap<String, Object>();
GenericValue content = (GenericValue) trailNode.get("value");
if (content != null) {
context.put("content", content);
List<Object> purposes = getPurposes(content);
context.put("purposes", purposes);
List<Object> sections = getSections(content);
context.put("sections", sections);
List<Object> topics = getTopics(content);
context.put("topics", topics);
String contentTypeId = (String) content.get("contentTypeId");
List<String> contentTypeAncestry = new LinkedList<String>();
try {
getContentTypeAncestry(delegator, contentTypeId, contentTypeAncestry);
} catch (GenericEntityException e) {
Debug.logError(e.getMessage(), module);
}
context.put("typeAncestry", contentTypeAncestry);
if (contentAssoc == null && (content.getEntityName().indexOf("Assoc") >= 0)) {
contentAssoc = delegator.makeValue("ContentAssoc");
try {
// TODO: locale needs to be gotten correctly
SimpleMapProcessor.runSimpleMapProcessor("component://content/minilang/ContentManagementMapProcessors.xml", "contentAssocIn", content, contentAssoc, new LinkedList<Object>(), Locale.getDefault());
context.put("contentAssocTypeId", contentAssoc.get("contentAssocTypeId"));
context.put("contentAssocPredicateId", contentAssoc.get("contentAssocPredicateId"));
context.put("mapKey", contentAssoc.get("mapKey"));
} catch (MiniLangException e) {
Debug.logError(e.getMessage(), module);
}
} else {
context.put("contentAssocTypeId", null);
context.put("contentAssocPredicateId", null);
context.put("mapKey", null);
}
}
boolean isReturnBefore = checkWhen(context, (String) whenMap.get("returnBeforePickWhen"), false);
trailNode.put("isReturnBefore", Boolean.valueOf(isReturnBefore));
boolean isPick = checkWhen(context, (String) whenMap.get("pickWhen"), true);
trailNode.put("isPick", Boolean.valueOf(isPick));
boolean isFollow = checkWhen(context, (String) whenMap.get("followWhen"), true);
trailNode.put("isFollow", Boolean.valueOf(isFollow));
boolean isReturnAfter = checkWhen(context, (String) whenMap.get("returnAfterPickWhen"), false);
trailNode.put("isReturnAfter", Boolean.valueOf(isReturnAfter));
trailNode.put("checked", Boolean.TRUE);
}
use of org.apache.ofbiz.minilang.MiniLangException in project ofbiz-framework by apache.
the class LayoutEvents method createLayoutSubContent.
public static String createLayoutSubContent(HttpServletRequest request, HttpServletResponse response) {
try {
LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
HttpSession session = request.getSession();
Map<String, Object> paramMap = UtilHttp.getParameterMap(request);
String contentIdTo = (String) paramMap.get("contentIdTo");
String mapKey = (String) paramMap.get("mapKey");
if (Debug.verboseOn()) {
Debug.logVerbose("in createSubContent, contentIdTo:" + contentIdTo, module);
Debug.logVerbose("in createSubContent, mapKey:" + mapKey, module);
}
Map<String, Object> context = new HashMap<String, Object>();
List<Object> errorMessages = new LinkedList<>();
Locale loc = (Locale) request.getSession().getServletContext().getAttribute("locale");
if (loc == null) {
loc = Locale.getDefault();
}
GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");
context.put("userLogin", userLogin);
String rootDir = request.getSession().getServletContext().getRealPath("/");
context.put("rootDir", rootDir);
try {
SimpleMapProcessor.runSimpleMapProcessor("component://content/minilang/ContentManagementMapProcessors.xml", "contentIn", paramMap, context, errorMessages, loc);
SimpleMapProcessor.runSimpleMapProcessor("component://content/minilang/ContentManagementMapProcessors.xml", "dataResourceIn", paramMap, context, errorMessages, loc);
SimpleMapProcessor.runSimpleMapProcessor("component://content/minilang/ContentManagementMapProcessors.xml", "contentAssocIn", paramMap, context, errorMessages, loc);
} catch (MiniLangException e) {
request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
return "error";
}
context.put("dataResourceName", context.get("contentName"));
String contentPurposeTypeId = (String) paramMap.get("contentPurposeTypeId");
if (UtilValidate.isNotEmpty(contentPurposeTypeId)) {
context.put("contentPurposeList", UtilMisc.toList(contentPurposeTypeId));
}
context.put("contentIdTo", paramMap.get("contentIdTo"));
context.put("mapKey", paramMap.get("mapKey"));
context.put("textData", paramMap.get("textData"));
context.put("contentAssocTypeId", "SUB_CONTENT");
if (Debug.verboseOn()) {
Debug.logVerbose("in createSubContent, context:" + context, module);
}
Map<String, Object> result = dispatcher.runSync("persistContentAndAssoc", context);
if (ServiceUtil.isError(result)) {
String errorMessage = ServiceUtil.getErrorMessage(result);
request.setAttribute("_ERROR_MESSAGE_", errorMessage);
Debug.logError(errorMessage, module);
return "error";
}
if (Debug.verboseOn()) {
Debug.logVerbose("in createLayoutFile, result:" + result, module);
}
String contentId = (String) result.get("contentId");
String dataResourceId = (String) result.get("dataResourceId");
request.setAttribute("contentId", contentId);
request.setAttribute("drDataResourceId", dataResourceId);
request.setAttribute("currentEntityName", "SubContentDataResourceId");
Map<String, Object> context2 = new HashMap<String, Object>();
context2.put("activeContentId", contentId);
context2.put("contentAssocTypeId", "SUB_CONTENT");
context2.put("fromDate", result.get("fromDate"));
context2.put("contentIdTo", contentIdTo);
context2.put("mapKey", mapKey);
context2.put("userLogin", userLogin);
Map<String, Object> serviceResult = new HashMap<String, Object>();
serviceResult = dispatcher.runSync("deactivateAssocs", context2);
if (ServiceUtil.isError(serviceResult)) {
String errorMessage = ServiceUtil.getErrorMessage(serviceResult);
request.setAttribute("_ERROR_MESSAGE_", errorMessage);
Debug.logError(errorMessage, module);
return "error";
}
} catch (GenericServiceException e) {
request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
return "error";
}
return "success";
}
Aggregations