Search in sources :

Example 1 with CriticalServiceQueryException

use of annis.gui.CriticalServiceQueryException in project ANNIS by korpling.

the class CorpusManagement method fetchFromService.

public void fetchFromService() throws CriticalServiceQueryException, ServiceQueryException {
    if (webResourceProvider != null) {
        corpora.clear();
        try {
            WebResource rootRes = webResourceProvider.getWebResource();
            List<AnnisCorpus> corporaList = rootRes.path("query").path("corpora").get(new GenericType<List<AnnisCorpus>>() {
            });
            for (AnnisCorpus c : corporaList) {
                corpora.put(c.getName(), c);
            }
        } catch (ClientHandlerException ex) {
            log.error(null, ex);
            throw new ServiceQueryException("Service not available: " + ex.getLocalizedMessage());
        } catch (UniformInterfaceException ex) {
            if (ex.getResponse().getStatus() == Response.Status.UNAUTHORIZED.getStatusCode()) {
                throw new CriticalServiceQueryException("You are not authorized to get the corpus list.");
            } else {
                log.error(null, ex);
                throw new ServiceQueryException("Remote exception: " + ex.getLocalizedMessage());
            }
        }
    }
}
Also used : ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) AnnisCorpus(annis.service.objects.AnnisCorpus) CriticalServiceQueryException(annis.gui.CriticalServiceQueryException) ServiceQueryException(annis.gui.ServiceQueryException) WebResource(com.sun.jersey.api.client.WebResource) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) CriticalServiceQueryException(annis.gui.CriticalServiceQueryException)

Example 2 with CriticalServiceQueryException

use of annis.gui.CriticalServiceQueryException in project ANNIS by korpling.

the class CorpusManagement method delete.

public void delete(String corpusName) throws CriticalServiceQueryException, ServiceQueryException {
    if (webResourceProvider != null) {
        try {
            WebResource rootRes = webResourceProvider.getWebResource();
            rootRes.path("admin").path("corpora").path(corpusName).delete();
            corpora.remove(corpusName);
        } catch (ClientHandlerException ex) {
            log.error(null, ex);
            throw new ServiceQueryException("Service not available: " + ex.getLocalizedMessage());
        } catch (UniformInterfaceException ex) {
            if (ex.getResponse().getStatus() == Response.Status.UNAUTHORIZED.getStatusCode()) {
                throw new CriticalServiceQueryException("You are not authorized to delete a corpus");
            } else if (ex.getResponse().getStatus() == Response.Status.NOT_FOUND.getStatusCode()) {
                throw new ServiceQueryException("Corpus with name " + corpusName + " not found");
            } else {
                log.error(null, ex);
                throw new ServiceQueryException("Remote exception: " + ex.getLocalizedMessage());
            }
        }
    }
}
Also used : ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) CriticalServiceQueryException(annis.gui.CriticalServiceQueryException) ServiceQueryException(annis.gui.ServiceQueryException) WebResource(com.sun.jersey.api.client.WebResource) CriticalServiceQueryException(annis.gui.CriticalServiceQueryException)

Aggregations

CriticalServiceQueryException (annis.gui.CriticalServiceQueryException)2 ServiceQueryException (annis.gui.ServiceQueryException)2 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)2 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)2 WebResource (com.sun.jersey.api.client.WebResource)2 AnnisCorpus (annis.service.objects.AnnisCorpus)1 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1