From 5e4034b5cba89460a62fa958fc78c2b85acb3d5f Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 7 Oct 2014 09:18:33 +0200 Subject: Repackage to org.cristalise --- .../lifecycle/desc/ElemActDefOutcomeHandler.java | 228 +++++++++++++++++++++ 1 file changed, 228 insertions(+) create mode 100644 src/main/java/org/cristalise/gui/lifecycle/desc/ElemActDefOutcomeHandler.java (limited to 'src/main/java/org/cristalise/gui/lifecycle/desc/ElemActDefOutcomeHandler.java') diff --git a/src/main/java/org/cristalise/gui/lifecycle/desc/ElemActDefOutcomeHandler.java b/src/main/java/org/cristalise/gui/lifecycle/desc/ElemActDefOutcomeHandler.java new file mode 100644 index 0000000..985ce0a --- /dev/null +++ b/src/main/java/org/cristalise/gui/lifecycle/desc/ElemActDefOutcomeHandler.java @@ -0,0 +1,228 @@ +package org.cristalise.gui.lifecycle.desc; + +import java.io.BufferedWriter; +import java.io.File; + +import javax.swing.JOptionPane; +import javax.swing.JPanel; + +import org.cristalise.gui.MainFrame; +import org.cristalise.gui.graph.view.VertexPropertyPanel; +import org.cristalise.gui.tabs.outcome.InvalidOutcomeException; +import org.cristalise.gui.tabs.outcome.InvalidSchemaException; +import org.cristalise.gui.tabs.outcome.OutcomeException; +import org.cristalise.gui.tabs.outcome.OutcomeHandler; +import org.cristalise.gui.tabs.outcome.OutcomeNotInitialisedException; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.entity.agent.Job; +import org.cristalise.kernel.entity.proxy.ItemProxy; +import org.cristalise.kernel.graph.model.GraphableVertex; +import org.cristalise.kernel.lifecycle.ActivityDef; +import org.cristalise.kernel.lifecycle.ActivitySlotDef; +import org.cristalise.kernel.lifecycle.CompositeActivityDef; +import org.cristalise.kernel.persistency.ClusterStorage; +import org.cristalise.kernel.persistency.outcome.Viewpoint; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.FileStringUtility; +import org.cristalise.kernel.utils.LocalObjectLoader; +import org.cristalise.kernel.utils.Logger; + + +/************************************************************************** + * + * $Revision: 1.5 $ + * $Date: 2005/10/05 07:39:37 $ + * + * Copyright (C) 2003 CERN - European Organization for Nuclear Research + * All rights reserved. + **************************************************************************/ + +public class ElemActDefOutcomeHandler extends VertexPropertyPanel implements OutcomeHandler { + + ActivityDef act; + boolean unsaved; + public ElemActDefOutcomeHandler() { + super(); + createLayout(null); + } + + /** + * + */ + @Override + public void setOutcome(String outcome) throws InvalidOutcomeException { + try { + act = (ActivityDef)Gateway.getMarshaller().unmarshall(outcome); + setVertex(act); + } catch (Exception ex) { + Logger.error(ex); + throw new InvalidOutcomeException(); + } + } + + /** + * + */ + @Override + public void setDescription(String description) + throws InvalidSchemaException { + // ignore + } + + /** + * + */ + @Override + public void setReadOnly(boolean readOnly) { + setEditable(!readOnly); + + } + + /** + * + */ + @Override + public JPanel getPanel() throws OutcomeNotInitialisedException { + return this; + } + + /** + * + */ + @Override + public String getOutcome() throws OutcomeException { + try { + return Gateway.getMarshaller().marshall(act); + } catch (Exception ex) { + Logger.error(ex); + throw new OutcomeException(); + } + } + + /** + * + */ + @Override + public void run() { + validate(); + } + + @Override + public boolean isUnsaved() { + return unsaved; + } + + @Override + public void saved() { + unsaved = false; + } + + @Override + public void export(File targetFile) throws Exception { + exportAct(targetFile.getParentFile(), null, act); + } + + public static void exportAct(File dir, BufferedWriter imports, ActivityDef actDef) throws Exception { + + // Export associated schema + exportSchema((String)actDef.getProperties().get("SchemaType"), actDef.getProperties().get("SchemaVersion"), imports, new File(dir, "OD")); + // Export associated script + exportScript((String)actDef.getProperties().get("ScriptName"), actDef.getProperties().get("ScriptVersion"), imports, new File(dir, "SC")); + + //Export child act if composite + if (actDef instanceof CompositeActivityDef) { + CompositeActivityDef compActDef = (CompositeActivityDef)actDef; + for (int i=0; iboot/CA/"+compActDef.getActName()+".xml\n"); + } + } + else { + FileStringUtility.string2File(new File(new File(dir, "EA"), actDef.getActName()+".xml"), Gateway.getMarshaller().marshall(actDef)); + if (imports!=null) imports.write("boot/EA/"+actDef.getActName()+".xml\n"); + } + } + + private static void resolveRealVersion(ActivitySlotDef childDef) throws ObjectNotFoundException { + String defName = childDef.getActName(); + ItemProxy actDefItem = LocalObjectLoader.loadLocalObjectDef("/desc/ActivityDesc/", defName); + String actType = actDefItem.getProperty("Complexity"); + Viewpoint last = actDefItem.getViewpoint( actType + "ActivityDef", "last"); + String[] viewpoints = actDefItem.getContents(ClusterStorage.VIEWPOINT+"/"+actType + "ActivityDef"); + for (String viewName : viewpoints) { + try { + Integer.parseInt(viewName); + } catch (NumberFormatException e) { + continue; // only count integer viewnames + } + Viewpoint thisView = actDefItem.getViewpoint(actType + "ActivityDef", viewName); + if (thisView.getEventId() == last.getEventId()) { + JOptionPane.showMessageDialog(null, defName+" defined as 'last'. Will use view "+viewName+" instead"); + childDef.getProperties().put("Version", viewName); + return; + } + } + JOptionPane.showMessageDialog(null, "Last view for "+defName+" has not been materialized. Executing CreateFromLast"); + try { + Job createJob = actDefItem.getJobByName("AssignNewActivityVersionFromLast", MainFrame.userAgent); + MainFrame.userAgent.execute(createJob); + } catch (Exception e) { + Logger.error(e); + throw new ObjectNotFoundException("Could not create new version of "+defName+" from last"); + } + resolveRealVersion(childDef); + } + + public static void exportScript(String name, Object version, BufferedWriter imports, File dir) { + if (name == null || name.length()==0 || name.contains(":")) return; + try { + int intVersion; + if (version instanceof String) intVersion = Integer.parseInt((String)version); + else if (version instanceof Integer) intVersion = ((Integer)version).intValue(); + else return; + + FileStringUtility.string2File(new File(dir, name+".xml"), + LocalObjectLoader.getScript(name, intVersion)); + if (imports!=null) imports.write("boot/SC/"+name+".xml\n"); + } catch (NumberFormatException ex) { + JOptionPane.showMessageDialog(null, "Invalid version number in script version:"+version); + } catch (Exception ex) { + Logger.error(ex); + JOptionPane.showMessageDialog(null, "Could not export script "+name+"_"+version, "Error", JOptionPane.ERROR_MESSAGE); + } + } + + public static void exportSchema(String name, Object version, BufferedWriter imports, File dir) { + if (name == null || name.length()==0) return; + try { + int intVersion; + if (version instanceof String) intVersion = Integer.parseInt((String)version); + else if (version instanceof Integer) intVersion = ((Integer)version).intValue(); + else return; + FileStringUtility.string2File(new File(dir, name+".xsd"), + LocalObjectLoader.getSchema(name, intVersion).schema); + if (imports!=null) imports.write("boot/OD/"+name+".xsd\n"); + } catch (NumberFormatException ex) { + JOptionPane.showMessageDialog(null, "Invalid version number in script version:"+version); + } catch (Exception ex) { + Logger.error(ex); + JOptionPane.showMessageDialog(null, "Could not export schema "+name+"_"+version, "Error", JOptionPane.ERROR_MESSAGE); + } + } +} -- cgit v1.2.3