/// <summary> Store the EAD information related to a digital resource on the cache </summary> /// <param name="BibID"> Bibliographic Identifier for the digital resource to store </param> /// <param name="VID"> Volume Identifier for the digital resource to store </param> /// <param name="StoreObject"> EAD information for a digital Resource object to store for later retrieval </param> /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering</param> public void Store_EAD_Info(string BibID, string VID, EAD_Transfer_Object StoreObject, Custom_Tracer Tracer) { // If the cache is disabled, just return before even tracing if (settings.Disabled) return; // Determine the key string key = "ITEM_" + BibID + "_" + VID + "_EadInfo"; const int LENGTH_OF_TIME = 3; if (Tracer != null) { Tracer.Add_Trace("CachedDataManager_ItemServices.Store_EAD_Info", "Adding object '" + key + "' to the local cache with expiration of " + LENGTH_OF_TIME + " minute"); } HttpContext.Current.Cache.Insert(key, StoreObject, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(LENGTH_OF_TIME)); }
/// <summary> Gets any EAD information related to an item </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> public void GetItemEAD(HttpResponse Response, List<string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { // Must at least have one URL segment for the BibID if (UrlSegments.Count > 0) { Custom_Tracer tracer = new Custom_Tracer(); try { // Get the BibID and VID string bibid = UrlSegments[0]; string vid = (UrlSegments.Count > 1) ? UrlSegments[1] : "00001"; tracer.Add_Trace("ItemServices.GetItemEAD", "Requested ead info for " + bibid + ":" + vid); // Is it a valid BibID/VID, at least in appearance? if ((vid.Length > 0) && (vid != "00000")) { // Get the JSON-P callback function string json_callback = "parseItemEAD"; if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"]))) { json_callback = QueryString["callback"]; } // Just look in the cache for the EAD information EAD_Transfer_Object eadTransferInfo = CachedDataManager.Items.Retrieve_EAD_Info(bibid, vid, tracer); if (eadTransferInfo != null) { tracer.Add_Trace("ItemServices.GetItemEAD", "Found pre-built EAD transfer object in the cache"); // If this was debug mode, then just write the tracer if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } // Use the base class to serialize the object according to request protocol Serialize(eadTransferInfo, Response, Protocol, json_callback); } // Get the full SOobekCM_Item object for the provided BibID / VID tracer.Add_Trace("ItemServices.GetItemEAD", "Get the full SobekCM_Item object for this BibID / VID"); SobekCM_Item currentItem = getSobekItem(bibid, vid, tracer); if (currentItem == null) { // If this was debug mode, then just write the tracer if (IsDebug) { tracer.Add_Trace("ItemServices.GetItemEAD", "Could not retrieve the full SobekCM_Item object"); Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); } return; } // Create the wrapper to return only basic citation-type information tracer.Add_Trace("ItemServices.GetItemEAD", "Create wrapper class to return only the ead info"); EAD_Transfer_Object responder = new EAD_Transfer_Object(); // Transfer all the data over to the EAD transfer object EAD_Info eadInfo = currentItem.Get_Metadata_Module(GlobalVar.PALMM_RIGHTSMD_METADATA_MODULE_KEY) as EAD_Info; if (eadInfo != null) { tracer.Add_Trace("ItemServices.GetItemEAD", "Copy all the source EAD information into the transfer EAD object"); // Copy over the full description responder.Full_Description = eadInfo.Full_Description; // Add all the ead TOC sections if (eadInfo.TOC_Included_Sections != null) { foreach (EAD_TOC_Included_Section tocSection in eadInfo.TOC_Included_Sections) { responder.Add_TOC_Included_Section(tocSection.Internal_Link_Name, tocSection.Section_Title); } } // Copy over all the container portions as well if (eadInfo.Container_Hierarchy != null) { responder.Container_Hierarchy.Type = eadInfo.Container_Hierarchy.Type; responder.Container_Hierarchy.Head = eadInfo.Container_Hierarchy.Head; responder.Container_Hierarchy.Did = ead_copy_did_to_transfer(eadInfo.Container_Hierarchy.Did); if (eadInfo.Container_Hierarchy.Containers != null) { foreach (Container_Info containerInfo in eadInfo.Container_Hierarchy.Containers) { responder.Container_Hierarchy.Containers.Add(ead_copy_container_to_transfer(containerInfo)); } } } } else { tracer.Add_Trace("ItemServices.GetItemEAD", "This existing digital resource has no special EAD information"); } // If this was debug mode, then just write the tracer if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } // Cache this as well, since it appears to be valid CachedDataManager.Items.Store_EAD_Info(bibid, vid, responder, tracer); // Use the base class to serialize the object according to request protocol Serialize(responder, Response, Protocol, json_callback); } else { tracer.Add_Trace("ItemServices.GetItemEAD", "Requested VID 0000 - Invalid"); // If this was debug mode, then just write the tracer if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); } } } catch (Exception ee) { if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("EXCEPTION CAUGHT!"); Response.Output.WriteLine(); Response.Output.WriteLine(ee.Message); Response.Output.WriteLine(); Response.Output.WriteLine(ee.StackTrace); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } Response.ContentType = "text/plain"; Response.Output.WriteLine("Error completing request"); Response.StatusCode = 500; } } }