Search in sources :

Example 31 with Function

use of org.wso2.carbon.apimgt.core.models.Function in project carbon-business-process by wso2.

the class ActivitiEngineBuilder method setResolverFactories.

/**
 * Function to register resolver factories that used by script engines and JUEL
 * @param processEngineConfiguration
 */
private void setResolverFactories(ProcessEngineConfigurationImpl processEngineConfiguration) {
    List<ResolverFactory> resolverFactories = new ArrayList<>();
    // Resolvers from Activiti
    resolverFactories.add(new VariableScopeResolverFactory());
    resolverFactories.add(new BeansResolverFactory());
    // Resolvers added for WSO2 BPS
    resolverFactories.add(new XmlAPIResolverFactory());
    resolverFactories.add(new JsonAPIResolverFactory());
    processEngineConfiguration.setResolverFactories(resolverFactories);
}
Also used : JsonAPIResolverFactory(org.wso2.carbon.bpmn.core.types.datatypes.json.JsonAPIResolverFactory) XmlAPIResolverFactory(org.wso2.carbon.bpmn.core.types.datatypes.xml.XmlAPIResolverFactory) BeansResolverFactory(org.activiti.engine.impl.scripting.BeansResolverFactory) ArrayList(java.util.ArrayList) BeansResolverFactory(org.activiti.engine.impl.scripting.BeansResolverFactory) VariableScopeResolverFactory(org.activiti.engine.impl.scripting.VariableScopeResolverFactory) JsonAPIResolverFactory(org.wso2.carbon.bpmn.core.types.datatypes.json.JsonAPIResolverFactory) XmlAPIResolverFactory(org.wso2.carbon.bpmn.core.types.datatypes.xml.XmlAPIResolverFactory) ResolverFactory(org.activiti.engine.impl.scripting.ResolverFactory) VariableScopeResolverFactory(org.activiti.engine.impl.scripting.VariableScopeResolverFactory)

Example 32 with Function

use of org.wso2.carbon.apimgt.core.models.Function in project carbon-business-process by wso2.

the class JsonNodeObject method jsonPath.

/**
 * Function to evaluate jsonpath over JsonNodeObject
 * @param jsonPathStr jsonpath
 * @return returns the evaluation result. The returned Object can be a
 *                      com.fasterxml.jackson.databind.JsonNode (in case the result is json object)
 *                      com.fasterxml.jackson.databind.node.ArrayNode (in case the result is json array)
 *                      Or main primitive data types (String, Integer, Byte, Character, Short, Long, Float, Double, Boolean)
 *                 This function returns new Object representing the evaluation results, no a reference to a node
 * @throws IOException
 * @throws BPMNJsonException is thrown if the the resulting data type cannot be identified
 */
public Object jsonPath(String jsonPathStr) throws IOException, BPMNJsonException {
    ObjectMapper mapper = new ObjectMapper();
    Map map = mapper.convertValue(jsonNode, Map.class);
    Object result = JsonPath.read(map, jsonPathStr);
    JsonBuilder builder = new JsonBuilder(mapper);
    if (result instanceof Map) {
        // If the result is a Map, then it should be a json object
        return builder.createJsonNodeFromMap((Map<String, Object>) result);
    } else if (result instanceof List) {
        // when result is a list, then it should be a json array
        return builder.createJsonArrayFromMap((List<Object>) result);
    } else if (result == null || result instanceof String || result instanceof Integer || result instanceof Byte || result instanceof Character || result instanceof Short || result instanceof Long || result instanceof Float || result instanceof Double || result instanceof Boolean) {
        // If result is primitive data type, then return it as it is
        return result;
    } else {
        // Un-filtered data type, considered as unknown types
        throw new BPMNJsonException("Unknown type data type: " + result.getClass().getName() + " resulted while evaluating json path");
    }
}
Also used : BPMNJsonException(org.wso2.carbon.bpmn.core.types.datatypes.json.BPMNJsonException) List(java.util.List) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 33 with Function

use of org.wso2.carbon.apimgt.core.models.Function in project carbon-business-process by wso2.

the class AttachmentUploadExecutor method execute.

@Override
public boolean execute(HttpServletRequest request, HttpServletResponse response) throws IOException {
    PrintWriter out = response.getWriter();
    String webContext = (String) request.getAttribute(CarbonConstants.WEB_CONTEXT);
    String serverURL = (String) request.getAttribute(CarbonConstants.SERVER_URL);
    String cookie = (String) request.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
    Map<String, ArrayList<String>> formFieldsMap = getFormFieldsMap();
    String redirect = null;
    try {
        if (formFieldsMap.get("redirect") != null) {
            redirect = formFieldsMap.get("redirect").get(0);
        }
        ArrayList<FileItemData> fileItemsMap = getFileItemsMap().get("fileToUpload");
        FileItemData fileToBeUpload = fileItemsMap.get(0);
        if (fileItemsMap == null || fileItemsMap.isEmpty() || fileItemsMap.size() != 1) {
            String msg = "File uploading failed.";
            log.error(msg);
            out.write("<textarea>" + "(function(){i18n.fileUplodedFailed();})();" + "</textarea>");
            return true;
        }
        AttachmentUploadClient client = new AttachmentUploadClient(configurationContext, serverURL + "AttachmentMgtService", cookie);
        response.setContentType("text/html; charset=utf-8");
        client.addUploadedFileItem(fileToBeUpload);
        String msg = "Your attachment has been uploaded successfully. Please refresh this page in a while to see " + "the status of the new process.";
        if (redirect != null) {
            CarbonUIMessage.sendCarbonUIMessage(msg, CarbonUIMessage.INFO, request, response, getContextRoot(request) + "/" + webContext + "/" + redirect);
        } else {
            CarbonUIMessage.sendCarbonUIMessage(msg, CarbonUIMessage.INFO, request);
        }
        return true;
    } catch (Exception ex) {
        String errMsg = "File upload failed.";
        log.error(errMsg, ex);
        if (redirect != null) {
            CarbonUIMessage.sendCarbonUIMessage(errMsg, CarbonUIMessage.ERROR, request, response, getContextRoot(request) + "/" + webContext + "/" + redirect);
        } else {
            CarbonUIMessage.sendCarbonUIMessage(errMsg, CarbonUIMessage.ERROR, request);
        }
    }
    return false;
}
Also used : FileItemData(org.wso2.carbon.utils.FileItemData) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 34 with Function

