use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry in project kie-wb-common by kiegroup.
the class ContextEntryPropertyConverter method wbFromDMN.
public static ContextEntry wbFromDMN(final org.kie.dmn.model.api.ContextEntry dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
final InformationItem variable = InformationItemPropertyConverter.wbFromDMN(dmn.getVariable());
final Expression expression = ExpressionPropertyConverter.wbFromDMN(dmn.getExpression(), hasComponentWidthsConsumer);
final ContextEntry result = new ContextEntry();
if (Objects.nonNull(variable)) {
variable.setParent(result);
}
result.setVariable(variable);
if (Objects.nonNull(expression)) {
expression.setParent(result);
}
result.setExpression(expression);
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry in project kie-wb-common by kiegroup.
the class ContextPropertyConverter method dmnFromWB.
public static org.kie.dmn.model.api.Context dmnFromWB(final Context wb, final Consumer<ComponentWidths> componentWidthsConsumer) {
final org.kie.dmn.model.api.Context result = new org.kie.dmn.model.v1_2.TContext();
result.setId(wb.getId().getValue());
result.setDescription(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef);
for (ContextEntry ce : wb.getContextEntry()) {
final org.kie.dmn.model.api.ContextEntry ceConverted = ContextEntryPropertyConverter.dmnFromWB(ce, componentWidthsConsumer);
if (ceConverted != null) {
ceConverted.setParent(result);
}
result.getContextEntry().add(ceConverted);
}
// The UI appends a ContextEntry for the _default_ result that may contain an undefined Expression.
// If this is the case then DMN does not require the ContextEntry to be written out to the XML.
// Conversion of ContextEntries will always create a _mock_ LiteralExpression if no Expression has
// been defined therefore remove the last entry from the org.kie.dmn.model if the WB had no Expression.
final int contextEntriesCount = result.getContextEntry().size();
if (contextEntriesCount > 0) {
if (Objects.isNull(wb.getContextEntry().get(contextEntriesCount - 1).getExpression())) {
result.getContextEntry().remove(contextEntriesCount - 1);
}
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry in project kie-wb-common by kiegroup.
the class ContextEntryDefaultValueUtilitiesTest method testGetNewContextEntryNameWithDeletion.
@Test
public void testGetNewContextEntryNameWithDeletion() {
final ContextEntry contextEntry1 = new ContextEntry() {
{
setVariable(new InformationItem());
}
};
context.getContextEntry().add(contextEntry1);
contextEntry1.getVariable().getName().setValue(ContextEntryDefaultValueUtilities.getNewContextEntryName(context));
assertThat(contextEntry1.getVariable().getName().getValue()).isEqualTo(ContextEntryDefaultValueUtilities.PREFIX + "1");
final ContextEntry contextEntry2 = new ContextEntry() {
{
setVariable(new InformationItem());
}
};
context.getContextEntry().add(contextEntry2);
contextEntry2.getVariable().getName().setValue(ContextEntryDefaultValueUtilities.getNewContextEntryName(context));
assertThat(contextEntry2.getVariable().getName().getValue()).isEqualTo(ContextEntryDefaultValueUtilities.PREFIX + "2");
context.getContextEntry().remove(contextEntry1);
final ContextEntry contextEntry3 = new ContextEntry() {
{
setVariable(new InformationItem());
}
};
context.getContextEntry().add(contextEntry3);
contextEntry3.getVariable().getName().setValue(ContextEntryDefaultValueUtilities.getNewContextEntryName(context));
assertThat(contextEntry3.getVariable().getName().getValue()).isEqualTo(ContextEntryDefaultValueUtilities.PREFIX + "3");
}
use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry in project kie-wb-common by kiegroup.
the class ContextEntryDefaultValueUtilitiesTest method testGetNewContextEntryName.
@Test
public void testGetNewContextEntryName() {
final ContextEntry contextEntry1 = new ContextEntry() {
{
setVariable(new InformationItem());
}
};
context.getContextEntry().add(contextEntry1);
contextEntry1.getVariable().getName().setValue(ContextEntryDefaultValueUtilities.getNewContextEntryName(context));
assertThat(contextEntry1.getVariable().getName().getValue()).isEqualTo(ContextEntryDefaultValueUtilities.PREFIX + "1");
final ContextEntry contextEntry2 = new ContextEntry() {
{
setVariable(new InformationItem());
}
};
context.getContextEntry().add(contextEntry2);
contextEntry2.getVariable().getName().setValue(ContextEntryDefaultValueUtilities.getNewContextEntryName(context));
assertThat(contextEntry2.getVariable().getName().getValue()).isEqualTo(ContextEntryDefaultValueUtilities.PREFIX + "2");
}
use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry in project kie-wb-common by kiegroup.
the class ContextEntryDefaultValueUtilitiesTest method testGetNewContextEntryNameWithExistingContextEntries.
@Test
public void testGetNewContextEntryNameWithExistingContextEntries() {
final ContextEntry contextEntry1 = new ContextEntry() {
{
setVariable(new InformationItem());
}
};
context.getContextEntry().add(contextEntry1);
contextEntry1.getVariable().getName().setValue("entry");
final ContextEntry contextEntry2 = new ContextEntry() {
{
setVariable(new InformationItem());
}
};
context.getContextEntry().add(contextEntry2);
contextEntry2.getVariable().getName().setValue(ContextEntryDefaultValueUtilities.getNewContextEntryName(context));
assertThat(contextEntry2.getVariable().getName().getValue()).isEqualTo(ContextEntryDefaultValueUtilities.PREFIX + "1");
}
Aggregations