65 lines
1.6 KiB
Java
65 lines
1.6 KiB
Java
package org.gcube.data.publishing.ckan2zenodo;
|
|
|
|
import com.jayway.jsonpath.DocumentContext;
|
|
import com.jayway.jsonpath.JsonPath;
|
|
import com.jayway.jsonpath.PathNotFoundException;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
@Slf4j
|
|
public class Fixer {
|
|
|
|
|
|
public static final String fixIncoming(String toFix) {
|
|
DocumentContext ctx=JsonPath.parse(toFix);
|
|
|
|
|
|
ctx=fixIncomingDate(ctx, "$.created");
|
|
ctx=fixIncomingDate(ctx, "$.modified");
|
|
|
|
return ctx.jsonString();
|
|
}
|
|
|
|
|
|
public static String fixSending(String toFix) {
|
|
DocumentContext ctx=JsonPath.parse(toFix);
|
|
|
|
fixOutgoingDate(ctx, "$.created");
|
|
fixOutgoingDate(ctx, "$.modified");
|
|
|
|
return ctx.jsonString();
|
|
}
|
|
|
|
//*** INCOMINGs
|
|
private static final DocumentContext fixIncomingDate(DocumentContext ctx,String toFixPath) {
|
|
try {
|
|
StringBuilder toFix=new StringBuilder(ctx.read(toFixPath));
|
|
|
|
|
|
ctx.put(toFixPath.substring(0,toFixPath.lastIndexOf(".")),
|
|
toFixPath.substring(toFixPath.lastIndexOf(".")+1),
|
|
toFix.deleteCharAt(toFix.lastIndexOf(":")).toString());
|
|
}catch(Throwable e) {
|
|
log.warn("Unable to fix "+toFixPath+". Cause : ",e);
|
|
}
|
|
return ctx;
|
|
}
|
|
|
|
|
|
//*** OUTGOINGs
|
|
|
|
private static final DocumentContext fixOutgoingDate(DocumentContext ctx,String toFixPath) {
|
|
try{
|
|
String toFix=ctx.read(toFixPath);
|
|
|
|
ctx.put(toFixPath.substring(0,toFixPath.lastIndexOf(".")),
|
|
toFixPath.substring(toFixPath.lastIndexOf(".")+1),
|
|
toFix.substring(0,toFix.length()-2)+":"+
|
|
toFix.substring(toFix.length()-2, toFix.length()));
|
|
}catch(Throwable t) {
|
|
log.debug("Unable to fix "+toFixPath+".Cause : ",t);
|
|
}
|
|
return ctx;
|
|
}
|
|
}
|