use of org.kie.workbench.common.dmn.api.definition.model.IsInformationItem in project kie-wb-common by kiegroup.
the class DMNIncludedNodeFactory method withNamespace.
private DRGElement withNamespace(final DRGElement drgElement, final IncludedModel includeModel) {
final String modelName = includeModel.getModelName();
drgElement.setName(new Name(modelName + "." + drgElement.getName().getValue()));
drgElement.setAllowOnlyVisualChange(true);
if (drgElement instanceof HasVariable) {
final HasVariable hasVariable = (HasVariable) drgElement;
final IsInformationItem variable = hasVariable.getVariable();
final QName qName = variable.getTypeRef();
if (qName != null && !isBuiltInType(qName.getLocalPart())) {
final QName typeRef = new QName(qName.getNamespaceURI(), modelName + "." + qName.getLocalPart(), qName.getPrefix());
setVariable(hasVariable, variable, typeRef);
}
}
return drgElement;
}
use of org.kie.workbench.common.dmn.api.definition.model.IsInformationItem in project kie-wb-common by kiegroup.
the class DMNIncludedModelHandler method updateDRGElementsVariableAndId.
private void updateDRGElementsVariableAndId(final String oldModelName, final String newModelName) {
dmnGraphUtils.getModelDRGElements().forEach(drgElement -> {
final Id oldId = drgElement.getId();
if (oldId.getValue().startsWith(oldModelName)) {
final String newId = oldId.getValue().replaceAll("^" + oldModelName, newModelName);
drgElement.setId(new Id(newId));
}
if (drgElement instanceof HasVariable) {
final HasVariable hasVariable = (HasVariable) drgElement;
final IsInformationItem variable = hasVariable.getVariable();
final QName typeRef = variable.getTypeRef();
final String oldType = typeRef.getLocalPart();
if (oldType.startsWith(oldModelName)) {
final String newType = oldType.replaceAll("^" + oldModelName, newModelName);
variable.setTypeRef(new QName(typeRef.getNamespaceURI(), newType, typeRef.getPrefix()));
}
}
});
}
use of org.kie.workbench.common.dmn.api.definition.model.IsInformationItem in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricher method getOutputClauseName.
private Optional<String> getOutputClauseName(final HasVariable hasVariable) {
final IsInformationItem variable = hasVariable.getVariable();
if (variable instanceof InformationItem) {
return Optional.ofNullable((variable).getName().getValue());
}
final DMNModelInstrumentedBase base = hasVariable.asDMNModelInstrumentedBase().getParent();
final DMNModelInstrumentedBase parent = base.getParent();
if (parent instanceof HasName) {
return Optional.ofNullable(((HasName) parent).getName().getValue());
}
if (parent instanceof HasVariable) {
return getOutputClauseName((HasVariable) parent);
}
return Optional.empty();
}
use of org.kie.workbench.common.dmn.api.definition.model.IsInformationItem in project kie-wb-common by kiegroup.
the class DMNIncludedNodeFactoryTest method testDrgElementWithNamespace.
@Test
public void testDrgElementWithNamespace() {
final DRGElement drgElement = mock(DRGElement.class, withSettings().extraInterfaces(HasVariable.class));
final IncludedModel includedModel = mock(IncludedModel.class);
final DMNIncludedNodeFactory factory = mock(DMNIncludedNodeFactory.class);
final Id elementId = mock(Id.class);
final String theId = "theId";
final String theName = "theName";
final String tType = "tType";
final String namespaceUri = "namespaceUri";
final String prefix = "prefix";
final String modelName = "Model Name";
final Name elementName = mock(Name.class);
final IsInformationItem informationItem = mock(IsInformationItem.class);
final QName qName = mock(QName.class);
final Name createdName = mock(Name.class);
final QName typeRef = mock(QName.class);
when(includedModel.getModelName()).thenReturn(modelName);
when(elementId.getValue()).thenReturn(theId);
when(elementName.getValue()).thenReturn(theName);
when(drgElement.getName()).thenReturn(elementName);
when(drgElement.getId()).thenReturn(elementId);
when(((HasVariable) drgElement).getVariable()).thenReturn(informationItem);
when(qName.getLocalPart()).thenReturn(tType);
when(informationItem.getTypeRef()).thenReturn(qName);
when(qName.getPrefix()).thenReturn(prefix);
when(qName.getNamespaceURI()).thenReturn(namespaceUri);
when(factory.createName(drgElement, modelName)).thenReturn(createdName);
when(factory.createTypeRef(modelName, qName)).thenReturn(typeRef);
doCallRealMethod().when(factory).drgElementWithNamespace(drgElement, includedModel);
factory.drgElementWithNamespace(drgElement, includedModel);
verify(drgElement).setName(createdName);
verify(drgElement).setAllowOnlyVisualChange(true);
verify(factory).setVariable((HasVariable) drgElement, informationItem, typeRef);
}
Aggregations