Search in sources :

Example 1 with TexeraWebResponse

use of edu.uci.ics.texera.web.response.TexeraWebResponse in project textdb by TextDB.

the class FileUploadResource method uploadDictionaryFile.

@POST
@Path("/dictionary")
public TexeraWebResponse uploadDictionaryFile(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail) throws Exception {
    StringBuilder dictionary = new StringBuilder();
    String line = "";
    try (BufferedReader br = new BufferedReader(new InputStreamReader(uploadedInputStream))) {
        while ((line = br.readLine()) != null) {
            dictionary.append(line);
        }
    } catch (IOException e) {
        throw new TexeraWebException("Error occurred whlie uploading dictionary");
    }
    String fileName = fileDetail.getFileName();
    // save the dictionary
    DictionaryManager dictionaryManager = DictionaryManager.getInstance();
    dictionaryManager.addDictionary(fileName, dictionary.toString());
    return new TexeraWebResponse(0, "Dictionary is uploaded");
}
Also used : DictionaryManager(edu.uci.ics.texera.dataflow.resource.dictionary.DictionaryManager) TexeraWebResponse(edu.uci.ics.texera.web.response.TexeraWebResponse) TexeraWebException(edu.uci.ics.texera.web.TexeraWebException) Path(javax.ws.rs.Path)

Example 2 with TexeraWebResponse

use of edu.uci.ics.texera.web.response.TexeraWebResponse in project textdb by TextDB.

the class SystemResource method getDictionary.

/**
 * Get the content of dictionary
 */
@GET
@Path("/dictionary")
public TexeraWebResponse getDictionary(@QueryParam("name") String name) {
    DictionaryManager dictionaryManager = DictionaryManager.getInstance();
    String dictionaryContent = dictionaryManager.getDictionary(name);
    return new TexeraWebResponse(0, dictionaryContent);
}
Also used : DictionaryManager(edu.uci.ics.texera.dataflow.resource.dictionary.DictionaryManager) TexeraWebResponse(edu.uci.ics.texera.web.response.TexeraWebResponse)

Example 3 with TexeraWebResponse

use of edu.uci.ics.texera.web.response.TexeraWebResponse in project textdb by TextDB.

the class SystemResource method getDictionaries.

/**
 * Get the list of dictionaries
 */
@GET
@Path("/dictionaries")
public TexeraWebResponse getDictionaries() throws StorageException, JsonProcessingException {
    DictionaryManager dictionaryManager = DictionaryManager.getInstance();
    List<String> dictionaries = dictionaryManager.getDictionaries();
    return new TexeraWebResponse(0, new ObjectMapper().writeValueAsString(dictionaries));
}
Also used : DictionaryManager(edu.uci.ics.texera.dataflow.resource.dictionary.DictionaryManager) TexeraWebResponse(edu.uci.ics.texera.web.response.TexeraWebResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

DictionaryManager (edu.uci.ics.texera.dataflow.resource.dictionary.DictionaryManager)3 TexeraWebResponse (edu.uci.ics.texera.web.response.TexeraWebResponse)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 TexeraWebException (edu.uci.ics.texera.web.TexeraWebException)1 Path (javax.ws.rs.Path)1