Search in sources :

Example 1 with HumanInteractionsDocument

use of org.wso2.carbon.humantask.HumanInteractionsDocument 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)

Aggregations

CarbonException (org.wso2.carbon.CarbonException)1 HumanInteractionsDocument (org.wso2.carbon.humantask.HumanInteractionsDocument)1