Search in sources :

Example 1 with HumanTaskPackageManagementSkeleton

use of org.wso2.carbon.humantask.skeleton.mgt.services.HumanTaskPackageManagementSkeleton in project carbon-business-process by wso2.

the class HumanTaskApplicationAdmin method getHumanTaskAppData.

/**
 * Gives a HumanTaskAppMetadata object with all humantask packages deployed through the
 * given app.
 *
 * @param appName - input app name
 * @return - HumanTaskAppMetadata object with found artifact info
 * @throws Exception - error on retrieving metadata
 */
public HumanTaskAppMetadata getHumanTaskAppData(String appName) throws Exception {
    HumanTaskAppMetadata data = new HumanTaskAppMetadata();
    String tenantId = AppDeployerUtils.getTenantIdString(getAxisConfig());
    // Check whether there is an application in the system from the given name
    ArrayList<CarbonApplication> appList = HumanTaskAppMgtServiceComponent.getAppManager().getCarbonApps(tenantId);
    CarbonApplication currentApplication = null;
    for (CarbonApplication application : appList) {
        if (appName.equals(application.getAppNameWithVersion())) {
            currentApplication = application;
            break;
        }
    }
    // If the app not found, throw an exception
    if (currentApplication == null) {
        String msg = "No Carbon Application found of the name : " + appName;
        log.error(msg);
        throw new Exception(msg);
    }
    // get all dependent artifacts of the cApp
    List<Artifact.Dependency> deps = currentApplication.getAppConfig().getApplicationArtifact().getDependencies();
    // we use the humantask backend admin service to get tasks from a humantask package
    HumanTaskPackageManagementSkeleton humantaskAdmin = new HumanTaskPackageManagementSkeleton();
    // package list to return
    List<PackageMetadata> packageList = new ArrayList<PackageMetadata>();
    String packageName;
    for (Artifact.Dependency dep : deps) {
        Artifact artifact = dep.getArtifact();
        packageName = artifact.getRuntimeObjectName();
        if (packageName == null) {
            continue;
        }
        if (HumanTaskAppDeployer.HUMANTASK_TYPE.equals(artifact.getType())) {
            PackageMetadata packageMetadata = new PackageMetadata();
            packageMetadata.setPackageName(packageName);
            // get the list of tasks
            List<String> taskList = new ArrayList<String>();
            Task_type0[] tasksInPackage = humantaskAdmin.listTasksInPackage(packageName);
            for (Task_type0 taskInfo : tasksInPackage) {
                taskList.add(taskInfo.getName());
            }
            String[] tasks = new String[taskList.size()];
            packageMetadata.setTaskList(tasks);
            packageList.add(packageMetadata);
        }
    }
    // convert the List into an array
    data.setPackages(packageList.toArray(new PackageMetadata[packageList.size()]));
    return data;
}
Also used : ArrayList(java.util.ArrayList) CarbonApplication(org.wso2.carbon.application.deployer.CarbonApplication) Artifact(org.wso2.carbon.application.deployer.config.Artifact) HumanTaskPackageManagementSkeleton(org.wso2.carbon.humantask.skeleton.mgt.services.HumanTaskPackageManagementSkeleton) Task_type0(org.wso2.carbon.humantask.skeleton.mgt.services.types.Task_type0)

Aggregations

ArrayList (java.util.ArrayList)1 CarbonApplication (org.wso2.carbon.application.deployer.CarbonApplication)1 Artifact (org.wso2.carbon.application.deployer.config.Artifact)1 HumanTaskPackageManagementSkeleton (org.wso2.carbon.humantask.skeleton.mgt.services.HumanTaskPackageManagementSkeleton)1 Task_type0 (org.wso2.carbon.humantask.skeleton.mgt.services.types.Task_type0)1