Search in sources :

Example 11 with AnnisCorpus

use of annis.service.objects.AnnisCorpus in project ANNIS by korpling.

the class CorpusListPanel method initCorpusBrowser.

public void initCorpusBrowser(String topLevelCorpusName, final Button l) {
    AnnisCorpus c = ui.getQueryState().getAvailableCorpora().getItem(topLevelCorpusName).getBean();
    MetaDataPanel meta = new MetaDataPanel(c.getName());
    CorpusBrowserPanel browse = new CorpusBrowserPanel(c, ui.getQueryController());
    GridLayout infoLayout = new GridLayout(2, 2);
    infoLayout.setSizeFull();
    String corpusURL = Helper.generateCorpusLink(Sets.newHashSet(topLevelCorpusName));
    Label lblLink = new Label("Link to corpus: <a href=\"" + corpusURL + "\">" + corpusURL + "</a>", ContentMode.HTML);
    lblLink.setHeight("-1px");
    lblLink.setWidth("-1px");
    infoLayout.addComponent(meta, 0, 0);
    infoLayout.addComponent(browse, 1, 0);
    infoLayout.addComponent(lblLink, 0, 1, 1, 1);
    infoLayout.setRowExpandRatio(0, 1.0f);
    infoLayout.setColumnExpandRatio(0, 0.5f);
    infoLayout.setColumnExpandRatio(1, 0.5f);
    infoLayout.setComponentAlignment(lblLink, Alignment.MIDDLE_CENTER);
    Window window = new Window("Corpus information for " + c.getName() + " (ID: " + c.getId() + ")", infoLayout);
    window.setWidth(70, Unit.EM);
    window.setHeight(45, Unit.EM);
    window.setResizable(true);
    window.setModal(false);
    window.setResizeLazy(true);
    window.addCloseListener(new Window.CloseListener() {

        @Override
        public void windowClose(Window.CloseEvent e) {
            l.setEnabled(true);
        }
    });
    UI.getCurrent().addWindow(window);
    window.center();
}
Also used : Window(com.vaadin.ui.Window) GridLayout(com.vaadin.ui.GridLayout) CorpusBrowserPanel(annis.gui.CorpusBrowserPanel) MetaDataPanel(annis.gui.MetaDataPanel) AnnisCorpus(annis.service.objects.AnnisCorpus) Label(com.vaadin.ui.Label)

Example 12 with AnnisCorpus

use of annis.service.objects.AnnisCorpus in project ANNIS by korpling.

the class CorpusListPanel method getCorpusListFromServer.

private List<AnnisCorpus> getCorpusListFromServer() {
    List<AnnisCorpus> result = new LinkedList<>();
    try {
        WebResource rootRes = Helper.getAnnisWebResource();
        result = rootRes.path("query").path("corpora").get(new AnnisCorpusListType());
        return result;
    } catch (ClientHandlerException ex) {
        log.error(null, ex);
        Notification.show("Service not available: " + ex.getLocalizedMessage(), Notification.Type.TRAY_NOTIFICATION);
    } catch (UniformInterfaceException ex) {
        if (ex.getResponse().getStatus() == Response.Status.UNAUTHORIZED.getStatusCode()) {
            Notification.show("You are not authorized to get the corpus list.", ex.getMessage(), Notification.Type.WARNING_MESSAGE);
        } else if (ex.getResponse().getStatus() == Response.Status.FORBIDDEN.getStatusCode()) {
            Notification.show("Your account has expired.", ex.getMessage(), Notification.Type.WARNING_MESSAGE);
            return result;
        } else {
            log.error(null, ex);
            if (!AnnisBaseUI.handleCommonError(ex, "get corpus list")) {
                Notification.show("Remote exception: " + ex.getLocalizedMessage(), Notification.Type.TRAY_NOTIFICATION);
            }
        }
    }
    return null;
}
Also used : ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) AnnisCorpus(annis.service.objects.AnnisCorpus) WebResource(com.sun.jersey.api.client.WebResource) LinkedList(java.util.LinkedList)

Example 13 with AnnisCorpus

use of annis.service.objects.AnnisCorpus in project ANNIS by korpling.

the class TestListCorpusHelper method mapRow.

@Test
public void mapRow() throws SQLException {
    // stub a result set to return a single row
    ResultSet resultSet = mock(ResultSet.class);
    when(resultSet.getLong("id")).thenReturn(ID1);
    when(resultSet.getString("name")).thenReturn(NAME1);
    when(resultSet.getInt("text")).thenReturn(TEXT_COUNT1);
    when(resultSet.getInt("tokens")).thenReturn(TOKEN_COUNT1);
    // call and test
    AnnisCorpus annisCorpus = listCorpusHelper.mapRow(resultSet, 0);
    assertThat(annisCorpus.getId(), is(ID1));
    assertThat(annisCorpus.getName(), is(NAME1));
    assertThat(annisCorpus.getTextCount(), is(TEXT_COUNT1));
    assertThat(annisCorpus.getTokenCount(), is(TOKEN_COUNT1));
}
Also used : AnnisCorpus(annis.service.objects.AnnisCorpus) ResultSet(java.sql.ResultSet) Test(org.junit.Test)

Example 14 with AnnisCorpus

use of annis.service.objects.AnnisCorpus in project ANNIS by korpling.

the class QueryServiceImpl method singleCorpus.

@GET
@Path("corpora/{top}")
@Produces("application/xml")
public List<AnnisCorpus> singleCorpus(@PathParam("top") String toplevelName) {
    List<AnnisCorpus> result = new ArrayList<>();
    Subject user = SecurityUtils.getSubject();
    LinkedList<String> originalCorpusNames = new LinkedList<>();
    originalCorpusNames.add(toplevelName);
    List<Long> ids = queryDao.mapCorpusNamesToIds(originalCorpusNames);
    // also add all corpora that match the alias name
    ids.addAll(queryDao.mapCorpusAliasToIds(toplevelName));
    if (!ids.isEmpty()) {
        List<AnnisCorpus> allCorpora = queryDao.listCorpora(ids);
        for (AnnisCorpus c : allCorpora) {
            if (user.isPermitted("query:show:" + c.getName())) {
                result.add(c);
            }
        }
    }
    return result;
}
Also used : AnnisCorpus(annis.service.objects.AnnisCorpus) ArrayList(java.util.ArrayList) Subject(org.apache.shiro.subject.Subject) LinkedList(java.util.LinkedList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

AnnisCorpus (annis.service.objects.AnnisCorpus)14 LinkedList (java.util.LinkedList)5 WebResource (com.sun.jersey.api.client.WebResource)4 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)3 ArrayList (java.util.ArrayList)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Subject (org.apache.shiro.subject.Subject)3 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)2 Window (com.vaadin.ui.Window)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 Properties (java.util.Properties)2 CorpusBrowserPanel (annis.gui.CorpusBrowserPanel)1 CriticalServiceQueryException (annis.gui.CriticalServiceQueryException)1 MetaDataPanel (annis.gui.MetaDataPanel)1