public object GetJsonFromMetadata(Metadata metadata, bool forBook) { dynamic derivativeInfo = null; if (forBook) { var originalMetadata = BookCopyrightAndLicense.GetOriginalMetadata(Model.CurrentBook.Storage.Dom, Model.CurrentBook.BookData); var languagePriorityIdsNotLang1 = Model.CurrentBook.BookData.GetLanguagePrioritiesForLocalizedTextOnPage(false); var licenseText = BookCopyrightAndLicense.GetOriginalLicenseSentence(languagePriorityIdsNotLang1, originalMetadata.License, out string _); derivativeInfo = new { isBookDerivative = BookCopyrightAndLicense.IsDerivative(originalMetadata), useOriginalCopyright = Model.CurrentBook.BookInfo.MetaData.UseOriginalCopyright, originalCopyrightAndLicenseText = $"{originalMetadata.CopyrightNotice}, {licenseText}", originalCopyrightYear = originalMetadata.GetCopyrightYear(), originalCopyrightHolder = originalMetadata.GetCopyrightBy(), originalLicense = GetLicense(originalMetadata) }; } var intellectualPropertyData = new { derivativeInfo = derivativeInfo, copyrightInfo = new { imageCreator = metadata.Creator ?? string.Empty, copyrightYear = metadata.GetCopyrightYear() ?? string.Empty, copyrightHolder = metadata.GetCopyrightBy() ?? string.Empty, }, licenseInfo = GetLicense(metadata), }; return(intellectualPropertyData); }
public void SetMetadata_CopiesCopyrightAndOriginalCopyrightToMultipleDestinations() { // We could test other fields too, but these are enough to cover the two main methods that do the copying. var html = @"<html><head><meta name='lockedDownAsShell' content='true'></meta></head><body> <div id='bloomDataDiv'> <div data-book='copyright' lang='*'>Copyright © 2008, Bar Publishers</div> <div data-book='originalLicenseUrl' lang='*'>http://creativecommons.org/licenses/by-nc/4.0/</div> <div data-book='originalLicenseNotes' lang='*'>You can do anything you want if your name is Fred.</div> <div data-book='originalCopyright' lang='*'>Copyright © 2007, Foo Publishers</div> </div> <div id='test' class='test'> <div data-derived='copyright' lang='*'>something obsolete</div> <div data-derived='originalCopyrightAndLicense' lang='en'>BoilerPlateDescription</div> </div> <div id='test2' class='test'> <div data-derived='copyright' lang='*'>something else obsolete to be overwritten</div> <div data-derived='originalCopyrightAndLicense' lang='en'>Some other place we show original copyright</div> </div> </body></html>" ; var bookDom = new HtmlDom(html); var bookData = new BookData(bookDom, _collectionSettings, null); var metadata = BookCopyrightAndLicense.GetMetadata(bookDom, bookData); metadata.CopyrightNotice = "Copyright © 2019, Foo-Bar Publishers"; BookCopyrightAndLicense.SetMetadata(metadata, bookDom, "", bookData, false); // This is an abbreviated version of the text we expect in originalCopyrightAndLicense. Now that we have an embedded <cite> element, matching the whole thing // is difficult. We have other tests that deal with exactly what goes in this field; here we're just concerned with generating it or not. AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='test']/*[@data-derived='originalCopyrightAndLicense' and @lang='*' and contains(text(),'This book is an adaptation of the original')]", 2); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='test']/*[@data-derived='copyright' and @lang='*' and contains(text(),'Copyright © 2019, Foo-Bar Publishers')]", 2); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='copyright' and contains(text(), 'Copyright © 2019, Foo-Bar Publishers')]", 1); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='originalCopyright' and contains(text(), 'Copyright © 2007, Foo Publishers')]", 1); AssertThatXmlIn.Dom(bookDom.RawDom).HasNoMatchForXpath("//div[@id='bloomDataDiv']/div[@data-book='licenseUrl']"); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='originalLicenseUrl' and contains(text(), 'http://creativecommons.org/licenses/by-nc/4.0/')]", 1); // Change to use the original copyright and license. var originalMetadata = BookCopyrightAndLicense.GetOriginalMetadata(bookDom, bookData); BookCopyrightAndLicense.SetMetadata(originalMetadata, bookDom, "", bookData, true); AssertThatXmlIn.Dom(bookDom.RawDom).HasNoMatchForXpath("//div[@class='test']/*[@data-derived='originalCopyrightAndLicense' and @lang='*']"); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='test']/*[@data-derived='originalCopyrightAndLicense' and .='']", 2); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='test']/*[@data-derived='copyright' and @lang='*' and contains(text(),'Copyright © 2007, Foo Publishers')]", 2); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='copyright' and contains(text(), 'Copyright © 2007, Foo Publishers')]", 1); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='originalCopyright' and contains(text(), 'Copyright © 2007, Foo Publishers')]", 1); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='licenseUrl' and contains(text(), 'http://creativecommons.org/licenses/by-nc/4.0/')]", 1); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='originalLicenseUrl' and contains(text(), 'http://creativecommons.org/licenses/by-nc/4.0/')]", 1); }
private Metadata GetMetadataFromJson(ApiRequest request, bool forBook) { var json = request.RequiredPostJson(); var settings = DynamicJson.Parse(json); if (forBook) { Model.CurrentBook.BookInfo.MetaData.UseOriginalCopyright = settings.derivativeInfo.useOriginalCopyright; if (settings.derivativeInfo.useOriginalCopyright) { return(BookCopyrightAndLicense.GetOriginalMetadata(Model.CurrentBook.Storage.Dom, Model.CurrentBook.BookData)); } } var metadata = new Metadata { Creator = settings.copyrightInfo.imageCreator }; metadata.SetCopyrightNotice(settings.copyrightInfo.copyrightYear, settings.copyrightInfo.copyrightHolder); if (settings.licenseInfo.licenseType == "creativeCommons") { metadata.License = new CreativeCommonsLicense( true, settings.licenseInfo.creativeCommonsInfo.allowCommercial == "yes", GetCcDerivativeRule(settings.licenseInfo.creativeCommonsInfo.allowDerivatives)) { IntergovernmentalOriganizationQualifier = settings.licenseInfo.creativeCommonsInfo.intergovernmentalVersion }; } else if (settings.licenseInfo.licenseType == "publicDomain") { metadata.License = CreativeCommonsLicense.FromToken("cc0"); } else if (settings.licenseInfo.licenseType == "contact") { metadata.License = new NullLicense(); } else { metadata.License = new CustomLicense(); } metadata.License.RightsStatement = settings.licenseInfo.rightsStatement; return(metadata); }