/// <summary> Constructor for a new instance of the Group_Add_Volume_MySobekViewer class </summary>
        /// <param name="RequestSpecificValues"> All the necessary, non-global data specific to the current request </param>
        public Group_Add_Volume_MySobekViewer(RequestCache RequestSpecificValues)  : base(RequestSpecificValues)
        {
            RequestSpecificValues.Tracer.Add_Trace("Group_Add_Volume_MySobekViewer.Constructor", String.Empty);

            // If no user then that is an error
            if ((RequestSpecificValues.Current_User == null) || (!RequestSpecificValues.Current_User.LoggedOn))
            {
                RequestSpecificValues.Current_Mode.Mode        = Display_Mode_Enum.Aggregation;
                RequestSpecificValues.Current_Mode.Aggregation = String.Empty;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                return;
            }

            // Ensure BibID provided
            RequestSpecificValues.Tracer.Add_Trace("Group_Add_Volume_MySobekViewer.Constructor", "Validate provided bibid");
            if (String.IsNullOrEmpty(RequestSpecificValues.Current_Mode.BibID))
            {
                RequestSpecificValues.Tracer.Add_Trace("Group_Add_Volume_MySobekViewer.Constructor", "BibID was not provided!");
                RequestSpecificValues.Current_Mode.Mode          = Display_Mode_Enum.Error;
                RequestSpecificValues.Current_Mode.Error_Message = "Invalid Request : BibID missing in item group metadata edit request";
                return;
            }

            RequestSpecificValues.Tracer.Add_Trace("Group_Add_Volume_MySobekViewer.Constructor", "Try to pull this sobek complete item group");
            currentItem = SobekEngineClient.Items.Get_Sobek_Item_Group(RequestSpecificValues.Current_Mode.BibID, RequestSpecificValues.Tracer);
            if (currentItem == null)
            {
                RequestSpecificValues.Tracer.Add_Trace("Group_Add_Volume_MySobekViewer.Constructor", "Unable to build complete item group");
                RequestSpecificValues.Current_Mode.Mode          = Display_Mode_Enum.Error;
                RequestSpecificValues.Current_Mode.Error_Message = "Invalid Request : Unable to build complete item";
                return;
            }

            // Pull the list of items tied to this group - Get the list of other volumes
            RequestSpecificValues.Tracer.Add_Trace("Group_Add_Volume_MySobekViewer.Constructor", "Get the list of items under " + RequestSpecificValues.Current_Mode.BibID);
            try
            {
                allVolumes = SobekEngineClient.Items.Get_Multiple_Volumes(RequestSpecificValues.Current_Mode.BibID, RequestSpecificValues.Tracer);
            }
            catch (Exception ee)
            {
                RequestSpecificValues.Tracer.Add_Trace("Tracking_ItemViewer.Constructor", "Unable to pull volumes under " + RequestSpecificValues.Current_Mode.BibID);
                RequestSpecificValues.Current_Mode.Mode          = Display_Mode_Enum.Error;
                RequestSpecificValues.Current_Mode.Error_Message = "Internal Error : Unable to pull volumes under " + RequestSpecificValues.Current_Mode.BibID;
                return;
            }

            // Set some defaults
            ipRestrict              = -1;
            title                   = String.Empty;
            date                    = String.Empty;
            level1                  = String.Empty;
            level2                  = String.Empty;
            level3                  = String.Empty;
            level1Order             = -1;
            level2Order             = -1;
            level3Order             = -1;
            hierarchyCopiedFromDate = false;
            message                 = String.Empty;
            trackingBox             = String.Empty;
            bornDigital             = false;
            materialRecdDate        = null;
            materialRecdNotes       = String.Empty;
            dispositionAdvice       = -1;
            dispositionAdviceNotes  = String.Empty;


            // If the user cannot edit this item, go back
            if (!RequestSpecificValues.Current_User.Can_Edit_This_Item(currentItem.BibID, currentItem.Bib_Info.SobekCM_Type_String, currentItem.Bib_Info.Source.Code, currentItem.Bib_Info.HoldingCode, currentItem.Behaviors.Aggregation_Code_List))
            {
                RequestSpecificValues.Current_Mode.My_Sobek_Type = My_Sobek_Type_Enum.Home;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                return;
            }

            // Determine the default CompleteTemplate code
            string template_code = "addvolume";

            if (!RequestSpecificValues.Current_User.Include_Tracking_In_Standard_Forms)
            {
                template_code = "addvolume_notracking";
            }

            // Load this CompleteTemplate
            completeTemplate = Template_MemoryMgmt_Utility.Retrieve_Template(template_code, RequestSpecificValues.Tracer);
            if (completeTemplate != null)
            {
                RequestSpecificValues.Tracer.Add_Trace("Group_Add_Volume_MySobekViewer.Constructor", "Found CompleteTemplate in cache");
            }
            else
            {
                RequestSpecificValues.Tracer.Add_Trace("Group_Add_Volume_MySobekViewer.Constructor", "Reading CompleteTemplate file");

                // Look in the user-defined templates portion first
                string user_template = UI_ApplicationCache_Gateway.Settings.Servers.Base_MySobek_Directory + "templates\\user\\standard\\" + template_code + ".xml";
                if (!File.Exists(user_template))
                {
                    user_template = UI_ApplicationCache_Gateway.Settings.Servers.Base_MySobek_Directory + "templates\\default\\standard\\" + template_code + ".xml";
                }

                // Read this template
                Template_XML_Reader reader = new Template_XML_Reader();
                completeTemplate = new CompleteTemplate();
                reader.Read_XML(user_template, completeTemplate, true);

                // Save this into the cache
                Template_MemoryMgmt_Utility.Store_Template(template_code, completeTemplate, RequestSpecificValues.Tracer);
            }

            // See if there was a hidden request
            string hidden_request = HttpContext.Current.Request.Form["action"] ?? String.Empty;

            // If this was a cancel request do that
            if (hidden_request == "cancel")
            {
                RequestSpecificValues.Current_Mode.Mode = Display_Mode_Enum.Item_Display;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
            }
            else if (hidden_request.IndexOf("save") == 0)
            {
                // Get the VID that used as a source for this
                string vid = HttpContext.Current.Request.Form["base_volume"];

                if (string.IsNullOrEmpty(vid))
                {
                    message = "<span style=\"color: red\"><strong>No base volume selected!</strong></span>";
                }
                else
                {
                    try
                    {
                        // Get a new instance of this item
                        Tuple <SobekCM_Item, SobekCM_Item_Error> itemAndError = SobekCM_Item_Factory.Get_Item(RequestSpecificValues.Current_Mode.BibID, vid, UI_ApplicationCache_Gateway.Icon_List, RequestSpecificValues.Tracer);
                        SobekCM_Item saveItem = itemAndError.Item1;

                        // Clear some values for this item
                        saveItem.VID = String.Empty;
                        saveItem.Divisions.Clear();
                        saveItem.Behaviors.Serial_Info.Clear();
                        saveItem.Bib_Info.Series_Part_Info.Clear();
                        saveItem.Behaviors.Clear_Ticklers();
                        saveItem.Tracking.Internal_Comments   = String.Empty;
                        saveItem.Bib_Info.Location.PURL       = String.Empty;
                        saveItem.Behaviors.Main_Thumbnail     = String.Empty;
                        saveItem.METS_Header.Create_Date      = DateTime.Now;
                        saveItem.METS_Header.Modify_Date      = saveItem.METS_Header.Create_Date;
                        saveItem.METS_Header.Creator_Software = "SobekCM Web - Online add a volume (derived from VID " + vid + ")";
                        saveItem.METS_Header.Clear_Creator_Individual_Notes();
                        saveItem.METS_Header.Creator_Individual            = RequestSpecificValues.Current_User.Full_Name;
                        saveItem.Bib_Info.Location.Other_URL               = String.Empty;
                        saveItem.Bib_Info.Location.Other_URL_Display_Label = String.Empty;
                        saveItem.Bib_Info.Location.Other_URL_Note          = String.Empty;

                        // Save the CompleteTemplate changes to this item
                        completeTemplate.Save_To_Bib(saveItem, RequestSpecificValues.Current_User, 1);

                        // Save this item and copy over
                        complete_item_submission(saveItem, RequestSpecificValues.Tracer);

                        // Clear the volume list
                        CachedDataManager.Items.Remove_Items_In_Title(saveItem.BibID, RequestSpecificValues.Tracer);
                        CachedDataManager.Items.Remove_Items_List(saveItem.BibID, RequestSpecificValues.Tracer);

                        // Also clear the engine
                        SobekEngineClient.Items.Clear_Item_Group_Cache(saveItem.BibID, RequestSpecificValues.Tracer);

                        // Also clear any searches or browses ( in the future could refine this to only remove those
                        // that are impacted by this save... but this is good enough for now )
                        CachedDataManager.Clear_Search_Results_Browses();

                        // Forward differently depending on request
                        switch (hidden_request)
                        {
                        case "save_edit":
                            RequestSpecificValues.Current_Mode.Mode          = Display_Mode_Enum.My_Sobek;
                            RequestSpecificValues.Current_Mode.My_Sobek_Type = My_Sobek_Type_Enum.Edit_Item_Metadata;
                            RequestSpecificValues.Current_Mode.VID           = saveItem.VID;
                            UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                            break;

                        case "save_again":
                            // No redirect, but save values
                            date                   = saveItem.Bib_Info.Origin_Info.Date_Issued;
                            ipRestrict             = saveItem.Behaviors.IP_Restriction_Membership;
                            trackingBox            = saveItem.Tracking.Tracking_Box;
                            bornDigital            = saveItem.Tracking.Born_Digital;
                            dispositionAdvice      = saveItem.Tracking.Disposition_Advice;
                            dispositionAdviceNotes = saveItem.Tracking.Disposition_Advice_Notes;
                            materialRecdDate       = saveItem.Tracking.Material_Received_Date;
                            materialRecdNotes      = saveItem.Tracking.Material_Received_Notes;
                            if (!hierarchyCopiedFromDate)
                            {
                                if (saveItem.Behaviors.Serial_Info.Count > 0)
                                {
                                    level1      = saveItem.Behaviors.Serial_Info[0].Display;
                                    level1Order = saveItem.Behaviors.Serial_Info[0].Order;
                                }
                                if (saveItem.Behaviors.Serial_Info.Count > 1)
                                {
                                    level2      = saveItem.Behaviors.Serial_Info[1].Display;
                                    level2Order = saveItem.Behaviors.Serial_Info[1].Order;
                                }
                                if (saveItem.Behaviors.Serial_Info.Count > 2)
                                {
                                    level3      = saveItem.Behaviors.Serial_Info[2].Display;
                                    level3Order = saveItem.Behaviors.Serial_Info[2].Order;
                                }
                            }
                            message = message + "<span style=\"color: blue\"><strong>Saved new volume ( " + saveItem.BibID + " : " + saveItem.VID + ")</strong></span>";
                            break;

                        case "save_addfiles":
                            RequestSpecificValues.Current_Mode.Mode          = Display_Mode_Enum.My_Sobek;
                            RequestSpecificValues.Current_Mode.My_Sobek_Type = My_Sobek_Type_Enum.File_Management;
                            RequestSpecificValues.Current_Mode.VID           = saveItem.VID;
                            UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                            break;

                        default:
                            RequestSpecificValues.Current_Mode.Mode = Display_Mode_Enum.Item_Display;
                            RequestSpecificValues.Current_Mode.VID  = saveItem.VID;
                            UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                            break;
                        }
                    }
                    catch (Exception ee)
                    {
                        message = message + "<br /><span style=\"color: red\"><strong>EXCEPTION CAUGHT!<br /><br />" + ee.Message + "<br /><br />" + ee.StackTrace.Replace("\n", "<br />") + "</strong></span>";
                    }
                }
            }
        }
        /// <summary> Constructor for a new instance of the Edit_Item_Behaviors_MySobekViewer class </summary>
        ///  <param name="RequestSpecificValues"> All the necessary, non-global data specific to the current request </param>
        public Edit_Item_Behaviors_MySobekViewer(RequestCache RequestSpecificValues) : base(RequestSpecificValues)
        {
            RequestSpecificValues.Tracer.Add_Trace("Edit_Item_Behaviors_MySobekViewer.Constructor", String.Empty);

            // If no user then that is an error
            if ((RequestSpecificValues.Current_User == null) || (!RequestSpecificValues.Current_User.LoggedOn))
            {
                RequestSpecificValues.Current_Mode.Mode        = Display_Mode_Enum.Aggregation;
                RequestSpecificValues.Current_Mode.Aggregation = String.Empty;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                return;
            }

            // Ensure BibID and VID provided
            RequestSpecificValues.Tracer.Add_Trace("Edit_Item_Behaviors_MySobekViewer.Constructor", "Validate provided bibid / vid");
            if ((String.IsNullOrEmpty(RequestSpecificValues.Current_Mode.BibID)) || (String.IsNullOrEmpty(RequestSpecificValues.Current_Mode.VID)))
            {
                RequestSpecificValues.Tracer.Add_Trace("Edit_Item_Behaviors_MySobekViewer.Constructor", "BibID or VID was not provided!");
                RequestSpecificValues.Current_Mode.Mode          = Display_Mode_Enum.Error;
                RequestSpecificValues.Current_Mode.Error_Message = "Invalid Request : BibID/VID missing in item behavior request";
                return;
            }

            RequestSpecificValues.Tracer.Add_Trace("Edit_Item_Behaviors_MySobekViewer.Constructor", "Try to pull this sobek complete item");
            currentItem = SobekEngineClient.Items.Get_Sobek_Item(RequestSpecificValues.Current_Mode.BibID, RequestSpecificValues.Current_Mode.VID, RequestSpecificValues.Current_User.UserID, RequestSpecificValues.Tracer);
            if (currentItem == null)
            {
                RequestSpecificValues.Tracer.Add_Trace("Edit_Item_Behaviors_MySobekViewer.Constructor", "Unable to build complete item");
                RequestSpecificValues.Current_Mode.Mode          = Display_Mode_Enum.Error;
                RequestSpecificValues.Current_Mode.Error_Message = "Invalid Request : Unable to build complete item";
                return;
            }


            // If no item, then an error occurred
            if (currentItem == null)
            {
                RequestSpecificValues.Current_Mode.Mode          = Display_Mode_Enum.Error;
                RequestSpecificValues.Current_Mode.Error_Message = "Invalid item indicated";
                return;
            }

            // If the RequestSpecificValues.Current_User cannot edit this currentItem, go back
            if (!RequestSpecificValues.Current_User.Can_Edit_This_Item(currentItem.BibID, currentItem.Bib_Info.SobekCM_Type_String, currentItem.Bib_Info.Source.Code, currentItem.Bib_Info.HoldingCode, currentItem.Behaviors.Aggregation_Code_List))
            {
                RequestSpecificValues.Current_Mode.My_Sobek_Type = My_Sobek_Type_Enum.Home;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                return;
            }

            const string TEMPLATE_CODE = "itembehaviors";

            completeTemplate = Template_MemoryMgmt_Utility.Retrieve_Template(TEMPLATE_CODE, RequestSpecificValues.Tracer);
            if (completeTemplate != null)
            {
                RequestSpecificValues.Tracer.Add_Trace("Edit_Item_Behaviors_MySobekViewer.Constructor", "Found CompleteTemplate in cache");
            }
            else
            {
                RequestSpecificValues.Tracer.Add_Trace("Edit_Item_Behaviors_MySobekViewer.Constructor", "Reading CompleteTemplate file");

                // Look in the user-defined templates portion first
                string user_template = UI_ApplicationCache_Gateway.Settings.Servers.Base_MySobek_Directory + "templates\\user\\standard\\" + TEMPLATE_CODE + ".xml";
                if (!File.Exists(user_template))
                {
                    user_template = UI_ApplicationCache_Gateway.Settings.Servers.Base_MySobek_Directory + "templates\\default\\standard\\" + TEMPLATE_CODE + ".xml";
                }


                // Read this CompleteTemplate
                Template_XML_Reader reader = new Template_XML_Reader();
                completeTemplate = new CompleteTemplate();
                reader.Read_XML(user_template, completeTemplate, true);

                // Save this into the cache
                Template_MemoryMgmt_Utility.Store_Template(TEMPLATE_CODE, completeTemplate, RequestSpecificValues.Tracer);
            }

            // See if there was a hidden request
            string hidden_request = HttpContext.Current.Request.Form["behaviors_request"] ?? String.Empty;

            // If this was a cancel request do that
            if (hidden_request == "cancel")
            {
                RequestSpecificValues.Current_Mode.Mode = Display_Mode_Enum.Item_Display;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
            }
            else if (hidden_request == "save")
            {
                // Changes to the tracking box require the metadata search citation be rebuilt for this currentItem
                // so save the old tracking box information first
                string oldTrackingBox = currentItem.Tracking.Tracking_Box;

                // Save these changes to bib
                completeTemplate.Save_To_Bib(currentItem, RequestSpecificValues.Current_User, 1);

                // Save the behaviors
                SobekCM_Item_Database.Save_Behaviors(currentItem, currentItem.Behaviors.Text_Searchable, false, false);

                // Save the serial hierarchy as well (sort of a behavior)
                SobekCM_Item_Database.Save_Serial_Hierarchy_Information(currentItem, currentItem.Web.GroupID, currentItem.Web.ItemID);

                // Did the tracking box change?
                if (currentItem.Tracking.Tracking_Box != oldTrackingBox)
                {
                    SobekCM_Item_Database.Create_Full_Citation_Value(currentItem.Web.ItemID);
                }

                // Remoe from the caches (to replace the other)
                CachedDataManager.Items.Remove_Digital_Resource_Object(currentItem.BibID, currentItem.VID, RequestSpecificValues.Tracer);

                // Also remove the list of volumes, since this may have changed
                CachedDataManager.Items.Remove_Items_In_Title(currentItem.BibID, RequestSpecificValues.Tracer);
                CachedDataManager.Items.Remove_Items_List(currentItem.BibID, RequestSpecificValues.Tracer);

                // Also clear the engine
                SobekEngineClient.Items.Clear_Item_Group_Cache(currentItem.BibID, RequestSpecificValues.Tracer);

                // Also clear any searches or browses ( in the future could refine this to only remove those
                // that are impacted by this save... but this is good enough for now )
                CachedDataManager.Clear_Search_Results_Browses();

                // Forward
                RequestSpecificValues.Current_Mode.Mode = Display_Mode_Enum.Item_Display;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
            }
        }
