use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project carbon-business-process by wso2.
the class HumanTaskUploadExecutor method validateHTDeploymentConfigDocument.
/**
* Validate HT deployment config Document.
*
* @param directoryPath Unzipped HumanTask archive directory.
* @throws Exception
*/
public void validateHTDeploymentConfigDocument(String directoryPath) throws Exception {
if (log.isDebugEnabled()) {
log.debug("Validating HumanTask deployment config.");
}
// We have to check whether the htconfig.xml file is in the root level.
// otherwise we cannot accept this as a valid human task package.
String htConfigFilePathString = directoryPath + File.separator + HumanTaskUIConstants.FILE_NAMES.HT_CONFIG_NAME;
File htConfigFile = new File(htConfigFilePathString);
if (!htConfigFile.exists()) {
throw new Exception("The uploaded task definition zip file does not contain a htconfig.xml" + "file. Please check the package and re-upload.");
}
HTDeploymentConfigDocument hiConf;
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(htConfigFile);
hiConf = HTDeploymentConfigDocument.Factory.parse(fileInputStream);
if (log.isDebugEnabled()) {
log.debug("Successfully Validated HumanTask deployment config.");
}
} catch (Exception e) {
String errMsg = "Error occurred while parsing the human interaction configuration " + "file: htconfig.xml";
throw new Exception(errMsg, e);
} finally {
if (fileInputStream != null) {
fileInputStream.close();
}
}
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project carbon-business-process by wso2.
the class HumanTaskUploadExecutor method validateHumanTaskDefinition.
/**
* Validate HumanTask definition.
*
* @param directoryPath Unzipped HumanTask archive directory.
* @throws Exception
*/
public void validateHumanTaskDefinition(String directoryPath) throws Exception {
if (log.isDebugEnabled()) {
log.debug("Validating HumanTask definition.");
}
File humantaskDir = new File(directoryPath);
List<File> hiDefinitionFiles = FileUtils.directoryEntriesInPath(humantaskDir, humantaskFilter);
if (hiDefinitionFiles.size() != 1) {
String errMsg;
if (hiDefinitionFiles.size() == 0) {
errMsg = "No Humantask definition files was found. Please check the package and re-upload.";
} else {
errMsg = "Multiple (" + hiDefinitionFiles.size() + ") Humantask definition files were found. Only single task definition file (.ht) allowed.";
}
throw new Exception(errMsg);
}
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(hiDefinitionFiles.get(0));
// Check Task definition compliant with schema.
HumanInteractionsDocument humanInteractionsDocument = HumanInteractionsDocument.Factory.parse(fileInputStream);
if (log.isDebugEnabled()) {
log.debug("successfully validate HumanTask definition.");
}
} catch (Exception e) {
String errMsg = "Error while reading Human Interactions definition. Reason : " + e.getMessage();
throw new Exception(errMsg, e);
} finally {
if (fileInputStream != null) {
fileInputStream.close();
}
}
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project carbon-business-process by wso2.
the class HumanTaskUploadExecutor 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;
}
HIUploaderClient uploaderClient = new HIUploaderClient(configurationContext, serverURL + HumanTaskUIConstants.SERVICE_NAMES.HUMANTASK_UPLOADER_SERVICE_NAME, cookie);
try {
for (FileItemData fieldData : fileItemsMap.get("humantaskFileName")) {
String fileName = getFileName(fieldData.getFileItem().getName());
// Check filename for \ charactors. This cannot be handled at the lower stages.
if (fileName.matches("(.*[\\\\].*[/].*|.*[/].*[\\\\].*)")) {
log.error("HumanTask Package Validation Failure: one or many of the following illegal characters are in " + "the package.\n ~!@#$;%^*()+={}[]| \\<>");
throw new Exception("HumanTask 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 ("humantaskFileName".equals(fieldData.getFileItem().getFieldName())) {
SaveExtractReturn uploadedFiles = saveAndExtractUploadedFile(fieldData.getFileItem());
validateHumanTaskPackage(uploadedFiles.extractedFile);
DataSource dataSource = new FileDataSource(uploadedFiles.zipFile);
uploaderClient.addUploadedFileItem(new DataHandler(dataSource), fileName, "zip");
}
}
uploaderClient.uploadFileItems();
String msg = "Your HumanTask package been uploaded successfully. Please refresh this page in a" + " while to see the status of the new package.";
CarbonUIMessage.sendCarbonUIMessage(msg, CarbonUIMessage.INFO, request, response, getContextRoot(request) + "/" + webContext + HumanTaskUIConstants.PAGES.PACKAGE_LIST_PAGE);
return true;
} catch (Exception e) {
errMsg = "File upload failed :" + e.getMessage();
log.error(errMsg, e);
// Removing <, > and </ characters from Error message, in order to provide accurate error message.
// TODO : FIX this correctly. Identify why latest browsers unable to render HTML encoded string. Eg: < with <
String encodedErrMsg = errMsg.replace("</", " ").replace(">", " ").replace("<", " ");
CarbonUIMessage.sendCarbonUIMessage(encodedErrMsg, CarbonUIMessage.ERROR, request, response, getContextRoot(request) + "/" + webContext + HumanTaskUIConstants.PAGES.UPLOAD_PAGE);
}
return false;
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project product-iots by wso2.
the class AppOperations method uploadApplication.
public static MobileApplication uploadApplication(String platform, String appName, String appContentType) {
String appUploadEndpoint = EMMQSGConfig.getInstance().getEmmHost() + appmPublisherMobileBinariesUrl;
String filePath = "apps" + File.separator + platform + File.separator + appName;
HTTPResponse httpResponse = HTTPInvoker.uploadFile(appUploadEndpoint, filePath, appContentType);
if (Constants.HTTPStatus.OK == httpResponse.getResponseCode()) {
JSONObject appMeta = null;
MobileApplication application = new MobileApplication();
try {
appMeta = (JSONObject) new JSONParser().parse(httpResponse.getResponse());
application.setPackageId((String) appMeta.get("package"));
application.setAppId(QSGUtils.getResourceId((String) appMeta.get("path")));
application.setVersion((String) appMeta.get("version"));
application.setPlatform(platform);
} catch (ParseException e) {
e.printStackTrace();
}
return application;
}
return null;
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project ballerina by ballerina-lang.
the class SymbolEnter method definePackageInitFunctions.
private void definePackageInitFunctions(BLangPackage pkgNode, SymbolEnv env) {
BLangFunction initFunction = pkgNode.initFunction;
// Add package level namespace declarations to the init function
pkgNode.xmlnsList.forEach(xmlns -> {
initFunction.body.addStatement(createNamespaceDeclrStatement(xmlns));
});
// Add global variables to the init function
pkgNode.globalVars.stream().filter(f -> f.expr != null).forEachOrdered(v -> initFunction.body.addStatement(createAssignmentStmt(v)));
addInitReturnStatement(initFunction.body);
defineNode(pkgNode.initFunction, env);
pkgNode.symbol.initFunctionSymbol = pkgNode.initFunction.symbol;
addInitReturnStatement(pkgNode.startFunction.body);
defineNode(pkgNode.startFunction, env);
pkgNode.symbol.startFunctionSymbol = pkgNode.startFunction.symbol;
addInitReturnStatement(pkgNode.stopFunction.body);
defineNode(pkgNode.stopFunction, env);
pkgNode.symbol.stopFunctionSymbol = pkgNode.stopFunction.symbol;
}
Aggregations