-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EPMRPP-94816 || Implement functionality to add Assignee for issue by …
…typing its name
- Loading branch information
1 parent
e2f46f7
commit 8d88760
Showing
9 changed files
with
283 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/com/epam/reportportal/extension/jira/command/UserSearchCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2024 EPAM Systems | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.epam.reportportal.extension.jira.command; | ||
|
||
import static java.util.Optional.ofNullable; | ||
|
||
import com.atlassian.jira.rest.client.api.domain.User; | ||
import com.epam.reportportal.extension.ProjectMemberCommand; | ||
import com.epam.reportportal.extension.jira.command.atlassian.AsynchronousUserRestClientExtended; | ||
import com.epam.reportportal.extension.jira.command.utils.CloudJiraClientProvider; | ||
import com.epam.reportportal.extension.jira.dto.UserDto; | ||
import com.epam.reportportal.extension.jira.utils.UserMapper; | ||
import com.epam.ta.reportportal.dao.ProjectRepository; | ||
import com.epam.ta.reportportal.entity.integration.Integration; | ||
import com.epam.ta.reportportal.entity.integration.IntegrationParams; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Andrei Piankouski</a> | ||
*/ | ||
public class UserSearchCommand extends ProjectMemberCommand<List<UserDto>> { | ||
|
||
private static final String SEARCH_TERM = "term"; | ||
private final CloudJiraClientProvider cloudJiraClientProvider; | ||
|
||
public UserSearchCommand(ProjectRepository projectRepository, | ||
CloudJiraClientProvider cloudJiraClientProvider) { | ||
super(projectRepository); | ||
this.cloudJiraClientProvider = cloudJiraClientProvider; | ||
} | ||
|
||
@Override | ||
protected List<UserDto> invokeCommand(Integration integration, Map<String, Object> params) { | ||
IntegrationParams integrationParams = integration.getParams(); | ||
String query = (String) ofNullable(params.get(SEARCH_TERM)).orElse(""); | ||
AsynchronousUserRestClientExtended userClient; | ||
userClient = cloudJiraClientProvider.createUserClient(integrationParams); | ||
Iterable<User> users = userClient.findUsers(query).claim(); | ||
return UserMapper.toUserDtoList(users); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "searchUsers"; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...pam/reportportal/extension/jira/command/atlassian/AsynchronousUserRestClientExtended.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright 2024 EPAM Systems | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.epam.reportportal.extension.jira.command.atlassian; | ||
|
||
import com.atlassian.httpclient.api.HttpClient; | ||
import com.atlassian.jira.rest.client.api.domain.User; | ||
import com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient; | ||
import com.atlassian.jira.rest.client.internal.json.UsersJsonParser; | ||
import io.atlassian.util.concurrent.Promise; | ||
import java.net.URI; | ||
import javax.annotation.Nullable; | ||
import javax.ws.rs.core.UriBuilder; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Andrei Piankouski</a> | ||
*/ | ||
public class AsynchronousUserRestClientExtended extends AbstractAsynchronousRestClient { | ||
|
||
private static final String USER_URI_PREFIX = "user"; | ||
private static final String SEARCH_URI_PREFIX = "search"; | ||
|
||
private static final String QUERY_ATTRIBUTE = "query"; | ||
private static final String START_AT_ATTRIBUTE = "startAt"; | ||
private static final String MAX_RESULTS_ATTRIBUTE = "maxResults"; | ||
private static final String INCLUDE_ACTIVE_ATTRIBUTE = "includeActive"; | ||
private static final String INCLUDE_INACTIVE_ATTRIBUTE = "includeInactive"; | ||
|
||
private final UsersJsonParser usersJsonParser = new UsersJsonParser(); | ||
|
||
private final URI baseUri; | ||
|
||
public AsynchronousUserRestClientExtended(URI serverUri, | ||
HttpClient client) { | ||
super(client); | ||
this.baseUri = UriBuilder.fromUri(serverUri).path("/rest/api/latest").build(); | ||
} | ||
|
||
public Promise<Iterable<User>> findUsers(String username) { | ||
return findUsers(username, null, null, null, null); | ||
} | ||
|
||
public Promise<Iterable<User>> findUsers(String username, @Nullable Integer startAt, | ||
@Nullable Integer maxResults, @Nullable Boolean includeActive, | ||
@Nullable Boolean includeInactive) { | ||
UriBuilder uriBuilder = UriBuilder.fromUri(baseUri).path(USER_URI_PREFIX).path(SEARCH_URI_PREFIX) | ||
.queryParam(QUERY_ATTRIBUTE, username); | ||
|
||
addOptionalQueryParam(uriBuilder, START_AT_ATTRIBUTE, startAt); | ||
addOptionalQueryParam(uriBuilder, MAX_RESULTS_ATTRIBUTE, maxResults); | ||
addOptionalQueryParam(uriBuilder, INCLUDE_ACTIVE_ATTRIBUTE, includeActive); | ||
addOptionalQueryParam(uriBuilder, INCLUDE_INACTIVE_ATTRIBUTE, includeInactive); | ||
addOptionalQueryParam(uriBuilder, INCLUDE_INACTIVE_ATTRIBUTE, includeInactive); | ||
addOptionalQueryParam(uriBuilder, INCLUDE_INACTIVE_ATTRIBUTE, includeInactive); | ||
|
||
final URI usersUri = uriBuilder.build(); | ||
return getAndParse(usersUri, usersJsonParser); | ||
} | ||
|
||
private void addOptionalQueryParam(final UriBuilder uriBuilder, final String key, final Object value) { | ||
if (value != null) { | ||
uriBuilder.queryParam(key, value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/com/epam/reportportal/extension/jira/dto/UserDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2024 EPAM Systems | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.epam.reportportal.extension.jira.dto; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Andrei Piankouski</a> | ||
*/ | ||
public class UserDto { | ||
|
||
private String id; | ||
private String name; | ||
|
||
public UserDto() { | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/epam/reportportal/extension/jira/utils/UserMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2024 EPAM Systems | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.epam.reportportal.extension.jira.utils; | ||
|
||
import com.atlassian.jira.rest.client.api.domain.User; | ||
import com.epam.reportportal.extension.jira.dto.UserDto; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.StreamSupport; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Andrei Piankouski</a> | ||
*/ | ||
public class UserMapper { | ||
|
||
public static List<UserDto> toUserDtoList(Iterable<User> users) { | ||
return StreamSupport.stream(users.spliterator(), false) | ||
.map(user -> { | ||
UserDto dto = new UserDto(); | ||
dto.setId(user.getAccountId()); | ||
dto.setName(user.getDisplayName()); | ||
return dto; | ||
}) | ||
.collect(Collectors.toList()); | ||
} | ||
} |