This commit is contained in:
Fabio Sinibaldi 2022-11-22 14:58:17 +01:00
parent 9954a653f7
commit cdff7547a5
2 changed files with 69 additions and 13 deletions

View File

@ -14,8 +14,8 @@ public class GCubeTest {
// InterfaceConstants.SERVICE_CLASS="Application";
// InterfaceConstants.SERVICE_NAME="GeoPortal";
// testContext = "/pred4s/preprod/preVRE";
testContext= "/gcube/devsec/devVRE";
testContext = "/pred4s/preprod/preVRE";
// testContext= "/gcube/devsec/devVRE";
System.out.println("TEST CONTEXT = "+testContext);
return testContext;

View File

@ -90,36 +90,37 @@ public class ExportConcessioniAsProjects {
AtomicLong warnCount = new AtomicLong(0);
AtomicLong errCount = new AtomicLong(0);
ExecutorService service = Executors.newFixedThreadPool(3);
ExecutorService service = Executors.newFixedThreadPool(1);
long startProcess = System.currentTimeMillis();
importFolder.getRelationshipMap().forEach((s,l)->{
AtomicReference<Boolean> isSetOk = new AtomicReference<>(true);
AtomicReference<Boolean> publish = new AtomicReference<>(true);
AtomicReference<Boolean> delete = new AtomicReference<>(false);
// Check if exists
Concessione c = l.get(0);
try {
List<Project> existing= getExisting(c,client);
if(existing.isEmpty()) {
log.info("Not Found");
}else {
if(existing.isEmpty()) log.info("Not Found {}",c.getNome());
else {
// found projects, check status
existing.forEach(project -> {
if (!project.getLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
isSetOk.set(false);
delete.set(true);
});
if(!isSetOk.get()){
if(delete.get()){
log.debug("Deleting error set for {}",c.getNome());
for (Project project : existing) {
client.deleteById(project.getId());
}
}
}else publish.set(false);
}
}catch(NullPointerException e){}
catch (Throwable t){throw new RuntimeException("Unexpected Exception while checking for "+c.getNome());}
if(!isSetOk.get()) {
log.info("Project name {} publish : {}",s,publish);
if(publish.get()) {
String relationshipTarget = null;
for (Concessione concessione : l) {
@ -426,7 +427,7 @@ public class ExportConcessioniAsProjects {
private static List<Project> getExisting(Concessione c,Projects client) throws RemoteException, JsonProcessingException, NullPointerException {
try {
QueryRequest req = new QueryRequest();
String queryString = String.format("{\"_theDocument.nome\" :{\"$eq\" : \"%1$s\"}}", c.getNome());
String queryString = String.format("{\"_theDocument.nome\" :{\"$eq\" : %1$s}}", quote(c.getNome()));
log.debug("Query String is {}", queryString);
req.setFilter(Document.parse(queryString));
AtomicInteger count = new AtomicInteger(0);
@ -446,4 +447,59 @@ public class ExportConcessioniAsProjects {
throw t;
}
}
public static String quote(String string) {
if (string == null || string.length() == 0) {
return "\"\"";
}
char c = 0;
int i;
int len = string.length();
StringBuilder sb = new StringBuilder(len + 4);
String t;
sb.append('"');
for (i = 0; i < len; i += 1) {
c = string.charAt(i);
switch (c) {
case '\\':
case '"':
sb.append('\\');
sb.append(c);
break;
case '/':
// if (b == '<') {
sb.append('\\');
// }
sb.append(c);
break;
case '\b':
sb.append("\\b");
break;
case '\t':
sb.append("\\t");
break;
case '\n':
sb.append("\\n");
break;
case '\f':
sb.append("\\f");
break;
case '\r':
sb.append("\\r");
break;
default:
if (c < ' ') {
t = "000" + Integer.toHexString(c);
sb.append("\\u" + t.substring(t.length() - 4));
} else {
sb.append(c);
}
}
}
sb.append('"');
return sb.toString();
}
}