Search in sources :

Example 36 with RefactoringPageRow

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

the class FormDefinitionIndexerTest method testFormsIndexing.

@Test
public void testFormsIndexing() throws Exception {
    List<Path> pathList = new ArrayList<>();
    ioService().startBatch(ioService().getFileSystem(basePath.toUri()));
    for (String formFile : FORMS) {
        Path path = basePath.resolve(formFile);
        pathList.add(path);
        String formContent = loadText(formFile);
        ioService().write(path, formContent);
    }
    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 = getFormResources();
                if (response != null && response.getPageRowList() != null && response.getPageRowList().size() >= paths.length) {
                    break;
                }
            }
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
        assertNotNull(response);
        Set<RefactoringPageRow> result = new HashSet(response.getPageRowList());
        assertEquals(paths.length, result.size());
    }
    {
        final Set<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>() {

            {
                add(new ValueResourceIndexTerm("*", ResourceType.FORM, ValueIndexTerm.TermSearchType.WILDCARD));
            }
        };
        try {
            Set<RefactoringPageRow> response = new HashSet(service.query(FindFormDefinitionIdsQuery.NAME, queryTerms));
            assertNotNull(response);
            assertEquals(paths.length, response.size());
            for (String expectedId : FORMS) {
                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(Arrays.asList(FORMS).contains(rKey));
                        foundId = true;
                    }
                }
                if (!foundId) {
                    fail("FormDefinition with ID <" + expectedId + " not found in results for " + FindFormDefinitionIdsQuery.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) ArrayList(java.util.ArrayList) PageResponse(org.uberfire.paging.PageResponse) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) Map(java.util.Map) HashSet(java.util.HashSet) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest) Test(org.junit.Test)

Example 37 with RefactoringPageRow

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

the class ImpactAnalysisJavaFileTest method testQueryOperationRequest.

private void testQueryOperationRequest(QueryOperationRequest queryOpRequest) {
    List<RefactoringPageRow> response = service.queryToList(queryOpRequest);
    assertNotNull("Null PageResonse", response);
    assertNotNull("Null PageRefactoringRow list", response);
    assertEquals("Objects referencing " + AnnotationValuesAnnotation.class.getName(), 1, response.size());
    for (RefactoringPageRow row : response) {
        org.uberfire.backend.vfs.Path rowPath = (org.uberfire.backend.vfs.Path) row.getValue();
        logger.debug(rowPath.toURI());
    }
    Object pageRowValue = response.get(0).getValue();
    assertTrue("Expected a " + org.uberfire.backend.vfs.Path.class.getName() + ", not a " + pageRowValue.getClass().getSimpleName(), org.uberfire.backend.vfs.Path.class.isAssignableFrom(pageRowValue.getClass()));
    String fileName = ((org.uberfire.backend.vfs.Path) pageRowValue).getFileName();
    assertTrue("File does not end with '.java'", fileName.endsWith(".java"));
    assertEquals("File name", this.getClass().getSimpleName(), fileName.subSequence(0, fileName.indexOf(".java")));
}
Also used : Path(org.uberfire.java.nio.file.Path) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow)

Example 38 with RefactoringPageRow

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

the class DefaultResponseBuilder method buildResponse.

@Override
public List<RefactoringPageRow> buildResponse(final List<KObject> kObjects) {
    final List<RefactoringPageRow> result = new ArrayList<RefactoringPageRow>(kObjects.size());
    for (final KObject kObject : kObjects) {
        final Path path = Paths.convert(ioService.get(URI.create(kObject.getKey())));
        final RefactoringPathPageRow row = new RefactoringPathPageRow();
        row.setValue(path);
        result.add(row);
    }
    return result;
}
Also used : Path(org.uberfire.backend.vfs.Path) KObject(org.uberfire.ext.metadata.model.KObject) ArrayList(java.util.ArrayList) RefactoringPathPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPathPageRow) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow)

Example 39 with RefactoringPageRow

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

the class ProcessesDataServiceTest method setup.

@Before
public void setup() {
    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);
    tested = new ProcessesDataService(queryService, processesUpdatedEvent);
}
Also used : Path(org.uberfire.backend.vfs.Path) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProcessesDataService(org.kie.workbench.common.stunner.bpmn.project.backend.service.ProcessesDataService) RefactoringMapPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringMapPageRow) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) Before(org.junit.Before)

Example 40 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 PARENT_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) IndexingTest(org.kie.workbench.common.services.refactoring.backend.server.IndexingTest) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest) 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