|
1 | 1 | package org.azd.work; |
2 | 2 |
|
| 3 | +import com.fasterxml.jackson.core.type.TypeReference; |
3 | 4 | import org.azd.common.ApiVersion; |
4 | 5 | import org.azd.connection.Connection; |
| 6 | +import org.azd.enums.CustomHeader; |
5 | 7 | import org.azd.enums.IterationsTimeFrame; |
6 | 8 | import org.azd.enums.RequestMethod; |
7 | 9 | import org.azd.exceptions.AzDException; |
8 | 10 | import org.azd.helpers.JsonMapper; |
9 | 11 | import org.azd.interfaces.WorkDetails; |
10 | 12 | import org.azd.utils.AzDAsyncApi; |
11 | | -import org.azd.work.types.IterationWorkItems; |
12 | | -import org.azd.work.types.TeamSettingsIteration; |
13 | | -import org.azd.work.types.TeamSettingsIterations; |
| 13 | +import org.azd.work.types.*; |
14 | 14 |
|
15 | 15 | import java.util.HashMap; |
| 16 | +import java.util.List; |
16 | 17 | import java.util.Map; |
17 | 18 |
|
18 | 19 | import static org.azd.helpers.URLHelper.encodeSpace; |
| 20 | +import static org.azd.helpers.URLHelper.encodeSpecialWithSpace; |
19 | 21 | import static org.azd.utils.RestClient.send; |
20 | 22 |
|
21 | 23 | /*** |
@@ -126,4 +128,83 @@ public Void deleteTeamSettingsIteration(String teamName, String iterationId) thr |
126 | 128 | return null; |
127 | 129 | } |
128 | 130 |
|
| 131 | + /** |
| 132 | + * Get a team's capacity including total capacity and days off |
| 133 | + * @param iterationId Pass the iteration id. |
| 134 | + * @param teamName The name of the Azure DevOps organization. |
| 135 | + * @return TeamCapacity Object {@link TeamCapacity} |
| 136 | + * @throws AzDException Default Api Exception handler. |
| 137 | + **/ |
| 138 | + @Override |
| 139 | + public TeamCapacity getTotalTeamCapacity(String iterationId, String teamName) throws AzDException { |
| 140 | + String r = send(RequestMethod.GET, CONNECTION, WORK, |
| 141 | + (CONNECTION.getProject() + "/" + encodeSpecialWithSpace(teamName)), |
| 142 | + AREA + "/teamsettings/iterations", iterationId, "capacities", ApiVersion.WORK_CAPACITY, |
| 143 | + null, null, null); |
| 144 | + |
| 145 | + return MAPPER.mapJsonResponse(r, TeamCapacity.class); |
| 146 | + } |
| 147 | + |
| 148 | + /** |
| 149 | + * Get a team member's capacity |
| 150 | + * @param iterationId Pass the team iteration id. |
| 151 | + * @param teamMemberId Id of the team member. |
| 152 | + * @param teamName Name of Azure DevOps team. |
| 153 | + * @return TeamMemberCapacityIdentityRef Object {@link TeamMemberCapacityIdentityRef} |
| 154 | + * @throws AzDException Default Api Exception handler. |
| 155 | + **/ |
| 156 | + @Override |
| 157 | + public TeamMemberCapacityIdentityRef getTeamMemberCapacity(String iterationId, String teamName, |
| 158 | + String teamMemberId) throws AzDException { |
| 159 | + String r = send(RequestMethod.GET, CONNECTION, WORK, |
| 160 | + (CONNECTION.getProject() + "/" + encodeSpecialWithSpace(teamName)), |
| 161 | + AREA + "/teamsettings/iterations", iterationId, "capacities/" + teamMemberId, ApiVersion.WORK_CAPACITY, |
| 162 | + null, null, null); |
| 163 | + |
| 164 | + return MAPPER.mapJsonResponse(r, TeamMemberCapacityIdentityRef.class); |
| 165 | + } |
| 166 | + |
| 167 | + /** |
| 168 | + * Replace a team's capacity |
| 169 | + * @param iterationId Pass the team iteration id. |
| 170 | + * @param teamName Name or id of the Azure DevOps team. |
| 171 | + * @param teamMembersCapacity A list of team members capacity to update. |
| 172 | + * @return TeamMemberCapacityIdentityRef Object {@link TeamMemberCapacityIdentityRef} |
| 173 | + * @throws AzDException Default Api Exception handler. |
| 174 | + **/ |
| 175 | + @Override |
| 176 | + public List<TeamMemberCapacityIdentityRef> updateTeamMembersCapacity(String iterationId, String teamName, |
| 177 | + List<TeamMemberCapacityIdentityRef> teamMembersCapacity) throws AzDException { |
| 178 | + String r = send(RequestMethod.PUT, CONNECTION, WORK, |
| 179 | + (CONNECTION.getProject() + "/" + encodeSpecialWithSpace(teamName)), |
| 180 | + AREA + "/teamsettings/iterations", iterationId, "capacities", ApiVersion.WORK_CAPACITY, |
| 181 | + null, teamMembersCapacity, CustomHeader.JSON_CONTENT_TYPE); |
| 182 | + return MAPPER.mapJsonResponse(r, new TypeReference<List<TeamMemberCapacityIdentityRef>>() {}); |
| 183 | + } |
| 184 | + |
| 185 | + /** |
| 186 | + * Update a team member's capacity |
| 187 | + * |
| 188 | + * @param iterationId Pass the team iteration id. |
| 189 | + * @param teamMemberId Id of the team member. |
| 190 | + * @param teamName Name of id of the Azure DevOps team. |
| 191 | + * @param teamMemberCapacity Team member capacity object to update. You can only pass the list of activities and optionally days off. |
| 192 | + * @return TeamMemberCapacityIdentityRef Object {@link TeamMemberCapacityIdentityRef} |
| 193 | + * @throws AzDException Default Api Exception handler. |
| 194 | + **/ |
| 195 | + @Override |
| 196 | + public TeamMemberCapacityIdentityRef updateTeamMemberCapacity(String iterationId, String teamName, String teamMemberId, |
| 197 | + TeamMemberCapacityIdentityRef teamMemberCapacity) throws AzDException { |
| 198 | + var body = new HashMap<String, Object>(){{ |
| 199 | + put("activities", teamMemberCapacity.getActivities()); |
| 200 | + put("daysOff", teamMemberCapacity.getDaysOff()); |
| 201 | + }}; |
| 202 | + |
| 203 | + String r = send(RequestMethod.PATCH, CONNECTION, WORK, |
| 204 | + (CONNECTION.getProject() + "/" + encodeSpecialWithSpace(teamName)), |
| 205 | + AREA + "/teamsettings/iterations", iterationId, "capacities/" + teamMemberId, ApiVersion.WORK_CAPACITY, |
| 206 | + null, body, CustomHeader.JSON_CONTENT_TYPE); |
| 207 | + return MAPPER.mapJsonResponse(r, TeamMemberCapacityIdentityRef.class); |
| 208 | + } |
| 209 | + |
129 | 210 | } |
0 commit comments