Skip to content
This repository was archived by the owner on Jun 9, 2021. It is now read-only.

Commit aee524c

Browse files
committed
Fine tuning notification confirmation feature
* Using AUI flag. * Showing invoked URL and response content. * Also logging error when variable cant be resolved. Was giving up entirely. Will now log and continue trying to resolve other variables.
1 parent 445b66b commit aee524c

24 files changed

+442
-262
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,32 @@ Changelog of Pull Request Notifier for Bitbucket.
44

55
## Unreleased
66
### No issue
7+
Fine tuning notification confirmation feature
8+
* Using AUI flag.
9+
* Showing invoked URL and response content.
10+
* Also logging error when variable cant be resolved. Was giving up entirely. Will now log and continue trying to resolve other variables.
11+
12+
[cd772334597de1f](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/cd772334597de1f) Tomas Bjerre *2016-07-29 22:25:58*
13+
14+
Add Button Trigger Confirmation Dialog
15+
16+
When clicking the various trigger buttons, there is no feedback to the
17+
user that the button was clicked. Even worse, the button may have been
18+
clicked but there was an error doing the trigger itself (either in
19+
the PRNFB code itself or when it actually does the final HTTP call
20+
to the backing service).
21+
22+
This change adds an optional confirmation dialog (with a default of it
23+
being disabled) that will report, after the button press is complete
24+
and we have a response from the server, whether each trigger was
25+
successful (or if no triggers were hit).
26+
27+
[445b66bd464144b](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/445b66bd464144b) Itay Neeman *2016-07-29 20:39:28*
28+
29+
doc
30+
31+
[da839907caf3a40](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/da839907caf3a40) Tomas Bjerre *2016-07-28 21:01:31*
32+
733
doc
834

935
[fbdec988218c8d9](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/fbdec988218c8d9) Tomas Bjerre *2016-07-18 21:19:06*

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ Changelog of Pull Request Notifier for Bitbucket.
258258
</profiles>
259259

260260
<properties>
261-
<bitbucket.version>4.7.1</bitbucket.version>
261+
<bitbucket.version>4.8.1</bitbucket.version>
262262
<bitbucket.data.version>${bitbucket.version}</bitbucket.data.version>
263263
<amps.version>6.1.0</amps.version>
264264
</properties>
265-
</project>
265+
</project>
Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,76 @@
11
package se.bjurr.prnfb.http;
22

