Search in sources :

Example 16 with ValueIndexTerm

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

the class LibraryServiceImpl method getProjectAssets.

@Override
public AssetQueryResult getProjectAssets(final ProjectAssetsQuery query) {
    checkNotNull("query", query);
    final boolean projectStillExists = ioService.exists(Paths.convert(query.getProject().getBranch().getPath()));
    if (!projectStillExists) {
        return AssetQueryResult.nonexistent();
    } else if (!indexOracle.isIndexed(query.getProject())) {
        return AssetQueryResult.unindexed();
    }
    final HashSet<ValueIndexTerm> queryTerms = buildProjectAssetsQuery(query);
    final PageResponse<RefactoringPageRow> findRulesByProjectQuery = refactoringQueryService.query(new RefactoringPageRequest(FindAllLibraryAssetsQuery.NAME, queryTerms, query.getStartIndex(), query.getAmount(), Boolean.TRUE));
    final List<FolderItem> assets = findRulesByProjectQuery.getPageRowList().stream().map(row -> {
        final Path path = (Path) row.getValue();
        return new FolderItem(path, path.getFileName(), FolderItemType.FILE, false, Paths.readLockedBy(path), Collections.<String>emptyList(), explorerServiceHelper.getRestrictedOperations(path));
    }).collect(Collectors.toList());
    return AssetQueryResult.normal(assets.stream().map(asset -> {
        AssetInfo info = null;
        try {
            final Map<String, Object> attributes = ioService.readAttributes(Paths.convert((Path) asset.getItem()));
            final FileTime lastModifiedFileTime = (FileTime) getAttribute(LibraryService.LAST_MODIFIED_TIME, attributes).get();
            final FileTime createdFileTime = (FileTime) getAttribute(LibraryService.CREATED_TIME, attributes).get();
            final Date lastModifiedTime = new Date(lastModifiedFileTime.toMillis());
            final Date createdTime = new Date(createdFileTime.toMillis());
            info = new AssetInfo(asset, lastModifiedTime, createdTime);
        } catch (NoSuchFileException nfe) {
            log.debug("File '" + asset.getFileName() + "' in LibraryIndex but not VFS. Suspected deletion. Skipping.");
        }
        return Optional.ofNullable(info);
    }).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList()));
}
Also used : FileTime(org.uberfire.java.nio.file.attribute.FileTime) Date(java.util.Date) ProjectAssetsQuery(org.kie.workbench.common.screens.library.api.ProjectAssetsQuery) GAV(org.guvnor.common.services.project.model.GAV) LoggerFactory(org.slf4j.LoggerFactory) AuthorizationManager(org.uberfire.security.authz.AuthorizationManager) OrganizationalUnitService(org.guvnor.structure.organizationalunit.OrganizationalUnitService) ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) FolderItem(org.kie.workbench.common.screens.explorer.model.FolderItem) Paths(org.uberfire.backend.server.util.Paths) LibraryValueFileNameIndexTerm(org.kie.workbench.common.screens.library.api.index.LibraryValueFileNameIndexTerm) POM(org.guvnor.common.services.project.model.POM) RepositoryEnvironmentConfigurations(org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations) RefactoringQueryService(org.kie.workbench.common.services.refactoring.service.RefactoringQueryService) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) Map(java.util.Map) Service(org.jboss.errai.bus.server.annotations.Service) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent) SessionInfo(org.uberfire.rpc.SessionInfo) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Repository(org.guvnor.structure.repositories.Repository) NewWorkspaceProjectUtils(org.kie.workbench.common.screens.projecteditor.util.NewWorkspaceProjectUtils) LibraryInfo(org.kie.workbench.common.screens.library.api.LibraryInfo) Collection(java.util.Collection) Set(java.util.Set) LibraryService(org.kie.workbench.common.screens.library.api.LibraryService) Collectors(java.util.stream.Collectors) NoSuchFileException(org.uberfire.java.nio.file.NoSuchFileException) List(java.util.List) DeploymentMode(org.guvnor.common.services.project.service.DeploymentMode) OrganizationalUnitRepositoryInfo(org.kie.workbench.common.screens.library.api.OrganizationalUnitRepositoryInfo) LibraryPreferences(org.kie.workbench.common.screens.library.api.preferences.LibraryPreferences) LibraryInternalPreferences(org.kie.workbench.common.screens.library.api.preferences.LibraryInternalPreferences) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) LibraryValueModuleRootPathIndexTerm(org.kie.workbench.common.screens.library.api.index.LibraryValueModuleRootPathIndexTerm) Pattern(java.util.regex.Pattern) PageResponse(org.uberfire.paging.PageResponse) AssetQueryResult(org.kie.workbench.common.screens.library.api.AssetQueryResult) AssetInfo(org.kie.workbench.common.screens.library.api.AssetInfo) PortablePreconditions.checkNotNull(org.kie.soup.commons.validation.PortablePreconditions.checkNotNull) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) LibraryValueFileExtensionIndexTerm(org.kie.workbench.common.screens.library.api.index.LibraryValueFileExtensionIndexTerm) ArrayList(java.util.ArrayList) Package(org.guvnor.common.services.project.model.Package) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Named(javax.inject.Named) SocialUserRepositoryAPI(org.ext.uberfire.social.activities.service.SocialUserRepositoryAPI) Path(org.uberfire.backend.vfs.Path) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) FolderItemType(org.kie.workbench.common.screens.explorer.model.FolderItemType) Logger(org.slf4j.Logger) RepositoryService(org.guvnor.structure.repositories.RepositoryService) ExplorerServiceHelper(org.kie.workbench.common.screens.explorer.backend.server.ExplorerServiceHelper) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) WorkspaceProjectService(org.guvnor.common.services.project.service.WorkspaceProjectService) ExamplesService(org.kie.workbench.common.screens.examples.service.ExamplesService) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) OrganizationalUnitAction(org.guvnor.structure.security.OrganizationalUnitAction) IOService(org.uberfire.io.IOService) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) ExampleProject(org.kie.workbench.common.screens.examples.model.ExampleProject) SocialUser(org.ext.uberfire.social.activities.model.SocialUser) Collections(java.util.Collections) Path(org.uberfire.backend.vfs.Path) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) Optional(java.util.Optional) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) NoSuchFileException(org.uberfire.java.nio.file.NoSuchFileException) FileTime(org.uberfire.java.nio.file.attribute.FileTime) AssetInfo(org.kie.workbench.common.screens.library.api.AssetInfo) Date(java.util.Date) FolderItem(org.kie.workbench.common.screens.explorer.model.FolderItem) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow)

