use of org.wso2.carbon.apimgt.core.models.Function in project ballerina by ballerina-lang.
the class HtmlDocTest method testFunctionsWithoutStructBindings.
@Test(description = "One function without a struct bindings in a package should not be grouped together with the" + "structs shown in the constructs")
public void testFunctionsWithoutStructBindings() throws Exception {
BLangPackage bLangPackage = createPackage("package x.y; " + "public function hello(){} " + "public struct Message { string message; int id;}");
Page page = generatePage(bLangPackage);
Assert.assertEquals(page.constructs.size(), 2);
Assert.assertEquals(page.constructs.get(0).name, "Message");
Assert.assertEquals(page.constructs.get(1).name, "hello");
}
use of org.wso2.carbon.apimgt.core.models.Function in project ballerina by ballerina-lang.
the class HtmlDocTest method testFunctionsWithStructBindings.
@Test(description = "One function with a struct bindings in a package should be grouped together shown in the " + "constructs")
public void testFunctionsWithStructBindings() throws Exception {
BLangPackage bLangPackage = createPackage("package x.y; " + "public function <Message m>hello(){} " + "public struct Message { string message; int id;}");
Page page = generatePage(bLangPackage);
Assert.assertEquals(page.constructs.size(), 1);
Assert.assertEquals(page.constructs.get(0).name, "Message");
Assert.assertEquals(page.constructs.get(0).children.get(0).name, "hello");
}
use of org.wso2.carbon.apimgt.core.models.Function in project carbon-business-process by wso2.
the class XMLDocument method set.
/**
* Function to set/replace/update an object (String / Element) to matching the xPath provided. (In case new element
* is added, this api will clone it and merge the new node to the target location pointed by xPath and return the new cloned node)
*
* @param xPathStr xPath to the location object need to set
* @param obj String or Node
* @return returns the node get updated when the set object is String, or returns newly added Node in case object is Element
* @throws XPathExpressionException If expression cannot be evaluated
* @throws BPMNXmlException is thrown due to : Provided XPath and object does not match, provided object is not a Node or String
* result is NodeList, not a Text node or Element
*/
public Node set(String xPathStr, Object obj) throws XPathExpressionException, BPMNXmlException {
NodeList evalResult = (NodeList) Utils.evaluateXPath(this.doc, xPathStr, XPathConstants.NODESET);
if (evalResult.getLength() == 1) {
Node targetNode = evalResult.item(0);
if (obj instanceof String && targetNode instanceof Text) {
// if string is provided, assume that user
// need to replace the node value
targetNode.setNodeValue((String) obj);
// return updated Text Node
return targetNode;
} else if ((obj instanceof Integer || obj instanceof Byte || obj instanceof Character || obj instanceof Short || obj instanceof Long || obj instanceof Float || obj instanceof Double || obj instanceof Boolean) && targetNode instanceof Text) {
// need to replace the node value
targetNode.setNodeValue(obj.toString());
// return updated Text Node
return targetNode;
} else if (obj instanceof Element && targetNode instanceof Element && targetNode.getParentNode() != null) {
// if the user provides Node object,
// assume that need to replace the target node
Node targetParent = targetNode.getParentNode();
Node nextSibling = targetNode.getNextSibling();
// remove the target node
targetParent.removeChild(targetNode);
// add new node
Node newNode = doc.importNode((Node) obj, true);
if (nextSibling != null) {
// If next sibling exists we have to put the new node before it
targetParent.insertBefore(newNode, nextSibling);
} else {
targetParent.appendChild(newNode);
}
// return new node
return newNode;
} else {
// provided XPath and object to set does not match
throw new BPMNXmlException("Provided XPath and provided object does not match");
}
} else if (evalResult.getLength() > 0) {
throw new BPMNXmlException("Error in provided xPath. Evaluation result is NodeList, not a Text node or Element");
} else {
throw new BPMNXmlException("Error in provided xPath. Evaluation result is not a Text node or Element");
}
}
use of org.wso2.carbon.apimgt.core.models.Function in project carbon-business-process by wso2.
the class BPELUploadExecutor method execute.
public boolean execute(HttpServletRequest request, HttpServletResponse response) throws CarbonException, IOException {
String errMsg;
response.setContentType("text/html; charset=utf-8");
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<FileItemData>> fileItemsMap = getFileItemsMap();
if (fileItemsMap == null || fileItemsMap.isEmpty()) {
String msg = "File uploading failed.";
log.error(msg);
out.write("<textarea>" + "(function(){i18n.fileUplodedFailed();})();" + "</textarea>");
return true;
}
BPELUploaderClient uploaderClient = new BPELUploaderClient(configurationContext, serverURL + "BPELUploader", cookie);
SaveExtractReturn uploadedFiles = null;
ArrayList<String> extractedFiles = new ArrayList<String>();
try {
for (FileItemData fieldData : fileItemsMap.get("bpelFileName")) {
String fileName = getFileName(fieldData.getFileItem().getName());
// Check filename for \ charactors. This cannot be handled at the lower stages.
if (fileName.matches("(.*[\\\\].*[/].*|.*[/].*[\\\\].*)")) {
log.error("BPEL Package Validation Failure: one or many of the following illegal characters are " + "in " + "the package.\n ~!@#$;%^*()+={}[]| \\<>");
throw new Exception("BPEL Package Validation Failure: one or many of the following illegal " + "characters " + "are in the package. ~!@#$;%^*()+={}[]| \\<>");
}
// Check file extension.
checkServiceFileExtensionValidity(fileName, ALLOWED_FILE_EXTENSIONS);
if (fileName.lastIndexOf('\\') != -1) {
int indexOfColon = fileName.lastIndexOf('\\') + 1;
fileName = fileName.substring(indexOfColon, fileName.length());
}
if (fieldData.getFileItem().getFieldName().equals("bpelFileName")) {
uploadedFiles = saveAndExtractUploadedFile(fieldData.getFileItem());
extractedFiles.add(uploadedFiles.extractedFile);
validateBPELPackage(uploadedFiles.extractedFile);
DataSource dataSource = new FileDataSource(uploadedFiles.zipFile);
uploaderClient.addUploadedFileItem(new DataHandler(dataSource), fileName, "zip");
}
}
uploaderClient.uploadFileItems();
String msg = "Your BPEL package been uploaded successfully. Please refresh this page in a" + " while to see the status of the new process.";
CarbonUIMessage.sendCarbonUIMessage(msg, CarbonUIMessage.INFO, request, response, getContextRoot(request) + "/" + webContext + "/bpel/process_list.jsp");
return true;
} catch (Exception e) {
errMsg = "File upload failed :" + e.getMessage();
log.error(errMsg, e);
CarbonUIMessage.sendCarbonUIMessage(errMsg, CarbonUIMessage.ERROR, request, response, getContextRoot(request) + "/" + webContext + "/bpel/upload_bpel.jsp");
} finally {
for (String s : extractedFiles) {
File extractedFile = new File(s);
if (log.isDebugEnabled()) {
log.debug("Cleaning temporarily extracted BPEL artifacts in " + extractedFile.getParent());
}
try {
FileUtils.cleanDirectory(new File(extractedFile.getParent()));
} catch (IOException ex) {
log.warn("Failed to clean temporary extractedFile.", ex);
}
}
}
return false;
}
use of org.wso2.carbon.apimgt.core.models.Function in project carbon-business-process by wso2.
the class BPMNUploadExecutor method execute.
@Override
public boolean execute(HttpServletRequest request, HttpServletResponse response) throws CarbonException, IOException {
String errMsg;
response.setContentType("text/html; charset=utf-8");
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<FileItemData>> fileItemsMap = getFileItemsMap();
if (fileItemsMap == null || fileItemsMap.isEmpty()) {
String msg = "File uploading failed.";
log.error(msg);
out.write("<textarea>" + "(function(){i18n.fileUplodedFailed();})();" + "</textarea>");
return true;
}
BPMNUploaderClient uploaderClient = new BPMNUploaderClient(configurationContext, serverURL + "BPMNUploaderService", cookie);
File uploadedTempFile;
try {
for (FileItemData fileData : fileItemsMap.get("bpmnFileName")) {
String fileName = getFileName(fileData.getFileItem().getName());
// Check filename for \ charactors. This cannot be handled at the lower stages.
if (fileName.matches("(.*[\\\\].*[/].*|.*[/].*[\\\\].*)")) {
log.error("BPMN Package Validation Failure: one or more of the following illegal characters are in " + "the package.\n ~!@#$;%^*()+={}[]| \\<>");
throw new Exception("BPMN Package Validation Failure: one or more of the following illegal characters " + "are in the package. ~!@#$;%^*()+={}[]| \\<>");
}
// Check file extension.
checkServiceFileExtensionValidity(fileName, ALLOWED_FILE_EXTENSIONS);
if (fileName.lastIndexOf('\\') != -1) {
int indexOfColon = fileName.lastIndexOf('\\') + 1;
fileName = fileName.substring(indexOfColon, fileName.length());
}
if (fileData.getFileItem().getFieldName().equals("bpmnFileName")) {
uploadedTempFile = new File(CarbonUtils.getTmpDir(), fileName);
fileData.getFileItem().write(uploadedTempFile);
DataSource dataSource = new FileDataSource(uploadedTempFile);
uploaderClient.addUploadedFileItem(new DataHandler(dataSource), fileName, "bar");
}
}
uploaderClient.uploadFileItems();
String msg = "Your BPMN package has been uploaded successfully. Please refresh this page in a" + " while to see the status of the new process.";
CarbonUIMessage.sendCarbonUIMessage(msg, CarbonUIMessage.INFO, request, response, getContextRoot(request) + "/" + webContext + "/bpmn/process_list_view.jsp");
return true;
} catch (Exception e) {
errMsg = "File upload failed :" + e.getMessage();
log.error(errMsg, e);
CarbonUIMessage.sendCarbonUIMessage(errMsg, CarbonUIMessage.ERROR, request, response, getContextRoot(request) + "/" + webContext + "/bpmn/process_list_view.jsp");
}
return false;
}
Aggregations