@PathParam("queryname") String queryName,
@FormParam("json") String jsonFormParam,
@FormParam("file") String fileFormParam,
MultivaluedMap<String, String> formParams) throws ServletException {
try {
ThinQuery tq = null;
String file = fileFormParam;
String json = jsonFormParam;
if (formParams != null) {
json = formParams.containsKey("json") ? formParams.getFirst("json") : jsonFormParam;
file = formParams.containsKey("file") ? formParams.getFirst("file") : fileFormParam;
}
String filecontent = null;
if (StringUtils.isNotBlank(json)) {
filecontent = json;
} else if (StringUtils.isNotBlank(file)) {
Response f = repository.getResource(file);
filecontent = new String((byte[]) f.getEntity());
}
if (StringUtils.isBlank(filecontent)) {
throw new SaikuServiceException(
"Cannot create new query. Empty file content " + StringUtils.isNotBlank(json) + " or read from file:"
+ file);
}
if (thinQueryService.isOldQuery(filecontent)) {
tq = thinQueryService.convertQuery(filecontent);
} else {
ObjectMapper om = new ObjectMapper();
tq = om.readValue(filecontent, ThinQuery.class);
}
if (LOG.isDebugEnabled()) {
LOG.debug("TRACK\t" + "\t/query/" + queryName + "\tPOST\t tq:" + (tq == null) + " file:" + file);
}
if (tq == null) {
throw new SaikuServiceException("Cannot create blank query (ThinQuery object = null)");
}
tq.setName(queryName);
//SaikuCube cube = tq.getCube();
//if (StringUtils.isNotBlank(xml)) {
//String query = ServletUtil.replaceParameters(formParams, xml);
//return thinQueryService.createNewOlapQuery(queryName, query);