Skip to content

Commit 01a5a17

Browse files
author
Shailesh Jagannath Padave
committed
Added new client
1 parent 9c6fdb5 commit 01a5a17

2 files changed

Lines changed: 281 additions & 0 deletions

File tree

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*
2+
* Copyright 2020 Conductor Authors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
* <p>
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* <p>
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package com.netflix.conductor.client.http;
14+
15+
import java.util.List;
16+
17+
import org.apache.commons.lang3.Validate;
18+
19+
import com.netflix.conductor.client.http.ConductorClientRequest.Method;
20+
import com.netflix.conductor.common.metadata.workflow.SharedResourceModel;
21+
22+
import com.fasterxml.jackson.core.type.TypeReference;
23+
24+
/**
25+
* Client for resource sharing operations in Conductor
26+
*/
27+
public final class ResourceSharingClient {
28+
29+
private ConductorClient client;
30+
31+
/** Creates a default resource sharing client */
32+
public ResourceSharingClient() {
33+
}
34+
35+
public ResourceSharingClient(ConductorClient client) {
36+
this.client = client;
37+
}
38+
39+
/**
40+
* Kept only for backwards compatibility
41+
*
42+
* @param rootUri basePath for the ApiClient
43+
*/
44+
@Deprecated
45+
public void setRootURI(String rootUri) {
46+
if (client != null) {
47+
client.shutdown();
48+
}
49+
client = new ConductorClient(rootUri);
50+
}
51+
52+
/**
53+
* Share a resource with another user or group
54+
*
55+
* @param resourceType Type of resource to share (e.g., "WORKFLOW", "TASK")
56+
* @param resourceName Name of the resource to share
57+
* @param sharedWith User or group to share the resource with
58+
*/
59+
public void shareResource(String resourceType, String resourceName, String sharedWith) {
60+
Validate.notBlank(resourceType, "ResourceType cannot be blank");
61+
Validate.notBlank(resourceName, "ResourceName cannot be blank");
62+
Validate.notBlank(sharedWith, "SharedWith cannot be blank");
63+
64+
ConductorClientRequest request = ConductorClientRequest.builder()
65+
.method(Method.POST)
66+
.path("/share/shareResource")
67+
.addQueryParam("resourceType", resourceType)
68+
.addQueryParam("resourceName", resourceName)
69+
.addQueryParam("sharedWith", sharedWith)
70+
.build();
71+
72+
client.execute(request);
73+
}
74+
75+
/**
76+
* Remove sharing of a resource with a user or group
77+
*
78+
* @param resourceType Type of resource to unshare
79+
* @param resourceName Name of the resource to unshare
80+
* @param sharedWith User or group to remove sharing from
81+
*/
82+
public void removeSharingResource(String resourceType, String resourceName, String sharedWith) {
83+
Validate.notBlank(resourceType, "ResourceType cannot be blank");
84+
Validate.notBlank(resourceName, "ResourceName cannot be blank");
85+
Validate.notBlank(sharedWith, "SharedWith cannot be blank");
86+
87+
ConductorClientRequest request = ConductorClientRequest.builder()
88+
.method(Method.DELETE)
89+
.path("/share/removeSharingResource")
90+
.addQueryParam("resourceType", resourceType)
91+
.addQueryParam("resourceName", resourceName)
92+
.addQueryParam("sharedWith", sharedWith)
93+
.build();
94+
95+
client.execute(request);
96+
}
97+
98+
/**
99+
* Get all shared resources accessible to the current user
100+
*
101+
* @return List of shared resources
102+
*/
103+
public List<SharedResourceModel> getSharedResources() {
104+
ConductorClientRequest request = ConductorClientRequest.builder()
105+
.method(Method.GET)
106+
.path("/share/getSharedResources")
107+
.build();
108+
109+
ConductorClientResponse<List<SharedResourceModel>> resp = client.execute(request, new TypeReference<>() {
110+
});
111+
112+
return resp.getData();
113+
}
114+
115+
/**
116+
* Get shared resources filtered by resource type
117+
*
118+
* @param resourceType Type of resource to filter by
119+
* @return List of shared resources of the specified type
120+
*/
121+
public List<SharedResourceModel> getSharedResources(String resourceType) {
122+
Validate.notBlank(resourceType, "ResourceType cannot be blank");
123+
124+
ConductorClientRequest request = ConductorClientRequest.builder()
125+
.method(Method.GET)
126+
.path("/share/getSharedResources")
127+
.addQueryParam("resourceType", resourceType)
128+
.build();
129+
130+
ConductorClientResponse<List<SharedResourceModel>> resp = client.execute(request, new TypeReference<>() {
131+
});
132+
133+
return resp.getData();
134+
}
135+
136+
/**
137+
* Check if a specific resource is shared with a user or group
138+
*
139+
* @param resourceType Type of resource
140+
* @param resourceName Name of the resource
141+
* @param sharedWith User or group to check
142+
* @return true if the resource is shared, false otherwise
143+
*/
144+
public boolean isResourceShared(String resourceType, String resourceName, String sharedWith) {
145+
List<SharedResourceModel> sharedResources = getSharedResources(resourceType);
146+
return sharedResources.stream()
147+
.anyMatch(resource ->
148+
resource.getResourceName().equals(resourceName) &&
149+
resource.getSharedWith().equals(sharedWith));
150+
}
151+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* Copyright 2020 Conductor Authors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
* <p>
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* <p>
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package com.netflix.conductor.common.metadata.workflow;
14+
15+
import com.fasterxml.jackson.annotation.JsonProperty;
16+
17+
import java.util.Objects;
18+
19+
/**
20+
* Model representing a shared resource between users/groups
21+
*/
22+
public class SharedResourceModel {
23+
24+
@JsonProperty("resourceType")
25+
private String resourceType;
26+
27+
@JsonProperty("resourceName")
28+
private String resourceName;
29+
30+
@JsonProperty("sharedWith")
31+
private String sharedWith;
32+
33+
@JsonProperty("owner")
34+
private String owner;
35+
36+
@JsonProperty("sharedAt")
37+
private Long sharedAt;
38+
39+
public SharedResourceModel() {
40+
}
41+
42+
public SharedResourceModel(String resourceType, String resourceName, String sharedWith) {
43+
this.resourceType = resourceType;
44+
this.resourceName = resourceName;
45+
this.sharedWith = sharedWith;
46+
}
47+
48+
/**
49+
* @return The type of resource being shared (e.g., "WORKFLOW", "TASK")
50+
*/
51+
public String getResourceType() {
52+
return resourceType;
53+
}
54+
55+
public void setResourceType(String resourceType) {
56+
this.resourceType = resourceType;
57+
}
58+
59+
/**
60+
* @return The name of the resource being shared
61+
*/
62+
public String getResourceName() {
63+
return resourceName;
64+
}
65+
66+
public void setResourceName(String resourceName) {
67+
this.resourceName = resourceName;
68+
}
69+
70+
/**
71+
* @return The user/group the resource is shared with
72+
*/
73+
public String getSharedWith() {
74+
return sharedWith;
75+
}
76+
77+
public void setSharedWith(String sharedWith) {
78+
this.sharedWith = sharedWith;
79+
}
80+
81+
/**
82+
* @return The owner of the resource
83+
*/
84+
public String getOwner() {
85+
return owner;
86+
}
87+
88+
public void setOwner(String owner) {
89+
this.owner = owner;
90+
}
91+
92+
/**
93+
* @return Timestamp when the resource was shared
94+
*/
95+
public Long getSharedAt() {
96+
return sharedAt;
97+
}
98+
99+
public void setSharedAt(Long sharedAt) {
100+
this.sharedAt = sharedAt;
101+
}
102+
103+
@Override
104+
public boolean equals(Object o) {
105+
if (this == o) return true;
106+
if (o == null || getClass() != o.getClass()) return false;
107+
SharedResourceModel that = (SharedResourceModel) o;
108+
return Objects.equals(resourceType, that.resourceType) &&
109+
Objects.equals(resourceName, that.resourceName) &&
110+
Objects.equals(sharedWith, that.sharedWith) &&
111+
Objects.equals(owner, that.owner) &&
112+
Objects.equals(sharedAt, that.sharedAt);
113+
}
114+
115+
@Override
116+
public int hashCode() {
117+
return Objects.hash(resourceType, resourceName, sharedWith, owner, sharedAt);
118+
}
119+
120+
@Override
121+
public String toString() {
122+
return "SharedResourceModel{" +
123+
"resourceType='" + resourceType + '\'' +
124+
", resourceName='" + resourceName + '\'' +
125+
", sharedWith='" + sharedWith + '\'' +
126+
", owner='" + owner + '\'' +
127+
", sharedAt=" + sharedAt +
128+
'}';
129+
}
130+
}

0 commit comments

Comments
 (0)