use of org.drools.scenariosimulation.api.model.AbstractScesimModel in project drools-wb by kiegroup.
the class ScenarioCsvImportExportTest method importData.
@Test
public void importData() throws IOException {
Simulation originalSimulation = createDummySimulation(3, 1);
assertEquals(1, originalSimulation.getUnmodifiableData().size());
String rawCSV = "OTHER,OTHER,GIVEN,GIVEN,GIVEN\r\n" + "#,Scenario description,instance1,instance2,instance3\r\n" + "Index,Description,property1,property2,property3\r\n" + "1,My Scenario,value1,value2,";
AbstractScesimModel retrieved = scenarioCsvImportExport.importData(rawCSV, originalSimulation);
assertEquals(1, retrieved.getUnmodifiableData().size());
assertEquals("value1", retrieved.getDataByIndex(0).getFactMappingValue(retrieved.getScesimModelDescriptor().getFactMappingByIndex(2)).get().getRawValue());
assertEquals("value2", retrieved.getDataByIndex(0).getFactMappingValue(retrieved.getScesimModelDescriptor().getFactMappingByIndex(3)).get().getRawValue());
assertNull(retrieved.getDataByIndex(0).getFactMappingValue(retrieved.getScesimModelDescriptor().getFactMappingByIndex(4)).get().getRawValue());
assertThatThrownBy(() -> scenarioCsvImportExport.importData("", originalSimulation)).isInstanceOf(IllegalArgumentException.class).hasMessage("Malformed file, missing header");
}
use of org.drools.scenariosimulation.api.model.AbstractScesimModel in project drools-wb by kiegroup.
the class CollectionEditorSingletonDOMElementFactory method createDomElement.
@Override
public CollectionEditorDOMElement createDomElement(final GridLayer gridLayer, final GridWidget gridWidget) {
if (this.widget != null) {
this.widget.close();
}
this.widget = createWidget();
/* Don't propagate MouseWheel and RightClick events to the Grid */
this.widget.addDomHandler(MouseWheelEvent::stopPropagation, MouseWheelEvent.getType());
this.widget.addDomHandler(event -> {
event.stopPropagation();
event.preventDefault();
}, ContextMenuEvent.getType());
this.widget.addDomHandler(ClickEvent::stopPropagation, ClickEvent.getType());
this.widget.addDomHandler(KeyDownEvent::stopPropagation, KeyDownEvent.getType());
final AbstractScesimGridModel<? extends AbstractScesimModel, ? extends AbstractScesimData> model = ((ScenarioGrid) gridWidget).getModel();
final GridData.SelectedCell selectedCellsOrigin = model.getSelectedCellsOrigin();
final Optional<GridColumn<?>> selectedColumn = model.getColumns().stream().filter(col -> col.getIndex() == selectedCellsOrigin.getColumnIndex()).findFirst();
selectedColumn.ifPresent(col -> {
final int actualIndex = model.getColumns().indexOf(col);
final FactMapping factMapping = model.getAbstractScesimModel().get().getScesimModelDescriptor().getFactMappingByIndex(actualIndex);
setCollectionEditorStructureData(this.widget, factMapping);
this.e = createDomElementInternal(widget, gridLayer, gridWidget);
});
return e;
}
use of org.drools.scenariosimulation.api.model.AbstractScesimModel in project drools-wb by kiegroup.
the class AbstractDataManagementStrategy method getPropertiesToHide.
/**
* This method returns a <code>List</code> with the properties of a given <b>Type</b> (Fact, class, other dmn defined) instance,
* to be hidden from the right panel for the selected column.
* <p>
* If click happen on an already assigned property, <b>all</b> all the properties of given type should be shown;
* if, instead, click is on an unassigned property, the already assigned properties must be hidden.
* (e.g. inside GIVEN there is an "Author" group; if clicking on "books" property header, this method returns an <b>empty</b> <code>List</code>;
* if click is on an unassigned property column, this method returns a <code>List</code>.
* with all the <b>already assigned</b> Author's properties)
* @param selectedColumn
* @param abstractScesimGridModel
* @return
*/
protected <T extends AbstractScesimModel<E>, E extends AbstractScesimData> List<List<String>> getPropertiesToHide(ScenarioGridColumn selectedColumn, AbstractScesimGridModel<T, E> abstractScesimGridModel) {
List<List<String>> toReturn = new ArrayList<>();
if (!selectedColumn.isPropertyAssigned()) {
abstractScesimGridModel.getAbstractScesimModel().ifPresent(simulation -> {
final ScesimModelDescriptor simulationDescriptor = simulation.getScesimModelDescriptor();
List<ScenarioGridColumn> instanceColumns = abstractScesimGridModel.getInstanceScenarioGridColumns(selectedColumn);
toReturn.addAll(instanceColumns.stream().filter(ScenarioGridColumn::isPropertyAssigned).map(instanceColumn -> abstractScesimGridModel.getColumns().indexOf(instanceColumn)).map(columnIndex -> {
List<String> propertyNameElements = simulationDescriptor.getFactMappingByIndex(columnIndex).getExpressionElementsWithoutClass().stream().map(ExpressionElement::getStep).collect(Collectors.toList());
if (propertyNameElements.isEmpty()) {
propertyNameElements.add(VALUE);
}
return Collections.unmodifiableList(propertyNameElements);
}).collect(Collectors.toList()));
});
}
return toReturn;
}
use of org.drools.scenariosimulation.api.model.AbstractScesimModel in project drools-wb by kiegroup.
the class ScenarioSimulationEditorPresenterTest method getImportCallback.
@Test
public void getImportCallback() {
List<AbstractScesimModel> toTest = Arrays.asList(new Simulation(), new Background());
for (AbstractScesimModel abstractScesimModel : toTest) {
FactMapping factMapping = abstractScesimModel.getScesimModelDescriptor().addFactMapping(FactIdentifier.EMPTY, ExpressionIdentifier.create("empty", FactMappingType.GIVEN));
FactMappingValue toBeRemoved = abstractScesimModel.addData().addOrUpdateMappingValue(factMapping.getFactIdentifier(), factMapping.getExpressionIdentifier(), "toBeRemoved");
presenterSpy.getImportCallBack().callback(abstractScesimModel);
verify(presenterSpy, times(1)).cleanReadOnlyColumn(eq(abstractScesimModel));
assertNull(toBeRemoved.getRawValue());
reset(presenterSpy);
}
}
use of org.drools.scenariosimulation.api.model.AbstractScesimModel in project drools-wb by kiegroup.
the class ScenarioSimulationMainGridPanelMouseMoveHandler method manageBodyCoordinates.
@Override
protected boolean manageBodyCoordinates(Integer uiRowIndex, Integer uiColumnIndex) {
/* In this case, the mouse is out ot the GridLayer, then return false, without perform any action */
if (uiColumnIndex == -1 || uiRowIndex == -1) {
return false;
}
/* If the mouse position is the same of the previous one and the popover is already open, it does nothing.
* It returns true because the click happened on an column of a grid row */
if (uiRowIndex.equals(currentlyShownBodyRowIndex) && uiColumnIndex.equals(currentlyShownBodyColumnIndex) && errorReportPopupPresenter.isShown()) {
return true;
}
/* It updates the coordinates of the current shown cell */
currentlyShownBodyRowIndex = uiRowIndex;
currentlyShownBodyColumnIndex = uiColumnIndex;
final Optional<AbstractScesimModel<? extends AbstractScesimData>> optionalAbstractScesimModel = scenarioGrid.getModel().getAbstractScesimModel();
final AbstractScesimModel<? extends AbstractScesimData> scesimModel = optionalAbstractScesimModel.orElseThrow(IllegalStateException::new);
final AbstractScesimData scenarioByIndex = scesimModel.getDataByIndex(uiRowIndex);
final FactMapping factMapping = scesimModel.getScesimModelDescriptor().getFactMappingByIndex(uiColumnIndex);
final Optional<FactMappingValue> factMappingValueOptional = scenarioByIndex.getFactMappingValue(factMapping);
factMappingValueOptional.ifPresent(factMappingValue -> manageFactMappingValue(factMappingValue, uiRowIndex, uiColumnIndex));
return true;
}
Aggregations