Example #1
0
        /// <summary> Saves this item to the SobekCM database </summary>
        /// <param name="Item_List"> Item list datatable for pulling out the original creation date for this resource </param>
        /// <param name="New_Item"> Flag indicates this is an entirely new item </param>
        /// <returns> TRUE if successful, otherwise FALSE </returns>
        public bool Save_to_Database(DataTable Item_List, bool New_Item)
        {
            if (bibPackage == null)
            {
                return(false);
            }

            try
            {
                // save the bib package to the SobekCM database
                bool      existed    = false;
                DateTime  createTime = packageTime;
                DataRow[] check      = Item_List.Select("BibID='" + bibid + "' and VID='" + vid + "'");
                if (check.Length > 0)
                {
                    existed = true;
                    if (Item_List.Columns.Contains("CreateDate"))
                    {
                        createTime = Convert.ToDateTime(check[0]["CreateDate"]);
                    }
                }

                // Set the file root again
                bibPackage.Web.File_Root = fileRoot;
                SobekCM_Database.Save_Digital_Resource(bibPackage, createTime, existed);

                // Save the behaviors if this is a new item
                if (!existed)
                {
                    // Some work here just in case the METS is missing stuff, or has old data

                    // Make sure not set to UFDC as only web skin by default (used to list UFDC on all METS files )
                    if ((bibPackage.Behaviors.Web_Skin_Count == 1) && (bibPackage.Behaviors.Web_Skins[0].ToUpper().Trim() == "UFDC"))
                    {
                        bibPackage.Behaviors.Clear_Web_Skins();
                    }

                    // Now, save the behaviors for this item
                    SobekCM_Database.Save_Behaviors(bibPackage, false, false);
                }

                //// Set the suppress endeca flag
                //if ((New_Item) && (!bibPackage.Behaviors.Suppress_Endeca))
                //{
                //    SobekCM.Library.Database.SobekCM_Database.Set_Endeca_Flag(bibPackage.BibID, bibPackage.Behaviors.Suppress_Endeca);
                //}
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #2
0
        /// <summary> Constructor for a new instance of the Edit_Item_Behaviors_MySobekViewer class </summary>
        /// <param name="User"> Authenticated user information </param>
        /// <param name="Current_Mode"> Mode / navigation information for the current request</param>
        /// <param name="Current_Item"> Individual digital resource to be edited by the user </param>
        /// <param name="Code_Manager"> Code manager contains the list of all valid aggregation codes </param>
        /// <param name="Tracer">Trace object keeps a list of each method executed and important milestones in rendering</param>
        public Edit_Item_Behaviors_MySobekViewer(User_Object User, SobekCM_Navigation_Object Current_Mode, SobekCM_Item Current_Item, Aggregation_Code_Manager Code_Manager, Custom_Tracer Tracer) : base(User)
        {
            Tracer.Add_Trace("Edit_Item_Behaviors_MySobekViewer.Constructor", String.Empty);

            currentMode = Current_Mode;
            item        = Current_Item;

            // If the user cannot edit this item, go back
            if (!user.Can_Edit_This_Item(item))
            {
                currentMode.My_Sobek_Type = My_Sobek_Type_Enum.Home;
                HttpContext.Current.Response.Redirect(currentMode.Redirect_URL());
            }

            const string templateCode = "itembehaviors";

            template = Cached_Data_Manager.Retrieve_Template(templateCode, Tracer);
            if (template != null)
            {
                Tracer.Add_Trace("Edit_Item_Behaviors_MySobekViewer.Constructor", "Found template in cache");
            }
            else
            {
                Tracer.Add_Trace("Edit_Item_Behaviors_MySobekViewer.Constructor", "Reading template file");

                // Read this template
                Template_XML_Reader reader = new Template_XML_Reader();
                template = new Template();
                reader.Read_XML(SobekCM_Library_Settings.Base_MySobek_Directory + "templates\\defaults\\" + templateCode + ".xml", template, true);

                // Add the current codes to this template
                template.Add_Codes(Code_Manager);

                // Save this into the cache
                Cached_Data_Manager.Store_Template(templateCode, template, 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")
            {
                currentMode.Mode = Display_Mode_Enum.Item_Display;
                HttpContext.Current.Response.Redirect(currentMode.Redirect_URL());
            }
            else if (hidden_request == "save")
            {
                // Changes to the tracking box require the metadata search citation be rebuilt for this item
                // so save the old tracking box information first
                string oldTrackingBox = item.Tracking.Tracking_Box;

                // Save these changes to bib
                template.Save_To_Bib(item, user, 1);

                // Save the behaviors
                SobekCM_Database.Save_Behaviors(item, item.Behaviors.Text_Searchable, false);

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

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

                // Remoe from the caches (to replace the other)
                Cached_Data_Manager.Remove_Digital_Resource_Object(item.BibID, item.VID, Tracer);

                // Also remove the list of volumes, since this may have changed
                Cached_Data_Manager.Remove_Items_In_Title(item.BibID, Tracer);

                // Forward
                currentMode.Mode = Display_Mode_Enum.Item_Display;
                HttpContext.Current.Response.Redirect(currentMode.Redirect_URL());
            }
        }
        private bool complete_item_submission(SobekCM_Item Item_To_Complete, Custom_Tracer Tracer)
        {
            // Set an initial flag
            criticalErrorEncountered = false;

            string[] all_files = Directory.GetFiles(digitalResourceDirectory);
            SortedList <string, List <string> > image_files    = new SortedList <string, List <string> >();
            SortedList <string, List <string> > download_files = new SortedList <string, List <string> >();

            foreach (string thisFile in all_files)
            {
                FileInfo thisFileInfo = new FileInfo(thisFile);

                if ((thisFileInfo.Name.IndexOf("agreement.txt") != 0) && (thisFileInfo.Name.IndexOf("TEMP000001_00001.mets") != 0) && (thisFileInfo.Name.IndexOf("doc.xml") != 0) && (thisFileInfo.Name.IndexOf("ufdc_mets.xml") != 0) && (thisFileInfo.Name.IndexOf("marc.xml") != 0))
                {
                    // Get information about this files name and extension
                    string extension_upper         = thisFileInfo.Extension.ToUpper();
                    string filename_sans_extension = thisFileInfo.Name.Replace(thisFileInfo.Extension, "");
                    string name_upper = thisFileInfo.Name.ToUpper();

                    // Is this a page image?
                    if ((extension_upper == ".JPG") || (extension_upper == ".TIF") || (extension_upper == ".JP2") || (extension_upper == ".JPX"))
                    {
                        // Exclude .QC.jpg files
                        if (name_upper.IndexOf(".QC.JPG") < 0)
                        {
                            // If this is a thumbnail, trim off the THM part on the file name
                            if (name_upper.IndexOf("THM.JPG") > 0)
                            {
                                filename_sans_extension = filename_sans_extension.Substring(0, filename_sans_extension.Length - 3);
                            }

                            // Is this the first image file with this name?
                            if (image_files.ContainsKey(filename_sans_extension.ToLower()))
                            {
                                image_files[filename_sans_extension.ToLower()].Add(thisFileInfo.Name);
                            }
                            else
                            {
                                List <string> newImageGrouping = new List <string> {
                                    thisFileInfo.Name
                                };
                                image_files[filename_sans_extension.ToLower()] = newImageGrouping;
                            }
                        }
                    }
                    else
                    {
                        // If this does not match the exclusion regular expression, than add this
                        if ((!Regex.Match(thisFileInfo.Name, SobekCM_Library_Settings.Files_To_Exclude_From_Downloads, RegexOptions.IgnoreCase).Success) && (String.Compare(thisFileInfo.Name, Item_To_Complete.BibID + "_" + Item_To_Complete.VID + ".html", true) != 0))
                        {
                            // Is this the first image file with this name?
                            if (download_files.ContainsKey(filename_sans_extension.ToLower()))
                            {
                                download_files[filename_sans_extension.ToLower()].Add(thisFileInfo.Name);
                            }
                            else
                            {
                                List <string> newDownloadGrouping = new List <string> {
                                    thisFileInfo.Name
                                };
                                download_files[filename_sans_extension.ToLower()] = newDownloadGrouping;
                            }
                        }
                    }
                }
            }

            // This package is good to go, so build it, save, etc...
            try
            {
                // Save the METS file to the database and back to the directory
                Item_To_Complete.Source_Directory = digitalResourceDirectory;

                // Step through and add each file
                Item_To_Complete.Divisions.Download_Tree.Clear();

                // Step through each file
                bool error_reading_file_occurred = false;

                // Add the image files first
                bool jpeg_added = false;
                bool jp2_added  = false;
                foreach (string thisFileKey in image_files.Keys)
                {
                    // Get the list of files
                    List <string> theseFiles = image_files[thisFileKey];

                    // Add each file
                    foreach (string thisFile in theseFiles)
                    {
                        // Create the new file object and compute a label
                        System.IO.FileInfo fileInfo = new System.IO.FileInfo(thisFile);
                        SobekCM.Resource_Object.Divisions.SobekCM_File_Info newFile = new SobekCM.Resource_Object.Divisions.SobekCM_File_Info(fileInfo.Name);
                        string label = fileInfo.Name.Replace(fileInfo.Extension, "");
                        if (System.Web.HttpContext.Current.Session["file_" + item.Web.ItemID + "_" + thisFileKey] != null)
                        {
                            string possible_label = System.Web.HttpContext.Current.Session["file_" + item.Web.ItemID + "_" + thisFileKey].ToString();
                            if (possible_label.Length > 0)
                            {
                                label = possible_label;
                            }
                        }

                        // Add this file
                        item.Divisions.Physical_Tree.Add_File(newFile, label);

                        // Seperate code for JP2 and JPEG type files
                        string extension = fileInfo.Extension.ToUpper();
                        if (extension.IndexOf("JP2") >= 0)
                        {
                            if (!error_reading_file_occurred)
                            {
                                if (!newFile.Compute_Jpeg2000_Attributes(item.Source_Directory))
                                {
                                    error_reading_file_occurred = true;
                                }
                            }
                            jp2_added = true;
                        }
                        else
                        {
                            if (!error_reading_file_occurred)
                            {
                                if (!newFile.Compute_Jpeg_Attributes(item.Source_Directory))
                                {
                                    error_reading_file_occurred = true;
                                }
                            }
                            jpeg_added = true;
                        }
                    }
                }

                // Add the download files next
                foreach (string thisFileKey in download_files.Keys)
                {
                    // Get the list of files
                    List <string> theseFiles = download_files[thisFileKey];

                    // Add each file
                    foreach (string thisFile in theseFiles)
                    {
                        // Create the new file object and compute a label
                        FileInfo          fileInfo = new FileInfo(thisFile);
                        SobekCM_File_Info newFile  = new SobekCM_File_Info(fileInfo.Name);
                        string            label    = fileInfo.Name.Replace(fileInfo.Extension, "");
                        if (HttpContext.Current.Session["file_" + item.Web.ItemID + "_" + thisFileKey] != null)
                        {
                            string possible_label = HttpContext.Current.Session["file_" + item.Web.ItemID + "_" + thisFileKey].ToString();
                            if (possible_label.Length > 0)
                            {
                                label = possible_label;
                            }
                        }

                        // Add this file
                        Item_To_Complete.Divisions.Download_Tree.Add_File(newFile, label);
                    }
                }

                // Add the JPEG2000 and JPEG-specific viewers
                item.Behaviors.Clear_Views();
                if (jpeg_added)
                {
                    item.Behaviors.Add_View(SobekCM.Resource_Object.Behaviors.View_Enum.JPEG);
                }
                if (jp2_added)
                {
                    item.Behaviors.Add_View(SobekCM.Resource_Object.Behaviors.View_Enum.JPEG2000);
                }


                // Determine the total size of the package before saving
                string[] all_files_final = Directory.GetFiles(digitalResourceDirectory);
                double   size            = all_files_final.Aggregate <string, double>(0, (current, thisFile) => current + (((new FileInfo(thisFile)).Length) / 1024));
                Item_To_Complete.DiskSize_MB = size;

                // Save to the database
                try
                {
                    SobekCM_Database.Save_Digital_Resource(Item_To_Complete);
                    SobekCM_Database.Save_Behaviors(Item_To_Complete, Item_To_Complete.Behaviors.Text_Searchable, false);
                }
                catch (Exception ee)
                {
                    StreamWriter writer = new StreamWriter(digitalResourceDirectory + "\\exception.txt", false);
                    writer.WriteLine("ERROR CAUGHT WHILE SAVING DIGITAL RESOURCE");
                    writer.WriteLine(DateTime.Now.ToString());
                    writer.WriteLine();
                    writer.WriteLine(ee.Message);
                    writer.WriteLine(ee.StackTrace);
                    writer.Flush();
                    writer.Close();
                    throw;
                }


                // Assign the file root and assoc file path
                Item_To_Complete.Web.File_Root     = Item_To_Complete.BibID.Substring(0, 2) + "\\" + Item_To_Complete.BibID.Substring(2, 2) + "\\" + Item_To_Complete.BibID.Substring(4, 2) + "\\" + Item_To_Complete.BibID.Substring(6, 2) + "\\" + Item_To_Complete.BibID.Substring(8, 2);
                Item_To_Complete.Web.AssocFilePath = Item_To_Complete.Web.File_Root + "\\" + Item_To_Complete.VID + "\\";

                // Create the static html pages
                string base_url = currentMode.Base_URL;
                try
                {
                    Static_Pages_Builder staticBuilder = new Static_Pages_Builder(SobekCM_Library_Settings.System_Base_URL, SobekCM_Library_Settings.Base_Data_Directory, Translator, codeManager, itemList, iconList, webSkin);
                    string filename = digitalResourceDirectory + "\\" + Item_To_Complete.BibID + "_" + Item_To_Complete.VID + ".html";
                    staticBuilder.Create_Item_Citation_HTML(Item_To_Complete, filename, String.Empty);
                }
                catch (Exception ee)
                {
                    string error = ee.Message;
                }

                currentMode.Base_URL = base_url;

                // Save the rest of the metadata
                Item_To_Complete.Save_SobekCM_METS();

                // Finally, set the item for more processing if there were any files
                if (((image_files.Count > 0) || (download_files.Count > 0)) && (Item_To_Complete.Web.ItemID > 0))
                {
                    Database.SobekCM_Database.Update_Additional_Work_Needed_Flag(Item_To_Complete.Web.ItemID, true, Tracer);
                }
            }
            catch (Exception ee)
            {
                validationErrors.Add("Error encountered during item save!");
                validationErrors.Add(ee.ToString().Replace("\r", "<br />"));

                // Set an initial flag
                criticalErrorEncountered = true;

                string error_body    = "<strong>ERROR ENCOUNTERED DURING ONLINE FILE MANAGEMENT</strong><br /><br /><blockquote>Title: " + Item_To_Complete.Bib_Info.Main_Title.Title + "<br />Permanent Link: <a href=\"" + base.currentMode.Base_URL + "/" + Item_To_Complete.BibID + "/" + Item_To_Complete.VID + "\">" + base.currentMode.Base_URL + "/" + Item_To_Complete.BibID + "/" + Item_To_Complete.VID + "</a><br />User: "******"<br /><br /></blockquote>" + ee.ToString().Replace("\n", "<br />");
                string error_subject = "Error during file management for '" + Item_To_Complete.Bib_Info.Main_Title.Title + "'";
                string email_to      = SobekCM_Library_Settings.System_Error_Email;
                if (email_to.Length == 0)
                {
                    email_to = SobekCM_Library_Settings.System_Email;
                }
                Database.SobekCM_Database.Send_Database_Email(email_to, error_subject, error_body, true, false, -1);
            }


            return(criticalErrorEncountered);
        }
Example #4
0
        /// <summary> Constructor for a new instance of the Mass_Update_Items_MySobekViewer class </summary>
        /// <param name="User"> Authenticated user information </param>
        /// <param name="Current_Mode"> Mode / navigation information for the current request</param>
        /// <param name="Current_Item"> Individual digital resource to be edited by the user </param>
        /// <param name="Code_Manager"> Code manager contains the list of all valid aggregation codes </param>
        /// <param name="Tracer">Trace object keeps a list of each method executed and important milestones in rendering</param>
        public Mass_Update_Items_MySobekViewer(User_Object User, SobekCM_Navigation_Object Current_Mode, SobekCM_Item Current_Item, Aggregation_Code_Manager Code_Manager, Custom_Tracer Tracer) : base(User)
        {
            Tracer.Add_Trace("Mass_Update_Items_MySobekViewer.Constructor", String.Empty);
            currentMode = Current_Mode;

            // Since this is a mass update, just create a new empty item with the GroupID included
            // from the provided item
            SobekCM_Item emptyItem = new SobekCM_Item {
                BibID = Current_Item.BibID
            };

            emptyItem.Web.GroupID          = Current_Item.Web.GroupID;
            emptyItem.Bib_Info.Source.Code = String.Empty;
            emptyItem.Behaviors.CheckOut_Required_Is_Null         = true;
            emptyItem.Behaviors.IP_Restriction_Membership_Is_Null = true;
            emptyItem.Behaviors.Dark_Flag_Is_Null = true;
            item = emptyItem;

            // If the user cannot edit this item, go back
            if (!user.Can_Edit_This_Item(Current_Item))
            {
                currentMode.My_Sobek_Type = My_Sobek_Type_Enum.Home;
                currentMode.Redirect();
                return;
            }

            const string TEMPLATE_CODE = "massupdate";

            template = Cached_Data_Manager.Retrieve_Template(TEMPLATE_CODE, Tracer);
            if (template != null)
            {
                Tracer.Add_Trace("Mass_Update_Items_MySobekViewer.Constructor", "Found template in cache");
            }
            else
            {
                Tracer.Add_Trace("Mass_Update_Items_MySobekViewer.Constructor", "Reading template file");

                // Read this template
                Template_XML_Reader reader = new Template_XML_Reader();
                template = new Template();
                reader.Read_XML(SobekCM_Library_Settings.Base_MySobek_Directory + "templates\\defaults\\" + TEMPLATE_CODE + ".xml", template, true);

                // Add the current codes to this template
                template.Add_Codes(Code_Manager);

                // Save this into the cache
                Cached_Data_Manager.Store_Template(TEMPLATE_CODE, template, 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")
            {
                currentMode.Mode = Display_Mode_Enum.Item_Display;
                currentMode.Redirect();
            }
            else if (hidden_request == "save")
            {
                // Save these changes to bib
                template.Save_To_Bib(item, user, 1);

                // Save the behaviors
                SobekCM_Database.Save_Behaviors(item, false, true);

                // Store on the caches (to replace the other)
                Cached_Data_Manager.Remove_Digital_Resource_Objects(item.BibID, Tracer);

                // Forward
                currentMode.Mode = Display_Mode_Enum.Item_Display;
                currentMode.Redirect();
            }
        }