use of org.wso2.carbon.apimgt.core.models.Function in project carbon-business-process by wso2.

the class HTRenderingApiImpl method getTaskDAO.

/**
 * Function to retrieve task DAO
 *
 * @param taskIdURI task ID
 * @return task DAO
 * @throws Exception
 * @throws IllegalArgumentException
 */
private TaskDAO getTaskDAO(URI taskIdURI) throws IllegalArgumentException, HumanTaskIllegalAccessException, Exception {
    final Long taskId = validateTaskId(taskIdURI);
    TaskDAO task = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<TaskDAO>() {

        public TaskDAO call() throws Exception {
            HumanTaskEngine engine = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine();
            HumanTaskDAOConnection daoConn = engine.getDaoConnectionFactory().getConnection();
            TaskDAO task = daoConn.getTask(taskId);
            validateTaskTenant(task);
            return task;
        }
    });
    return task;
}
Also used : HumanTaskEngine(org.wso2.carbon.humantask.core.engine.HumanTaskEngine) TaskDAO(org.wso2.carbon.humantask.core.dao.TaskDAO) HumanTaskDAOConnection(org.wso2.carbon.humantask.core.dao.HumanTaskDAOConnection) XPathExpressionException(javax.xml.xpath.XPathExpressionException) SetTaskOutputFaultException(org.wso2.carbon.humantask.rendering.api.SetTaskOutputFaultException) GetRenderingsFaultException(org.wso2.carbon.humantask.rendering.api.GetRenderingsFaultException) SAXException(org.xml.sax.SAXException) CompleteTaskFaultException(org.wso2.carbon.humantask.rendering.api.CompleteTaskFaultException) IOException(java.io.IOException) HumanTaskIllegalAccessException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException)

Example 35 with Function

use of org.wso2.carbon.apimgt.core.models.Function in project ballerina by ballerina-lang.

the class CommandExecutor method getDocumentEditForNode.

/**
 * Get the document edit attachment info for a given particular node.
 * @param node      Node given
 * @return          Doc Attachment Info
 */
private static CommandUtil.DocAttachmentInfo getDocumentEditForNode(Node node) {
    CommandUtil.DocAttachmentInfo docAttachmentInfo = null;
    int replaceFrom;
    switch(node.getKind()) {
        case FUNCTION:
            if (((BLangFunction) node).docAttachments.isEmpty()) {
                replaceFrom = CommonUtil.toZeroBasedPosition(((BLangFunction) node).getPosition()).getStartLine();
                docAttachmentInfo = CommandUtil.getFunctionNodeDocumentation((BLangFunction) node, replaceFrom);
            }
            break;
        case STRUCT:
            if (((BLangStruct) node).docAttachments.isEmpty()) {
                replaceFrom = CommonUtil.toZeroBasedPosition(((BLangStruct) node).getPosition()).getStartLine();
                docAttachmentInfo = CommandUtil.getStructNodeDocumentation((BLangStruct) node, replaceFrom);
            }
            break;
        case ENUM:
            if (((BLangEnum) node).docAttachments.isEmpty()) {
                replaceFrom = CommonUtil.toZeroBasedPosition(((BLangEnum) node).getPosition()).getStartLine();
                docAttachmentInfo = CommandUtil.getEnumNodeDocumentation((BLangEnum) node, replaceFrom);
            }
            break;
        case TRANSFORMER:
            if (((BLangTransformer) node).docAttachments.isEmpty()) {
                replaceFrom = CommonUtil.toZeroBasedPosition(((BLangTransformer) node).getPosition()).getStartLine();
                docAttachmentInfo = CommandUtil.getTransformerNodeDocumentation((BLangTransformer) node, replaceFrom);
            }
            break;
        case RESOURCE:
            if (((BLangResource) node).docAttachments.isEmpty()) {
                BLangResource bLangResource = (BLangResource) node;
                replaceFrom = getReplaceFromForServiceOrResource(bLangResource, bLangResource.getAnnotationAttachments());
                docAttachmentInfo = CommandUtil.getResourceNodeDocumentation(bLangResource, replaceFrom);
            }
            break;
        case SERVICE:
            if (((BLangService) node).docAttachments.isEmpty()) {
                BLangService bLangService = (BLangService) node;
                replaceFrom = getReplaceFromForServiceOrResource(bLangService, bLangService.getAnnotationAttachments());
                docAttachmentInfo = CommandUtil.getServiceNodeDocumentation(bLangService, replaceFrom);
            }
            break;
        default:
            break;
    }
    return docAttachmentInfo;
}
Also used : BLangTransformer(org.wso2.ballerinalang.compiler.tree.BLangTransformer) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) BLangEnum(org.wso2.ballerinalang.compiler.tree.BLangEnum)

Aggregations

Test (org.testng.annotations.Test)94 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)49 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)44 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)39 ArrayList (java.util.ArrayList)37 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)35 BString (org.ballerinalang.model.values.BString)30 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)29 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)26 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)25 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)20 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)20 BJSON (org.ballerinalang.model.values.BJSON)19 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)19 List (java.util.List)18 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)18 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)16 BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)15 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)14 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)14