Example #3
0
        /// <summary> Update the exsting digital resource, by saving the changes to the database and rewriting metadata files </summary>
        /// <param name="Item"> Digital resource object with all the updated metadata </param>
        /// <param name="User"> User who performed the update, for the item milestones </param>
        /// <param name="Error_Message"> [OUT] Return an error message if an exception is encountered </param>
        /// <returns> TRUE if successful, otherwise FALSE </returns>
        public static bool Update_Item(SobekCM_Item Item, User_Object User, out string Error_Message)
        {
            Error_Message = String.Empty;

            // Determine the in process directory for this
            string user_bib_vid_process_directory = Path.Combine(Engine_ApplicationCache_Gateway.Settings.Servers.In_Process_Submission_Location, User.ShibbID + "\\metadata_updates\\" + Item.BibID + "_" + Item.VID);

            if (User.ShibbID.Trim().Length == 0)
            {
                user_bib_vid_process_directory = Path.Combine(Engine_ApplicationCache_Gateway.Settings.Servers.In_Process_Submission_Location, User.UserName.Replace(".", "").Replace("@", "") + "\\metadata_updates\\" + Item.BibID + "_" + Item.VID);
            }

            // Ensure the folder exists and is empty to start with
            if (!Directory.Exists(user_bib_vid_process_directory))
            {
                Directory.CreateDirectory(user_bib_vid_process_directory);
            }
            else
            {
                // Anything older than a day should be deleted
                string[] files = Directory.GetFiles(user_bib_vid_process_directory);
                foreach (string thisFile in files)
                {
                    try
                    {
                        File.Delete(thisFile);
                    }
                    catch (Exception)
                    {
                        // Not much to do here
                    }
                }
            }

            // Update the METS file with METS note and name
            Item.METS_Header.Creator_Individual = User.UserName;
            Item.METS_Header.Modify_Date        = DateTime.Now;
            Item.METS_Header.RecordStatus_Enum  = METS_Record_Status.METADATA_UPDATE;

            // Create the options dictionary used when saving information to the database, or writing MarcXML
            Dictionary <string, object> options = new Dictionary <string, object>();

            if (Engine_ApplicationCache_Gateway.Settings.MarcGeneration != null)
            {
                options["MarcXML_File_ReaderWriter:MARC Cataloging Source Code"] = Engine_ApplicationCache_Gateway.Settings.MarcGeneration.Cataloging_Source_Code;
                options["MarcXML_File_ReaderWriter:MARC Location Code"]          = Engine_ApplicationCache_Gateway.Settings.MarcGeneration.Location_Code;
                options["MarcXML_File_ReaderWriter:MARC Reproduction Agency"]    = Engine_ApplicationCache_Gateway.Settings.MarcGeneration.Reproduction_Agency;
                options["MarcXML_File_ReaderWriter:MARC Reproduction Place"]     = Engine_ApplicationCache_Gateway.Settings.MarcGeneration.Reproduction_Place;
                options["MarcXML_File_ReaderWriter:MARC XSLT File"] = Engine_ApplicationCache_Gateway.Settings.MarcGeneration.XSLT_File;
            }
            options["MarcXML_File_ReaderWriter:System Name"]         = Engine_ApplicationCache_Gateway.Settings.System.System_Name;
            options["MarcXML_File_ReaderWriter:System Abbreviation"] = Engine_ApplicationCache_Gateway.Settings.System.System_Abbreviation;
            //  options["MarcXML_File_ReaderWriter:Additional_Tags"] = Item.MARC_Sobek_Standard_Tags(true, Engine_ApplicationCache_Gateway.Settings.System.System_Name, Engine_ApplicationCache_Gateway.Settings.System.System_Abbreviation);


            // Save the METS file and related Items
            bool db_successful_save = true;

            try
            {
                SobekCM_Item_Database.Save_Digital_Resource(Item, options, DateTime.Now, true);
            }
            catch
            {
                db_successful_save = false;
            }

            // Save the data to SOLR
            bool solr_successful_save = true;

            try
            {
                // Save this to the Solr/Lucene database
                if (!String.IsNullOrEmpty(Engine_ApplicationCache_Gateway.Settings.Servers.Document_Solr_Index_URL))
                {
                    Solr_Controller.Update_Index(Engine_ApplicationCache_Gateway.Settings.Servers.Document_Solr_Index_URL, Engine_ApplicationCache_Gateway.Settings.Servers.Page_Solr_Index_URL, Item, true);
                }
            }
            catch
            {
                solr_successful_save = false;
            }


            //// Create the static html pages
            //string base_url = RequestSpecificValues.Current_Mode.Base_URL;
            //try
            //{
            //    Static_Pages_Builder staticBuilder = new Static_Pages_Builder(Engine_AppliationCache_Gateway.Settings.Servers.System_Base_URL, Engine_AppliationCache_Gateway.Settings.Servers.Base_Data_Directory, RequestSpecificValues.HTML_Skin.Skin_Code);
            //    string filename = user_bib_vid_process_directory + "\\" + Item.BibID + "_" + Item.VID + ".html";
            //    staticBuilder.Create_Item_Citation_HTML(Item, filename, Engine_AppliationCache_Gateway.Settings.Servers.Image_Server_Network + Item.Web.AssocFilePath);

            //    // Copy the static HTML file to the web server
            //    try
            //    {
            //        if (!Directory.Exists(Engine_AppliationCache_Gateway.Settings.Servers.Static_Pages_Location + Item.BibID.Substring(0, 2) + "\\" + Item.BibID.Substring(2, 2) + "\\" + Item.BibID.Substring(4, 2) + "\\" + Item.BibID.Substring(6, 2) + "\\" + Item.BibID.Substring(8)))
            //            Directory.CreateDirectory(Engine_AppliationCache_Gateway.Settings.Servers.Static_Pages_Location + Item.BibID.Substring(0, 2) + "\\" + Item.BibID.Substring(2, 2) + "\\" + Item.BibID.Substring(4, 2) + "\\" + Item.BibID.Substring(6, 2) + "\\" + Item.BibID.Substring(8));
            //        if (File.Exists(user_bib_vid_process_directory + "\\" + Item.BibID + "_" + Item.VID + ".html"))
            //            File.Copy(user_bib_vid_process_directory + "\\" + Item.BibID + "_" + Item.VID + ".html", Engine_AppliationCache_Gateway.Settings.Servers.Static_Pages_Location + Item.BibID.Substring(0, 2) + "\\" + Item.BibID.Substring(2, 2) + "\\" + Item.BibID.Substring(4, 2) + "\\" + Item.BibID.Substring(6, 2) + "\\" + Item.BibID.Substring(8) + "\\" + Item.BibID + "_" + Item.VID + ".html", true);
            //    }
            //    catch
            //    {
            //        // This is not critical
            //    }
            //}
            //catch
            //{
            //    // Failing to make the static page is not the worst thing in the world...
            //}
            //RequestSpecificValues.Current_Mode.Base_URL = base_url;

            Item.Source_Directory = user_bib_vid_process_directory;
            Item.Save_SobekCM_METS();

            // If this was not able to be saved in the database, try it again
            if (!db_successful_save)
            {
                SobekCM_Item_Database.Save_Digital_Resource(Item, options, DateTime.Now, false);
            }

            // If this was not able to be saved to solr, try it again
            if (!solr_successful_save)
            {
                try
                {
                    // Save this to the Solr/Lucene database
                    if (!String.IsNullOrEmpty(Engine_ApplicationCache_Gateway.Settings.Servers.Document_Solr_Index_URL))
                    {
                        Solr_Controller.Update_Index(Engine_ApplicationCache_Gateway.Settings.Servers.Document_Solr_Index_URL, Engine_ApplicationCache_Gateway.Settings.Servers.Page_Solr_Index_URL, Item, true);
                    }
                }
                catch
                {
                    solr_successful_save = false;
                }
            }

            // Make sure the progress has been added to this Item's work log
            try
            {
                Engine_Database.Tracking_Online_Edit_Complete(Item.Web.ItemID, User.Full_Name, String.Empty);
            }
            catch (Exception)
            {
                // This is not critical
            }

            // Save the MARC file
            MarcXML_File_ReaderWriter marcWriter = new MarcXML_File_ReaderWriter();
            string errorMessage;

            marcWriter.Write_Metadata(Item.Source_Directory + "\\marc.xml", Item, options, out errorMessage);

            // Determine the server folder
            string serverNetworkFolder = Engine_ApplicationCache_Gateway.Settings.Servers.Image_Server_Network + Item.Web.AssocFilePath;

            // Create the folder
            if (!Directory.Exists(serverNetworkFolder))
            {
                Directory.CreateDirectory(serverNetworkFolder);
                if (!Directory.Exists(serverNetworkFolder + "\\" + Engine_ApplicationCache_Gateway.Settings.Resources.Backup_Files_Folder_Name))
                {
                    Directory.CreateDirectory(serverNetworkFolder + "\\" + Engine_ApplicationCache_Gateway.Settings.Resources.Backup_Files_Folder_Name);
                }
            }
            else
            {
                if (!Directory.Exists(serverNetworkFolder + "\\" + Engine_ApplicationCache_Gateway.Settings.Resources.Backup_Files_Folder_Name))
                {
                    Directory.CreateDirectory(serverNetworkFolder + "\\" + Engine_ApplicationCache_Gateway.Settings.Resources.Backup_Files_Folder_Name);
                }

                // Rename any existing standard mets to keep a backup
                if (File.Exists(serverNetworkFolder + "\\" + Item.BibID + "_" + Item.VID + ".mets.xml"))
                {
                    FileInfo currentMetsFileInfo = new FileInfo(serverNetworkFolder + "\\" + Item.BibID + "_" + Item.VID + ".mets.xml");
                    DateTime lastModDate         = currentMetsFileInfo.LastWriteTime;
                    File.Copy(serverNetworkFolder + "\\" + Item.BibID + "_" + Item.VID + ".mets.xml", serverNetworkFolder + "\\" + Engine_ApplicationCache_Gateway.Settings.Resources.Backup_Files_Folder_Name + "\\" + Item.BibID + "_" + Item.VID + "_" + lastModDate.Year + "_" + lastModDate.Month + "_" + lastModDate.Day + ".mets.bak", true);
                }
            }

            // Copy the static HTML page over first
            if (File.Exists(user_bib_vid_process_directory + "\\" + Item.BibID + "_" + Item.VID + ".html"))
            {
                File.Copy(user_bib_vid_process_directory + "\\" + Item.BibID + "_" + Item.VID + ".html", serverNetworkFolder + "\\" + Engine_ApplicationCache_Gateway.Settings.Resources.Backup_Files_Folder_Name + "\\" + Item.BibID + "_" + Item.VID + ".html", true);
                File.Delete(user_bib_vid_process_directory + "\\" + Item.BibID + "_" + Item.VID + ".html");
            }

            // Copy all the files
            string[] allFiles = Directory.GetFiles(user_bib_vid_process_directory);
            foreach (string thisFile in allFiles)
            {
                string destination_file = serverNetworkFolder + "\\" + (new FileInfo(thisFile)).Name;
                File.Copy(thisFile, destination_file, true);
            }

            // Now, delete all the files here
            string[] all_files = Directory.GetFiles(user_bib_vid_process_directory);
            foreach (string thisFile in all_files)
            {
                try
                {
                    File.Delete(thisFile);
                }
                catch
                {
                }
            }

            // Clear the User-specific and global cache of this Item
            CachedDataManager.Items.Remove_Digital_Resource_Object(User.UserID, Item.BibID, Item.VID, null);
            CachedDataManager.Items.Remove_Digital_Resource_Object(Item.BibID, Item.VID, null);
            CachedDataManager.Items.Remove_Items_In_Title(Item.BibID, null);

            // Also clear any searches or browses ( in the future could refine this to only remove those
            // that are impacted by this save... but this is good enough for now )
            CachedDataManager.Clear_Search_Results_Browses();

            return(true);
        }
