Skip to content
Snippets Groups Projects
Commit 9cdc9733 authored by granier's avatar granier
Browse files

correction checkStatus

parent 32676fcc
No related branches found
No related tags found
No related merge requests found
Pipeline #6643 passed with stages
in 1 minute and 4 seconds
......@@ -38,6 +38,7 @@ import com.fasterxml.jackson.databind.JsonMappingException;
import fr.cines.pacit.Pacit;
import fr.cines.pacit.parse.ParseXml;
import fr.cines.pacit.tranfer.ArchiveService;
import fr.cines.vitam.proxy.request.RequesterInfo;
/**
* @author Raphael Ella <ella@cines.fr>
......@@ -45,59 +46,60 @@ import fr.cines.pacit.tranfer.ArchiveService;
*/
public class SubmissionTask implements Runnable{
private ArchiveService archiveService;
private Path path;
private Path pathAtrExpected;
private String atrRuLes= "/pacit/src/main/resources/rules.xml";
Path atrRule = Paths.get(atrRuLes);
private static Map<String, String> mapRules = new HashMap<String, String>();
private static Map<String, String> mapResult = new HashMap<String, String>();
private static Map<String, String> mapExpected = new HashMap<String, String>();
private ParseXml parser = new ParseXml();
public SubmissionTask(Path path, ArchiveService archiveSerice, Path pathAtrExpected) {
this.archiveService = archiveSerice;
this.path = path;
this.pathAtrExpected = pathAtrExpected;
}
@Override
public void run() {
try {
String idRequest = archiveService.put(this.path);
while(!isStatutTerminal(idRequest)) {
Thread.sleep(2000);
}
String result = archiveService.retreiveResult(idRequest);
if (result != null) {
mapResult = parser.buildMap(result);
mapExpected = parser.buildMap(pathAtrExpected);
mapRules= parser.buildMap(atrRule);
Pacit pacit = new Pacit();
boolean comparaison = pacit.compare(mapExpected, mapResult, mapRules);
System.out.println(comparaison);
}
} catch (Exception e) {
e.printStackTrace();
}
}
private boolean isStatutTerminal(String idRequest) throws JsonMappingException, JsonProcessingException, URISyntaxException, IOException, InterruptedException {
String status = archiveService.checkRequest(idRequest);
System.out.println("check request status request: " + idRequest+ " Thread "+ Thread.currentThread().getName());
if(status.equals("OK") || status.equals("KO"))
return true;
else {
return false;
}
}
private ArchiveService archiveService;
private Path path;
private Path pathAtrExpected;
private String atrRuLes= "/pacit/src/main/resources/rules.xml";
Path atrRule = Paths.get(atrRuLes);
private static Map<String, String> mapRules = new HashMap<String, String>();
private static Map<String, String> mapResult = new HashMap<String, String>();
private static Map<String, String> mapExpected = new HashMap<String, String>();
private ParseXml parser = new ParseXml();
public SubmissionTask(Path path, ArchiveService archiveSerice, Path pathAtrExpected) {
this.archiveService = archiveSerice;
this.path = path;
this.pathAtrExpected = pathAtrExpected;
}
@Override
public void run() {
try {
String idRequest = archiveService.put(this.path);
while(!isStatutTerminal(idRequest)) {
Thread.sleep(5000);
}
Thread.sleep(5000);
String result = archiveService.retreiveResult(idRequest);
if (result != null) {
mapResult = parser.buildMap(result);
mapExpected = parser.buildMap(pathAtrExpected);
mapRules= parser.buildMap(atrRule);
Pacit pacit = new Pacit();
boolean comparaison = pacit.compare(mapExpected, mapResult, mapRules);
System.out.println(comparaison);
}
} catch (Exception e) {
e.printStackTrace();
}
}
private boolean isStatutTerminal(String idRequest) throws JsonMappingException, JsonProcessingException, URISyntaxException, IOException, InterruptedException {
String status = archiveService.checkRequest(idRequest);
System.out.println("check request status request: " + idRequest+ " Thread "+ Thread.currentThread().getName());
if(status.equals("COMPLETED"))
return true;
else {
return false;
}
}
}
......@@ -24,7 +24,7 @@ public class TransferCamelImpl {
String url ;
String localPath ;
String fileName = "//vitam-data-test.zip";
String compessedFile = "C:/Users/ella/Desktop/CompressedFile/vitam-data-test.zip";
String compessedFile = localPath + "vitam-data-test.zip";
......
......@@ -120,7 +120,7 @@ public class TransferImpl implements Transfer{
public Properties loadProperties() throws IOException {
Properties prop = new Properties() ;
String configFolder ="C:/Users/ella/git/pacit/src/main/resources/" ;
String configFolder ="src/main/resources/" ;
InputStream is = new FileInputStream(configFolder + File.separator + "config.properties");
prop.load(is);
is.close();
......
......@@ -63,6 +63,7 @@ public class VitamArchiveService implements ArchiveService {
requestInfo.setContextID("CINES_WORKFLOW");
requestInfo.setContrat_acces("CE-000001");
requestInfo.setTenant_id("0");
// requestInfo.setClientCert(null);
System.out.println("Soumission de " + path.toString());
Thread.sleep(500);
......@@ -90,30 +91,27 @@ public class VitamArchiveService implements ArchiveService {
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonResponse = mapper.readTree(httpResponse.body());
String status = jsonResponse.get("$results").get(0).get("globalStatus").asText();
if ("KO".equals(status)) {
System.out.println("foiré");
}
//System.out.println(jsonResponse.get("httpCode"));
return status;
String state = jsonResponse.get("$results").get(0).get("globalState").asText();
return state;
}
@Override
public String retreiveResult(String idRequest) {
RequesterInfo requestInfo = new RequesterInfo();
requestInfo.setContextID("CINES_WORKFLOW");
requestInfo.setContrat_acces("CE-000001");
requestInfo.setTenant_id("0");
HttpResponse<String> ingestExternalResponse;
try {
System.out.println("retreive result : " + idRequest);
ingestExternalResponse = VitamApiProxyRequest.Ingest().getATR(requestInfo, idRequest);
String atr = ingestExternalResponse.body();
//System.out.println(atr);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonIngestExternalResponse = mapper.readTree(ingestExternalResponse.body());
String responseCode = jsonIngestExternalResponse.get("httpCode").asText();
if(!responseCode.equals("404")) {
return atr ;
}
System.out.println(responseCode);
int responseCode = ingestExternalResponse.statusCode();
if(responseCode == 200) {
String atr = ingestExternalResponse.body();
return atr ;
}
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
......@@ -125,10 +123,8 @@ public class VitamArchiveService implements ArchiveService {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.err.println("Erreur : Pas d'ATR");
return null;
}
}
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