Skip to content

Commit

Permalink
[kie-issues#853] Update DMN classes in the engine to 1.5 (apache#5669)
Browse files Browse the repository at this point in the history
* Add base for DMN 1.5 model classes.

* Add new attribute typeConstraint into the DMN 1.5 model.

* Copy dmndi model classes to 1.5 package.

* Add new attribute useAlternativeInputDataShape to the DMNDI model.

* Add new DMN 1.5 model classes to the reflect-config.json.

* Copy DMN marshalling classes from 1.4 to 1.5 package.

* Add DMNDI 1.5 converter classes.

* Fix imports in DMN backend converters for DMN 1.5.

* Update XML marshallers for DMN 1.5.

* Align UnmarshallMarshalTest

* Fix marshalling and unmarshalling of DMN 1.5.

* Add DMN 1.5 elements and attributes to marshalling tests.

* Update kie-dmn-core classes with DMN 1.5.

* Update tests in kie-dmn-core to DMN 1.5.

* Update kie-dmn-validation to DMN 1.5.

* Update kie-dmn-validation tests to DMN 1.5.

* Update kie-dmn-validation rules to DMN 1.5.
  • Loading branch information
baldimir authored and rgdoliveira committed Feb 5, 2024
1 parent 81c9e6a commit 1e8e025
Show file tree
Hide file tree
Showing 717 changed files with 21,097 additions and 1,255 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.kie.dmn.backend.marshalling.v1_5.xstream;

import com.thoughtworks.xstream.XStream;

public abstract class ArtifactConverter extends DMNElementConverter {

public ArtifactConverter(XStream xstream) {
super(xstream);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.kie.dmn.backend.marshalling.v1_5.xstream;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import org.kie.dmn.model.api.Association;
import org.kie.dmn.model.api.AssociationDirection;
import org.kie.dmn.model.api.DMNElementReference;
import org.kie.dmn.model.api.DMNModelInstrumentedBase;
import org.kie.dmn.model.v1_5.TAssociation;

public class AssociationConverter extends ArtifactConverter {
public static final String TARGET_REF = "targetRef";
public static final String SOURCE_REF = "sourceRef";
public static final String ASSOCIATION_DIRECTION = "associationDirection";

public AssociationConverter(XStream xstream) {
super(xstream);
}

@Override
protected DMNModelInstrumentedBase createModelObject() {
return new TAssociation();
}

@Override
public boolean canConvert(Class clazz) {
return clazz.equals(TAssociation.class);
}

@Override
protected void assignChildElement(Object parent, String nodeName, Object child) {
Association a = (Association) parent;

if( SOURCE_REF.equals( nodeName ) ) {
a.setSourceRef( (DMNElementReference) child );
} else if( TARGET_REF.equals( nodeName ) ) {
a.setTargetRef( (DMNElementReference) child );
} else {
super.assignChildElement( parent, nodeName, child );
}
}

@Override
protected void assignAttributes(HierarchicalStreamReader reader, Object parent) {
super.assignAttributes(reader, parent);
Association a = (Association) parent;

String associationDirectionValue = reader.getAttribute(ASSOCIATION_DIRECTION);

if (associationDirectionValue != null) a.setAssociationDirection(AssociationDirection.fromValue(associationDirectionValue));
}

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
Association a = (Association) parent;

writeChildrenNode(writer, context, a.getSourceRef(), SOURCE_REF);
writeChildrenNode(writer, context, a.getTargetRef(), TARGET_REF);
}

@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
super.writeAttributes(writer, parent);
Association a = (Association) parent;

if (a.getAssociationDirection() != null) writer.addAttribute(ASSOCIATION_DIRECTION, a.getAssociationDirection().value());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.kie.dmn.backend.marshalling.v1_5.xstream;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import org.kie.dmn.model.api.AuthorityRequirement;
import org.kie.dmn.model.api.DMNElementReference;
import org.kie.dmn.model.api.DMNModelInstrumentedBase;
import org.kie.dmn.model.v1_5.TAuthorityRequirement;

public class AuthorityRequirementConverter extends DMNElementConverter {
public static final String REQUIRED_AUTHORITY = "requiredAuthority";
public static final String REQUIRED_INPUT = "requiredInput";
public static final String REQUIRED_DECISION = "requiredDecision";

@Override
protected void assignChildElement(Object parent, String nodeName, Object child) {
AuthorityRequirement ar = (AuthorityRequirement) parent;

if (REQUIRED_DECISION.equals(nodeName)) {
ar.setRequiredDecision( (DMNElementReference) child );
} else if (REQUIRED_INPUT.equals(nodeName)) {
ar.setRequiredInput( (DMNElementReference) child );
} else if (REQUIRED_AUTHORITY.equals(nodeName)) {
ar.setRequiredAuthority( (DMNElementReference) child );
} else {
super.assignChildElement(parent, nodeName, child);
}
}

@Override
protected void assignAttributes(HierarchicalStreamReader reader, Object parent) {
super.assignAttributes(reader, parent);

// no attributes.
}

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
AuthorityRequirement ar = (AuthorityRequirement) parent;

if (ar.getRequiredDecision() != null) writeChildrenNode(writer, context, ar.getRequiredDecision(), REQUIRED_DECISION);
if (ar.getRequiredInput() != null) writeChildrenNode(writer, context, ar.getRequiredInput(), REQUIRED_INPUT);
if (ar.getRequiredAuthority() != null) writeChildrenNode(writer, context, ar.getRequiredAuthority(), REQUIRED_AUTHORITY);
}

@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
super.writeAttributes(writer, parent);

// no attributes.
}

public AuthorityRequirementConverter(XStream xstream) {
super(xstream);
}

@Override
protected DMNModelInstrumentedBase createModelObject() {
return new TAuthorityRequirement();
}

@Override
public boolean canConvert(Class clazz) {
return clazz.equals(TAuthorityRequirement.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.kie.dmn.backend.marshalling.v1_5.xstream;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import org.kie.dmn.model.api.Binding;
import org.kie.dmn.model.api.DMNModelInstrumentedBase;
import org.kie.dmn.model.api.Expression;
import org.kie.dmn.model.api.InformationItem;
import org.kie.dmn.model.v1_5.TBinding;

public class BindingConverter extends DMNModelInstrumentedBaseConverter {
public static final String EXPRESSION = "expression";
public static final String PARAMETER = "parameter";

@Override
protected void assignChildElement(Object parent, String nodeName, Object child) {
Binding b = (Binding) parent;

if (PARAMETER.equals(nodeName)) {
b.setParameter((InformationItem) child);
} else if (child instanceof Expression) {
b.setExpression((Expression) child);
} else {
super.assignChildElement(parent, nodeName, child);
}
}

@Override
protected void assignAttributes(HierarchicalStreamReader reader, Object parent) {
super.assignAttributes(reader, parent);

// no attributes.
}

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
Binding b = (Binding) parent;

writeChildrenNode(writer, context, b.getParameter(), PARAMETER);
if (b.getExpression() != null) writeChildrenNode(writer, context, b.getExpression(), MarshallingUtils.defineExpressionNodeName(xstream, b.getExpression()));
}

@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
super.writeAttributes(writer, parent);

// no attributes.
}

public BindingConverter(XStream xstream) {
super(xstream);
}

@Override
protected DMNModelInstrumentedBase createModelObject() {
return new TBinding();
}

@Override
public boolean canConvert(Class clazz) {
return clazz.equals(TBinding.class);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.kie.dmn.backend.marshalling.v1_5.xstream;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import org.kie.dmn.backend.marshalling.v1_5.xstream.DMNModelInstrumentedBaseConverter;
import org.kie.dmn.backend.marshalling.v1_5.xstream.FormatUtils;
import org.kie.dmn.model.api.DMNModelInstrumentedBase;
import org.kie.dmn.model.api.dmndi.Bounds;

public class BoundsConverter extends DMNModelInstrumentedBaseConverter {


private static final String HEIGHT = "height";
private static final String WIDTH = "width";
private static final String Y = "y";
private static final String X = "x";

public BoundsConverter(XStream xstream) {
super(xstream);
}

@Override
protected void assignChildElement(Object parent, String nodeName, Object child) {
super.assignChildElement(parent, nodeName, child);
}

@Override
protected void assignAttributes(HierarchicalStreamReader reader, Object parent) {
super.assignAttributes(reader, parent);
Bounds abs = (Bounds) parent;

abs.setX(Double.valueOf(reader.getAttribute(X)));
abs.setY(Double.valueOf(reader.getAttribute(Y)));
abs.setWidth(Double.valueOf(reader.getAttribute(WIDTH)));
abs.setHeight(Double.valueOf(reader.getAttribute(HEIGHT)));
}

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
}

@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
super.writeAttributes(writer, parent);

Bounds abs = (Bounds) parent;

writer.addAttribute(X, org.kie.dmn.backend.marshalling.v1_5.xstream.FormatUtils.manageDouble(abs.getX()));
writer.addAttribute(Y, org.kie.dmn.backend.marshalling.v1_5.xstream.FormatUtils.manageDouble(abs.getY()));
writer.addAttribute(WIDTH, org.kie.dmn.backend.marshalling.v1_5.xstream.FormatUtils.manageDouble(abs.getWidth()));
writer.addAttribute(HEIGHT, FormatUtils.manageDouble(abs.getHeight()));
}

@Override
protected DMNModelInstrumentedBase createModelObject() {
return new org.kie.dmn.model.v1_5.dmndi.Bounds();
}

@Override
public boolean canConvert(Class type) {
return type.equals(org.kie.dmn.model.v1_5.dmndi.Bounds.class);
}

}
Loading

0 comments on commit 1e8e025

Please sign in to comment.