Search in sources :

Example 91 with PACKAGE

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();
        }
    }
}
Also used : HTDeploymentConfigDocument(org.wso2.carbon.humantask.core.deployment.config.HTDeploymentConfigDocument) CarbonException(org.wso2.carbon.CarbonException)

Example 92 with PACKAGE

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();
        }
    }
}
Also used : HumanInteractionsDocument(org.wso2.carbon.humantask.HumanInteractionsDocument) CarbonException(org.wso2.carbon.CarbonException)

Example 93 with PACKAGE

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: &lt; with <
        String encodedErrMsg = errMsg.replace("</", " ").replace(">", " ").replace("<", " ");
        CarbonUIMessage.sendCarbonUIMessage(encodedErrMsg, CarbonUIMessage.ERROR, request, response, getContextRoot(request) + "/" + webContext + HumanTaskUIConstants.PAGES.UPLOAD_PAGE);
    }
    return false;
}
Also used : FileItemData(org.wso2.carbon.utils.FileItemData) ArrayList(java.util.ArrayList) FileDataSource(javax.activation.FileDataSource) DataHandler(javax.activation.DataHandler) CarbonException(org.wso2.carbon.CarbonException) FileDataSource(javax.activation.FileDataSource) DataSource(javax.activation.DataSource)

Example 94 with PACKAGE

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;
}
Also used : JSONObject(org.json.simple.JSONObject) MobileApplication(org.wso2.mdm.qsg.dto.MobileApplication) HTTPResponse(org.wso2.mdm.qsg.dto.HTTPResponse) JSONParser(org.json.simple.parser.JSONParser) ParseException(org.json.simple.parser.ParseException)

Example 95 with PACKAGE

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;
}
Also used : BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BLangReturn(org.wso2.ballerinalang.compiler.tree.statements.BLangReturn) BAttachedFunction(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol.BAttachedFunction) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) BConnectorType(org.wso2.ballerinalang.compiler.semantics.model.types.BConnectorType) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) BLangImportPackage(org.wso2.ballerinalang.compiler.tree.BLangImportPackage) Flag(org.ballerinalang.model.elements.Flag) IdentifierNode(org.ballerinalang.model.tree.IdentifierNode) TopLevelNode(org.ballerinalang.model.tree.TopLevelNode) BLangCompilationUnit(org.wso2.ballerinalang.compiler.tree.BLangCompilationUnit) BAnnotationSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol) Names(org.wso2.ballerinalang.compiler.util.Names) BServiceSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BServiceSymbol) BEnumType(org.wso2.ballerinalang.compiler.semantics.model.types.BEnumType) EnumSet(java.util.EnumSet) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) BLangDiagnosticLog(org.wso2.ballerinalang.compiler.util.diagnotic.BLangDiagnosticLog) BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BXMLNSSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol) BConnectorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BConnectorSymbol) BStructType(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) CompilerPhase(org.ballerinalang.compiler.CompilerPhase) BXMLAttributeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLAttributeSymbol) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) PackageID(org.ballerinalang.model.elements.PackageID) Set(java.util.Set) BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) BLangXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS) BLangAnnotAttribute(org.wso2.ballerinalang.compiler.tree.BLangAnnotAttribute) Collectors(java.util.stream.Collectors) BLangTransformer(org.wso2.ballerinalang.compiler.tree.BLangTransformer) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) List(java.util.List) IMPORT(org.ballerinalang.model.tree.NodeKind.IMPORT) Scope(org.wso2.ballerinalang.compiler.semantics.model.Scope) BLangEnum(org.wso2.ballerinalang.compiler.tree.BLangEnum) NodeKind(org.ballerinalang.model.tree.NodeKind) BAnnotationAttributeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationAttributeSymbol) StatementNode(org.ballerinalang.model.tree.statements.StatementNode) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol) BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) BLangXMLNSStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangXMLNSStatement) BLangInvokableNode(org.wso2.ballerinalang.compiler.tree.BLangInvokableNode) BLangAction(org.wso2.ballerinalang.compiler.tree.BLangAction) BStructField(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType.BStructField) BLangUserDefinedType(org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType) BAnnotationType(org.wso2.ballerinalang.compiler.semantics.model.types.BAnnotationType) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BLangExpressionStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt) BLangAnnotation(org.wso2.ballerinalang.compiler.tree.BLangAnnotation) BLangXMLAttribute(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttribute) BLangStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement) BLangNodeVisitor(org.wso2.ballerinalang.compiler.tree.BLangNodeVisitor) PackageLoader(org.wso2.ballerinalang.compiler.PackageLoader) TypeTags(org.wso2.ballerinalang.compiler.util.TypeTags) BServiceType(org.wso2.ballerinalang.compiler.semantics.model.types.BServiceType) Flags(org.wso2.ballerinalang.util.Flags) BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) DocTag(org.ballerinalang.model.elements.DocTag) TreeBuilder(org.ballerinalang.model.TreeBuilder) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) XMLConstants(javax.xml.XMLConstants) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BTransformerSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTransformerSymbol) BLangObject(org.wso2.ballerinalang.compiler.tree.BLangObject) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Symbols(org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) Name(org.wso2.ballerinalang.compiler.util.Name) SymTag(org.wso2.ballerinalang.compiler.semantics.model.symbols.SymTag) DiagnosticCode(org.ballerinalang.util.diagnostic.DiagnosticCode) BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) BLangEnumerator(org.wso2.ballerinalang.compiler.tree.BLangEnum.BLangEnumerator) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BLangConnector(org.wso2.ballerinalang.compiler.tree.BLangConnector) BEndpointVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) SymbolTable(org.wso2.ballerinalang.compiler.semantics.model.SymbolTable) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction)

Aggregations

BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)49 ArrayList (java.util.ArrayList)34 Test (org.testng.annotations.Test)29 Page (org.ballerinalang.docgen.model.Page)18 File (java.io.File)16 CompilerContext (org.wso2.ballerinalang.compiler.util.CompilerContext)16 IOException (java.io.IOException)15 Path (java.nio.file.Path)13 List (java.util.List)13 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)11 PackageID (org.ballerinalang.model.elements.PackageID)10 Compiler (org.wso2.ballerinalang.compiler.Compiler)10 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)10 CompilerOptions (org.wso2.ballerinalang.compiler.util.CompilerOptions)10 Collectors (java.util.stream.Collectors)9 Arrays (java.util.Arrays)8 CompilerPhase (org.ballerinalang.compiler.CompilerPhase)7 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)6 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)6 BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)6