Skip to content

Commit 85e2751

Browse files
authored
feat(gql) allow unsetting optional incident fields (#12801)
1 parent 7e749ff commit 85e2751

File tree

3 files changed

+15
-31
lines changed

3 files changed

+15
-31
lines changed

datahub-graphql-core/src/main/java/com/linkedin/datahub/graphql/resolvers/incident/IncidentUtils.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.linkedin.common.AuditStamp;
77
import com.linkedin.common.urn.Urn;
88
import com.linkedin.common.urn.UrnUtils;
9+
import com.linkedin.data.template.SetMode;
910
import com.linkedin.datahub.graphql.QueryContext;
1011
import com.linkedin.datahub.graphql.authorization.AuthorizationUtils;
1112
import com.linkedin.datahub.graphql.generated.IncidentPriority;
@@ -92,12 +93,13 @@ public static IncidentStatus mapIncidentStatus(
9293

9394
IncidentStatus status = new IncidentStatus();
9495
status.setState(IncidentState.valueOf(input.getState().toString()));
95-
if (input.getStage() != null) {
96-
status.setStage(IncidentStage.valueOf(input.getStage().toString()));
97-
}
96+
status.setStage(
97+
input.getStage() == null ? null : IncidentStage.valueOf(input.getStage().toString()),
98+
SetMode.REMOVE_IF_NULL);
9899
if (input.getMessage() != null) {
99100
status.setMessage(input.getMessage());
100101
}
102+
status.setLastUpdated(auditStamp);
101103
return status;
102104
}
103105

datahub-graphql-core/src/main/java/com/linkedin/datahub/graphql/resolvers/incident/UpdateIncidentResolver.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.linkedin.common.UrnArray;
1313
import com.linkedin.common.urn.Urn;
1414
import com.linkedin.common.urn.UrnUtils;
15+
import com.linkedin.data.template.SetMode;
1516
import com.linkedin.datahub.graphql.QueryContext;
1617
import com.linkedin.datahub.graphql.authorization.AuthorizationUtils;
1718
import com.linkedin.datahub.graphql.exception.AuthorizationException;
@@ -116,18 +117,19 @@ private void updateIncidentInfo(
116117
if (input.getDescription() != null) {
117118
info.setDescription(input.getDescription());
118119
}
119-
if (input.getPriority() != null) {
120-
info.setPriority(IncidentUtils.mapIncidentPriority(input.getPriority()));
121-
}
122-
if (input.getAssigneeUrns() != null) {
123-
info.setAssignees(IncidentUtils.mapIncidentAssignees(input.getAssigneeUrns(), actorStamp));
124-
}
125120
if (input.getStatus() != null) {
126121
info.setStatus(IncidentUtils.mapIncidentStatus(input.getStatus(), actorStamp));
127122
}
128123
if (input.getResourceUrns() != null && !input.getResourceUrns().isEmpty()) {
129124
info.setEntities(new UrnArray(IncidentUtils.stringsToUrns(input.getResourceUrns())));
130125
}
126+
127+
info.setPriority(
128+
IncidentUtils.mapIncidentPriority(input.getPriority()), SetMode.REMOVE_IF_NULL);
129+
130+
info.setAssignees(
131+
IncidentUtils.mapIncidentAssignees(input.getAssigneeUrns(), actorStamp),
132+
SetMode.REMOVE_IF_NULL);
131133
}
132134

133135
private boolean isAuthorizedToUpdateIncident(final Urn resourceUrn, final QueryContext context) {

datahub-graphql-core/src/test/java/com/linkedin/datahub/graphql/resolvers/incident/UpdateIncidentResolverTest.java

+2-22
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,7 @@ public void testGetSuccessAllFields() throws Exception {
5353
existingInfo.setEntities(
5454
new UrnArray(ImmutableList.of(UrnUtils.getUrn("urn:li:dataset:(test,test,test)"))));
5555
existingInfo.setStatus(
56-
new IncidentStatus()
57-
.setState(IncidentState.ACTIVE)
58-
.setStage(IncidentStage.INVESTIGATION)
59-
.setMessage("Message"));
60-
existingInfo.setAssignees(
61-
new IncidentAssigneeArray(
62-
ImmutableList.of(
63-
new IncidentAssignee()
64-
.setActor(UrnUtils.getUrn("urn:li:corpuser:test"))
65-
.setAssignedAt(new AuditStamp()))));
66-
existingInfo.setPriority(0);
56+
new IncidentStatus().setState(IncidentState.ACTIVE).setMessage("Message"));
6757
existingInfo.setSource(new IncidentSource().setType(IncidentSourceType.MANUAL));
6858

6959
EntityService mockEntityService = Mockito.mock(EntityService.class);
@@ -198,17 +188,7 @@ public void testGetSuccessRequiredFields() throws Exception {
198188
expectedInfo.setEntities(
199189
new UrnArray(ImmutableList.of(UrnUtils.getUrn("urn:li:dataset:(test,test,test)"))));
200190
expectedInfo.setStatus(
201-
new IncidentStatus()
202-
.setState(IncidentState.ACTIVE)
203-
.setStage(IncidentStage.INVESTIGATION)
204-
.setMessage("Message"));
205-
expectedInfo.setAssignees(
206-
new IncidentAssigneeArray(
207-
ImmutableList.of(
208-
new IncidentAssignee()
209-
.setActor(UrnUtils.getUrn("urn:li:corpuser:test"))
210-
.setAssignedAt(new AuditStamp()))));
211-
expectedInfo.setPriority(0);
191+
new IncidentStatus().setState(IncidentState.ACTIVE).setMessage("Message"));
212192
expectedInfo.setSource(new IncidentSource().setType(IncidentSourceType.MANUAL));
213193

214194
// Verify entity client

0 commit comments

Comments
 (0)