Skip to content

Commit 1112388

Browse files
author
Caitlin Bales (MSFT)
committed
Planner External References
1 parent d8a2a61 commit 1112388

File tree

2 files changed

+92
-20
lines changed

2 files changed

+92
-20
lines changed

src/main/java/com/microsoft/graph/models/extensions/PlannerExternalReferences.java

Lines changed: 80 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,93 @@
44

55
package com.microsoft.graph.models.extensions;
66

7-
import com.microsoft.graph.concurrency.*;
8-
import com.microsoft.graph.core.*;
9-
import com.microsoft.graph.models.extensions.*;
7+
import com.google.gson.JsonElement;
108
import com.microsoft.graph.models.generated.*;
11-
import com.microsoft.graph.http.*;
12-
import com.microsoft.graph.requests.extensions.*;
13-
import com.microsoft.graph.requests.generated.*;
14-
import com.microsoft.graph.options.*;
159
import com.microsoft.graph.serializer.*;
1610

17-
import java.util.Arrays;
18-
import java.util.EnumSet;
19-
11+
import java.security.InvalidParameterException;
2012
// This file is available for extending, afterwards please submit a pull request.
2113

2214
/**
2315
* The class for the Planner External References.
2416
*/
2517
public class PlannerExternalReferences extends BasePlannerExternalReferences {
26-
18+
/*
19+
* Specifies the character - encoding pairs to apply on the external reference URLs
20+
*/
21+
private static String[][] conversions = { { "%", "%25" }, { "@", "%40" }, { ".", "%2E" }, { ":", "%3A" } };
22+
23+
/**
24+
* Gets external reference data for a given reference URL
25+
* @param url The external reference URL
26+
* @return The external reference
27+
*/
28+
public PlannerExternalReference reference(String url) {
29+
if (url == null || url.isEmpty()) {
30+
throw new InvalidParameterException("URL cannot be empty");
31+
}
32+
if (this.additionalDataManager().containsKey(encode(url))) {
33+
JsonElement refObject = this.additionalDataManager().get(encode(url));
34+
ISerializer serializer = this.getSerializer();
35+
return serializer.deserializeObject(
36+
refObject.getAsString(),
37+
PlannerExternalReference.class
38+
);
39+
} else {
40+
return null;
41+
}
42+
}
43+
44+
/**
45+
* Adds a new external reference with the given URL and short name
46+
* @param url URL of the external reference
47+
* @param alias Short name for the external reference
48+
* @return The created external reference
49+
*/
50+
public PlannerExternalReference addReference(String url, String alias) {
51+
if (url == null || url.isEmpty()) {
52+
throw new InvalidParameterException("URL cannot be empty");
53+
}
54+
if (alias == null || alias.isEmpty()) {
55+
throw new InvalidParameterException("Alias cannot be empty");
56+
}
57+
58+
PlannerExternalReference plannerExternalReference = new PlannerExternalReference();
59+
plannerExternalReference.alias = alias;
60+
this.additionalDataManager().put(encode(url), plannerExternalReference.getRawObject());
61+
return plannerExternalReference;
62+
}
63+
64+
/**
65+
* Encodes the URL of an external reference to be compatible with OData property naming requirements
66+
* @param externalReferenceUrl URL to encode
67+
* @return Encoded URL
68+
*/
69+
private static String encode(String externalReferenceUrl) {
70+
if (externalReferenceUrl == null || externalReferenceUrl.isEmpty()) {
71+
throw new InvalidParameterException("URL cannot be empty");
72+
}
73+
74+
for (int i = 0; i < conversions.length; i++)
75+
{
76+
externalReferenceUrl = externalReferenceUrl.replace(conversions[i][0], conversions[i][1]);
77+
}
78+
return externalReferenceUrl;
79+
}
80+
81+
/**
82+
* Decodes an encoded URL of an external reference
83+
* @param externalReferenceUrl URL to encode
84+
* @return Decoded URL
85+
*/
86+
private static String decode(String externalReferenceUrl) {
87+
if (externalReferenceUrl == null || externalReferenceUrl.isEmpty()) {
88+
throw new InvalidParameterException("URL cannot be empty");
89+
}
90+
91+
for (int i = conversions.length - 1; i >= 0; i--) {
92+
externalReferenceUrl = externalReferenceUrl.replace(conversions[i][1], conversions[i][0]);
93+
}
94+
return externalReferenceUrl;
95+
}
2796
}

src/test/java/com/microsoft/graph/functional/PlannerTests.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.microsoft.graph.requests.extensions.IPlannerTaskRequest;
1313
import com.microsoft.graph.models.extensions.PlannerAssignedToTaskBoardTaskFormat;
1414
import com.microsoft.graph.models.extensions.PlannerAssignment;
15+
import com.microsoft.graph.models.extensions.PlannerAssignments;
1516
import com.microsoft.graph.models.extensions.PlannerBucket;
1617
import com.microsoft.graph.models.extensions.PlannerBucketTaskBoardTaskFormat;
1718
import com.microsoft.graph.models.extensions.PlannerCategoryDescriptions;
@@ -33,7 +34,7 @@
3334
import java.util.Calendar;
3435
import java.util.UUID;
3536

36-
@Ignore
37+
//@Ignore
3738
public class PlannerTests {
3839
private TestBase testBase;
3940
// For now, you must specify a specific plan ID since the test cannot
@@ -104,17 +105,19 @@ public void testUpdateTask() throws InterruptedException {
104105

105106
PlannerAssignment assignment = new PlannerAssignment();
106107
assignment.orderHint = " !";
108+
AdditionalDataManager assignmentAdditionalData = assignment.additionalDataManager();
109+
assignmentAdditionalData.put("@odata.Type", new JsonPrimitive("#microsoft.graph.plannerAssignment"));
107110
assignment.oDataType = "#microsoft.graph.plannerAssignment";
108-
assignment.additionalDataManager().put("@odata.type", new JsonPrimitive("#microsoft.graph.plannerAssignment"));
109111

110-
AdditionalDataManager dataManager = task.additionalDataManager();
111-
task.oDataType = "#microsoft.graph.plannerTask";
112+
PlannerAssignments a2 = new PlannerAssignments();
113+
a2.put(me.id, assignment);
114+
task.assignments = a2;
112115

113-
JsonObject assignments = new JsonObject();
114-
Gson gson = new Gson();
115-
JsonElement assignmentJson = gson.toJsonTree(assignment);
116-
assignments.add(me.id, assignmentJson);
117-
dataManager.put("assignments", assignments);
116+
// JsonObject assignments = new JsonObject();
117+
// Gson gson = new Gson();
118+
// JsonElement assignmentJson = gson.toJsonTree(assignment);
119+
// assignments.add(me.id, assignmentJson);
120+
// dataManager.put("assignments", assignments);
118121

119122
IPlannerTaskRequest req = testBase.graphClient.planner().tasks(planTask.id).buildRequest();
120123
req.addHeader("If-Match", getEtag(planTask.getRawObject()));

0 commit comments

Comments
 (0)