Skip to content
Snippets Groups Projects
Commit 14f8c6e2 authored by ella's avatar ella
Browse files

tantive de connexion a VITAM et mise en place de la methode PUT

parent 055b0b25
No related branches found
No related tags found
No related merge requests found
Pipeline #6532 passed with stages
in 1 minute and 4 seconds
Showing with 113 additions and 43 deletions
......@@ -66,13 +66,18 @@
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.kie.commons</groupId>
<artifactId>kie-nio2-api</artifactId>
<version>6.0.0.Beta3</version>
</dependency>
<groupId>org.kie.commons</groupId>
<artifactId>kie-nio2-api</artifactId>
<version>6.0.0.Beta3</version>
</dependency>
<dependency>
<groupId>net.lingala.zip4j</groupId>
<artifactId>zip4j</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>
......
......@@ -92,7 +92,7 @@ public class Pacit {
submissionList.add(task);
}
ExecutorService executor = Executors.newFixedThreadPool(10);
ExecutorService executor = Executors.newFixedThreadPool(1);
for(SubmissionTask s : submissionList){
executor.execute(s);
......
......@@ -5,52 +5,111 @@ package fr.cines.pacit.transfer.impl;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipInputStream;
import java.io.*;
import org.apache.camel.dataformat.zipfile.ZipSplitter;
public class TransferCamelImpl {
String url ;
String localPath ;
String fileName = "vitam-data-test-master";
String fileName = "//vitam-data-test.zip";
String compessedFile = "C:/Users/ella/Desktop/CompressedFile/";
public void downloadFile(String url, String localPath) throws IOException
{
{
URL ulr = new URL(url);
HttpURLConnection connection = (HttpURLConnection) ulr.openConnection();
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("accept", "*/*");
ReadableByteChannel readableFileChannel = Channels.newChannel(connection.getInputStream());
FileOutputStream fos = new FileOutputStream(localPath + "//vitam-data-test.zip");
fos.getChannel().transferFrom(readableFileChannel, 0, Long.MAX_VALUE);
ReadableByteChannel readableFileChannel = Channels.newChannel(connection.getInputStream());
FileOutputStream fos = new FileOutputStream(compessedFile + fileName);
fos.getChannel().transferFrom(readableFileChannel, 0, Long.MAX_VALUE);
fos.close();
}
// Unzip
byte[] buffer = new byte[1024];
ZipInputStream zis = new ZipInputStream(new FileInputStream(compessedFile + fileName));
ZipEntry zipEntry = zis.getNextEntry();
while (zipEntry != null) {
File newFile = newFile(new File(localPath), zipEntry);
if (zipEntry.isDirectory()) {
if (!newFile.isDirectory() && !newFile.mkdirs()) {
throw new IOException("Failed to create directory " + newFile);
}
} else {
// fix for Windows-created archives
File parent = newFile.getParentFile();
if (!parent.isDirectory() && !parent.mkdirs()) {
throw new IOException("Failed to create directory " + parent);
}
// write file content
FileOutputStream entryOutputStream = new FileOutputStream(newFile);
int len;
while ((len = zis.read(buffer)) > 0) {
entryOutputStream.write(buffer, 0, len);
}
entryOutputStream.close();
}
zipEntry = zis.getNextEntry();
}
zis.closeEntry();
zis.close();
}
public static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException {
File destFile = new File(destinationDir, zipEntry.getName());
String destDirPath = destinationDir.getCanonicalPath();
String destFilePath = destFile.getCanonicalPath();
if (!destFilePath.startsWith(destDirPath + File.separator)) {
throw new IOException("Entry is outside of the target dir: " + zipEntry.getName());
}
return destFile;
}
public void deletezip() {
File fileZip = new File("C:/Users/ella/Desktop/CompressedFile/vitam-data-test.zip") ;
try {
if(fileZip.delete()) {
System.out.println("fichier zip supprim");
}else {
System.out.println("fichier zip n'a pas t supprim");
}
}catch(Exception e) {
e.printStackTrace();
//System.out.println(e.getMessage());
}
}
public TransferCamelImpl(String url, String localPath) {
this.url = url ;
this.localPath = localPath ;
}
}
......@@ -33,6 +33,7 @@ import java.util.Properties;
import org.apache.camel.main.Main;
import fr.cines.pacit.tranfer.Transfer;
import net.lingala.zip4j.exception.ZipException;
/**
* @author Raphael Ella <ella@cines.fr>
......@@ -53,6 +54,7 @@ public class TransferImpl implements Transfer{
TransferCamelImpl p = new TransferCamelImpl(url, localPath) ;
try {
p.downloadFile(url, localPath);
p.deletezip();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
......
......@@ -21,16 +21,15 @@
package fr.cines.pacit.transfer.impl;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.http.HttpResponse;
import java.nio.file.Path;
import java.util.List;
import java.util.Timer;
import org.apache.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.cines.pacit.tranfer.ArchiveService;
import fr.cines.vitam.proxy.VitamApiProxyRequest;
......@@ -41,19 +40,24 @@ import fr.cines.vitam.proxy.request.RequesterInfo;
*
*/
public class VitamArchiveService implements ArchiveService {
private static Logger LOGGER = LoggerFactory.getLogger(VitamArchiveService.class);
@Override
public void put(Path path) throws IOException, URISyntaxException, InterruptedException{
if(!path.toString().endsWith("zip"))return ;
RequesterInfo requestInfo = new RequesterInfo();
System.out.println("Soumission de " + path.toString());
Thread.sleep(500);
// InputStream is = new FileInputStream(path.toFile());
// HttpResponse<String> ExternalResponse = VitamApiProxyRequest.Ingest().ingestFile(requestInfo, is);
// if(ExternalResponse.statusCode() == HttpStatus.SC_ACCEPTED) {
//
// //String requestId = ExternalResponse.headers().firstValue(CinesVitamConnectorConfiguration.X_REQUEST_ID).get();
// //LOGGER.info("Ingestion accepted - RequestId {}", requestId);
// }
InputStream is = new FileInputStream(path.toFile());
HttpResponse<String> ExternalResponse = VitamApiProxyRequest.Ingest().ingestFile(requestInfo, is);
if(ExternalResponse.statusCode() == HttpStatus.SC_ACCEPTED) {
String requestId = ExternalResponse.headers().firstValue("X-Request-Id").get();
LOGGER.info("Ingestion accepted - RequestId {}", requestId);
}
}
@Override
......
proxy.api.url-admin.external=https://sandbox34.cines.fr:8444/admin-external/v1/
proxy.api.url-access.external=https://sandbox34.cines.fr:8444/access-external/v1/
proxy.api.url-ingest=https://sandbox34.cines.fr:8443/ingest-external/v1/
proxy.api.keyStore-password=azerty4
proxy.api.keyStore-path=/Users/ella/git/pacit/src/test/resources/keystore_ihm-demo.p12
proxy.api.keyStore-password=azerty
proxy.api.keyStore-path=rc/test/resources/keystore_inserm.p12
proxy.api.trustStore-password=azerty10
proxy.api.trustStore-path=/Users/ella/git/pacit/src/test/resources/truststore_ihm-demo.jks
proxy.api.trustStore-path=rc/test/resources/truststore_34.jks
proxy.api.contrat-acces=CINES-0
proxy.api.tenant-id=0
proxy.api.disable-hostname-verification=true
\ No newline at end of file
url=https://dci-gitlab.cines.fr/dad/vitam-data-test/-/archive/master/vitam-data-test-master.zip
localPath=C:/Users/ella/Desktop/TestTranfer2/
\ No newline at end of file
localPath=C:/Users/ella/Desktop/TestTranfer2
\ No newline at end of file
File deleted
File added
File added
File deleted
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment