|
| 1 | +package com.auth0.client.mgmt; |
| 2 | + |
| 3 | +import com.auth0.client.mgmt.filter.PageBasedPaginationFilter; |
| 4 | +import com.auth0.json.mgmt.selfserviceprofiles.SelfServiceProfile; |
| 5 | +import com.auth0.json.mgmt.selfserviceprofiles.SelfServiceProfileResponse; |
| 6 | +import com.auth0.json.mgmt.selfserviceprofiles.SelfServiceProfileResponsePage; |
| 7 | +import com.auth0.net.BaseRequest; |
| 8 | +import com.auth0.net.Request; |
| 9 | +import com.auth0.net.VoidRequest; |
| 10 | +import com.auth0.net.client.Auth0HttpClient; |
| 11 | +import com.auth0.net.client.HttpMethod; |
| 12 | +import com.auth0.utils.Asserts; |
| 13 | +import com.fasterxml.jackson.core.type.TypeReference; |
| 14 | +import okhttp3.HttpUrl; |
| 15 | + |
| 16 | +import java.util.Map; |
| 17 | + |
| 18 | +public class SelfServiceProfilesEntity extends BaseManagementEntity { |
| 19 | + |
| 20 | + private final static String ORGS_PATH = "api/v2/self-service-profiles"; |
| 21 | + |
| 22 | + SelfServiceProfilesEntity(Auth0HttpClient client, HttpUrl baseUrl, TokenProvider tokenProvider) { |
| 23 | + super(client, baseUrl, tokenProvider); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * Request the list of self-service profiles. |
| 28 | + * A token with scope read:self_service_profiles is needed |
| 29 | + * See <a href="https://auth0.com/docs/api/management/v2/self-service-profiles/get-self-service-profiles">https://auth0.com/docs/api/management/v2/self-service-profiles/get-self-service-profiles</a> |
| 30 | + * @param pageFilter the pagination filter to apply. Can be null to use the default values. |
| 31 | + * @return a Request to execute. |
| 32 | + */ |
| 33 | + public Request<SelfServiceProfileResponsePage> get(PageBasedPaginationFilter pageFilter) { |
| 34 | + HttpUrl.Builder builder = baseUrl.newBuilder() |
| 35 | + .addPathSegments(ORGS_PATH); |
| 36 | + |
| 37 | + if (pageFilter != null) { |
| 38 | + for (Map.Entry<String, Object> e : pageFilter.getAsMap().entrySet()) { |
| 39 | + builder.addQueryParameter(e.getKey(), String.valueOf(e.getValue())); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + String url = builder.build().toString(); |
| 44 | + return new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.GET, new TypeReference<SelfServiceProfileResponsePage>() { |
| 45 | + }); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Create a new self-service profile. |
| 50 | + * A token with scope create:self_service_profiles is needed |
| 51 | + * See <a href="https://auth0.com/docs/api/management/v2/self-service-profiles/post-self-service-profiles">https://auth0.com/docs/api/management/v2/self-service-profiles/post-self-service-profiles</a> |
| 52 | + * @param selfServiceProfile the self-service profile to create. |
| 53 | + * @return a Request to execute. |
| 54 | + */ |
| 55 | + public Request<SelfServiceProfileResponse> create(SelfServiceProfile selfServiceProfile) { |
| 56 | + Asserts.assertNotNull(selfServiceProfile, "self service profile"); |
| 57 | + Asserts.assertNotNull(selfServiceProfile.getName(), "name"); |
| 58 | + |
| 59 | + String url = baseUrl.newBuilder() |
| 60 | + .addPathSegments(ORGS_PATH) |
| 61 | + .build() |
| 62 | + .toString(); |
| 63 | + |
| 64 | + BaseRequest<SelfServiceProfileResponse> request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.POST, new TypeReference<SelfServiceProfileResponse>() { |
| 65 | + }); |
| 66 | + request.setBody(selfServiceProfile); |
| 67 | + return request; |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Request the self-service profile with the given ID. |
| 72 | + * A token with scope read:self_service_profiles is needed |
| 73 | + * See <a href="https://auth0.com/docs/api/management/v2/self-service-profiles/get-self-service-profiles-by-id">https://auth0.com/docs/api/management/v2/self-service-profiles/get-self-service-profiles-by-id</a> |
| 74 | + * @param id the self-service profile ID. |
| 75 | + * @return a Request to execute. |
| 76 | + */ |
| 77 | + public Request<SelfServiceProfileResponse> getById(String id) { |
| 78 | + Asserts.assertNotNull(id, "id"); |
| 79 | + |
| 80 | + String url = baseUrl.newBuilder() |
| 81 | + .addPathSegments(ORGS_PATH) |
| 82 | + .addPathSegment(id) |
| 83 | + .build() |
| 84 | + .toString(); |
| 85 | + |
| 86 | + return new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.GET, new TypeReference<SelfServiceProfileResponse>() { |
| 87 | + }); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * Delete the self-service profile with the given ID. |
| 92 | + * A token with scope delete:self_service_profiles is needed |
| 93 | + * See <a href="https://auth0.com/docs/api/management/v2/self-service-profiles/delete-self-service-profiles-by-id">https://auth0.com/docs/api/management/v2/self-service-profiles/delete-self-service-profiles-by-id</a> |
| 94 | + * @param id the self-service profile ID. |
| 95 | + * @return a Request to execute. |
| 96 | + */ |
| 97 | + public Request<Void> delete(String id) { |
| 98 | + Asserts.assertNotNull(id, "id"); |
| 99 | + |
| 100 | + String url = baseUrl.newBuilder() |
| 101 | + .addPathSegments(ORGS_PATH) |
| 102 | + .addPathSegment(id) |
| 103 | + .build() |
| 104 | + .toString(); |
| 105 | + |
| 106 | + return new VoidRequest(this.client, tokenProvider, url, HttpMethod.DELETE); |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * Update the self-service profile with the given ID. |
| 111 | + * A token with scope update:self_service_profiles is needed |
| 112 | + * See <a href="https://auth0.com/docs/api/management/v2/self-service-profiles/patch-self-service-profiles-by-id">https://auth0.com/docs/api/management/v2/self-service-profiles/patch-self-service-profiles-by-id</a> |
| 113 | + * @param selfServiceProfile the self-service profile to update. |
| 114 | + * @param id the self-service profile ID. |
| 115 | + * @return a Request to execute. |
| 116 | + */ |
| 117 | + public Request<SelfServiceProfileResponse> update(SelfServiceProfile selfServiceProfile, String id) { |
| 118 | + Asserts.assertNotNull(selfServiceProfile, "self service profile"); |
| 119 | + Asserts.assertNotNull(id, "id"); |
| 120 | + |
| 121 | + String url = baseUrl.newBuilder() |
| 122 | + .addPathSegments(ORGS_PATH) |
| 123 | + .addPathSegment(id) |
| 124 | + .build() |
| 125 | + .toString(); |
| 126 | + |
| 127 | + BaseRequest<SelfServiceProfileResponse> request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.PATCH, new TypeReference<SelfServiceProfileResponse>() { |
| 128 | + }); |
| 129 | + request.setBody(selfServiceProfile); |
| 130 | + return request; |
| 131 | + } |
| 132 | +} |
0 commit comments