/// <summary> /// Rebuilds the RDF graphs. /// </summary> public static void Rebuild() { _latestRebuildOutcome = "ok"; try { var ontologyGraph = new OntologyFactory(new UmbracoDocumentTypeRepository(), new UmbracoPropertyTypeRepository()). GenerateOntologyGraph(); var resourceGraph = new ResourceFactory(new UmbracoNodeRepository(), new UmbracoPropertyTypeRepository(), new UmbracoDocumentTypeRepository()).GenerateResourceGraph(); SaveGraphs(ontologyGraph, resourceGraph); } catch (Exception ex) { var errorEntry = string.IsNullOrEmpty(ex.Message) ? "Unspecified" : ex.Message; if (!string.IsNullOrEmpty(ex.StackTrace)) { errorEntry += " - " + ex.StackTrace; } if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message)) { errorEntry += " - " + ex.InnerException.Message; } _latestRebuildOutcome = errorEntry; Log.Error(errorEntry); } }
public void GenerateDocumentType() { var dt9 = new UmbracoDocumentType() { AllowedContentTypeChildrenIds = new int[] {10}, InherritanceParentId = 16, InherritanceChildrenIds = new List<int>(){13}, Name = "TestDocumentType", PropertyTypes = new List<UmbracoPropertyType>() { new UmbracoPropertyType() {DatabaseType = "nvarchar", Name = "title"}, new UmbracoPropertyType() {DatabaseType = "nvarchar", Name = "content"} } }; var dt16 = new UmbracoDocumentType() { AllowedContentTypeChildrenIds = new int[] { 9 }, Name = "TestParentDocumentType", PropertyTypes = new List<UmbracoPropertyType>() { new UmbracoPropertyType() {DatabaseType = "nvarchar", Name = "title"}, new UmbracoPropertyType() {DatabaseType = "nvarchar", Name = "content"} } }; var dt13 = new UmbracoDocumentType() { Name = "TestInherritanceChildType", PropertyTypes = new List<UmbracoPropertyType>() { new UmbracoPropertyType() {DatabaseType = "nvarchar", Name = "title"}, new UmbracoPropertyType() {DatabaseType = "nvarchar", Name = "content"} } }; var dt10 = new UmbracoDocumentType() { Name = "TestAllowedContentChild", PropertyTypes = new List<UmbracoPropertyType>() { new UmbracoPropertyType() {DatabaseType = "nvarchar", Name = "title"}, new UmbracoPropertyType() {DatabaseType = "nvarchar", Name = "content"} } }; var mockDocTypeRepo = new Mock<IUmbracoDocumentTypeRepository>(); mockDocTypeRepo.Setup(x => x.GetById(9)) .Returns(dt9); mockDocTypeRepo.Setup(x => x.GetById(16)) .Returns(dt16); mockDocTypeRepo.Setup(x => x.GetById(13)) .Returns(dt13); mockDocTypeRepo.Setup(x => x.GetById(10)) .Returns(dt10); var titleDt = new UmbracoPropertyType {DatabaseType = "nvarchar", Name = "title"}; var contentDt = new UmbracoPropertyType { DatabaseType = "nvarchar", Name = "content" }; var mockPropTypeRepo = new Mock<IUmbracoPropertyTypeRepository>(); mockPropTypeRepo.Setup(x => x.GetForNativeDocumentTypePropertyAlias(9, "title")) .Returns(titleDt); mockPropTypeRepo.Setup(x => x.GetForNativeDocumentTypePropertyAlias(9, "content")) .Returns(contentDt); var factory = new OntologyFactory(mockDocTypeRepo.Object, mockPropTypeRepo.Object); var docType = factory.GenerateDocumentType(9); Debug.WriteLine("Created document type with IRI: " + docType.Iri); Assert.AreEqual("http://localhost/rdf/ontology#TestDocumentType", docType.Iri); Assert.AreEqual("http://localhost/rdf/ontology#TestParentDocumentType", docType.ParentIri); Assert.AreEqual(2, docType.PropertyTypes.Count); Assert.IsTrue(docType.PropertyTypes.Any(x => x.Iri == "http://localhost/rdf/ontology#hasTitle" && x.DatabaseType == "nvarchar")); Assert.IsTrue(docType.PropertyTypes.Single(x => x.Iri == "http://localhost/rdf/ontology#hasTitle").EquivalentIris.Count == 3); Assert.IsTrue(docType.PropertyTypes.Any(x => x.Iri == "http://localhost/rdf/ontology#hasContent" && x.DatabaseType == "nvarchar")); Assert.AreEqual(1, docType.AllowedContentTypeChildrenIris.Count); Assert.AreEqual("http://localhost/rdf/ontology#TestAllowedContentChild", docType.AllowedContentTypeChildrenIris[0]); Assert.AreEqual(1, docType.ChildrenIris.Count); Assert.IsTrue(docType.ChildrenIris.Any(x => x == "http://localhost/rdf/ontology#TestInherritanceChildType")); }