src/main/java/converter/Manager.java
File was removed.
src/main/java/converter/BPMNManager.java to src/main/java/converter/GenericBcmManager.java
--- a/src/main/java/converter/BPMNManager.java +++ b/src/main/java/converter/GenericBcmManager.java @@ -1,181 +1,96 @@ package converter; -import bpcf.*; -import bpcf.impl.EndImpl; -import bpcf.impl.StartImpl; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import genericbcm.*; -import java.io.File; -import java.io.IOException; -import java.util.Collections; import java.util.HashMap; -import java.util.UUID; /** - * Created by miguel on 06-05-2014. + * Created by miguel on 04-09-2014. */ -public class BPMNManager implements Manager { +public class GenericBcmManager { - private BpcfFactory factory; - private BPCtrlFlowModel bpCtrlFlowModel; + private GenericbcmFactory factory; + private BCMModel model; private HashMap<String, Object> elements; - private long numberOfElements = 1; - public BPMNManager() { - factory = BpcfFactory.eINSTANCE; - bpCtrlFlowModel = factory.createBPCtrlFlowModel(); + public GenericBcmManager() { + factory = GenericbcmFactory.eINSTANCE; + model = factory.createBCMModel(); elements = new HashMap<String, Object>(); } - public void addActivity(String id, String name) { - System.out.println(".. Adding Activity " + name); - Activity activity = factory.createActivity(); - activity.setId(numberOfElements); - numberOfElements++; - activity.setName(name); + public void addMergedImpactTable(String unitId, String tableId, String time, String financial, String legal, String severity, String external) { - bpCtrlFlowModel.getBpElements().add(activity); - elements.put(id, activity); + BusinessImpactTableRow table = factory.createBusinessImpactTableRow(); + table.setUuid(tableId); + if (time != null && !time.equals("")) + table.setTime(Double.valueOf(time)); + if (financial != null && !financial.equals("")) + table.setFinancial(Double.valueOf(financial)); + if (legal != null && !legal.equals("")) + table.setLegal(Double.valueOf(legal)); + if (severity != null && !severity.equals("")) + table.setSeverity(Double.valueOf(severity)); + if (external != null && !external.equals("")) + table.setExternal(Double.valueOf(external)); + /* if (elements.containsKey(unitId)) + ((Unit)elements.get(unitId)) + */ } - public void addFlow(BPElement one, BPElement two) { - one.getTarget().add(two); - two.getSource().add(one); + public void addFailure(String unitId, String id, String name, String description) { + FailureEffect failure = factory.createFailureEffect(); + failure.setUuid(id); + if (name != null && !name.equals("")) + failure.setName(name); + if (description != null && !description.equals("")) + failure.setDescription(description); + + elements.put(id, failure); } - public void addFlow(String idFrom, String idTo) { - if (elements.containsKey(idFrom) && elements.containsKey(idTo)) { - System.out.println(".. Adding flow from " + ((BPElement) elements.get(idFrom)).getName() + " to " + ((BPElement) elements.get(idTo)).getName()); - addFlow((BPElement) elements.get(idFrom), (BPElement) elements.get(idTo)); + public void addRecovery(String failureId, String id, String name, String description, String cost, String recoveryTimeMax, String recoveryTimeMin, String weight, String deps) { + + Recovery recovery = factory.createRecovery(); + recovery.setUuid(id); + if (name != null && !name.equals("")) + recovery.setName(name); + if (description != null && !description.equals("")) + recovery.setDescription(description); + if (cost != null && !cost.equals("")) + recovery.setCost(Double.valueOf(cost)); + if (recoveryTimeMax != null && !recoveryTimeMax.equals("")) + recovery.setRecoveryTimeMax(Double.valueOf(recoveryTimeMax)); + if (recoveryTimeMin != null && !recoveryTimeMin.equals("")) + recovery.setRecoveryTimeMin(Double.valueOf(recoveryTimeMin)); + if (weight != null && !weight.equals("")) + recovery.setWeight(Integer.valueOf(weight)); + if (deps != null && !deps.equals("")) + recovery.setDeps(Integer.valueOf(deps)); + + if (elements.containsKey(failureId)) + ((FailureEffect) elements.get(failureId)).setRecovery(recovery); + else + System.out.println("LOG: Recovery " + name + "could not be added because parent failure element does not exist"); + + elements.put(id, recovery); + } + + public void addDependencyToUnit(String unitId, String id, String name, String description, String on, String from) { + + Dependency dependency = factory.createDependency(); + dependency.setUuid(id); + if (name != null && !name.equals("")) + dependency.setName(name); + if (description != null && !description.equals("")) + dependency.setDescription(description); + if(from != null && !from.equals("")) + dependency.setFrom(from); + if(on != null && !on.equals("")){ + if (elements.containsKey(on)) + dependency.setOn((Unit) elements.get(on)); } } - public void addMerge(String id, String name) { - System.out.println(".. Adding Merge Element " + name); - Merge merge = factory.createMerge(); - merge.setId(numberOfElements); - numberOfElements++; - merge.setName(name); - - bpCtrlFlowModel.getBpElements().add(merge); - elements.put(id, merge); - - } - - public void addFork(String id, String name) { - System.out.println(".. Adding Fork Element " + name); - Fork fork = factory.createFork(); - fork.setId(numberOfElements); - numberOfElements++; - fork.setName(name); - - bpCtrlFlowModel.getBpElements().add(fork); - elements.put(id, fork); - - } - - public void addJoin(String id, String name) { - System.out.println(".. Adding Join Element " + name); - Join join = factory.createJoin(); - join.setId(numberOfElements); - numberOfElements++; - join.setName(name); - - bpCtrlFlowModel.getBpElements().add(join); - elements.put(id, join); - - } - - public void addDecision(String id, String name) { - System.out.println(".. Adding Decision Element " + name); - Decision decision = factory.createDecision(); - decision.setId(numberOfElements); - numberOfElements++; - decision.setName(name); - - bpCtrlFlowModel.getBpElements().add(decision); - elements.put(id, decision); - - } - - public void addStart(String id, String name) { - System.out.println(".. Adding Start Element " + name); - Start start = factory.createStart(); - start.setName(name); - start.setId(numberOfElements); - numberOfElements++; - elements.put(id, start); - - bpCtrlFlowModel.getBpElements().add(start); - bpCtrlFlowModel.getStartEvents().add(start); - } - - public void addArtificialStart(String flowToId) { - if (elements.containsKey(flowToId) && elements.get(flowToId).getClass() != StartImpl.class) { - System.out.println(".. Adding Infered Start Element flowing to " + ((BPElement) elements.get(flowToId)).getName()); - String uuid = UUID.randomUUID().toString(); - addStart(uuid, "INF_START"); - addFlow((BPElement) elements.get(uuid), (BPElement) elements.get(flowToId)); - } - } - - public void addFinish(String id, String name) { - System.out.println(".. Adding Finish Element " + name); - End end = factory.createEnd(); - end.setId(numberOfElements); - end.setName(name); - numberOfElements++; - - elements.put(id, end); - - bpCtrlFlowModel.getBpElements().add(end); - } - - public void addArtificialFinish(String flowFromId) { - if (elements.containsKey(flowFromId) && elements.get(flowFromId).getClass() != EndImpl.class) { - System.out.println(".. Adding Infered End Element flowing from " + ((BPElement) elements.get(flowFromId)).getName()); - String uuid = UUID.randomUUID().toString(); - addFinish(uuid, "INF_END"); - addFlow((BPElement) elements.get(flowFromId), (BPElement) elements.get(uuid)); - } - } - - public void saveModel(String path) { - System.out.println("Saving model in " + path + "..."); - - ResourceSet resSet = new ResourceSetImpl(); - resSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put( - Resource.Factory.Registry.DEFAULT_EXTENSION, new org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl()); - String newFileString = new File(path).getAbsolutePath(); - URI fileURI = URI.createFileURI(newFileString); - Resource resource = resSet.createResource(fileURI); - resource.getContents().add(bpCtrlFlowModel); - try { - resource.save(Collections.EMPTY_MAP); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public HashMap<String, Object> getElements() { - return elements; - } - - public static void main(String[] args) { - BpcfFactory factory = BpcfFactory.eINSTANCE; - BPCtrlFlowModel bpCtrlFlowModel = factory.createBPCtrlFlowModel(); - -// bpCtrlFlowModel.getBpElements().add(start); - BPElement start = factory.createStart(); - Start start1 = factory.createStart(); -// System.out.println(StartImpl.class); -// bpCtrlFlowModel.getStartEvents().add(start); - - } - }