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