public Metadata Transform(Metadata metadata) { if (metadata.Kref != null && metadata.Kref.Source == KrefSource) { var json = metadata.Json(); Log.InfoFormat("Executing MetaNetkan transformation with {0}", metadata.Kref); Log.DebugFormat("Input metadata:{0}{1}", Environment.NewLine, json); var uri = new Uri(metadata.Kref.Id); var targetFileText = _http.DownloadText(uri); Log.DebugFormat("Target netkan:{0}{1}", Environment.NewLine, targetFileText); var targetJson = JObject.Parse(targetFileText); var targetMetadata = new Metadata(targetJson); if (targetMetadata.Kref == null || targetMetadata.Kref.Source != "netkan") { json["spec_version"] = ModuleVersion.Max(metadata.SpecVersion, targetMetadata.SpecVersion) .ToSpecVersionJson(); if (targetJson["$kref"] != null) { json["$kref"] = targetJson["$kref"]; } else { json.Remove("$kref"); } foreach (var property in targetJson.Properties()) { json.SafeAdd(property.Name, property.Value); } Log.DebugFormat("Transformed metadata:{0}{1}", Environment.NewLine, json); return(new Metadata(json)); } else { throw new Kraken("The target of a metanetkan may not also be a metanetkan."); } } return(metadata); }
public IEnumerable <Metadata> Transform(Metadata metadata, TransformOptions opts) { if (metadata.Download != null) { var json = metadata.Json(); string file = _http.DownloadModule(metadata); var internalJson = _moduleService.GetInternalCkan(file); if (internalJson != null) { Log.InfoFormat("Executing internal CKAN transformation with {0}", metadata.Kref); Log.DebugFormat("Input metadata:{0}{1}", Environment.NewLine, json); foreach (var property in internalJson.Properties()) { // We've already got the file, too late to tell us where it lives if (property.Name == "$kref") { Log.DebugFormat("Skipping $kref property: {0}", property.Value); continue; } json.SafeAdd(property.Name, property.Value); } json["spec_version"] = ModuleVersion.Max(metadata.SpecVersion, new Metadata(internalJson).SpecVersion) .ToSpecVersionJson(); json.SafeMerge("resources", internalJson["resources"]); Log.DebugFormat("Transformed metadata:{0}{1}", Environment.NewLine, json); } yield return(new Metadata(json)); } else { yield return(metadata); } }
public IEnumerable <Metadata> Transform(Metadata metadata, TransformOptions opts) { if (metadata.Kref != null && metadata.Kref.Source == KrefSource) { var json = metadata.Json(); Log.InfoFormat("Executing MetaNetkan transformation with {0}", metadata.Kref); Log.DebugFormat("Input metadata:{0}{1}", Environment.NewLine, json); // Make sure resources exist, save metanetkan if (json["resources"] == null) { json["resources"] = new JObject(); } var resourcesJson = (JObject)json["resources"]; resourcesJson.SafeAdd("metanetkan", metadata.Kref.Id); var uri = new Uri(metadata.Kref.Id); var targetFileText = _github?.DownloadText(uri) ?? _http.DownloadText(CKAN.Net.GetRawUri(uri)); Log.DebugFormat("Target netkan:{0}{1}", Environment.NewLine, targetFileText); var targetJson = JObject.Parse(targetFileText); var targetMetadata = new Metadata(targetJson); if (targetMetadata.Kref == null || targetMetadata.Kref.Source != "netkan") { json["spec_version"] = ModuleVersion.Max(metadata.SpecVersion, targetMetadata.SpecVersion) .ToSpecVersionJson(); if (targetJson["$kref"] != null) { json["$kref"] = targetJson["$kref"]; } else { json.Remove("$kref"); } json.SafeMerge("resources", targetJson["resources"]); foreach (var property in targetJson.Properties()) { json.SafeAdd(property.Name, property.Value); } Log.DebugFormat("Transformed metadata:{0}{1}", Environment.NewLine, json); yield return(new Metadata(json)); } else { throw new Kraken("The target of a metanetkan may not also be a metanetkan."); } } else { yield return(metadata); } }