@@ -227,6 +227,44 @@ private boolean manageLockForWorkspace(long workspaceId, boolean lock) throws St
227227 * @throws StructurizrClientException if there are problems related to the network, authorization, JSON deserialization, etc
228228 */
229229 public Workspace getWorkspace (long workspaceId ) throws StructurizrClientException {
230+ String json = getWorkspaceAsJson (workspaceId );
231+
232+ try {
233+ if (encryptionStrategy == null ) {
234+ if (json .contains ("\" encryptionStrategy\" " ) && json .contains ("\" ciphertext\" " )) {
235+ log .warn ("The JSON may contain a client-side encrypted workspace, but no passphrase has been specified." );
236+ }
237+
238+ JsonReader jsonReader = new JsonReader ();
239+ jsonReader .setIdGenerator (idGenerator );
240+ return jsonReader .read (new StringReader (json ));
241+ } else {
242+ EncryptedWorkspace encryptedWorkspace = new EncryptedJsonReader ().read (new StringReader (json ));
243+
244+ if (encryptedWorkspace .getEncryptionStrategy () != null ) {
245+ encryptedWorkspace .getEncryptionStrategy ().setPassphrase (encryptionStrategy .getPassphrase ());
246+ return encryptedWorkspace .getWorkspace ();
247+ } else {
248+ // this workspace isn't encrypted, even though the client has an encryption strategy set
249+ JsonReader jsonReader = new JsonReader ();
250+ jsonReader .setIdGenerator (idGenerator );
251+ return jsonReader .read (new StringReader (json ));
252+ }
253+ }
254+ } catch (Exception e ) {
255+ log .error (e );
256+ throw new StructurizrClientException (e );
257+ }
258+ }
259+
260+ /**
261+ * Gets the workspace with the given ID, as a JSON string.
262+ *
263+ * @param workspaceId the workspace ID
264+ * @return a JSON string
265+ * @throws StructurizrClientException if there are problems related to the network, authorization, JSON deserialization, etc
266+ */
267+ public String getWorkspaceAsJson (long workspaceId ) throws StructurizrClientException {
230268 if (workspaceId <= 0 ) {
231269 throw new IllegalArgumentException ("The workspace ID must be a positive integer." );
232270 }
@@ -251,27 +289,7 @@ public Workspace getWorkspace(long workspaceId) throws StructurizrClientExceptio
251289 if (response .getCode () == HttpStatus .SC_OK ) {
252290 archiveWorkspace (workspaceId , json );
253291
254- if (encryptionStrategy == null ) {
255- if (json .contains ("\" encryptionStrategy\" " ) && json .contains ("\" ciphertext\" " )) {
256- log .warn ("The JSON may contain a client-side encrypted workspace, but no passphrase has been specified." );
257- }
258-
259- JsonReader jsonReader = new JsonReader ();
260- jsonReader .setIdGenerator (idGenerator );
261- return jsonReader .read (new StringReader (json ));
262- } else {
263- EncryptedWorkspace encryptedWorkspace = new EncryptedJsonReader ().read (new StringReader (json ));
264-
265- if (encryptedWorkspace .getEncryptionStrategy () != null ) {
266- encryptedWorkspace .getEncryptionStrategy ().setPassphrase (encryptionStrategy .getPassphrase ());
267- return encryptedWorkspace .getWorkspace ();
268- } else {
269- // this workspace isn't encrypted, even though the client has an encryption strategy set
270- JsonReader jsonReader = new JsonReader ();
271- jsonReader .setIdGenerator (idGenerator );
272- return jsonReader .read (new StringReader (json ));
273- }
274- }
292+ return json ;
275293 } else {
276294 ApiResponse apiResponse = ApiResponse .parse (json );
277295 throw new StructurizrClientException (apiResponse .getMessage ());
0 commit comments