Search in sources :

Example 26 with PACKAGE

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project carbon-business-process by wso2.

the class HumanTaskPackageRepository method addLatestArchiveToRegistryCollection.

/**
 * Add latest human task package zip to the registry
 *
 * @param deploymentUnitDAO
 * @param humanTaskFile
 * @throws RegistryException
 * @throws HumanTaskStoreException
 */
private void addLatestArchiveToRegistryCollection(DeploymentUnitDAO deploymentUnitDAO, File humanTaskFile) throws HumanTaskStoreException, RegistryException {
    FileInputStream fileInputStream = null;
    try {
        Resource latestHumanTaskArchive = configRegistry.newResource();
        fileInputStream = new FileInputStream(humanTaskFile);
        latestHumanTaskArchive.setContent(fileInputStream);
        configRegistry.put(HumanTaskPackageRepositoryUtils.getHumanTaskPackageArchiveResourcePath(deploymentUnitDAO.getPackageName()), latestHumanTaskArchive);
    } catch (FileNotFoundException ex) {
        String errMsg = "HumanTask package zip file couldn't found on given location " + humanTaskFile.getAbsolutePath();
        throw new HumanTaskStoreException(errMsg, ex);
    } catch (RegistryException ex) {
        String errMsg = "Exception occurred while adding latest archive to registry collection";
        throw new RegistryException(errMsg, ex);
    } finally {
        if (fileInputStream != null) {
            try {
                fileInputStream.close();
            } catch (IOException e) {
                log.warn("Cannot close file input stream.", e);
            }
        }
    }
}
Also used : HumanTaskStoreException(org.wso2.carbon.humantask.core.store.HumanTaskStoreException) Resource(org.wso2.carbon.registry.core.Resource) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) FileInputStream(java.io.FileInputStream)

Example 27 with PACKAGE

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE 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;
}
Also used : FileItemData(org.wso2.carbon.utils.FileItemData) ArrayList(java.util.ArrayList) FileDataSource(javax.activation.FileDataSource) DataHandler(javax.activation.DataHandler) File(java.io.File) IOException(java.io.IOException) CarbonException(org.wso2.carbon.CarbonException) PrintWriter(java.io.PrintWriter) FileDataSource(javax.activation.FileDataSource) DataSource(javax.activation.DataSource)

Example 28 with PACKAGE

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project carbon-business-process by wso2.

the class BPMNDeploymentService method aggregateRemovableProcessInstances.

private void aggregateRemovableProcessInstances(BPMNDeletableInstances bpmnDeletableInstances, String deploymentId, Integer tenantId, ProcessEngine processEngine) throws BPSFault {
    ProcessDefinitionQuery query = processEngine.getRepositoryService().createProcessDefinitionQuery();
    List<ProcessDefinition> processes = query.processDefinitionTenantId(tenantId.toString()).deploymentId(deploymentId).list();
    for (ProcessDefinition process : processes) {
        if (!constructBPMNInstancesByProcessID(bpmnDeletableInstances, process.getId(), tenantId, processEngine)) {
            String errorMessage = " Failed to undeploy the package. Please delete the instances before undeploying " + "the package";
            throw new BPSFault(errorMessage);
        }
    }
}
Also used : BPSFault(org.wso2.carbon.bpmn.core.BPSFault) ProcessDefinitionQuery(org.activiti.engine.repository.ProcessDefinitionQuery) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition)

Example 29 with PACKAGE

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project carbon-business-process by wso2.

the class BPMNDeploymentService method getLatestChecksum.

/**
 * Get the checksum of latest deployment for given deployment name
 *
 * @param deploymentName
 * @return
 * @throws BPSFault
 */
public String getLatestChecksum(String deploymentName) throws BPSFault {
    try {
        Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
        RegistryService registryService = BPMNServerHolder.getInstance().getRegistryService();
        Registry tenantRegistry = registryService.getConfigSystemRegistry(tenantId);
        String deploymentRegistryPath = BPMNConstants.BPMN_REGISTRY_PATH + BPMNConstants.REGISTRY_PATH_SEPARATOR + deploymentName;
        if (tenantRegistry.resourceExists(deploymentRegistryPath)) {
            Resource deploymentEntry = tenantRegistry.get(deploymentRegistryPath);
            return deploymentEntry.getProperty(BPMNConstants.LATEST_CHECKSUM_PROPERTY);
        } else {
            return null;
        }
    } catch (RegistryException e) {
        String msg = "Error while accessing registry to get latest checksum for package : " + deploymentName;
        throw new BPSFault(msg, e);
    }
}
Also used : BPSFault(org.wso2.carbon.bpmn.core.BPSFault) Resource(org.wso2.carbon.registry.api.Resource) Registry(org.wso2.carbon.registry.api.Registry) RegistryService(org.wso2.carbon.registry.api.RegistryService) RegistryException(org.wso2.carbon.registry.api.RegistryException)

Example 30 with PACKAGE

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project carbon-business-process by wso2.

the class BPMNDeploymentService method undeploy.

public void undeploy(String deploymentName) throws BPSFault {
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    ProcessEngine processEngine = BPMNServerHolder.getInstance().getEngine();
    DeploymentQuery query = processEngine.getRepositoryService().createDeploymentQuery();
    query = query.deploymentTenantId(tenantId.toString());
    query = query.deploymentNameLike("%" + deploymentName + "%");
    int deploymentCount = (int) query.count();
    log.info("Package " + deploymentName + " id going to be undeployed for the deployment count : " + deploymentCount);
    BPMNDeletableInstances bpmnDeletableInstances = new BPMNDeletableInstances();
    bpmnDeletableInstances.setTenantId(tenantId);
    List<Deployment> deployments = query.listPage(0, deploymentCount + 1);
    for (Deployment deployment : deployments) {
        aggregateRemovableProcessInstances(bpmnDeletableInstances, deployment.getId(), tenantId, processEngine);
    }
    if ((bpmnDeletableInstances.getActiveInstanceCount() + bpmnDeletableInstances.getCompletedInstanceCount()) > maximumDeleteCount) {
        String errorMessage = " Failed to un deploy the package. Please delete the instances before un deploying " + "the package";
        throw new BPSFault(errorMessage, new Exception(errorMessage));
    }
    deleteInstances(bpmnDeletableInstances, processEngine);
    TenantRepository tenantRepository = BPMNServerHolder.getInstance().getTenantManager().getTenantRepository(tenantId);
    tenantRepository.undeploy(deploymentName, false);
}
Also used : DeploymentQuery(org.activiti.engine.repository.DeploymentQuery) BPSFault(org.wso2.carbon.bpmn.core.BPSFault) BPMNDeployment(org.wso2.carbon.bpmn.core.mgt.model.BPMNDeployment) Deployment(org.activiti.engine.repository.Deployment) TenantRepository(org.wso2.carbon.bpmn.core.deployment.TenantRepository) RegistryException(org.wso2.carbon.registry.api.RegistryException) IOException(java.io.IOException) ProcessEngine(org.activiti.engine.ProcessEngine) BPMNDeletableInstances(org.wso2.carbon.bpmn.core.mgt.model.BPMNDeletableInstances)

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