Search in sources :

Example 1 with ValuePartIndexTerm

use of org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePartIndexTerm in project kie-wb-common by kiegroup.

the class FindResourcePartsQueryValidIndexTermsTest method initExpectedValues.

private List<Pair<String, String>> initExpectedValues() {
    List<Pair<String, String>> expectedValues = new ArrayList<Pair<String, String>>();
    expectedValues.add(new Pair<String, String>(ResourceType.JAVA.toString(), "org.kie.workbench.common.screens.datamodeller.backend.server.indexing.Pojo1"));
    // identifying info
    String[] fieldNames = new String[] { "o_BigDecimal", "o_BigInteger", "o_Boolean", "o_Byte", "o_Character", "o_Date", "o_Double", "o_Float", "o_Integer", "o_Long", "o_Short", "o_String", "p_boolean", "p_byte", "p_char", "p_double", "p_float", "p_int", "p_long", "p_short" };
    for (String className : fieldNames) {
        ValuePartIndexTerm partTerm = new ValuePartIndexTerm(className, PartType.FIELD);
        expectedValues.add(new Pair<String, String>(partTerm.getTerm(), partTerm.getValue()));
    }
    // references
    String[] referencedClasses = new String[] { "java.util.Date", "java.io.Serializable", "java.math.BigDecimal", "java.lang.Boolean", "java.lang.Byte", "java.lang.Character", "java.lang.Double", "java.lang.Float", "java.lang.Integer", "java.lang.Long", "boolean", "byte", "char", "double", "float", "long", "short" };
    for (String className : referencedClasses) {
        ValueReferenceIndexTerm refTerm = new ValueReferenceIndexTerm(className, ResourceType.JAVA);
        expectedValues.add(new Pair<String, String>(refTerm.getTerm(), refTerm.getValue()));
    }
    return expectedValues;
}
Also used : ValueReferenceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm) ArrayList(java.util.ArrayList) ValuePartIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePartIndexTerm) Pair(org.uberfire.commons.data.Pair)

Example 2 with ValuePartIndexTerm

use of org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePartIndexTerm in project kie-wb-common by kiegroup.

the class FindResourcePartsQueryValidIndexTermsTest method testIndexJavaFilesAndFindResourcePartsQuery.

@Test
public void testIndexJavaFilesAndFindResourcePartsQuery() throws Exception {
    // setup
    ioService();
    // Add test files
    String pojo1FileName = "Pojo1.java";
    Path path = basePath.resolve(pojo1FileName);
    String javaSourceText = loadText("../" + pojo1FileName);
    ioService().write(path, javaSourceText);
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath.getFileSystem()).getClusterId());
    {
        final Query query = new SingleTermQueryBuilder(new ValueResourceIndexTerm("*", ResourceType.JAVA, TermSearchType.WILDCARD)).build();
        List<KObject> hits = getConfig().getIndexProvider().findByQuery(index, query, 10);
        assertEquals(1, hits.size());
        List<Pair<String, String>> expectedValues = initExpectedValues();
        KObject doc = null;
        for (KObject kObject : hits) {
            doc = kObject;
            for (KProperty<?> property : doc.getProperties()) {
                String fieldVal = property.getValue().toString();
                if (fieldVal.startsWith("git://")) {
                    if (fieldVal.contains(pojo1FileName)) {
                        break;
                    }
                } else {
                    continue;
                }
            }
        }
        assertContains(expectedValues, doc);
    }
    {
        HashSet<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>();
        queryTerms.add(new ValuePartIndexTerm("o_BigDecimal", PartType.FIELD));
        final RefactoringPageRequest request = new RefactoringPageRequest(FindResourcePartsQuery.NAME, queryTerms, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull("No documents found!", response);
            assertEquals(1, response.getPageRowList().size());
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            fail("Could not execute query: " + e.getMessage());
        }
    }
    ;
}
Also used : Path(org.uberfire.java.nio.file.Path) ValueResourceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) Query(org.apache.lucene.search.Query) FindResourcePartsQuery(org.kie.workbench.common.services.refactoring.backend.server.query.standard.FindResourcePartsQuery) NamedQuery(org.kie.workbench.common.services.refactoring.backend.server.query.NamedQuery) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) KObject(org.uberfire.ext.metadata.model.KObject) SingleTermQueryBuilder(org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder) KProperty(org.uberfire.ext.metadata.model.KProperty) PageResponse(org.uberfire.paging.PageResponse) ArrayList(java.util.ArrayList) List(java.util.List) ValuePartIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePartIndexTerm) HashSet(java.util.HashSet) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest) Test(org.junit.Test)

Example 3 with ValuePartIndexTerm

use of org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePartIndexTerm in project kie-wb-common by kiegroup.

the class Resource method toIndexElements.

@Override
public List<KProperty<?>> toIndexElements() {
    final List<KProperty<?>> indexElements = new ArrayList<>();
    ValueResourceIndexTerm resTerm = new ValueResourceIndexTerm(resourceFQN, resourceType);
    indexElements.add(new KPropertyImpl<>(resTerm.getTerm(), resTerm.getValue()));
    parts.entrySet().forEach((part) -> {
        ValuePartIndexTerm partTerm = new ValuePartIndexTerm(part.getKey(), part.getValue());
        indexElements.add(new KPropertyImpl<>(partTerm.getTerm(), partTerm.getValue()));
    });
    return indexElements;
}
Also used : ValueResourceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm) KProperty(org.uberfire.ext.metadata.model.KProperty) ArrayList(java.util.ArrayList) ValuePartIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePartIndexTerm)

Aggregations

ArrayList (java.util.ArrayList)3 ValuePartIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePartIndexTerm)3 ValueResourceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm)2 KProperty (org.uberfire.ext.metadata.model.KProperty)2 HashSet (java.util.HashSet)1 List (java.util.List)1 Query (org.apache.lucene.search.Query)1 Test (org.junit.Test)1 BaseIndexingTest (org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)1 NamedQuery (org.kie.workbench.common.services.refactoring.backend.server.query.NamedQuery)1 SingleTermQueryBuilder (org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder)1 FindResourcePartsQuery (org.kie.workbench.common.services.refactoring.backend.server.query.standard.FindResourcePartsQuery)1 ValueIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm)1 ValueReferenceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm)1 RefactoringPageRequest (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest)1 Pair (org.uberfire.commons.data.Pair)1 KObject (org.uberfire.ext.metadata.model.KObject)1 Path (org.uberfire.java.nio.file.Path)1 PageResponse (org.uberfire.paging.PageResponse)1