Search in sources :

Example 1 with RefactoringPageRow

use of org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow in project kie-wb-common by kiegroup.

the class CalledElementFormProvider method getBusinessProcessIDs.

public Map<Object, String> getBusinessProcessIDs() {
    final Set<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>() {

        {
            add(new ValueResourceIndexTerm("*", ResourceType.BPMN2, ValueIndexTerm.TermSearchType.WILDCARD));
        }
    };
    List<RefactoringPageRow> results = queryService.query(FindBpmnProcessIdsQuery.NAME, queryTerms);
    Map<Object, String> businessProcessIDs = new TreeMap<Object, String>();
    for (RefactoringPageRow row : results) {
        Map<String, Path> mapRow = (Map<String, Path>) row.getValue();
        for (String rKey : mapRow.keySet()) {
            businessProcessIDs.put(rKey, rKey);
        }
    }
    return businessProcessIDs;
}
Also used : Path(org.uberfire.backend.vfs.Path) ValueResourceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) TreeMap(java.util.TreeMap) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) TreeMap(java.util.TreeMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with RefactoringPageRow

use of org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow in project kie-wb-common by kiegroup.

the class BpmnFileIndexerTest method testBpmnIndexing.

@Test
public void testBpmnIndexing() throws Exception {
    List<Path> pathList = new ArrayList<>();
    ioService().startBatch(ioService().getFileSystem(basePath.toUri()));
    for (int i = 0; i < BPMN_FILES.length; ++i) {
        String bpmnFile = BPMN_FILES[i];
        if (bpmnFile.endsWith("bpmn")) {
            Path path = basePath.resolve(bpmnFile);
            pathList.add(path);
            String bpmnStr = loadText(bpmnFile);
            ioService().write(path, bpmnStr);
        }
    }
    ioService().endBatch();
    Path[] paths = pathList.toArray(new Path[pathList.size()]);
    {
        PageResponse<RefactoringPageRow> response = null;
        try {
            for (int i = 0; i < MAX_WAIT_TIMES; i++) {
                Thread.sleep(WAIT_TIME_MILLIS);
                response = queryBPMN2Resources();
                if (response != null && response.getPageRowList() != null && response.getPageRowList().size() >= paths.length) {
                    break;
                }
            }
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
        assertNotNull(response);
        assertEquals(paths.length, response.getPageRowList().size());
    }
    {
        QueryOperationRequest request = QueryOperationRequest.referencesSharedPart("*", PartType.RULEFLOW_GROUP, ValueIndexTerm.TermSearchType.WILDCARD).inAllModules().onAllBranches();
        try {
            final List<RefactoringPageRow> response = service.queryToList(request);
            assertNotNull(response);
            assertEquals(1, response.size());
            assertResponseContains(response, paths[4]);
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
    {
        QueryOperationRequest request = QueryOperationRequest.referencesSharedPart("MySignal", PartType.SIGNAL).inAllModules().onAllBranches();
        try {
            final List<RefactoringPageRow> response = service.queryToList(request);
            assertNotNull(response);
            assertEquals(1, response.size());
            assertResponseContains(response, paths[5]);
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
    {
        QueryOperationRequest request = QueryOperationRequest.referencesSharedPart("BrokenSignal", PartType.SIGNAL).inAllModules().onAllBranches();
        try {
            final List<RefactoringPageRow> response = service.queryToList(request);
            assertNotNull(response);
            assertEquals(1, response.size());
            assertResponseContains(response, paths[6]);
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
    {
        QueryOperationRequest request = QueryOperationRequest.referencesSharedPart("name", PartType.GLOBAL).inAllModules().onAllBranches();
        try {
            final List<RefactoringPageRow> response = service.queryToList(request);
            assertNotNull(response);
            assertEquals(2, response.size());
            assertResponseContains(response, paths[5]);
            assertResponseContains(response, paths[6]);
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
    {
        final Set<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>() {

            {
                add(new ValueResourceIndexTerm("*", ResourceType.BPMN2, ValueIndexTerm.TermSearchType.WILDCARD));
            }
        };
        try {
            List<RefactoringPageRow> response = service.query(FindBpmnProcessIdsQuery.NAME, queryTerms);
            assertNotNull(response);
            assertEquals(paths.length, response.size());
            for (String expectedId : PROCESS_IDS) {
                boolean foundId = false;
                for (RefactoringPageRow row : response) {
                    Map<String, org.uberfire.backend.vfs.Path> mapRow = (Map<String, org.uberfire.backend.vfs.Path>) row.getValue();
                    for (String rKey : mapRow.keySet()) {
                        assertTrue(PROCESS_IDS.contains(rKey));
                        foundId = true;
                    }
                }
                if (!foundId) {
                    fail("Process with ID <" + expectedId + " not found in results for " + FindBpmnProcessIdsQuery.NAME);
                }
            }
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) ValueResourceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm) HashSet(java.util.HashSet) Set(java.util.Set) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) QueryOperationRequest(org.kie.workbench.common.services.refactoring.service.impact.QueryOperationRequest) ArrayList(java.util.ArrayList) PageResponse(org.uberfire.paging.PageResponse) ArrayList(java.util.ArrayList) List(java.util.List) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) Map(java.util.Map) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest) Test(org.junit.Test)

Example 3 with RefactoringPageRow

use of org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow in project kie-wb-common by kiegroup.

the class CalledElementFormProviderTest method setup.

@Before
public void setup() {
    calledElementFormProvider.setQueryService(queryService);
    List<RefactoringPageRow> results = new ArrayList<RefactoringPageRow>();
    RefactoringMapPageRow refactoringMapPageRow = new RefactoringMapPageRow();
    Map<String, Path> map = new HashMap<String, Path>();
    map.put(ID1, path1);
    map.put(ID2, path2);
    refactoringMapPageRow.setValue(map);
    results.add(refactoringMapPageRow);
    when(queryService.query(anyString(), anyObject())).thenReturn(results);
}
Also used : Path(org.uberfire.backend.vfs.Path) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RefactoringMapPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringMapPageRow) Matchers.anyString(org.mockito.Matchers.anyString) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) Before(org.junit.Before)

Example 4 with RefactoringPageRow

use of org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow in project kie-wb-common by kiegroup.

the class DMNPathsHelperImplTest method doTestGetPathsWhenWorkspaceProjectIsNotNull.

private void doTestGetPathsWhenWorkspaceProjectIsNotNull(final Function<WorkspaceProject, List<Path>> paths) {
    final Path rootPath = mock(Path.class);
    final String uri = "/src/path//project/root";
    final RefactoringPageRow row1 = mock(RefactoringPageRow.class);
    final RefactoringPageRow row2 = mock(RefactoringPageRow.class);
    final RefactoringPageRow row3 = mock(RefactoringPageRow.class);
    final List<RefactoringPageRow> rows = asList(row1, row2, row3);
    final Path path1 = mock(Path.class);
    final Path path2 = mock(Path.class);
    final Path path3 = mock(Path.class);
    when(workspaceProject.getRootPath()).thenReturn(rootPath);
    when(rootPath.toURI()).thenReturn(uri);
    when(refactoringQueryService.query(any(RefactoringPageRequest.class))).thenReturn(pageResponse);
    when(pageResponse.getPageRowList()).thenReturn(rows);
    when(row1.getValue()).thenReturn(path1);
    when(row2.getValue()).thenReturn(path2);
    when(row3.getValue()).thenReturn(path3);
    final List<Path> result = paths.apply(workspaceProject);
    assertEquals(3, result.size());
    assertEquals(path1, result.get(0));
    assertEquals(path2, result.get(1));
    assertEquals(path3, result.get(2));
}
Also used : Path(org.uberfire.backend.vfs.Path) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow)

Example 5 with RefactoringPageRow

use of org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow in project kie-wb-common by kiegroup.

the class FindAllLibraryAssetsSortedQueryTest method listAllInProjectSortedPaged.

@Test
public void listAllInProjectSortedPaged() throws IOException, InterruptedException {
    setUp(TEST_PROJECT_ROOT1);
    final RefactoringPageRequest request1 = new RefactoringPageRequest(FindAllLibraryAssetsQuery.NAME, new HashSet<ValueIndexTerm>() {

        {
            add(new LibraryValueRepositoryRootIndexTerm(getRepositoryRootPath(), TermSearchType.NORMAL));
        }
    }, 0, 6);
    final PageResponse<RefactoringPageRow> response1 = service.query(request1);
    assertNotNull(response1);
    // Remove duplicates and sort file names alphabetically
    Set<String> resultSet1 = new TreeSet<>();
    for (RefactoringPageRow row : response1.getPageRowList()) {
        String fileName = ((Path) row.getValue()).getFileName();
        System.out.println(fileName);
        resultSet1.add(fileName);
    }
    String[] expectedResult1 = new String[] { ".gitkeep", "DRL4.drl", "drl1.drl", "drl2.ext2", "drl3.ext3" };
    assertArrayEquals(expectedResult1, resultSet1.toArray());
    final RefactoringPageRequest request2 = new RefactoringPageRequest(FindAllLibraryAssetsQuery.NAME, new HashSet<ValueIndexTerm>() {

        {
            add(new LibraryValueRepositoryRootIndexTerm(getRepositoryRootPath(), TermSearchType.NORMAL));
        }
    }, 4, 4);
    final PageResponse<RefactoringPageRow> response2 = service.query(request2);
    assertNotNull(response2);
    // Remove duplicates and sort file names alphabetically
    Set<String> resultSet2 = new TreeSet<>();
    for (RefactoringPageRow row : response2.getPageRowList()) {
        String fileName = ((Path) row.getValue()).getFileName();
        System.out.println(fileName);
        resultSet2.add(fileName);
    }
    String[] expectedResult2 = new String[] { "DRL4.drl", "drl3.ext3", "functions.functions", "rule3.rule" };
    assertArrayEquals(expectedResult2, resultSet2.toArray());
}
Also used : Path(org.uberfire.backend.vfs.Path) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) TreeSet(java.util.TreeSet) LibraryValueRepositoryRootIndexTerm(org.kie.workbench.common.services.refactoring.backend.server.query.standard.LibraryValueRepositoryRootIndexTerm) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) Test(org.junit.Test)

Aggregations

RefactoringPageRow (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow)40 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)19 Path (org.uberfire.backend.vfs.Path)16 HashSet (java.util.HashSet)13 RefactoringPageRequest (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest)12 ValueIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm)11 PageResponse (org.uberfire.paging.PageResponse)10 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)8 Path (org.uberfire.java.nio.file.Path)7 Map (java.util.Map)6 LibraryValueRepositoryRootIndexTerm (org.kie.workbench.common.services.refactoring.backend.server.query.standard.LibraryValueRepositoryRootIndexTerm)6 ValueResourceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm)5 Set (java.util.Set)4 Branch (org.guvnor.structure.repositories.Branch)4 ProjectAssetsQuery (org.kie.workbench.common.screens.library.api.ProjectAssetsQuery)4 BaseIndexingTest (org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)4 RefactoringMapPageRow (org.kie.workbench.common.services.refactoring.model.query.RefactoringMapPageRow)4 KObject (org.uberfire.ext.metadata.model.KObject)4 List (java.util.List)3