Append feature

pull/1/head
Fabio Sinibaldi 4 years ago
parent 847046a06d
commit ad5755c7e3

@ -2,4 +2,5 @@ eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

@ -230,11 +230,21 @@ public class Translator {
if(targetElementFound==null || targetElementFound.size()==0 || targetElementFound.get(0)==null) {
// targetCtx=targetCtx.add(mapping.getTargetPath(),Collections.singletonList("nothing"));
targetCtx=Parsing.addElement(targetCtx, mapping.getTargetPath());
}
// apply resulting value
}
targetCtx=targetCtx.put(mapping.getTargetPath(),mapping.getTargetElement(),resultingValue);
if(mapping.getTargetElement().getAppend()){
String original=((List<String>)targetCtx.read(mapping.getTargetPath()+"."+mapping.getTargetElement().getTargetElement())).get(0);
if(original!=null && !original.isEmpty())
resultingValue=original+resultingValue;
}
targetCtx=targetCtx.put(mapping.getTargetPath(),mapping.getTargetElement().getTargetElement(),
resultingValue);
}
}catch(Throwable t) {
throw new TransformationException("Exception while applying "+mapping,t);

@ -15,6 +15,7 @@ import org.gcube.data.publishing.ckan2zenodo.model.parsing.Mapping;
import org.gcube.data.publishing.ckan2zenodo.model.parsing.Mapping.Regexp;
import org.gcube.data.publishing.ckan2zenodo.model.parsing.Mapping.Source;
import org.gcube.data.publishing.ckan2zenodo.model.parsing.Mapping.Source.Value;
import org.gcube.data.publishing.ckan2zenodo.model.parsing.Mapping.TargetElement;
import org.gcube.data.publishing.ckan2zenodo.model.parsing.ResourceFilter;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
@ -67,13 +68,23 @@ public class IS {
Source source=new Source();
for(int j=0;j<valuesNodeList.getLength();j++) {
Element valueElement=(Element) valuesNodeList.item(j);
source.getValues().add(new Value(Value.Type.valueOf(valueElement.getAttribute("type")),
valueElement.getTextContent()));
Value valueObject=new Value(Value.Type.valueOf(valueElement.getAttribute("type")),
valueElement.getTextContent());
if(valueElement.hasAttribute("split"))
valueObject.setSplit(valueElement.getAttribute("split"));
source.getValues().add(valueObject);
}
String targetPath=mapping.getElementsByTagName("targetPath").item(0).getTextContent();
String targetElement=mapping.getElementsByTagName("targetElement").item(0).getTextContent();
Element targetElement=(Element) mapping.getElementsByTagName("targetElement").item(0);
TargetElement targetObject=new TargetElement(targetElement.getTextContent());
if(targetElement.hasAttribute("append"))
targetObject.setAppend(Boolean.parseBoolean(targetElement.getAttribute("append")));
HashMap<String,String> values=new HashMap<>();
NodeList valueMappings=mapping.getElementsByTagName("valueMapping");
@ -100,7 +111,7 @@ public class IS {
}
toReturn.add(new Mapping(source,targetPath,targetElement,values,regularExpressions));
toReturn.add(new Mapping(source,targetPath,targetObject,values,regularExpressions));
}

@ -41,7 +41,7 @@ public class Mapping {
public static enum Type{
jsonPath,constant
}
@Setter
private String split;
@NonNull
private Type type;
@ -52,13 +52,23 @@ public class Mapping {
private List<Value> values=new ArrayList<>();
}
@Getter
@ToString
@RequiredArgsConstructor
public static class TargetElement{
@Setter
private Boolean append = false;
@NonNull
private String targetElement;
}
@NonNull
private Source source;
@NonNull
private String targetPath;
@NonNull
private String targetElement;
private TargetElement targetElement;
@NonNull
private HashMap<String,String> valueMapping;
@NonNull

@ -58,7 +58,7 @@
<source>
<value type="jsonPath">$.extras[?(@.key=='Identity:Owner')].value</value>
</source>
<targetPath>$.metadata.contributors[3]</targetPath>
<targetPath>$.metadata.contributors[*]</targetPath>
<targetElement>name</targetElement>
</mapping>
@ -66,7 +66,7 @@
<source>
<value type="constant">ContactPerson</value>
</source>
<targetPath>$.metadata.contributors[3]</targetPath>
<targetPath>$.metadata.contributors[*]</targetPath>
<targetElement>type</targetElement>
</mapping>
@ -146,14 +146,14 @@
<value type="jsonPath">$.extras[?(@.key=='AccessMode:Accessibility')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>access_conditions</targetElement>
<targetElement append="true">access_conditions</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>AccessMode.Accessibility : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>;</replacement>
<replacement>; </replacement>
</regexp>
</mapping>
@ -163,8 +163,15 @@
<value type="jsonPath">$.extras[?(@.key=='AccessMode:Availability')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>access_conditions</targetElement>
<targetElement append="true">access_conditions</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>AccessMode.Availability : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
<!-- AccessMode:AccessibilityMode -->
@ -173,7 +180,15 @@
<value type="jsonPath">$.extras[?(@.key=='AccessMode:AccessibilityMode')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>access_conditions</targetElement>
<targetElement append="true">access_conditions</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>AccessMode.AccessibilityMode : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
@ -183,7 +198,15 @@
<value type="jsonPath">$.extras[?(@.key=='TechnicalDetails:ProcessingDegree')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>notes</targetElement>
<targetElement append="true">notes</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>TechnicalDetails.ProcessingDegree : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
<!-- TechnicalDetails:ManifestationType -->
@ -192,7 +215,15 @@
<value type="jsonPath">$.extras[?(@.key=='TechnicalDetails:ManifestationType')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>notes</targetElement>
<targetElement append="true">notes</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>TechnicalDetails.ManifestationType : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
<!-- TechnicalDetails:Language -->
@ -210,7 +241,15 @@
<value type="jsonPath">$.extras[?(@.key=='TechnicalDetails:Size')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>notes</targetElement>
<targetElement append="true">notes</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>TechnicalDetails.Size : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
<!-- TechnicalDetails:DiskSize -->
@ -219,7 +258,15 @@
<value type="jsonPath">$.extras[?(@.key=='TechnicalDetails:DiskSize')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>notes</targetElement>
<targetElement append="true">notes</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>TechnicalDetails.DiskSize : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
<!-- TechnicalDetails:Format -->
@ -228,7 +275,15 @@
<value type="jsonPath">$.extras[?(@.key=='TechnicalDetails:Format')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>notes</targetElement>
<targetElement append="true">notes</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>TechnicalDetails.Format : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
<!-- TechnicalDetails:FormatSchema -->
@ -237,7 +292,15 @@
<value type="jsonPath">$.extras[?(@.key=='TechnicalDetails:FormatSchema')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>notes</targetElement>
<targetElement append="true">notes</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>TechnicalDetails.FormatSchema : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
@ -247,7 +310,15 @@
<value type="jsonPath">$.extras[?(@.key=='DataProtection:PersonalData')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>notes</targetElement>
<targetElement append="true">notes</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>DataProtection.PersonalData : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
<!-- DataProtection:PersonalSensitiveData -->
@ -256,7 +327,15 @@
<value type="jsonPath">$.extras[?(@.key=='DataProtection:PersonalSensitiveData')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>notes</targetElement>
<targetElement append="true">notes</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>DataProtection.PersonalSensitiveData : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
@ -266,7 +345,15 @@
<value type="jsonPath">$.extras[?(@.key=='DataProtection:Consent of the data subject')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>notes</targetElement>
<targetElement append="true">notes</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>DataProtection.Consent of the data subject : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
<!-- DataProtection:Consent obtained also covers the envisaged transfer of the personal data outside the EU -->
@ -275,7 +362,15 @@
<value type="jsonPath">$.extras[?(@.key=='DataProtection:Consent obtained also covers the envisaged transfer of the personal data outside the EU')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>notes</targetElement>
<targetElement append="true">notes</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>DataProtection.Consent obtained also covers the envisaged transfer of the personal data outside the EU : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
<!-- DataProtection:Personal data was manifestly made public by the data subject -->
@ -284,7 +379,15 @@
<value type="jsonPath">$.extras[?(@.key=='DataProtection:Personal data was manifestly made public by the data subject')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>notes</targetElement>
<targetElement append="true">notes</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>DataProtection.Personal data was manifestly made public by the data subject : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
<!-- DataProtection:DataProtectionDirective -->
@ -293,7 +396,15 @@
<value type="jsonPath">$.extras[?(@.key=='DataProtection:PersonalSensitiveData')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>notes</targetElement>
<targetElement append="true">notes</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>DataProtection.DataProtectionDirective : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
@ -303,7 +414,15 @@
<value type="jsonPath">$.extras[?(@.key=='Rights:IP/Copyrights')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>notes</targetElement>
<targetElement append="true">notes</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>Rights.IP/Copyrights : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
<!-- Rights:Field/Scope of use -->
@ -312,7 +431,15 @@
<value type="jsonPath">$.extras[?(@.key=='Rights:Field/Scope of use')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>notes</targetElement>
<targetElement append="true">notes</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>Rights.Field/Scope of use : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
@ -322,7 +449,15 @@
<value type="jsonPath">$.extras[?(@.key=='Rights:Basic rights')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>notes</targetElement>
<targetElement append="true">notes</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>Rights.Basic rights : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
@ -332,7 +467,15 @@
<value type="jsonPath">$.extras[?(@.key=='Rights:Restrictions on use')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>notes</targetElement>
<targetElement append="true">notes</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>Rights.Restrictions on use : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
@ -342,7 +485,15 @@
<value type="jsonPath">$.extras[?(@.key=='Rights:Sublicense rights')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>notes</targetElement>
<targetElement append="true">notes</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>Rights.Sublicense rights : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
<!-- Rights:Territory of use -->
@ -351,7 +502,15 @@
<value type="jsonPath">$.extras[?(@.key=='Rights:Territory of use')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>notes</targetElement>
<targetElement append="true">notes</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>Rights.Territory of use : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
<!-- Rights:License term -->
@ -360,7 +519,15 @@
<value type="jsonPath">$.extras[?(@.key=='Rights:License term')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>notes</targetElement>
<targetElement append="true">notes</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>Rights.License term : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
@ -370,7 +537,15 @@
<value type="jsonPath">$.extras[?(@.key=='Rights:Requirement of non-disclosure (confidentiality mark)')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>notes</targetElement>
<targetElement append="true">notes</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>Rights.Requirement of non-disclosure (confidentiality mark) : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
@ -380,7 +555,15 @@
<value type="jsonPath">$.extras[?(@.key=='Attribution:Attribution requirements')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>notes</targetElement>
<targetElement append="true">notes</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>Attribution.Attribution requirements : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
@ -390,7 +573,15 @@
<value type="jsonPath">$.extras[?(@.key=='Attribution:Attribution requirements')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>notes</targetElement>
<targetElement append="true">notes</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>Attribution.Display requirements : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
@ -400,7 +591,15 @@
<value type="jsonPath">$.extras[?(@.key=='Attribution:Distribution requirements')].value</value>
</source>
<targetPath>$.metadata</targetPath>
<targetElement>notes</targetElement>
<targetElement append="true">notes</targetElement>
<regexp type="replace">
<target>^</target>
<replacement>Attribution.Distribution requirements : </replacement>
</regexp>
<regexp type="replace">
<target>$</target>
<replacement>; </replacement>
</regexp>
</mapping>
</mappings>

Loading…
Cancel
Save