You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/05/28 12:22:55 UTC
[isis] branch master updated: ISIS-1955: Introduces EmailTicket
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new 866b641 ISIS-1955: Introduces EmailTicket
866b641 is described below
commit 866b641635dbe8b1e68fa09fa77d5bcc7e19aac4
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon May 28 14:22:43 2018 +0200
ISIS-1955: Introduces EmailTicket
a Ticket variant, that allows for sending the error stacktrace via email
Task-Url: https://issues.apache.org/jira/browse/ISIS-1955
---
.../core/runtime/services/error/EmailTicket.java | 141 +++++++++++++++++++++
1 file changed, 141 insertions(+)
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/error/EmailTicket.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/error/EmailTicket.java
new file mode 100644
index 0000000..bf0abd3
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/error/EmailTicket.java
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.core.runtime.services.error;
+
+import static org.apache.isis.commons.internal.base._NullSafe.stream;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.isis.applib.services.error.ErrorDetails;
+import org.apache.isis.applib.services.error.ErrorReportingService;
+
+/**
+ * Response from the {@link ErrorReportingService}, containing information to show to the end-user.
+ *
+ * <p>
+ * Implementation notes:
+ * <ul>
+ * <li>a class has been used here so that additional fields might be added in the future.</li>
+ * <li>the class is {@link Serializable}</li> so that it can be stored by the Wicket viewer as a Wicket model.
+ * </ul>
+ * </p>
+ */
+public class EmailTicket extends SimpleTicket {
+
+ // -- MAILTO VALUE TYPE
+
+ public static class MailTo implements Serializable {
+
+ private static final long serialVersionUID = -817872853109724987L;
+
+ public static class MailToBuilder {
+ private final MailTo mailTo = new MailTo();
+ public MailTo build() {
+ return mailTo;
+ }
+ public MailToBuilder linkName(String linkName) {
+ mailTo.linkName = linkName;
+ return this;
+ }
+ public MailToBuilder receiver(String receiver) {
+ mailTo.receiver = receiver;
+ return this;
+ }
+ public MailToBuilder subject(String subject) {
+ mailTo.subject = subject;
+ return this;
+ }
+ public MailToBuilder body(String body) {
+ mailTo.body = body;
+ return this;
+ }
+ }
+
+ public static MailToBuilder builder() {
+ return new MailToBuilder();
+ }
+
+ private String linkName = "Email";
+ private String receiver = "no-one@nowhere";
+ private String subject = "[Module-Name] Unexpected Error (#ref)";
+ private String body = "empty body";
+
+ public String toHtmlLink() {
+ return String.format("<a href=\"mailto:%s?subject=%s&body=%s\">%s</a>",
+ receiver,
+ htmlEscape(subject),
+ htmlEscape(body),
+ linkName
+ );
+ }
+
+ // -- STACKTRACE FORMATTING
+
+ public static String mailBodyOf(ErrorDetails errorDetails) {
+ return "Stacktrace:%0D%0A=================%0D%0A" +
+ stream(errorDetails.getStackTraceDetailPerCause())
+ .map(MailTo::causeToString)
+ .collect(Collectors.joining("%0D%0A%0D%0A"))
+ ;
+ }
+
+ private static String causeToString(List<String> list) {
+ return "Cause%0D%0A------------%0D%0A" +
+ stream(list)
+ .map(entry->String.format("# %s", entry))
+ .collect(Collectors.joining("%0D%0A"))
+ ;
+ }
+
+
+ }
+
+ // TICKET IMPL
+
+ private static final long serialVersionUID = -748973805361941912L;
+ private MailTo mailTo;
+
+ public EmailTicket(
+ MailTo mailTo,
+ String reference,
+ String userMessage,
+ String details,
+ StackTracePolicy stackTracePolicy,
+ String kittenUrl) {
+ super(reference, userMessage, details, stackTracePolicy, kittenUrl);
+ this.mailTo = mailTo;
+ }
+
+ @Override
+ public String getMarkup() {
+ return
+ "<p>" +
+ ifPresentMap(getDetails(), s->"<h3>" + htmlEscape(s) + "</h3>") +
+ ifPresentMap(getKittenUrl(), s->"<img src=\"" + s + "\"></img>") +
+ "</p>" +
+ ifPresentMap(getReference(), s->
+ "<p><h4>Please report this error: <span>" + mailTo.toHtmlLink() + "</span></h4></p>")
+ ;
+ }
+
+
+
+}
--
To stop receiving notification emails like this one, please contact
ahuber@apache.org.