|
14 | 14 | import gov.osti.listeners.DoeServletContextListener; |
15 | 15 | import gov.osti.repository.GitRepository; |
16 | 16 | import gov.osti.repository.SubversionRepository; |
| 17 | +import gov.osti.connectors.GitHub; |
17 | 18 | import java.io.IOException; |
18 | 19 | import java.io.Serializable; |
19 | 20 | import java.net.URLEncoder; |
@@ -118,6 +119,7 @@ private static class ValidationRequest implements Serializable { |
118 | 119 | private String type; |
119 | 120 | private String value; |
120 | 121 | private String error; |
| 122 | + private String extraInfo; |
121 | 123 |
|
122 | 124 | /** |
123 | 125 | * @return the type |
@@ -160,6 +162,20 @@ public String getError() { |
160 | 162 | public void setError(String error) { |
161 | 163 | this.error = error; |
162 | 164 | } |
| 165 | + |
| 166 | + /** |
| 167 | + * @return the value |
| 168 | + */ |
| 169 | + public String getExtraInfo() { |
| 170 | + return extraInfo; |
| 171 | + } |
| 172 | + |
| 173 | + /** |
| 174 | + * @param info the value to set |
| 175 | + */ |
| 176 | + public void setExtraInfo(String info) { |
| 177 | + this.extraInfo = info; |
| 178 | + } |
163 | 179 | } |
164 | 180 |
|
165 | 181 | /** |
@@ -501,9 +517,19 @@ public Response checkEmail(@QueryParam("value") String value) { |
501 | 517 | @Produces (MediaType.APPLICATION_JSON) |
502 | 518 | @Path ("/repositorylink") |
503 | 519 | public Response checkRepositoryLink(@QueryParam("value") String value) { |
504 | | - return ( isValidRepositoryLink(value) ) ? |
505 | | - Response.ok().entity(mapper.createObjectNode().put("value", "OK").toString()).build() : |
506 | | - ErrorResponse.badRequest(generateURLErrorMsg(value, "repositorylink")).build(); |
| 520 | + // is link a tag URL, or valid Repo |
| 521 | + String tag = GitHub.getTagFromUrl(value); |
| 522 | + |
| 523 | + if (tag != null && GitHub.isTagReferenceAndValid(value)) |
| 524 | + return Response.ok().entity(mapper.createObjectNode() |
| 525 | + .put("value", "OK").put("isTaggedVersion", true) |
| 526 | + .put("isTaggedVersion", true) |
| 527 | + .put("tagName", tag) |
| 528 | + .toString()).build(); |
| 529 | + else if (isValidRepositoryLink(value)) |
| 530 | + return Response.ok().entity(mapper.createObjectNode().put("value", "OK").toString()).build(); |
| 531 | + else |
| 532 | + return ErrorResponse.badRequest(generateURLErrorMsg(value, "repositorylink")).build(); |
507 | 533 | } |
508 | 534 |
|
509 | 535 | /** |
@@ -565,7 +591,11 @@ public Response request(String object) throws IOException { |
565 | 591 | if (StringUtils.equalsIgnoreCase(req.getType(), "doi")) { |
566 | 592 | req.setError((isValidDoi(req.getValue()) ? "" : req.getValue() + " is not a valid DOI.")); |
567 | 593 | } else if (StringUtils.equalsIgnoreCase(req.getType(), "repositorylink")) { |
568 | | - req.setError(isValidRepositoryLink(req.getValue()) ? "" : generateURLErrorMsg(req.getValue(), req.getType())); |
| 594 | + String value = req.getValue(); |
| 595 | + // is link a tag URL, or valid Repo |
| 596 | + String tag = GitHub.getTagFromUrl(value); |
| 597 | + req.setError(GitHub.isTagReferenceAndValid(value) || isValidRepositoryLink(value) ? "" : generateURLErrorMsg(value, req.getType())); |
| 598 | + req.setExtraInfo(tag); |
569 | 599 | } else if (StringUtils.equalsIgnoreCase(req.getType(), "phonenumber")) { |
570 | 600 | req.setError((isValidPhoneNumber(req.getValue()) ? "" : req.getValue() + " is not a valid phone number.")); |
571 | 601 | } else if (StringUtils.equalsIgnoreCase(req.getType(), "url")) { |
|
0 commit comments