From 15866226dc37a35f74ad8359bad7bffd8c91214a Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 29 May 2018 15:34:00 +0200 Subject: [PATCH 01/62] Add example payload for object generation --- .../main/resources/templates/oslc/issue.json | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 plugin/src/main/resources/templates/oslc/issue.json diff --git a/plugin/src/main/resources/templates/oslc/issue.json b/plugin/src/main/resources/templates/oslc/issue.json new file mode 100644 index 0000000..5176814 --- /dev/null +++ b/plugin/src/main/resources/templates/oslc/issue.json @@ -0,0 +1,82 @@ +{ + "dcterms:type": "Issue", + "git_cm:title": "iac variables shall allow to print to stdout", + "dcterms:title": "iac variables shall allow to print to stdout", + "dcterms:description": "In general a user wants a fast test to validate his variables based on the scope.\nWhen a user doesn't provide a output file (-o) the user would like to see the generated content in the stdout.\nThe following command shall use the standard output instead of a file:\n```bash\niac variables --scope ansible\n```", + "git_cm:description": "In general a user wants a fast test to validate his variables based on the scope.\nWhen a user doesn't provide a output file (-o) the user would like to see the generated content in the stdout.\nThe following command shall use the standard output instead of a file:\n```bash\niac variables --scope ansible\n```", + "dcterms:subject": "Feature, SizeXXL", + "git_cm:labels": [ + "Feature", + "SizeXXL" + ], + "rdf:about": "https://code.siemens.com/guido.schneider/RTC-Commit-Picker-Demo/issues/10", + "dcterms:created": "2018-02-09T17:18:28.949Z", + "git_cm:created_at": "2018-03-09T15:04:02.789+01:00", + "dcterms:modified": "2018-04-04T08:57:34.453Z", + "git_cm:updated_at": "2018-03-13T09:38:12.038+01:00", + "oslc_cm:closed": false, + "git_cm:closed_at": null, + "oslc_cm:status": "", + "git_cm:state": "opened", + "oslc:shortId": "42", + "dcterms:identifier": "80816", + "git_cm:id": 80816, + "git_cm:iid": 42, + "prefixes": { + "git_cm": "http://jazz-community.org/ns/git_cm", + "rtc_cm": "http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/", + "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", + "dcterms": "http://purl.org/dc/terms/", + "oslc": "http://open-services.net/ns/core#", + "oslc_cm": "http://open-services.net/ns/cm#" + }, + "oslc:shortTitle": "Issue 42", + "rtc_cm:due": "2018-04-19T10:00:00.000Z", + "rtc_cm:estimate": 18000000, + "rtc_cm:timeSpent": 10800000, + "rtc_cm:correctedEstimate": null, + "git_cm:details": "/details", + "git_cm:project_id": 23862, + "git_cm:milestone": { + "project_id" : 23862, + "description" : "Ducimus nam enim ex consequatur cumque ratione.", + "state" : "closed", + "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:assignees": [], + "git_cm:author": { + "id": 3537, + "name": "Bajohr Rayk adbara10", + "username": "adbara10", + "state": "active", + "avatar_url": null, + "web_url": "https://code.siemens.com/adbara10" + }, + "git_cm:closed_by" : null, + "git_cm:user_notes_count": 0, + "git_cm:upvotes": 0, + "git_cm:downvotes": 0, + "git_cm:due_date": null, + "git_cm:confidential": false, + "git_cm:weight": null, + "git_cm:discussion_locked": null, + "git_cm:web_url": "https://code.siemens.com/sisuite/sisuite-infrastructure-as-code/issues/42", + "git_cm:time_stats": { + "time_estimate": 0, + "total_time_spent": 0, + "human_time_estimate": null, + "human_total_time_spent": null + }, + "git_cm:_links": { + "self": "http://code.siemens.com/api/v4/projects/23862/issues/42", + "notes": "http://code.siemens.com/api/v4/projects/23862/issues/42/notes", + "award_emoji": "http://code.siemens.com/api/v4/projects/23862/issues/42/award_emoji", + "project": "http://code.siemens.com/api/v4/projects/23862" + }, + "git_cm:subscribed": false +} From 96b3cb64844ef1965c3a66f23838240aa8e3e323 Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 29 May 2018 16:11:41 +0200 Subject: [PATCH 02/62] Activate generation of oslc json payloads --- plugin/pom.xml | 43 ++- .../oslc/issue/OslcIssue.json} | 0 pom.xml | 288 +++++++++--------- 3 files changed, 166 insertions(+), 165 deletions(-) rename plugin/src/main/resources/{templates/oslc/issue.json => schemas/oslc/issue/OslcIssue.json} (100%) diff --git a/plugin/pom.xml b/plugin/pom.xml index 205a5a3..4e41eb8 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -32,28 +32,27 @@ - - - - - - - - - - - - - - - - - - - - - - + + org.jsonschema2pojo + jsonschema2pojo-maven-plugin + 0.5.1 + + true + gson + false + false + ${basedir}/src/main/resources/schemas/oslc + json + org.jazzcommunity.GitConnectorService.olsc.type + + + + + generate + + + + diff --git a/plugin/src/main/resources/templates/oslc/issue.json b/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json similarity index 100% rename from plugin/src/main/resources/templates/oslc/issue.json rename to plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json diff --git a/pom.xml b/pom.xml index e4c2212..1646a90 100644 --- a/pom.xml +++ b/pom.xml @@ -1,150 +1,152 @@ - - 4.0.0 + + 4.0.0 - org.jazzcommunity.GitConnectorService - org.jazzcommunity.GitConnectorService.parent - 1.0.0-SNAPSHOT - pom + org.jazzcommunity.GitConnectorService + org.jazzcommunity.GitConnectorService.parent + 1.0.0-SNAPSHOT + pom - - UTF-8 - 1.0.0 - + + UTF-8 + 1.0.0 + 1.7 + - - - junit - junit - 4.12 - test - - - com.google.code.gson - gson - 2.8.2 - - - org.jtwig - jtwig-core - 5.86.1.RELEASE - - - com.atlassian.commonmark - commonmark - 0.11.0 - - - ch.sbi - minigit - 1.0.0-SNAPSHOT - - - com.siemens.bt.jazz.services.base - com.siemens.bt.jazz.services.base - 2.0.1-SNAPSHOT - - - com.siemens.bt.jazz.services.PersonalTokenService - com.siemens.bt.jazz.services.PersonalTokenService - 1.0.1-SNAPSHOT - - + + + junit + junit + 4.12 + test + + + com.google.code.gson + gson + 2.8.2 + + + org.jtwig + jtwig-core + 5.86.1.RELEASE + + + com.atlassian.commonmark + commonmark + 0.11.0 + + + ch.sbi + minigit + 1.0.0-SNAPSHOT + + + com.siemens.bt.jazz.services.base + com.siemens.bt.jazz.services.base + 2.0.1-SNAPSHOT + + + com.siemens.bt.jazz.services.PersonalTokenService + com.siemens.bt.jazz.services.PersonalTokenService + 1.0.1-SNAPSHOT + + - - plugin - feature - update-site - test - + + plugin + feature + update-site + test + - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.5.1 - - 1.7 - 1.7 - - - - org.apache.maven.plugins - maven-dependency-plugin - 3.0.0 - - - copy-dependencies-init - initialize - - copy-dependencies - - - runtime - - - - - - org.eclipse.tycho - tycho-maven-plugin - ${tycho-version} - true - - - org.eclipse.tycho - target-platform-configuration - ${tycho-version} - - - - - - - linux - gtk - x86 - - - linux - gtk - x86_64 - - - win32 - win32 - x86 - - - win32 - win32 - x86_64 - - - macosx - cocoa - x86_64 - - - - - - - - + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + ${java-version} + ${java-version} + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.0.0 + + + copy-dependencies-init + initialize + + copy-dependencies + + + runtime + + + + + + org.eclipse.tycho + tycho-maven-plugin + ${tycho-version} + true + + + org.eclipse.tycho + target-platform-configuration + ${tycho-version} + + + + + + + linux + gtk + x86 + + + linux + gtk + x86_64 + + + win32 + win32 + x86 + + + win32 + win32 + x86_64 + + + macosx + cocoa + x86_64 + + + + + + + + From 96330dfc0bc9f612779654c8a6eea575935a0380 Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 29 May 2018 16:26:56 +0200 Subject: [PATCH 03/62] Add oslc request handling --- .../GitConnectorService/builder/gitlab/IssueLinkService.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java index 962bced..7ce4ddf 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java @@ -31,11 +31,16 @@ public void execute() throws IOException { if (Request.isLinkRequest(request)) { sendLinkResponse(issue, parameters); + } else if(Request.isOslcRequest(request)) { + sendOslcResponse(issue, parameters); } else { response.sendRedirect(issue.getWebUrl()); } } + private void sendOslcResponse(Issue issue, UrlParameters parameters) { + } + private void sendLinkResponse(Issue issue, UrlParameters parameters) throws IOException { URL preview = UrlBuilder.getPreviewUrl(parentService, parameters, "issue"); From 2e7d9888ea695cd4744f3e4b75af630c9220ceff Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 29 May 2018 17:49:24 +0200 Subject: [PATCH 04/62] Implement basic and non-functional automapping --- plugin/META-INF/MANIFEST.MF | 1 + .../builder/gitlab/IssueLinkService.java | 14 +++++++++++++- pom.xml | 12 +++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/plugin/META-INF/MANIFEST.MF b/plugin/META-INF/MANIFEST.MF index 2d283f9..a030ef5 100644 --- a/plugin/META-INF/MANIFEST.MF +++ b/plugin/META-INF/MANIFEST.MF @@ -49,6 +49,7 @@ Bundle-ClassPath: target/dependency/gson-2.8.2.jar, target/dependency/parboiled-java-1.1.7.jar, target/dependency/minigit-1.0.0-SNAPSHOT.jar, target/dependency/commonmark-0.11.0.jar, + target/dependency/modelmapper-2.0.0.jar, target/java-gen, . Import-Package: com.ibm.team.jfs.app, diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java index 7ce4ddf..031f9fd 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java @@ -2,17 +2,22 @@ import ch.sbi.minigit.gitlab.GitlabApi; import ch.sbi.minigit.type.gitlab.issue.Issue; +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.AbstractRestService; import com.siemens.bt.jazz.services.base.rest.RestRequest; import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.logging.Log; +import org.apache.http.entity.ContentType; import org.jazzcommunity.GitConnectorService.data.TokenHelper; import org.jazzcommunity.GitConnectorService.net.Request; import org.jazzcommunity.GitConnectorService.net.UrlBuilder; import org.jazzcommunity.GitConnectorService.net.UrlParameters; +import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; import org.jtwig.JtwigModel; import org.jtwig.JtwigTemplate; +import org.modelmapper.ModelMapper; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -38,7 +43,14 @@ public void execute() throws IOException { } } - private void sendOslcResponse(Issue issue, UrlParameters parameters) { + private void sendOslcResponse(Issue issue, UrlParameters parameters) throws IOException { + // what might I need parameters for here? + ModelMapper mapper = new ModelMapper(); + OslcIssue oslcPayload = mapper.map(issue, OslcIssue.class); + Gson gson = new GsonBuilder().create(); + String json = gson.toJson(oslcPayload); + response.setContentType(ContentType.APPLICATION_JSON.toString()); + response.getWriter().write(json); } private void sendLinkResponse(Issue issue, UrlParameters parameters) throws IOException { diff --git a/pom.xml b/pom.xml index 1646a90..3ec76ed 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ UTF-8 - 1.0.0 + 1.1.0 1.7 @@ -51,6 +51,11 @@ com.siemens.bt.jazz.services.PersonalTokenService 1.0.1-SNAPSHOT + + org.modelmapper + modelmapper + 2.0.0 + @@ -62,6 +67,11 @@ + + org.eclipse.tycho + tycho-versions-plugin + ${tycho-version} + org.apache.maven.plugins maven-compiler-plugin From 2d77c8d6dc8c24ceca8bf512ea04fcca43508f78 Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 29 May 2018 18:03:25 +0200 Subject: [PATCH 05/62] Demonstrate how to use modelmapper for clean mappings between payloads --- .../builder/gitlab/IssueLinkService.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java index 031f9fd..c4431cd 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java @@ -18,6 +18,7 @@ import org.jtwig.JtwigModel; import org.jtwig.JtwigTemplate; import org.modelmapper.ModelMapper; +import org.modelmapper.PropertyMap; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -46,6 +47,15 @@ public void execute() throws IOException { private void sendOslcResponse(Issue issue, UrlParameters parameters) throws IOException { // what might I need parameters for here? ModelMapper mapper = new ModelMapper(); + + mapper.addMappings(new PropertyMap() { + @Override + protected void configure() { + map().setDctermsTitle(source.getTitle()); + map().setDctermsDescription(source.getDescription()); + } + }); + OslcIssue oslcPayload = mapper.map(issue, OslcIssue.class); Gson gson = new GsonBuilder().create(); String json = gson.toJson(oslcPayload); From 67447317bd73cc5c459c45de308f9ea95827b359 Mon Sep 17 00:00:00 2001 From: SBI- Date: Mon, 4 Jun 2018 10:52:48 +0200 Subject: [PATCH 06/62] Extract mapping logic to seperate package Also introduced a string utility class to avoid using google guava. If we need more comparable functionlity, we should throw this away and just use guava instead. --- .../mapping/IssueMapper.java | 31 +++++++++++++++++++ .../mapping/StringJoiner.java | 30 ++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java create mode 100644 plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/StringJoiner.java diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java new file mode 100644 index 0000000..2003db0 --- /dev/null +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java @@ -0,0 +1,31 @@ +package org.jazzcommunity.GitConnectorService.mapping; + +import ch.sbi.minigit.type.gitlab.issue.Issue; +import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; +import org.modelmapper.ModelMapper; +import org.modelmapper.PropertyMap; + +public class IssueMapper { + private IssueMapper(){} + + public static ModelMapper get() { + ModelMapper mapper = new ModelMapper(); + + mapper.addMappings(new PropertyMap() { + @Override + protected void configure() { + map().setDctermsType("Issue"); + + map().setDctermsTitle(source.getTitle()); + map().setGitCmTitle(source.getTitle()); + + map().setDctermsDescription(source.getDescription()); + map().setGitCmDescription(source.getDescription()); + + map().setDctermsSubject(StringJoiner.join(source.getLabels(), ", ")); + } + }); + + return mapper; + } +} diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/StringJoiner.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/StringJoiner.java new file mode 100644 index 0000000..dfd5340 --- /dev/null +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/StringJoiner.java @@ -0,0 +1,30 @@ +package org.jazzcommunity.GitConnectorService.mapping; + +import java.util.Collection; + +/** + * This could be solved using Google's guava library. To reduce dependencies, this class was + * added. However, if we need more functionality of this kind, we really should consider + * using a proper library for this. + */ +public class StringJoiner { + private StringJoiner() {} + + public static String join(Collection strings) { + return join(strings, ""); + } + + public static String join(Collection strings, String on) { + if (strings == null || strings.size() == 0) { + return ""; + } + + StringBuilder builder = new StringBuilder(); + for (String string : strings) { + builder.append(string); + builder.append(on); + } +// builder.delete(builder.length() - on.length() - 1, builder.length() - 1); + return builder.toString(); + } +} From b5a1132aa6ce601eb7024ebf4144b3b556dda63d Mon Sep 17 00:00:00 2001 From: SBI- Date: Mon, 4 Jun 2018 11:39:22 +0200 Subject: [PATCH 07/62] Implement label mapping demonstrating converter Showing how to work with custom converters and java 7 syntax to convert between objects and not only properties. --- .../builder/gitlab/IssueLinkService.java | 14 +++---------- .../mapping/IssueMapper.java | 20 +++++++++++++++++-- .../mapping/StringJoiner.java | 1 + 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java index c4431cd..91c8935 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java @@ -11,6 +11,7 @@ import org.apache.commons.logging.Log; import org.apache.http.entity.ContentType; import org.jazzcommunity.GitConnectorService.data.TokenHelper; +import org.jazzcommunity.GitConnectorService.mapping.IssueMapper; import org.jazzcommunity.GitConnectorService.net.Request; import org.jazzcommunity.GitConnectorService.net.UrlBuilder; import org.jazzcommunity.GitConnectorService.net.UrlParameters; @@ -18,7 +19,6 @@ import org.jtwig.JtwigModel; import org.jtwig.JtwigTemplate; import org.modelmapper.ModelMapper; -import org.modelmapper.PropertyMap; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -46,16 +46,8 @@ public void execute() throws IOException { private void sendOslcResponse(Issue issue, UrlParameters parameters) throws IOException { // what might I need parameters for here? - ModelMapper mapper = new ModelMapper(); - - mapper.addMappings(new PropertyMap() { - @Override - protected void configure() { - map().setDctermsTitle(source.getTitle()); - map().setDctermsDescription(source.getDescription()); - } - }); - + ModelMapper mapper = IssueMapper.get(); + // instead of get, IssueMapper should just export a 'map' function anyway... OslcIssue oslcPayload = mapper.map(issue, OslcIssue.class); Gson gson = new GsonBuilder().create(); String json = gson.toJson(oslcPayload); diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java index 2003db0..a32323d 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java @@ -2,14 +2,25 @@ import ch.sbi.minigit.type.gitlab.issue.Issue; import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; +import org.modelmapper.AbstractConverter; import org.modelmapper.ModelMapper; import org.modelmapper.PropertyMap; +import java.util.Collection; + public class IssueMapper { private IssueMapper(){} public static ModelMapper get() { - ModelMapper mapper = new ModelMapper(); + final ModelMapper mapper = new ModelMapper(); + + final AbstractConverter, String> labelConverter = + new AbstractConverter, String>() { + @Override + protected String convert(Collection strings) { + return StringJoiner.join(strings, ", "); + } + }; mapper.addMappings(new PropertyMap() { @Override @@ -22,7 +33,12 @@ protected void configure() { map().setDctermsDescription(source.getDescription()); map().setGitCmDescription(source.getDescription()); - map().setDctermsSubject(StringJoiner.join(source.getLabels(), ", ")); + /* + * see http://modelmapper.org/user-manual/property-mapping/ for documentation on the convention + * of passing null when using a custom converter. + */ + using(labelConverter).map(source.getLabels()).setDctermsSubject(null); + map().setGitCmLabels(source.getLabels()); } }); diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/StringJoiner.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/StringJoiner.java index dfd5340..ee2c966 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/StringJoiner.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/StringJoiner.java @@ -15,6 +15,7 @@ public static String join(Collection strings) { } public static String join(Collection strings, String on) { + // I'm fairly sure this is unnecessary if (strings == null || strings.size() == 0) { return ""; } From 77b63b6e3cf6ea34de1badd238180cb4084b1e43 Mon Sep 17 00:00:00 2001 From: SBI- Date: Mon, 4 Jun 2018 12:02:43 +0200 Subject: [PATCH 08/62] Clean up string joiner implementation --- .../GitConnectorService/mapping/IssueMapper.java | 2 ++ .../GitConnectorService/mapping/StringJoiner.java | 9 +++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java index a32323d..3283f92 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java @@ -39,6 +39,8 @@ protected void configure() { */ using(labelConverter).map(source.getLabels()).setDctermsSubject(null); map().setGitCmLabels(source.getLabels()); + + // dates left out for now. } }); diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/StringJoiner.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/StringJoiner.java index ee2c966..bee8a03 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/StringJoiner.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/StringJoiner.java @@ -15,17 +15,14 @@ public static String join(Collection strings) { } public static String join(Collection strings, String on) { - // I'm fairly sure this is unnecessary - if (strings == null || strings.size() == 0) { - return ""; - } - StringBuilder builder = new StringBuilder(); + for (String string : strings) { builder.append(string); builder.append(on); } -// builder.delete(builder.length() - on.length() - 1, builder.length() - 1); + + builder.delete(builder.length() - on.length(), builder.length()); return builder.toString(); } } From 5822d58f4a5c9ba233a9d3677639339d07328708 Mon Sep 17 00:00:00 2001 From: SBI- Date: Mon, 4 Jun 2018 12:38:26 +0200 Subject: [PATCH 09/62] Add converter for short title --- .../mapping/IssueMapper.java | 24 +++++++++++++++++-- .../schemas/oslc/issue/OslcIssue.json | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java index 3283f92..5298b48 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java @@ -14,7 +14,7 @@ private IssueMapper(){} public static ModelMapper get() { final ModelMapper mapper = new ModelMapper(); - final AbstractConverter, String> labelConverter = + final AbstractConverter, String> listToString = new AbstractConverter, String>() { @Override protected String convert(Collection strings) { @@ -22,6 +22,14 @@ protected String convert(Collection strings) { } }; + final AbstractConverter shortTitleConverter = + new AbstractConverter() { + @Override + protected String convert(Integer iid) { + return "Issue " + iid; + } + }; + mapper.addMappings(new PropertyMap() { @Override protected void configure() { @@ -37,10 +45,22 @@ protected void configure() { * see http://modelmapper.org/user-manual/property-mapping/ for documentation on the convention * of passing null when using a custom converter. */ - using(labelConverter).map(source.getLabels()).setDctermsSubject(null); + using(listToString).map(source.getLabels()).setDctermsSubject(null); map().setGitCmLabels(source.getLabels()); // dates left out for now. + + // does this need a custom converter? + map().setOslcCmClosed(source.getClosedAt() != null); + + // Todos skipped + + map().setGitCmId(source.getId()); + map().setGitCmIid(source.getIid()); + + // prefixes skipped, this will need to be a custom object defined separately + + using(shortTitleConverter).map(source.getIid()).setOslcShortTitle(null); } }); diff --git a/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json b/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json index 5176814..fb02759 100644 --- a/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json +++ b/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json @@ -15,7 +15,7 @@ "dcterms:modified": "2018-04-04T08:57:34.453Z", "git_cm:updated_at": "2018-03-13T09:38:12.038+01:00", "oslc_cm:closed": false, - "git_cm:closed_at": null, + "git_cm:closed_at": "2018-03-13T09:38:12.038+01:00", "oslc_cm:status": "", "git_cm:state": "opened", "oslc:shortId": "42", From d9b1a99d72ec15d2538db8e4fae08d3097273f53 Mon Sep 17 00:00:00 2001 From: SBI- Date: Mon, 4 Jun 2018 13:57:58 +0200 Subject: [PATCH 10/62] Add oslc state converter --- .../mapping/IssueMapper.java | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java index 5298b48..6182d16 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java @@ -14,6 +14,8 @@ private IssueMapper(){} public static ModelMapper get() { final ModelMapper mapper = new ModelMapper(); + // I think a log of these converters can be extracted and reused, especially the ones that will + // need to be written for deep mapping of objects like links etc. final AbstractConverter, String> listToString = new AbstractConverter, String>() { @Override @@ -30,6 +32,13 @@ protected String convert(Integer iid) { } }; + final AbstractConverter stateConverter = new AbstractConverter() { + @Override + protected Boolean convert(String state) { + return state != null; + } + }; + mapper.addMappings(new PropertyMap() { @Override protected void configure() { @@ -48,10 +57,13 @@ protected void configure() { using(listToString).map(source.getLabels()).setDctermsSubject(null); map().setGitCmLabels(source.getLabels()); + // rdf:about needs to be the url of this link, so something like + // https://localhost:7443/jazz/service/org.jazzcommunity.GitConnectorService.IGitConnectorService/gitlab/code.siemens.com/project/13027/issue/9/link + // dates left out for now. // does this need a custom converter? - map().setOslcCmClosed(source.getClosedAt() != null); + using(stateConverter).map(source.getClosedAt()).setOslcCmClosed(null); // Todos skipped @@ -61,6 +73,27 @@ protected void configure() { // prefixes skipped, this will need to be a custom object defined separately using(shortTitleConverter).map(source.getIid()).setOslcShortTitle(null); + + // Lots of properties skipped which are not definitively defined + + map().setGitCmProjectId(source.getProjectId()); + + // milestone skipped because deep object not defined yet + // same with assignees and author + + map().setGitCmUserNotesCount(source.getUserNotesCount()); + map().setGitCmUpvotes(source.getUpvotes()); + map().setGitCmDownvotes(source.getDownvotes()); + map().setGitCmDueDate(source.getDueDate()); + map().setGitCmConfidential(source.getConfidential()); + // Weight skipped, EE feature only. Not sure if we need this. + map().setGitCmDiscussionLocked(source.getDiscussionLocked()); + map().setGitCmWebUrl(source.getWebUrl()); + + // time stats skipped, deep mapping undefined + + // links skipped, deep mapping not implemented + map().setGitCmSubscribed(source.getSubscribed()); } }); From 8686dbf45c0597a13990c62b9db05bc562f1612c Mon Sep 17 00:00:00 2001 From: SBI- Date: Mon, 4 Jun 2018 14:17:56 +0200 Subject: [PATCH 11/62] Split URL builder for different links --- .../mapping/IssueMapper.java | 1 - .../GitConnectorService/net/UrlBuilder.java | 24 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java index 6182d16..099a9be 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java @@ -62,7 +62,6 @@ protected void configure() { // dates left out for now. - // does this need a custom converter? using(stateConverter).map(source.getClosedAt()).setOslcCmClosed(null); // Todos skipped diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/net/UrlBuilder.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/net/UrlBuilder.java index 9f5ca7c..2021b14 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/net/UrlBuilder.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/net/UrlBuilder.java @@ -10,16 +10,32 @@ public class UrlBuilder { public static URL getPreviewUrl( TeamRawService parentService, UrlParameters parameters, - String type) throws MalformedURLException { + String gitType) throws MalformedURLException { + return getUrl(parentService, parameters, gitType, "preview"); + } + + public static URL getLinkUrl( + TeamRawService parentService, + UrlParameters parameters, + String gitType) throws MalformedURLException { + return getUrl(parentService, parameters, gitType, "link"); + } + + private static URL getUrl( + TeamRawService parentService, + UrlParameters parameters, + String gitType, + String linkType) throws MalformedURLException { String base = parentService.getRequestRepositoryURL(); String name = parentService.getClass().getInterfaces()[0].getCanonicalName(); return new URL(String.format( - "%sservice/%s/gitlab/%s/project/%s/%s/%s/preview", + "%sservice/%s/gitlab/%s/project/%s/%s/%s/%s", base, name, parameters.getHost(), parameters.getProject(), - type, - parameters.getArtifact())); + gitType, + parameters.getArtifact(), + linkType)); } } From ee5188d4e17708cb8052caedc2bca93061ed9582 Mon Sep 17 00:00:00 2001 From: SBI- Date: Mon, 4 Jun 2018 14:21:25 +0200 Subject: [PATCH 12/62] Create map method that maps right away --- .../GitConnectorService/builder/gitlab/IssueLinkService.java | 4 ++-- .../GitConnectorService/mapping/IssueMapper.java | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java index 91c8935..50beab2 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java @@ -46,9 +46,9 @@ public void execute() throws IOException { private void sendOslcResponse(Issue issue, UrlParameters parameters) throws IOException { // what might I need parameters for here? - ModelMapper mapper = IssueMapper.get(); // instead of get, IssueMapper should just export a 'map' function anyway... - OslcIssue oslcPayload = mapper.map(issue, OslcIssue.class); + OslcIssue oslcPayload = + IssueMapper.map(issue, UrlBuilder.getLinkUrl(parentService, parameters, "issue")); Gson gson = new GsonBuilder().create(); String json = gson.toJson(oslcPayload); response.setContentType(ContentType.APPLICATION_JSON.toString()); diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java index 099a9be..5f9286d 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java @@ -6,12 +6,13 @@ import org.modelmapper.ModelMapper; import org.modelmapper.PropertyMap; +import java.net.URL; import java.util.Collection; public class IssueMapper { private IssueMapper(){} - public static ModelMapper get() { + public static OslcIssue map(Issue issue, URL self) { final ModelMapper mapper = new ModelMapper(); // I think a log of these converters can be extracted and reused, especially the ones that will @@ -96,6 +97,6 @@ protected void configure() { } }); - return mapper; + return mapper.map(issue, OslcIssue.class); } } From d937698dcdc866ca13c4cb8ffc1b25e55c23ceae Mon Sep 17 00:00:00 2001 From: SBI- Date: Mon, 4 Jun 2018 14:46:50 +0200 Subject: [PATCH 13/62] Add rdf:about link to current jazz link --- .../GitConnectorService/mapping/IssueMapper.java | 7 ++++++- .../GitConnectorService/mapping/StringJoiner.java | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java index 5f9286d..9255654 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java @@ -3,6 +3,7 @@ import ch.sbi.minigit.type.gitlab.issue.Issue; import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; import org.modelmapper.AbstractConverter; +import org.modelmapper.AbstractProvider; import org.modelmapper.ModelMapper; import org.modelmapper.PropertyMap; @@ -12,7 +13,8 @@ public class IssueMapper { private IssueMapper(){} - public static OslcIssue map(Issue issue, URL self) { + public static OslcIssue map(Issue issue, final URL self) { + final String link = self.toString(); final ModelMapper mapper = new ModelMapper(); // I think a log of these converters can be extracted and reused, especially the ones that will @@ -58,6 +60,9 @@ protected void configure() { using(listToString).map(source.getLabels()).setDctermsSubject(null); map().setGitCmLabels(source.getLabels()); + // self should probably be in a provider + map().setRdfAbout(link); + // rdf:about needs to be the url of this link, so something like // https://localhost:7443/jazz/service/org.jazzcommunity.GitConnectorService.IGitConnectorService/gitlab/code.siemens.com/project/13027/issue/9/link diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/StringJoiner.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/StringJoiner.java index bee8a03..3e9d8de 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/StringJoiner.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/StringJoiner.java @@ -15,6 +15,10 @@ public static String join(Collection strings) { } public static String join(Collection strings, String on) { + if (strings == null || strings.size() <= 0) { + return ""; + } + StringBuilder builder = new StringBuilder(); for (String string : strings) { From c280d15303e6737dcf1074ce4f6097280b32ce92 Mon Sep 17 00:00:00 2001 From: SBI- Date: Mon, 4 Jun 2018 17:04:32 +0200 Subject: [PATCH 14/62] Add git date mapping --- .../GitConnectorService/mapping/IssueMapper.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java index 9255654..6637024 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java @@ -3,7 +3,6 @@ import ch.sbi.minigit.type.gitlab.issue.Issue; import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; import org.modelmapper.AbstractConverter; -import org.modelmapper.AbstractProvider; import org.modelmapper.ModelMapper; import org.modelmapper.PropertyMap; @@ -60,13 +59,18 @@ protected void configure() { using(listToString).map(source.getLabels()).setDctermsSubject(null); map().setGitCmLabels(source.getLabels()); - // self should probably be in a provider map().setRdfAbout(link); // rdf:about needs to be the url of this link, so something like // https://localhost:7443/jazz/service/org.jazzcommunity.GitConnectorService.IGitConnectorService/gitlab/code.siemens.com/project/13027/issue/9/link // dates left out for now. + // jazz dates need to just be utc, while github dates are ISO with timezone + // for converting to utc, I'll probably want to use the threeten backport: + // http://www.threeten.org/threetenbp/ + + map().setGitCmCreatedAt(source.getCreatedAt()); + map().setGitCmUpdatedAt(source.getUpdatedAt()); using(stateConverter).map(source.getClosedAt()).setOslcCmClosed(null); From ecbc6f75e56cffe35605e85b5cbbc184a4cad8e9 Mon Sep 17 00:00:00 2001 From: SBI- Date: Mon, 4 Jun 2018 17:21:31 +0200 Subject: [PATCH 15/62] Add threethen backport for timezone conversion --- plugin/META-INF/MANIFEST.MF | 1 + .../GitConnectorService/mapping/IssueMapper.java | 7 +++++++ pom.xml | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/plugin/META-INF/MANIFEST.MF b/plugin/META-INF/MANIFEST.MF index a030ef5..2ea6cf2 100644 --- a/plugin/META-INF/MANIFEST.MF +++ b/plugin/META-INF/MANIFEST.MF @@ -50,6 +50,7 @@ Bundle-ClassPath: target/dependency/gson-2.8.2.jar, target/dependency/minigit-1.0.0-SNAPSHOT.jar, target/dependency/commonmark-0.11.0.jar, target/dependency/modelmapper-2.0.0.jar, + target/dependency/threetenbp-1.3.6.jar, target/java-gen, . Import-Package: com.ibm.team.jfs.app, diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java index 6637024..4c0c19e 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java @@ -41,6 +41,13 @@ protected Boolean convert(String state) { } }; + AbstractConverter toUtc = new AbstractConverter() { + @Override + protected String convert(String datetime) { + return null; + } + }; + mapper.addMappings(new PropertyMap() { @Override protected void configure() { diff --git a/pom.xml b/pom.xml index 3ec76ed..f40a57e 100644 --- a/pom.xml +++ b/pom.xml @@ -56,6 +56,11 @@ modelmapper 2.0.0 + + org.threeten + threetenbp + 1.3.6 + From cfcc8313ff84dab9b77b4d0a4dd48228b222d793 Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 08:24:12 +0200 Subject: [PATCH 16/62] Fix comments regarding date --- .../mapping/IssueMapper.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java index 4c0c19e..1483add 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java @@ -5,6 +5,8 @@ import org.modelmapper.AbstractConverter; import org.modelmapper.ModelMapper; import org.modelmapper.PropertyMap; +import org.threeten.bp.LocalDateTime; +import org.threeten.bp.format.DateTimeFormatter; import java.net.URL; import java.util.Collection; @@ -41,10 +43,12 @@ protected Boolean convert(String state) { } }; - AbstractConverter toUtc = new AbstractConverter() { + final AbstractConverter toUtc = new AbstractConverter() { @Override protected String convert(String datetime) { - return null; + LocalDateTime parsed = LocalDateTime.parse(datetime); + // actually, just confirm that those are utc times... + return parsed.toString(); } }; @@ -72,13 +76,13 @@ protected void configure() { // https://localhost:7443/jazz/service/org.jazzcommunity.GitConnectorService.IGitConnectorService/gitlab/code.siemens.com/project/13027/issue/9/link // dates left out for now. - // jazz dates need to just be utc, while github dates are ISO with timezone - // for converting to utc, I'll probably want to use the threeten backport: - // http://www.threeten.org/threetenbp/ + // All dates are utc anyway... No need to convert anything map().setGitCmCreatedAt(source.getCreatedAt()); map().setGitCmUpdatedAt(source.getUpdatedAt()); + using(toUtc).map(source.getCreatedAt()).setDctermsCreated(null); + using(stateConverter).map(source.getClosedAt()).setOslcCmClosed(null); // Todos skipped @@ -108,6 +112,10 @@ protected void configure() { // time stats skipped, deep mapping undefined + // this is for the due date, which is just a datestring "2018-09-11" + // for converting to utc, I'll probably want to use the threeten backport: + // http://www.threeten.org/threetenbp/ + // links skipped, deep mapping not implemented map().setGitCmSubscribed(source.getSubscribed()); } From c45cff9dcfa2af3b12169c5487a48bb20d0da75f Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 09:03:53 +0200 Subject: [PATCH 17/62] Handle all utc dates --- .../GitConnectorService/mapping/IssueMapper.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java index 1483add..7412db8 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java @@ -43,15 +43,6 @@ protected Boolean convert(String state) { } }; - final AbstractConverter toUtc = new AbstractConverter() { - @Override - protected String convert(String datetime) { - LocalDateTime parsed = LocalDateTime.parse(datetime); - // actually, just confirm that those are utc times... - return parsed.toString(); - } - }; - mapper.addMappings(new PropertyMap() { @Override protected void configure() { @@ -80,8 +71,9 @@ protected void configure() { map().setGitCmCreatedAt(source.getCreatedAt()); map().setGitCmUpdatedAt(source.getUpdatedAt()); + map().setDctermsCreated(source.getCreatedAt()); + map().setDctermsModified(source.getUpdatedAt()); - using(toUtc).map(source.getCreatedAt()).setDctermsCreated(null); using(stateConverter).map(source.getClosedAt()).setOslcCmClosed(null); From 9aade6bea01b2e784607d30e1889bb7425dcf468 Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 09:23:17 +0200 Subject: [PATCH 18/62] Remove string join implemenation I just realized that google guava is a transitive dependency anyway, so we can just use it anyway. Replaced string fuctionality with appropriate guava function. --- .../mapping/IssueMapper.java | 3 +- .../mapping/StringJoiner.java | 32 ------------------- 2 files changed, 2 insertions(+), 33 deletions(-) delete mode 100644 plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/StringJoiner.java diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java index 7412db8..418bb5d 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java @@ -1,6 +1,7 @@ package org.jazzcommunity.GitConnectorService.mapping; import ch.sbi.minigit.type.gitlab.issue.Issue; +import com.google.common.base.Joiner; import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; import org.modelmapper.AbstractConverter; import org.modelmapper.ModelMapper; @@ -24,7 +25,7 @@ public static OslcIssue map(Issue issue, final URL self) { new AbstractConverter, String>() { @Override protected String convert(Collection strings) { - return StringJoiner.join(strings, ", "); + return Joiner.on(", ").join(strings); } }; diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/StringJoiner.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/StringJoiner.java deleted file mode 100644 index 3e9d8de..0000000 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/StringJoiner.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.jazzcommunity.GitConnectorService.mapping; - -import java.util.Collection; - -/** - * This could be solved using Google's guava library. To reduce dependencies, this class was - * added. However, if we need more functionality of this kind, we really should consider - * using a proper library for this. - */ -public class StringJoiner { - private StringJoiner() {} - - public static String join(Collection strings) { - return join(strings, ""); - } - - public static String join(Collection strings, String on) { - if (strings == null || strings.size() <= 0) { - return ""; - } - - StringBuilder builder = new StringBuilder(); - - for (String string : strings) { - builder.append(string); - builder.append(on); - } - - builder.delete(builder.length() - on.length(), builder.length()); - return builder.toString(); - } -} From d2a64408990b97096cbc5aabe9c52eea2393bb38 Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 09:31:22 +0200 Subject: [PATCH 19/62] Add state mapping --- .../GitConnectorService/mapping/IssueMapper.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java index 418bb5d..e8f05bc 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java @@ -79,6 +79,11 @@ protected void configure() { using(stateConverter).map(source.getClosedAt()).setOslcCmClosed(null); // Todos skipped + map().setGitCmClosedAt(source.getClosedAt()); + map().setOslcCmStatus(source.getState()); + map().setGitCmState(source.getState()); + map().setOslcShortId(source.getIid().toString()); + map().setDctermsIdentifier(source.getId().toString()); map().setGitCmId(source.getId()); map().setGitCmIid(source.getIid()); From 9a7421e0f73b0441409397169b3cf71d0ac24e85 Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 09:34:53 +0200 Subject: [PATCH 20/62] Clean up oslc package naming --- .../GitConnectorService/builder/gitlab/IssueLinkService.java | 3 +-- .../GitConnectorService/{ => oslc}/mapping/IssueMapper.java | 2 +- .../jazzcommunity/GitConnectorService/oslc/type/Prefixes.java | 4 ++++ 3 files changed, 6 insertions(+), 3 deletions(-) rename plugin/src/main/java/org/jazzcommunity/GitConnectorService/{ => oslc}/mapping/IssueMapper.java (98%) create mode 100644 plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/type/Prefixes.java diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java index 50beab2..d71026c 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java @@ -11,14 +11,13 @@ import org.apache.commons.logging.Log; import org.apache.http.entity.ContentType; import org.jazzcommunity.GitConnectorService.data.TokenHelper; -import org.jazzcommunity.GitConnectorService.mapping.IssueMapper; +import org.jazzcommunity.GitConnectorService.oslc.mapping.IssueMapper; import org.jazzcommunity.GitConnectorService.net.Request; import org.jazzcommunity.GitConnectorService.net.UrlBuilder; import org.jazzcommunity.GitConnectorService.net.UrlParameters; import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; import org.jtwig.JtwigModel; import org.jtwig.JtwigTemplate; -import org.modelmapper.ModelMapper; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java similarity index 98% rename from plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java rename to plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index e8f05bc..5df0c70 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -1,4 +1,4 @@ -package org.jazzcommunity.GitConnectorService.mapping; +package org.jazzcommunity.GitConnectorService.oslc.mapping; import ch.sbi.minigit.type.gitlab.issue.Issue; import com.google.common.base.Joiner; diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/type/Prefixes.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/type/Prefixes.java new file mode 100644 index 0000000..12facd6 --- /dev/null +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/type/Prefixes.java @@ -0,0 +1,4 @@ +package org.jazzcommunity.GitConnectorService.oslc.type; + +public class Prefixes { +} From de957b06ebca6ec51d3d13591252c43b78fb8095 Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 10:04:58 +0200 Subject: [PATCH 21/62] Set up test module for testing data mapping --- plugin/META-INF/MANIFEST.MF | 2 +- .../oslc/mapping/IssueMapper.java | 2 + .../oslc/type/Prefixes.java | 29 +++++++++++++- test/META-INF/MANIFEST.MF | 18 ++++++++- test/pom.xml | 40 +++++++++++++++++++ .../oslc/mapping/IssueMapperTests.java | 6 +++ 6 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTests.java diff --git a/plugin/META-INF/MANIFEST.MF b/plugin/META-INF/MANIFEST.MF index 2ea6cf2..2b47026 100644 --- a/plugin/META-INF/MANIFEST.MF +++ b/plugin/META-INF/MANIFEST.MF @@ -35,7 +35,7 @@ Require-Bundle: com.ibm.team.build.service Bundle-ClassPath: target/dependency/gson-2.8.2.jar, target/dependency/com.siemens.bt.jazz.services.base-2.0.1-SNAPSHOT.jar, - target/dependency/com.siemens.bt.jazz.services.PersonalTokenService-1.0.1-SNAPSHOT.jar, + target/dependency/com.siemens.bt.jazz.services.PersonalTokenService-1.0.2-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, diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index 5df0c70..81ea43b 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -3,6 +3,7 @@ import ch.sbi.minigit.type.gitlab.issue.Issue; import com.google.common.base.Joiner; import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; +import org.jazzcommunity.GitConnectorService.olsc.type.issue.Prefixes; import org.modelmapper.AbstractConverter; import org.modelmapper.ModelMapper; import org.modelmapper.PropertyMap; @@ -75,6 +76,7 @@ protected void configure() { map().setDctermsCreated(source.getCreatedAt()); map().setDctermsModified(source.getUpdatedAt()); + map().setPrefixes(new Prefixes()); using(stateConverter).map(source.getClosedAt()).setOslcCmClosed(null); diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/type/Prefixes.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/type/Prefixes.java index 12facd6..ba4f51a 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/type/Prefixes.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/type/Prefixes.java @@ -1,4 +1,31 @@ package org.jazzcommunity.GitConnectorService.oslc.type; -public class Prefixes { +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public final class Prefixes { + + @SerializedName("git_cm") + @Expose + private final String gitCm = "http://jazz-community.org/ns/git_cm"; + + @SerializedName("rtc_cm") + @Expose + private final String rtcCm = "http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/"; + + @SerializedName("rdf") + @Expose + private final String rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; + + @SerializedName("dcterms") + @Expose + private final String dcterms = "http://purl.org/dc/terms/"; + + @SerializedName("oslc") + @Expose + private final String oslc = "http://open-services.net/ns/core#"; + + @SerializedName("oslc_cm") + @Expose + private final String oslcCm = "http://open-services.net/ns/cm#"; } diff --git a/test/META-INF/MANIFEST.MF b/test/META-INF/MANIFEST.MF index 3c637eb..0985a2f 100644 --- a/test/META-INF/MANIFEST.MF +++ b/test/META-INF/MANIFEST.MF @@ -7,9 +7,25 @@ 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.7.jar, + target/dependency/gson-2.8.2.jar, target/dependency/com.siemens.bt.jazz.services.base-2.0.1-SNAPSHOT.jar, target/dependency/com.siemens.bt.jazz.services.PersonalTokenService-1.0.2-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, + target/dependency/asm-util-5.0.3.jar, + target/dependency/commons-lang3-3.6.jar, + target/dependency/concurrentlinkedhashmap-lru-1.4.2.jar, + target/dependency/guava-18.0.jar, + target/dependency/jtwig-core-5.86.1.RELEASE.jar, + target/dependency/jtwig-reflection-5.86.1.RELEASE.jar, + target/dependency/parboiled-core-1.1.7.jar, + target/dependency/parboiled-java-1.1.7.jar, + target/dependency/minigit-1.0.0-SNAPSHOT.jar, + target/dependency/commonmark-0.11.0.jar, + target/dependency/modelmapper-2.0.0.jar, + target/dependency/threetenbp-1.3.6.jar, + target/java-gen, . Require-Bundle: com.ibm.team.repository.common, com.ibm.team.repository.service, diff --git a/test/pom.xml b/test/pom.xml index c00c11d..2765fb7 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -32,6 +32,46 @@ target-platform-configuration ${tycho-version} + + org.codehaus.mojo + build-helper-maven-plugin + 3.0.0 + + + Generated Payloads + generate-sources + + add-source + + + + test/target/java-gen + + + + + + + org.jsonschema2pojo + jsonschema2pojo-maven-plugin + 0.5.1 + + true + gson + false + false + plugin/src/main/resources/schemas/oslc + json + org.jazzcommunity.GitConnectorService.olsc.type + + + + + generate + + + + diff --git a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTests.java b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTests.java new file mode 100644 index 0000000..3715441 --- /dev/null +++ b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTests.java @@ -0,0 +1,6 @@ +package org.jazzcommunity.GitConnectorService.oslc.mapping; + +import org.junit.Test; + +public class IssueMapperTests { +} From e1bf7d9c842ed86150183adb0a97490b8394144e Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 10:36:56 +0200 Subject: [PATCH 22/62] Add plugin service dependency for testing --- .../oslc/mapping/IssueMapper.java | 2 -- test/pom.xml | 5 +++++ .../oslc/mapping/IssueMapperTests.java | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index 81ea43b..5b2f77b 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -7,8 +7,6 @@ import org.modelmapper.AbstractConverter; import org.modelmapper.ModelMapper; import org.modelmapper.PropertyMap; -import org.threeten.bp.LocalDateTime; -import org.threeten.bp.format.DateTimeFormatter; import java.net.URL; import java.util.Collection; diff --git a/test/pom.xml b/test/pom.xml index 2765fb7..9e9b9fc 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -18,6 +18,11 @@ 4.12 test + + org.jazzcommunity.GitConnectorService + org.jazzcommunity.GitConnectorService + 1.0.0-SNAPSHOT + diff --git a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTests.java b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTests.java index 3715441..06c46c4 100644 --- a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTests.java +++ b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTests.java @@ -1,6 +1,20 @@ package org.jazzcommunity.GitConnectorService.oslc.mapping; +import ch.sbi.minigit.type.gitlab.issue.Issue; +import org.junit.Before; import org.junit.Test; public class IssueMapperTests { + + private Issue issue; + + @Before + public void makeIssue() { + this.issue = new Issue(); + issue.setTitle("Unit test issue"); + } + + @Test + public void checkTitlesAreMapped() { + } } From adf808015adb043fdaa98e5aaeb0686ed7046e87 Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 11:03:17 +0200 Subject: [PATCH 23/62] Demonstrate basic mapping tests --- test/META-INF/MANIFEST.MF | 1 + .../oslc/mapping/IssueMapperTest.java | 108 ++++++++++++++++++ .../oslc/mapping/IssueMapperTests.java | 20 ---- 3 files changed, 109 insertions(+), 20 deletions(-) create mode 100644 test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java delete mode 100644 test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTests.java diff --git a/test/META-INF/MANIFEST.MF b/test/META-INF/MANIFEST.MF index 0985a2f..5735644 100644 --- a/test/META-INF/MANIFEST.MF +++ b/test/META-INF/MANIFEST.MF @@ -10,6 +10,7 @@ Bundle-ClassPath: target/dependency/junit-4.12.jar, target/dependency/gson-2.8.2.jar, target/dependency/com.siemens.bt.jazz.services.base-2.0.1-SNAPSHOT.jar, target/dependency/com.siemens.bt.jazz.services.PersonalTokenService-1.0.2-SNAPSHOT.jar, + target/dependency/org.jazzcommunity.GitConnectorService-1.0.0-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, diff --git a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java new file mode 100644 index 0000000..6c533b5 --- /dev/null +++ b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java @@ -0,0 +1,108 @@ +package org.jazzcommunity.GitConnectorService.oslc.mapping; + +import ch.sbi.minigit.type.gitlab.issue.Issue; +import com.google.gson.Gson; +import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.net.MalformedURLException; +import java.net.URL; + +public class IssueMapperTest { + + private OslcIssue oslcIssue; + + @Test + public void checkSubjectIsCommaSeparatedString() { + Assert.assertEquals(oslcIssue.getDctermsSubject(), "Label1, Label2"); + } + + @Test + public void checkDescriptionIsMapped() { + Assert.assertEquals(oslcIssue.getDctermsDescription(), "This issue is used in rtc-git-connector-service unit tests"); + Assert.assertEquals(oslcIssue.getGitCmDescription(), "This issue is used in rtc-git-connector-service unit tests"); + } + + @Test + public void checkTypeIsIssue() { + Assert.assertEquals(oslcIssue.getDctermsType(), "Issue"); + } + + @Test + public void checkTitlesAreMapped() { + Assert.assertEquals(oslcIssue.getGitCmTitle(), "Unit Test Issue"); + Assert.assertEquals(oslcIssue.getDctermsTitle(), "Unit Test Issue"); + } + + @Before + public void makeIssue() throws MalformedURLException { + String json = "{\n" + + " \"id\": 81560,\n" + + " \"iid\": 9,\n" + + " \"project_id\": 13027,\n" + + " \"title\": \"Unit Test Issue\",\n" + + " \"description\": \"This issue is used in rtc-git-connector-service unit tests\",\n" + + " \"state\": \"opened\",\n" + + " \"created_at\": \"2018-03-13T15:24:48.339+01:00\",\n" + + " \"updated_at\": \"2018-06-04T15:28:20.376+02:00\",\n" + + " \"closed_at\": null,\n" + + " \"closed_by\": null,\n" + + " \"labels\": [\n" + + " \"Label1\",\n" + + " \"Label2\"\n" + + " ],\n" + + " \"milestone\": null,\n" + + " \"assignees\": [\n" + + " {\n" + + " \"id\": 115,\n" + + " \"name\": \"User 1 user1\",\n" + + " \"username\": \"user.1\",\n" + + " \"state\": \"active\",\n" + + " \"avatar_url\": \"https://repo.git.com/uploads/-/system/user/avatar/115/avatar.png\",\n" + + " \"web_url\": \"https://git.lab/user.1\"\n" + + " }\n" + + " ],\n" + + " \"author\": {\n" + + " \"id\": 150,\n" + + " \"name\": \"User 2\",\n" + + " \"username\": \"user.2\",\n" + + " \"state\": \"active\",\n" + + " \"avatar_url\": null,\n" + + " \"web_url\": \"https://git.lab/user.2\"\n" + + " },\n" + + " \"assignee\": {\n" + + " \"id\": 115,\n" + + " \"name\": \"User 1 user1\",\n" + + " \"username\": \"user.1\",\n" + + " \"state\": \"active\",\n" + + " \"avatar_url\": \"https://repo.git.com/uploads/-/system/user/avatar/115/avatar.png\",\n" + + " \"web_url\": \"https://git.lab/user.1\"\n" + + " },\n" + + " \"user_notes_count\": 6,\n" + + " \"upvotes\": 0,\n" + + " \"downvotes\": 0,\n" + + " \"due_date\": null,\n" + + " \"confidential\": false,\n" + + " \"discussion_locked\": null,\n" + + " \"web_url\": \"https://git.lab/user.1/unit-test-project/issues/9\",\n" + + " \"time_stats\": {\n" + + " \"time_estimate\": 0,\n" + + " \"total_time_spent\": 0,\n" + + " \"human_time_estimate\": null,\n" + + " \"human_total_time_spent\": null\n" + + " },\n" + + " \"_links\": {\n" + + " \"self\": \"https://git.lab/api/v4/projects/13027/issues/9\",\n" + + " \"notes\": \"https://git.lab/api/v4/projects/13027/issues/9/notes\",\n" + + " \"award_emoji\": \"https://git.lab/api/v4/projects/13027/issues/9/award_emoji\",\n" + + " \"project\": \"https://git.lab/api/v4/projects/13027\"\n" + + " },\n" + + " \"subscribed\": true\n" + + "}\n"; + + Issue issue = new Gson().fromJson(json, Issue.class); + this.oslcIssue = IssueMapper.map(issue, new URL("http://link-to-myself.ch")); + } +} diff --git a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTests.java b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTests.java deleted file mode 100644 index 06c46c4..0000000 --- a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTests.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.jazzcommunity.GitConnectorService.oslc.mapping; - -import ch.sbi.minigit.type.gitlab.issue.Issue; -import org.junit.Before; -import org.junit.Test; - -public class IssueMapperTests { - - private Issue issue; - - @Before - public void makeIssue() { - this.issue = new Issue(); - issue.setTitle("Unit test issue"); - } - - @Test - public void checkTitlesAreMapped() { - } -} From a58df6ff2e7d39e3f7a4c097b1ffc0a6cf1d83ce Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 12:18:02 +0200 Subject: [PATCH 24/62] Add utc date time tests --- .../oslc/mapping/IssueMapperTest.java | 44 ++++++++++++++++--- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java index 6c533b5..34ed6aa 100644 --- a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java +++ b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java @@ -6,6 +6,8 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.threeten.bp.ZonedDateTime; +import org.threeten.bp.format.DateTimeFormatter; import java.net.MalformedURLException; import java.net.URL; @@ -14,26 +16,56 @@ public class IssueMapperTest { private OslcIssue oslcIssue; + @Test + public void checkUtcDateTimeMapping() { + ZonedDateTime created = ZonedDateTime.parse( + "2018-03-13T15:24:48.339+01:00", + DateTimeFormatter.ISO_OFFSET_DATE_TIME); + + ZonedDateTime modified = ZonedDateTime.parse( + "2018-06-04T15:28:20.376+02:00", + DateTimeFormatter.ISO_OFFSET_DATE_TIME); + + created.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME); + + Assert.assertEquals(created.toString(), oslcIssue.getDctermsCreated()); + Assert.assertEquals(created.toString(), oslcIssue.getGitCmCreatedAt()); + Assert.assertEquals(modified.toString(), oslcIssue.getDctermsModified()); + Assert.assertEquals(modified.toString(), oslcIssue.getGitCmUpdatedAt()); + Assert.assertEquals(null, oslcIssue.getGitCmClosedAt()); + } + + @Test + public void checkAboutIsUrl() { + Assert.assertEquals("http://link-to-myself.ch", oslcIssue.getRdfAbout()); + } + + @Test + public void checkLabelsAreMapped() { + String[] strings = {"Label1", "Label2"}; + Assert.assertArrayEquals(strings, oslcIssue.getGitCmLabels().toArray()); + } + @Test public void checkSubjectIsCommaSeparatedString() { - Assert.assertEquals(oslcIssue.getDctermsSubject(), "Label1, Label2"); + Assert.assertEquals("Label1, Label2", oslcIssue.getDctermsSubject()); } @Test public void checkDescriptionIsMapped() { - Assert.assertEquals(oslcIssue.getDctermsDescription(), "This issue is used in rtc-git-connector-service unit tests"); - Assert.assertEquals(oslcIssue.getGitCmDescription(), "This issue is used in rtc-git-connector-service unit tests"); + Assert.assertEquals("This issue is used in rtc-git-connector-service unit tests", oslcIssue.getDctermsDescription()); + Assert.assertEquals("This issue is used in rtc-git-connector-service unit tests", oslcIssue.getGitCmDescription()); } @Test public void checkTypeIsIssue() { - Assert.assertEquals(oslcIssue.getDctermsType(), "Issue"); + Assert.assertEquals("Issue", oslcIssue.getDctermsType()); } @Test public void checkTitlesAreMapped() { - Assert.assertEquals(oslcIssue.getGitCmTitle(), "Unit Test Issue"); - Assert.assertEquals(oslcIssue.getDctermsTitle(), "Unit Test Issue"); + Assert.assertEquals("Unit Test Issue", oslcIssue.getGitCmTitle()); + Assert.assertEquals("Unit Test Issue", oslcIssue.getDctermsTitle()); } @Before From 538830b16c25aad4bd0e52a8c359f36172ca2077 Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 13:07:07 +0200 Subject: [PATCH 25/62] Add flat mapping for gitcm data --- .../oslc/mapping/IssueMapperTest.java | 80 ++++++++++++++++++- 1 file changed, 78 insertions(+), 2 deletions(-) diff --git a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java index 34ed6aa..192a67d 100644 --- a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java +++ b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java @@ -16,6 +16,78 @@ public class IssueMapperTest { private OslcIssue oslcIssue; + @Test + public void checkSubscribed() { + Assert.assertFalse(oslcIssue.getGitCmSubscribed()); + } + + @Test + public void checkWebUrl() { + Assert.assertEquals( + "https://git.lab/user.1/unit-test-project/issues/9", + oslcIssue.getGitCmWebUrl()); + } + + @Test + public void checkConfidential() { + Assert.assertFalse(oslcIssue.getGitCmConfidential()); + } + + @Test + public void checkVoteStats() { + Assert.assertEquals(new Integer(0), oslcIssue.getGitCmUpvotes()); + Assert.assertEquals(new Integer(0), oslcIssue.getGitCmDownvotes()); + } + + @Test + public void checkUserNotesCount() { + Assert.assertEquals(new Integer(6), oslcIssue.getGitCmUserNotesCount()); + } + + @Test + public void checkClosedBy() { + Assert.assertFalse(oslcIssue.getOslcCmClosed()); + Assert.assertNull(oslcIssue.getGitCmClosedBy()); + } + + @Test + public void checkProjectId() { + Assert.assertEquals(new Integer(13027), oslcIssue.getGitCmProjectId()); + } + + @Test + public void checkShortTitle() { + Assert.assertEquals("Issue 9", oslcIssue.getOslcShortTitle()); + } + + @Test + public void checkGitCmIds() { + Assert.assertEquals(new Integer(81560), oslcIssue.getGitCmId()); + Assert.assertEquals(new Integer(9), oslcIssue.getGitCmIid()); + } + + @Test + public void checkDcTermsIdentifier() { + Assert.assertEquals("81560", oslcIssue.getDctermsIdentifier()); + } + + @Test + public void checkShortIdMapping() { + Assert.assertEquals("9", oslcIssue.getOslcShortId()); + } + + @Test + public void checkStateMapping() { + Assert.assertEquals("opened", oslcIssue.getOslcCmStatus()); + Assert.assertEquals("opened", oslcIssue.getGitCmState()); + } + + @Test + public void checkCmClosedMapsToClosedAt() { + Assert.assertNull(oslcIssue.getGitCmClosedAt()); + Assert.assertFalse(oslcIssue.getOslcCmClosed()); + } + @Test public void checkUtcDateTimeMapping() { ZonedDateTime created = ZonedDateTime.parse( @@ -53,8 +125,12 @@ public void checkSubjectIsCommaSeparatedString() { @Test public void checkDescriptionIsMapped() { - Assert.assertEquals("This issue is used in rtc-git-connector-service unit tests", oslcIssue.getDctermsDescription()); - Assert.assertEquals("This issue is used in rtc-git-connector-service unit tests", oslcIssue.getGitCmDescription()); + Assert.assertEquals( + "This issue is used in rtc-git-connector-service unit tests", + oslcIssue.getDctermsDescription()); + Assert.assertEquals( + "This issue is used in rtc-git-connector-service unit tests", + oslcIssue.getGitCmDescription()); } @Test From bf23f5e58a5295adb151d3dad7f778fafd2d9458 Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 13:25:21 +0200 Subject: [PATCH 26/62] Improve implementation of prefix usage --- .../oslc/mapping/IssueMapper.java | 3 +- .../oslc/type/PrefixBuilder.java | 26 ++++++++++++++++ .../oslc/type/Prefixes.java | 31 ------------------- .../oslc/mapping/IssueMapperTest.java | 8 ++++- 4 files changed, 35 insertions(+), 33 deletions(-) create mode 100644 plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/type/PrefixBuilder.java delete mode 100644 plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/type/Prefixes.java diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index 5b2f77b..d22527a 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -4,6 +4,7 @@ import com.google.common.base.Joiner; import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; import org.jazzcommunity.GitConnectorService.olsc.type.issue.Prefixes; +import org.jazzcommunity.GitConnectorService.oslc.type.PrefixBuilder; import org.modelmapper.AbstractConverter; import org.modelmapper.ModelMapper; import org.modelmapper.PropertyMap; @@ -74,7 +75,7 @@ protected void configure() { map().setDctermsCreated(source.getCreatedAt()); map().setDctermsModified(source.getUpdatedAt()); - map().setPrefixes(new Prefixes()); + map().setPrefixes(PrefixBuilder.get()); using(stateConverter).map(source.getClosedAt()).setOslcCmClosed(null); diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/type/PrefixBuilder.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/type/PrefixBuilder.java new file mode 100644 index 0000000..dc90cd0 --- /dev/null +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/type/PrefixBuilder.java @@ -0,0 +1,26 @@ +package org.jazzcommunity.GitConnectorService.oslc.type; + +import org.jazzcommunity.GitConnectorService.olsc.type.issue.Prefixes; + +public final class PrefixBuilder { + + private PrefixBuilder() {} + + private static final String gitCm = "http://jazz-community.org/ns/git_cm"; + private static final String rtcCm = "http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/"; + private static final String rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; + private static final String dcterms = "http://purl.org/dc/terms/"; + private static final String oslc = "http://open-services.net/ns/core#"; + private static final String oslcCm = "http://open-services.net/ns/cm#"; + + public static Prefixes get() { + Prefixes prefixes = new Prefixes(); + prefixes.setGitCm(gitCm); + prefixes.setRtcCm(rtcCm); + prefixes.setRdf(rdf); + prefixes.setDcterms(dcterms); + prefixes.setOslc(oslc); + prefixes.setOslcCm(oslcCm); + return prefixes; + } +} diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/type/Prefixes.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/type/Prefixes.java deleted file mode 100644 index ba4f51a..0000000 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/type/Prefixes.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.jazzcommunity.GitConnectorService.oslc.type; - -import com.google.gson.annotations.Expose; -import com.google.gson.annotations.SerializedName; - -public final class Prefixes { - - @SerializedName("git_cm") - @Expose - private final String gitCm = "http://jazz-community.org/ns/git_cm"; - - @SerializedName("rtc_cm") - @Expose - private final String rtcCm = "http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/"; - - @SerializedName("rdf") - @Expose - private final String rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; - - @SerializedName("dcterms") - @Expose - private final String dcterms = "http://purl.org/dc/terms/"; - - @SerializedName("oslc") - @Expose - private final String oslc = "http://open-services.net/ns/core#"; - - @SerializedName("oslc_cm") - @Expose - private final String oslcCm = "http://open-services.net/ns/cm#"; -} diff --git a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java index 192a67d..00a8f8f 100644 --- a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java +++ b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java @@ -3,6 +3,7 @@ import ch.sbi.minigit.type.gitlab.issue.Issue; import com.google.gson.Gson; import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; +import org.jazzcommunity.GitConnectorService.olsc.type.issue.Prefixes; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -16,9 +17,14 @@ public class IssueMapperTest { private OslcIssue oslcIssue; + @Test + public void checkPrefixes() { + Assert.assertEquals(new Prefixes(), oslcIssue.getPrefixes()); + } + @Test public void checkSubscribed() { - Assert.assertFalse(oslcIssue.getGitCmSubscribed()); + Assert.assertTrue(oslcIssue.getGitCmSubscribed()); } @Test From ec6625a21f3b2c1b6a445f5763c94724551ebfcd Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 13:31:54 +0200 Subject: [PATCH 27/62] Show how to use apache for deep object comparison --- .../GitConnectorService/oslc/mapping/IssueMapperTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java index 00a8f8f..9819fb5 100644 --- a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java +++ b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java @@ -2,8 +2,10 @@ import ch.sbi.minigit.type.gitlab.issue.Issue; import com.google.gson.Gson; +import org.apache.commons.lang3.builder.EqualsBuilder; import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; import org.jazzcommunity.GitConnectorService.olsc.type.issue.Prefixes; +import org.jazzcommunity.GitConnectorService.oslc.type.PrefixBuilder; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -19,7 +21,8 @@ public class IssueMapperTest { @Test public void checkPrefixes() { - Assert.assertEquals(new Prefixes(), oslcIssue.getPrefixes()); + Assert.assertTrue( + EqualsBuilder.reflectionEquals(PrefixBuilder.get(), oslcIssue.getPrefixes())); } @Test From 5d0a8526f163c6734eb7393dd7f5aee332f324ad Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 13:47:17 +0200 Subject: [PATCH 28/62] Add failing link test --- .../oslc/mapping/IssueMapper.java | 22 +++++++++---------- .../oslc/mapping/LinksMapper.java | 11 ++++++++++ .../oslc/mapping/IssueMapperTest.java | 15 ++++++++++++- 3 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/LinksMapper.java diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index d22527a..81219a4 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -1,9 +1,10 @@ package org.jazzcommunity.GitConnectorService.oslc.mapping; import ch.sbi.minigit.type.gitlab.issue.Issue; +import ch.sbi.minigit.type.gitlab.issue.Links; import com.google.common.base.Joiner; +import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmLinks; import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; -import org.jazzcommunity.GitConnectorService.olsc.type.issue.Prefixes; import org.jazzcommunity.GitConnectorService.oslc.type.PrefixBuilder; import org.modelmapper.AbstractConverter; import org.modelmapper.ModelMapper; @@ -44,6 +45,13 @@ protected Boolean convert(String state) { } }; + final AbstractConverter linkConverter = new AbstractConverter() { + @Override + protected GitCmLinks convert(Links links) { + return LinksMapper.map(links); + } + }; + mapper.addMappings(new PropertyMap() { @Override protected void configure() { @@ -61,15 +69,8 @@ protected void configure() { */ using(listToString).map(source.getLabels()).setDctermsSubject(null); map().setGitCmLabels(source.getLabels()); - map().setRdfAbout(link); - // rdf:about needs to be the url of this link, so something like - // https://localhost:7443/jazz/service/org.jazzcommunity.GitConnectorService.IGitConnectorService/gitlab/code.siemens.com/project/13027/issue/9/link - - // dates left out for now. - // All dates are utc anyway... No need to convert anything - map().setGitCmCreatedAt(source.getCreatedAt()); map().setGitCmUpdatedAt(source.getUpdatedAt()); map().setDctermsCreated(source.getCreatedAt()); @@ -79,7 +80,6 @@ protected void configure() { using(stateConverter).map(source.getClosedAt()).setOslcCmClosed(null); - // Todos skipped map().setGitCmClosedAt(source.getClosedAt()); map().setOslcCmStatus(source.getState()); map().setGitCmState(source.getState()); @@ -89,8 +89,6 @@ protected void configure() { map().setGitCmId(source.getId()); map().setGitCmIid(source.getIid()); - // prefixes skipped, this will need to be a custom object defined separately - using(shortTitleConverter).map(source.getIid()).setOslcShortTitle(null); // Lots of properties skipped which are not definitively defined @@ -115,6 +113,8 @@ protected void configure() { // for converting to utc, I'll probably want to use the threeten backport: // http://www.threeten.org/threetenbp/ + using(linkConverter).map(source.getLinks()).setGitCmLinks(null); + // links skipped, deep mapping not implemented map().setGitCmSubscribed(source.getSubscribed()); } diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/LinksMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/LinksMapper.java new file mode 100644 index 0000000..87a2175 --- /dev/null +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/LinksMapper.java @@ -0,0 +1,11 @@ +package org.jazzcommunity.GitConnectorService.oslc.mapping; + +import ch.sbi.minigit.type.gitlab.issue.Links; +import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmLinks; + +public class LinksMapper { + public static GitCmLinks map(Links from) { + GitCmLinks to = new GitCmLinks(); + return to; + } +} diff --git a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java index 9819fb5..cba0f02 100644 --- a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java +++ b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java @@ -3,8 +3,8 @@ import ch.sbi.minigit.type.gitlab.issue.Issue; import com.google.gson.Gson; import org.apache.commons.lang3.builder.EqualsBuilder; +import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmLinks; import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; -import org.jazzcommunity.GitConnectorService.olsc.type.issue.Prefixes; import org.jazzcommunity.GitConnectorService.oslc.type.PrefixBuilder; import org.junit.Assert; import org.junit.Before; @@ -19,6 +19,19 @@ public class IssueMapperTest { private OslcIssue oslcIssue; + @Test + public void checkLinks() { + GitCmLinks expected = new GitCmLinks(); + expected.setSelf("https://git.lab/api/v4/projects/13027/issues/9"); + expected.setNotes("https://git.lab/api/v4/projects/13027/issues/9/notes"); + expected.setAwardEmoji("https://git.lab/api/v4/projects/13027/issues/9/award_emoji"); + expected.setProject("https://git.lab/api/v4/projects/13027"); + + Assert.assertTrue( + EqualsBuilder.reflectionEquals(expected, oslcIssue.getGitCmLinks()) + ); + } + @Test public void checkPrefixes() { Assert.assertTrue( From 27e6c1dbf46cb14f6d918b7ed3bf5545914ddcfe Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 13:55:00 +0200 Subject: [PATCH 29/62] Implement link mapping --- .../GitConnectorService/oslc/mapping/IssueMapper.java | 2 +- .../GitConnectorService/oslc/mapping/LinksMapper.java | 11 ----------- 2 files changed, 1 insertion(+), 12 deletions(-) delete mode 100644 plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/LinksMapper.java diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index 81219a4..7140f02 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -48,7 +48,7 @@ protected Boolean convert(String state) { final AbstractConverter linkConverter = new AbstractConverter() { @Override protected GitCmLinks convert(Links links) { - return LinksMapper.map(links); + return new ModelMapper().map(links, GitCmLinks.class); } }; diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/LinksMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/LinksMapper.java deleted file mode 100644 index 87a2175..0000000 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/LinksMapper.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.jazzcommunity.GitConnectorService.oslc.mapping; - -import ch.sbi.minigit.type.gitlab.issue.Links; -import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmLinks; - -public class LinksMapper { - public static GitCmLinks map(Links from) { - GitCmLinks to = new GitCmLinks(); - return to; - } -} From de1e97f02c522d08e91b44eab0c362d5921e14bf Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 14:21:29 +0200 Subject: [PATCH 30/62] Add failing due date test --- .../oslc/mapping/IssueMapper.java | 2 +- .../oslc/mapping/IssueMapperTest.java | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index 7140f02..dffa079 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -91,7 +91,7 @@ protected void configure() { using(shortTitleConverter).map(source.getIid()).setOslcShortTitle(null); - // Lots of properties skipped which are not definitively defined + map().setRtcCmDue(source.getDueDate()); map().setGitCmProjectId(source.getProjectId()); diff --git a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java index cba0f02..cd97eff 100644 --- a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java +++ b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java @@ -19,6 +19,15 @@ public class IssueMapperTest { private OslcIssue oslcIssue; + @Test + public void checkDueDateIsUtc() { + ZonedDateTime expected = ZonedDateTime.parse( + "2018-09-29T00:00:00Z", + DateTimeFormatter.ISO_OFFSET_DATE_TIME); + + Assert.assertEquals(expected.toString(), oslcIssue.getRtcCmDue()); + } + @Test public void checkLinks() { GitCmLinks expected = new GitCmLinks(); @@ -66,6 +75,11 @@ public void checkUserNotesCount() { Assert.assertEquals(new Integer(6), oslcIssue.getGitCmUserNotesCount()); } + @Test + public void checkClosedAt() { + Assert.assertEquals(null, oslcIssue.getGitCmClosedAt()); + } + @Test public void checkClosedBy() { Assert.assertFalse(oslcIssue.getOslcCmClosed()); @@ -213,7 +227,7 @@ public void makeIssue() throws MalformedURLException { " \"user_notes_count\": 6,\n" + " \"upvotes\": 0,\n" + " \"downvotes\": 0,\n" + - " \"due_date\": null,\n" + + " \"due_date\": \"2018-09-29\",\n" + " \"confidential\": false,\n" + " \"discussion_locked\": null,\n" + " \"web_url\": \"https://git.lab/user.1/unit-test-project/issues/9\",\n" + From db488303c465254d39cdbcdd64740df56e4015ad Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 14:52:13 +0200 Subject: [PATCH 31/62] Implement utc converter for mapping --- .../oslc/mapping/IssueMapper.java | 13 ++++++++++++- .../oslc/mapping/IssueMapperTest.java | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index dffa079..ab79139 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -9,6 +9,8 @@ import org.modelmapper.AbstractConverter; import org.modelmapper.ModelMapper; import org.modelmapper.PropertyMap; +import org.threeten.bp.*; +import org.threeten.bp.format.DateTimeFormatter; import java.net.URL; import java.util.Collection; @@ -52,6 +54,15 @@ protected GitCmLinks convert(Links links) { } }; + final AbstractConverter toUtc = new AbstractConverter() { + @Override + protected String convert(String from) { + LocalDate date = LocalDate.parse(from, DateTimeFormatter.ISO_DATE); + ZonedDateTime dateTime = ZonedDateTime.of(date, LocalTime.MIDNIGHT, ZoneOffset.UTC); + return dateTime.toString(); + } + }; + mapper.addMappings(new PropertyMap() { @Override protected void configure() { @@ -91,7 +102,7 @@ protected void configure() { using(shortTitleConverter).map(source.getIid()).setOslcShortTitle(null); - map().setRtcCmDue(source.getDueDate()); + using(toUtc).map(source.getDueDate()).setRtcCmDue(null); map().setGitCmProjectId(source.getProjectId()); diff --git a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java index cd97eff..e1e87e5 100644 --- a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java +++ b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java @@ -9,11 +9,12 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.threeten.bp.ZonedDateTime; +import org.threeten.bp.*; import org.threeten.bp.format.DateTimeFormatter; import java.net.MalformedURLException; import java.net.URL; +import java.text.spi.DateFormatProvider; public class IssueMapperTest { From 7be37927dfed3545873bd1bc1622f4c8855eaafa Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 15:03:06 +0200 Subject: [PATCH 32/62] Add cm time stats tests --- .../src/main/resources/schemas/oslc/issue/OslcIssue.json | 1 - .../GitConnectorService/oslc/mapping/IssueMapperTest.java | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json b/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json index fb02759..b3c87f5 100644 --- a/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json +++ b/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json @@ -34,7 +34,6 @@ "rtc_cm:due": "2018-04-19T10:00:00.000Z", "rtc_cm:estimate": 18000000, "rtc_cm:timeSpent": 10800000, - "rtc_cm:correctedEstimate": null, "git_cm:details": "/details", "git_cm:project_id": 23862, "git_cm:milestone": { diff --git a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java index e1e87e5..1d657e2 100644 --- a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java +++ b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java @@ -14,12 +14,17 @@ import java.net.MalformedURLException; import java.net.URL; -import java.text.spi.DateFormatProvider; public class IssueMapperTest { private OslcIssue oslcIssue; + @Test + public void checkCmTimeStats() { + Assert.assertEquals("0", oslcIssue.getRtcCmEstimate()); + Assert.assertEquals(String.valueOf(3600 * 1000), oslcIssue.getRtcCmTimeSpent()); + } + @Test public void checkDueDateIsUtc() { ZonedDateTime expected = ZonedDateTime.parse( From b9519112a619ff8b96340d0d98a95aa6d76678ed Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 15:30:57 +0200 Subject: [PATCH 33/62] Add time stats converter and test --- .../oslc/mapping/IssueMapper.java | 11 ++++++++++ .../oslc/mapping/IssueMapperTest.java | 20 +++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index ab79139..2909e3c 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -2,8 +2,10 @@ import ch.sbi.minigit.type.gitlab.issue.Issue; import ch.sbi.minigit.type.gitlab.issue.Links; +import ch.sbi.minigit.type.gitlab.issue.TimeStats; import com.google.common.base.Joiner; import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmLinks; +import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmTimeStats; import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; import org.jazzcommunity.GitConnectorService.oslc.type.PrefixBuilder; import org.modelmapper.AbstractConverter; @@ -63,6 +65,14 @@ protected String convert(String from) { } }; + final AbstractConverter timeStatsConverter = + new AbstractConverter() { + @Override + protected GitCmTimeStats convert(TimeStats timeStats) { + return new ModelMapper().map(timeStats, GitCmTimeStats.class); + } + }; + mapper.addMappings(new PropertyMap() { @Override protected void configure() { @@ -119,6 +129,7 @@ protected void configure() { map().setGitCmWebUrl(source.getWebUrl()); // time stats skipped, deep mapping undefined + using(timeStatsConverter).map(source.getTimeStats()).setGitCmTimeStats(null); // this is for the due date, which is just a datestring "2018-09-11" // for converting to utc, I'll probably want to use the threeten backport: diff --git a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java index 1d657e2..7e0f024 100644 --- a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java +++ b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java @@ -4,6 +4,7 @@ import com.google.gson.Gson; import org.apache.commons.lang3.builder.EqualsBuilder; import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmLinks; +import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmTimeStats; import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; import org.jazzcommunity.GitConnectorService.oslc.type.PrefixBuilder; import org.junit.Assert; @@ -25,6 +26,18 @@ public void checkCmTimeStats() { Assert.assertEquals(String.valueOf(3600 * 1000), oslcIssue.getRtcCmTimeSpent()); } + @Test + public void checkGitLabTimeStats() { + GitCmTimeStats expected = new GitCmTimeStats(); + expected.setTimeEstimate(0); + expected.setTotalTimeSpent(3600); + expected.setHumanTimeEstimate(null); + expected.setHumanTotalTimeSpent("1h"); + + Assert.assertTrue( + EqualsBuilder.reflectionEquals(expected, oslcIssue.getGitCmTimeStats())); + } + @Test public void checkDueDateIsUtc() { ZonedDateTime expected = ZonedDateTime.parse( @@ -43,8 +56,7 @@ public void checkLinks() { expected.setProject("https://git.lab/api/v4/projects/13027"); Assert.assertTrue( - EqualsBuilder.reflectionEquals(expected, oslcIssue.getGitCmLinks()) - ); + EqualsBuilder.reflectionEquals(expected, oslcIssue.getGitCmLinks())); } @Test @@ -239,9 +251,9 @@ public void makeIssue() throws MalformedURLException { " \"web_url\": \"https://git.lab/user.1/unit-test-project/issues/9\",\n" + " \"time_stats\": {\n" + " \"time_estimate\": 0,\n" + - " \"total_time_spent\": 0,\n" + + " \"total_time_spent\": 3600,\n" + " \"human_time_estimate\": null,\n" + - " \"human_total_time_spent\": null\n" + + " \"human_total_time_spent\": \"1h\"\n" + " },\n" + " \"_links\": {\n" + " \"self\": \"https://git.lab/api/v4/projects/13027/issues/9\",\n" + From 51ace501a2bb6db23bf491860c889d8a8c54fa93 Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 15:37:36 +0200 Subject: [PATCH 34/62] Implement rtc time stamp converter --- .../oslc/mapping/IssueMapper.java | 19 ++++++++++++++----- .../oslc/mapping/IssueMapperTest.java | 4 ++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index 2909e3c..248e08d 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -73,6 +73,14 @@ protected GitCmTimeStats convert(TimeStats timeStats) { } }; + final AbstractConverter toRtcTimeStamp = + new AbstractConverter() { + @Override + protected Integer convert(Integer timeStamp) { + return timeStamp * 1000; + } + }; + mapper.addMappings(new PropertyMap() { @Override protected void configure() { @@ -128,16 +136,17 @@ protected void configure() { map().setGitCmDiscussionLocked(source.getDiscussionLocked()); map().setGitCmWebUrl(source.getWebUrl()); - // time stats skipped, deep mapping undefined using(timeStatsConverter).map(source.getTimeStats()).setGitCmTimeStats(null); + using(toRtcTimeStamp) + .map(source.getTimeStats().getTimeEstimate()) + .setRtcCmEstimate(null); - // this is for the due date, which is just a datestring "2018-09-11" - // for converting to utc, I'll probably want to use the threeten backport: - // http://www.threeten.org/threetenbp/ + using(toRtcTimeStamp) + .map(source.getTimeStats().getTotalTimeSpent()) + .setRtcCmTimeSpent(null); using(linkConverter).map(source.getLinks()).setGitCmLinks(null); - // links skipped, deep mapping not implemented map().setGitCmSubscribed(source.getSubscribed()); } }); diff --git a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java index 7e0f024..50f3040 100644 --- a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java +++ b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java @@ -22,8 +22,8 @@ public class IssueMapperTest { @Test public void checkCmTimeStats() { - Assert.assertEquals("0", oslcIssue.getRtcCmEstimate()); - Assert.assertEquals(String.valueOf(3600 * 1000), oslcIssue.getRtcCmTimeSpent()); + Assert.assertEquals(Integer.valueOf(0), oslcIssue.getRtcCmEstimate()); + Assert.assertEquals(Integer.valueOf(3600 * 1000), oslcIssue.getRtcCmTimeSpent()); } @Test From 509f8a9668fcb60d8ed04875eac49f61b1aed53f Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 15:57:27 +0200 Subject: [PATCH 35/62] Avoid NPE when mapping date strings --- .../GitConnectorService/oslc/mapping/IssueMapper.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index 248e08d..8869775 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -8,9 +8,8 @@ import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmTimeStats; import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; import org.jazzcommunity.GitConnectorService.oslc.type.PrefixBuilder; -import org.modelmapper.AbstractConverter; -import org.modelmapper.ModelMapper; -import org.modelmapper.PropertyMap; +import org.modelmapper.*; +import org.modelmapper.spi.MappingContext; import org.threeten.bp.*; import org.threeten.bp.format.DateTimeFormatter; @@ -59,6 +58,10 @@ protected GitCmLinks convert(Links links) { final AbstractConverter toUtc = new AbstractConverter() { @Override protected String convert(String from) { + if (from == null) { + return null; + } + LocalDate date = LocalDate.parse(from, DateTimeFormatter.ISO_DATE); ZonedDateTime dateTime = ZonedDateTime.of(date, LocalTime.MIDNIGHT, ZoneOffset.UTC); return dateTime.toString(); From fc4b5b5efc59d207791202c524a9bfa133ae8b74 Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 16:09:08 +0200 Subject: [PATCH 36/62] Add author example url --- .../resources/schemas/oslc/issue/OslcIssue.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json b/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json index b3c87f5..3594999 100644 --- a/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json +++ b/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json @@ -53,8 +53,8 @@ "name": "Bajohr Rayk adbara10", "username": "adbara10", "state": "active", - "avatar_url": null, - "web_url": "https://code.siemens.com/adbara10" + "avatar_url": "https://git.lab/uploads/-/system/user/avatar/115/avatar.png", + "web_url": "https://git.lab/adbara10" }, "git_cm:closed_by" : null, "git_cm:user_notes_count": 0, @@ -64,7 +64,7 @@ "git_cm:confidential": false, "git_cm:weight": null, "git_cm:discussion_locked": null, - "git_cm:web_url": "https://code.siemens.com/sisuite/sisuite-infrastructure-as-code/issues/42", + "git_cm:web_url": "https://git.lab/sisuite/sisuite-infrastructure-as-code/issues/42", "git_cm:time_stats": { "time_estimate": 0, "total_time_spent": 0, @@ -72,10 +72,10 @@ "human_total_time_spent": null }, "git_cm:_links": { - "self": "http://code.siemens.com/api/v4/projects/23862/issues/42", - "notes": "http://code.siemens.com/api/v4/projects/23862/issues/42/notes", - "award_emoji": "http://code.siemens.com/api/v4/projects/23862/issues/42/award_emoji", - "project": "http://code.siemens.com/api/v4/projects/23862" + "self": "http://git.lab/api/v4/projects/23862/issues/42", + "notes": "http://git.lab/api/v4/projects/23862/issues/42/notes", + "award_emoji": "http://git.lab/api/v4/projects/23862/issues/42/award_emoji", + "project": "http://git.lab/api/v4/projects/23862" }, "git_cm:subscribed": false } From a6a819fabd901fa8475cd3c4529acd2e62e97aeb Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 16:09:18 +0200 Subject: [PATCH 37/62] Add author mapping test --- .../oslc/mapping/IssueMapper.java | 10 ++++++++++ .../oslc/mapping/IssueMapperTest.java | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index 8869775..161447f 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -1,9 +1,11 @@ package org.jazzcommunity.GitConnectorService.oslc.mapping; +import ch.sbi.minigit.type.gitlab.issue.Author; import ch.sbi.minigit.type.gitlab.issue.Issue; import ch.sbi.minigit.type.gitlab.issue.Links; import ch.sbi.minigit.type.gitlab.issue.TimeStats; import com.google.common.base.Joiner; +import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmAuthor; import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmLinks; import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmTimeStats; import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; @@ -84,6 +86,13 @@ protected Integer convert(Integer timeStamp) { } }; + AbstractConverter authorConverter = new AbstractConverter() { + @Override + protected GitCmAuthor convert(Author from) { + return new ModelMapper().map(from, GitCmAuthor.class); + } + }; + mapper.addMappings(new PropertyMap() { @Override protected void configure() { @@ -129,6 +138,7 @@ protected void configure() { // milestone skipped because deep object not defined yet // same with assignees and author + map().setGitCmUserNotesCount(source.getUserNotesCount()); map().setGitCmUpvotes(source.getUpvotes()); diff --git a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java index 50f3040..22b6c80 100644 --- a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java +++ b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java @@ -3,6 +3,7 @@ import ch.sbi.minigit.type.gitlab.issue.Issue; import com.google.gson.Gson; import org.apache.commons.lang3.builder.EqualsBuilder; +import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmAuthor; import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmLinks; import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmTimeStats; import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; @@ -20,6 +21,20 @@ public class IssueMapperTest { private OslcIssue oslcIssue; + @Test + public void checkAuthorMapping() { + GitCmAuthor expected = new GitCmAuthor(); + expected.setId(150); + expected.setName("User 2"); + expected.setUsername("user.2"); + expected.setState("active"); + expected.setAvatarUrl(null); + expected.setWebUrl("https://git.lab/user.2"); + + Assert.assertTrue( + EqualsBuilder.reflectionEquals(expected, oslcIssue.getGitCmAuthor())); + } + @Test public void checkCmTimeStats() { Assert.assertEquals(Integer.valueOf(0), oslcIssue.getRtcCmEstimate()); From 7536c0c907d210a9f1c3c0fe8b07fd167a7e4d00 Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 16:13:22 +0200 Subject: [PATCH 38/62] Implement author mapping --- .../GitConnectorService/oslc/mapping/IssueMapper.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index 161447f..b805a50 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -86,7 +86,8 @@ protected Integer convert(Integer timeStamp) { } }; - AbstractConverter authorConverter = new AbstractConverter() { + // extract this to a general "userconverter" that can be passed a typetoken. + final AbstractConverter authorConverter = new AbstractConverter() { @Override protected GitCmAuthor convert(Author from) { return new ModelMapper().map(from, GitCmAuthor.class); @@ -138,8 +139,8 @@ protected void configure() { // milestone skipped because deep object not defined yet // same with assignees and author + using(authorConverter).map(source.getAuthor()).setGitCmAuthor(null); - map().setGitCmUserNotesCount(source.getUserNotesCount()); map().setGitCmUpvotes(source.getUpvotes()); map().setGitCmDownvotes(source.getDownvotes()); From ac377ec2e64d9a9d6e38648b23d80f639beb2af1 Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 16:41:18 +0200 Subject: [PATCH 39/62] Add failing mile stone mapping test --- .../schemas/oslc/issue/OslcIssue.json | 1 + .../oslc/mapping/IssueMapperTest.java | 36 ++++++++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json b/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json index 3594999..a96fcb4 100644 --- a/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json +++ b/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json @@ -40,6 +40,7 @@ "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", diff --git a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java index 22b6c80..115b2fd 100644 --- a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java +++ b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java @@ -3,10 +3,7 @@ import ch.sbi.minigit.type.gitlab.issue.Issue; import com.google.gson.Gson; import org.apache.commons.lang3.builder.EqualsBuilder; -import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmAuthor; -import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmLinks; -import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmTimeStats; -import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; +import org.jazzcommunity.GitConnectorService.olsc.type.issue.*; import org.jazzcommunity.GitConnectorService.oslc.type.PrefixBuilder; import org.junit.Assert; import org.junit.Before; @@ -21,6 +18,24 @@ public class IssueMapperTest { private OslcIssue oslcIssue; + @Test + public void checkMilestoneMapping() { + GitCmMilestone expected = new GitCmMilestone(); + expected.setId(5607); + expected.setIid(1); + expected.setProjectId(13027); + expected.setTitle("Unit testing milestone"); + expected.setDescription("This is a mile stone for unit testing.\\r\\n\\r\\n# It can have Markdown!\\r\\n\\r\\n[and_attachments.txt](/uploads/50395a5a72794a9f4f1c629ce95ebaf2/and_attachments.txt)"); + expected.setState("active"); + expected.setCreatedAt("2018-06-05T16:19:05.023+02:00"); + expected.setUpdatedAt("2018-06-05T16:19:05.023+02:00"); + expected.setDueDate("2019-06-01"); + expected.setStartDate("2018-06-01"); + + Assert.assertTrue( + EqualsBuilder.reflectionEquals(expected, oslcIssue.getGitCmMilestone())); + } + @Test public void checkAuthorMapping() { GitCmAuthor expected = new GitCmAuthor(); @@ -230,7 +245,18 @@ public void makeIssue() throws MalformedURLException { " \"Label1\",\n" + " \"Label2\"\n" + " ],\n" + - " \"milestone\": null,\n" + + " \"milestone\": {\n" + + " \"id\": 5607,\n" + + " \"iid\": 1,\n" + + " \"project_id\": 13027,\n" + + " \"title\": \"Unit testing milestone\",\n" + + " \"description\": \"This is a mile stone for unit testing.\\r\\n\\r\\n# It can have Markdown!\\r\\n\\r\\n[and_attachments.txt](/uploads/50395a5a72794a9f4f1c629ce95ebaf2/and_attachments.txt)\",\n" + + " \"state\": \"active\",\n" + + " \"created_at\": \"2018-06-05T16:19:05.023+02:00\",\n" + + " \"updated_at\": \"2018-06-05T16:19:05.023+02:00\",\n" + + " \"due_date\": \"2019-06-01\",\n" + + " \"start_date\": \"2018-06-01\"\n" + + " },\n" + " \"assignees\": [\n" + " {\n" + " \"id\": 115,\n" + From e26f83759782dd3bb3461f65075987c95fb4a6e6 Mon Sep 17 00:00:00 2001 From: SBI- Date: Tue, 5 Jun 2018 17:05:40 +0200 Subject: [PATCH 40/62] Implement milestone mapping --- .../oslc/mapping/IssueMapper.java | 22 ++++++++++++------- .../oslc/mapping/IssueMapperTest.java | 4 ++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index b805a50..34e9935 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -1,14 +1,8 @@ package org.jazzcommunity.GitConnectorService.oslc.mapping; -import ch.sbi.minigit.type.gitlab.issue.Author; -import ch.sbi.minigit.type.gitlab.issue.Issue; -import ch.sbi.minigit.type.gitlab.issue.Links; -import ch.sbi.minigit.type.gitlab.issue.TimeStats; +import ch.sbi.minigit.type.gitlab.issue.*; import com.google.common.base.Joiner; -import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmAuthor; -import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmLinks; -import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmTimeStats; -import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; +import org.jazzcommunity.GitConnectorService.olsc.type.issue.*; import org.jazzcommunity.GitConnectorService.oslc.type.PrefixBuilder; import org.modelmapper.*; import org.modelmapper.spi.MappingContext; @@ -86,6 +80,17 @@ protected Integer convert(Integer timeStamp) { } }; + final AbstractConverter milestoneConverter = + new AbstractConverter() { + @Override + protected GitCmMilestone convert(Milestone milestone) { + if (milestone == null) { + return null; + } + return new ModelMapper().map(milestone, GitCmMilestone.class); + } + }; + // extract this to a general "userconverter" that can be passed a typetoken. final AbstractConverter authorConverter = new AbstractConverter() { @Override @@ -138,6 +143,7 @@ protected void configure() { map().setGitCmProjectId(source.getProjectId()); // milestone skipped because deep object not defined yet + using(milestoneConverter).map(source.getMilestone()).setGitCmMilestone(null); // same with assignees and author using(authorConverter).map(source.getAuthor()).setGitCmAuthor(null); diff --git a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java index 115b2fd..a6b8c5d 100644 --- a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java +++ b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java @@ -25,7 +25,7 @@ public void checkMilestoneMapping() { expected.setIid(1); expected.setProjectId(13027); expected.setTitle("Unit testing milestone"); - expected.setDescription("This is a mile stone for unit testing.\\r\\n\\r\\n# It can have Markdown!\\r\\n\\r\\n[and_attachments.txt](/uploads/50395a5a72794a9f4f1c629ce95ebaf2/and_attachments.txt)"); + expected.setDescription("This is a milestone for unit testing."); expected.setState("active"); expected.setCreatedAt("2018-06-05T16:19:05.023+02:00"); expected.setUpdatedAt("2018-06-05T16:19:05.023+02:00"); @@ -250,7 +250,7 @@ public void makeIssue() throws MalformedURLException { " \"iid\": 1,\n" + " \"project_id\": 13027,\n" + " \"title\": \"Unit testing milestone\",\n" + - " \"description\": \"This is a mile stone for unit testing.\\r\\n\\r\\n# It can have Markdown!\\r\\n\\r\\n[and_attachments.txt](/uploads/50395a5a72794a9f4f1c629ce95ebaf2/and_attachments.txt)\",\n" + + " \"description\": \"This is a milestone for unit testing.\",\n" + " \"state\": \"active\",\n" + " \"created_at\": \"2018-06-05T16:19:05.023+02:00\",\n" + " \"updated_at\": \"2018-06-05T16:19:05.023+02:00\",\n" + From 7daf9e8e7a3c2c42f4202d911061b2924ac258f4 Mon Sep 17 00:00:00 2001 From: SBI- Date: Wed, 6 Jun 2018 09:58:14 +0200 Subject: [PATCH 41/62] Extract user converter for use with all user types --- .../oslc/mapping/IssueMapper.java | 15 ++++---------- .../oslc/mapping/UserConverter.java | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/UserConverter.java diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index 34e9935..72493b8 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -5,7 +5,6 @@ import org.jazzcommunity.GitConnectorService.olsc.type.issue.*; import org.jazzcommunity.GitConnectorService.oslc.type.PrefixBuilder; import org.modelmapper.*; -import org.modelmapper.spi.MappingContext; import org.threeten.bp.*; import org.threeten.bp.format.DateTimeFormatter; @@ -91,14 +90,6 @@ protected GitCmMilestone convert(Milestone milestone) { } }; - // extract this to a general "userconverter" that can be passed a typetoken. - final AbstractConverter authorConverter = new AbstractConverter() { - @Override - protected GitCmAuthor convert(Author from) { - return new ModelMapper().map(from, GitCmAuthor.class); - } - }; - mapper.addMappings(new PropertyMap() { @Override protected void configure() { @@ -145,8 +136,10 @@ protected void configure() { // milestone skipped because deep object not defined yet using(milestoneConverter).map(source.getMilestone()).setGitCmMilestone(null); // same with assignees and author - using(authorConverter).map(source.getAuthor()).setGitCmAuthor(null); - + using(UserConverter.to(GitCmAuthor.class)) + .map(source.getAuthor()) + .setGitCmAuthor(null); + map().setGitCmUserNotesCount(source.getUserNotesCount()); map().setGitCmUpvotes(source.getUpvotes()); map().setGitCmDownvotes(source.getDownvotes()); diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/UserConverter.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/UserConverter.java new file mode 100644 index 0000000..90ad8f7 --- /dev/null +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/UserConverter.java @@ -0,0 +1,20 @@ +package org.jazzcommunity.GitConnectorService.oslc.mapping; + +import org.modelmapper.AbstractConverter; +import org.modelmapper.ModelMapper; + +public final class UserConverter { + private UserConverter() {} + + public static AbstractConverter to(final Class to) { + // it would be nice to have a reflective check here to see if the + // two user types are actually compatible... Or maybe find out how + // to define inheritance with auto-generated types + return new AbstractConverter() { + @Override + protected To convert(From from) { + return new ModelMapper().map(from, to); + } + }; + } +} From 987a4c68b29fd9accc4da962bbd0d9c0d5bd7fa9 Mon Sep 17 00:00:00 2001 From: SBI- Date: Wed, 6 Jun 2018 11:26:28 +0200 Subject: [PATCH 42/62] Add test for assignee mapping --- .../oslc/mapping/IssueMapper.java | 2 ++ .../oslc/mapping/UserConverter.java | 4 ++++ .../oslc/mapping/IssueMapperTest.java | 21 +++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index 72493b8..7afa536 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -90,6 +90,8 @@ protected GitCmMilestone convert(Milestone milestone) { } }; +// new AbstractConverter, List<>>() + mapper.addMappings(new PropertyMap() { @Override protected void configure() { diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/UserConverter.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/UserConverter.java index 90ad8f7..613ddb0 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/UserConverter.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/UserConverter.java @@ -13,6 +13,10 @@ public static AbstractConverter to(final Class to) { return new AbstractConverter() { @Override protected To convert(From from) { + if (from == null) { + return null; + } + return new ModelMapper().map(from, to); } }; diff --git a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java index a6b8c5d..238bc1c 100644 --- a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java +++ b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java @@ -18,6 +18,27 @@ public class IssueMapperTest { private OslcIssue oslcIssue; + @Test + public void checkAssigneeMapping() { + GitCmAuthor expected = new GitCmAuthor(); + expected.setId(115); + expected.setName("User 1"); + expected.setUsername("user.1"); + expected.setState("active"); + expected.setAvatarUrl("https://repo.git.com/uploads/-/system/user/avatar/115/avatar.png"); + expected.setWebUrl("https://git.lab/user.1"); + + // in gitlab ce, assignees is always a collection of exactly one user, + // which is why this test currently only checks for a single assignee. + Assert.assertNotNull(oslcIssue.getGitCmAssignees()); + Assert.assertFalse(oslcIssue.getGitCmAssignees().isEmpty()); + Assert.assertNotNull(oslcIssue.getGitCmAssignees().get(0)); + + Object assignee = oslcIssue.getGitCmAssignees().get(0); + Assert.assertTrue( + EqualsBuilder.reflectionEquals(expected, assignee)); + } + @Test public void checkMilestoneMapping() { GitCmMilestone expected = new GitCmMilestone(); From fcd031f8355f396a1b1ced643a185b6fc39c7362 Mon Sep 17 00:00:00 2001 From: SBI- Date: Wed, 6 Jun 2018 11:59:40 +0200 Subject: [PATCH 43/62] Implement assignee collection mapping --- .../oslc/mapping/IssueMapper.java | 20 ++++++++++++++++++- .../schemas/oslc/issue/OslcIssue.json | 9 ++++++++- .../oslc/mapping/IssueMapperTest.java | 7 ++++--- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index 7afa536..bb3892b 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -9,7 +9,9 @@ import org.threeten.bp.format.DateTimeFormatter; import java.net.URL; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; public class IssueMapper { private IssueMapper(){} @@ -90,7 +92,21 @@ protected GitCmMilestone convert(Milestone milestone) { } }; -// new AbstractConverter, List<>>() + final AbstractConverter, List> assigneeConverter = new AbstractConverter, List>() { + @Override + protected List convert(List assignees) { + if (assignees == null) { + return null; + } + + ModelMapper mapper = new ModelMapper(); + List converted = new ArrayList<>(assignees.size()); + for (Assignee assignee : assignees) { + converted.add(mapper.map(assignee, GitCmAssignee.class)); + } + return converted; + } + }; mapper.addMappings(new PropertyMap() { @Override @@ -142,6 +158,8 @@ protected void configure() { .map(source.getAuthor()) .setGitCmAuthor(null); + using(assigneeConverter).map(source.getAssignees()).setGitCmAssignees(null); + map().setGitCmUserNotesCount(source.getUserNotesCount()); map().setGitCmUpvotes(source.getUpvotes()); map().setGitCmDownvotes(source.getDownvotes()); diff --git a/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json b/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json index a96fcb4..e8986a8 100644 --- a/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json +++ b/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json @@ -48,7 +48,14 @@ "id" : 17, "updated_at" : "2016-01-04T15:31:39.996Z" }, - "git_cm:assignees": [], + "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", diff --git a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java index 238bc1c..dd21e72 100644 --- a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java +++ b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java @@ -20,9 +20,9 @@ public class IssueMapperTest { @Test public void checkAssigneeMapping() { - GitCmAuthor expected = new GitCmAuthor(); + GitCmAssignee expected = new GitCmAssignee(); expected.setId(115); - expected.setName("User 1"); + expected.setName("User 1 user1"); expected.setUsername("user.1"); expected.setState("active"); expected.setAvatarUrl("https://repo.git.com/uploads/-/system/user/avatar/115/avatar.png"); @@ -34,7 +34,8 @@ public void checkAssigneeMapping() { Assert.assertFalse(oslcIssue.getGitCmAssignees().isEmpty()); Assert.assertNotNull(oslcIssue.getGitCmAssignees().get(0)); - Object assignee = oslcIssue.getGitCmAssignees().get(0); + + GitCmAssignee assignee = oslcIssue.getGitCmAssignees().get(0); Assert.assertTrue( EqualsBuilder.reflectionEquals(expected, assignee)); } From b907fb93ffc6fcebe287523d7e7ad937e59b6c0e Mon Sep 17 00:00:00 2001 From: SBI- Date: Wed, 6 Jun 2018 15:08:57 +0200 Subject: [PATCH 44/62] Map directly to list type --- .../GitConnectorService/oslc/mapping/IssueMapper.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index bb3892b..731b18c 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -8,8 +8,8 @@ import org.threeten.bp.*; import org.threeten.bp.format.DateTimeFormatter; +import java.lang.reflect.Type; import java.net.URL; -import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -99,12 +99,8 @@ protected List convert(List assignees) { return null; } - ModelMapper mapper = new ModelMapper(); - List converted = new ArrayList<>(assignees.size()); - for (Assignee assignee : assignees) { - converted.add(mapper.map(assignee, GitCmAssignee.class)); - } - return converted; + Type converted = new TypeToken>() {}.getType(); + return mapper.map(assignees, converted); } }; From ec15afb091410d44d8d1d840527015f653b1c882 Mon Sep 17 00:00:00 2001 From: SBI- Date: Wed, 6 Jun 2018 15:59:31 +0200 Subject: [PATCH 45/62] Always serialize null values in issue link --- .../GitConnectorService/builder/gitlab/IssueLinkService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java index d71026c..893f6be 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java @@ -48,7 +48,7 @@ private void sendOslcResponse(Issue issue, UrlParameters parameters) throws IOEx // instead of get, IssueMapper should just export a 'map' function anyway... OslcIssue oslcPayload = IssueMapper.map(issue, UrlBuilder.getLinkUrl(parentService, parameters, "issue")); - Gson gson = new GsonBuilder().create(); + Gson gson = new GsonBuilder().serializeNulls().create(); String json = gson.toJson(oslcPayload); response.setContentType(ContentType.APPLICATION_JSON.toString()); response.getWriter().write(json); From 9c4abbc093c680a3c03a57238a82bb7392d240f7 Mon Sep 17 00:00:00 2001 From: SBI- Date: Wed, 6 Jun 2018 16:51:16 +0200 Subject: [PATCH 46/62] Start extracting converters to separate class --- .../oslc/mapping/Converters.java | 28 +++++++++++++++++++ .../oslc/mapping/IssueMapper.java | 22 ++------------- 2 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java new file mode 100644 index 0000000..281a0c3 --- /dev/null +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java @@ -0,0 +1,28 @@ +package org.jazzcommunity.GitConnectorService.oslc.mapping; + +import com.google.common.base.Joiner; +import org.modelmapper.AbstractConverter; + +import java.util.Collection; + +public final class Converters { + private Converters() {} + + public static AbstractConverter, String> listToString() { + return new AbstractConverter, String>() { + @Override + protected String convert(Collection strings) { + return Joiner.on(", ").join(strings); + } + }; + } + + public static AbstractConverter state() { + return new AbstractConverter() { + @Override + protected Boolean convert(String state) { + return state != null; + } + }; + } +} diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index 731b18c..4252e66 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -10,7 +10,6 @@ import java.lang.reflect.Type; import java.net.URL; -import java.util.Collection; import java.util.List; public class IssueMapper { @@ -20,16 +19,6 @@ public static OslcIssue map(Issue issue, final URL self) { final String link = self.toString(); final ModelMapper mapper = new ModelMapper(); - // I think a log of these converters can be extracted and reused, especially the ones that will - // need to be written for deep mapping of objects like links etc. - final AbstractConverter, String> listToString = - new AbstractConverter, String>() { - @Override - protected String convert(Collection strings) { - return Joiner.on(", ").join(strings); - } - }; - final AbstractConverter shortTitleConverter = new AbstractConverter() { @Override @@ -38,13 +27,6 @@ protected String convert(Integer iid) { } }; - final AbstractConverter stateConverter = new AbstractConverter() { - @Override - protected Boolean convert(String state) { - return state != null; - } - }; - final AbstractConverter linkConverter = new AbstractConverter() { @Override protected GitCmLinks convert(Links links) { @@ -119,7 +101,7 @@ protected void configure() { * see http://modelmapper.org/user-manual/property-mapping/ for documentation on the convention * of passing null when using a custom converter. */ - using(listToString).map(source.getLabels()).setDctermsSubject(null); + using(Converters.listToString()).map(source.getLabels()).setDctermsSubject(null); map().setGitCmLabels(source.getLabels()); map().setRdfAbout(link); @@ -130,7 +112,7 @@ protected void configure() { map().setPrefixes(PrefixBuilder.get()); - using(stateConverter).map(source.getClosedAt()).setOslcCmClosed(null); + using(Converters.state()).map(source.getClosedAt()).setOslcCmClosed(null); map().setGitCmClosedAt(source.getClosedAt()); map().setOslcCmStatus(source.getState()); From d4266283d51df122bc18a458507e48af6b2a1441 Mon Sep 17 00:00:00 2001 From: SBI- Date: Thu, 7 Jun 2018 09:33:33 +0200 Subject: [PATCH 47/62] Extract short title conversion --- .../GitConnectorService/oslc/mapping/Converters.java | 12 +++++++++++- .../oslc/mapping/IssueMapper.java | 10 +--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java index 281a0c3..da526d2 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java @@ -6,7 +6,8 @@ import java.util.Collection; public final class Converters { - private Converters() {} + private Converters() { + } public static AbstractConverter, String> listToString() { return new AbstractConverter, String>() { @@ -25,4 +26,13 @@ protected Boolean convert(String state) { } }; } + + public static AbstractConverter toShortTitle() { + return new AbstractConverter() { + @Override + protected String convert(Integer iid) { + return "Issue " + iid; + } + }; + } } diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index 4252e66..38e304f 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -19,14 +19,6 @@ public static OslcIssue map(Issue issue, final URL self) { final String link = self.toString(); final ModelMapper mapper = new ModelMapper(); - final AbstractConverter shortTitleConverter = - new AbstractConverter() { - @Override - protected String convert(Integer iid) { - return "Issue " + iid; - } - }; - final AbstractConverter linkConverter = new AbstractConverter() { @Override protected GitCmLinks convert(Links links) { @@ -123,7 +115,7 @@ protected void configure() { map().setGitCmId(source.getId()); map().setGitCmIid(source.getIid()); - using(shortTitleConverter).map(source.getIid()).setOslcShortTitle(null); + using(Converters.toShortTitle()).map(source.getIid()).setOslcShortTitle(null); using(toUtc).map(source.getDueDate()).setRtcCmDue(null); From a94aeccd0d3d50a8dcd7ff0618ebf028b473e9b6 Mon Sep 17 00:00:00 2001 From: SBI- Date: Thu, 7 Jun 2018 15:13:42 +0200 Subject: [PATCH 48/62] Fix NPE when item has no description --- .../GitConnectorService/builder/gitlab/IssueLinkService.java | 1 + .../jazzcommunity/GitConnectorService/html/MarkdownParser.java | 3 +++ 2 files changed, 4 insertions(+) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java index 893f6be..b124130 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java @@ -51,6 +51,7 @@ private void sendOslcResponse(Issue issue, UrlParameters parameters) throws IOEx Gson gson = new GsonBuilder().serializeNulls().create(); String json = gson.toJson(oslcPayload); response.setContentType(ContentType.APPLICATION_JSON.toString()); + response.setHeader("OSLC-Core-Version", "2.0"); response.getWriter().write(json); } diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/html/MarkdownParser.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/html/MarkdownParser.java index 4f95572..0d1d52d 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/html/MarkdownParser.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/html/MarkdownParser.java @@ -6,6 +6,9 @@ public class MarkdownParser { public static String toHtml(String markdown) { + if (markdown == null) { + return ""; + } Parser parser = Parser.builder().build(); Node document = parser.parse(markdown); HtmlRenderer renderer = HtmlRenderer.builder().build(); From c40f9e0c0014b943efa4d088a52acff29d680fd7 Mon Sep 17 00:00:00 2001 From: SBI- Date: Thu, 7 Jun 2018 16:29:21 +0200 Subject: [PATCH 49/62] Add mapping for dcterms:contributor --- .../oslc/mapping/Converters.java | 14 +++++++++++++ .../oslc/mapping/IssueMapper.java | 4 ++++ .../schemas/oslc/issue/OslcIssue.json | 21 +++++++++++++------ .../oslc/mapping/IssueMapperTest.java | 10 +++++++++ 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java index da526d2..a8f3adb 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java @@ -1,6 +1,8 @@ package org.jazzcommunity.GitConnectorService.oslc.mapping; +import ch.sbi.minigit.type.gitlab.issue.Author; import com.google.common.base.Joiner; +import org.jazzcommunity.GitConnectorService.olsc.type.issue.DctermsContributor; import org.modelmapper.AbstractConverter; import java.util.Collection; @@ -35,4 +37,16 @@ protected String convert(Integer iid) { } }; } + + public static AbstractConverter authorToContributor() { + return new AbstractConverter() { + @Override + protected DctermsContributor convert(Author author) { + DctermsContributor contributor = new DctermsContributor(); + contributor.setFoafName(author.getName()); + contributor.setRdfAbout(author.getWebUrl()); + return contributor; + } + }; + } } diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index 38e304f..bdcccd0 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -124,6 +124,10 @@ protected void configure() { // milestone skipped because deep object not defined yet using(milestoneConverter).map(source.getMilestone()).setGitCmMilestone(null); // same with assignees and author + using(Converters.authorToContributor()) + .map(source.getAuthor()) + .setDctermsContributor(null); + using(UserConverter.to(GitCmAuthor.class)) .map(source.getAuthor()) .setGitCmAuthor(null); diff --git a/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json b/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json index e8986a8..d08750a 100644 --- a/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json +++ b/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json @@ -10,6 +10,15 @@ "SizeXXL" ], "rdf:about": "https://code.siemens.com/guido.schneider/RTC-Commit-Picker-Demo/issues/10", + "dcterms:contributor": { + "rdf:type": [ + { + "rdf:resource": "http://xmlns.com/foaf/0.1/Person" + } + ], + "foaf:name": "myadmin", + "rdf:about": "https://localhost:7443/jazz/users/myadmin" + }, "dcterms:created": "2018-02-09T17:18:28.949Z", "git_cm:created_at": "2018-03-09T15:04:02.789+01:00", "dcterms:modified": "2018-04-04T08:57:34.453Z", @@ -49,12 +58,12 @@ "updated_at" : "2016-01-04T15:31:39.996Z" }, "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" + "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, diff --git a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java index dd21e72..8d2ff7f 100644 --- a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java +++ b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java @@ -18,6 +18,16 @@ public class IssueMapperTest { private OslcIssue oslcIssue; + @Test + public void checkDcTermsContributorIsAuthor() { + DctermsContributor contributor = new DctermsContributor(); + contributor.setFoafName("User 2"); + contributor.setRdfAbout("https://git.lab/user.2"); + + Assert.assertTrue( + EqualsBuilder.reflectionEquals(contributor, oslcIssue.getDctermsContributor())); + } + @Test public void checkAssigneeMapping() { GitCmAssignee expected = new GitCmAssignee(); From 4b1c75ad7ec2a0e8d22de462a25b17bdaa04f2af Mon Sep 17 00:00:00 2001 From: SBI- Date: Fri, 8 Jun 2018 09:55:02 +0200 Subject: [PATCH 50/62] Fix deep comparison of rdf contributor --- .../oslc/mapping/Converters.java | 8 +++++++ .../oslc/mapping/IssueMapperTest.java | 24 +++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java index a8f3adb..d055676 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java @@ -3,8 +3,10 @@ import ch.sbi.minigit.type.gitlab.issue.Author; import com.google.common.base.Joiner; import org.jazzcommunity.GitConnectorService.olsc.type.issue.DctermsContributor; +import org.jazzcommunity.GitConnectorService.olsc.type.issue.RdfType; import org.modelmapper.AbstractConverter; +import java.util.ArrayList; import java.util.Collection; public final class Converters { @@ -42,7 +44,13 @@ public static AbstractConverter authorToContributor( return new AbstractConverter() { @Override protected DctermsContributor convert(Author author) { + RdfType type = new RdfType(); + type.setRdfResource("http://xmlns.com/foaf/0.1/Person"); + ArrayList types = new ArrayList<>(); + types.add(type); + DctermsContributor contributor = new DctermsContributor(); + contributor.setRdfType(types); contributor.setFoafName(author.getName()); contributor.setRdfAbout(author.getWebUrl()); return contributor; diff --git a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java index 8d2ff7f..9ce7078 100644 --- a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java +++ b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java @@ -13,6 +13,7 @@ import java.net.MalformedURLException; import java.net.URL; +import java.util.ArrayList; public class IssueMapperTest { @@ -20,12 +21,21 @@ public class IssueMapperTest { @Test public void checkDcTermsContributorIsAuthor() { - DctermsContributor contributor = new DctermsContributor(); - contributor.setFoafName("User 2"); - contributor.setRdfAbout("https://git.lab/user.2"); - - Assert.assertTrue( - EqualsBuilder.reflectionEquals(contributor, oslcIssue.getDctermsContributor())); + RdfType type = new RdfType(); + type.setRdfResource("http://xmlns.com/foaf/0.1/Person"); + ArrayList types = new ArrayList<>(); + types.add(type); + + DctermsContributor expected = new DctermsContributor(); + expected.setRdfType(types); + expected.setFoafName("User 2"); + expected.setRdfAbout("https://git.lab/user.2"); + + Assert.assertEquals(expected.getFoafName(), oslcIssue.getDctermsContributor().getFoafName()); + Assert.assertEquals(expected.getRdfAbout(), oslcIssue.getDctermsContributor().getRdfAbout()); + Assert.assertEquals( + expected.getRdfType().get(0).getRdfResource(), + oslcIssue.getDctermsContributor().getRdfType().get(0).getRdfResource()); } @Test @@ -38,7 +48,7 @@ public void checkAssigneeMapping() { expected.setAvatarUrl("https://repo.git.com/uploads/-/system/user/avatar/115/avatar.png"); expected.setWebUrl("https://git.lab/user.1"); - // in gitlab ce, assignees is always a collection of exactly one user, + // in gitlab ce, assignees is always a collection of at most one user, // which is why this test currently only checks for a single assignee. Assert.assertNotNull(oslcIssue.getGitCmAssignees()); Assert.assertFalse(oslcIssue.getGitCmAssignees().isEmpty()); From f4a978fefee43b0f0e925849d713b3f49e733e3c Mon Sep 17 00:00:00 2001 From: SBI- Date: Fri, 8 Jun 2018 09:58:06 +0200 Subject: [PATCH 51/62] Clean up code formatting in contributor test --- .../oslc/mapping/IssueMapperTest.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java index 9ce7078..c42cefa 100644 --- a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java +++ b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java @@ -8,7 +8,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.threeten.bp.*; +import org.threeten.bp.ZonedDateTime; import org.threeten.bp.format.DateTimeFormatter; import java.net.MalformedURLException; @@ -31,8 +31,12 @@ public void checkDcTermsContributorIsAuthor() { expected.setFoafName("User 2"); expected.setRdfAbout("https://git.lab/user.2"); - Assert.assertEquals(expected.getFoafName(), oslcIssue.getDctermsContributor().getFoafName()); - Assert.assertEquals(expected.getRdfAbout(), oslcIssue.getDctermsContributor().getRdfAbout()); + Assert.assertEquals( + expected.getFoafName(), + oslcIssue.getDctermsContributor().getFoafName()); + Assert.assertEquals( + expected.getRdfAbout(), + oslcIssue.getDctermsContributor().getRdfAbout()); Assert.assertEquals( expected.getRdfType().get(0).getRdfResource(), oslcIssue.getDctermsContributor().getRdfType().get(0).getRdfResource()); From 5e814ee6b54082d94cad00e23a2d50f3cb2de5db Mon Sep 17 00:00:00 2001 From: SBI- Date: Fri, 8 Jun 2018 10:21:02 +0200 Subject: [PATCH 52/62] Extract link and date converters --- .../oslc/mapping/Converters.java | 32 +++++++++++++++++++ .../oslc/mapping/IssueMapper.java | 24 ++------------ 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java index d055676..1beac86 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java @@ -1,10 +1,18 @@ package org.jazzcommunity.GitConnectorService.oslc.mapping; import ch.sbi.minigit.type.gitlab.issue.Author; +import ch.sbi.minigit.type.gitlab.issue.Links; import com.google.common.base.Joiner; import org.jazzcommunity.GitConnectorService.olsc.type.issue.DctermsContributor; +import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmLinks; import org.jazzcommunity.GitConnectorService.olsc.type.issue.RdfType; import org.modelmapper.AbstractConverter; +import org.modelmapper.ModelMapper; +import org.threeten.bp.LocalDate; +import org.threeten.bp.LocalTime; +import org.threeten.bp.ZoneOffset; +import org.threeten.bp.ZonedDateTime; +import org.threeten.bp.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Collection; @@ -57,4 +65,28 @@ protected DctermsContributor convert(Author author) { } }; } + + public static AbstractConverter links() { + return new AbstractConverter() { + @Override + protected GitCmLinks convert(Links links) { + return new ModelMapper().map(links, GitCmLinks.class); + } + }; + } + + public static AbstractConverter dateToUtc() { + return new AbstractConverter() { + @Override + protected String convert(String from) { + if (from == null) { + return null; + } + + LocalDate date = LocalDate.parse(from, DateTimeFormatter.ISO_DATE); + ZonedDateTime dateTime = ZonedDateTime.of(date, LocalTime.MIDNIGHT, ZoneOffset.UTC); + return dateTime.toString(); + } + }; + } } diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index bdcccd0..c170960 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -19,26 +19,6 @@ public static OslcIssue map(Issue issue, final URL self) { final String link = self.toString(); final ModelMapper mapper = new ModelMapper(); - final AbstractConverter linkConverter = new AbstractConverter() { - @Override - protected GitCmLinks convert(Links links) { - return new ModelMapper().map(links, GitCmLinks.class); - } - }; - - final AbstractConverter toUtc = new AbstractConverter() { - @Override - protected String convert(String from) { - if (from == null) { - return null; - } - - LocalDate date = LocalDate.parse(from, DateTimeFormatter.ISO_DATE); - ZonedDateTime dateTime = ZonedDateTime.of(date, LocalTime.MIDNIGHT, ZoneOffset.UTC); - return dateTime.toString(); - } - }; - final AbstractConverter timeStatsConverter = new AbstractConverter() { @Override @@ -117,7 +97,7 @@ protected void configure() { using(Converters.toShortTitle()).map(source.getIid()).setOslcShortTitle(null); - using(toUtc).map(source.getDueDate()).setRtcCmDue(null); + using(Converters.dateToUtc()).map(source.getDueDate()).setRtcCmDue(null); map().setGitCmProjectId(source.getProjectId()); @@ -152,7 +132,7 @@ protected void configure() { .map(source.getTimeStats().getTotalTimeSpent()) .setRtcCmTimeSpent(null); - using(linkConverter).map(source.getLinks()).setGitCmLinks(null); + using(Converters.links()).map(source.getLinks()).setGitCmLinks(null); map().setGitCmSubscribed(source.getSubscribed()); } From 269dbfe8c66b2fa83ed65dd7b9de8828f3805913 Mon Sep 17 00:00:00 2001 From: SBI- Date: Fri, 8 Jun 2018 10:41:19 +0200 Subject: [PATCH 53/62] Extract time and milestone converters --- .../oslc/mapping/Converters.java | 37 ++++++++++++++++-- .../oslc/mapping/IssueMapper.java | 38 ++----------------- 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java index 1beac86..27972d9 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java @@ -2,10 +2,10 @@ import ch.sbi.minigit.type.gitlab.issue.Author; import ch.sbi.minigit.type.gitlab.issue.Links; +import ch.sbi.minigit.type.gitlab.issue.Milestone; +import ch.sbi.minigit.type.gitlab.issue.TimeStats; import com.google.common.base.Joiner; -import org.jazzcommunity.GitConnectorService.olsc.type.issue.DctermsContributor; -import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmLinks; -import org.jazzcommunity.GitConnectorService.olsc.type.issue.RdfType; +import org.jazzcommunity.GitConnectorService.olsc.type.issue.*; import org.modelmapper.AbstractConverter; import org.modelmapper.ModelMapper; import org.threeten.bp.LocalDate; @@ -89,4 +89,35 @@ protected String convert(String from) { } }; } + + public static AbstractConverter timeStats() { + return new AbstractConverter() { + @Override + protected GitCmTimeStats convert(TimeStats timeStats) { + return new ModelMapper().map(timeStats, GitCmTimeStats.class); + } + }; + } + + public static AbstractConverter timeStamp() { + return new AbstractConverter() { + @Override + protected Integer convert(Integer timeStamp) { + return timeStamp * 1000; + } + }; + } + + public static AbstractConverter milestone() { + return new AbstractConverter() { + @Override + protected GitCmMilestone convert(Milestone milestone) { + if (milestone == null) { + return null; + } + + return new ModelMapper().map(milestone, GitCmMilestone.class); + } + }; + } } diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index c170960..fad9146 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -1,12 +1,9 @@ package org.jazzcommunity.GitConnectorService.oslc.mapping; import ch.sbi.minigit.type.gitlab.issue.*; -import com.google.common.base.Joiner; import org.jazzcommunity.GitConnectorService.olsc.type.issue.*; import org.jazzcommunity.GitConnectorService.oslc.type.PrefixBuilder; import org.modelmapper.*; -import org.threeten.bp.*; -import org.threeten.bp.format.DateTimeFormatter; import java.lang.reflect.Type; import java.net.URL; @@ -19,33 +16,6 @@ public static OslcIssue map(Issue issue, final URL self) { final String link = self.toString(); final ModelMapper mapper = new ModelMapper(); - final AbstractConverter timeStatsConverter = - new AbstractConverter() { - @Override - protected GitCmTimeStats convert(TimeStats timeStats) { - return new ModelMapper().map(timeStats, GitCmTimeStats.class); - } - }; - - final AbstractConverter toRtcTimeStamp = - new AbstractConverter() { - @Override - protected Integer convert(Integer timeStamp) { - return timeStamp * 1000; - } - }; - - final AbstractConverter milestoneConverter = - new AbstractConverter() { - @Override - protected GitCmMilestone convert(Milestone milestone) { - if (milestone == null) { - return null; - } - return new ModelMapper().map(milestone, GitCmMilestone.class); - } - }; - final AbstractConverter, List> assigneeConverter = new AbstractConverter, List>() { @Override protected List convert(List assignees) { @@ -102,7 +72,7 @@ protected void configure() { map().setGitCmProjectId(source.getProjectId()); // milestone skipped because deep object not defined yet - using(milestoneConverter).map(source.getMilestone()).setGitCmMilestone(null); + using(Converters.milestone()).map(source.getMilestone()).setGitCmMilestone(null); // same with assignees and author using(Converters.authorToContributor()) .map(source.getAuthor()) @@ -123,12 +93,12 @@ protected void configure() { map().setGitCmDiscussionLocked(source.getDiscussionLocked()); map().setGitCmWebUrl(source.getWebUrl()); - using(timeStatsConverter).map(source.getTimeStats()).setGitCmTimeStats(null); - using(toRtcTimeStamp) + using(Converters.timeStats()).map(source.getTimeStats()).setGitCmTimeStats(null); + using(Converters.timeStamp()) .map(source.getTimeStats().getTimeEstimate()) .setRtcCmEstimate(null); - using(toRtcTimeStamp) + using(Converters.timeStamp()) .map(source.getTimeStats().getTotalTimeSpent()) .setRtcCmTimeSpent(null); From 35909c4c8a08f0de25e9772b7586c2a1b4071c71 Mon Sep 17 00:00:00 2001 From: SBI- Date: Fri, 8 Jun 2018 10:51:25 +0200 Subject: [PATCH 54/62] Extract remaining converters --- .../oslc/mapping/Converters.java | 22 +++++++++++++++---- .../oslc/mapping/IssueMapper.java | 16 ++------------ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java index 27972d9..6128ae3 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java @@ -1,21 +1,21 @@ package org.jazzcommunity.GitConnectorService.oslc.mapping; -import ch.sbi.minigit.type.gitlab.issue.Author; -import ch.sbi.minigit.type.gitlab.issue.Links; -import ch.sbi.minigit.type.gitlab.issue.Milestone; -import ch.sbi.minigit.type.gitlab.issue.TimeStats; +import ch.sbi.minigit.type.gitlab.issue.*; import com.google.common.base.Joiner; import org.jazzcommunity.GitConnectorService.olsc.type.issue.*; import org.modelmapper.AbstractConverter; import org.modelmapper.ModelMapper; +import org.modelmapper.TypeToken; import org.threeten.bp.LocalDate; import org.threeten.bp.LocalTime; import org.threeten.bp.ZoneOffset; import org.threeten.bp.ZonedDateTime; import org.threeten.bp.format.DateTimeFormatter; +import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Collection; +import java.util.List; public final class Converters { private Converters() { @@ -120,4 +120,18 @@ protected GitCmMilestone convert(Milestone milestone) { } }; } + + public static AbstractConverter, List> assignees() { + return new AbstractConverter, List>() { + @Override + protected List convert(List assignees) { + if (assignees == null) { + return null; + } + + Type converted = new TypeToken>() {}.getType(); + return new ModelMapper().map(assignees, converted); + } + }; + } } diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index fad9146..8ab9366 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -14,19 +14,7 @@ private IssueMapper(){} public static OslcIssue map(Issue issue, final URL self) { final String link = self.toString(); - final ModelMapper mapper = new ModelMapper(); - - final AbstractConverter, List> assigneeConverter = new AbstractConverter, List>() { - @Override - protected List convert(List assignees) { - if (assignees == null) { - return null; - } - - Type converted = new TypeToken>() {}.getType(); - return mapper.map(assignees, converted); - } - }; + ModelMapper mapper = new ModelMapper(); mapper.addMappings(new PropertyMap() { @Override @@ -82,7 +70,7 @@ protected void configure() { .map(source.getAuthor()) .setGitCmAuthor(null); - using(assigneeConverter).map(source.getAssignees()).setGitCmAssignees(null); + using(Converters.assignees()).map(source.getAssignees()).setGitCmAssignees(null); map().setGitCmUserNotesCount(source.getUserNotesCount()); map().setGitCmUpvotes(source.getUpvotes()); From b51605ee11f4a23f9b044cbab463cac4c8cf1ff6 Mon Sep 17 00:00:00 2001 From: SBI- Date: Fri, 8 Jun 2018 10:53:13 +0200 Subject: [PATCH 55/62] Run code cleanup --- .../oslc/mapping/Converters.java | 3 ++- .../oslc/mapping/IssueMapper.java | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java index 6128ae3..e26c8b3 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java @@ -129,7 +129,8 @@ protected List convert(List assignees) { return null; } - Type converted = new TypeToken>() {}.getType(); + Type converted = new TypeToken>() { + }.getType(); return new ModelMapper().map(assignees, converted); } }; diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index 8ab9366..5baaa92 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -1,16 +1,17 @@ package org.jazzcommunity.GitConnectorService.oslc.mapping; -import ch.sbi.minigit.type.gitlab.issue.*; -import org.jazzcommunity.GitConnectorService.olsc.type.issue.*; +import ch.sbi.minigit.type.gitlab.issue.Issue; +import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmAuthor; +import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; import org.jazzcommunity.GitConnectorService.oslc.type.PrefixBuilder; -import org.modelmapper.*; +import org.modelmapper.ModelMapper; +import org.modelmapper.PropertyMap; -import java.lang.reflect.Type; import java.net.URL; -import java.util.List; public class IssueMapper { - private IssueMapper(){} + private IssueMapper() { + } public static OslcIssue map(Issue issue, final URL self) { final String link = self.toString(); From 041c2e54bb017d03d056e9c9654705d77e0bab54 Mon Sep 17 00:00:00 2001 From: SBI- Date: Fri, 8 Jun 2018 10:59:52 +0200 Subject: [PATCH 56/62] Autoformat code --- .../GitConnectorService/GitConnectorService.java | 8 ++++++-- .../builder/github/RequestLinkService.java | 2 +- .../builder/gitlab/CommitPreviewService.java | 11 +++++------ .../builder/gitlab/IssueLinkService.java | 4 ++-- .../builder/gitlab/RequestLinkService.java | 2 +- .../GitConnectorService/data/TokenHelper.java | 2 +- .../GitConnectorService/net/Request.java | 2 +- .../GitConnectorService/oslc/mapping/IssueMapper.java | 2 +- .../oslc/mapping/UserConverter.java | 3 ++- .../GitConnectorService/oslc/type/PrefixBuilder.java | 4 ++-- 10 files changed, 22 insertions(+), 18 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/GitConnectorService.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/GitConnectorService.java index 4c74abf..f8fe298 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/GitConnectorService.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/GitConnectorService.java @@ -6,7 +6,10 @@ import com.siemens.bt.jazz.services.base.rest.RestActionBuilder; import com.siemens.bt.jazz.services.base.rest.RestRequest; import com.siemens.bt.jazz.services.base.router.factory.RestFactory; -import org.jazzcommunity.GitConnectorService.builder.gitlab.*; +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.router.CustomRouter; import javax.servlet.http.HttpServletRequest; @@ -50,6 +53,7 @@ public GitConnectorService() { // router.addService(HttpMethod.GET, ".*/gitlab/[a-zA-Z.]+/project/[0-9]+/commit/[^\\/]+/preview.*", // new RestFactory(CommitPreviewService.class)); } + @Override public void perform_GET(String uri, HttpServletRequest request, HttpServletResponse response) throws IOException { performAction(uri, request, response); @@ -69,7 +73,7 @@ protected void performAction(String uri, HttpServletRequest request, HttpServlet // This will need extra logging, but we quench it for now to allow non-authorized requests // without spamming the server log. Sorry :-* //throw e; - } catch (Exception e) { + } catch (Exception e) { // catch everything and log. Makes sure that there is no checked exception from our service back // to jazz, except for the expected IOException when the response isn't writable. We need to make // sure that our plug-in conforms to the contract that no exceptions bubble out into the system. diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/github/RequestLinkService.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/github/RequestLinkService.java index 04db0c7..3d9133d 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/github/RequestLinkService.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/github/RequestLinkService.java @@ -5,8 +5,8 @@ import com.siemens.bt.jazz.services.base.rest.AbstractRestService; import com.siemens.bt.jazz.services.base.rest.RestRequest; import org.apache.commons.logging.Log; -import org.jazzcommunity.GitConnectorService.net.ArtifactInformation; import org.jazzcommunity.GitConnectorService.data.GithubConnection; +import org.jazzcommunity.GitConnectorService.net.ArtifactInformation; import org.jazzcommunity.GitConnectorService.net.Request; import org.jtwig.JtwigModel; import org.jtwig.JtwigTemplate; diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/CommitPreviewService.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/CommitPreviewService.java index 4bb40c7..fc84913 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/CommitPreviewService.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/CommitPreviewService.java @@ -2,12 +2,6 @@ import ch.sbi.minigit.gitlab.GitlabApi; import ch.sbi.minigit.type.gitlab.commit.Commit; -import java.io.IOException; -import java.net.URL; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import com.ibm.team.repository.service.TeamRawService; import com.siemens.bt.jazz.services.base.rest.AbstractRestService; import com.siemens.bt.jazz.services.base.rest.RestRequest; @@ -18,6 +12,11 @@ import org.jtwig.JtwigModel; import org.jtwig.JtwigTemplate; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.net.URL; + public class CommitPreviewService extends AbstractRestService { public CommitPreviewService(Log log, HttpServletRequest request, HttpServletResponse response, RestRequest restRequest, TeamRawService parentService) { diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java index b124130..84121dd 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/IssueLinkService.java @@ -11,11 +11,11 @@ import org.apache.commons.logging.Log; import org.apache.http.entity.ContentType; import org.jazzcommunity.GitConnectorService.data.TokenHelper; -import org.jazzcommunity.GitConnectorService.oslc.mapping.IssueMapper; import org.jazzcommunity.GitConnectorService.net.Request; import org.jazzcommunity.GitConnectorService.net.UrlBuilder; import org.jazzcommunity.GitConnectorService.net.UrlParameters; import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; +import org.jazzcommunity.GitConnectorService.oslc.mapping.IssueMapper; import org.jtwig.JtwigModel; import org.jtwig.JtwigTemplate; @@ -36,7 +36,7 @@ public void execute() throws IOException { if (Request.isLinkRequest(request)) { sendLinkResponse(issue, parameters); - } else if(Request.isOslcRequest(request)) { + } else if (Request.isOslcRequest(request)) { sendOslcResponse(issue, parameters); } else { response.sendRedirect(issue.getWebUrl()); diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/RequestLinkService.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/RequestLinkService.java index f609625..2095960 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/RequestLinkService.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/builder/gitlab/RequestLinkService.java @@ -1,5 +1,6 @@ package org.jazzcommunity.GitConnectorService.builder.gitlab; +import ch.sbi.minigit.gitlab.GitlabApi; import ch.sbi.minigit.type.gitlab.mergerequest.MergeRequest; import com.ibm.team.repository.service.TeamRawService; import com.siemens.bt.jazz.services.base.rest.AbstractRestService; @@ -10,7 +11,6 @@ import org.jazzcommunity.GitConnectorService.net.Request; import org.jazzcommunity.GitConnectorService.net.UrlBuilder; import org.jazzcommunity.GitConnectorService.net.UrlParameters; -import ch.sbi.minigit.gitlab.GitlabApi; import org.jtwig.JtwigModel; import org.jtwig.JtwigTemplate; diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/data/TokenHelper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/data/TokenHelper.java index 427d0c1..9dcbce7 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/data/TokenHelper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/data/TokenHelper.java @@ -3,11 +3,11 @@ import com.ibm.team.repository.common.IContributor; import com.ibm.team.repository.common.TeamRepositoryException; import com.ibm.team.repository.service.TeamRawService; -import org.jazzcommunity.GitConnectorService.buildsecret.security.Crypto; import org.jazzcommunity.GitConnectorService.buildsecret.internal.BuildSecretsHelper; import org.jazzcommunity.GitConnectorService.buildsecret.internal.BuildSecretsReader; import org.jazzcommunity.GitConnectorService.buildsecret.jazz.AdvancedProperties; import org.jazzcommunity.GitConnectorService.buildsecret.jazz.User; +import org.jazzcommunity.GitConnectorService.buildsecret.security.Crypto; import java.io.UnsupportedEncodingException; import java.net.URL; diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/net/Request.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/net/Request.java index 46abe3e..29f3993 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/net/Request.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/net/Request.java @@ -8,7 +8,7 @@ public class Request { public static boolean isLinkRequest(HttpServletRequest request) { return request.getHeader("Accept").contains("application/x-jazz-compact-rendering") - || request.getHeader("Accept").contains("application/x-oslc-compact+xml"); + || request.getHeader("Accept").contains("application/x-oslc-compact+xml"); } public static boolean isOslcRequest(HttpServletRequest request) { diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index 5baaa92..7c7bf6f 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -9,7 +9,7 @@ import java.net.URL; -public class IssueMapper { +public final class IssueMapper { private IssueMapper() { } diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/UserConverter.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/UserConverter.java index 613ddb0..0984b9d 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/UserConverter.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/UserConverter.java @@ -4,7 +4,8 @@ import org.modelmapper.ModelMapper; public final class UserConverter { - private UserConverter() {} + private UserConverter() { + } public static AbstractConverter to(final Class to) { // it would be nice to have a reflective check here to see if the diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/type/PrefixBuilder.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/type/PrefixBuilder.java index dc90cd0..69711d9 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/type/PrefixBuilder.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/type/PrefixBuilder.java @@ -4,14 +4,14 @@ public final class PrefixBuilder { - private PrefixBuilder() {} - private static final String gitCm = "http://jazz-community.org/ns/git_cm"; private static final String rtcCm = "http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/"; private static final String rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; private static final String dcterms = "http://purl.org/dc/terms/"; private static final String oslc = "http://open-services.net/ns/core#"; private static final String oslcCm = "http://open-services.net/ns/cm#"; + private PrefixBuilder() { + } public static Prefixes get() { Prefixes prefixes = new Prefixes(); From 8a06d29fac009e39e25cfddd55fac02f363d926a Mon Sep 17 00:00:00 2001 From: SBI- Date: Fri, 8 Jun 2018 12:24:19 +0200 Subject: [PATCH 57/62] Add comments and fix order in mapper --- .../oslc/mapping/Converters.java | 3 +- .../oslc/mapping/IssueMapper.java | 90 +++++++++++-------- 2 files changed, 56 insertions(+), 37 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java index e26c8b3..6128ae3 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/Converters.java @@ -129,8 +129,7 @@ protected List convert(List assignees) { return null; } - Type converted = new TypeToken>() { - }.getType(); + Type converted = new TypeToken>() {}.getType(); return new ModelMapper().map(assignees, converted); } }; diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index 7c7bf6f..ac792f9 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -13,6 +13,19 @@ public final class IssueMapper { private IssueMapper() { } + /** + * Returns an Oslc formatted Issue that can be used in jazz UI Plugins. Mimicks other rtc + * entities in its representation. + * + *

+ * see http://modelmapper.org/user-manual/property-mapping/ for documentation on the + * convention of passing null when using a custom converter. + *

+ * + * @param issue The Gitlab issue to map + * @param self The web link to the current entity + * @return An Oslc representation of 'issue' + */ public static OslcIssue map(Issue issue, final URL self) { final String link = self.toString(); ModelMapper mapper = new ModelMapper(); @@ -20,79 +33,86 @@ public static OslcIssue map(Issue issue, final URL self) { mapper.addMappings(new PropertyMap() { @Override protected void configure() { + // Entity type map().setDctermsType("Issue"); - + // Title map().setDctermsTitle(source.getTitle()); map().setGitCmTitle(source.getTitle()); - + // Description map().setDctermsDescription(source.getDescription()); map().setGitCmDescription(source.getDescription()); - - /* - * see http://modelmapper.org/user-manual/property-mapping/ for documentation on the convention - * of passing null when using a custom converter. - */ + // Subject and labels using(Converters.listToString()).map(source.getLabels()).setDctermsSubject(null); map().setGitCmLabels(source.getLabels()); + // Link to self map().setRdfAbout(link); - + // Contributor + using(Converters.authorToContributor()) + .map(source.getAuthor()) + .setDctermsContributor(null); + // Creation and modification time stamps map().setGitCmCreatedAt(source.getCreatedAt()); map().setGitCmUpdatedAt(source.getUpdatedAt()); map().setDctermsCreated(source.getCreatedAt()); map().setDctermsModified(source.getUpdatedAt()); - - map().setPrefixes(PrefixBuilder.get()); - + // Entity state using(Converters.state()).map(source.getClosedAt()).setOslcCmClosed(null); - map().setGitCmClosedAt(source.getClosedAt()); map().setOslcCmStatus(source.getState()); map().setGitCmState(source.getState()); + // Identifiers map().setOslcShortId(source.getIid().toString()); map().setDctermsIdentifier(source.getId().toString()); - map().setGitCmId(source.getId()); map().setGitCmIid(source.getIid()); - + // Prefixes object + map().setPrefixes(PrefixBuilder.get()); + // Short title using(Converters.toShortTitle()).map(source.getIid()).setOslcShortTitle(null); - + // Due Date using(Converters.dateToUtc()).map(source.getDueDate()).setRtcCmDue(null); + // RTC time estimate and time spent + using(Converters.timeStamp()) + .map(source.getTimeStats().getTimeEstimate()) + .setRtcCmEstimate(null); + using(Converters.timeStamp()) + .map(source.getTimeStats().getTotalTimeSpent()) + .setRtcCmTimeSpent(null); - map().setGitCmProjectId(source.getProjectId()); + // TODO: Add + // Git cm details - // milestone skipped because deep object not defined yet + // Project id + map().setGitCmProjectId(source.getProjectId()); + // Milestone object using(Converters.milestone()).map(source.getMilestone()).setGitCmMilestone(null); - // same with assignees and author - using(Converters.authorToContributor()) - .map(source.getAuthor()) - .setDctermsContributor(null); - + // Assignees + using(Converters.assignees()).map(source.getAssignees()).setGitCmAssignees(null); + // Author using(UserConverter.to(GitCmAuthor.class)) .map(source.getAuthor()) .setGitCmAuthor(null); - - using(Converters.assignees()).map(source.getAssignees()).setGitCmAssignees(null); - + // TODO: Add + // Closed by + // Comment and vote statistics map().setGitCmUserNotesCount(source.getUserNotesCount()); map().setGitCmUpvotes(source.getUpvotes()); map().setGitCmDownvotes(source.getDownvotes()); + // Due date map().setGitCmDueDate(source.getDueDate()); + // Confidentiality map().setGitCmConfidential(source.getConfidential()); + // TODO: Add? // Weight skipped, EE feature only. Not sure if we need this. + // Discussion state map().setGitCmDiscussionLocked(source.getDiscussionLocked()); + // Web url of issue in gitlab map().setGitCmWebUrl(source.getWebUrl()); - + // Time statistics object using(Converters.timeStats()).map(source.getTimeStats()).setGitCmTimeStats(null); - using(Converters.timeStamp()) - .map(source.getTimeStats().getTimeEstimate()) - .setRtcCmEstimate(null); - - using(Converters.timeStamp()) - .map(source.getTimeStats().getTotalTimeSpent()) - .setRtcCmTimeSpent(null); - + // Git links object using(Converters.links()).map(source.getLinks()).setGitCmLinks(null); - + // User subscription map().setGitCmSubscribed(source.getSubscribed()); } }); From dfd66bb45800fe09ccd71285710a60b4d5b029b1 Mon Sep 17 00:00:00 2001 From: SBI- Date: Fri, 8 Jun 2018 12:39:06 +0200 Subject: [PATCH 58/62] Remove details url --- .../GitConnectorService/oslc/mapping/IssueMapper.java | 4 ---- plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json | 1 - 2 files changed, 5 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index ac792f9..c75d3db 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -78,10 +78,6 @@ protected void configure() { using(Converters.timeStamp()) .map(source.getTimeStats().getTotalTimeSpent()) .setRtcCmTimeSpent(null); - - // TODO: Add - // Git cm details - // Project id map().setGitCmProjectId(source.getProjectId()); // Milestone object diff --git a/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json b/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json index d08750a..3818fb2 100644 --- a/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json +++ b/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json @@ -43,7 +43,6 @@ "rtc_cm:due": "2018-04-19T10:00:00.000Z", "rtc_cm:estimate": 18000000, "rtc_cm:timeSpent": 10800000, - "git_cm:details": "/details", "git_cm:project_id": 23862, "git_cm:milestone": { "project_id" : 23862, From 339a34788f0dace4875eef48b8ae80d82f7fad7d Mon Sep 17 00:00:00 2001 From: SBI- Date: Fri, 8 Jun 2018 13:42:59 +0200 Subject: [PATCH 59/62] Implement closed by and map to user --- .../GitConnectorService/oslc/mapping/IssueMapper.java | 8 ++++++-- .../src/main/resources/schemas/oslc/issue/OslcIssue.json | 9 ++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index c75d3db..b15ce0d 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -2,6 +2,7 @@ import ch.sbi.minigit.type.gitlab.issue.Issue; import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmAuthor; +import org.jazzcommunity.GitConnectorService.olsc.type.issue.GitCmClosedBy; import org.jazzcommunity.GitConnectorService.olsc.type.issue.OslcIssue; import org.jazzcommunity.GitConnectorService.oslc.type.PrefixBuilder; import org.modelmapper.ModelMapper; @@ -57,9 +58,9 @@ protected void configure() { map().setDctermsModified(source.getUpdatedAt()); // Entity state using(Converters.state()).map(source.getClosedAt()).setOslcCmClosed(null); - map().setGitCmClosedAt(source.getClosedAt()); map().setOslcCmStatus(source.getState()); map().setGitCmState(source.getState()); + map().setGitCmClosedAt(source.getClosedAt()); // Identifiers map().setOslcShortId(source.getIid().toString()); map().setDctermsIdentifier(source.getId().toString()); @@ -88,8 +89,11 @@ protected void configure() { using(UserConverter.to(GitCmAuthor.class)) .map(source.getAuthor()) .setGitCmAuthor(null); - // TODO: Add // Closed by + using(UserConverter.to(GitCmClosedBy.class)) + .map(source.getClosedBy()) + .setGitCmClosedBy(null); + // TODO: Add // Comment and vote statistics map().setGitCmUserNotesCount(source.getUserNotesCount()); map().setGitCmUpvotes(source.getUpvotes()); diff --git a/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json b/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json index 3818fb2..a2f7c0e 100644 --- a/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json +++ b/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json @@ -72,7 +72,14 @@ "avatar_url": "https://git.lab/uploads/-/system/user/avatar/115/avatar.png", "web_url": "https://git.lab/adbara10" }, - "git_cm:closed_by" : null, + "git_cm:closed_by" : { + "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:user_notes_count": 0, "git_cm:upvotes": 0, "git_cm:downvotes": 0, From 03bf00fa8b9f58bb91c53c33fca40444f1035c5e Mon Sep 17 00:00:00 2001 From: SBI- Date: Fri, 8 Jun 2018 14:06:33 +0200 Subject: [PATCH 60/62] Add tests for closed at and by data --- .../oslc/mapping/IssueMapperTest.java | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java index c42cefa..ff02f81 100644 --- a/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java +++ b/test/src/test/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapperTest.java @@ -171,13 +171,24 @@ public void checkUserNotesCount() { @Test public void checkClosedAt() { - Assert.assertEquals(null, oslcIssue.getGitCmClosedAt()); + Assert.assertEquals("2018-06-08T15:28:20.376+02:00", oslcIssue.getGitCmClosedAt()); } @Test public void checkClosedBy() { - Assert.assertFalse(oslcIssue.getOslcCmClosed()); - Assert.assertNull(oslcIssue.getGitCmClosedBy()); + Assert.assertTrue(oslcIssue.getOslcCmClosed()); + Assert.assertNotNull(oslcIssue.getGitCmClosedBy()); + + GitCmClosedBy expected = new GitCmClosedBy(); + expected.setId(150); + expected.setName("User 2"); + expected.setUsername("user.2"); + expected.setState("active"); + expected.setAvatarUrl(null); + expected.setWebUrl("https://git.lab/user.2"); + + Assert.assertTrue( + EqualsBuilder.reflectionEquals(expected, oslcIssue.getGitCmClosedBy())); } @Test @@ -214,8 +225,8 @@ public void checkStateMapping() { @Test public void checkCmClosedMapsToClosedAt() { - Assert.assertNull(oslcIssue.getGitCmClosedAt()); - Assert.assertFalse(oslcIssue.getOslcCmClosed()); + Assert.assertNotNull(oslcIssue.getGitCmClosedAt()); + Assert.assertTrue(oslcIssue.getOslcCmClosed()); } @Test @@ -228,13 +239,15 @@ public void checkUtcDateTimeMapping() { "2018-06-04T15:28:20.376+02:00", DateTimeFormatter.ISO_OFFSET_DATE_TIME); - created.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME); + ZonedDateTime closed = ZonedDateTime.parse( + "2018-06-08T15:28:20.376+02:00", + DateTimeFormatter.ISO_OFFSET_DATE_TIME); Assert.assertEquals(created.toString(), oslcIssue.getDctermsCreated()); Assert.assertEquals(created.toString(), oslcIssue.getGitCmCreatedAt()); Assert.assertEquals(modified.toString(), oslcIssue.getDctermsModified()); Assert.assertEquals(modified.toString(), oslcIssue.getGitCmUpdatedAt()); - Assert.assertEquals(null, oslcIssue.getGitCmClosedAt()); + Assert.assertEquals(closed.toString(), oslcIssue.getGitCmClosedAt()); } @Test @@ -285,8 +298,15 @@ public void makeIssue() throws MalformedURLException { " \"state\": \"opened\",\n" + " \"created_at\": \"2018-03-13T15:24:48.339+01:00\",\n" + " \"updated_at\": \"2018-06-04T15:28:20.376+02:00\",\n" + - " \"closed_at\": null,\n" + - " \"closed_by\": null,\n" + + " \"closed_at\": \"2018-06-08T15:28:20.376+02:00\",\n" + + " \"closed_by\": {\n" + + " \"id\": 150,\n" + + " \"name\": \"User 2\",\n" + + " \"username\": \"user.2\",\n" + + " \"state\": \"active\",\n" + + " \"avatar_url\": null,\n" + + " \"web_url\": \"https://git.lab/user.2\"\n" + + " },\n" + " \"labels\": [\n" + " \"Label1\",\n" + " \"Label2\"\n" + From 0cb6004711468fda1546ccd50d4d79e341713ec9 Mon Sep 17 00:00:00 2001 From: SBI- Date: Fri, 8 Jun 2018 14:12:15 +0200 Subject: [PATCH 61/62] Remove EE-only weight attribute --- .../GitConnectorService/oslc/mapping/IssueMapper.java | 3 --- plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json | 1 - 2 files changed, 4 deletions(-) diff --git a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java index b15ce0d..62193bb 100644 --- a/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java +++ b/plugin/src/main/java/org/jazzcommunity/GitConnectorService/oslc/mapping/IssueMapper.java @@ -93,7 +93,6 @@ protected void configure() { using(UserConverter.to(GitCmClosedBy.class)) .map(source.getClosedBy()) .setGitCmClosedBy(null); - // TODO: Add // Comment and vote statistics map().setGitCmUserNotesCount(source.getUserNotesCount()); map().setGitCmUpvotes(source.getUpvotes()); @@ -102,8 +101,6 @@ protected void configure() { map().setGitCmDueDate(source.getDueDate()); // Confidentiality map().setGitCmConfidential(source.getConfidential()); - // TODO: Add? - // Weight skipped, EE feature only. Not sure if we need this. // Discussion state map().setGitCmDiscussionLocked(source.getDiscussionLocked()); // Web url of issue in gitlab diff --git a/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json b/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json index a2f7c0e..45a818b 100644 --- a/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json +++ b/plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json @@ -85,7 +85,6 @@ "git_cm:downvotes": 0, "git_cm:due_date": null, "git_cm:confidential": false, - "git_cm:weight": null, "git_cm:discussion_locked": null, "git_cm:web_url": "https://git.lab/sisuite/sisuite-infrastructure-as-code/issues/42", "git_cm:time_stats": { From 760aa860de5c036741c3e195cb074171b88c88b7 Mon Sep 17 00:00:00 2001 From: SBI- Date: Fri, 8 Jun 2018 14:30:59 +0200 Subject: [PATCH 62/62] Bump minor version introducing new issue link --- feature/feature.xml | 2 +- feature/pom.xml | 2 +- plugin/META-INF/MANIFEST.MF | 2 +- plugin/pom.xml | 2 +- pom.xml | 2 +- test/META-INF/MANIFEST.MF | 4 ++-- test/pom.xml | 4 ++-- update-site/pom.xml | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/feature/feature.xml b/feature/feature.xml index 989095e..6e77d69 100644 --- a/feature/feature.xml +++ b/feature/feature.xml @@ -2,7 +2,7 @@ diff --git a/feature/pom.xml b/feature/pom.xml index 57fdc2c..ff0d6d4 100644 --- a/feature/pom.xml +++ b/feature/pom.xml @@ -7,7 +7,7 @@ org.jazzcommunity.GitConnectorService org.jazzcommunity.GitConnectorService.parent - 1.0.0-SNAPSHOT + 1.1.0-SNAPSHOT ../ diff --git a/plugin/META-INF/MANIFEST.MF b/plugin/META-INF/MANIFEST.MF index 2b47026..fbe80a0 100644 --- a/plugin/META-INF/MANIFEST.MF +++ b/plugin/META-INF/MANIFEST.MF @@ -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.0.0.qualifier +Bundle-Version: 1.1.0.qualifier Bundle-Vendor: VENDOR Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Require-Bundle: diff --git a/plugin/pom.xml b/plugin/pom.xml index 4e41eb8..231c42d 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -7,7 +7,7 @@ org.jazzcommunity.GitConnectorService org.jazzcommunity.GitConnectorService.parent - 1.0.0-SNAPSHOT + 1.1.0-SNAPSHOT ../ diff --git a/pom.xml b/pom.xml index f40a57e..03a02cd 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.jazzcommunity.GitConnectorService org.jazzcommunity.GitConnectorService.parent - 1.0.0-SNAPSHOT + 1.1.0-SNAPSHOT pom diff --git a/test/META-INF/MANIFEST.MF b/test/META-INF/MANIFEST.MF index 5735644..1a06c03 100644 --- a/test/META-INF/MANIFEST.MF +++ b/test/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: org.jazzcommunity.GitConnectorService Bundle-SymbolicName: org.jazzcommunity.GitConnectorService.test;singleton:=true -Bundle-Version: 1.0.0.qualifier +Bundle-Version: 1.1.0.qualifier Bundle-Vendor: VENDOR Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Bundle-ClassPath: target/dependency/junit-4.12.jar, @@ -10,7 +10,7 @@ Bundle-ClassPath: target/dependency/junit-4.12.jar, target/dependency/gson-2.8.2.jar, target/dependency/com.siemens.bt.jazz.services.base-2.0.1-SNAPSHOT.jar, target/dependency/com.siemens.bt.jazz.services.PersonalTokenService-1.0.2-SNAPSHOT.jar, - target/dependency/org.jazzcommunity.GitConnectorService-1.0.0-SNAPSHOT.jar, + target/dependency/org.jazzcommunity.GitConnectorService-1.1.0-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, diff --git a/test/pom.xml b/test/pom.xml index 9e9b9fc..ba6aeba 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -7,7 +7,7 @@ org.jazzcommunity.GitConnectorService org.jazzcommunity.GitConnectorService.parent - 1.0.0-SNAPSHOT + 1.1.0-SNAPSHOT ../ @@ -21,7 +21,7 @@ org.jazzcommunity.GitConnectorService org.jazzcommunity.GitConnectorService - 1.0.0-SNAPSHOT + 1.1.0-SNAPSHOT diff --git a/update-site/pom.xml b/update-site/pom.xml index abdbb5d..7cfd2c4 100644 --- a/update-site/pom.xml +++ b/update-site/pom.xml @@ -7,7 +7,7 @@ org.jazzcommunity.GitConnectorService org.jazzcommunity.GitConnectorService.parent - 1.0.0-SNAPSHOT + 1.1.0-SNAPSHOT ../