Example #4
0
        /// <summary> Constructor for a new instance of the Edit_Item_Permissions_MySobekViewer class  </summary>
        /// <param name="RequestSpecificValues"> All the necessary, non-global data specific to the current request </param>
        public Edit_Item_Permissions_MySobekViewer(RequestCache RequestSpecificValues) : base(RequestSpecificValues)
        {
            // If no user then that is an error
            if ((RequestSpecificValues.Current_User == null) || (!RequestSpecificValues.Current_User.LoggedOn))
            {
                RequestSpecificValues.Current_Mode.Mode        = Display_Mode_Enum.Aggregation;
                RequestSpecificValues.Current_Mode.Aggregation = String.Empty;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                return;
            }

            // Ensure BibID and VID provided
            RequestSpecificValues.Tracer.Add_Trace("File_Management_MySobekViewer.Constructor", "Validate provided bibid / vid");
            if ((String.IsNullOrEmpty(RequestSpecificValues.Current_Mode.BibID)) || (String.IsNullOrEmpty(RequestSpecificValues.Current_Mode.VID)))
            {
                RequestSpecificValues.Tracer.Add_Trace("File_Management_MySobekViewer.Constructor", "BibID or VID was not provided!");
                RequestSpecificValues.Current_Mode.Mode          = Display_Mode_Enum.Error;
                RequestSpecificValues.Current_Mode.Error_Message = "Invalid Request : BibID/VID missing in item file upload request";
                return;
            }

            RequestSpecificValues.Tracer.Add_Trace("File_Management_MySobekViewer.Constructor", "Try to pull this sobek complete item");
            currentItem = SobekEngineClient.Items.Get_Sobek_Item(RequestSpecificValues.Current_Mode.BibID, RequestSpecificValues.Current_Mode.VID, RequestSpecificValues.Current_User.UserID, RequestSpecificValues.Tracer);
            if (currentItem == null)
            {
                RequestSpecificValues.Tracer.Add_Trace("File_Management_MySobekViewer.Constructor", "Unable to build complete item");
                RequestSpecificValues.Current_Mode.Mode          = Display_Mode_Enum.Error;
                RequestSpecificValues.Current_Mode.Error_Message = "Invalid Request : Unable to build complete item";
                return;
            }

            bool userCanEditItem = RequestSpecificValues.Current_User.Can_Edit_This_Item(currentItem.BibID, currentItem.Bib_Info.SobekCM_Type_String, currentItem.Bib_Info.Source.Code, currentItem.Bib_Info.HoldingCode, currentItem.Behaviors.Aggregation_Code_List);

            if (!userCanEditItem)
            {
                RequestSpecificValues.Current_Mode.Mode = Display_Mode_Enum.Item_Display;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
            }

            // Start by setting the values by the item (good the first time user comes here)
            ipRestrictionMask  = currentItem.Behaviors.IP_Restriction_Membership;
            isDark             = currentItem.Behaviors.Dark_Flag;
            restrictedSelected = (ipRestrictionMask > 0);


            // Is there already a RightsMD module in the item?
            // Ensure this metadata module extension exists
            RightsMD_Info rightsInfo = currentItem.Get_Metadata_Module(GlobalVar.PALMM_RIGHTSMD_METADATA_MODULE_KEY) as RightsMD_Info;

            if ((rightsInfo != null) && (rightsInfo.Has_Embargo_End))
            {
                embargoDate = rightsInfo.Embargo_End;
            }


            // Is this a postback?
            if (RequestSpecificValues.Current_Mode.isPostBack)
            {
                // Get the restriction mask and isDark flag
                if (HttpContext.Current.Request.Form["restrictionMask"] != null)
                {
                    ipRestrictionMask = short.Parse(HttpContext.Current.Request.Form["restrictionMask"]);
                    isDark            = bool.Parse(HttpContext.Current.Request.Form["isDark"]);
                }

                // Look for embargo date
                if (HttpContext.Current.Request.Form["embargoDateBox"] != null)
                {
                    string   embargoText = HttpContext.Current.Request.Form["embargoDateBox"];
                    DateTime embargoDateNew;
                    if (DateTime.TryParse(embargoText, out embargoDateNew))
                    {
                        embargoDate = embargoDateNew;
                    }
                }

                // If this was restrcted, there will be some checkboxes to determine ip restriction mask
                short checked_mask = 0;

                // Determine the IP restriction mask
                foreach (IP_Restriction_Range thisRange in UI_ApplicationCache_Gateway.IP_Restrictions.IpRanges)
                {
                    // Is this check box checked?
                    if (HttpContext.Current.Request.Form["range" + thisRange.RangeID] != null)
                    {
                        checked_mask += ((short)Math.Pow(2, (thisRange.RangeID - 1)));
                    }
                }


                // Handle any request from the internal header for the item
                if (HttpContext.Current.Request.Form["permissions_action"] != null)
                {
                    // Pull the action value
                    string action = HttpContext.Current.Request.Form["permissions_action"].Trim();

                    // Is this to change accessibility?
                    if ((action == "public") || (action == "private") || (action == "restricted") || (action == "dark"))
                    {
                        switch (action)
                        {
                        case "public":
                            ipRestrictionMask  = 0;
                            isDark             = false;
                            restrictedSelected = false;
                            break;

                        case "private":
                            ipRestrictionMask  = -1;
                            isDark             = false;
                            restrictedSelected = false;
                            break;

                        case "restricted":
                            ipRestrictionMask  = short.Parse(HttpContext.Current.Request.Form["selectRestrictionMask"]);
                            restrictedSelected = true;
                            isDark             = false;
                            break;

                        case "dark":
                            isDark             = true;
                            restrictedSelected = false;
                            break;
                        }
                    }
                }

                // Was the SAVE button pushed?
                if (HttpContext.Current.Request.Form["behaviors_request"] != null)
                {
                    string behaviorRequest = HttpContext.Current.Request.Form["behaviors_request"];
                    if (behaviorRequest == "save")
                    {
                        currentItem.Behaviors.IP_Restriction_Membership = ipRestrictionMask;
                        currentItem.Behaviors.Dark_Flag = isDark;

                        if (checked_mask > 0)
                        {
                            ipRestrictionMask = checked_mask;
                        }

                        // Save this to the database
                        if (SobekCM_Item_Database.Set_Item_Visibility(currentItem.Web.ItemID, ipRestrictionMask, isDark, embargoDate, RequestSpecificValues.Current_User.UserName))
                        {
                            // Update the web.config
                            Resource_Web_Config_Writer.Update_Web_Config(currentItem.Source_Directory, currentItem.Behaviors.Dark_Flag, ipRestrictionMask, currentItem.Behaviors.Main_Thumbnail);

                            // Remove the cached item
                            CachedDataManager.Items.Remove_Digital_Resource_Object(currentItem.BibID, currentItem.VID, RequestSpecificValues.Tracer);

                            // Also clear the engine
                            SobekEngineClient.Items.Clear_Item_Cache(currentItem.BibID, currentItem.VID, RequestSpecificValues.Tracer);

                            // Also clear any searches or browses ( in the future could refine this to only remove those
                            // that are impacted by this save... but this is good enough for now )
                            CachedDataManager.Clear_Search_Results_Browses();
                        }
                        RequestSpecificValues.Current_Mode.Mode = Display_Mode_Enum.Item_Display;
                        UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                    }
                }
            }
        }