public void DeployProcessArchive(Stream processArchiveStream, DbSession dbSession)
        {
            log.Debug("reading process archive...");

            // construct an empty process definition
            ProcessDefinitionImpl processDefinition = new ProcessDefinitionImpl();

            // Then save the process definition
            // This is done so hibernate will assign an id to this object.
            dbSession.Save(processDefinition);

            IDictionary<string, byte[]> entries = null;
            entries = ZipUtility.ReadEntries(processArchiveStream);

            ProcessDefinitionBuildContext processDefinitionBuilder = new ProcessDefinitionBuildContext(processDefinition, entries, dbSession);
            try
            {
                if (!entries.ContainsKey("processdefinition.xml"))
                {
                    processDefinitionBuilder.AddError("entry '" + "processdefinition.xml" + "' found not found in the process archive");
                    throw new SystemException("entry '" + "processdefinition.xml" + "' found not found in the process archive");
                }
                // parse the  processdefinition.xml
                XmlElement xmlElement = getXmlElementFromBytes(entries["processdefinition.xml"]);
                // build the object model from the xml
                processDefinitionBuilder.PushScope("in processdefinition.xml");
                processDefinition.ReadProcessData(xmlElement, processDefinitionBuilder);
                processDefinition.Version = GetVersionNr(processDefinitionBuilder, processDefinition.Name);
                processDefinition.ClassFiles = GetAssemblyFiles(processDefinitionBuilder, processDefinition);
                processDefinitionBuilder.PopScope();
                // resolve all forward references
                processDefinitionBuilder.ResolveReferences();

                processDefinition.Validate(processDefinitionBuilder);

                if (processDefinitionBuilder.HasErrors())
                {
                    throw new NpdlException(processDefinitionBuilder.Errors);
                }
                // read the optional web-interface information
                if (entries.ContainsKey("web/webinterface.xml"))
                {
                    log.Debug("processing webinterface.xml...");
                    xmlElement = getXmlElementFromBytes(entries["web/webinterface.xml"]);
                    processDefinitionBuilder.PushScope("in webinterface.xml");
                    processDefinition.ReadWebData(xmlElement, processDefinitionBuilder);
                    processDefinitionBuilder.PopScope();
                }
                else
                {
                    log.Debug("no web/webinterface.xml was supplied");
                }

                processDefinitionRepository.Save(processDefinition, dbSession);
            }
            catch (SystemException e)
            {
                log.Error("xml parsing error :", e);
                processDefinitionBuilder.AddError(e.GetType().FullName + " : " + e.Message);
                processDefinitionBuilder.AddError("couldn't continue to parse the process archive");
                throw new NpdlException(processDefinitionBuilder.Errors);
            }
        }
Exemplo n.º 2
0
		public void DeployProcessArchive(Stream processArchiveStream, DbSession dbSession)
		{
			log.Debug("reading process archive...");
			try
			{
				IDictionary entries = null;
				// construct an empty process definition
				ProcessDefinitionImpl processDefinition = new ProcessDefinitionImpl();
				try
				{
					entries = ReadEntries(processArchiveStream);
				}
				catch (IOException e)
				{
					throw new NpdlException("couldn't deploy process archive, the processArchiveBytes do not seem to be a valid jar-file : " + e.Message, e);
				}

				// Then save the process definition
				// This is done so hibernate will assign an id to this object.
				dbSession.Save(processDefinition);
				CreationContext creationContext = new CreationContext(processDefinition, entries, dbSession);
				try
				{
					// parse the  processdefinition.xml
					XmlElement xmlElement = GetXmlElementForEntry("processdefinition.xml", entries, creationContext);
					// build the object model from the xml
					creationContext.PushScope("in processdefinition.xml");
					processDefinition.ReadProcessData(xmlElement, creationContext);
					creationContext.PopScope();
					// resolve all forward references
					creationContext.ResolveReferences();

					processDefinition.Validate(creationContext);

					if (creationContext.HasErrors())
					{
						throw new NpdlException(creationContext.Errors);
					}
					// read the optional web-interface information
					if (entries.Contains("web/webinterface.xml"))
					{
						log.Debug("processing webinterface.xml...");
						xmlElement = GetXmlElementForEntry("web/webinterface.xml", entries, creationContext);
						creationContext.PushScope("in webinterface.xml");
						processDefinition.ReadWebData(xmlElement, creationContext);
						creationContext.PopScope();
					}
					else
					{
						log.Debug("no web/webinterface.xml was supplied");
					}

				}
				catch (SystemException e)
				{
					log.Error("xml parsing error :", e);
					creationContext.AddError(e.GetType().FullName + " : " + e.Message);
					creationContext.AddError("couldn't continue to parse the process archive");
					throw new NpdlException(creationContext.Errors);
				}

				// flush the changes to the database
				dbSession.SaveOrUpdate(processDefinition);
				dbSession.Flush();
			}
			catch (DbException e)
			{
				throw new NpdlException("couldn't deploy process archive due to a database exception : " + e.Message, e);
			}
		}