Search in sources :

Example 11 with ItemReference

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"));
}
Also used : ItemReference(org.eclipse.che.api.project.shared.dto.ItemReference) LinkedHashSet(java.util.LinkedHashSet) ContainerResponse(org.everrest.core.impl.ContainerResponse) TreeElement(org.eclipse.che.api.project.shared.dto.TreeElement) Test(org.testng.annotations.Test)

Example 12 with ItemReference

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;
}
Also used : ItemReference(org.eclipse.che.api.project.shared.dto.ItemReference) ConflictException(org.eclipse.che.api.core.ConflictException) Searcher(org.eclipse.che.api.vfs.search.Searcher) ArrayList(java.util.ArrayList) NotFoundException(org.eclipse.che.api.core.NotFoundException) SearchResult(org.eclipse.che.api.vfs.search.SearchResult) QueryExpression(org.eclipse.che.api.vfs.search.QueryExpression) SearchResultEntry(org.eclipse.che.api.vfs.search.SearchResultEntry) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 13 with ItemReference

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);
    }
}
Also used : ItemReference(org.eclipse.che.api.project.shared.dto.ItemReference) Message(org.eclipse.che.ide.websocket.Message) MessageBuilder(org.eclipse.che.ide.websocket.MessageBuilder) WebSocketException(org.eclipse.che.ide.websocket.WebSocketException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with ItemReference

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());
        }
    });
}
Also used : ItemReference(org.eclipse.che.api.project.shared.dto.ItemReference) Command(com.google.gwt.user.client.Command) UiHandler(com.google.gwt.uibinder.client.UiHandler)

Example 15 with ItemReference

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"));
}
Also used : ItemReference(org.eclipse.che.api.project.shared.dto.ItemReference) LinkedHashSet(java.util.LinkedHashSet) ContainerResponse(org.everrest.core.impl.ContainerResponse) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Aggregations

ItemReference (org.eclipse.che.api.project.shared.dto.ItemReference)26 Test (org.testng.annotations.Test)22 ContainerResponse (org.everrest.core.impl.ContainerResponse)20 ArrayList (java.util.ArrayList)14 LinkedHashSet (java.util.LinkedHashSet)13 List (java.util.List)13 Collections.singletonList (java.util.Collections.singletonList)11 LinkedList (java.util.LinkedList)11 TreeElement (org.eclipse.che.api.project.shared.dto.TreeElement)4 Link (org.eclipse.che.api.core.rest.shared.dto.Link)2 UiHandler (com.google.gwt.uibinder.client.UiHandler)1 Command (com.google.gwt.user.client.Command)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 ConflictException (org.eclipse.che.api.core.ConflictException)1 NotFoundException (org.eclipse.che.api.core.NotFoundException)1 Function (org.eclipse.che.api.promises.client.Function)1