Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DROOLS-3719: [DMN Designer] Included Models - Add the 'Included Model…
… dialog' to the 'Included Models tab' (#2562) DROOLS-3719: [DMN Designer] Included Models - Add the 'Included Model dialog' to the 'Included Models tab'
- Loading branch information
Showing
63 changed files
with
3,803 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...dmn-api/src/main/java/org/kie/workbench/common/dmn/api/editors/types/DMNIncludeModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright 2019 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed 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.workbench.common.dmn.api.editors.types; | ||
|
||
import org.jboss.errai.common.client.api.annotations.MapsTo; | ||
import org.jboss.errai.common.client.api.annotations.Portable; | ||
|
||
@Portable | ||
public class DMNIncludeModel { | ||
|
||
private String modelName; | ||
|
||
private String modelPackage; | ||
|
||
private final String path; | ||
|
||
private String namespace; | ||
|
||
public DMNIncludeModel(final @MapsTo("modelName") String modelName, | ||
final @MapsTo("modelPackage") String modelPackage, | ||
final @MapsTo("path") String path, | ||
final @MapsTo("namespace") String namespace) { | ||
this.modelName = modelName; | ||
this.modelPackage = modelPackage; | ||
this.path = path; | ||
this.namespace = namespace; | ||
} | ||
|
||
public String getModelName() { | ||
return modelName; | ||
} | ||
|
||
public String getModelPackage() { | ||
return modelPackage; | ||
} | ||
|
||
public String getPath() { | ||
return path; | ||
} | ||
|
||
public String getNamespace() { | ||
return namespace; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...src/main/java/org/kie/workbench/common/dmn/api/editors/types/DMNIncludeModelsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2019 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed 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.workbench.common.dmn.api.editors.types; | ||
|
||
import java.util.List; | ||
|
||
import org.guvnor.common.services.project.model.WorkspaceProject; | ||
import org.jboss.errai.bus.server.annotations.Remote; | ||
|
||
@Remote | ||
public interface DMNIncludeModelsService { | ||
|
||
List<DMNIncludeModel> loadModels(final WorkspaceProject rootPath); | ||
} |
145 changes: 145 additions & 0 deletions
145
...on-dmn-api/src/test/java/org/kie/workbench/common/dmn/api/definition/v1_1/ImportTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/* | ||
* Copyright 2019 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed 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.workbench.common.dmn.api.definition.v1_1; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.kie.workbench.common.dmn.api.property.dmn.Description; | ||
import org.kie.workbench.common.dmn.api.property.dmn.Id; | ||
import org.kie.workbench.common.dmn.api.property.dmn.Name; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotEquals; | ||
|
||
public class ImportTest { | ||
|
||
private Import import1; | ||
|
||
private Import import2; | ||
|
||
@Before | ||
public void setup() { | ||
import1 = new Import(); | ||
import2 = new Import(); | ||
import1.setId(new Id("123")); | ||
import2.setId(new Id("123")); | ||
} | ||
|
||
@Test | ||
public void testNotEqualsId() { | ||
|
||
import1.setId(new Id("123")); | ||
import2.setId(new Id("456")); | ||
|
||
assertNotEquals(import1, import2); | ||
} | ||
|
||
@Test | ||
public void testEqualsId() { | ||
assertEquals(import1, import2); | ||
} | ||
|
||
@Test | ||
public void testNotEqualsDescription() { | ||
|
||
import1.setDescription(new Description("desc1")); | ||
import2.setDescription(new Description("desc2")); | ||
|
||
assertNotEquals(import1, import2); | ||
} | ||
|
||
@Test | ||
public void testEqualsDescription() { | ||
|
||
import1.setDescription(new Description("desc")); | ||
import2.setDescription(new Description("desc")); | ||
|
||
assertEquals(import1, import2); | ||
} | ||
|
||
@Test | ||
public void testEqualsName() { | ||
|
||
import1.setName(new Name("name")); | ||
import2.setName(new Name("name")); | ||
|
||
assertEquals(import1, import2); | ||
} | ||
|
||
@Test | ||
public void testNotEqualsName() { | ||
|
||
import1.setName(new Name("name1")); | ||
import2.setName(new Name("name2")); | ||
|
||
assertNotEquals(import1, import2); | ||
} | ||
|
||
@Test | ||
public void testHashCodeWithTheSameId() { | ||
|
||
import1.setId(new Id("123")); | ||
import2.setId(new Id("123")); | ||
|
||
assertEquals(import1.hashCode(), import2.hashCode()); | ||
} | ||
|
||
@Test | ||
public void testHashCodeWithTheADifferentId() { | ||
|
||
import1.setId(new Id("123")); | ||
import2.setId(new Id("456")); | ||
|
||
assertNotEquals(import1.hashCode(), import2.hashCode()); | ||
} | ||
|
||
@Test | ||
public void testHashCodeWithTheSameName() { | ||
|
||
import1.setName(new Name("123")); | ||
import2.setName(new Name("123")); | ||
|
||
assertEquals(import1.hashCode(), import2.hashCode()); | ||
} | ||
|
||
@Test | ||
public void testHashCodeWithTheADifferentName() { | ||
|
||
import1.setName(new Name("123")); | ||
import2.setName(new Name("456")); | ||
|
||
assertNotEquals(import1.hashCode(), import2.hashCode()); | ||
} | ||
|
||
@Test | ||
public void testHashCodeWithTheSameDescription() { | ||
|
||
import1.setDescription(new Description("desc")); | ||
import2.setDescription(new Description("desc")); | ||
|
||
assertEquals(import1.hashCode(), import2.hashCode()); | ||
} | ||
|
||
@Test | ||
public void testHashCodeWithTheADifferentDescription() { | ||
|
||
import1.setDescription(new Description("desc1")); | ||
import2.setDescription(new Description("desc2")); | ||
|
||
assertNotEquals(import1.hashCode(), import2.hashCode()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
.../main/java/org/kie/workbench/common/dmn/backend/editors/types/DMNIncludeModelFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright 2019 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed 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.workbench.common.dmn.backend.editors.types; | ||
|
||
import java.util.Optional; | ||
import java.util.stream.StreamSupport; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.guvnor.common.services.project.model.Package; | ||
import org.kie.workbench.common.dmn.api.definition.v1_1.DMNDiagram; | ||
import org.kie.workbench.common.dmn.api.editors.types.DMNIncludeModel; | ||
import org.kie.workbench.common.dmn.backend.editors.types.exceptions.DMNIncludeModelCouldNotBeCreatedException; | ||
import org.kie.workbench.common.services.shared.project.KieModuleService; | ||
import org.kie.workbench.common.stunner.core.diagram.Diagram; | ||
import org.kie.workbench.common.stunner.core.diagram.Metadata; | ||
import org.kie.workbench.common.stunner.core.graph.Graph; | ||
import org.kie.workbench.common.stunner.core.graph.Node; | ||
import org.kie.workbench.common.stunner.core.graph.content.definition.Definition; | ||
import org.kie.workbench.common.stunner.core.service.DiagramService; | ||
import org.uberfire.backend.vfs.Path; | ||
|
||
public class DMNIncludeModelFactory { | ||
|
||
private static final String DEFAULT_PACKAGE_NAME = ""; | ||
|
||
private final DiagramService diagramService; | ||
|
||
private final KieModuleService moduleService; | ||
|
||
@Inject | ||
public DMNIncludeModelFactory(final DiagramService diagramService, | ||
final KieModuleService moduleService) { | ||
this.diagramService = diagramService; | ||
this.moduleService = moduleService; | ||
} | ||
|
||
public DMNIncludeModel create(final Path path) throws DMNIncludeModelCouldNotBeCreatedException { | ||
try { | ||
|
||
final String fileName = path.getFileName(); | ||
final String modelPackage = getPackage(path); | ||
final String pathURI = path.toURI(); | ||
final String namespace = getNamespace(path); | ||
|
||
return new DMNIncludeModel(fileName, modelPackage, pathURI, namespace); | ||
} catch (final Exception e) { | ||
throw new DMNIncludeModelCouldNotBeCreatedException(); | ||
} | ||
} | ||
|
||
private String getPackage(final Path path) { | ||
return Optional | ||
.ofNullable(moduleService.resolvePackage(path)) | ||
.map(Package::getPackageName) | ||
.orElse(DEFAULT_PACKAGE_NAME); | ||
} | ||
|
||
String getNamespace(final Path path) { | ||
final Diagram<Graph, Metadata> diagram = getDiagramByPath(path); | ||
return getNamespace(diagram); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
String getNamespace(final Diagram diagram) { | ||
|
||
final Graph<?, Node> graph = diagram.getGraph(); | ||
|
||
return StreamSupport | ||
.stream(graph.nodes().spliterator(), false) | ||
.map(Node::getContent) | ||
.filter(c -> c instanceof Definition) | ||
.map(c -> (Definition) c) | ||
.map(Definition::getDefinition) | ||
.filter(d -> d instanceof DMNDiagram) | ||
.map(d -> (DMNDiagram) d) | ||
.findFirst() | ||
.map(DMNDiagram::getDefinitions) | ||
.map(definitions -> definitions.getNamespace().getValue()) | ||
.orElse(""); | ||
} | ||
|
||
private Diagram<Graph, Metadata> getDiagramByPath(final Path path) { | ||
return diagramService.getDiagramByPath(path); | ||
} | ||
} |
Oops, something went wrong.