3+
import java.net.URI;
4+
35
public class HttpResponse {
4-
public HttpResponse(int status, String content) {
5-
this.status = status;
6-
this.content = content;
7-
}
8-
9-
private int status;
10-
private String content;
11-
12-
public int getStatus() {
13-
return status;
14-
}
15-
16-
public String getContent() {
17-
return content;
18-
}
6+
private final String content;
7+
8+
private final int status;
9+
10+
private final URI uri;
11+
12+
public HttpResponse(URI uri, int status, String content) {
13+
this.uri = uri;
14+
this.status = status;
15+
this.content = content;
16+
}
17+
18+
@Override
19+
public boolean equals(Object obj) {
20+
if (this == obj) {
21+
return true;
22+
}
23+
if (obj == null) {
24+
return false;
25+
}
26+
if (getClass() != obj.getClass()) {
27+
return false;
28+
}
29+
HttpResponse other = (HttpResponse) obj;
30+
if (this.content == null) {
31+
if (other.content != null) {
32+
return false;
33+
}
34+
} else if (!this.content.equals(other.content)) {
35+
return false;
36+
}
37+
if (this.status != other.status) {
38+
return false;
39+
}
40+
if (this.uri == null) {
41+
if (other.uri != null) {
42+
return false;
43+
}
44+
} else if (!this.uri.equals(other.uri)) {
45+
return false;
46+
}
47+
return true;
48+
}
49+
50+
public String getContent() {
51+
return this.content;
52+
}
53+
54+
public int getStatus() {
55+
return this.status;
56+
}
57+
58+
public URI getUri() {
59+
return this.uri;
60+
}
61+
62+
@Override
63+
public int hashCode() {
64+
final int prime = 31;
65+
int result = 1;
66+
result = prime * result + ((this.content == null) ? 0 : this.content.hashCode());
67+
result = prime * result + this.status;
68+
result = prime * result + ((this.uri == null) ? 0 : this.uri.hashCode());
69+
return result;
70+
}
71+
72+
@Override
73+
public String toString() {
74+
return "HttpResponse [content=" + this.content + ", status=" + this.status + ", uri=" + this.uri + "]";
75+
}
1976
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package se.bjurr.prnfb.http;
2+
3+
import java.util.UUID;
4+
5+
public class NotificationResponse {
6+
private final HttpResponse httpResponse;
7+
private final UUID notification;
8+
private final String notificationName;
9+
10+
public NotificationResponse(UUID notification, String notificationName, HttpResponse httpResponse) {
11+
this.notification = notification;
12+
this.notificationName = notificationName;
13+
this.httpResponse = httpResponse;
14+
}
15+
16+
@Override
17+
public boolean equals(Object obj) {
18+
if (this == obj) {
19+
return true;
20+
}
21+
if (obj == null) {
22+
return false;
23+
}
24+
if (getClass() != obj.getClass()) {
25+
return false;
26+
}
27+
NotificationResponse other = (NotificationResponse) obj;
28+
if (this.httpResponse == null) {
29+
if (other.httpResponse != null) {
30+
return false;
31+
}
32+
} else if (!this.httpResponse.equals(other.httpResponse)) {
33+
return false;
34+
}
35+
if (this.notification == null) {
36+
if (other.notification != null) {
37+
return false;
38+
}
39+
} else if (!this.notification.equals(other.notification)) {
40+
return false;
41+
}
42+
if (this.notificationName == null) {
43+
if (other.notificationName != null) {
44+
return false;
45+
}
46+
} else if (!this.notificationName.equals(other.notificationName)) {
47+
return false;
48+
}
49+
return true;
50+
}
51+
52+
public HttpResponse getHttpResponse() {
53+
return this.httpResponse;
54+
}
55+
56+
public UUID getNotification() {
57+
return this.notification;
58+
}
59+
60+
public String getNotificationName() {
61+
return this.notificationName;
62+
}
63+
64+
@Override
65+
public int hashCode() {
66+
final int prime = 31;
67+
int result = 1;
68+
result = prime * result + ((this.httpResponse == null) ? 0 : this.httpResponse.hashCode());
69+
result = prime * result + ((this.notification == null) ? 0 : this.notification.hashCode());
70+
result = prime * result + ((this.notificationName == null) ? 0 : this.notificationName.hashCode());
71+
return result;
72+
}
73+
74+
@Override
75+
public String toString() {
76+
return "NotificationResponse [httpResponse=" + this.httpResponse + ", notification=" + this.notification
77+
+ ", notificationName=" + this.notificationName + "]";
78+
}
79+
80+
}

src/main/java/se/bjurr/prnfb/http/UrlInvoker.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public HttpResponse invoke() {
162162

163163
this.response = doInvoke(httpRequestBase, builder);
164164
LOG.debug(this.response.getContent());
165-
165+
166166
return this.response;
167167
}
168168

@@ -340,9 +340,8 @@ HttpResponse doInvoke(HttpRequestBase httpRequestBase, HttpClientBuilder builder
340340
.execute(httpRequestBase);
341341

342342
HttpEntity entity = httpResponse.getEntity();
343-
return new HttpResponse(
344-
httpResponse.getStatusLine().getStatusCode(),
345-
EntityUtils.toString(entity, UTF_8));
343+
return new HttpResponse(httpRequestBase.getURI(), httpResponse.getStatusLine().getStatusCode(),
344+
EntityUtils.toString(entity, UTF_8));
346345
} catch (final Exception e) {
347346
LOG.error("", e);
348347
} finally {

src/main/java/se/bjurr/prnfb/listener/PrnfbPullRequestEventListener.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import se.bjurr.prnfb.http.ClientKeyStore;
2424
import se.bjurr.prnfb.http.HttpResponse;
2525
import se.bjurr.prnfb.http.Invoker;
26+
import se.bjurr.prnfb.http.NotificationResponse;
2627
import se.bjurr.prnfb.http.UrlInvoker;
2728
import se.bjurr.prnfb.service.PrnfbRenderer;
2829
import se.bjurr.prnfb.service.PrnfbRendererFactory;
@@ -128,7 +129,7 @@ public boolean isNotificationTriggeredByAction(PrnfbNotification notification,
128129
return TRUE;
129130
}
130131

131-
public HttpResponse notify(final PrnfbNotification notification, PrnfbPullRequestAction pullRequestAction,
132+
public NotificationResponse notify(final PrnfbNotification notification, PrnfbPullRequestAction pullRequestAction,
132133
PullRequest pullRequest, PrnfbRenderer renderer, ClientKeyStore clientKeyStore, Boolean shouldAcceptAnyCertificate) {
133134
if (!isNotificationTriggeredByAction(notification, pullRequestAction, renderer, pullRequest, clientKeyStore,
134135
shouldAcceptAnyCertificate)) {
@@ -156,12 +157,14 @@ public HttpResponse notify(final PrnfbNotification notification, PrnfbPullReques
156157
.withHeader(header.getName(),
157158
renderer.render(header.getValue(), FALSE, clientKeyStore, shouldAcceptAnyCertificate));
158159
}
159-
return createInvoker().invoke(urlInvoker//
160+
HttpResponse httpResponse = createInvoker().invoke(urlInvoker//
160161
.withProxyServer(notification.getProxyServer()) //
161162
.withProxyPort(notification.getProxyPort())//
162163
.withProxyUser(notification.getProxyUser())//
163164
.withProxyPassword(notification.getProxyPassword())//
164165
.shouldAcceptAnyCertificate(shouldAcceptAnyCertificate));
166+
167+
return new NotificationResponse(notification.getUuid(), notification.getName(), httpResponse);
165168
}
166169

167170
@EventListener

src/main/java/se/bjurr/prnfb/presentation/ButtonServlet.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
import static javax.ws.rs.core.Response.status;
66
import static javax.ws.rs.core.Response.Status.OK;
77
import static javax.ws.rs.core.Response.Status.UNAUTHORIZED;
8-
import static se.bjurr.prnfb.transformer.ButtonTransformer.toTriggerResultDto;
98
import static se.bjurr.prnfb.transformer.ButtonTransformer.toButtonDto;
109
import static se.bjurr.prnfb.transformer.ButtonTransformer.toButtonDtoList;
1110
import static se.bjurr.prnfb.transformer.ButtonTransformer.toPrnfbButton;
11+
import static se.bjurr.prnfb.transformer.ButtonTransformer.toTriggerResultDto;
1212

1313
import java.util.Collections;
1414
import java.util.List;
15-
import java.util.Map;
1615
import java.util.UUID;
1716

1817
import javax.ws.rs.Consumes;
@@ -24,9 +23,9 @@
2423
import javax.ws.rs.Produces;
2524
import javax.ws.rs.core.Response;
2625

27-
import se.bjurr.prnfb.http.HttpResponse;
26+
import se.bjurr.prnfb.http.NotificationResponse;
2827
import se.bjurr.prnfb.presentation.dto.ButtonDTO;
29-
import se.bjurr.prnfb.presentation.dto.TriggerResultDTO;
28+
import se.bjurr.prnfb.presentation.dto.NotificationResponseDTO;
3029
import se.bjurr.prnfb.service.ButtonsService;
3130
import se.bjurr.prnfb.service.SettingsService;
3231
import se.bjurr.prnfb.service.UserCheckService;
@@ -152,9 +151,9 @@ public Response press(@PathParam("repositoryId") Integer repositoryId, @PathPara
152151
if (!this.userCheckService.isAllowedUseButton(button)) {
153152
return status(UNAUTHORIZED).build();
154153
}
155-
Map<String, HttpResponse> results = this.buttonsService.handlePressed(repositoryId, pullRequestId, buttionUuid);
154+
List<NotificationResponse> results = this.buttonsService.handlePressed(repositoryId, pullRequestId, buttionUuid);
156155

157-
TriggerResultDTO dto = toTriggerResultDto(button, results);
156+
List<NotificationResponseDTO> dto = toTriggerResultDto(results);
158157
return ok(dto, APPLICATION_JSON).build();
159158
}
160159

src/main/java/se/bjurr/prnfb/presentation/dto/ButtonDTO.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
@XmlAccessorType(FIELD)
1616
public class ButtonDTO implements Comparable<ButtonDTO> {
1717

18+
private ON_OR_OFF confirmation;
1819
private String name;
1920
private String projectKey;
2021
private String repositorySlug;
21-
private String confirmation;
2222
private USER_LEVEL userLevel;
2323
private UUID uuid;
2424

@@ -80,6 +80,10 @@ public boolean equals(Object obj) {
8080
return true;
8181
}
8282

83+
public ON_OR_OFF getConfirmation() {
84+
return this.confirmation;
85+
}
86+
8387
public String getName() {
8488
return this.name;
8589
}
@@ -96,10 +100,6 @@ public USER_LEVEL getUserLevel() {
96100
return this.userLevel;
97101
}
98102

99-
public String getConfirmation() {
100-
return this.confirmation;
101-
}
102-
103103
public UUID getUuid() {
104104
return this.uuid;
105105
}
@@ -121,6 +121,10 @@ public int hashCode() {
121121
return result;
122122
}
123123

124+
public void setConfirmation(ON_OR_OFF confirmation) {
125+
this.confirmation = confirmation;
126+
}
127+
124128
public void setName(String name) {
125129
this.name = name;
126130
}
@@ -141,18 +145,6 @@ public void setUuid(UUID uuid) {
141145
this.uuid = uuid;
142146
}
143147

144-
public void setConfirmation(String confirmation) {
145-
if (confirmation == null) {
146-
this.confirmation = "off";
147-
}
148-
else if (confirmation.equalsIgnoreCase("on")) {
149-
this.confirmation = "on";
150-
}
151-
else {
152-
this.confirmation = "off";
153-
}
154-
}
155-
156148
@Override
157149
public String toString() {
158150
return "ButtonDTO [name=" + this.name + ", userLevel=" + this.userLevel + ", uuid=" + this.uuid + ", repositorySlug="

0 commit comments

Comments
 (0)