Skip to content

Commit

Permalink
DROOLS-3719: [DMN Designer] Included Models - Add the 'Included Model…
Browse files Browse the repository at this point in the history
… 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
karreiro committed Apr 4, 2019
1 parent 7aad59e commit 34fea1f
Show file tree
Hide file tree
Showing 63 changed files with 3,803 additions and 30 deletions.
Expand Up @@ -81,6 +81,15 @@ public boolean equals(final Object o) {

final Import that = (Import) o;

if (id != null ? !id.equals(that.id) : that.id != null) {
return false;
}
if (description != null ? !description.equals(that.description) : that.description != null) {
return false;
}
if (name != null ? !name.equals(that.name) : that.name != null) {
return false;
}
if (namespace != null ? !namespace.equals(that.namespace) : that.namespace != null) {
return false;
}
Expand All @@ -92,7 +101,10 @@ public boolean equals(final Object o) {

@Override
public int hashCode() {
return HashUtil.combineHashCodes(namespace != null ? namespace.hashCode() : 0,
return HashUtil.combineHashCodes(id != null ? id.hashCode() : 0,
description != null ? description.hashCode() : 0,
name != null ? name.hashCode() : 0,
namespace != null ? namespace.hashCode() : 0,
locationURI != null ? locationURI.hashCode() : 0,
importType != null ? importType.hashCode() : 0);
}
Expand Down
@@ -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;
}
}
@@ -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);
}
@@ -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());
}
}
25 changes: 25 additions & 0 deletions kie-wb-common-dmn/kie-wb-common-dmn-backend/pom.xml
Expand Up @@ -55,6 +55,31 @@
<artifactId>kie-wb-common-stunner-backend-common</artifactId>
</dependency>

<dependency>
<groupId>org.kie.workbench.services</groupId>
<artifactId>kie-wb-common-refactoring-backend</artifactId>
</dependency>

<dependency>
<groupId>org.kie.workbench.services</groupId>
<artifactId>kie-wb-common-refactoring-api</artifactId>
</dependency>

<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
</dependency>

<dependency>
<groupId>org.uberfire</groupId>
<artifactId>uberfire-project-api</artifactId>
</dependency>

<dependency>
<groupId>org.kie.workbench.services</groupId>
<artifactId>kie-wb-common-services-api</artifactId>
</dependency>

<dependency>
<groupId>org.kie.workbench</groupId>
<artifactId>kie-wb-common-dmn-api</artifactId>
Expand Down
@@ -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);
}
}

0 comments on commit 34fea1f

Please sign in to comment.