Map<String, ResourceEntity> resources = deployment.getResources();
//if (resources.keySet().size() != 2) {
// throw new FixFlowException("发布的流程资源文件必须含有.bpmn和.png文件");
//}
ResourceEntity resourceBpmn = null;
ResourceEntity resourcePng = null;
for (String resourceName : resources.keySet()) {
LOG.info("资源 " + resourceName + " 发布!");
if (resourceName.toLowerCase().endsWith(BPMN_RESOURCE_SUFFIX)) {
resourceBpmn = resources.get(resourceName);
} else {
if (resourceName.toLowerCase().endsWith(DIAGRAM_SUFFIXES)) {
resourcePng = resources.get(resourceName);
}
}
}
if (resourceBpmn == null) {
throw new FixFlowException("发布的流程资源文件必须含有.bpmn");
}
byte[] bytes = resourceBpmn.getBytes();
ResourceSet resourceSet = getResourceSet();
String tmp = ProcessEngineManagement.getDefaultProcessEngine().getProcessEngineConfiguration().getDefaultTemplatePath();
String filePath = this.getClass().getClassLoader().getResource(tmp).toString();
Resource ddddResource = null;
if (!filePath.startsWith("jar")) {
try {
filePath = java.net.URLDecoder.decode(ReflectUtil.getResource(tmp).getFile(), "utf-8");
} catch (UnsupportedEncodingException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
throw new FixFlowException("流程定义文件加载失败!", e);
}
ddddResource = resourceSet.createResource(URI.createFileURI(filePath));
} else {
ddddResource = resourceSet.createResource(URI.createURI(filePath));
}
try {
ddddResource.load(new ByteArrayInputStream(bytes), null);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
throw new FixFlowException("定义文件加载失败!", e);
} catch (IOException e) {
// TODO Auto-generated catch block
throw new FixFlowException("定义文件加载失败!", e);
}
DefinitionsBehavior definitions = (DefinitionsBehavior) ddddResource.getContents().get(0).eContents().get(0);
ProcessDefinitionBehavior process = null;
for (RootElement rootElement : definitions.getRootElements()) {
if (rootElement instanceof ProcessDefinitionBehavior) {
// ProcessDefinitionBehavior
// processObj=(ProcessDefinitionBehavior)rootElement;
// if(processObj.getProcessDefinitionKey().equals("")){
process = (ProcessDefinitionBehavior) rootElement;
break;
// }
}
}
//增加模型验证,by ych 2013 12 27
if(process.isVerification()){
@SuppressWarnings("unused")
StringBuffer sb = new StringBuffer();
String result = VerificationUtil.verifyAll(process);
if(result.length() > 0){
throw new FixFlowException(result);
}
}
process.setDefinitions(definitions);
process.setResourceName(resourceBpmn.getName());
process.setResourceId(resourceBpmn.getId());
if(resourcePng!=null){
String diagramResourceName = StringUtil.getString(resourcePng.getName());
process.setDiagramResourceName(diagramResourceName);
}
CommandContext commandContext = Context.getCommandContext();