public UpccModelXsdTypes(IDocLibrary docLibrary) { xsdTypes = new Dictionary <string, XsdType>(); alreadyCompiledTypes = new HashSet <int>(); Compile(docLibrary); }
private static void PruneUpccModel(IDocLibrary docLibrary, IBieLibrary bieLibrary) { abiesToBeRemoved.Clear(); masToBeRemoved.Clear(); alreadyPrunedItems.Clear(); PruneMa(docLibrary.DocumentRoot); List <IAbie> abies = new List <IAbie>(bieLibrary.Abies); foreach (IAbie abie in abies) { if (abiesToBeRemoved.Contains(abie.Id)) { bieLibrary.RemoveAbie(abie); } } List <IMa> mas = new List <IMa>(docLibrary.Mas); foreach (IMa ma in mas) { if (masToBeRemoved.Contains(ma.Id)) { docLibrary.RemoveMa(ma); } } }
public void Test_roundtrip_ebinterface_to_ubl_and_back() { string ebiInvoiceSchema = TestUtils.PathToTestResource(@"XSDExporterTest\transformer\roundtrip_ebinterface_to_ubl_and_back\original_ebinterface_invoice_xml_schema\Invoice.xsd"); string ebiXmlSchemaExportDirectory_1 = TestUtils.PathToTestResource(@"XSDExporterTest\transformer\roundtrip_ebinterface_to_ubl_and_back\imported_ebinterface_model_exported_as_ebinterface_xml_schema\"); string ebiXmlSchemaExportDirectory_2 = TestUtils.PathToTestResource(@"XSDExporterTest\transformer\roundtrip_ebinterface_to_ubl_and_back\transformed_ebinterface_as_ubl_as_ebinterface_xml_schema\"); string repositoryFile = TestUtils.PathToTestResource(@"XSDExporterTest\transformer\roundtrip_ebinterface_to_ubl_and_back\repository_containing_roundtripped_models.eap"); Repository eaRepository = new Repository(); eaRepository.OpenFile(repositoryFile); ICctsRepository cctsRepository = CctsRepositoryFactory.CreateCctsRepository(eaRepository); IBieLibrary ebiBieLibrary = cctsRepository.GetBieLibraryByPath((Path)"Model" / "bLibrary" / "ebInterface BIELibrary"); IBieLibrary ublBieLibrary = cctsRepository.GetBieLibraryByPath((Path)"Model" / "bLibrary" / "UBL BIE Library"); IDocLibrary ebiDocLibrary = cctsRepository.GetDocLibraryByPath((Path)"Model" / "bLibrary" / "ebInterface DOCLibrary"); IDocLibrary ublDocLibrary = cctsRepository.GetDocLibraryByPath((Path)"Model" / "bLibrary" / "UBL DOC Library"); SubsetExporter.ExportSubset(ebiDocLibrary, ebiInvoiceSchema, ebiXmlSchemaExportDirectory_1); Transformer.Transform(ebiBieLibrary, ublBieLibrary, ebiDocLibrary, ublDocLibrary); Transformer.Transform(ublBieLibrary, ebiBieLibrary, ublDocLibrary, ebiDocLibrary); SubsetExporter.ExportSubset(ebiDocLibrary, ebiInvoiceSchema, ebiXmlSchemaExportDirectory_2); }
public static void ExportSubset(IDocLibrary docLibrary, string schemaFileComplete, string schemaDirectorySubset) { SubsetExporter exporter = new SubsetExporter(schemaFileComplete); exporter.ExecuteXmlSchemaSubsetting(docLibrary); exporter.WriteXmlSchemaSubset(schemaDirectorySubset); }
///<summary> ///</summary> ///<param name="repository"></param> ///<param name="targetNamespace"></param> ///<param name="namespacePrefix"></param> ///<param name="annotate"></param> ///<param name="allschemas"></param> ///<param name="outputDirectory"></param> ///<param name="docLibrary"></param> public GeneratorContext(ICctsRepository repository, string targetNamespace, string namespacePrefix, bool annotate, bool allschemas, string outputDirectory, IDocLibrary docLibrary) { Allschemas = allschemas; Repository = repository; TargetNamespace = targetNamespace; NamespacePrefix = namespacePrefix; Annotate = annotate; OutputDirectory = outputDirectory; DocLibrary = docLibrary; progress = 100 / (allschemas ? 5 : 3); }
private static void AddIncludes(XmlSchema schema, GeneratorContext context, IDocLibrary docLibrary) { foreach (SchemaInfo si in context.Schemas) { //XmlTextReader textReader = new XmlTextReader(context.OutputDirectory + si.FileName); //XmlSchema includeSchema = XmlSchema.Read(textReader, null); var include = new XmlSchemaInclude(); //include.Schema = includeSchema; include.SchemaLocation = si.FileName; schema.Includes.Add(include); } }
private static void AddImports(XmlSchema schema, GeneratorContext context, IDocLibrary docLibrary) { if (context.Annotate) { var import = new XmlSchemaImport { Namespace = "urn:un:unece:uncefact:documentation:standard:XMLNDRDocumentation:3", SchemaLocation = "documentation/standard/XMLNDR_Documentation_3p0.xsd" }; schema.Includes.Add(import); } }
public static DocLibrarySpec CloneDocLibrary(IDocLibrary docLibrary) { return(new DocLibrarySpec { Name = docLibrary.Name, BusinessTerms = new List <string>(docLibrary.BusinessTerms), Copyrights = new List <string>(docLibrary.Copyrights), Owners = new List <string>(docLibrary.Owners), References = new List <string>(docLibrary.References), Status = docLibrary.Status, VersionIdentifier = docLibrary.VersionIdentifier, BaseURN = docLibrary.BaseURN, NamespacePrefix = docLibrary.NamespacePrefix, }); }
private void treeTargetDoc_SelectionChanged(object sender, RoutedEventArgs e) { if (treeTargetDoc.SelectedItem != null) { var item = (TreeViewItem)treeTargetDoc.SelectedItem; if (item.Tag is IDocLibrary) { var lib = (IDocLibrary)item.Tag; selectedTargetDocLibrary = lib; buttonTargetDoc.Content = lib.Name; UpdateUI(); popupTargetDoc.IsOpen = false; } } }
public void Test_exporting_subset_of_ubl() { string schemaFileComplete = TestUtils.PathToTestResource(@"XSDExporterTest\mapping\SubsetExporter\exporting_subset_of_ubl\invoice\UBL-Invoice-2.0.xsd"); string schemaDirectorySubset = TestUtils.PathToTestResource(@"XSDExporterTest\mapping\SubsetExporter\exporting_subset_of_ubl\subset\"); string repositoryFile = TestUtils.PathToTestResource(@"XSDExporterTest\mapping\SubsetExporter\exporting_subset_of_ubl\Invoice_complete.eap"); Repository eaRepository = new Repository(); eaRepository.OpenFile(repositoryFile); ICctsRepository cctsRepository = CctsRepositoryFactory.CreateCctsRepository(eaRepository); IDocLibrary docLibrary = cctsRepository.GetDocLibraryByPath((Path)"Model" / "bLibrary" / "Test DOC Library"); SubsetExporter.ExportSubset(docLibrary, schemaFileComplete, schemaDirectorySubset); }
public void LoadDOC(ICctsRepository repository) { if (DOC == null) { IDocLibrary docl = repository.GetDocLibraryById(Id); IMa document = docl.DocumentRoot; if (document != null) { DOC = new cDOC(document.Name, document.Id, CheckState.Unchecked, docl.BaseURN, docl.NamespacePrefix); } else { throw new CacheException("No Document root found!"); } } }
private static IMa ShouldContainMa(IDocLibrary docLibrary, string name, AsmaDescriptor[] asmaDescriptors) { var ma = docLibrary.GetMaByName(name); Assert.IsNotNull(ma, "MA '" + name + "' not generated"); if (asmaDescriptors == null || asmaDescriptors.Length == 0) { Assert.That(AsmaDescriptors(ma), Is.Empty); } else { Assert.That(AsmaDescriptors(ma), Is.EquivalentTo(asmaDescriptors)); } return(ma); }
private void buttonClose_Click(object sender, RoutedEventArgs e) { selectedSourceBieLibrary = null; selectedSourceDocLibrary = null; selectedTargetBieLibrary = null; selectedTargetDocLibrary = null; xsdFilename = ""; targetFolder = ""; buttonXsdDocument.IsEnabled = true; buttonTargetModel.IsEnabled = true; buttonSourceModel.IsEnabled = true; buttonTargetFolder.IsEnabled = true; popupFinished.Visibility = Visibility.Collapsed; ShowShield(false); UpdateUI(); //this.Close(); }
private void buttonTransform_Click(object sender, RoutedEventArgs e) { innerCanvas.Visibility = Visibility.Visible; innerCanvas.Dispatcher.Invoke(DispatcherPriority.Render, new Action(delegate { })); Mouse.OverrideCursor = Cursors.Wait; IDocLibrary sourceDocLibrary = null; IDocLibrary targetDocLibrary = null; IBieLibrary sourceBieLibrary = null; IBieLibrary targetBieLibrary = null; foreach (var library in cctsR.GetAllLibraries()) { if (library is IDocLibrary) { var doclibrary = (IDocLibrary)library; if (doclibrary.Name.Equals(selectedSourceDocLibrary)) { sourceDocLibrary = doclibrary; } else if (doclibrary.Name.Equals(selectedTargetDocLibrary)) { targetDocLibrary = doclibrary; } } else if (library is IBieLibrary) { var bieLibrary = (IBieLibrary)library; if (bieLibrary.Name.Equals(selectedSourceBieLibrary)) { sourceBieLibrary = bieLibrary; } else if (bieLibrary.Name.Equals(selectedTargetBieLibrary)) { targetBieLibrary = bieLibrary; } } } Transformer.Transform(sourceBieLibrary, targetBieLibrary, sourceDocLibrary, targetDocLibrary); SubsetExporter.ExportSubset(targetDocLibrary, targetXSDFilename, outputDirectory); innerCanvas.Visibility = Visibility.Collapsed; Mouse.OverrideCursor = Cursors.Arrow; }
/// <summary> /// Takes the names of the libraries to be created as well as a qualifier as input and creates the /// libraries. /// </summary> public void GenerateLibraries() { bdtLibrary = bLibrary.CreateBdtLibrary(new BdtLibrarySpec { Name = bdtLibraryName }); bieLibrary = bLibrary.CreateBieLibrary(new BieLibrarySpec { Name = bieLibraryName }); docLibrary = bLibrary.CreateDocLibrary(new DocLibrarySpec { Name = docLibraryName }); GenerateBdtsAndAbiesAndMas(); GenerateRootABIE(); }
private void Compile(IDocLibrary docLibrary) { IMa documentRoot = docLibrary.DocumentRoot; IAsma asma = documentRoot.Asmas.FirstOrDefault(); BieAggregator bieAggregator = asma.AssociatedBieAggregator; if (bieAggregator.IsMa) { CompileXsdTypesFromMa(bieAggregator.Ma); } else if (bieAggregator.IsAbie) { CompileXsdTypesFromAbie(bieAggregator.Abie); } else { throw new Exception("The ASMA " + asma.Name + " of the Document Root Element " + documentRoot.Name + " neither aggregates a MA nor an ABIE."); } }
private void buttonGenerate_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; richtextStatus.Text = "Starting to generate XML schemas ...\n\n"; GatherUserInput(); cBIV currentBIV = cache.BIVs[selectedBIVName]; // TODO: check if path is valid IAbie rootAbie = null; cDOC document = currentBIV.DOC; if (document != null && document.State == CheckState.Checked) { rootAbie = cctsR.GetAbieById(document.Id); } IDocLibrary docl = cctsR.GetDocLibraryById(currentBIV.Id); // TODO: xsd generator needs to be adapted - currently all doc libraries are being generated whereas // only the ones that are checked should be generated.. //TODO: currently the wizard just takes the input from the text fields whereas the prefix and the // target namespace should be (a) stored in the cache and (b) read from there while generation.. string targetNamespace = textTargetNS.Text; string namespacePrefix = textPrefixTargetNS.Text; bool annotate = checkboxAnnotations.CheckState == CheckState.Checked ? true : false; bool allschemas = checkboxAllschemas.CheckState == CheckState.Checked ? true : false; var generationContext = new GeneratorContext(cctsR, targetNamespace, namespacePrefix, annotate, allschemas, outputDirectory, docl); generationContext.SchemaAdded += HandleSchemaAdded; export.cctsndr.XSDGenerator.GenerateSchemas(generationContext); richtextStatus.Text += "\nGenerating XML schemas completed!"; progressBar.Value = 100; Cursor.Current = Cursors.Default; }
private void buttonExport_Click(object sender, RoutedEventArgs e) { Cursor = Cursors.Wait; textBoxStatus.Text = "Starting to generate XML schemas ...\n\n"; GatherUserInput(); cBIV currentBIV = cache.BIVs[selectedBIVName]; IDocLibrary docl = cctsR.GetDocLibraryById(currentBIV.Id); // TODO: xsd generator needs to be adapted - currently all doc libraries are being generated whereas // only the ones that are checked should be generated.. //TODO: currently the wizard just takes the input from the text fields whereas the prefix and the // target namespace should be (a) stored in the cache and (b) read from there while generation.. if (comboboxDocumentModel.SelectedItem.Equals("CCTS")) { // TODO: check if path is valid cDOC document = currentBIV.DOC; if (document != null && document.State == CheckState.Checked) { } string targetNamespace = textboxTagetNamespace.Text; string namespacePrefix = textboxPrefix.Text; bool annotate = checkboxDocumentationAnnotations.IsChecked == true ? true : false; bool allschemas = checkboxGenerateCcSchemas.IsChecked == true ? true : false; var generationContext = new GeneratorContext(cctsR, targetNamespace, namespacePrefix, annotate, allschemas, outputDirectory, docl); generationContext.SchemaAdded += HandleSchemaAdded; XSDGenerator.GenerateSchemas(generationContext); } else { SubsetExporter.ExportSubset(docl, originalXMLSchema, outputDirectory); } textBoxStatus.Text += "\nGenerating XML schemas completed!"; Cursor = Cursors.Arrow; }
public void Test_transforming_ebinterface_to_ubl() { string ublInvoiceSchema = TestUtils.PathToTestResource(@"XSDExporterTest\transformer\transforming_ebinterface_to_ubl\ubl_invoice\UBL-Invoice-2.0.xsd"); string ebInterfaceAsUblSchemaDirectory = TestUtils.PathToTestResource(@"XSDExporterTest\transformer\transforming_ebinterface_to_ubl\ebinterface_as_ubl\"); string repositoryFile = TestUtils.PathToTestResource(@"XSDExporterTest\transformer\transforming_ebinterface_to_ubl\invoice.eap"); Repository eaRepository = new Repository(); eaRepository.OpenFile(repositoryFile); ICctsRepository cctsRepository = CctsRepositoryFactory.CreateCctsRepository(eaRepository); IBieLibrary ebiBieLibrary = cctsRepository.GetBieLibraryByPath((Path)"Model" / "bLibrary" / "ebInterface BIELibrary"); IBieLibrary ublBieLibrary = cctsRepository.GetBieLibraryByPath((Path)"Model" / "bLibrary" / "UBL BIE Library"); IDocLibrary ebiDocLibrary = cctsRepository.GetDocLibraryByPath((Path)"Model" / "bLibrary" / "ebInterface DOCLibrary"); IDocLibrary ublDocLibrary = cctsRepository.GetDocLibraryByPath((Path)"Model" / "bLibrary" / "UBL DOC Library"); Transformer.Transform(ebiBieLibrary, ublBieLibrary, ebiDocLibrary, ublDocLibrary); SubsetExporter.ExportSubset(ublDocLibrary, ublInvoiceSchema, ebInterfaceAsUblSchemaDirectory); }
public GeneratorContext(ICctsRepository repository, string targetNamespace, string baseURN, string namespacePrefix, bool annotate, bool allschemas, string outputDirectory, IDocLibrary docLibrary) { Allschemas = allschemas; Repository = repository; TargetNamespace = targetNamespace; BaseURN = baseURN; NamespacePrefix = namespacePrefix; Annotate = annotate; OutputDirectory = outputDirectory; DocLibrary = docLibrary; progress = 100 / (allschemas ? 5 : 3); string invalidInput = string.Empty; if (string.IsNullOrEmpty(targetNamespace)) { invalidInput = "targetNamespace"; } else if (string.IsNullOrEmpty(BaseURN)) { invalidInput = "baseURN"; } else if (string.IsNullOrEmpty(namespacePrefix)) { invalidInput = "namespacePrefix"; } else if (string.IsNullOrEmpty(namespacePrefix)) { invalidInput = "outputDirectory"; } if (!string.IsNullOrEmpty(invalidInput)) { throw new ArgumentException(string.Format("Cannot create generator context for {0} because parameter {1} is empty", docLibrary != null ? docLibrary.Name : "unknow doclibrary", invalidInput)); } }
public AsmaToGenerate(IDocLibrary docLibrary, string name, string associatedMaName) { this.docLibrary = docLibrary; this.name = name; associatedBieName = associatedMaName; }
public void ExecuteXmlSchemaSubsetting(IDocLibrary docLibrary) { // The UpccModelXsdTypes contains a list of extracted Xsd Type Names, such as the // name of an ABIE with the qualifier removed. Furthermore, each type, such as an ABIE // contains his respective children - in the case of an ABIE this would be the BBIEs // of the ABIE. UpccModelXsdTypes remainingXsdTypes = new UpccModelXsdTypes(docLibrary); HashSet <string> baseTypeNames = new HashSet <string>(); // Iterate through the XML schema files and for each type we need to check // whether the type still exists in our list of remaining types created through // the UpccModelXsdTypes constructor (see above). In case the type is contained // in the list of types according to the Upcc model, we add the type to a list named // baseTypeNames. The advantage is that we then only have those types from the XML // schema in the list which are also contained in the Upcc model. foreach (XmlSchema xmlSchema in xmlSchemas) { foreach (XmlSchemaType type in xmlSchema.SchemaTypes.Values) { if (remainingXsdTypes.ContainsXsdType(GetXsdTypeName(type))) { AddBaseTypeNames(type, baseTypeNames); } } } // Based on our knowledge, which types should stay in the XML schema file // we are now able to iterate through the XML schema and if necessary delete // the complex or simple type from the XML schema. foreach (XmlSchema xmlSchema in xmlSchemas) { foreach (XmlSchemaObject item in CopyValues(xmlSchema.Items)) { if (item is XmlSchemaComplexType) { string complexTypeName = ((XmlSchemaComplexType)item).QualifiedName.Name; if (remainingXsdTypes.ContainsXsdType(complexTypeName)) { RemoveElementsAndAttributesFromComplexType((XmlSchemaComplexType)item, remainingXsdTypes); } else { if (!baseTypeNames.Contains(complexTypeName)) { xmlSchema.Items.Remove(item); } } } if (item is XmlSchemaSimpleType) { string simpleTypeName = ((XmlSchemaSimpleType)item).QualifiedName.Name; if (!remainingXsdTypes.ContainsXsdType(simpleTypeName)) { if (!baseTypeNames.Contains(simpleTypeName)) { xmlSchema.Items.Remove(item); } } } } RemoveGlobalElementsHavingAnInvalidXsdType(xmlSchema, remainingXsdTypes, baseTypeNames); RemoveGlobalAttributesHavingAnInvalidXsdType(xmlSchema, remainingXsdTypes, baseTypeNames); } }
public void Test_calculate_remaining_xsd_types_from_document_model() { EARepository eaRepository = new EARepository(); Element bdtStringText = null; Element primString = null; Element abiePersonTypePerson = null; Element abiePersonTypeNote = null; #region EA Repository Subset eaRepository.AddModel( "Test Model Subset", m => m.AddPackage("bLibrary", bLibrary => { bLibrary.Element.Stereotype = Stereotype.bLibrary; bLibrary.AddPackage("PRIMLibrary", package => { package.Element.Stereotype = Stereotype.PRIMLibrary; primString = package.AddPRIM("String"); }); bLibrary.AddPackage("BDTLibrary", package => { package.Element.Stereotype = Stereotype.BDTLibrary; bdtStringText = package.AddBDT("String_Text").With(e => { e.Stereotype = Stereotype.BDT; e.AddCON(primString); }); }); bLibrary.AddPackage("BIELibrary", package => { package.Element.Stereotype = Stereotype.BIELibrary; Element abieAddressTypeAddress = package.AddClass("AddressType_Address").With(e => { e.Stereotype = Stereotype.ABIE; e.AddBBIE(bdtStringText, "City_CityName"); }); abiePersonTypePerson = package.AddClass("PersonType_Person").With(e => { e.Stereotype = Stereotype.ABIE; e.AddBBIE(bdtStringText, "Name_Name"); e.AddASBIE(abieAddressTypeAddress, "Address_Residence", EaAggregationKind.Composite); }); abiePersonTypeNote = package.AddClass("PersonType_Note").With(e => { e.Stereotype = Stereotype.ABIE; }); }); bLibrary.AddPackage("DOCLibrary", package => { package.Element.Stereotype = Stereotype.DOCLibrary; Element maPersonType = package.AddClass("PersonType").With(e => { e.Stereotype = Stereotype.MA; e.AddASMA(abiePersonTypePerson, "Person"); e.AddASMA(abiePersonTypeNote, "Note"); }); Element maPassportType = package.AddClass("PassportType").With(e => { e.Stereotype = Stereotype.MA; e.AddASMA(maPersonType, "Person"); }); package.AddClass("Austrian_Passport").With(e => { e.Stereotype = Stereotype.MA; e.AddASMA(maPassportType, "Passport"); }); }); })); #endregion ICctsRepository cctsRepository = CctsRepositoryFactory.CreateCctsRepository(eaRepository); IDocLibrary docLibrarySubset = cctsRepository.GetDocLibraryByPath((Path)"Test Model Subset" / "bLibrary" / "DOCLibrary"); UpccModelXsdTypes existingXsdTypes = new UpccModelXsdTypes(docLibrarySubset); // Positive Assertions Assert.That(existingXsdTypes.Count, Is.EqualTo(4)); Assert.That(existingXsdTypes.ContainsXsdType("String"), Is.True); Assert.That(existingXsdTypes.ContainsXsdType("AddressType"), Is.True); Assert.That(existingXsdTypes.ContainsXsdType("PersonType"), Is.True); Assert.That(existingXsdTypes.ContainsXsdType("PassportType"), Is.True); Assert.That(existingXsdTypes.NumberOfChildren("String"), Is.EqualTo(0)); Assert.That(existingXsdTypes.NumberOfChildren("AddressType"), Is.EqualTo(1)); Assert.That(existingXsdTypes.NumberOfChildren("PersonType"), Is.EqualTo(2)); Assert.That(existingXsdTypes.NumberOfChildren("PassportType"), Is.EqualTo(1)); Assert.That(existingXsdTypes.XsdTypeContainsChild("AddressType", "City"), Is.True); Assert.That(existingXsdTypes.XsdTypeContainsChild("PersonType", "Name"), Is.True); Assert.That(existingXsdTypes.XsdTypeContainsChild("PersonType", "Address"), Is.True); Assert.That(existingXsdTypes.XsdTypeContainsChild("PassportType", "Person"), Is.True); //Negative Assertions Assert.That(existingXsdTypes.ContainsXsdType("SuperDooperNonExistingType"), Is.False); Assert.That(existingXsdTypes.NumberOfChildren("SuperDooperNonExistingType"), Is.EqualTo(0)); Assert.That(existingXsdTypes.XsdTypeContainsChild("AddressType", "NonExistingChild"), Is.False); }
public void Test_exporting_subset_of_complex_type_mapped_to_multiple_accs() { string schemaFileComplete = TestUtils.PathToTestResource(@"XSDExporterTest\mapping\SubsetExporter\exporting_subset_of_complex_type_mapped_to_multiple_accs\source.xsd"); string schemaFileSubset = TestUtils.PathToTestResource(@"XSDExporterTest\mapping\SubsetExporter\exporting_subset_of_complex_type_mapped_to_multiple_accs\subset\"); EARepository eaRepository = new EARepository(); Element bdtStringText = null; Element primString = null; Element abiePersonTypePerson = null; Element abiePersonTypeNote = null; #region EA Repository Subset eaRepository.AddModel( "Test Model Subset", m => m.AddPackage("bLibrary", bLibrary => { bLibrary.Element.Stereotype = Stereotype.bLibrary; bLibrary.AddPackage("PRIMLibrary", package => { package.Element.Stereotype = Stereotype.PRIMLibrary; primString = package.AddPRIM("String"); }); bLibrary.AddPackage("BDTLibrary", package => { package.Element.Stereotype = Stereotype.BDTLibrary; bdtStringText = package.AddBDT("String_Text").With(e => { e.Stereotype = Stereotype.BDT; e.AddCON(primString); }); }); bLibrary.AddPackage("BIELibrary", package => { package.Element.Stereotype = Stereotype.BIELibrary; Element abieAddressTypeAddress = package.AddClass("AddressType_Address").With(e => { e.Stereotype = Stereotype.ABIE; e.AddBBIE(bdtStringText, "City_CityName"); }); abiePersonTypePerson = package.AddClass("PersonType_Person").With(e => { e.Stereotype = Stereotype.ABIE; e.AddBBIE(bdtStringText, "Name_Name"); e.AddASBIE(abieAddressTypeAddress, "Address_Residence", EaAggregationKind.Composite); }); abiePersonTypeNote = package.AddClass("PersonType_Note").With(e => { e.Stereotype = Stereotype.ABIE; }); }); bLibrary.AddPackage("DOCLibrary", package => { package.Element.Stereotype = Stereotype.DOCLibrary; Element maPersonType = package.AddClass("PersonType").With(e => { e.Stereotype = Stereotype.MA; e.AddASMA(abiePersonTypePerson, "Person"); e.AddASMA(abiePersonTypeNote, "Note"); }); Element maPassportType = package.AddClass("PassportType").With(e => { e.Stereotype = Stereotype.MA; e.AddASMA(maPersonType, "Person"); }); package.AddClass("Austrian_Passport").With(e => { e.Stereotype = Stereotype.MA; e.AddASMA(maPassportType, "Passport"); }); }); })); #endregion ICctsRepository cctsRepository = CctsRepositoryFactory.CreateCctsRepository(eaRepository); IDocLibrary docLibrary = cctsRepository.GetDocLibraryByPath((Path)"Test Model Subset" / "bLibrary" / "DOCLibrary"); SubsetExporter.ExportSubset(docLibrary, schemaFileComplete, schemaFileSubset); }
public UpccModelDiff(IDocLibrary docLibraryComplete, IDocLibrary docLibrarySubset) { this.docLibraryComplete = docLibraryComplete; this.docLibrarySubset = docLibrarySubset; }
/// <summary> /// /// </summary> /// <param name="schema"></param> /// <param name="ma"></param> /// <param name="context"></param> /// <param name="docLibrary"></param> private static void AddRootTypeDefinition(XmlSchema schema, IMa ma, GeneratorContext context, IDocLibrary docLibrary) { //XmlSchemaComplexType type = BIESchemaGenerator.GenerateComplexTypeABIE(context, schema, ma, NSPREFIX_BIE); var rootType = new XmlSchemaComplexType(); rootType.Name = ma.Name + "Type"; var sequence = new XmlSchemaSequence(); foreach (IAsma asma in ma.Asmas.OrderBy(a => a.Name)) { XmlSchemaElement elementAsma = null; // Take care of ASMAS aggregating ABIEs if (asma.AssociatedBieAggregator.IsAbie) { elementAsma = new XmlSchemaElement { Name = NDR.GetXsdElementNameFromAsma(asma), SchemaTypeName = new XmlQualifiedName(NSPREFIX_BIE + ":" + asma.AssociatedBieAggregator.Name + "Type") }; } else if (asma.AssociatedBieAggregator.IsMa) { elementAsma = new XmlSchemaElement { Name = NDR.GetXsdElementNameFromAsma(asma), SchemaTypeName = new XmlQualifiedName(context.NamespacePrefix + ":" + asma.AssociatedBieAggregator.Name + "Type") }; } var refAsma = new XmlSchemaElement { RefName = new XmlQualifiedName(context.NamespacePrefix + ":" + NDR.GetXsdElementNameFromAsma(asma)) }; // every shared ASCC may only appear once in the XSD file if (!globalAsmas.Contains(elementAsma.Name)) { // R 9241: for ASBIEs with AggregationKind = shared a global element must be declared. schema.Items.Add(elementAsma); globalAsmas.Add(elementAsma.Name); } sequence.Items.Add(refAsma); } rootType.Particle = sequence; if (context.Annotate) { rootType.Annotation = GetMaAnnotation(ma); } schema.Items.Add(rootType); }
public void Test_model_diff() { EARepository eaRepository = new EARepository(); Element cdtText = null; Element bdtStringText = null; Element primString = null; Element accAddress = null; Element accPerson = null; Element abieAddressTypeAddress = null; Element abieAddressTypePerson = null; #region EA Repository Complete eaRepository.AddModel( "Test Model Complete", m => m.AddPackage("bLibrary", bLibrary => { bLibrary.Element.Stereotype = Stereotype.bLibrary; bLibrary.AddPackage("PRIMLibrary", package => { package.Element.Stereotype = Stereotype.PRIMLibrary; primString = package.AddPRIM("String"); }); bLibrary.AddPackage("CDTLibrary", package => { package.Element.Stereotype = Stereotype.CDTLibrary; cdtText = package.AddCDT("Text").With(e => { e.Stereotype = Stereotype.CDT; e.AddCON(primString); e.AddSUPs(primString, "Language", "LanguageLocale"); }); }); bLibrary.AddPackage("CCLibrary", package => { package.Element.Stereotype = Stereotype.CCLibrary; accAddress = package.AddClass("Address") .With(e => e.Stereotype = Stereotype.ACC) .With(e => e.AddBCCs(cdtText, "StreetName", "CityName", "AttentionOf")); accPerson = package.AddClass("Person") .With(e => e.Stereotype = Stereotype.ACC) .With(e => e.AddBCCs(cdtText, "Name", "Title", "Salutation")); }); bLibrary.AddPackage("BDTLibrary", package => { package.Element.Stereotype = Stereotype.BDTLibrary; bdtStringText = package.AddBDT("String_Text").With(e => { e.Stereotype = Stereotype.BDT; e.AddBasedOnDependency(cdtText); e.AddCON(primString); }); }); bLibrary.AddPackage("BIELibrary", package => { package.Element.Stereotype = Stereotype.BIELibrary; abieAddressTypeAddress = package.AddClass("AddressType_Address").With(e => { e.Stereotype = Stereotype.ABIE; e.AddBasedOnDependency(accAddress); e.AddBBIE(bdtStringText, "Town_CityName"); }); abieAddressTypePerson = package.AddClass("AddressType_Person").With(e => { e.Stereotype = Stereotype.ABIE; e.AddBasedOnDependency(accPerson); e.AddBBIE(bdtStringText, "PersonName_Name"); }); }); bLibrary.AddPackage("DOCLibrary", package => { package.Element.Stereotype = Stereotype.DOCLibrary; Element maAddressType = package.AddClass("AddressType").With(e => { e.Stereotype = Stereotype.MA; e.AddASMA(abieAddressTypeAddress, "Address"); e.AddASMA(abieAddressTypePerson, "Person"); }); Element maInvoiceType = package.AddClass("InvoiceType").With(e => { e.Stereotype = Stereotype.MA; e.AddASMA(maAddressType, "Address"); }); package.AddClass("Test_Invoice").With(e => { e.Stereotype = Stereotype.MA; e.AddASMA(maInvoiceType, "Invoice"); }); }); })); #endregion #region EA Repository Subset eaRepository.AddModel( "Test Model Subset", m => m.AddPackage("bLibrary", bLibrary => { bLibrary.Element.Stereotype = Stereotype.bLibrary; bLibrary.AddPackage("PRIMLibrary", package => { package.Element.Stereotype = Stereotype.PRIMLibrary; primString = package.AddPRIM("String"); }); bLibrary.AddPackage("CDTLibrary", package => { package.Element.Stereotype = Stereotype.CDTLibrary; cdtText = package.AddCDT("Text").With(e => { e.Stereotype = Stereotype.CDT; e.AddCON(primString); e.AddSUPs(primString, "Language", "LanguageLocale"); }); }); bLibrary.AddPackage("CCLibrary", package => { package.Element.Stereotype = Stereotype.CCLibrary; accAddress = package.AddClass("Address") .With(e => e.Stereotype = Stereotype.ACC) .With(e => e.AddBCCs(cdtText, "StreetName", "CityName", "AttentionOf")); accPerson = package.AddClass("Person") .With(e => e.Stereotype = Stereotype.ACC) .With(e => e.AddBCCs(cdtText, "Name", "Title", "Salutation")); }); bLibrary.AddPackage("BDTLibrary", package => { package.Element.Stereotype = Stereotype.BDTLibrary; bdtStringText = package.AddBDT("String_Text").With(e => { e.Stereotype = Stereotype.BDT; e.AddBasedOnDependency(cdtText); e.AddCON(primString); }); }); bLibrary.AddPackage("BIELibrary", package => { package.Element.Stereotype = Stereotype.BIELibrary; abieAddressTypeAddress = package.AddClass("AddressType_Address").With(e => { e.Stereotype = Stereotype.ABIE; e.AddBasedOnDependency(accAddress); e.AddBBIE(bdtStringText, "Town_CityName"); }); abieAddressTypePerson = package.AddClass("AddressType_Person").With(e => { e.Stereotype = Stereotype.ABIE; e.AddBasedOnDependency(accPerson); }); }); bLibrary.AddPackage("DOCLibrary", package => { package.Element.Stereotype = Stereotype.DOCLibrary; Element maAddressType = package.AddClass("AddressType").With(e => { e.Stereotype = Stereotype.MA; e.AddASMA(abieAddressTypeAddress, "Address"); e.AddASMA(abieAddressTypePerson, "Person"); }); Element maInvoiceType = package.AddClass("InvoiceType").With(e => { e.Stereotype = Stereotype.MA; e.AddASMA(maAddressType, "Address"); }); package.AddClass("Test_Invoice").With(e => { e.Stereotype = Stereotype.MA; e.AddASMA(maInvoiceType, "Invoice"); }); }); })); #endregion ICctsRepository cctsRepository = CctsRepositoryFactory.CreateCctsRepository(eaRepository); IDocLibrary docLibraryComplete = cctsRepository.GetDocLibraryByPath((Path)"Test Model Complete" / "bLibrary" / "DOCLibrary"); IDocLibrary docLibrarySubset = cctsRepository.GetDocLibraryByPath((Path)"Test Model Subset" / "bLibrary" / "DOCLibrary"); Dictionary <string, List <string> > mutatedComplexTypes = new UpccModelDiff(docLibraryComplete, docLibrarySubset).CalculateDiff(); Dictionary <string, List <string> > expectedMutatedComplexTypes = new Dictionary <string, List <string> >(); expectedMutatedComplexTypes.Add("AddressType", new List <string> { "PersonName" }); Assert.That(mutatedComplexTypes.Keys, Is.EquivalentTo(expectedMutatedComplexTypes.Keys), "Defective Complex Type Mutation."); foreach (string complexTypeName in expectedMutatedComplexTypes.Keys) { Assert.That(mutatedComplexTypes[complexTypeName], Is.EquivalentTo(expectedMutatedComplexTypes[complexTypeName]), "Difference between Complex Type Mutation and expected Complex Type Mutation: " + complexTypeName + "."); } }
public static void Transform(IBieLibrary sourceBieLibrary, IBieLibrary targetBieLibrary, IDocLibrary sourceDocLibrary, IDocLibrary targetDocLibrary) { // ************** ANSATZ 1 ************************** // 0. BDTs und ASBIEs werden derzeit ignoriert. HashSet <int> existingBccs = new HashSet <int>(); // 1. Hashset von allen BCCs => dazu muessen wir: // => in der source BIE (i.e. ebInterface) library alle ABIEs durchlaufen, darin die BBIEs durchlaufen, // und fuer jeden BBIE den basedOn BCC im Hashset speichern foreach (IAbie abie in sourceBieLibrary.Abies) { foreach (IBbie bbie in abie.Bbies) { existingBccs.Add(bbie.BasedOn.Id); } } // 2. Durchlaufen aller ABIEs in der BIE Library von target (i.e. UBL), fuer jeden ABIE die BBIEs durchlaufen und // fuer jeden BBIE folgenden Schritt durchführen // => ist der BCC, auf welchem der BBIE basiert im Hashset vorhanden? // nein => loeschen des BBIEs // ja => nix tun // // The same alrogithm is used for BDT/SUP as well as ASBIEs. foreach (IAbie abie in targetBieLibrary.Abies) { List <IBbie> bbies = new List <IBbie>(abie.Bbies); foreach (IBbie bbie in bbies) { if (!existingBccs.Contains(bbie.BasedOn.Id)) { abie.RemoveBbie(bbie); } } } // 3. Durchlaufen des DOC Library Baumes, und bei den Blättern beginnend: existiert ein BBIE oder an ASBIE innherhalb // des aktuellen ABIEs? // // Nein? Dann wird der ABIE gelöscht. Es müssen auch die ASMAs oder ASBIEs welche auf den ABIE zeigen, entfernt werden. PruneUpccModel(targetDocLibrary, targetBieLibrary); // ************** ANSATZ 2 ************************** // Prinzipiell ist der Algorithmus gleich nur dass in diesem Ansatz nicht ueber die BIE Libraries iteriert wird // sondern rekursiv ueber die DOC Baeume. }
public void RemoveDocLibrary(IDocLibrary docLibrary) { throw new NotImplementedException(); }
public IDocLibrary UpdateDocLibrary(IDocLibrary docLibrary, DocLibrarySpec specification) { throw new NotImplementedException(); }