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");
}
}
}
Aggregations