Skip to content

Commit

Permalink
Merge pull request #14 from SBI-/master
Browse files Browse the repository at this point in the history
Support custom icons for git artifact links
  • Loading branch information
SBI- authored Jul 9, 2018
2 parents cdaa9e0 + e8a3a79 commit a0e71c6
Show file tree
Hide file tree
Showing 29 changed files with 119 additions and 62 deletions.
2 changes: 1 addition & 1 deletion feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="org.jazzcommunity.GitConnectorService.feature"
label="REST Service"
version="1.6.4.qualifier"
version="1.7.1.qualifier"
provider-name="PROVIDER">

<description url="http://www.example.com/description">
Expand Down
2 changes: 1 addition & 1 deletion feature/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.jazzcommunity.GitConnectorService</groupId>
<artifactId>org.jazzcommunity.GitConnectorService.parent</artifactId>
<version>1.6.4-SNAPSHOT</version>
<version>1.7.1-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion plugin/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: org.jazzcommunity.GitConnectorService
Bundle-SymbolicName: org.jazzcommunity.GitConnectorService;singleton:=true
Bundle-Version: 1.6.4.qualifier
Bundle-Version: 1.7.1.qualifier
Bundle-Vendor: VENDOR
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Require-Bundle:
Expand Down
2 changes: 1 addition & 1 deletion plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.jazzcommunity.GitConnectorService</groupId>
<artifactId>org.jazzcommunity.GitConnectorService.parent</artifactId>
<version>1.6.4-SNAPSHOT</version>
<version>1.7.1-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.jazzcommunity.GitConnectorService;

import com.siemens.bt.jazz.services.base.BaseService;
import org.jazzcommunity.GitConnectorService.builder.VersionService;
import org.jazzcommunity.GitConnectorService.builder.gitlab.IssueLinkService;
import org.jazzcommunity.GitConnectorService.builder.gitlab.IssuePreviewService;
import org.jazzcommunity.GitConnectorService.builder.gitlab.RequestLinkService;
import org.jazzcommunity.GitConnectorService.builder.gitlab.RequestPreviewService;
import org.jazzcommunity.GitConnectorService.service.VersionService;
import org.jazzcommunity.GitConnectorService.service.gitlab.IssueLinkService;
import org.jazzcommunity.GitConnectorService.service.gitlab.IssuePreviewService;
import org.jazzcommunity.GitConnectorService.service.gitlab.RequestLinkService;
import org.jazzcommunity.GitConnectorService.service.gitlab.RequestPreviewService;
import org.jazzcommunity.GitConnectorService.service.resource.ImageService;

