use of org.eclipse.che.api.project.shared.dto.ItemReference in project che by eclipse.
the class ProjectServiceTest method testGetTreeWithDepthAndIncludeFiles.
@Test
public void testGetTreeWithDepthAndIncludeFiles() throws Exception {
RegisteredProject myProject = pm.getProject("my_project");
FolderEntry a = myProject.getBaseFolder().createFolder("a");
a.createFolder("b/c");
a.createFolder("x").createFile("test.txt", "test".getBytes(Charset.defaultCharset()));
ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/tree/my_project/a?depth=100&includeFiles=true", "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
TreeElement tree = (TreeElement) response.getEntity();
ItemReference a_node = tree.getNode();
assertEquals(a_node.getName(), "a");
List<TreeElement> children = tree.getChildren();
assertNotNull(children);
Set<String> names = new LinkedHashSet<>(4);
for (TreeElement subTree : children) {
ItemReference _node = subTree.getNode();
validateFolderLinks(_node);
String name = _node.getName();
names.add(name);
for (TreeElement subSubTree : subTree.getChildren()) {
ItemReference __node = subSubTree.getNode();
if (__node.getType().equals("folder")) {
validateFolderLinks(__node);
} else if (__node.getType().equals("file")) {
validateFileLinks(__node);
}
names.add(name + "/" + __node.getName());
}
}
Assert.assertTrue(names.contains("b"));
Assert.assertTrue(names.contains("x"));
Assert.assertTrue(names.contains("b/c"));
Assert.assertTrue(names.contains("x/test.txt"));
}
use of org.eclipse.che.api.project.shared.dto.ItemReference in project che by eclipse.
the class ProjectService method search.
@GET
@Path("/search/{path:.*}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Search for resources", notes = "Search for resources applying a number of search filters as query parameters", response = ItemReference.class, responseContainer = "List")
@ApiResponses({ @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 403, message = "User not authorized to call this operation"), @ApiResponse(code = 404, message = "Not found"), @ApiResponse(code = 409, message = "Conflict error"), @ApiResponse(code = 500, message = "Internal Server Error") })
public List<ItemReference> search(@ApiParam(value = "Path to resource, i.e. where to search?", required = true) @PathParam("path") String path, @ApiParam(value = "Resource name") @QueryParam("name") String name, @ApiParam(value = "Search keywords") @QueryParam("text") String text, @ApiParam(value = "Maximum items to display. If this parameter is dropped, there are no limits") @QueryParam("maxItems") @DefaultValue("-1") int maxItems, @ApiParam(value = "Skip count") @QueryParam("skipCount") int skipCount) throws NotFoundException, ForbiddenException, ConflictException, ServerException {
final Searcher searcher;
try {
searcher = projectManager.getSearcher();
} catch (NotFoundException e) {
LOG.warn(e.getLocalizedMessage());
return Collections.emptyList();
}
if (skipCount < 0) {
throw new ConflictException(String.format("Invalid 'skipCount' parameter: %d.", skipCount));
}
final QueryExpression expr = new QueryExpression().setPath(path.startsWith("/") ? path : ('/' + path)).setName(name).setText(text).setMaxItems(maxItems).setSkipCount(skipCount);
final SearchResult result = searcher.search(expr);
final List<SearchResultEntry> searchResultEntries = result.getResults();
final List<ItemReference> items = new ArrayList<>(searchResultEntries.size());
final FolderEntry root = projectManager.getProjectsRoot();
for (SearchResultEntry searchResultEntry : searchResultEntries) {
final VirtualFileEntry child = root.getChild(searchResultEntry.getFilePath());
if (child != null && child.isFile()) {
items.add(injectFileLinks(asDto((FileEntry) child)));
}
}
return items;
}
use of org.eclipse.che.api.project.shared.dto.ItemReference in project che by eclipse.
the class NavigateToFilePresenter method onFileNameChanged.
@Override
public void onFileNameChanged(String fileName) {
if (fileName.isEmpty()) {
view.showItems(new ArrayList<ItemReference>());
return;
}
// add '*' to allow search files by first letters
final String url = SEARCH_URL + "/?name=" + URL.encodePathSegment(fileName + "*");
final Message message = new MessageBuilder(GET, url).header(ACCEPT, APPLICATION_JSON).build();
final Unmarshallable<List<ItemReference>> unmarshaller = dtoUnmarshallerFactory.newWSListUnmarshaller(ItemReference.class);
try {
wsMessageBus.send(message, new RequestCallback<List<ItemReference>>(unmarshaller) {
@Override
protected void onSuccess(List<ItemReference> result) {
view.showItems(result);
}
@Override
protected void onFailure(Throwable exception) {
Log.error(getClass(), exception);
}
});
} catch (WebSocketException e) {
Log.error(getClass(), e);
}
}
use of org.eclipse.che.api.project.shared.dto.ItemReference in project che by eclipse.
the class NavigateToFileViewImpl method handleKeyDown.
@UiHandler("fileName")
void handleKeyDown(KeyDownEvent event) {
switch(event.getNativeKeyCode()) {
case KeyCodes.KEY_UP:
event.stopPropagation();
event.preventDefault();
if (list != null) {
list.getSelectionModel().selectPrevious();
}
return;
case KeyCodes.KEY_DOWN:
event.stopPropagation();
event.preventDefault();
if (list != null) {
list.getSelectionModel().selectNext();
}
return;
case KeyCodes.KEY_PAGEUP:
event.stopPropagation();
event.preventDefault();
if (list != null) {
list.getSelectionModel().selectPreviousPage();
}
return;
case KeyCodes.KEY_PAGEDOWN:
event.stopPropagation();
event.preventDefault();
if (list != null) {
list.getSelectionModel().selectNextPage();
}
return;
case KeyCodes.KEY_ENTER:
event.stopPropagation();
event.preventDefault();
ItemReference selectedItem = list.getSelectionModel().getSelectedItem();
if (selectedItem != null) {
delegate.onFileSelected(Path.valueOf(selectedItem.getPath()));
;
}
return;
case KeyCodes.KEY_ESCAPE:
event.stopPropagation();
event.preventDefault();
hidePopup();
return;
}
Scheduler.get().scheduleDeferred(new Command() {
@Override
public void execute() {
delegate.onFileNameChanged(fileName.getText());
}
});
}
use of org.eclipse.che.api.project.shared.dto.ItemReference in project che by eclipse.
the class ProjectServiceTest method testSearchParticularSequenceWords.
@SuppressWarnings("unchecked")
@Test
public void testSearchParticularSequenceWords() throws Exception {
String queryToSearch = "?text=" + URL_ENCODED_QUOTES + "To" + URL_ENCODED_SPACE + "be" + URL_ENCODED_SPACE + "or" + URL_ENCODED_SPACE + "not" + URL_ENCODED_SPACE + "to" + URL_ENCODED_SPACE + "be" + URL_ENCODED_QUOTES;
RegisteredProject myProject = pm.getProject("my_project");
myProject.getBaseFolder().createFolder("x/y").createFile("containsSearchText.txt", "To be or not to be that is the question".getBytes(Charset.defaultCharset()));
myProject.getBaseFolder().createFolder("a/b").createFile("test.txt", "Pay attention! To be or to be that is the question".getBytes(Charset.defaultCharset()));
myProject.getBaseFolder().createFolder("c").createFile("_test", "Pay attention! To be or to not be that is the question".getBytes(Charset.defaultCharset()));
ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/search/my_project" + queryToSearch, "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
List<ItemReference> result = (List<ItemReference>) response.getEntity();
assertEquals(result.size(), 1);
Set<String> paths = new LinkedHashSet<>(1);
paths.addAll(result.stream().map(ItemReference::getPath).collect(Collectors.toList()));
Assert.assertTrue(paths.contains("/my_project/x/y/containsSearchText.txt"));
}
Aggregations