Commits (12)
......@@ -317,13 +317,11 @@ any resulting litigation.
<import plugin="org.eclipse.emf.ecore"/>
<import plugin="org.eclipse.xtext"/>
<import plugin="org.etsi.mts.tdl.model"/>
<import plugin="org.etsi.mts.tdl.TPLan2"/>
<import plugin="org.eclipse.ocl.xtext.essentialocl"/>
<import plugin="org.etsi.mts.tdl.common"/>
<import plugin="org.eclipse.emf.common"/>
<import plugin="com.reprezen.swagedit.openapi3"/>
<import plugin="com.reprezen.swagedit.core"/>
<import plugin="com.reprezen.swagedit.dependencies"/>
<import plugin="org.etsi.mts.tdl.helper"/>
<import plugin="org.etsi.mts.tdl.TPLan2"/>
</requires>
<plugin
......@@ -348,24 +346,36 @@ any resulting litigation.
unpack="false"/>
<plugin
id="org.etsi.mts.tdl.openapi2tdl"
id="org.etsi.mts.tdl.asn2tdl"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
<plugin
id="org.etsi.mts.tdl.asn2tdl"
id="org.etsi.mts.tdl.to2tdl"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
<plugin
id="org.etsi.mts.tdl.to2tdl"
id="org.etsi.mts.tdl.json2tdl"
download-size="0"
install-size="0"
version="0.0.0"/>
<plugin
id="org.etsi.mts.tdl.openapi2tdl.next"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
<plugin
id="org.etsi.mts.tdl.openapi.generator.wrapper"
download-size="0"
install-size="0"
version="0.0.0"/>
</feature>
......@@ -12,6 +12,7 @@ import org.etsi.mts.tdl.Annotation;
import org.etsi.mts.tdl.AnnotationType;
import org.etsi.mts.tdl.Constraint;
import org.etsi.mts.tdl.ConstraintType;
import org.etsi.mts.tdl.DataElementMapping;
import org.etsi.mts.tdl.DataResourceMapping;
import org.etsi.mts.tdl.DataType;
import org.etsi.mts.tdl.Element;
......@@ -20,6 +21,9 @@ import org.etsi.mts.tdl.EnumDataType;
import org.etsi.mts.tdl.NamedElement;
import org.etsi.mts.tdl.Package;
import org.etsi.mts.tdl.PackageableElement;
import org.etsi.mts.tdl.Parameter;
import org.etsi.mts.tdl.ParameterBinding;
import org.etsi.mts.tdl.ParameterMapping;
import org.etsi.mts.tdl.SimpleDataType;
import org.etsi.mts.tdl.StructuredDataType;
import org.etsi.mts.tdl.tdlFactory;
......@@ -34,6 +38,10 @@ public abstract class AbstractTranslator {
protected SimpleDataType referencedType;
protected boolean useQualifiers = true;
protected boolean fullPrefix = false;
protected String sourceMappingTag = "SOURCE_MAPPING";
protected String targetMappingTag = "TARGET_MAPPING";
public AbstractTranslator() {
super();
}
......@@ -73,7 +81,8 @@ public abstract class AbstractTranslator {
public String cleanName(String name) {
//TODO: use keywords filter?
List<String> keywords = List.of("Message", "Time", "Type", "type", "name", "instance", "size", "component");
// List<String> keywords = List.of("Message", "Time", "Type", "type", "name", "instance", "size", "component");
List<String> keywords = List.of("Message", "Time", "Type", "instance", "size", "component");
if (keywords.contains(name)) {
name = "^"+name;
}
......@@ -182,7 +191,24 @@ public abstract class AbstractTranslator {
generatedType.getConstraint().add(constraint);
}
}
protected DataElementMapping addDataElementMapping(String uri, DataType dataType, String tag) {
DataElementMapping mapping = getTypeFor(dataType.getName()+"_"+tag, tdlPackage.Literals.DATA_ELEMENT_MAPPING);
mapping.setMappableDataElement(dataType);
mapping.setElementURI(uri);
mapping.setDataResourceMapping(drm);
return mapping;
}
protected void addParameterMapping(DataElementMapping mapping, Parameter p, String uri) {
Optional<ParameterMapping> opm = getContentWithPredicate(e->e.getParameter() == p, mapping, ParameterMapping.class);
if (opm.isEmpty()) {
ParameterMapping pm = (ParameterMapping) tdlFactory.eINSTANCE.create(tdlPackage.Literals.PARAMETER_MAPPING);
pm.setParameter(p);
pm.setParameterURI(uri.replaceAll("\\^", ""));
mapping.getParameterMapping().add(pm);
}
}
public Resource getTargetResource() {
return targetResource;
......
......@@ -18,7 +18,8 @@ Require-Bundle: org.eclipse.ui,
org.etsi.mts.tdl.common,
org.etsi.mts.tdl.asn2tdl,
org.etsi.mts.tdl.openapi2tdl.next,
org.etsi.mts.tdl.to2tdl
org.etsi.mts.tdl.to2tdl,
org.etsi.mts.tdl.json2tdl
Bundle-ActivationPolicy: lazy
Import-Package: org.eclipse.emf.common.util
Bundle-RequiredExecutionEnvironment: JavaSE-11
......@@ -12,7 +12,6 @@ import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
......@@ -23,15 +22,15 @@ import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.internal.ide.dialogs.InternalErrorDialog;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.xtext.resource.XtextResourceSet;
import org.eclipse.xtext.ui.resource.IResourceSetProvider;
import org.etsi.mts.tdl.Package;
import org.etsi.mts.tdl.asn2tdl.ASN2TDLTranslator;
import org.etsi.mts.tdl.json2tdl.JSON2TDLTranslator;
import org.etsi.mts.tdl.openapi2tdl.next.OpenAPI2TDLTranslatorNext;
import org.etsi.mts.tdl.to2tdl.TO2TDLTranslator;
import org.osgi.framework.Bundle;
import org.etsi.mts.tdl.transform.AbstractTranslator;
import com.google.inject.Guice;
import com.google.inject.Inject;
......@@ -129,34 +128,17 @@ public class TranslationHandler extends AbstractHandler {
URI targetURI = URI.createURI(uri.toString()+"-generated."+extension);
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
Resource tr = resourceSet.createResource(targetURI);
AbstractTranslator translator = null;
if (type.contains("asn")) {
ASN2TDLTranslator translator = new ASN2TDLTranslator();
translator.setTargetResource(tr);
translator.initTargetResource(translator.cleanName(file.getName()));
try {
translator.translate(filepath);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
MessageDialog errorDialog = new MessageDialog(
Display.getDefault().getActiveShell(),
"Translation error...",
null,
"An error occurred during the translation. "
+ "It may be due to problems occurring while processing the input, "
+ "e.g if the input could not be processed. "
+ "See details for a more technical description:\n\n"
+ e.getMessage()
,
MessageDialog.ERROR,
0,
new String[] {"OK"});
errorDialog.open();
}
translator = new ASN2TDLTranslator();
}
if (type.contains("json")) {
translator = new JSON2TDLTranslator();
}
if (type.contains("yaml")) {
OpenAPI2TDLTranslatorNext translator = new OpenAPI2TDLTranslatorNext();
translator = new OpenAPI2TDLTranslatorNext();
}
if (translator != null) {
translator.setTargetResource(tr);
translator.initTargetResource(translator.cleanName(file.getName()));
try {
......@@ -164,57 +146,50 @@ public class TranslationHandler extends AbstractHandler {
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
MessageDialog errorDialog = new MessageDialog(
Display.getDefault().getActiveShell(),
"Translation error...",
null,
"An error occurred during the translation. "
+ "It may be due to problems occurring while processing the input, "
+ "e.g if the input could not be processed. "
+ "See details for a more technical description:\n\n"
+ e.getMessage()
,
MessageDialog.ERROR,
0,
new String[] {"OK"});
errorDialog.open();
showErrorDialog(e);
}
}
}
if (type.contains("tplan2")) { //TODO: also new syntax
Resource r = rs.getResource(uri, true);
Package p = (Package) r.getContents().get(0);
TO2TDLTranslator translator = new TO2TDLTranslator();
translator = new TO2TDLTranslator();
translator.setTargetResource(tr);
translator.initTargetResource("generated_from_"+p.getName());
translator.addImports(p);
translator.transform(p);
((TO2TDLTranslator)translator).transform(p);
}
//tr.getContents().addAll(EcoreUtil.copyAll(r.getContents()));
try {
tr.save(null);
} catch (Exception e1) {
} catch (Exception e) {
// TODO Auto-generated catch block
e1.printStackTrace();
MessageDialog errorDialog = new MessageDialog(
Display.getDefault().getActiveShell(),
"Translation error...",
null,
"An error occurred during the translation. "
+ "It may be due to problems occurring while storing the output. "
+ "See details for a more technical description and consider usind a different target format:\n\n"
+ e1.getMessage()
,
MessageDialog.ERROR,
0,
new String[] {"OK"});
errorDialog.open();
e.printStackTrace();
showErrorDialog(e);
}
}
}
//TODO: throw proper execution exceptions?
return null;
}
private void showErrorDialog(Exception e) {
MessageDialog errorDialog = new MessageDialog(
Display.getDefault().getActiveShell(),
"Translation error...",
null,
"An error occurred during the translation. "
+ "It may be due to problems occurring while processing the input, "
+ "e.g if the input could not be processed. "
+ "See details for a more technical description:\n\n"
+ e.getMessage()
,
MessageDialog.ERROR,
0,
new String[] {"OK"});
errorDialog.open();
}
public void init(IWorkbenchWindow window) {
this.window = window;
......
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/gson-2.9.1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.etsi.mts.tdl.json2tdl</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
encoding/<project>=UTF-8
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=11
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Json2tdl
Bundle-SymbolicName: org.etsi.mts.tdl.json2tdl
Bundle-Version: 1.0.0.qualifier
Export-Package: org.etsi.mts.tdl.json2tdl
Require-Bundle: org.etsi.mts.tdl.common,
org.eclipse.emf.ecore
Automatic-Module-Name: org.etsi.mts.tdl.json2tdl
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
package org.etsi.mts.tdl.json2tdl;
import java.io.File;
import java.io.FileReader;
import java.util.Map;
import java.util.Map.Entry;
import org.etsi.mts.tdl.CollectionDataInstance;
import org.etsi.mts.tdl.CollectionDataType;
import org.etsi.mts.tdl.DataElementMapping;
import org.etsi.mts.tdl.DataElementUse;
import org.etsi.mts.tdl.DataType;
import org.etsi.mts.tdl.DataUse;
import org.etsi.mts.tdl.LiteralValueUse;
import org.etsi.mts.tdl.Member;
import org.etsi.mts.tdl.MemberAssignment;
import org.etsi.mts.tdl.ParameterBinding;
import org.etsi.mts.tdl.StructuredDataInstance;
import org.etsi.mts.tdl.StructuredDataType;
import org.etsi.mts.tdl.tdlFactory;
import org.etsi.mts.tdl.tdlPackage;
import org.etsi.mts.tdl.transform.AbstractTranslator;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class JSON2TDLTranslator extends AbstractTranslator{
private static final String JSON_STRING = "JSON_String";
//for reference and debugging
private void dumpJson(String prefix, Map.Entry<String,JsonElement> e) {
System.out.println();
System.out.print(prefix+"\t"+e.getKey() + ":");
dumpJson(prefix + "\t", e.getValue());
}
//for reference and debugging
private void dumpJson(String prefix, JsonElement e) {
if (e.isJsonArray()) {
((JsonArray) e).forEach(a -> dumpJson(prefix + "\t", a));
} else if (e.isJsonObject()) {
((JsonObject) e).entrySet().forEach(a -> dumpJson(prefix + "\t", a));
} else if (e.isJsonPrimitive()) {
System.out.print(" "+e);
}
}
//inherited entry point
@Override
public void translate(String targetFilename) throws Exception {
String sourceMappingTag = "SOURCE_MAPPING";
drm = getTypeFor(sourceMappingTag, tdlPackage.Literals.DATA_RESOURCE_MAPPING);
drm.setResourceURI(new File(targetFilename).getName());
try {
//TODO: import and extend body? or how is the content to be referenced
//TODO: add model name as prefix for disambiguation? -> optional
JsonElement jsonElement = JsonParser.parseReader(new FileReader(targetFilename));
dumpJson("", jsonElement);
System.out.println();
String prefix = "JSON";
getSimpleDataTypeFor(JSON_STRING);
translate(prefix, jsonElement);
//DONE: data instances as well? -> only one data instance,
//TODO: make optional
//TODO: add more sophisticated name? make configurable
//TODO: error reporting
translateInstance(prefix, jsonElement);
drm = getTypeFor(sourceMappingTag, tdlPackage.Literals.DATA_RESOURCE_MAPPING);
drm.setResourceURI(new File(targetFilename).getName());
addMappings(prefix, jsonElement);
//update with unique name, only after everything is in place
//TODO: make optional / configurable
DataType root = getDataTypeFor(prefix);
root.setName(prefix+"_"+cleanName(drm.getResourceURI()));
//TODO: add optional extends Body? needs also corresponding import
//using a wrapper may be more adequate
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//translate elements
private void translate(String prefix, JsonElement e) {
if (e.isJsonArray()) {
String iPrefix = prefix+"_item";
CollectionDataType collectionType = getTypeFor(prefix, tdlPackage.Literals.COLLECTION_DATA_TYPE);
((JsonArray) e).forEach(a -> translate(iPrefix, a));
DataType itemType = getDataTypeFor(JSON_STRING);
if (!e.getAsJsonArray().isEmpty()) {
if (e.getAsJsonArray().get(0).isJsonPrimitive()) {
} else {
itemType = getDataTypeFor(iPrefix);
}
}
collectionType.setItemType(itemType);
} else if (e.isJsonObject()) {
StructuredDataType dataType = getStructuredDataTypeFor(prefix);
((JsonObject) e).entrySet().forEach(a -> translate(prefix, a));
} else if (e.isJsonPrimitive()) {
//TODO: needs handling?
// System.out.print(" "+e);
}
}
//translate assignments
private void translate(String prefix, Map.Entry<String,JsonElement> e) {
//TODO: extract prefixing scheme / method
String iPrefix = "JSON_"+e.getKey(); //short prefix
//TODO: make configurable: default: last segment only -> explain possible issues
//TODO: also for YAML/ASN.1 imports
//TODO: can we make name, type, component not be restricted names?
if (fullPrefix) {
iPrefix = prefix+"_"+e.getKey(); //full prefix
}
translate(iPrefix, e.getValue());
StructuredDataType dataType = getStructuredDataTypeFor(prefix);
//TODO: deduplicate types?
//TODO: handle booleans and integers?
//TODO: add mappings to reconstruct JSON
//DONE: permit "-" and ":" in names? -> "-" feasible / enabled, ":" more challenging due to wide use,
//note also mapping to target which will require substitution in any case
//TODO: make substitution configurable
Member m = getContentWithName(e.getKey(), dataType, tdlPackage.Literals.MEMBER);
DataType memberType = getSimpleDataTypeFor(JSON_STRING);
if (!e.getValue().isJsonPrimitive()) {
memberType = getDataTypeFor(iPrefix);
}
m.setDataType(memberType);
dataType.getMember().add(m);
}
//translate elements
private void addMappings(String prefix, JsonElement e) {
if (e.isJsonArray()) {
String iPrefix = prefix+"_item";
CollectionDataType collectionType = getTypeFor(prefix, tdlPackage.Literals.COLLECTION_DATA_TYPE);
((JsonArray) e).forEach(a -> addMappings(iPrefix, a));
//TODO: what about the rest?
} else if (e.isJsonObject()) {
StructuredDataType dataType = getStructuredDataTypeFor(prefix);
//TODO: make replacement optional, more robust
DataElementMapping addDataElementMapping = addDataElementMapping(prefix.replaceAll("_", "."), dataType, sourceMappingTag);
((JsonObject) e).entrySet().forEach(a -> addMappings(prefix, a));
} else if (e.isJsonPrimitive()) {
//TODO: needs handling?
// System.out.print(" "+e);
}
}
//translate assignments
private void addMappings(String prefix, Map.Entry<String,JsonElement> e) {
//TODO: extract prefixing scheme / method
String iPrefix = "JSON_"+e.getKey(); //short prefix
if (fullPrefix) {
iPrefix = prefix+"_"+e.getKey(); //full prefix
}
StructuredDataType dataType = getStructuredDataTypeFor(prefix);
Member m = getContentWithName(e.getKey(), dataType, tdlPackage.Literals.MEMBER);
DataElementMapping sourceMapping = getTypeFor(prefix+"_"+sourceMappingTag, tdlPackage.Literals.DATA_ELEMENT_MAPPING);
addParameterMapping(sourceMapping, m, e.getKey());
//TODO: fully qualified uris?
addMappings(iPrefix, e.getValue());
}
//first level: data instance
private void translateInstance(String prefix, JsonElement e) {
if (e.isJsonArray()) {
String iPrefix = prefix + "_item";
CollectionDataType collectionType = getTypeFor(prefix, tdlPackage.Literals.COLLECTION_DATA_TYPE);
CollectionDataInstance cInstance = getTypeFor(prefix+"_instance", tdlPackage.Literals.COLLECTION_DATA_INSTANCE);
cInstance.setDataType(collectionType);
((JsonArray) e).forEach(a -> cInstance.getItem().add(translateDataUse(iPrefix, a)));
} else if (e.isJsonObject()) {
StructuredDataType dataType = getStructuredDataTypeFor(prefix);
StructuredDataInstance eInstance = getTypeFor(prefix+"_instance", tdlPackage.Literals.STRUCTURED_DATA_INSTANCE);
eInstance.setDataType(dataType);
((JsonObject) e).entrySet().forEach(a->eInstance.getMemberAssignment().add(translateMemberAssignment(prefix, a)));
} else if (e.isJsonPrimitive()) {
System.out.print(" " + e);
//TODO: complete?
}
}
//TODO: move to parent? -> too specific, abstract away..
//first level: data instance member assignments
private MemberAssignment translateMemberAssignment(String prefix, Map.Entry<String,JsonElement> e) {
StructuredDataType dataType = getStructuredDataTypeFor(prefix);
Member m = getContentWithName(e.getKey(), dataType, tdlPackage.Literals.MEMBER);
DataUse du = translateDataUse(m.getDataType().getName(), e.getValue());
MemberAssignment ma = (MemberAssignment) tdlFactory.eINSTANCE.create(tdlPackage.Literals.MEMBER_ASSIGNMENT);
ma.setMember(m);
ma.setMemberSpec(du);
return ma;
}
//nested levels: data use
private DataUse translateDataUse(String prefix, JsonElement e) {
if (e.isJsonArray()) {
String iPrefix = prefix + "_item";
DataElementUse du = (DataElementUse) tdlFactory.eINSTANCE.create(tdlPackage.Literals.DATA_ELEMENT_USE);
((JsonArray) e).forEach(a -> du.getItem().add(translateDataUse(iPrefix, a)));
return du;
} else if (e.isJsonObject()) {
DataElementUse du = (DataElementUse) tdlFactory.eINSTANCE.create(tdlPackage.Literals.DATA_ELEMENT_USE);
((JsonObject) e).entrySet().forEach(a-> du.getArgument().add(translateParameterBindings(prefix, a)));
return du;
} else if (e.isJsonPrimitive()) {
LiteralValueUse lvu = (LiteralValueUse) tdlFactory.eINSTANCE.create(tdlPackage.Literals.LITERAL_VALUE_USE);
lvu.setValue(e.getAsString());;
return lvu;
} else {
//TODO: what should happen here?
return null;
}
}
//nested levels: parameter bindings
private ParameterBinding translateParameterBindings(String prefix, Entry<String, JsonElement> a) {
StructuredDataType dataType = getStructuredDataTypeFor(prefix);
Member m = getContentWithName(a.getKey(), dataType, tdlPackage.Literals.MEMBER);
ParameterBinding pb = (ParameterBinding) tdlFactory.eINSTANCE.create(tdlPackage.Literals.PARAMETER_BINDING);
pb.setParameter(m);
pb.setDataUse(translateDataUse(m.getDataType().getName(), a.getValue()));
return pb;
}
}
......@@ -4,7 +4,8 @@ bin.includes = .,\
model/,\
META-INF/,\
plugin.xml,\
plugin.properties
plugin.properties,\
library/
jars.compile.order = .
source.. = src/,\
src-gen/
......
......@@ -4,6 +4,7 @@ import java.io.File;
import org.eclipse.emf.ecore.resource.Resource;
import org.etsi.mts.tdl.helper.TDLHelper;
import org.etsi.mts.tdl.transform.AbstractTranslator;
import org.openapitools.codegen.utils.ModelUtils;
import io.swagger.parser.OpenAPIParser;
......@@ -43,7 +44,7 @@ public class ConverterNext {
public static String process(String inputPath, String outputPath) {
OpenAPI spec = parseSpec(inputPath);
OpenAPI2TDLTranslatorNext translator = new OpenAPI2TDLTranslatorNext();
AbstractTranslator translator = new OpenAPI2TDLTranslatorNext();
String name = "imported";
try {
Resource tr = TDLHelper.create(outputPath);
......
......@@ -6,10 +6,7 @@ import org.etsi.mts.tdl.CollectionDataType;
import org.etsi.mts.tdl.DataElementMapping;
import org.etsi.mts.tdl.DataType;
import org.etsi.mts.tdl.Member;
import org.etsi.mts.tdl.Parameter;
import org.etsi.mts.tdl.ParameterMapping;
import org.etsi.mts.tdl.StructuredDataType;
import org.etsi.mts.tdl.tdlFactory;
import org.etsi.mts.tdl.tdlPackage;
import org.etsi.mts.tdl.transform.AbstractTranslator;
import org.openapitools.codegen.utils.ModelUtils;
......@@ -27,8 +24,6 @@ public class OpenAPI2TDLTranslatorNext extends AbstractTranslator {
private OpenAPI model;
public void translate(String filename) throws Exception {
String sourceMappingTag = "SOURCE_MAPPING";
String targetMappingTag = "TARGET_MAPPING";
translate(filename, sourceMappingTag, targetMappingTag);
}
......@@ -56,15 +51,10 @@ public class OpenAPI2TDLTranslatorNext extends AbstractTranslator {
}
private void addMapping(Schema<?> schema, DataType dataType, String sourceMappingTag, String targetMappingTag) {
DataElementMapping sourceMapping = getTypeFor(schema.getName()+"_"+sourceMappingTag, tdlPackage.Literals.DATA_ELEMENT_MAPPING);
sourceMapping.setMappableDataElement(dataType);
sourceMapping.setElementURI("#/components/schemas/"+schema.getName()+"");
sourceMapping.setDataResourceMapping(drm);
DataElementMapping sourceMapping = addDataElementMapping("#/components/schemas/"+schema.getName()+"", dataType, sourceMappingTag);
//TODO: make configurable?
DataElementMapping targetMapping = getTypeFor(schema.getName()+"_"+targetMappingTag, tdlPackage.Literals.DATA_ELEMENT_MAPPING);
targetMapping.setMappableDataElement(dataType);
targetMapping.setElementURI(""+schema.getName()+"");
DataElementMapping targetMapping = addDataElementMapping(""+schema.getName()+"", dataType, targetMappingTag);
targetMapping.setDataResourceMapping(drmTarget);
if (dataType instanceof StructuredDataType) {
......@@ -75,13 +65,6 @@ public class OpenAPI2TDLTranslatorNext extends AbstractTranslator {
}
}
private void addParameterMapping(DataElementMapping mapping, Parameter p, String uri) {
ParameterMapping pm = (ParameterMapping) tdlFactory.eINSTANCE.create(tdlPackage.Literals.PARAMETER_MAPPING);
pm.setParameter(p);
pm.setParameterURI(uri.replaceAll("\\^", ""));
mapping.getParameterMapping().add(pm);
}
private DataType translate(Schema<?> schema, String prefix) {
if (schema.getType()==null && (schema.getProperties() == null || schema.getProperties().isEmpty())) {
if (schema.getName() == null) {
......
......@@ -18,5 +18,6 @@ Require-Bundle: org.eclipse.core.runtime,
org.etsi.mts.tdl.openapi2tdl.next,
org.etsi.mts.tdl.constraints,
org.eclipse.epsilon.evl.engine,
org.etsi.mts.tdl.tools.to.docx.poi
org.etsi.mts.tdl.tools.to.docx.poi,
org.etsi.mts.tdl.json2tdl
Bundle-ClassPath: .
{
"ieee802-dot1q-bridge:bridges": {
"bridge": [
{
"name": "ne2",
"address": "10-10-10-10-10-10",
"bridge-type": "ieee802-dot1q-bridge:customer-vlan-bridge",
"component": [
{
"name": "cv0",
"id": 0,
"type": "ieee802-dot1q-bridge:c-vlan-component",
"bridge-port": [
"eth1",
"eth2",
"eth3"
],
"filtering-database": {
"vlan-registration-entry": [
{
"database-id": 1,
"vids": "200",
"entry-type": "static",
"port-map": [
{
"port-ref": 1,
"static-vlan-registration-entries": {
"vlan-transmitted": "tagged"
}
},
{
"port-ref": 3,
"static-vlan-registration-entries": {
"vlan-transmitted": "tagged"
}
}
]
},
{
"database-id": 1,
"vids": "300",
"entry-type": "static",
"port-map": [
{
"port-ref": 2,
"static-vlan-registration-entries": {
"vlan-transmitted": "untagged"
}
},
{
"port-ref": 3,
"static-vlan-registration-entries": {
"vlan-transmitted": "tagged"
}
}
]
}
]
},
"bridge-vlan": {
"vlan": [
{
"vid": 200,
"name": "E-Line 200",
"egress-ports": [
"eth1",
"eth3"
]
},
{
"vid": 300,
"name": "E-Line 300",
"untagged-ports": [
"eth2"
],
"egress-ports": [
"eth2",
"eth3"
]
}
]
}
}
]
}
]
},
"ietf-interfaces:interfaces": {
"interface": [
{
"name": "eth1",
"type": "iana-if-type:ethernetCsmacd",
"oper-status": "up",
"statistics": {
"discontinuity-time": "2022-04-06T11:00:00+02:00"
},
"ieee802-dot1q-bridge:bridge-port": {
"bridge-name": "ne2",
"component-name": "cv0",
"port-type": "ieee802-dot1q-bridge:c-vlan-bridge-port",
"pvid": 1,
"acceptable-frame": "admit-only-VLAN-tagged-frames",
"enable-ingress-filtering": true,
"port-number": 1
}
},
{
"name": "eth2",
"type": "iana-if-type:ethernetCsmacd",
"oper-status": "up",
"statistics": {
"discontinuity-time": "2022-04-06T11:00:00+02:00"
},
"ieee802-dot1q-bridge:bridge-port": {
"bridge-name": "ne2",
"component-name": "cv0",
"port-type": "ieee802-dot1q-bridge:c-vlan-bridge-port",
"pvid": 300,
"acceptable-frame": "admit-only-untagged-and-priority-tagged",
"enable-ingress-filtering": true,
"port-number": 2
}
},
{
"name": "eth3",
"type": "iana-if-type:ethernetCsmacd",
"oper-status": "up",
"statistics": {
"discontinuity-time": "2022-04-06T11:00:00+02:00"
},
"ieee802-dot1q-bridge:bridge-port": {
"bridge-name": "ne2",
"component-name": "cv0",
"port-type": "ieee802-dot1q-bridge:c-vlan-bridge-port",
"pvid": 1,
"acceptable-frame": "admit-only-VLAN-tagged-frames",
"enable-ingress-filtering": true,
"port-number": 3
}
}
]
}
}
\ No newline at end of file
Package generated_from_e_line_examples_c_vlan_bridge_json {
Type String
Type TODO_RESOLVE_REFERENCED
Use "e-line-examples-c-vlan-bridge.json" as SOURCE_MAPPING
Type JSON_String
Structure JSON_e_line_examples_c_vlan_bridge_json (
JSON_ieee802_dot1q_bridge_bridges ieee802_dot1q_bridge_bridges,
JSON_ietf_interfaces_interfaces ietf_interfaces_interfaces
)
Structure JSON_ieee802_dot1q_bridge_bridges (
JSON_bridge bridge
)
Collection JSON_bridge of JSON_bridge_item
Structure JSON_bridge_item (
JSON_String name,
JSON_String address,
JSON_String bridge_type,
JSON_component ^component
)
Collection JSON_component of JSON_component_item
Structure JSON_component_item (
JSON_String name,
JSON_String id,
JSON_String type,
JSON_bridge_port bridge_port,
JSON_filtering_database filtering_database,
JSON_bridge_vlan bridge_vlan
)
Collection JSON_bridge_port of JSON_String
Structure JSON_filtering_database (
JSON_vlan_registration_entry vlan_registration_entry
)
Collection JSON_vlan_registration_entry of JSON_vlan_registration_entry_item
Structure JSON_vlan_registration_entry_item (
JSON_String database_id,
JSON_String vids,
JSON_String entry_type,
JSON_port_map port_map
)
Collection JSON_port_map of JSON_port_map_item
Structure JSON_port_map_item (
JSON_String port_ref,
JSON_static_vlan_registration_entries static_vlan_registration_entries
)
Structure JSON_static_vlan_registration_entries (
JSON_String vlan_transmitted
)
Structure JSON_bridge_vlan (
JSON_vlan vlan
)
Collection JSON_vlan of JSON_vlan_item
Structure JSON_vlan_item (
JSON_String vid,
JSON_String name,
JSON_egress_ports egress_ports,
JSON_untagged_ports untagged_ports
)
Collection JSON_egress_ports of JSON_String
Collection JSON_untagged_ports of JSON_String
Structure JSON_ietf_interfaces_interfaces (
JSON_interface interface
)
Collection JSON_interface of JSON_interface_item
Structure JSON_interface_item (
JSON_String name,
JSON_String type,
JSON_String oper_status,
JSON_statistics statistics,
JSON_ieee802_dot1q_bridge_bridge_port ieee802_dot1q_bridge_bridge_port
)
Structure JSON_statistics (
JSON_String discontinuity_time
)
Structure JSON_ieee802_dot1q_bridge_bridge_port (
JSON_String bridge_name,
JSON_String component_name,
JSON_String port_type,
JSON_String pvid,
JSON_String acceptable_frame,
JSON_String enable_ingress_filtering,
JSON_String port_number
)
JSON_e_line_examples_c_vlan_bridge_json JSON_instance (
ieee802_dot1q_bridge_bridges = (
bridge = [
(
name = "ne2",
address = "10-10-10-10-10-10",
bridge_type = "ieee802-dot1q-bridge:customer-vlan-bridge",
^component = [
(
name = "cv0",
id = "0",
type = "ieee802-dot1q-bridge:c-vlan-component",
bridge_port = [
"eth1",
"eth2",
"eth3"
],
filtering_database = (
vlan_registration_entry = [
(
database_id = "1",
vids = "200",
entry_type = "static",
port_map = [
(
port_ref = "1",
static_vlan_registration_entries = (
vlan_transmitted = "tagged"
)
),
(
port_ref = "3",
static_vlan_registration_entries = (
vlan_transmitted = "tagged"
)
)
]
),
(
database_id = "1",
vids = "300",
entry_type = "static",
port_map = [
(
port_ref = "2",
static_vlan_registration_entries = (
vlan_transmitted = "untagged"
)
),
(
port_ref = "3",
static_vlan_registration_entries = (
vlan_transmitted = "tagged"
)
)
]
)
]
),
bridge_vlan = (
vlan = [
(
vid = "200",
name = "E-Line 200",
egress_ports = [
"eth1",
"eth3"
]
),
(
vid = "300",
name = "E-Line 300",
untagged_ports = [
"eth2"
],
egress_ports = [
"eth2",
"eth3"
]
)
]
)
)
]
)
]
),
ietf_interfaces_interfaces = (
interface = [
(
name = "eth1",
type = "iana-if-type:ethernetCsmacd",
oper_status = "up",
statistics = (
discontinuity_time = "2022-04-06T11:00:00+02:00"
),
ieee802_dot1q_bridge_bridge_port = (
bridge_name = "ne2",
component_name = "cv0",
port_type = "ieee802-dot1q-bridge:c-vlan-bridge-port",
pvid = "1",
acceptable_frame = "admit-only-VLAN-tagged-frames",
enable_ingress_filtering = "true",
port_number = "1"
)
),
(
name = "eth2",
type = "iana-if-type:ethernetCsmacd",
oper_status = "up",
statistics = (
discontinuity_time = "2022-04-06T11:00:00+02:00"
),
ieee802_dot1q_bridge_bridge_port = (
bridge_name = "ne2",
component_name = "cv0",
port_type = "ieee802-dot1q-bridge:c-vlan-bridge-port",
pvid = "300",
acceptable_frame = "admit-only-untagged-and-priority-tagged",
enable_ingress_filtering = "true",
port_number = "2"
)
),
(
name = "eth3",
type = "iana-if-type:ethernetCsmacd",
oper_status = "up",
statistics = (
discontinuity_time = "2022-04-06T11:00:00+02:00"
),
ieee802_dot1q_bridge_bridge_port = (
bridge_name = "ne2",
component_name = "cv0",
port_type = "ieee802-dot1q-bridge:c-vlan-bridge-port",
pvid = "1",
acceptable_frame = "admit-only-VLAN-tagged-frames",
enable_ingress_filtering = "true",
port_number = "3"
)
)
]
)
)
Map JSON_e_line_examples_c_vlan_bridge_json to "JSON" in SOURCE_MAPPING as JSON_SOURCE_MAPPING {
ieee802_dot1q_bridge_bridges -> "ieee802-dot1q-bridge:bridges",
ietf_interfaces_interfaces -> "ietf-interfaces:interfaces"
}
Map JSON_ieee802_dot1q_bridge_bridges to "JSON.ieee802-dot1q-bridge:bridges" in SOURCE_MAPPING as JSON_ieee802_dot1q_bridge_bridges_SOURCE_MAPPING {
bridge -> "bridge"
}
Map JSON_bridge_item to "JSON.bridge.item" in SOURCE_MAPPING as JSON_bridge_item_SOURCE_MAPPING {
name -> "name",
address -> "address",
bridge_type -> "bridge-type",
^component -> "component"
}
Map JSON_component_item to "JSON.component.item" in SOURCE_MAPPING as JSON_component_item_SOURCE_MAPPING {
name -> "name",
id -> "id",
type -> "type",
bridge_port -> "bridge-port",
filtering_database -> "filtering-database",
bridge_vlan -> "bridge-vlan"
}
Map JSON_filtering_database to "JSON.filtering-database" in SOURCE_MAPPING as JSON_filtering_database_SOURCE_MAPPING {
vlan_registration_entry -> "vlan-registration-entry"
}
Map JSON_vlan_registration_entry_item to "JSON.vlan-registration-entry.item" in SOURCE_MAPPING as JSON_vlan_registration_entry_item_SOURCE_MAPPING {
database_id -> "database-id",
vids -> "vids",
entry_type -> "entry-type",
port_map -> "port-map"
}
Map JSON_port_map_item to "JSON.port-map.item" in SOURCE_MAPPING as JSON_port_map_item_SOURCE_MAPPING {
port_ref -> "port-ref",
static_vlan_registration_entries -> "static-vlan-registration-entries"
}
Map JSON_static_vlan_registration_entries to "JSON.static-vlan-registration-entries" in SOURCE_MAPPING as JSON_static_vlan_registration_entries_SOURCE_MAPPING {
vlan_transmitted -> "vlan-transmitted"
}
Map JSON_bridge_vlan to "JSON.bridge-vlan" in SOURCE_MAPPING as JSON_bridge_vlan_SOURCE_MAPPING {
vlan -> "vlan"
}
Map JSON_vlan_item to "JSON.vlan.item" in SOURCE_MAPPING as JSON_vlan_item_SOURCE_MAPPING {
vid -> "vid",
name -> "name",
egress_ports -> "egress-ports",
untagged_ports -> "untagged-ports"
}
Map JSON_ietf_interfaces_interfaces to "JSON.ietf-interfaces:interfaces" in SOURCE_MAPPING as JSON_ietf_interfaces_interfaces_SOURCE_MAPPING {
interface -> "interface"
}
Map JSON_interface_item to "JSON.interface.item" in SOURCE_MAPPING as JSON_interface_item_SOURCE_MAPPING {
name -> "name",
type -> "type",
oper_status -> "oper-status",
statistics -> "statistics",
ieee802_dot1q_bridge_bridge_port -> "ieee802-dot1q-bridge:bridge-port"
}
Map JSON_statistics to "JSON.statistics" in SOURCE_MAPPING as JSON_statistics_SOURCE_MAPPING {
discontinuity_time -> "discontinuity-time"
}
Map JSON_ieee802_dot1q_bridge_bridge_port to "JSON.ieee802-dot1q-bridge:bridge-port" in SOURCE_MAPPING as JSON_ieee802_dot1q_bridge_bridge_port_SOURCE_MAPPING {
bridge_name -> "bridge-name",
component_name -> "component-name",
port_type -> "port-type",
pvid -> "pvid",
acceptable_frame -> "acceptable-frame",
enable_ingress_filtering -> "enable-ingress-filtering",
port_number -> "port-number"
}
}
\ No newline at end of file
{
"ieee802-dot1q-bridge:bridges": {
"bridge": [
{
"name": "ne1",
"address": "10-10-10-10-10-10",
"bridge-type": "ieee802-dot1q-bridge:provider-edge-bridge",
"component": [
{
"name": "sv0",
"id": 0,
"type": "ieee802-dot1q-bridge:s-vlan-component",
"bridge-port": [
"eth3",
"eth4",
"eth5"
],
"filtering-database": {
"vlan-registration-entry": [
{
"database-id": 1,
"vids": "200",
"entry-type": "static",
"port-map": [
{
"port-ref": 1,
"static-vlan-registration-entries": {
"vlan-transmitted": "untagged"
}
},
{
"port-ref": 5,
"static-vlan-registration-entries": {
"vlan-transmitted": "tagged"
}
}
]
},
{
"database-id": 1,
"vids": "300",
"entry-type": "static",
"port-map": [
{
"port-ref": 2,
"static-vlan-registration-entries": {
"vlan-transmitted": "untagged"
}
},
{
"port-ref": 5,
"static-vlan-registration-entries": {
"vlan-transmitted": "tagged"
}
}
]
},
{
"database-id": 1,
"vids": "400",
"entry-type": "static",
"port-map": [
{
"port-ref": 3,
"static-vlan-registration-entries": {
"vlan-transmitted": "untagged"
}
},
{
"port-ref": 5,
"static-vlan-registration-entries": {
"vlan-transmitted": "tagged"
}
}
]
},
{
"database-id": 1,
"vids": "500",
"entry-type": "static",
"port-map": [
{
"port-ref": 4,
"static-vlan-registration-entries": {
"vlan-transmitted": "tagged"
}
},
{
"port-ref": 5,
"static-vlan-registration-entries": {
"vlan-transmitted": "tagged"
}
}
]
}
]
},
"bridge-vlan": {
"vlan": [
{
"vid": 200,
"name": "E-Line 200",
"untagged-ports": [
"eth1"
],
"egress-ports": [
"eth1",
"eth5"
]
},
{
"vid": 300,
"name": "E-Line 300",
"untagged-ports": [
"eth2"
],
"egress-ports": [
"eth2",
"eth5"
]
},
{
"vid": 400,
"name": "E-Line 400",
"untagged-ports": [
"eth3"
],
"egress-ports": [
"eth3",
"eth5"
]
},
{
"vid": 500,
"name": "E-Line 500",
"egress-ports": [
"eth4",
"eth5"
]
}
]
}
},
{
"name": "cv1",
"id": 1,
"type": "ieee802-dot1q-bridge:c-vlan-component",
"bridge-port": [
"eth1"
]
},
{
"name": "cv2",
"id": 2,
"type": "ieee802-dot1q-bridge:c-vlan-component",
"bridge-port": [
"eth2"
]
}
]
}
]
},
"ietf-interfaces:interfaces": {
"interface": [
{
"name": "eth1",
"type": "iana-if-type:ethernetCsmacd",
"oper-status": "up",
"statistics": {
"discontinuity-time": "2022-03-23T11:00:00+02:00"
},
"ieee802-dot1q-bridge:bridge-port": {
"bridge-name": "ne1",
"component-name": "cv1",
"port-type": "ieee802-dot1q-bridge:customer-edge-port",
"pvid": 1,
"acceptable-frame": "admit-only-VLAN-tagged-frames",
"enable-ingress-filtering": true,
"port-number": 1,
"ieee802-dot1q-pb:cvid-registration": [
{
"cvid": 100,
"svid": 200,
"untagged-pep": false,
"untagged-cep": false
}
]
}
},
{
"name": "eth2",
"type": "iana-if-type:ethernetCsmacd",
"oper-status": "up",
"statistics": {
"discontinuity-time": "2022-03-23T11:00:00+02:00"
},
"ieee802-dot1q-bridge:bridge-port": {
"bridge-name": "ne1",
"component-name": "cv2",
"port-type": "ieee802-dot1q-bridge:customer-edge-port",
"pvid": 1,
"acceptable-frame": "admit-only-untagged-and-priority-tagged",
"enable-ingress-filtering": true,
"port-number": 2,
"ieee802-dot1q-pb:cvid-registration": [
{
"cvid": 1,
"svid": 300,
"untagged-pep": true,
"untagged-cep": true
}
]
}
},
{
"name": "eth3",
"type": "iana-if-type:ethernetCsmacd",
"oper-status": "up",
"statistics": {
"discontinuity-time": "2022-03-23T11:00:00+02:00"
},
"ieee802-dot1q-bridge:bridge-port": {
"bridge-name": "ne1",
"component-name": "sv0",
"port-type": "ieee802-dot1q-bridge:customer-network-port",
"pvid": 400,
"acceptable-frame": "admit-only-untagged-and-priority-tagged",
"enable-ingress-filtering": true,
"port-number": 3
}
},
{
"name": "eth4",
"type": "iana-if-type:ethernetCsmacd",
"oper-status": "up",
"statistics": {
"discontinuity-time": "2022-03-23T11:00:00+02:00"
},
"ieee802-dot1q-bridge:bridge-port": {
"bridge-name": "ne1",
"component-name": "sv0",
"port-type": "ieee802-dot1q-bridge:customer-network-port",
"pvid": 1,
"acceptable-frame": "admit-only-VLAN-tagged-frames",
"enable-ingress-filtering": true,
"port-number": 4,
"enable-vid-translation-table": true,
"enable-egress-vid-translation-table": false,
"vid-translations": [
{
"local-vid": 100,
"relay-vid": 500
}
]
}
},
{
"name": "eth5",
"type": "iana-if-type:ethernetCsmacd",
"oper-status": "up",
"statistics": {
"discontinuity-time": "2022-03-23T11:00:00+02:00"
},
"ieee802-dot1q-bridge:bridge-port": {
"bridge-name": "ne1",
"component-name": "sv0",
"port-type": "ieee802-dot1q-bridge:provider-network-port",
"pvid": 1,
"acceptable-frame": "admit-only-VLAN-tagged-frames",
"enable-ingress-filtering": true,
"port-number": 5
}
}
]
}
}
\ No newline at end of file