Search in sources :

Example 1 with TexeraWebException

use of edu.uci.ics.texera.web.TexeraWebException 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 TexeraWebException

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

the class QueryPlanResource method executeQueryPlan.

/**
 * This is the edu.uci.ics.texera.web.request handler for the execution of a Query Plan.
 * @param logicalPlanJson, the json representation of the logical plan
 * @return - Generic GenericWebResponse object
 */
@POST
@Path("/execute")
public // TODO: investigate how to use LogicalPlan directly
JsonNode executeQueryPlan(@Session HttpSession session, String logicalPlanJson) {
    try {
        UserResource.User user = UserResource.getUser(session);
        QueryContext ctx = new QueryContext();
        if (user != null) {
            ctx.setProjectOwnerID(user.userID.toString());
        }
        LogicalPlan logicalPlan = new ObjectMapper().readValue(logicalPlanJson, LogicalPlan.class);
        logicalPlan.setContext(ctx);
        Plan plan = logicalPlan.buildQueryPlan();
        return executeMutipleSinkPlan(plan);
    } catch (IOException | TexeraException e) {
        throw new TexeraWebException(e.getMessage());
    }
}
Also used : LogicalPlan(edu.uci.ics.texera.dataflow.plangen.LogicalPlan) QueryContext(edu.uci.ics.texera.dataflow.plangen.QueryContext) IOException(java.io.IOException) Plan(edu.uci.ics.texera.api.engine.Plan) LogicalPlan(edu.uci.ics.texera.dataflow.plangen.LogicalPlan) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) TexeraWebException(edu.uci.ics.texera.web.TexeraWebException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 3 with TexeraWebException

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

the class PlanStoreResource method updateQueryPlan.

@PUT
@Path("/{plan_name}")
public GenericWebResponse updateQueryPlan(@PathParam("plan_name") String planName, String queryPlanBeanJson) {
    try {
        QueryPlanBean queryPlanBean = new ObjectMapper().readValue(queryPlanBeanJson, QueryPlanBean.class);
        // Updating the plan in the plan store
        planStore.updatePlan(planName, queryPlanBean.getDescription(), mapper.writeValueAsString(queryPlanBean.getQueryPlan()));
    } catch (IOException | TexeraException e) {
        throw new TexeraWebException(e.getMessage());
    }
    return new GenericWebResponse(0, "Success");
}
Also used : IOException(java.io.IOException) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) TexeraWebException(edu.uci.ics.texera.web.TexeraWebException) GenericWebResponse(edu.uci.ics.texera.web.response.GenericWebResponse) QueryPlanBean(edu.uci.ics.texera.web.response.planstore.QueryPlanBean) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with TexeraWebException

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

the class QueryPlanResource method executeQueryPlan.

/**
 * This is the edu.uci.ics.texera.web.request handler for the execution of a Query Plan.
 * @param logicalPlanJson, the json representation of the logical plan
 * @return - Generic TexeraWebResponse object
 */
@POST
@Path("/execute")
public // TODO: investigate how to use LogicalPlan directly
JsonNode executeQueryPlan(String logicalPlanJson) {
    try {
        LogicalPlan logicalPlan = new ObjectMapper().readValue(logicalPlanJson, LogicalPlan.class);
        Plan plan = logicalPlan.buildQueryPlan();
        ISink sink = plan.getRoot();
        // send response back to frontend
        if (sink instanceof TupleSink) {
            TupleSink tupleSink = (TupleSink) sink;
            tupleSink.open();
            List<Tuple> results = tupleSink.collectAllTuples();
            tupleSink.close();
            // make sure result directory is created
            if (Files.notExists(resultDirectory)) {
                Files.createDirectories(resultDirectory);
            }
            // clean up old result files
            cleanupOldResults();
            // generate new UUID as the result id
            String resultID = UUID.randomUUID().toString();
            // write original json of the result into a file
            java.nio.file.Path resultFile = resultDirectory.resolve(resultID + ".json");
            Files.createFile(resultFile);
            Files.write(resultFile, new ObjectMapper().writeValueAsBytes(results));
            // put readable json of the result into response
            ArrayNode resultNode = new ObjectMapper().createArrayNode();
            for (Tuple tuple : results) {
                resultNode.add(tuple.getReadableJson());
            }
            ObjectNode response = new ObjectMapper().createObjectNode();
            response.put("code", 0);
            response.set("result", resultNode);
            response.put("resultID", resultID);
            return response;
        } else {
            // execute the plan and return success message
            Engine.getEngine().evaluate(plan);
            ObjectNode response = new ObjectMapper().createObjectNode();
            response.put("code", 1);
            response.put("message", "plan sucessfully executed");
            return response;
        }
    } catch (IOException | TexeraException e) {
        throw new TexeraWebException(e.getMessage());
    }
}
Also used : TupleSink(edu.uci.ics.texera.dataflow.sink.tuple.TupleSink) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) IOException(java.io.IOException) Plan(edu.uci.ics.texera.api.engine.Plan) LogicalPlan(edu.uci.ics.texera.dataflow.plangen.LogicalPlan) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) ISink(edu.uci.ics.texera.api.dataflow.ISink) LogicalPlan(edu.uci.ics.texera.dataflow.plangen.LogicalPlan) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) TexeraWebException(edu.uci.ics.texera.web.TexeraWebException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 5 with TexeraWebException

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

the class KeywordDictionaryResource method uploadManualDictionary.

@POST
@Path("/upload-manual-dict")
public GenericWebResponse uploadManualDictionary(@Session HttpSession session, UserManualDictionary userManualDictionary) {
    if (userManualDictionary == null || !userManualDictionary.isValid()) {
        throw new TexeraWebException("Error occurred in user manual dictionary");
    }
    UInteger userID = UserResource.getUser(session).getUserID();
    if (userManualDictionary.separator.isEmpty()) {
        userManualDictionary.separator = ",";
    }
    List<String> itemArray = convertStringToList(userManualDictionary.content, userManualDictionary.separator);
    byte[] contentByteArray = convertListToByteArray(itemArray);
    int count = insertDictionaryToDataBase(userManualDictionary.name, contentByteArray, userManualDictionary.description, userID);
    throwErrorWhenNotOne("Error occurred while inserting dictionary to database", count);
    return GenericWebResponse.generateSuccessResponse();
}
Also used : UInteger(org.jooq.types.UInteger) TexeraWebException(edu.uci.ics.texera.web.TexeraWebException)

Aggregations

TexeraWebException (edu.uci.ics.texera.web.TexeraWebException)11 TexeraException (edu.uci.ics.texera.api.exception.TexeraException)7 IOException (java.io.IOException)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 Path (javax.ws.rs.Path)5 LogicalPlan (edu.uci.ics.texera.dataflow.plangen.LogicalPlan)4 QueryPlanBean (edu.uci.ics.texera.web.response.planstore.QueryPlanBean)4 Tuple (edu.uci.ics.texera.api.tuple.Tuple)3 POST (javax.ws.rs.POST)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Plan (edu.uci.ics.texera.api.engine.Plan)2 QueryContext (edu.uci.ics.texera.dataflow.plangen.QueryContext)2 GenericWebResponse (edu.uci.ics.texera.web.response.GenericWebResponse)2 ArrayList (java.util.ArrayList)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ISink (edu.uci.ics.texera.api.dataflow.ISink)1 StorageException (edu.uci.ics.texera.api.exception.StorageException)1