/**
* Entry point for the Service, called by the Jazz class loader.
Expand Down Expand Up @@ -39,6 +40,10 @@ public GitConnectorService() {
"info/version",
VersionService.class);

router.get(
"img/{filename}",
ImageService.class);

/**
* This code is purposely commented out and not deleted!
* We have decided to use the IBM rich hovers for now, but potential support will remain built into
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ private IssueMapper() {
* entities in its representation.
*
* <p>
* see http://modelmapper.org/user-manual/property-mapping/ for documentation on the
* convention of passing null when using a custom converter.
* see http://modelmapper.org/user-manual/property-mapping/ for documentation on the
* convention of passing null when using a custom converter.
* </p>
*
* @param issue The Gitlab issue to map
Expand All @@ -33,7 +33,9 @@ private IssueMapper() {
*/
public static OslcIssue map(Issue issue, URL self, String baseUrl) {
final String link = self.toString();
final String iconUrl = String.format("%sweb/com.ibm.team.git.web/ui/internal/images/page/git_commit_desc_16.gif", baseUrl);
final String iconUrl = String.format(
"%sservice/org.jazzcommunity.GitConnectorService.IGitConnectorService/img/issue_gitlab_16x16.png",
baseUrl);
// This mapping needs to be handled outside of the property map, because
// of how ModelMapper determines type mappings using reflection. Moving
// the ContributorBuilder invocation inside the TypeMap will always fail
Expand Down Expand Up @@ -121,7 +123,8 @@ protected void configure() {
assignee,
GitCmAssignee.class));
// Assignees
Type assignees = new TypeToken<List<GitCmAssignee_>>() {}.getType();
Type assignees = new TypeToken<List<GitCmAssignee_>>() {
}.getType();
using(TypeConverter.to(assignees))
.map(source.getAssignees())
.setGitCmAssignees(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ private MergeRequestMapper() {
// iconurl should probably already be passed in here...
public static OslcMergeRequest map(MergeRequest request, URL self, String baseUrl) {
final String link = self.toString();
final String iconUrl = String.format("%sweb/com.ibm.team.git.web/ui/internal/images/page/git_commit_desc_16.gif", baseUrl);
final String iconUrl = String.format(
"%sservice/org.jazzcommunity.GitConnectorService.IGitConnectorService/img/request_gitlab_16x16.png",
baseUrl);
final ContributorPrototype contributor = new ContributorPrototype(
request.getAuthor().getName(),
request.getAuthor().getWebUrl());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.jazzcommunity.GitConnectorService.builder;
package org.jazzcommunity.GitConnectorService.service;

import com.google.gson.*;
import com.google.common.net.MediaType;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.ibm.team.repository.service.TeamRawService;
import com.siemens.bt.jazz.services.base.rest.parameters.PathParameters;
import com.siemens.bt.jazz.services.base.rest.parameters.RestRequest;
Expand All @@ -24,6 +26,7 @@ public VersionService(Log log, HttpServletRequest request, HttpServletResponse r
@Override
public void execute() throws Exception {
Version version = FrameworkUtil.getBundle(getClass()).getVersion();
response.setContentType(MediaType.JSON_UTF_8.toString());
response.getWriter().write(gson.toJson(new VersionAdapter(version)));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jazzcommunity.GitConnectorService.builder.github;
package org.jazzcommunity.GitConnectorService.service.github;

import com.google.gson.JsonObject;
import com.ibm.team.repository.service.TeamRawService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jazzcommunity.GitConnectorService.builder.github;
package org.jazzcommunity.GitConnectorService.service.github;

import com.google.gson.JsonObject;
import com.ibm.team.repository.service.TeamRawService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jazzcommunity.GitConnectorService.builder.github;
package org.jazzcommunity.GitConnectorService.service.github;

import com.google.gson.JsonObject;
import com.ibm.team.repository.service.TeamRawService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jazzcommunity.GitConnectorService.builder.github;
package org.jazzcommunity.GitConnectorService.service.github;

import com.ibm.team.repository.service.TeamRawService;
import com.siemens.bt.jazz.services.base.rest.parameters.PathParameters;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jazzcommunity.GitConnectorService.builder.gitlab;
package org.jazzcommunity.GitConnectorService.service.gitlab;

import ch.sbi.minigit.gitlab.GitlabApi;
import ch.sbi.minigit.type.gitlab.commit.Commit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jazzcommunity.GitConnectorService.builder.gitlab;
package org.jazzcommunity.GitConnectorService.service.gitlab;

import ch.sbi.minigit.gitlab.GitlabApi;
import ch.sbi.minigit.type.gitlab.commit.Commit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.jazzcommunity.GitConnectorService.builder.gitlab;
package org.jazzcommunity.GitConnectorService.service.gitlab;

import ch.sbi.minigit.gitlab.GitlabApi;
import ch.sbi.minigit.type.gitlab.issue.Issue;
import com.google.common.net.MediaType;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.ibm.team.repository.service.TeamRawService;
Expand Down Expand Up @@ -56,16 +57,15 @@ private void sendOslcResponse(Issue issue, GitServiceArtifact parameters) throws

Gson gson = new GsonBuilder().serializeNulls().create();
String json = gson.toJson(oslcPayload);
response.setContentType(ContentType.APPLICATION_JSON.toString());
response.setContentType(MediaType.JSON_UTF_8.toString());
response.setHeader("OSLC-Core-Version", "2.0");
response.getWriter().write(json);
}

private void sendLinkResponse(Issue issue, GitServiceArtifact parameters) throws IOException {
URL preview = UrlBuilder.getPreviewUrl(parentService, parameters, "issue");

// TODO: Find a nice way of handling static resources?
String icon = String.format("%sweb/com.ibm.team.git.web/ui/internal/images/page/git_commit_desc_16.gif",
String icon = String.format(
"%sservice/org.jazzcommunity.GitConnectorService.IGitConnectorService/img/issue_gitlab_16x16.png",
parentService.getRequestRepositoryURL());

JtwigTemplate template = JtwigTemplate.classpathTemplate("templates/xml/issue_link.twig");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jazzcommunity.GitConnectorService.builder.gitlab;
package org.jazzcommunity.GitConnectorService.service.gitlab;

import ch.sbi.minigit.gitlab.GitlabApi;
import ch.sbi.minigit.type.gitlab.issue.Issue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.jazzcommunity.GitConnectorService.builder.gitlab;
package org.jazzcommunity.GitConnectorService.service.gitlab;

import ch.sbi.minigit.gitlab.GitlabApi;
import ch.sbi.minigit.type.gitlab.mergerequest.MergeRequest;
import com.google.common.net.MediaType;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.ibm.team.repository.service.TeamRawService;
Expand Down Expand Up @@ -56,15 +57,15 @@ private void sendOslcResponse(MergeRequest mergeRequest, GitServiceArtifact para

Gson gson = new GsonBuilder().serializeNulls().create();
String json = gson.toJson(oslcRequest);
response.setContentType(ContentType.APPLICATION_JSON.toString());
response.setContentType(MediaType.JSON_UTF_8.toString());
response.setHeader("OSLC-Core-Version", "2.0");
response.getWriter().write(json);
}

private void sendLinkResponse(MergeRequest request, GitServiceArtifact parameters) throws IOException {
URL preview = UrlBuilder.getPreviewUrl(parentService, parameters, "merge-request");

String icon = String.format("%sweb/com.ibm.team.git.web/ui/internal/images/page/git_commit_desc_16.gif",
String icon = String.format(
"%sservice/org.jazzcommunity.GitConnectorService.IGitConnectorService/img/request_gitlab_16x16.png",
parentService.getRequestRepositoryURL());

JtwigTemplate template = JtwigTemplate.classpathTemplate("templates/xml/issue_link.twig");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jazzcommunity.GitConnectorService.builder.gitlab;
package org.jazzcommunity.GitConnectorService.service.gitlab;

import ch.sbi.minigit.gitlab.GitlabApi;
import ch.sbi.minigit.type.gitlab.mergerequest.MergeRequest;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.jazzcommunity.GitConnectorService.service.resource;

import com.google.common.io.ByteSource;
import com.google.common.io.Resources;
import com.google.common.net.MediaType;
import com.ibm.team.repository.service.TeamRawService;
import com.siemens.bt.jazz.services.base.rest.parameters.PathParameters;
import com.siemens.bt.jazz.services.base.rest.parameters.RestRequest;
import com.siemens.bt.jazz.services.base.rest.service.AbstractRestService;
import org.apache.commons.logging.Log;
import org.apache.http.HttpStatus;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.URL;

public class ImageService extends AbstractRestService {
public ImageService(
Log log,
HttpServletRequest request,
HttpServletResponse response,
RestRequest restRequest,
TeamRawService parentService,
PathParameters pathParameters) {
super(log, request, response, restRequest, parentService, pathParameters);
}

@Override
public void execute() throws Exception {
try {
String filename = String.format("images/%s", pathParameters.get("filename"));
URL url = Resources.getResource(filename);
ByteSource source = Resources.asByteSource(url);

response.setContentType(MediaType.ANY_IMAGE_TYPE.toString());
source.copyTo(response.getOutputStream());
} catch (IllegalArgumentException e) {
response.setStatus(HttpStatus.SC_NOT_FOUND);
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugin/src/main/resources/images/link_16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 25 additions & 23 deletions plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,24 @@
"rtc_cm:due": "2018-04-19T10:00:00.000Z",
"rtc_cm:estimate": 18000000,
"rtc_cm:timeSpent": 10800000,
"rtc_cm:type":{
"rdf:type":[],
"rtc_cm:iconUrl":"https://localhost:7443/jazz/service/com.ibm.team.workitem.common.internal.model.IImageContentService/processattachment/_Y868wPuZEeau1PCMVYBRLg/workitemtype/bug.gif",
"dcterms:title":"Issue",
"dcterms:identifier":"issue"
"rtc_cm:type": {
"rdf:type": [],
"rtc_cm:iconUrl": "https://localhost:7443/jazz/service/com.ibm.team.workitem.common.internal.model.IImageContentService/processattachment/_Y868wPuZEeau1PCMVYBRLg/workitemtype/bug.gif",
"dcterms:title": "Issue",
"dcterms:identifier": "issue"
},
"git_cm:project_id": 23862,
"git_cm:milestone": {
"project_id" : 23862,
"description" : "Ducimus nam enim ex consequatur cumque ratione.",
"state" : "closed",
"project_id": 23862,
"description": "Ducimus nam enim ex consequatur cumque ratione.",
"state": "closed",
"start_date": "2016-01-04",
"due_date" : null,
"iid" : 2,
"created_at" : "2016-01-04T15:31:39.996Z",
"title" : "v4.0",
"id" : 17,
"updated_at" : "2016-01-04T15:31:39.996Z"
"due_date": null,
"iid": 2,
"created_at": "2016-01-04T15:31:39.996Z",
"title": "v4.0",
"id": 17,
"updated_at": "2016-01-04T15:31:39.996Z"
},
"git_cm:assignee": {
"id": 150,
Expand All @@ -66,14 +66,16 @@
"avatar_url": "url",
"web_url": "https://code.siemens.com/userurl"
},
"git_cm:assignees": [{
"id": 3537,
"name": "Bajohr Rayk adbara10",
"username": "adbara10",
"state": "active",
"avatar_url": "https://git.lab/uploads/-/system/user/avatar/115/avatar.png",
"web_url": "https://git.lab/adbara10"
}],
"git_cm:assignees": [
{
"id": 3537,
"name": "Bajohr Rayk adbara10",
"username": "adbara10",
"state": "active",
"avatar_url": "https://git.lab/uploads/-/system/user/avatar/115/avatar.png",
"web_url": "https://git.lab/adbara10"
}
],
"git_cm:author": {
"id": 3537,
"name": "Bajohr Rayk adbara10",
Expand All @@ -82,7 +84,7 @@
"avatar_url": "https://git.lab/uploads/-/system/user/avatar/115/avatar.png",
"web_url": "https://git.lab/adbara10"
},
"git_cm:closed_by" : {
"git_cm:closed_by": {
"id": 3537,
"name": "Bajohr Rayk adbara10",
"username": "adbara10",
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.jazzcommunity.GitConnectorService</groupId>
<artifactId>org.jazzcommunity.GitConnectorService.parent</artifactId>
<version>1.6.4-SNAPSHOT</version>
<version>1.7.1-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
Expand Down
4 changes: 2 additions & 2 deletions test/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: org.jazzcommunity.GitConnectorService
Bundle-SymbolicName: org.jazzcommunity.GitConnectorService.test;singleton:=true
Bundle-Version: 1.6.4.qualifier
Bundle-Version: 1.7.1.qualifier
Bundle-Vendor: VENDOR
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ClassPath: target/dependency/junit-4.12.jar,
target/dependency/hamcrest-core-1.3.jar,
target/dependency/gson-2.8.2.jar,
target/dependency/com.siemens.bt.jazz.services.base-3.0.2-SNAPSHOT.jar,
target/dependency/com.siemens.bt.jazz.services.PersonalTokenService-1.0.2-SNAPSHOT.jar,
target/dependency/org.jazzcommunity.GitConnectorService-1.6.4-SNAPSHOT.jar,
target/dependency/org.jazzcommunity.GitConnectorService-1.7.1-SNAPSHOT.jar,
target/dependency/asm-5.0.3.jar,
target/dependency/asm-analysis-5.0.3.jar,
target/dependency/asm-tree-5.0.3.jar,
Expand Down
4 changes: 2 additions & 2 deletions test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.jazzcommunity.GitConnectorService</groupId>
<artifactId>org.jazzcommunity.GitConnectorService.parent</artifactId>
<version>1.6.4-SNAPSHOT</version>
<version>1.7.1-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand All @@ -21,7 +21,7 @@
<dependency>
<groupId>org.jazzcommunity.GitConnectorService</groupId>
<artifactId>org.jazzcommunity.GitConnectorService</artifactId>
<version>1.6.4-SNAPSHOT</version>
<version>1.7.1-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down
Loading

0 comments on commit a0e71c6

Please sign in to comment.