Skip to content

Commit

Permalink
Merge pull request #11 from SBI-/master
Browse files Browse the repository at this point in the history
Unified assignee mapping for issues and merge requests
  • Loading branch information
SBI- committed Jul 4, 2018
2 parents 064a3f7 + 47e84b9 commit c0b2aa4
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 18 deletions.
2 changes: 1 addition & 1 deletion feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="org.jazzcommunity.GitConnectorService.feature"
label="REST Service"
version="1.6.1.qualifier"
version="1.6.2.qualifier"
provider-name="PROVIDER">

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jazzcommunity.GitConnectorService.oslc.mapping;

import ch.sbi.minigit.type.gitlab.issue.Assignee;
import ch.sbi.minigit.type.gitlab.issue.Issue;
import org.jazzcommunity.GitConnectorService.olsc.type.issue.*;
import org.jazzcommunity.GitConnectorService.oslc.type.ContributorPrototype;
Expand Down Expand Up @@ -41,6 +42,11 @@ public static OslcIssue map(Issue issue, URL self, String baseUrl) {
issue.getAuthor().getName(),
issue.getAuthor().getWebUrl());

// maybe write a converter for list types that checks empty
final Assignee assignee = issue.getAssignees().isEmpty() ?
null :
issue.getAssignees().get(0);

ModelMapper mapper = new ModelMapper();

mapper.addMappings(new PropertyMap<Issue, OslcIssue>() {
Expand Down Expand Up @@ -82,9 +88,10 @@ protected void configure() {
map().setGitCmId(source.getId());
map().setGitCmIid(source.getIid());
// Prefixes object
map().setPrefixes(TypeConverter.<PrefixPrototype, Prefixes>convert(
new PrefixPrototype(),
Prefixes.class));
map().setPrefixes(
TypeConverter.<PrefixPrototype, Prefixes>convert(
new PrefixPrototype(),
Prefixes.class));
// Short title
using(Converters.toShortTitle()).map(source.getIid()).setOslcShortTitle(null);
// Due Date
Expand All @@ -108,8 +115,13 @@ protected void configure() {
using(TypeConverter.to(GitCmMilestone.class))
.map(source.getMilestone())
.setGitCmMilestone(null);
// Assignee
map().setGitCmAssignee(
TypeConverter.<Assignee, GitCmAssignee>convert(
assignee,
GitCmAssignee.class));
// Assignees
Type assignees = new TypeToken<List<GitCmAssignee>>() {}.getType();
Type assignees = new TypeToken<List<GitCmAssignee_>>() {}.getType();
using(TypeConverter.to(assignees))
.map(source.getAssignees())
.setGitCmAssignees(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jazzcommunity.GitConnectorService.oslc.mapping;

import ch.sbi.minigit.type.gitlab.mergerequest.Assignee;
import ch.sbi.minigit.type.gitlab.mergerequest.MergeRequest;
import org.jazzcommunity.GitConnectorService.olsc.type.merge_request.*;
import org.jazzcommunity.GitConnectorService.oslc.type.ContributorPrototype;
Expand All @@ -9,6 +10,8 @@
import org.modelmapper.PropertyMap;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class MergeRequestMapper {
private MergeRequestMapper() {
Expand All @@ -22,6 +25,16 @@ public static OslcMergeRequest map(MergeRequest request, URL self, String baseUr
request.getAuthor().getName(),
request.getAuthor().getWebUrl());

final GitCmAssignee_ assignee = TypeConverter.<Assignee, GitCmAssignee_>convert(
request.getAssignee(),
GitCmAssignee_.class);

// make sure that assignee list is empty, if nobody has been assigned
final List<GitCmAssignee_> assignees = new ArrayList<>();
if (assignee != null) {
assignees.add(assignee);
}

ModelMapper mapper = new ModelMapper();

mapper.addMappings(new PropertyMap<MergeRequest, OslcMergeRequest>() {
Expand Down Expand Up @@ -61,8 +74,8 @@ protected void configure() {
map().setGitCmIid(source.getIid());
// Prefixes object
map().setPrefixes(TypeConverter.<PrefixPrototype, Prefixes>convert(
new PrefixPrototype(),
Prefixes.class));
new PrefixPrototype(),
Prefixes.class));
// Short title
using(Converters.toShortTitle()).map(source.getIid()).setOslcShortTitle(null);
// RTC time estimate and time spent
Expand Down Expand Up @@ -92,6 +105,8 @@ protected void configure() {
using(TypeConverter.to(GitCmAssignee.class))
.map(source.getAssignee())
.setGitCmAssignee(null);
// Assignees
map().setGitCmAssignees(assignees);
// Merged by
using(TypeConverter.to(GitCmMergedBy.class))
.map(source.getMergedBy())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ private TypeConverter() {
}

public static <From, To> To convert(final From from, final Type type) {
if (from == null) {
return null;
}

return new ModelMapper().map(from, type);
}

Expand Down
8 changes: 8 additions & 0 deletions plugin/src/main/resources/schemas/oslc/issue/OslcIssue.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@
"id" : 17,
"updated_at" : "2016-01-04T15:31:39.996Z"
},
"git_cm:assignee": {
"id": 150,
"name": "User Name",
"username": "username",
"state": "active",
"avatar_url": "url",
"web_url": "https://code.siemens.com/userurl"
},
"git_cm:assignees": [{
"id": 3537,
"name": "Bajohr Rayk adbara10",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,17 @@
"name": "User Name",
"username": "username",
"state": "active",
"avatar_url": null,
"avatar_url": "url",
"web_url": "https://code.siemens.com/userurl"
},
"git_cm:assignees": [{
"id": 3537,
"name": "Bajohr Rayk adbara10",
"username": "adbara10",
"state": "active",
"avatar_url": "https://git.lab/uploads/-/system/user/avatar/115/avatar.png",
"web_url": "https://git.lab/adbara10"
}],
"git_cm:author": {
"id": 3537,
"name": "Bajohr Rayk adbara10",
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.jazzcommunity.GitConnectorService</groupId>
<artifactId>org.jazzcommunity.GitConnectorService.parent</artifactId>
<version>1.6.1-SNAPSHOT</version>
<version>1.6.2-SNAPSHOT</version>
<packaging>pom</packaging>

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,29 @@ public void checkAssigneeMapping() {
expected.setAvatarUrl("https://repo.git.com/uploads/-/system/user/avatar/115/avatar.png");
expected.setWebUrl("https://git.lab/user.1");

GitCmAssignee assignee = oslcIssue.getGitCmAssignee();
Assert.assertTrue(
EqualsBuilder.reflectionEquals(expected, assignee));
}

@Test
public void checkAssigneesMapping() {
GitCmAssignee_ expected = new GitCmAssignee_();
expected.setId(115);
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");
expected.setWebUrl("https://git.lab/user.1");

// 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());
Assert.assertNotNull(oslcIssue.getGitCmAssignees().get(0));


GitCmAssignee assignee = oslcIssue.getGitCmAssignees().get(0);
GitCmAssignee_ assignee = oslcIssue.getGitCmAssignees().get(0);
Assert.assertTrue(
EqualsBuilder.reflectionEquals(expected, assignee));
}
Expand Down
2 changes: 1 addition & 1 deletion update-site/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.jazzcommunity.GitConnectorService</groupId>
<artifactId>org.jazzcommunity.GitConnectorService.parent</artifactId>
<version>1.6.1-SNAPSHOT</version>
<version>1.6.2-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down

0 comments on commit c0b2aa4

Please sign in to comment.