use of org.codice.ddf.catalog.ui.query.feedback.FeedbackRequest in project ddf by codice.
the class FeedbackApplication method init.
@Override
public void init() {
post("/feedback", APPLICATION_JSON, (req, res) -> {
if (StringUtils.isNotEmpty(emailDestination)) {
FeedbackRequest feedback = parseFeedbackRequest(req.body());
feedback.setAuthUsername(getCurrentUser());
String emailSubject = getEmailSubject(feedback);
String emailBody = getEmailBody(feedback);
if (emailBody != null) {
emailBody = emailBody.replaceAll("\\\\n", "\n");
}
Session emailSession = smtpClient.createSession();
MimeMessage message = new MimeMessage(emailSession);
message.addRecipient(Message.RecipientType.TO, new InternetAddress(emailDestination));
message.setSubject(emailSubject);
message.setContent(emailBody, "text/html; charset=utf-8");
smtpClient.send(message);
res.body("{}");
res.status(200);
return res;
} else {
res.status(500);
res.body("No destination email configured, feedback cannot be submitted.");
LOGGER.debug("Feedback submission failed, destination email is not configured.");
return res;
}
});
exception(Exception.class, (e, request, response) -> {
response.status(500);
response.body("Error submitting feedback");
LOGGER.debug("Feedback submission failed", e);
});
enableRouteOverview();
}
use of org.codice.ddf.catalog.ui.query.feedback.FeedbackRequest in project ddf by codice.
the class FeedbackApplication method parseFeedbackRequest.
private static FeedbackRequest parseFeedbackRequest(String json) {
FeedbackRequest feedbackRequest = new FeedbackRequest();
String name = UNKNOWN;
String email = UNKNOWN;
String searchStr = UNKNOWN;
String workspaceId = UNKNOWN;
String workspaceName = UNKNOWN;
Date searchInitiated = null;
ValueList searchStatus = null;
ValueList searchResults = null;
Map<String, Object> rootObject = MAPPER.parser().parseMap(json);
Object userObj = rootObject.get("user");
if (userObj instanceof Map) {
Map<String, Object> userObject = (Map<String, Object>) userObj;
name = (String) userObject.get("name");
email = (String) userObject.get("email");
}
Object searchObj = rootObject.get("search");
if (searchObj instanceof Map) {
Map<String, Object> searchObject = (Map<String, Object>) searchObj;
searchStr = (String) searchObject.get("cql");
searchInitiated = (Date) searchObject.get("initiated");
searchStatus = (ValueList) searchObject.get("status");
Object resultsObj = searchObject.get("results");
if (resultsObj instanceof ValueList) {
searchResults = (ValueList) resultsObj;
}
}
Object workspaceObj = rootObject.get("workspace");
if (workspaceObj instanceof Map) {
Map<String, Object> workspaceObject = (Map<String, Object>) workspaceObj;
workspaceId = (String) workspaceObject.get("id");
workspaceName = (String) workspaceObject.get("name");
}
String comments = (String) rootObject.get("comments");
feedbackRequest.setUsername(name);
feedbackRequest.setEmail(email);
feedbackRequest.setQuery(searchStr);
if (searchInitiated != null) {
feedbackRequest.setQueryInitiated(searchInitiated.toString());
}
if (searchResults != null) {
String prettyPrintedJson = Boon.toPrettyJson(searchResults);
feedbackRequest.setQueryResults(prettyPrintedJson);
}
if (searchStatus != null) {
feedbackRequest.setQueryStatus(searchStatus.stream().map(Object::toString).collect(Collectors.joining(", ")));
}
feedbackRequest.setWorkspaceId(workspaceId);
feedbackRequest.setWorkspaceName(workspaceName);
feedbackRequest.setComments(comments);
return feedbackRequest;
}
Aggregations