public void putWorkspace ( long workspaceId , Workspace workspace ) throws StructurizrClientException { if ( workspace == null ) { throw new IllegalArgumentException ( "The workspace must not be null." ) ; } else if ( workspaceId <= 0 ) { throw new IllegalArgumentException ( "The workspace ID must be a positive integer." ) ; } try ( CloseableHttpClient httpClient = HttpClients . createSystem ( ) ) { if ( mergeFromRemote ) { Workspace remoteWorkspace = getWorkspace ( workspaceId ) ; if ( remoteWorkspace != null ) { workspace . getViews ( ) . copyLayoutInformationFrom ( remoteWorkspace . getViews ( ) ) ; workspace . getViews ( ) . getConfiguration ( ) . copyConfigurationFrom ( remoteWorkspace . getViews ( ) . getConfiguration ( ) ) ; } } workspace . setId ( workspaceId ) ; workspace . setThumbnail ( null ) ; workspace . setLastModifiedDate ( new Date ( ) ) ; workspace . setLastModifiedAgent ( STRUCTURIZR_FOR_JAVA_AGENT ) ; workspace . setLastModifiedUser ( getUser ( ) ) ; workspace . countAndLogWarnings ( ) ; HttpPut httpPut = new HttpPut ( url + WORKSPACE_PATH + workspaceId ) ; StringWriter stringWriter = new StringWriter ( ) ; if ( encryptionStrategy == null ) { JsonWriter jsonWriter = new JsonWriter ( false ) ; jsonWriter . write ( workspace , stringWriter ) ; } else { EncryptedWorkspace encryptedWorkspace = new EncryptedWorkspace ( workspace , encryptionStrategy ) ; encryptionStrategy . setLocation ( EncryptionLocation . Client ) ; EncryptedJsonWriter jsonWriter = new EncryptedJsonWriter ( false ) ; jsonWriter . write ( encryptedWorkspace , stringWriter ) ; } StringEntity stringEntity = new StringEntity ( stringWriter . toString ( ) , ContentType . APPLICATION_JSON ) ; httpPut . setEntity ( stringEntity ) ; addHeaders ( httpPut , EntityUtils . toString ( stringEntity ) , ContentType . APPLICATION_JSON . toString ( ) ) ; debugRequest ( httpPut , EntityUtils . toString ( stringEntity ) ) ; log . info ( "Putting workspace with ID " + workspaceId ) ; try ( CloseableHttpResponse response = httpClient . execute ( httpPut ) ) { String json = EntityUtils . toString ( response . getEntity ( ) ) ; if ( response . getCode ( ) == HttpStatus . SC_OK ) { debugResponse ( response ) ; log . info ( json ) ; } else { ApiResponse apiResponse = ApiResponse . parse ( json ) ; throw new StructurizrClientException ( apiResponse . getMessage ( ) ) ; } } } catch ( Exception e ) { log . error ( e ) ; throw new StructurizrClientException ( e ) ; } }
Updates the given workspace .