001package com.box.sdkgen.managers.classifications; 002 003import static com.box.sdkgen.internal.utils.UtilsManager.mapOf; 004import static com.box.sdkgen.internal.utils.UtilsManager.mergeMaps; 005import static com.box.sdkgen.internal.utils.UtilsManager.prepareParams; 006 007import com.box.sdkgen.networking.auth.Authentication; 008import com.box.sdkgen.networking.fetchoptions.FetchOptions; 009import com.box.sdkgen.networking.fetchoptions.ResponseFormat; 010import com.box.sdkgen.networking.fetchresponse.FetchResponse; 011import com.box.sdkgen.networking.network.NetworkSession; 012import com.box.sdkgen.schemas.classificationtemplate.ClassificationTemplate; 013import com.box.sdkgen.serialization.json.JsonManager; 014import java.util.List; 015import java.util.Map; 016 017public class ClassificationsManager { 018 019 public Authentication auth; 020 021 public NetworkSession networkSession; 022 023 public ClassificationsManager() { 024 this.networkSession = new NetworkSession(); 025 } 026 027 protected ClassificationsManager(Builder builder) { 028 this.auth = builder.auth; 029 this.networkSession = builder.networkSession; 030 } 031 032 /** 033 * Retrieves the classification metadata template and lists all the classifications available to 034 * this enterprise. 035 * 036 * <p>This API can also be called by including the enterprise ID in the URL explicitly, for 037 * example `/metadata_templates/enterprise_12345/securityClassification-6VMVochwUWo/schema`. 038 */ 039 public ClassificationTemplate getClassificationTemplate() { 040 return getClassificationTemplate(new GetClassificationTemplateHeaders()); 041 } 042 043 /** 044 * Retrieves the classification metadata template and lists all the classifications available to 045 * this enterprise. 046 * 047 * <p>This API can also be called by including the enterprise ID in the URL explicitly, for 048 * example `/metadata_templates/enterprise_12345/securityClassification-6VMVochwUWo/schema`. 049 * 050 * @param headers Headers of getClassificationTemplate method 051 */ 052 public ClassificationTemplate getClassificationTemplate( 053 GetClassificationTemplateHeaders headers) { 054 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 055 FetchResponse response = 056 this.networkSession 057 .getNetworkClient() 058 .fetch( 059 new FetchOptions.Builder( 060 String.join( 061 "", 062 this.networkSession.getBaseUrls().getBaseUrl(), 063 "/2.0/metadata_templates/enterprise/securityClassification-6VMVochwUWo/schema"), 064 "GET") 065 .headers(headersMap) 066 .responseFormat(ResponseFormat.JSON) 067 .auth(this.auth) 068 .networkSession(this.networkSession) 069 .build()); 070 return JsonManager.deserialize(response.getData(), ClassificationTemplate.class); 071 } 072 073 /** 074 * Adds one or more new classifications to the list of classifications available to the 075 * enterprise. 076 * 077 * <p>This API can also be called by including the enterprise ID in the URL explicitly, for 078 * example `/metadata_templates/enterprise_12345/securityClassification-6VMVochwUWo/schema`. 079 * 080 * @param requestBody Request body of addClassification method 081 */ 082 public ClassificationTemplate addClassification(List<AddClassificationRequestBody> requestBody) { 083 return addClassification(requestBody, new AddClassificationHeaders()); 084 } 085 086 /** 087 * Adds one or more new classifications to the list of classifications available to the 088 * enterprise. 089 * 090 * <p>This API can also be called by including the enterprise ID in the URL explicitly, for 091 * example `/metadata_templates/enterprise_12345/securityClassification-6VMVochwUWo/schema`. 092 * 093 * @param requestBody Request body of addClassification method 094 * @param headers Headers of addClassification method 095 */ 096 public ClassificationTemplate addClassification( 097 List<AddClassificationRequestBody> requestBody, AddClassificationHeaders headers) { 098 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 099 FetchResponse response = 100 this.networkSession 101 .getNetworkClient() 102 .fetch( 103 new FetchOptions.Builder( 104 String.join( 105 "", 106 this.networkSession.getBaseUrls().getBaseUrl(), 107 "/2.0/metadata_templates/enterprise/securityClassification-6VMVochwUWo/schema#add"), 108 "PUT") 109 .headers(headersMap) 110 .data(JsonManager.serialize(requestBody)) 111 .contentType("application/json") 112 .responseFormat(ResponseFormat.JSON) 113 .auth(this.auth) 114 .networkSession(this.networkSession) 115 .build()); 116 return JsonManager.deserialize(response.getData(), ClassificationTemplate.class); 117 } 118 119 /** 120 * Updates the labels and descriptions of one or more classifications available to the enterprise. 121 * 122 * <p>This API can also be called by including the enterprise ID in the URL explicitly, for 123 * example `/metadata_templates/enterprise_12345/securityClassification-6VMVochwUWo/schema`. 124 * 125 * @param requestBody Request body of updateClassification method 126 */ 127 public ClassificationTemplate updateClassification( 128 List<UpdateClassificationRequestBody> requestBody) { 129 return updateClassification(requestBody, new UpdateClassificationHeaders()); 130 } 131 132 /** 133 * Updates the labels and descriptions of one or more classifications available to the enterprise. 134 * 135 * <p>This API can also be called by including the enterprise ID in the URL explicitly, for 136 * example `/metadata_templates/enterprise_12345/securityClassification-6VMVochwUWo/schema`. 137 * 138 * @param requestBody Request body of updateClassification method 139 * @param headers Headers of updateClassification method 140 */ 141 public ClassificationTemplate updateClassification( 142 List<UpdateClassificationRequestBody> requestBody, UpdateClassificationHeaders headers) { 143 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 144 FetchResponse response = 145 this.networkSession 146 .getNetworkClient() 147 .fetch( 148 new FetchOptions.Builder( 149 String.join( 150 "", 151 this.networkSession.getBaseUrls().getBaseUrl(), 152 "/2.0/metadata_templates/enterprise/securityClassification-6VMVochwUWo/schema#update"), 153 "PUT") 154 .headers(headersMap) 155 .data(JsonManager.serialize(requestBody)) 156 .contentType("application/json-patch+json") 157 .responseFormat(ResponseFormat.JSON) 158 .auth(this.auth) 159 .networkSession(this.networkSession) 160 .build()); 161 return JsonManager.deserialize(response.getData(), ClassificationTemplate.class); 162 } 163 164 /** 165 * When an enterprise does not yet have any classifications, this API call initializes the 166 * classification template with an initial set of classifications. 167 * 168 * <p>If an enterprise already has a classification, the template will already exist and instead 169 * an API call should be made to add additional classifications. 170 * 171 * @param requestBody Request body of createClassificationTemplate method 172 */ 173 public ClassificationTemplate createClassificationTemplate( 174 CreateClassificationTemplateRequestBody requestBody) { 175 return createClassificationTemplate(requestBody, new CreateClassificationTemplateHeaders()); 176 } 177 178 /** 179 * When an enterprise does not yet have any classifications, this API call initializes the 180 * classification template with an initial set of classifications. 181 * 182 * <p>If an enterprise already has a classification, the template will already exist and instead 183 * an API call should be made to add additional classifications. 184 * 185 * @param requestBody Request body of createClassificationTemplate method 186 * @param headers Headers of createClassificationTemplate method 187 */ 188 public ClassificationTemplate createClassificationTemplate( 189 CreateClassificationTemplateRequestBody requestBody, 190 CreateClassificationTemplateHeaders headers) { 191 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 192 FetchResponse response = 193 this.networkSession 194 .getNetworkClient() 195 .fetch( 196 new FetchOptions.Builder( 197 String.join( 198 "", 199 this.networkSession.getBaseUrls().getBaseUrl(), 200 "/2.0/metadata_templates/schema#classifications"), 201 "POST") 202 .headers(headersMap) 203 .data(JsonManager.serialize(requestBody)) 204 .contentType("application/json") 205 .responseFormat(ResponseFormat.JSON) 206 .auth(this.auth) 207 .networkSession(this.networkSession) 208 .build()); 209 return JsonManager.deserialize(response.getData(), ClassificationTemplate.class); 210 } 211 212 public Authentication getAuth() { 213 return auth; 214 } 215 216 public NetworkSession getNetworkSession() { 217 return networkSession; 218 } 219 220 public static class Builder { 221 222 protected Authentication auth; 223 224 protected NetworkSession networkSession; 225 226 public Builder() {} 227 228 public Builder auth(Authentication auth) { 229 this.auth = auth; 230 return this; 231 } 232 233 public Builder networkSession(NetworkSession networkSession) { 234 this.networkSession = networkSession; 235 return this; 236 } 237 238 public ClassificationsManager build() { 239 if (this.networkSession == null) { 240 this.networkSession = new NetworkSession(); 241 } 242 return new ClassificationsManager(this); 243 } 244 } 245}