@@ -0,0 +1,2789 @@
+package de.retest.recheck.persistence;%0A%0Aimport static de.retest.recheck.XmlTransformerUtil.getXmlTransformer;%0A%0Aimport java.io.File;%0Aimport java.io.IOException;%0Aimport java.net.URI;%0Aimport java.nio.file.Paths;%0A%0Aimport de.retest.recheck.Properties;%0Aimport de.retest.recheck.auth.RetestAuthentication;%0Aimport de.retest.recheck.persistence.bin.KryoPersistence;%0Aimport de.retest.recheck.persistence.xml.XmlFolderPersistence;%0Aimport lombok.extern.slf4j.Slf4j;%0Aimport okhttp3.OkHttpClient;%0Aimport okhttp3.Request;%0Aimport okhttp3.RequestBody;%0Aimport okhttp3.Response;%0A%0A@Slf4j%0Apublic class CloudPersistence%3CT extends Persistable%3E implements Persistence%3CT%3E %7B%0A%09private static final String SERVICE_ENDPOINT = %22https://marvin.prod.cloud.retest.org/api/report%22;%0A%09private final KryoPersistence%3CT%3E kryoPersistence = new KryoPersistence%3C%3E();%0A%09private final XmlFolderPersistence%3CT%3E folderPersistence = new XmlFolderPersistence%3C%3E( getXmlTransformer() );%0A%09private final OkHttpClient client = new OkHttpClient();%0A%0A%09public static final String RECHECK_API_KEY = %22RECHECK_API_KEY%22;%0A%0A%09@Override%0A%09public void save( final URI identifier, final T element ) throws IOException %7B%0A%09%09kryoPersistence.save( identifier, element );%0A%09%09if ( identifier.getPath().endsWith( Properties.AGGREGATED_TEST_REPORT_FILE_NAME ) ) %7B%0A%09%09%09saveToCloud( identifier );%0A%09%09%7D%0A%09%7D%0A%0A%09private void saveToCloud( final URI identifier ) throws IOException %7B%0A%09%09final Response uploadUrlResponse = getUploadUrl();%0A%0A%09%09if ( uploadUrlResponse.isSuccessful() ) %7B%0A%09%09%09uploadReport( identifier, uploadUrlResponse.body().string() );%0A%09%09%7D%0A%09%7D%0A%0A%09private void uploadReport( final URI identifier, final String url ) throws IOException %7B%0A%09%09final Request uploadRequest = new Request.Builder() //%0A%09%09%09%09.url( url ) //%0A%09%09%09%09.put( RequestBody.create( null, new File( identifier ) ) ) //%0A%09%09%09%09.addHeader( %22x-amz-meta-report-name%22, Paths.get( identifier ).getFileName().toString() ) //%0A%09%09%09%09.build();%0A%0A%09%09final Response uploadResponse = client.newCall( uploadRequest ).execute();%0A%0A%09%09if ( uploadResponse.isSuccessful() ) %7B%0A%09%09%09log.info( %22Sucessfully uploaded report to rehub%22 );%0A%09%09%7D%0A%09%7D%0A%0A%09private Response getUploadUrl() throws IOException %7B%0A%09%09final RetestAuthentication auth = RetestAuthentication.getInstance();%0A%09%09final String token = String.format( %22Bearer %25s%22, auth.getAccessTokenString() );%0A%0A%09%09final Request uploadUrlRequest = new Request.Builder() //%0A%09%09%09%09.url( SERVICE_ENDPOINT ) //%0A%09%09%09%09.post( RequestBody.create( null, %22%22 ) ) //%0A%09%09%09%09.addHeader( %22Authorization%22, token ) //%0A%09%09%09%09.build();%0A%0A%09%09return client.newCall( uploadUrlRequest ).execute();%0A%09%7D%0A%0A%09@Override%0A%09public T load( final URI identifier ) throws IOException %7B%0A%09%09if ( Paths.get( identifier ).toFile().isDirectory() ) %7B%0A%09%09%09return folderPersistence.load( identifier );%0A%09%09%7D%0A%09%09return kryoPersistence.load( identifier );%0A%09%7D%0A%0A%7D%0A

Add basic cloud persistence