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