Search in sources :

Example 1 with DataDistributionWrapper

use of de.hpi.bpt.scylla.plugin.dataobject.DataDistributionWrapper in project scylla by bptlab.

the class BatchPluginUtils method getDataViewOfInstance.

private Map<String, Object> getDataViewOfInstance(TaskBeginEvent desmojEvent, ProcessInstance processInstance, BatchActivity batchActivity) {
    if (batchActivity.getGroupingCharacteristic().isEmpty()) {
        return null;
    } else {
        // ***********
        // get the value of the dataObject
        // ***********
        ProcessModel processModel = processInstance.getProcessModel();
        ProcessSimulationComponents desmojObjects = desmojEvent.getDesmojObjects();
        int nodeId = desmojEvent.getNodeId();
        boolean showInTrace = desmojEvent.traceIsOn();
        SimulationModel model = (SimulationModel) desmojEvent.getModel();
        try {
            // ***************************
            // GET INPUT
            // ***************************
            // fetch all available data objects
            Map<Integer, Object> dataObjects = (Map<Integer, Object>) desmojObjects.getExtensionDistributions().get(DataObjectPluginUtils.PLUGIN_NAME);
            Map<String, Object> simulationInput = new HashMap<String, Object>();
            // iterate over all available data objects
            for (int dataObjectId : dataObjects.keySet()) {
                // fetch all data fields
                Map<String, DataObjectField> dataObjectFields = (Map<String, DataObjectField>) dataObjects.get(dataObjectId);
                String dataObjectName = processModel.getDisplayNames().get(dataObjectId);
                for (String fieldName : dataObjectFields.keySet()) {
                    // create the key by concatenating dataObjectName + fieldName and assure that the first letter is lower case
                    String key = dataObjectName + "." + fieldName;
                    // handle the distribution of every data field
                    DataObjectField dataObjectField = dataObjectFields.get(fieldName);
                    DataDistributionWrapper distWrapper = dataObjectField.getDataDistributionWrapper();
                    try {
                        simulationInput.put(key, distWrapper.getSample());
                    } catch (ScyllaRuntimeException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
            Map<String, Object> dataView = new HashMap<String, Object>();
            for (String dataViewElement : batchActivity.getGroupingCharacteristic()) {
                dataView.put(dataViewElement, simulationInput.get(dataViewElement));
            }
            return dataView;
        } catch (ScyllaValidationException e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
            SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
            return null;
        }
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) HashMap(java.util.HashMap) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) ProcessSimulationComponents(de.hpi.bpt.scylla.simulation.ProcessSimulationComponents) DataObjectField(de.hpi.bpt.scylla.plugin.dataobject.DataObjectField) ResourceObject(de.hpi.bpt.scylla.simulation.ResourceObject) DataDistributionWrapper(de.hpi.bpt.scylla.plugin.dataobject.DataDistributionWrapper) HashMap(java.util.HashMap) Map(java.util.Map) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Aggregations

ScyllaRuntimeException (de.hpi.bpt.scylla.exception.ScyllaRuntimeException)1 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)1 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)1 DataDistributionWrapper (de.hpi.bpt.scylla.plugin.dataobject.DataDistributionWrapper)1 DataObjectField (de.hpi.bpt.scylla.plugin.dataobject.DataObjectField)1 ProcessSimulationComponents (de.hpi.bpt.scylla.simulation.ProcessSimulationComponents)1 ResourceObject (de.hpi.bpt.scylla.simulation.ResourceObject)1 SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1