|
| 1 | +package com.auth0.client.mgmt; |
| 2 | + |
| 3 | +import com.auth0.client.mgmt.filter.UserAttributeProfilesFilter; |
| 4 | +import com.auth0.json.mgmt.userAttributeProfiles.*; |
| 5 | +import com.auth0.net.BaseRequest; |
| 6 | +import com.auth0.net.Request; |
| 7 | +import com.auth0.net.VoidRequest; |
| 8 | +import com.auth0.net.client.Auth0HttpClient; |
| 9 | +import com.auth0.net.client.HttpMethod; |
| 10 | +import com.auth0.utils.Asserts; |
| 11 | +import com.fasterxml.jackson.core.type.TypeReference; |
| 12 | +import okhttp3.HttpUrl; |
| 13 | + |
| 14 | +public class UserAttributeProfilesEntity extends BaseManagementEntity { |
| 15 | + |
| 16 | + private final static String ORGS_PATH = "api/v2/user-attribute-profiles"; |
| 17 | + |
| 18 | + UserAttributeProfilesEntity(Auth0HttpClient client, HttpUrl baseUrl, TokenProvider tokenProvider) { |
| 19 | + super(client, baseUrl, tokenProvider); |
| 20 | + } |
| 21 | + |
| 22 | + /** |
| 23 | + * Get a user attribute profile by its ID. A token with {@code read:user_attribute_profiles} scope is required. |
| 24 | + * @param id the ID of the user attribute profile to retrieve. |
| 25 | + * @return a Request to execute. |
| 26 | + */ |
| 27 | + public Request<UserAttributeProfile> get(String id) { |
| 28 | + Asserts.assertNotNull(id, "id"); |
| 29 | + |
| 30 | + String url = baseUrl.newBuilder() |
| 31 | + .addPathSegments(ORGS_PATH) |
| 32 | + .addPathSegment(id) |
| 33 | + .build().toString(); |
| 34 | + |
| 35 | + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<UserAttributeProfile>() { |
| 36 | + }); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * Get all user attribute profiles. A token with {@code read:user_attribute_profiles} scope is required. |
| 41 | + * |
| 42 | + * @param filter an optional pagination filter |
| 43 | + * @return a Request to execute |
| 44 | + * |
| 45 | + */ |
| 46 | + public Request<ListUserAttributeProfile> getAll(UserAttributeProfilesFilter filter) { |
| 47 | + HttpUrl.Builder builder = baseUrl.newBuilder() |
| 48 | + .addPathSegments(ORGS_PATH); |
| 49 | + |
| 50 | + if (filter != null) { |
| 51 | + filter.getAsMap().forEach((k, v) -> builder.addQueryParameter(k, String.valueOf(v))); |
| 52 | + } |
| 53 | + |
| 54 | + String url = builder.build().toString(); |
| 55 | + |
| 56 | + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<ListUserAttributeProfile>() { |
| 57 | + }); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Update a user attribute profile. A token with {@code update:user_attribute_profiles} scope is required. |
| 62 | + * |
| 63 | + * @param userAttributeProfile the user attribute profile to update. |
| 64 | + * @return a Request to execute. |
| 65 | + */ |
| 66 | + public Request<UserAttributeProfile> update(String id, UserAttributeProfile userAttributeProfile) { |
| 67 | + Asserts.assertNotNull(id, "id"); |
| 68 | + Asserts.assertNotNull(userAttributeProfile, "userAttributeProfile"); |
| 69 | + |
| 70 | + String url = baseUrl.newBuilder() |
| 71 | + .addPathSegments(ORGS_PATH) |
| 72 | + .addPathSegment(id) |
| 73 | + .build().toString(); |
| 74 | + |
| 75 | + BaseRequest<UserAttributeProfile> request = new BaseRequest<>(client, tokenProvider, url, HttpMethod.PATCH, new TypeReference<UserAttributeProfile>() { |
| 76 | + }); |
| 77 | + |
| 78 | + request.setBody(userAttributeProfile); |
| 79 | + return request; |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * Create a new user attribute profile. A token with {@code create:user_attribute_profiles} scope is required. |
| 84 | + * @param userAttributeProfile the user attribute profile to create. |
| 85 | + * @return a Request to execute. |
| 86 | + */ |
| 87 | + public Request<UserAttributeProfile> create(UserAttributeProfile userAttributeProfile) { |
| 88 | + Asserts.assertNotNull(userAttributeProfile.getName(), "name"); |
| 89 | + Asserts.assertNotNull(userAttributeProfile.getUserAttributes(), "userAttributes"); |
| 90 | + |
| 91 | + String url = baseUrl.newBuilder() |
| 92 | + .addPathSegments(ORGS_PATH) |
| 93 | + .build().toString(); |
| 94 | + |
| 95 | + BaseRequest<UserAttributeProfile> request = new BaseRequest<>(client, tokenProvider, url, HttpMethod.POST, new TypeReference<UserAttributeProfile>() { |
| 96 | + }); |
| 97 | + |
| 98 | + request.setBody(userAttributeProfile); |
| 99 | + return request; |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * Delete a user attribute profile by its ID. A token with {@code delete:user_attribute_profiles} scope is required. |
| 104 | + * @param id the ID of the user attribute profile to delete. |
| 105 | + * @return a Request to execute. |
| 106 | + */ |
| 107 | + public Request<Void> delete(String id) { |
| 108 | + Asserts.assertNotNull(id, "id"); |
| 109 | + |
| 110 | + HttpUrl.Builder builder = baseUrl |
| 111 | + .newBuilder() |
| 112 | + .addPathSegments(ORGS_PATH) |
| 113 | + .addPathSegment(id); |
| 114 | + |
| 115 | + String url = builder.build().toString(); |
| 116 | + return new VoidRequest(client, tokenProvider, url, HttpMethod.DELETE); |
| 117 | + } |
| 118 | + |
| 119 | + /** |
| 120 | + * Get a user attribute profile template by its ID. A token with {@code read:user_attribute_profiles} scope is required. |
| 121 | + * @param id the ID of the user attribute profile template to retrieve. |
| 122 | + * @return a Request to execute. |
| 123 | + */ |
| 124 | + public Request<UserAttributeProfileTemplate> getTemplate(String id) { |
| 125 | + Asserts.assertNotNull(id, "id"); |
| 126 | + |
| 127 | + String url = baseUrl.newBuilder() |
| 128 | + .addPathSegments(ORGS_PATH) |
| 129 | + .addPathSegment("templates") |
| 130 | + .addPathSegment(id) |
| 131 | + .build().toString(); |
| 132 | + |
| 133 | + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<UserAttributeProfileTemplate>() { |
| 134 | + }); |
| 135 | + } |
| 136 | + |
| 137 | + /** |
| 138 | + * Get all user attribute profile templates. A token with {@code read:user_attribute_profiles} scope is required. |
| 139 | + * |
| 140 | + * @return a Request to execute |
| 141 | + */ |
| 142 | + public Request<ListUserAttributeProfileTemplate> getAllTemplates() { |
| 143 | + String url = baseUrl.newBuilder() |
| 144 | + .addPathSegments(ORGS_PATH) |
| 145 | + .addPathSegment("templates") |
| 146 | + .build().toString(); |
| 147 | + |
| 148 | + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<ListUserAttributeProfileTemplate>() { |
| 149 | + }); |
| 150 | + } |
| 151 | +} |
0 commit comments