package com.camunda.fox.cockpit.demo.deployer;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import org.activiti.engine.impl.util.IoUtil;

import com.camunda.fox.cockpit.demo.DemoDataDeployer;
import com.camunda.fox.platform.spi.ProcessArchive;
import com.camunda.fox.platform.spi.ProcessArchiveCallback;
import java.util.Random;

public class DemoDataProcessArchiveImpl implements ProcessArchive {

  private final ProcessArchiveContextExecutor archiveContextExecutor;
  private final Map<String, Object> properties = new HashMap<String, Object>();

  public DemoDataProcessArchiveImpl(ProcessArchiveContextExecutor archiveContextExecutor) {
    this.archiveContextExecutor = archiveContextExecutor;
    properties.put(PROP_IS_DELETE_UPON_UNDEPLOY, false);
    properties.put(PROP_IS_SCAN_FOR_PROCESS_DEFINITIONS, false);
  }
  
  public String getProcessEngineName() {
    return null;  // = use default
  }
    
  public String getName() {
    return "cockpit-demo-processes" + new Random().nextInt(50000);
  }

  public Map<String, byte[]> getProcessResources() {
    Map<String, byte[]> processes = new HashMap<String, byte[]>();
    
    for (String processDefinition : DemoDataDeployer.DEMO_PROCESSES) {
      InputStream resource = getClassLoader().getResourceAsStream(processDefinition);
      byte[] process = IoUtil.readInputStream(resource, processDefinition);
      processes.put(processDefinition, process);
    }
    
    return processes;
  }

  public <T> T executeWithinContext(ProcessArchiveCallback<T> callback) throws Exception {
    return archiveContextExecutor.executeWithinContext(callback);
  }

  public ClassLoader getClassLoader() {
    return DemoDataProcessArchiveImpl.class.getClassLoader();
  }

  public Map<String, Object> getProperties() {
    return properties;
  }

}

@@ -121,16 +121,42 @@
 il.Map;%0D
+%0Aimport java.util.Random;%0D
 %0A%0D%0Aimpor
@@ -370,34 +370,8 @@
 ck;%0D
-%0Aimport java.util.Random;%0D
 %0A%0D%0Ap
@@ -591,16 +591,54 @@
 ect%3E();%0D
+%0A  private String processArchiveName;%0D
 %0A%0D%0A  pub
@@ -1039,22 +1039,77 @@
  %7B%0D%0A    
-return
+if (processArchiveName == null) %7B%0D%0A      processArchiveName =
  %22cockpi
@@ -1154,24 +1154,63 @@
 nt(50000);%0D%0A
+    %7D%0D%0A    return processArchiveName;%0D%0A
   %7D%0D%0A%0D%0A  pub

Fix to deploy and start DemoDataProcesses