Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions instance/emf/serializer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

<properties>
<gecko.emf.version>6.2.0</gecko.emf.version>
<emf.common.version>2.30.0</emf.common.version>
<emf.ecore.version>2.36.0</emf.ecore.version>
<emf.ecore.xmi.version>2.37.0</emf.ecore.xmi.version>
<emf.common.version>2.44.0</emf.common.version>
<emf.ecore.version>2.41.0</emf.ecore.version>
<emf.ecore.xmi.version>2.39.0</emf.ecore.xmi.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,20 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import org.eclipse.daanse.rolap.mapping.model.provider.CatalogMappingSupplier;
import org.eclipse.daanse.xmla.csdl.model.v2.bi.BiPackage;
import org.eclipse.daanse.xmla.csdl.model.v2.edm.EdmPackage;
import org.eclipse.daanse.xmla.csdl.model.v2.edm.util.EdmResourceFactoryImpl;
import org.eclipse.daanse.olap.check.model.check.OlapCheckPackage;
import org.eclipse.daanse.olap.check.model.check.OlapCheckSuite;
import org.eclipse.daanse.olap.check.runtime.api.OlapCheckSuiteSupplier;
import org.eclipse.daanse.xmla.csdl.model.provider.OlapTSchemaSupplier;
import org.eclipse.daanse.rolap.mapping.model.AbstractElement;
import org.eclipse.daanse.rolap.mapping.model.Catalog;
import org.eclipse.daanse.rolap.mapping.model.Documentation;
Expand All @@ -52,6 +60,7 @@
import org.eclipse.emf.ecore.EStructuralFeature;
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.emf.ecore.xmi.XMLResource;
import org.gecko.emf.osgi.annotation.require.RequireEMF;
Expand Down Expand Up @@ -112,20 +121,26 @@ public static void beforeAll() throws IOException {
@Test
@Order(1)
public void writePopulation(@InjectBundleContext BundleContext bc,
@InjectService(cardinality = 1, filter = "(" + EMFNamespaces.EMF_MODEL_NAME + "="
+ RolapMappingPackage.eNAME + ")") ResourceSet resourceSet,
@InjectService ServiceAware<CatalogMappingSupplier> mappingSuppiersSA)
throws SQLException, InterruptedException, IOException {
@InjectService(cardinality = 1, filter = "(" + EMFNamespaces.EMF_MODEL_NAME + "="
+ RolapMappingPackage.eNAME + ")") ResourceSet resourceSet,
@InjectService ServiceAware<CatalogMappingSupplier> mappingSuppiersSA,
@InjectService ServiceAware<OlapCheckSuiteSupplier> checkSuiteSuppliersSA,
@InjectService ServiceAware<OlapTSchemaSupplier> tSchemaSupplierSA)
throws SQLException, InterruptedException, IOException {

try {

List<ServiceReference<CatalogMappingSupplier>> srs = mappingSuppiersSA.getServiceReferences();
List<ServiceReference<OlapCheckSuiteSupplier>> chrs = checkSuiteSuppliersSA.getServiceReferences();
List<OlapTSchemaSupplier> tss = tSchemaSupplierSA.getServices();
StringBuilder parentReadme = new StringBuilder();
parentReadme.append(TEXT);

// Create combined ZIP directory structure
Path zipDir = Files.createDirectories(tempDir.resolve("cubeserver/tutorial/zip"));
Path checkZipDir = Files.createDirectories(tempDir.resolve("cubeserver/checkSuite/zip"));
ZipOutputStream combinedZos = new ZipOutputStream(new FileOutputStream(zipDir.resolve("all-tutorials.zip").toFile()));
ZipOutputStream combinedCheckSuiteZos = new ZipOutputStream(new FileOutputStream(checkZipDir.resolve("all-check-suites.zip").toFile()));

srs.sort((o1, o2) -> {
Object s1 = o1.getProperty("number");
Expand All @@ -141,15 +156,28 @@ public void writePopulation(@InjectBundleContext BundleContext bc,
CatalogMappingSupplier catalogMappingSupplier = mappingSuppiersSA.getService(sr);

parentReadme.append("\n");
String name = catalogMappingSupplier.getClass().getPackageName();
Optional<OlapTSchemaSupplier> oOlapTSchemaSupplier = tss.stream().filter(s -> name.equals(s.getClass().getPackageName())).findFirst();
serializeCatalog(resourceSet, parentReadme, catalogMappingSupplier, oOlapTSchemaSupplier, sr.getProperties(), combinedZos);
} catch (Exception e) {
e.printStackTrace();
}
}

for (ServiceReference<OlapCheckSuiteSupplier> chs : chrs) {

try {
OlapCheckSuiteSupplier catalogMappingSupplier = checkSuiteSuppliersSA.getService(chs);

serializeCatalog(resourceSet, parentReadme, catalogMappingSupplier, sr.getProperties(), combinedZos);
serializeCheckSuite(resourceSet, catalogMappingSupplier, combinedCheckSuiteZos);
} catch (Exception e) {
e.printStackTrace();
}
}

// Close combined ZIP
combinedZos.close();
combinedCheckSuiteZos.close();

Path rootReadmeFile = Files.createFile(tempDir.resolve("index.md"));
Files.writeString(rootReadmeFile, parentReadme);
Expand All @@ -159,10 +187,65 @@ public void writePopulation(@InjectBundleContext BundleContext bc,

}

@Test
public void test() throws IOException {
org.eclipse.daanse.rolap.mapping.instance.emf.tutorial.cube.calculatedmember.color.TSchemaSupplier supplier = new org.eclipse.daanse.rolap.mapping.instance.emf.tutorial.cube.calculatedmember.color.TSchemaSupplier();
String csdl = serializeToXml(supplier.get());
System.out.println(csdl);
}

Map<Documentation, EObject> map = new HashMap<Documentation, EObject>();

private void serializeCheckSuite(ResourceSet resourceSet,
OlapCheckSuiteSupplier checkSuiteSupplier, ZipOutputStream combinedZos) throws IOException {

String name = checkSuiteSupplier.getClass().getPackageName();
name = name.substring(46);

Path zipDir = Files.createDirectories(tempDir.resolve("cubeserver/checkSuite/zip"));
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipDir.resolve(name + ".zip").toFile()));

OlapCheckSuite chs = checkSuiteSupplier.get();

URI uriCatalog = URI.createFileURI("catalog.xmi");
Resource resourceCatalog = resourceSet.createResource(uriCatalog);

Set<EObject> set = new HashSet<>();

set = allRef(set, chs);

// sort

List<EObject> sortedList = set.stream().sorted(checkSuiteComparator).toList();


for (EObject eObject : sortedList) {
if (eObject.eContainer() == null) {
resourceCatalog.getContents().add(eObject);
}
}
Map<Object, Object> options = new HashMap<>();
options.put(XMLResource.OPTION_ENCODING, "UTF-8");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
resourceCatalog.save(baos, options);

ZipEntry entry = new ZipEntry(name + "/checkSuite.xmi");
zos.putNextEntry(entry);
zos.write(baos.toByteArray());
zos.closeEntry();

ZipEntry combinedEntry = new ZipEntry(name + "/checkSuite.xmi");
combinedZos.putNextEntry(combinedEntry);
combinedZos.write(baos.toByteArray());
combinedZos.closeEntry();

Files.createDirectories(zipDir);
zos.close();
}


private void serializeCatalog(ResourceSet resourceSet, StringBuilder parentReadme,
CatalogMappingSupplier catalogMappingSupplier, Dictionary<String, Object> dictionary, ZipOutputStream combinedZos) throws IOException {
CatalogMappingSupplier catalogMappingSupplier, Optional<OlapTSchemaSupplier> oOlapTSchemaSupplier, Dictionary<String, Object> dictionary, ZipOutputStream combinedZos) throws IOException {

String name = catalogMappingSupplier.getClass().getPackageName();
name = name.substring(46);
Expand Down Expand Up @@ -256,6 +339,26 @@ private void serializeCatalog(ResourceSet resourceSet, StringBuilder parentReadm
combinedZos.write(baos.toByteArray());
combinedZos.closeEntry();

if (oOlapTSchemaSupplier.isPresent()) {
resourceSet.getPackageRegistry().put(EdmPackage.eNS_URI, EdmPackage.eINSTANCE);
resourceSet.getPackageRegistry().put(BiPackage.eNS_URI, BiPackage.eINSTANCE);
Resource resource = resourceSet.createResource(URI.createURI("csdl.xmi"));
resource.getContents().add(oOlapTSchemaSupplier.get().get());
ByteArrayOutputStream baosCsdl = new ByteArrayOutputStream();
resource.save(baosCsdl, options);

ZipEntry tschemaEntry = new ZipEntry(name + "/csdl/csdl.xmi");
zos.putNextEntry(tschemaEntry);
zos.write(baosCsdl.toByteArray());
zos.closeEntry();

// Add to combined ZIP
ZipEntry tschemaCombinedEntry = new ZipEntry(name + "/csdl/csdl.xmi");
combinedZos.putNextEntry(tschemaCombinedEntry);
combinedZos.write(baosCsdl.toByteArray());
combinedZos.closeEntry();
}

Files.createDirectories(zipDir);

for (Documentation documentation : docs) {
Expand Down Expand Up @@ -628,6 +731,75 @@ public int compare(EObject o1, EObject o2) {
}
};

static CheckSuiteEObjectComparator checkSuiteComparator = new CheckSuiteEObjectComparator();

static class CheckSuiteEObjectComparator implements Comparator<EObject> {

AtomicInteger COUNTER = new AtomicInteger(1);
Map<EClass, Integer> map = new HashMap<EClass, Integer>();

CheckSuiteEObjectComparator() {
add(OlapCheckPackage.Literals.CATALOG_CHECK);
add(OlapCheckPackage.Literals.CATALOG_ATTRIBUTE_CHECK);
add(OlapCheckPackage.Literals.DATABASE_SCHEMA_CHECK);
add(OlapCheckPackage.Literals.DATABASE_SCHEMA_ATTRIBUTE_CHECK);
add(OlapCheckPackage.Literals.DATABASE_TABLE_CHECK);
add(OlapCheckPackage.Literals.DATABASE_TABLE_ATTRIBUTE_CHECK);
add(OlapCheckPackage.Literals.DATABASE_COLUMN_CHECK);
add(OlapCheckPackage.Literals.DATABASE_COLUMN_ATTRIBUTE_CHECK);
add(OlapCheckPackage.Literals.CUBE_CHECK);
add(OlapCheckPackage.Literals.CUBE_ATTRIBUTE_CHECK);
add(OlapCheckPackage.Literals.DIMENSION_CHECK);
add(OlapCheckPackage.Literals.DIMENSION_ATTRIBUTE_CHECK);
add(OlapCheckPackage.Literals.HIERARCHY_CHECK);
add(OlapCheckPackage.Literals.HIERARCHY_ATTRIBUTE_CHECK);
add(OlapCheckPackage.Literals.LEVEL_CHECK);
add(OlapCheckPackage.Literals.LEVEL_ATTRIBUTE_CHECK);
add(OlapCheckPackage.Literals.MEASURE_CHECK);
add(OlapCheckPackage.Literals.MEASURE_ATTRIBUTE_CHECK);
add(OlapCheckPackage.Literals.QUERY_CHECK);
add(OlapCheckPackage.Literals.QUERY_CHECK_RESULT);
//TODO
}

void add(EClass eClass) {
map.put(eClass, COUNTER.incrementAndGet());
}

@Override
public int compare(EObject o1, EObject o2) {

EClass eClass1 = o1.eClass();
EClass eClass2 = o2.eClass();
int value = map.getOrDefault(eClass1, 0) - map.getOrDefault(eClass2, 0);

if (value != 0) {
return value;
}

Object s1 = "";
Object s2 = "";
EStructuralFeature eStructuralFeature1 = eClass1.getEStructuralFeature("id");
if (eStructuralFeature1 != null) {

s1 = o1.eGet(eStructuralFeature1);
}
EStructuralFeature eStructuralFeature2 = eClass2.getEStructuralFeature("id");
if (eStructuralFeature2 != null) {

s2 = o2.eGet(eStructuralFeature2);
}
if (s1 == null) {
s1 = "";
}
if (s2 == null) {
s2 = "";
}

return s1.toString().compareToIgnoreCase(s2.toString());
}
};

public static void deleteDirectory(Path directory) throws IOException {
if (!Files.exists(directory)) {
return;
Expand All @@ -647,4 +819,30 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx
}
});
}

private String serializeToXml(EObject eObject) throws IOException {
ResourceSetImpl resourceSet = new ResourceSetImpl();

// Register the EDM resource factory that respects ExtendedMetaData
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xml", new EdmResourceFactoryImpl());

// Register packages
resourceSet.getPackageRegistry().put(EdmPackage.eNS_URI, EdmPackage.eINSTANCE);
resourceSet.getPackageRegistry().put(BiPackage.eNS_URI, BiPackage.eINSTANCE);
Resource resource = resourceSet.createResource(URI.createURI("temp.xml"));
resource.getContents().add(eObject);

ByteArrayOutputStream baos = new ByteArrayOutputStream();
Map<String, Object> options = new HashMap<>();
options.put(XMLResource.OPTION_ENCODING, "UTF-8");
options.put(XMLResource.OPTION_FORMATTED, Boolean.TRUE);
options.put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);

resource.save(baos, options);

resource.getContents().clear();
resourceSet.getResources().remove(resource);

return baos.toString("UTF-8");
}
}
16 changes: 12 additions & 4 deletions instance/emf/serializer/test.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
bnd.identity;id='org.eclipse.daanse.rolap.mapping.instance.emf.complex.expressivenames',\
bnd.identity;id='org.eclipse.daanse.rolap.mapping.instance.emf.complex.population.jena',\
bnd.identity;id='org.eclipse.daanse.rolap.mapping.instance.emf.tutorial.level.unique',\
bnd.identity;id='org.eclipse.daanse.rolap.mapping.instance.emf.complex.foodmart'
bnd.identity;id='org.eclipse.daanse.rolap.mapping.instance.emf.complex.foodmart',\
bnd.identity;id='org.eclipse.daanse.rolap.mapping.instance.emf.complex.steelwheels',\
bnd.identity;id='org.eclipse.daanse.rolap.mapping.instance.emf.complex.parcel'
# -runbundles is calculated by the bnd-resolver-maven-plugin
Expand All @@ -148,8 +148,10 @@
org.eclipse.daanse.olap.check.runtime;version='[0.0.1,0.0.2)',\
org.eclipse.daanse.rolap.mapping.instance.emf.complex.expressivenames;version='[0.0.1,0.0.2)',\
org.eclipse.daanse.rolap.mapping.instance.emf.complex.foodmart;version='[0.0.1,0.0.2)',\
org.eclipse.daanse.rolap.mapping.instance.emf.complex.parcel;version='[0.0.1,0.0.2)',\
org.eclipse.daanse.rolap.mapping.instance.emf.complex.population.jena;version='[0.0.1,0.0.2)',\
org.eclipse.daanse.rolap.mapping.instance.emf.complex.school;version='[0.0.1,0.0.2)',\
org.eclipse.daanse.rolap.mapping.instance.emf.complex.steelwheels;version='[0.0.1,0.0.2)',\
org.eclipse.daanse.rolap.mapping.instance.emf.serializer;version='[0.0.1,0.0.2)',\
org.eclipse.daanse.rolap.mapping.instance.emf.serializer-tests;version='[0.0.1,0.0.2)',\
org.eclipse.daanse.rolap.mapping.instance.emf.tutorial.access.cataloggrand;version='[0.0.1,0.0.2)',\
Expand Down Expand Up @@ -228,9 +230,15 @@
org.eclipse.daanse.rolap.mapping.instance.emf.tutorial.writeback.withoutdimension;version='[0.0.1,0.0.2)',\
org.eclipse.daanse.rolap.mapping.model;version='[0.0.1,0.0.2)',\
org.eclipse.daanse.sql.guard.api;version='[0.0.1,0.0.2)',\
org.eclipse.emf.common;version='[2.30.0,2.30.1)',\
org.eclipse.emf.ecore;version='[2.36.0,2.36.1)',\
org.eclipse.emf.ecore.xmi;version='[2.37.0,2.37.1)',\
org.eclipse.daanse.xmla.csdl.model.provider;version='[0.0.1,0.0.2)',\
org.eclipse.daanse.xmla.csdl.model.v2.an;version='[0.0.1,0.0.2)',\
org.eclipse.daanse.xmla.csdl.model.v2.bi;version='[0.0.1,0.0.2)',\
org.eclipse.daanse.xmla.csdl.model.v2.cg;version='[0.0.1,0.0.2)',\
org.eclipse.daanse.xmla.csdl.model.v2.edm;version='[0.0.1,0.0.2)',\
org.eclipse.emf.common;version='[2.44.0,2.44.1)',\
org.eclipse.emf.ecore;version='[2.41.0,2.41.1)',\
org.eclipse.emf.ecore.xmi;version='[2.39.0,2.39.1)',\
org.eclipse.fennec.emf.osgi.api;version='[1.0.0,1.0.1)',\
org.gecko.emf.osgi.component;version='[6.2.0,6.2.1)',\
org.opentest4j;version='[1.3.0,1.3.1)',\
org.osgi.service.cm;version='[1.6.1,1.6.2)',\
Expand Down
Loading
Loading