@Path("/setjql")
@Produces({MediaType.APPLICATION_JSON})
public Response setJcl(@Context HttpServletRequest req)
{
JiraAuthenticationContext authCtx = ComponentManager.getInstance().getJiraAuthenticationContext();
I18nHelper i18n = authCtx.getI18nHelper();
User user = authCtx.getLoggedInUser();
if (user == null)
{
log.error("QueryFieldsService::setJcl - User is not logged");
return Response.ok(i18n.getText("queryfields.error.notlogged")).status(401).build();
}
XsrfTokenGenerator xsrfTokenGenerator = ComponentManager.getComponentInstanceOfType(XsrfTokenGenerator.class);
String token = xsrfTokenGenerator.getToken(req);
if (!xsrfTokenGenerator.generatedByAuthenticatedUser(token))
{
log.error("QueryFieldsService::setJcl - There is no token");
return Response.ok(i18n.getText("queryfields.error.internalerror")).status(500).build();
}
else
{
String atl_token = req.getParameter("atl_token");
if (!atl_token.equals(token))
{
log.error("QueryFieldsService::setJcl - Token is invalid");
return Response.ok(i18n.getText("queryfields.error.internalerror")).status(500).build();
}
}
String cfIdStr = req.getParameter("cfId");
String prIdStr = req.getParameter("prId");
String data = req.getParameter("jqlclause");
String jqlnull = req.getParameter("jqlnull");
String autocompleteView = req.getParameter("autocompleteview");
String[] options = req.getParameterValues("options");
if (!Utils.isValidStr(cfIdStr) || !Utils.isValidStr(prIdStr))
{
log.error("QueryFieldsService::setJcl - Required parameters are not set");
return Response.ok(i18n.getText("queryfields.error.notrequiredparms")).status(500).build();
}
long cfId;
long prId;
try
{
cfId = Long.parseLong(cfIdStr);
prId = Long.parseLong(prIdStr);
}
catch (NumberFormatException nex)
{
log.error("QueryFieldsService::setJcl - Parameters are not valid");
return Response.ok(i18n.getText("queryfields.error.notvalidparms")).status(500).build();
}
if (Utils.isValidStr(data))
{
String jqlQuery = data;
if (data.startsWith(Consts.REVERSE_LINK_PART))
{
String reserveData = data.substring(Consts.REVERSE_LINK_PART.length());
int inx = reserveData.indexOf("|");
if (inx < 0)
{
Set<String> errs = new TreeSet<String>();
errs.add(i18n.getText("queryfields.error.rlinkerror"));
Map<String, Object> params = new HashMap<String, Object>();
params.put("errs", errs);
params.put("i18n", i18n);
try
{
String body = ComponentAccessor.getVelocityManager().getBody("templates/", "conferr.vm", params);
return Response.ok(new HtmlEntity(body)).status(500).build();
}
catch (VelocityException vex)
{
log.error("QueryFieldsService::setJcl - Velocity parsing error", vex);
return Response.ok(i18n.getText("queryfields.error.internalerror")).status(500).build();
}
}
String proj = reserveData.substring(0, inx);
String cfName = reserveData.substring(inx + 1);
jqlQuery = String.format(Consts.TEST_QUERY_PATTERN, proj, cfName);
}
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlQuery);
if (parseResult.isValid())
{
qfMgr.setQueryFieldData(cfId, prId, data);
if (Utils.isValidStr(jqlnull) && jqlnull.equals("on"))
{
qfMgr.setAddNull(cfId, prId, true);
}
else
{
qfMgr.setAddNull(cfId, prId, false);
}
if (Utils.isValidStr(autocompleteView) && autocompleteView.equals("on"))
{
qfMgr.setAutocompleteView(cfId, prId, true);
}
else
{
qfMgr.setAutocompleteView(cfId, prId, false);
}
List<String> optList = new ArrayList<String>();
if (options != null)
{
for (String option : options)
{
optList.add(option);
}
}
qfMgr.setLinkerFieldOptions(cfId, prId, optList);
}
else
{
MessageSet ms = parseResult.getErrors();
Set<String> errs = ms.getErrorMessages();
Map<String, Object> params = new HashMap<String, Object>();
params.put("errs", errs);
params.put("i18n", i18n);
try
{
String body = ComponentAccessor.getVelocityManager().getBody("templates/", "conferr.vm", params);
return Response.ok(new HtmlEntity(body)).status(500).build();
}
catch (VelocityException vex)
{
log.error("QueryFieldsService::setJcl - Velocity parsing error", vex);
return Response.ok(i18n.getText("queryfields.error.internalerror")).status(500).build();
}
}
}
else
{