|
1 | | -package io.jenkins.plugins.gitlabbranchsource.helpers; |
2 | | - |
3 | | -import io.jenkins.cli.shaded.org.apache.commons.lang.StringUtils; |
4 | | -import java.io.Serializable; |
5 | | -import java.util.Objects; |
6 | | - |
7 | | -public class GitLabAvatarLocation implements Serializable { |
8 | | - |
9 | | - /** |
10 | | - * Ensure consistent serialization. |
11 | | - */ |
12 | | - private static final long serialVersionUID = 1L; |
13 | | - |
14 | | - private final String avatarUrl; |
15 | | - private final String serverName; |
16 | | - private final String fullPath; |
17 | | - private final boolean isProject; |
18 | | - |
19 | | - /** |
20 | | - * Constructor |
21 | | - * |
22 | | - * @param url the external GitLab URL of the source avatar image. |
23 | | - * @param serverName server to use for API call, null to fall back to URL instead |
24 | | - * @param fullPath project/group id parameter for API call, null to fall back to URL instead |
25 | | - * @param isProject does the fullPath represent a project (true) or group (false) |
26 | | - */ |
27 | | - public GitLabAvatarLocation(String avatarUrl, String serverName, String fullPath, boolean isProject) { |
28 | | - this.avatarUrl = avatarUrl; |
29 | | - this.serverName = serverName; |
30 | | - this.fullPath = fullPath; |
31 | | - this.isProject = isProject; |
32 | | - } |
33 | | - |
34 | | - public GitLabAvatarLocation(String avatarUrl) { |
35 | | - this(avatarUrl, null, null, false); |
36 | | - } |
37 | | - |
38 | | - public boolean apiAvailable() { |
39 | | - return (serverName != null && fullPath != null); |
40 | | - } |
41 | | - |
42 | | - public boolean available() { |
43 | | - // since the url string will not magically turn itself into a HTTP url it is effectively unusable |
44 | | - return (apiAvailable() |
45 | | - || (avatarUrl != null && (avatarUrl.startsWith("http://") || avatarUrl.startsWith("https://")))); |
46 | | - } |
47 | | - |
48 | | - public String getAvatarUrl() { |
49 | | - return avatarUrl; |
50 | | - } |
51 | | - |
52 | | - public String getServerName() { |
53 | | - return serverName; |
54 | | - } |
55 | | - |
56 | | - public String getFullPath() { |
57 | | - return fullPath; |
58 | | - } |
59 | | - |
60 | | - public boolean isProject() { |
61 | | - return isProject; |
62 | | - } |
63 | | - |
64 | | - @Override |
65 | | - public boolean equals(Object o) { |
66 | | - if (this == o) { |
67 | | - return true; |
68 | | - } |
69 | | - if (o == null || getClass() != o.getClass()) { |
70 | | - return false; |
71 | | - } |
72 | | - |
73 | | - GitLabAvatarLocation that = (GitLabAvatarLocation) o; |
74 | | - |
75 | | - return Objects.equals(avatarUrl, that.avatarUrl) |
76 | | - && Objects.equals(serverName, that.serverName) |
77 | | - && Objects.equals(fullPath, that.fullPath); |
78 | | - } |
79 | | - |
80 | | - @Override |
81 | | - public int hashCode() { |
82 | | - if (StringUtils.isNotBlank(avatarUrl)) { |
83 | | - return avatarUrl.hashCode(); |
84 | | - } else if (apiAvailable()) { |
85 | | - return String.format("%s/%s", serverName, fullPath).hashCode(); |
86 | | - } |
87 | | - return 0; |
88 | | - } |
89 | | - |
90 | | - @Override |
91 | | - public String toString() { |
92 | | - if (apiAvailable()) { |
93 | | - return String.format("API://%s/%s", serverName, fullPath); |
94 | | - } else if (StringUtils.isNotBlank(avatarUrl)) { |
95 | | - return avatarUrl; |
96 | | - } |
97 | | - return ""; |
98 | | - } |
99 | | -} |
| 1 | +package io.jenkins.plugins.gitlabbranchsource.helpers; |
| 2 | + |
| 3 | +import io.jenkins.cli.shaded.org.apache.commons.lang.StringUtils; |
| 4 | +import java.io.Serializable; |
| 5 | +import java.util.Objects; |
| 6 | + |
| 7 | +public class GitLabAvatarLocation implements Serializable { |
| 8 | + |
| 9 | + /** |
| 10 | + * Ensure consistent serialization. |
| 11 | + */ |
| 12 | + private static final long serialVersionUID = 1L; |
| 13 | + |
| 14 | + private final String avatarUrl; |
| 15 | + private final String serverName; |
| 16 | + private final String fullPath; |
| 17 | + private final boolean isProject; |
| 18 | + |
| 19 | + /** |
| 20 | + * Constructor |
| 21 | + * |
| 22 | + * @param url the external GitLab URL of the source avatar image. |
| 23 | + * @param serverName server to use for API call, null to fall back to URL instead |
| 24 | + * @param fullPath project/group id parameter for API call, null to fall back to URL instead |
| 25 | + * @param isProject does the fullPath represent a project (true) or group (false) |
| 26 | + */ |
| 27 | + public GitLabAvatarLocation(String avatarUrl, String serverName, String fullPath, boolean isProject) { |
| 28 | + this.avatarUrl = avatarUrl; |
| 29 | + this.serverName = serverName; |
| 30 | + this.fullPath = fullPath; |
| 31 | + this.isProject = isProject; |
| 32 | + } |
| 33 | + |
| 34 | + public GitLabAvatarLocation(String avatarUrl) { |
| 35 | + this(avatarUrl, null, null, false); |
| 36 | + } |
| 37 | + |
| 38 | + public boolean apiAvailable() { |
| 39 | + return (serverName != null && fullPath != null); |
| 40 | + } |
| 41 | + |
| 42 | + public boolean available() { |
| 43 | + // since the url string will not magically turn itself into a HTTP url it is effectively unusable |
| 44 | + return (apiAvailable() |
| 45 | + || (avatarUrl != null && (avatarUrl.startsWith("http://") || avatarUrl.startsWith("https://")))); |
| 46 | + } |
| 47 | + |
| 48 | + public String getAvatarUrl() { |
| 49 | + return avatarUrl; |
| 50 | + } |
| 51 | + |
| 52 | + public String getServerName() { |
| 53 | + return serverName; |
| 54 | + } |
| 55 | + |
| 56 | + public String getFullPath() { |
| 57 | + return fullPath; |
| 58 | + } |
| 59 | + |
| 60 | + public boolean isProject() { |
| 61 | + return isProject; |
| 62 | + } |
| 63 | + |
| 64 | + @Override |
| 65 | + public boolean equals(Object o) { |
| 66 | + if (this == o) { |
| 67 | + return true; |
| 68 | + } |
| 69 | + if (o == null || getClass() != o.getClass()) { |
| 70 | + return false; |
| 71 | + } |
| 72 | + |
| 73 | + GitLabAvatarLocation that = (GitLabAvatarLocation) o; |
| 74 | + |
| 75 | + return Objects.equals(avatarUrl, that.avatarUrl) |
| 76 | + && Objects.equals(serverName, that.serverName) |
| 77 | + && Objects.equals(fullPath, that.fullPath); |
| 78 | + } |
| 79 | + |
| 80 | + @Override |
| 81 | + public int hashCode() { |
| 82 | + if (StringUtils.isNotBlank(avatarUrl)) { |
| 83 | + return avatarUrl.hashCode(); |
| 84 | + } else if (apiAvailable()) { |
| 85 | + return String.format("%s/%s", serverName, fullPath).hashCode(); |
| 86 | + } |
| 87 | + return 0; |
| 88 | + } |
| 89 | + |
| 90 | + @Override |
| 91 | + public String toString() { |
| 92 | + if (apiAvailable()) { |
| 93 | + return String.format("API://%s/%s", serverName, fullPath); |
| 94 | + } else if (StringUtils.isNotBlank(avatarUrl)) { |
| 95 | + return avatarUrl; |
| 96 | + } |
| 97 | + return ""; |
| 98 | + } |
| 99 | +} |
0 commit comments