Example 17 with ValueIndexTerm

use of org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm 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 18 with ValueIndexTerm

use of org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm 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 19 with ValueIndexTerm

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

the class RefactoringQueryServiceImpl method convertToRefactoringPageRequest.

private RefactoringPageRequest convertToRefactoringPageRequest(QueryOperationRequest refOpRequest) {
    RefactoringPageRequest request = new RefactoringPageRequest(FindAllChangeImpactQuery.NAME, new HashSet<>(), refOpRequest.getStartRowIndex(), refOpRequest.getPageSize());
    request.getQueryTerms().addAll(refOpRequest.getQueryTerms());
    // add project info
    String projectName = refOpRequest.getModuleName();
    if (projectName != null && projectName != QueryOperationRequest.ALL) {
        ValueModuleNameIndexTerm valueIndexTerm = new ValueModuleNameIndexTerm(projectName);
        Set<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>(1);
        queryTerms.add(valueIndexTerm);
        request.getQueryTerms().addAll(queryTerms);
    }
    String projectRootPathURI = refOpRequest.getModuleRootPathURI();
    if (projectRootPathURI != null && projectRootPathURI != QueryOperationRequest.ALL) {
        ValueModuleRootPathIndexTerm valueIndexTerm = new ValueModuleRootPathIndexTerm(projectRootPathURI);
        Set<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>(1);
        queryTerms.add(valueIndexTerm);
        request.getQueryTerms().addAll(queryTerms);
    }
    String branchName = refOpRequest.getBranchName();
    if (branchName != null && branchName != QueryOperationRequest.ALL) {
        ValueBranchNameIndexTerm valueIndexTerm = new ValueBranchNameIndexTerm(branchName);
        Set<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>(1);
        queryTerms.add(valueIndexTerm);
        request.getQueryTerms().addAll(queryTerms);
    }
    return request;
}
Also used : RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) ValueBranchNameIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueBranchNameIndexTerm) ValueModuleRootPathIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueModuleRootPathIndexTerm) ValueModuleNameIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueModuleNameIndexTerm) HashSet(java.util.HashSet)

Example 20 with ValueIndexTerm

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

the class AbstractQueryBuilder method getQuery.

public Query getQuery(ValueIndexTerm valueTerm) {
    final String text = getText(valueTerm);
    Term term = new Term(valueTerm.getTerm(), text);
    Query termQuery;
    switch(valueTerm.getSearchType()) {
        case PREFIX:
            termQuery = new PrefixQuery(term);
            break;
        case WILDCARD:
            termQuery = new WildcardQuery(term);
            break;
        case REGEXP:
            // NONE until there's a specific reason to use extend regex syntax
            termQuery = new RegexpQuery(term, RegExp.NONE);
            break;
        case NORMAL:
            termQuery = new TermQuery(term);
            break;
        default:
            throw new UnsupportedOperationException(ValueIndexTerm.TermSearchType.class.getSimpleName() + " value " + valueTerm.getSearchType().toString() + " is unsupported!");
    }
    return termQuery;
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) TermQuery(org.apache.lucene.search.TermQuery) Query(org.apache.lucene.search.Query) TermQuery(org.apache.lucene.search.TermQuery) RegexpQuery(org.apache.lucene.search.RegexpQuery) PrefixQuery(org.apache.lucene.search.PrefixQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) PrefixQuery(org.apache.lucene.search.PrefixQuery) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) Term(org.apache.lucene.index.Term) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) RegexpQuery(org.apache.lucene.search.RegexpQuery)

Aggregations

ValueIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm)23 HashSet (java.util.HashSet)13 Test (org.junit.Test)12 ValueResourceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm)10 RefactoringPageRequest (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest)8 RefactoringPageRow (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow)8 BaseIndexingTest (org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)7 Path (org.uberfire.java.nio.file.Path)6 ArrayList (java.util.ArrayList)5 LibraryValueModuleRootPathIndexTerm (org.kie.workbench.common.screens.library.api.index.LibraryValueModuleRootPathIndexTerm)5 ValueSharedPartIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueSharedPartIndexTerm)5 PageResponse (org.uberfire.paging.PageResponse)5 Map (java.util.Map)4 Term (org.apache.lucene.index.Term)4 List (java.util.List)3 Set (java.util.Set)3 BooleanQuery (org.apache.lucene.search.BooleanQuery)3 Query (org.apache.lucene.search.Query)3 TermQuery (org.apache.lucene.search.TermQuery)3 Path (org.uberfire.backend.vfs.Path)3