Search in sources :

Example 1 with AnnisCorpus

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

the class QueryDaoImpl method getCorpusConfigurations.

@Override
public CorpusConfigMap getCorpusConfigurations() {
    List<AnnisCorpus> annisCorpora = listCorpora();
    CorpusConfigMap cConfigs = new CorpusConfigMap();
    if (annisCorpora != null) {
        for (AnnisCorpus c : annisCorpora) {
            try {
                Properties p = getCorpusConfiguration(c.getName());
                if (p != null) {
                    CorpusConfig corpusConfig = new CorpusConfig();
                    corpusConfig.setConfig(p);
                    cConfigs.put(c.getName(), corpusConfig);
                }
            } catch (FileNotFoundException ex) {
                log.error("no corpus.properties found for {}", c.getName());
            }
        }
    }
    return cConfigs;
}
Also used : AnnisCorpus(annis.service.objects.AnnisCorpus) CorpusConfigMap(annis.service.objects.CorpusConfigMap) FileNotFoundException(java.io.FileNotFoundException) Properties(java.util.Properties) CorpusConfig(annis.service.objects.CorpusConfig)

Example 2 with AnnisCorpus

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

the class QueryDaoImpl method mapCorpusIdsToNames.

@Override
public List<String> mapCorpusIdsToNames(List<Long> ids) {
    List<String> names = new ArrayList<>();
    Map<Long, String> corpusNamesById = new TreeMap<>();
    List<AnnisCorpus> corpora = listCorpora();
    for (AnnisCorpus corpus : corpora) {
        corpusNamesById.put(corpus.getId(), corpus.getName());
    }
    for (Long id : ids) {
        if (corpusNamesById.containsKey(id)) {
            names.add(corpusNamesById.get(id));
        }
    }
    return names;
}
Also used : AnnisCorpus(annis.service.objects.AnnisCorpus) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap)

Example 3 with AnnisCorpus

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

the class QueryDaoImpl method parseCorpusConfiguration.

private void parseCorpusConfiguration() {
    corpusConfiguration = new HashMap<>();
    try {
        List<AnnisCorpus> corpora = listCorpora();
        for (AnnisCorpus c : corpora) {
            // copy properties from map
            Properties p;
            try {
                p = getCorpusConfiguration(c.getName());
            } catch (FileNotFoundException ex) {
                log.warn("no config found for {}", c.getName());
                continue;
            }
            corpusConfiguration.put(c.getId(), p);
        }
    } catch (org.springframework.jdbc.CannotGetJdbcConnectionException ex) {
        log.warn("No corpus configuration loaded due to missing database connection.");
    } catch (org.springframework.jdbc.BadSqlGrammarException ex) {
        log.warn("Your database schema seems to be old. Probably you need to reinit it");
    }
}
Also used : AnnisCorpus(annis.service.objects.AnnisCorpus) FileNotFoundException(java.io.FileNotFoundException) Properties(java.util.Properties)

Example 4 with AnnisCorpus

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

the class QueryServiceImpl method corpora.

@GET
@Path("corpora")
@Produces("application/xml")
public List<AnnisCorpus> corpora() {
    List<AnnisCorpus> allCorpora = queryDao.listCorpora();
    List<AnnisCorpus> allowedCorpora = new LinkedList<>();
    // filter by which corpora the user is allowed to access
    Subject user = SecurityUtils.getSubject();
    for (AnnisCorpus c : allCorpora) {
        if (user.isPermitted("query:show:" + c.getName())) {
            allowedCorpora.add(c);
        }
    }
    return allowedCorpora;
}
Also used : AnnisCorpus(annis.service.objects.AnnisCorpus) LinkedList(java.util.LinkedList) Subject(org.apache.shiro.subject.Subject) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with AnnisCorpus

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

the class QueryServiceImpl method getExampleQueries.

/**
 * Fetches the example queries for a specific corpus.
 *
 * @param rawCorpusNames specifies the corpora the examples are fetched from.
 */
@GET
@Path("corpora/example-queries/")
@Produces(MediaType.APPLICATION_XML)
public List<ExampleQuery> getExampleQueries(@QueryParam("corpora") String rawCorpusNames) throws WebApplicationException {
    Subject user = SecurityUtils.getSubject();
    try {
        String[] corpusNames;
        if (rawCorpusNames != null) {
            corpusNames = rawCorpusNames.split(",");
        } else {
            List<AnnisCorpus> allCorpora = queryDao.listCorpora();
            corpusNames = new String[allCorpora.size()];
            for (int i = 0; i < corpusNames.length; i++) {
                corpusNames[i] = allCorpora.get(i).getName();
            }
        }
        List<String> allowedCorpora = new ArrayList<>();
        // filter by which corpora the user is allowed to access
        for (String c : corpusNames) {
            if (user.isPermitted("query:*:" + c)) {
                allowedCorpora.add(c);
            }
        }
        List<Long> corpusIDs = queryDao.mapCorpusNamesToIds(allowedCorpora);
        return queryDao.getExampleQueries(corpusIDs);
    } catch (Exception ex) {
        log.error("Problem accessing example queries", ex);
        throw new WebApplicationException(ex, 500);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) AnnisCorpus(annis.service.objects.AnnisCorpus) ArrayList(java.util.ArrayList) Subject(org.apache.shiro.subject.Subject) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) 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