-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JBPM-9597: [BPMN] Open subprocesses in a new editor (BC only) (#3596)
- Loading branch information
Showing
14 changed files
with
673 additions
and
2 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
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
31 changes: 31 additions & 0 deletions
31
...mn-client/src/main/java/org/kie/workbench/common/stunner/bpmn/client/util/GraphUtils.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,31 @@ | ||
/* | ||
* Copyright 2021 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.stunner.bpmn.client.util; | ||
|
||
import org.kie.workbench.common.stunner.bpmn.definition.ReusableSubprocess; | ||
import org.kie.workbench.common.stunner.core.graph.Element; | ||
import org.kie.workbench.common.stunner.core.graph.content.view.View; | ||
|
||
public class GraphUtils { | ||
|
||
@SuppressWarnings("unchecked") | ||
public static boolean isReusableSubProcess(final Element<?> element) { | ||
return null != element.asNode() && | ||
element.getContent() instanceof View && | ||
((Element<View<?>>) element).getContent().getDefinition() instanceof ReusableSubprocess; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...lient/src/test/java/org/kie/workbench/common/stunner/bpmn/client/util/GraphUtilsTest.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,65 @@ | ||
/* | ||
* Copyright 2021 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.stunner.bpmn.client.util; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.kie.workbench.common.stunner.bpmn.definition.ReusableSubprocess; | ||
import org.kie.workbench.common.stunner.bpmn.definition.UserTask; | ||
import org.kie.workbench.common.stunner.core.graph.Element; | ||
import org.kie.workbench.common.stunner.core.graph.content.Bounds; | ||
import org.kie.workbench.common.stunner.core.graph.content.view.View; | ||
import org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl; | ||
import org.kie.workbench.common.stunner.core.graph.impl.NodeImpl; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class GraphUtilsTest { | ||
|
||
@Test | ||
public void testContentIsNotSet() { | ||
Element<Object> element = mock(Element.class); | ||
assertFalse(GraphUtils.isReusableSubProcess(element)); | ||
} | ||
|
||
@Test | ||
public void testNonView() { | ||
Element<Object> element = new NodeImpl<>("UUID"); | ||
element.setContent(new Object()); | ||
assertFalse(GraphUtils.isReusableSubProcess(element)); | ||
} | ||
|
||
@Test | ||
public void testNonReusableSubprocess() { | ||
Element<View<UserTask>> element = new NodeImpl<>("UUID"); | ||
View<UserTask> userTaskView = new ViewImpl<>(new UserTask(), Bounds.create()); | ||
element.setContent(userTaskView); | ||
assertFalse(GraphUtils.isReusableSubProcess(element)); | ||
} | ||
|
||
@Test | ||
public void testReusableSubprocess() { | ||
Element<View<ReusableSubprocess>> element = new NodeImpl<>("UUID"); | ||
View<ReusableSubprocess> reusableSubprocessView = new ViewImpl<>(new ReusableSubprocess(), Bounds.create()); | ||
element.setContent(reusableSubprocessView); | ||
assertTrue(GraphUtils.isReusableSubProcess(element)); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...e/workbench/common/stunner/bpmn/project/service/ProjectOpenReusableSubprocessService.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,26 @@ | ||
/* | ||
* Copyright 2021 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.stunner.bpmn.project.service; | ||
|
||
import java.util.List; | ||
|
||
import org.jboss.errai.bus.server.annotations.Remote; | ||
|
||
@Remote | ||
public interface ProjectOpenReusableSubprocessService { | ||
List<String> openReusableSubprocess(String processId); | ||
} |
92 changes: 92 additions & 0 deletions
92
...common/stunner/bpmn/project/backend/service/ProjectOpenReusableSubprocessServiceImpl.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,92 @@ | ||
/* | ||
* Copyright 2021 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.stunner.bpmn.project.backend.service; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.function.Supplier; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
|
||
import org.jboss.errai.bus.server.annotations.Service; | ||
import org.kie.soup.commons.util.Sets; | ||
import org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm; | ||
import org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm; | ||
import org.kie.workbench.common.services.refactoring.service.RefactoringQueryService; | ||
import org.kie.workbench.common.services.refactoring.service.ResourceType; | ||
import org.kie.workbench.common.stunner.bpmn.project.backend.query.FindBpmnProcessIdsQuery; | ||
import org.kie.workbench.common.stunner.bpmn.project.service.ProjectOpenReusableSubprocessService; | ||
import org.uberfire.backend.vfs.Path; | ||
|
||
@ApplicationScoped | ||
@Service | ||
public class ProjectOpenReusableSubprocessServiceImpl implements ProjectOpenReusableSubprocessService { | ||
|
||
private final RefactoringQueryService queryService; | ||
private final Supplier<ResourceType> resourceType; | ||
private final Supplier<String> queryName; | ||
private final Set<ValueIndexTerm> queryTerms; | ||
|
||
// CDI proxy. | ||
protected ProjectOpenReusableSubprocessServiceImpl() { | ||
this(null); | ||
} | ||
|
||
@Inject | ||
public ProjectOpenReusableSubprocessServiceImpl(final RefactoringQueryService queryService) { | ||
this.queryService = queryService; | ||
this.resourceType = () -> ResourceType.BPMN2; | ||
this.queryName = () -> FindBpmnProcessIdsQuery.NAME; | ||
this.queryTerms = new Sets.Builder<ValueIndexTerm>() | ||
.add(new ValueResourceIndexTerm("*", | ||
resourceType.get(), | ||
ValueIndexTerm.TermSearchType.WILDCARD)) | ||
.build(); | ||
} | ||
|
||
String getQueryName() { | ||
return queryName.get(); | ||
} | ||
|
||
Set<ValueIndexTerm> createQueryTerms() { | ||
return queryTerms; | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public List<String> openReusableSubprocess(String processId) { | ||
List<String> answer = new ArrayList<>(); | ||
Map<String, Path> subprocesses = queryService | ||
.query(getQueryName(), createQueryTerms()) | ||
.stream() | ||
.map(row -> (Map<String, Path>) row.getValue()) | ||
.filter(row -> row.get(processId) != null) | ||
.findFirst() | ||
.orElse(null); | ||
|
||
if (subprocesses == null) { | ||
return answer; | ||
} | ||
|
||
answer.add(subprocesses.get(processId).getFileName()); | ||
answer.add(subprocesses.get(processId).toURI()); | ||
return answer; | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
...on/stunner/bpmn/project/backend/service/ProjectOpenReusableSubprocessServiceImplTest.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 2021 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.stunner.bpmn.project.backend.service; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow; | ||
import org.kie.workbench.common.services.refactoring.service.RefactoringQueryService; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.uberfire.backend.vfs.Path; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ProjectOpenReusableSubprocessServiceImplTest { | ||
|
||
private final static String PROCESS_ID = "processId"; | ||
private final static String NOT_REGISTERED_PROCESS_ID = "not_registered_process_id"; | ||
private final static String PROCESS_FILE_NAME = "File Name"; | ||
private final static String PROCESS_URI = "URI"; | ||
|
||
@Mock | ||
private RefactoringQueryService serviceQuery; | ||
@Mock | ||
private Path path; | ||
|
||
private ProjectOpenReusableSubprocessServiceImpl service; | ||
private List<RefactoringPageRow> rows; | ||
|
||
@Before | ||
public void setUp() { | ||
when(path.getFileName()).thenReturn(PROCESS_FILE_NAME); | ||
when(path.toURI()).thenReturn(PROCESS_URI); | ||
|
||
RefactoringPageRow<Map<String, Path>> row = new RefactoringPageRow<Map<String, Path>>() { | ||
@Override | ||
public void setValue(Map<String, Path> value) { | ||
super.setValue(value); | ||
} | ||
|
||
@Override | ||
public Map<String, Path> getValue() { | ||
Map<String, Path> subprocess = new HashMap<>(); | ||
subprocess.put(PROCESS_ID, path); | ||
return subprocess; | ||
} | ||
}; | ||
|
||
rows = new ArrayList<>(); | ||
rows.add(row); | ||
|
||
service = new ProjectOpenReusableSubprocessServiceImpl(serviceQuery); | ||
} | ||
|
||
@Test | ||
public void testNotFound() { | ||
assertTrue(service.openReusableSubprocess(PROCESS_ID).isEmpty()); | ||
} | ||
|
||
@Test | ||
public void testReusableSubprocessFound() { | ||
when(serviceQuery.query(service.getQueryName(), service.createQueryTerms())).thenReturn(rows); | ||
|
||
List<String> answer = service.openReusableSubprocess(PROCESS_ID); | ||
assertEquals(2, answer.size()); | ||
assertEquals(PROCESS_FILE_NAME, answer.get(0)); | ||
assertEquals(PROCESS_URI, answer.get(1)); | ||
} | ||
|
||
@Test | ||
public void testProcessWithIdNotFound() { | ||
when(serviceQuery.query(service.getQueryName(), service.createQueryTerms())).thenReturn(rows); | ||
|
||
List<String> answer = service.openReusableSubprocess(NOT_REGISTERED_PROCESS_ID); | ||
assertEquals(0, answer.size()); | ||
} | ||
} |
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
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
Oops, something went wrong.