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()));
}
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());
}
}
}
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());
}
}
;
}
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;
}
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;
}
Aggregations