Search in sources :

Example 6 with UploadedFileItem

use of org.wso2.carbon.bpel.deployer.services.types.UploadedFileItem in project carbon-business-process by wso2.

the class BPMNUploader method uploadService.

public void uploadService(UploadedFileItem[] fileItems) throws AxisFault {
    // First lets filter for jar resources
    ConfigurationContext configurationContext = getConfigContext();
    String repo = configurationContext.getAxisConfiguration().getRepository().getPath();
    if (CarbonUtils.isURL(repo)) {
        throw new AxisFault("URL Repositories are not supported: " + repo);
    }
    // Writing the artifacts to the proper location
    String bpmnDirectory = repo + File.separator + BPMNConstants.BPMN_REPO_NAME;
    String bpmnTemp = CarbonUtils.getCarbonHome() + BPMNConstants.BPMN_PACKAGE_TEMP_DIRECTORY;
    File bpmnTempDir = new File(bpmnTemp);
    if (!bpmnTempDir.exists() && !bpmnTempDir.mkdirs()) {
        throw new AxisFault("Fail to create the directory: " + bpmnTempDir.getAbsolutePath());
    }
    File bpmnDir = new File(bpmnDirectory);
    if (!bpmnDir.exists() && !bpmnDir.mkdirs()) {
        throw new AxisFault("Fail to create the directory: " + bpmnDir.getAbsolutePath());
    }
    for (UploadedFileItem uploadedFile : fileItems) {
        String fileName = uploadedFile.getFileName();
        if (fileName == null || fileName.equals("")) {
            throw new AxisFault("Invalid file name. File name is not available");
        }
        if (uploadedFile.getFileType().equals(BPMNConstants.BPMN_PACKAGE_EXTENSION)) {
            try {
                writeResource(uploadedFile.getDataHandler(), bpmnTemp, fileName, bpmnDir);
            } catch (IOException e) {
                throw new AxisFault("IOError: Writing resource failed.", e);
            }
        } else {
            throw new AxisFault("Invalid file type : " + uploadedFile.getFileType() + " ." + BPMNConstants.BPMN_PACKAGE_EXTENSION + " file type is expected");
        }
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) UploadedFileItem(org.wso2.carbon.bpmn.core.mgt.model.UploadedFileItem) IOException(java.io.IOException) File(java.io.File)

Aggregations

AxisFault (org.apache.axis2.AxisFault)3 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)3 File (java.io.File)2 IOException (java.io.IOException)2 UploadedFileItem (org.wso2.carbon.bpel.deployer.services.types.UploadedFileItem)1 UploadedFileItem (org.wso2.carbon.bpel.stub.upload.types.UploadedFileItem)1 UploadedFileItem (org.wso2.carbon.bpmn.core.mgt.model.UploadedFileItem)1 UploadedFileItem (org.wso2.carbon.bpmn.core.mgt.model.xsd.UploadedFileItem)1 UploadedFileItem (org.wso2.carbon.core.common.UploadedFileItem)1 UploadedFileItem (org.wso2.carbon.humantask.stub.upload.types.UploadedFileItem)1