Search in sources :

Example 1 with GenericWebResponse

use of edu.uci.ics.texera.web.response.GenericWebResponse 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 2 with GenericWebResponse

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

the class KeywordDictionaryResource method uploadDictionary.

@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public GenericWebResponse uploadDictionary(@Session HttpSession session, @FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail, @FormDataParam("size") String sizeString, @FormDataParam("description") String description) {
    UInteger userID = UserResource.getUser(session).getUserID();
    String dictName = fileDetail.getFileName();
    String separator = ",";
    long size = parseStringToUInteger(sizeString).longValue();
    Pair<Integer, String> validationResult = validateDictionary(dictName, userID, size);
    if (validationResult.getLeft() != 0) {
        return new GenericWebResponse(validationResult.getLeft(), validationResult.getRight());
    }
    String content = readFileContent(uploadedInputStream);
    List<String> itemList = convertStringToList(content, separator);
    byte[] contentByteArray = convertListToByteArray(itemList);
    int count = insertDictionaryToDataBase(dictName, contentByteArray, description, userID);
    throwErrorWhenNotOne("Error occurred while inserting dictionary to database", count);
    return GenericWebResponse.generateSuccessResponse();
}
Also used : UInteger(org.jooq.types.UInteger) UInteger(org.jooq.types.UInteger) GenericWebResponse(edu.uci.ics.texera.web.response.GenericWebResponse)

Example 3 with GenericWebResponse

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

the class UserFileResource method validateUserFile.

@POST
@Path("/validate")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public GenericWebResponse validateUserFile(@Session HttpSession session, @FormDataParam("name") String fileName) {
    UInteger userID = UserResource.getUser(session).getUserID();
    Pair<Boolean, String> validationResult = validateFileName(fileName, userID);
    return new GenericWebResponse(validationResult.getLeft() ? 0 : 1, validationResult.getRight());
}
Also used : UInteger(org.jooq.types.UInteger) GenericWebResponse(edu.uci.ics.texera.web.response.GenericWebResponse)

Example 4 with GenericWebResponse

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

the class UserFileResource method deleteUserFile.

@DELETE
@Path("/delete/{fileID}")
public GenericWebResponse deleteUserFile(@PathParam("fileID") String fileID, @Session HttpSession session) {
    UInteger userID = UserResource.getUser(session).getUserID();
    UInteger fileIdUInteger = parseStringToUInteger(fileID);
    Record1<String> result = deleteInDatabase(fileIdUInteger, userID);
    if (result == null)
        return new GenericWebResponse(1, "The file does not exist");
    String filePath = result.get(FILE.PATH);
    FileManager.getInstance().deleteFile(Paths.get(filePath));
    return GenericWebResponse.generateSuccessResponse();
}
Also used : UInteger(org.jooq.types.UInteger) GenericWebResponse(edu.uci.ics.texera.web.response.GenericWebResponse)

Example 5 with GenericWebResponse

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

the class PlanStoreResource method addQueryPlan.

@POST
public GenericWebResponse addQueryPlan(String queryPlanBeanJson) {
    try {
        QueryPlanBean queryPlanBean = new ObjectMapper().readValue(queryPlanBeanJson, QueryPlanBean.class);
        // Adding the query plan to the PlanStore
        planStore.addPlan(queryPlanBean.getName(), queryPlanBean.getDescription(), mapper.writeValueAsString(queryPlanBean.getQueryPlan()));
    } catch (TexeraException e) {
        throw new TexeraWebException(e.getMessage());
    } catch (IOException 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)

Aggregations

GenericWebResponse (edu.uci.ics.texera.web.response.GenericWebResponse)7 UInteger (org.jooq.types.UInteger)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 TexeraException (edu.uci.ics.texera.api.exception.TexeraException)2 TexeraWebException (edu.uci.ics.texera.web.TexeraWebException)2 QueryPlanBean (edu.uci.ics.texera.web.response.planstore.QueryPlanBean)2 IOException (java.io.IOException)2