/// <summary> Update the flag which indicates the builder should relook /// at the item and reuild it. </summary> /// <param name="Item"> Item to update the flag for </param> /// <param name="NewFlag"> New flag for the additional work flag </param> /// <returns> TRUE if successful, otherwise FALSE </returns> public static bool Set_Item_Rebuild_Flag(SobekCM_Item Item, bool NewFlag) { try { SobekCM_Item_Database.Update_Additional_Work_Needed_Flag(Item.Web.ItemID, NewFlag); return(true); } catch { return(false); } }
private void Complete_Any_Recent_Loads_Requiring_Additional_Work() { // Get the list of recent loads requiring additional work DataTable additionalWorkRequired = Engine_Database.Items_Needing_Aditional_Work; if ((additionalWorkRequired != null) && (additionalWorkRequired.Rows.Count > 0)) { Add_NonError_To_Log("Processing recently loaded items needing additional work", "Standard", String.Empty, String.Empty, -1); // Create the incoming digital folder object which will be used for all these Actionable_Builder_Source_Folder sourceFolder = new Actionable_Builder_Source_Folder(); // Step through each one foreach (DataRow thisRow in additionalWorkRequired.Rows) { // Get the information about this item string bibID = thisRow["BibID"].ToString(); string vid = thisRow["VID"].ToString(); // Determine the file root for this string file_root = bibID.Substring(0, 2) + "\\" + bibID.Substring(2, 2) + "\\" + bibID.Substring(4, 2) + "\\" + bibID.Substring(6, 2) + "\\" + bibID.Substring(8, 2); // Determine the source folder for this resource string resource_folder = settings.Servers.Image_Server_Network + file_root + "\\" + vid; // Determine the METS file name string mets_file = resource_folder + "\\" + bibID + "_" + vid + ".mets.xml"; // Ensure these both exist if ((Directory.Exists(resource_folder)) && (File.Exists(mets_file))) { // Create the incoming digital resource object Incoming_Digital_Resource additionalWorkResource = new Incoming_Digital_Resource(resource_folder, sourceFolder) { BibID = bibID, VID = vid, File_Root = bibID.Substring(0, 2) + "\\" + bibID.Substring(2, 2) + "\\" + bibID.Substring(4, 2) + "\\" + bibID.Substring(6, 2) + "\\" + bibID.Substring(8, 2) }; Complete_Single_Recent_Load_Requiring_Additional_Work(additionalWorkResource); } else { Add_Error_To_Log("Unable to find valid resource files for reprocessing " + bibID + ":" + vid, bibID + ":" + vid, "Reprocess", -1); int itemID = Engine_Database.Get_ItemID_From_Bib_VID(bibID, vid); SobekCM_Item_Database.Update_Additional_Work_Needed_Flag(itemID, false); } } } }
/// <summary> Ensures a main thumbnail has been selected for this digital resource </summary> /// <param name="Resource"> Incoming digital resource object </param> /// <returns> TRUE if processing can continue, FALSE if a critical error occurred which should stop all processing </returns> public override bool DoWork(Incoming_Digital_Resource Resource) { // Ensure a thumbnail is attached if ((Resource.Metadata.Behaviors.Main_Thumbnail.Length == 0) || ((Resource.Metadata.Behaviors.Main_Thumbnail.IndexOf("http:") < 0) && (!File.Exists(Path.Combine(Resource.Resource_Folder, Resource.Metadata.Behaviors.Main_Thumbnail))))) { // Look for a valid thumbnail if (File.Exists(Path.Combine(Resource.Resource_Folder, "mainthm.jpg"))) { Resource.Metadata.Behaviors.Main_Thumbnail = "mainthm.jpg"; } else { string[] jpeg_files = Directory.GetFiles(Resource.Resource_Folder, "*thm.jpg"); if (jpeg_files.Length > 0) { Resource.Metadata.Behaviors.Main_Thumbnail = (new FileInfo(jpeg_files[0])).Name; } else { if (Resource.Metadata.Divisions.Page_Count == 0) { List <SobekCM_File_Info> downloads = Resource.Metadata.Divisions.Download_Other_Files; foreach (SobekCM_File_Info thisDownloadFile in downloads) { string mimetype = thisDownloadFile.MIME_Type(thisDownloadFile.File_Extension).ToUpper(); if ((mimetype.IndexOf("AUDIO") >= 0) || (mimetype.IndexOf("VIDEO") >= 0)) { if (File.Exists(Path.Combine(MultiInstance_Builder_Settings.Builder_Executable_Directory, "images\\multimedia.jpg"))) { File.Copy(Path.Combine(MultiInstance_Builder_Settings.Builder_Executable_Directory, "images\\multimedia.jpg"), Path.Combine(Resource.Resource_Folder, "multimediathm.jpg"), true); Resource.Metadata.Behaviors.Main_Thumbnail = "multimediathm.jpg"; } break; } } } } } // Should this be saved? if ((Resource.Metadata.Web.ItemID > 0) && (Resource.Metadata.Behaviors.Main_Thumbnail.Length > 0)) { SobekCM_Item_Database.Set_Item_Main_Thumbnail(Resource.BibID, Resource.VID, Resource.Metadata.Behaviors.Main_Thumbnail); } } return(true); }
/// <summary> Adds new tracking workflow and milestones for the incoming digital resource folder </summary> /// <param name="Resource"> Incoming digital resource object </param> /// <returns> TRUE if processing can continue, FALSE if a critical error occurred which should stop all processing </returns> public override bool DoWork(Incoming_Digital_Resource Resource) { // Clear the flag for additional work SobekCM_Item_Database.Update_Additional_Work_Needed_Flag(Resource.Metadata.Web.ItemID, false); // Mark a log in the database that this was handled as well SobekCM_Item_Database.Add_Workflow(Resource.Metadata.Web.ItemID, "Bulk Loaded", String.Empty, "SobekCM Bulk Loader", String.Empty); // If the item is born digital, has files, and is currently public, close out the digitization milestones completely if ((!Resource.Metadata.Tracking.Born_Digital_Is_Null) && (Resource.Metadata.Tracking.Born_Digital) && (Resource.Metadata.Behaviors.IP_Restriction_Membership >= 0) && (Resource.Metadata.Divisions.Download_Tree.Has_Files)) { SobekCM_Item_Database.Update_Digitization_Milestone(Resource.Metadata.Web.ItemID, 4, DateTime.Now); } return(true); }
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("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, UI_ApplicationCache_Gateway.Settings.Resources.Files_To_Exclude_From_Downloads, RegexOptions.IgnoreCase).Success) && (String.Compare(thisFileInfo.Name, Item_To_Complete.BibID + "_" + Item_To_Complete.VID + ".html", StringComparison.OrdinalIgnoreCase) != 0)) { // Also, exclude files that are .XML and marc.xml, or doc.xml, or have the bibid in the name if ((thisFileInfo.Name.IndexOf("marc.xml", StringComparison.OrdinalIgnoreCase) != 0) && (thisFileInfo.Name.IndexOf("marc.xml", StringComparison.OrdinalIgnoreCase) != 0) && (thisFileInfo.Name.IndexOf(".mets", StringComparison.OrdinalIgnoreCase) < 0) && (thisFileInfo.Name.IndexOf("citation_mets.xml", StringComparison.OrdinalIgnoreCase) < 0) && ((thisFileInfo.Name.IndexOf(".xml", StringComparison.OrdinalIgnoreCase) < 0) || (thisFileInfo.Name.IndexOf(Item_To_Complete.BibID, StringComparison.OrdinalIgnoreCase) < 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(); // 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_" + currentItem.Web.ItemID + "_" + thisFileKey] != null) { string possible_label = HttpContext.Current.Session["file_" + currentItem.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); } } // 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_KB = size; // Create the options dictionary used when saving information to the database, or writing MarcXML Dictionary <string, object> options = new Dictionary <string, object>(); if (UI_ApplicationCache_Gateway.Settings.MarcGeneration != null) { options["MarcXML_File_ReaderWriter:MARC Cataloging Source Code"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Cataloging_Source_Code; options["MarcXML_File_ReaderWriter:MARC Location Code"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Location_Code; options["MarcXML_File_ReaderWriter:MARC Reproduction Agency"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Reproduction_Agency; options["MarcXML_File_ReaderWriter:MARC Reproduction Place"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Reproduction_Place; options["MarcXML_File_ReaderWriter:MARC XSLT File"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.XSLT_File; } options["MarcXML_File_ReaderWriter:System Name"] = UI_ApplicationCache_Gateway.Settings.System.System_Name; options["MarcXML_File_ReaderWriter:System Abbreviation"] = UI_ApplicationCache_Gateway.Settings.System.System_Abbreviation; // Save to the database try { SobekCM_Item_Database.Save_Digital_Resource(Item_To_Complete, options); SobekCM_Item_Database.Save_Behaviors(Item_To_Complete, Item_To_Complete.Behaviors.Text_Searchable, false, 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 = RequestSpecificValues.Current_Mode.Base_URL; //try //{ // Static_Pages_Builder staticBuilder = new Static_Pages_Builder(UI_ApplicationCache_Gateway.Settings.Servers.System_Base_URL, UI_ApplicationCache_Gateway.Settings.Servers.Base_Data_Directory, RequestSpecificValues.HTML_Skin.Skin_Code); // if (!Directory.Exists(digitalResourceDirectory + "\\" + UI_ApplicationCache_Gateway.Settings.Resources.Backup_Files_Folder_Name)) // Directory.CreateDirectory(digitalResourceDirectory + "\\" + UI_ApplicationCache_Gateway.Settings.Resources.Backup_Files_Folder_Name); // string filename = digitalResourceDirectory + "\\" + UI_ApplicationCache_Gateway.Settings.Resources.Backup_Files_Folder_Name + "\\" + Item_To_Complete.BibID + "_" + Item_To_Complete.VID + ".html"; // staticBuilder.Create_Item_Citation_HTML(Item_To_Complete, filename, String.Empty); // // Copy the static HTML file to the web server // try // { // if (!Directory.Exists(UI_ApplicationCache_Gateway.Settings.Servers.Static_Pages_Location + currentItem.BibID.Substring(0, 2) + "\\" + currentItem.BibID.Substring(2, 2) + "\\" + currentItem.BibID.Substring(4, 2) + "\\" + currentItem.BibID.Substring(6, 2) + "\\" + currentItem.BibID.Substring(8))) // Directory.CreateDirectory(UI_ApplicationCache_Gateway.Settings.Servers.Static_Pages_Location + currentItem.BibID.Substring(0, 2) + "\\" + currentItem.BibID.Substring(2, 2) + "\\" + currentItem.BibID.Substring(4, 2) + "\\" + currentItem.BibID.Substring(6, 2) + "\\" + currentItem.BibID.Substring(8)); // if (File.Exists(filename)) // File.Copy(filename, UI_ApplicationCache_Gateway.Settings.Servers.Static_Pages_Location + currentItem.BibID.Substring(0, 2) + "\\" + currentItem.BibID.Substring(2, 2) + "\\" + currentItem.BibID.Substring(4, 2) + "\\" + currentItem.BibID.Substring(6, 2) + "\\" + currentItem.BibID.Substring(8) + "\\" + currentItem.BibID + "_" + currentItem.VID + ".html", true); // } // catch (Exception) // { // // This is not critical // } //} //catch (Exception) //{ //} //RequestSpecificValues.Current_Mode.Base_URL = base_url; // Save the rest of the metadata Item_To_Complete.Save_SobekCM_METS(); // Finally, set the currentItem for more processing if there were any files if (((image_files.Count > 0) || (download_files.Count > 0)) && (Item_To_Complete.Web.ItemID > 0)) { SobekCM_Item_Database.Update_Additional_Work_Needed_Flag(Item_To_Complete.Web.ItemID, true); } } catch (Exception ee) { // 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=\"" + RequestSpecificValues.Current_Mode.Base_URL + "/" + Item_To_Complete.BibID + "/" + Item_To_Complete.VID + "\">" + RequestSpecificValues.Current_Mode.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 = UI_ApplicationCache_Gateway.Settings.Email.System_Error_Email; if (email_to.Length == 0) { email_to = UI_ApplicationCache_Gateway.Settings.Email.System_Email; } Email_Helper.SendEmail(email_to, error_subject, error_body, true, String.Empty); } return(criticalErrorEncountered); }
/// <summary> Check for folders that are not named in BibID or BibiD/VID format and do not have metadata. For /// these items, creates a BibID/VID folder with minimal metadata from the folder name. </summary> /// <param name="BuilderFolder"> Builder folder upon which to perform all work </param> /// <param name="IncomingPackages"> List of valid incoming packages, which may be modified by this process </param> /// <param name="Deletes"> List of valid deletes, which may be modifyed by this process </param> public override void DoWork(Actionable_Builder_Source_Folder BuilderFolder, List <Incoming_Digital_Resource> IncomingPackages, List <Incoming_Digital_Resource> Deletes) { string[] subdirs = Directory.GetDirectories(BuilderFolder.Inbound_Folder); foreach (string thisSubDir in subdirs) { try { string thisSubDirName = (new DirectoryInfo(thisSubDir)).Name; // Must have some files to continue if (Directory.GetFiles(thisSubDir).Length == 0) { continue; } // Need to check if this MAY be a valid BibID. // Need to make this a bit more specific in the future, as it will skip ANY folders // that are ten digits long right now. if ((thisSubDir.Length == 10) || ((thisSubDir.Length == 16) && (thisSubDirName[0] == '_'))) { continue; } // Look for a METS file or any source of metadata in the folder if ((Directory.GetFiles(thisSubDir, "*.mets").Length > 0) || (Directory.GetFiles(thisSubDir, "*.xml").Length > 0)) { continue; } // Clean any additional periods in the filenames first string[] allFiles = Directory.GetFiles(thisSubDir); foreach (string thisFile in allFiles) { string fileName = Path.GetFileName(thisFile); if (Regex.Matches(fileName, "\\.").Count > 1) { string newFileName = fileName; while (Regex.Matches(newFileName, "\\.").Count > 1) { char[] charArr = newFileName.ToCharArray(); charArr[newFileName.IndexOf(".")] = '_'; // freely modify the array newFileName = new string(charArr); } File.Move(thisFile, Path.Combine(thisSubDir, newFileName)); } } // Create the new object SobekCM_Item newItem = new SobekCM_Item(); newItem.Bib_Info.SobekCM_Type = TypeOfResource_SobekCM_Enum.Archival; newItem.Bib_Info.Main_Title.Title = thisSubDirName; newItem.Bib_Info.Add_Identifier(thisSubDirName); newItem.Bib_Info.Source.Code = Arguments[1]; newItem.Bib_Info.Source.Statement = Arguments[2]; newItem.BibID = Arguments[0]; newItem.VID = "00001"; // Save this item, for the necessary bibid SobekCM_Item_Database.Save_New_Digital_Resource(newItem, false, false, "Builder", "Created BibID folder from '" + thisSubDirName + "'", -1); string newFolderName = newItem.BibID + "_" + newItem.VID; string newFolder = Path.Combine(BuilderFolder.Inbound_Folder, newFolderName); Directory.Move(thisSubDir, newFolder); newItem.Source_Directory = newFolder; newItem.Save_METS(); } catch (Exception ee) { Console.WriteLine("Error moving directory " + ee.Message); } } }
private void complete_item_submission(SobekCM_Item Item_To_Complete, Custom_Tracer Tracer) { // If this is a newspaper type, and the pubdate has a value, try to use that for the serial heirarchy if ((Item_To_Complete.Behaviors.Serial_Info.Count == 0) && (Item_To_Complete.Bib_Info.Origin_Info.Date_Issued.Length > 0) && (Item_To_Complete.Bib_Info.SobekCM_Type == TypeOfResource_SobekCM_Enum.Newspaper)) { DateTime asDateTime; if (DateTime.TryParse(Item_To_Complete.Bib_Info.Origin_Info.Date_Issued, out asDateTime)) { hierarchyCopiedFromDate = true; Item_To_Complete.Behaviors.Serial_Info.Add_Hierarchy(1, asDateTime.Year, asDateTime.Year.ToString()); switch (asDateTime.Month) { case 1: Item_To_Complete.Behaviors.Serial_Info.Add_Hierarchy(2, asDateTime.Month, "January"); break; case 2: Item_To_Complete.Behaviors.Serial_Info.Add_Hierarchy(2, asDateTime.Month, "February"); break; case 3: Item_To_Complete.Behaviors.Serial_Info.Add_Hierarchy(2, asDateTime.Month, "March"); break; case 4: Item_To_Complete.Behaviors.Serial_Info.Add_Hierarchy(2, asDateTime.Month, "April"); break; case 5: Item_To_Complete.Behaviors.Serial_Info.Add_Hierarchy(2, asDateTime.Month, "May"); break; case 6: Item_To_Complete.Behaviors.Serial_Info.Add_Hierarchy(2, asDateTime.Month, "June"); break; case 7: Item_To_Complete.Behaviors.Serial_Info.Add_Hierarchy(2, asDateTime.Month, "July"); break; case 8: Item_To_Complete.Behaviors.Serial_Info.Add_Hierarchy(2, asDateTime.Month, "August"); break; case 9: Item_To_Complete.Behaviors.Serial_Info.Add_Hierarchy(2, asDateTime.Month, "September"); break; case 10: Item_To_Complete.Behaviors.Serial_Info.Add_Hierarchy(2, asDateTime.Month, "October"); break; case 11: Item_To_Complete.Behaviors.Serial_Info.Add_Hierarchy(2, asDateTime.Month, "November"); break; case 12: Item_To_Complete.Behaviors.Serial_Info.Add_Hierarchy(2, asDateTime.Month, "December"); break; } Item_To_Complete.Behaviors.Serial_Info.Add_Hierarchy(3, asDateTime.Day, asDateTime.Day.ToString()); } } // Determine the in process directory for this string user_in_process_directory = UI_ApplicationCache_Gateway.Settings.Servers.In_Process_Submission_Location + "\\" + RequestSpecificValues.Current_User.UserName.Replace(".", "").Replace("@", "") + "\\newitem"; if (RequestSpecificValues.Current_User.ShibbID.Trim().Length > 0) { user_in_process_directory = UI_ApplicationCache_Gateway.Settings.Servers.In_Process_Submission_Location + "\\" + RequestSpecificValues.Current_User.ShibbID + "\\newitem"; } // Ensure this directory exists if (!Directory.Exists(user_in_process_directory)) { Directory.CreateDirectory(user_in_process_directory); } // Now, delete all the files in the processing directory string[] all_files = Directory.GetFiles(user_in_process_directory); foreach (string thisFile in all_files) { File.Delete(thisFile); } // Save to the database 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); SobekCM_Item_Database.Save_New_Digital_Resource(Item_To_Complete, false, false, RequestSpecificValues.Current_User.UserName, String.Empty, -1); // Assign the file root and assoc file path Item_To_Complete.Web.AssocFilePath = Item_To_Complete.Web.File_Root + "\\" + Item_To_Complete.VID + "\\"; // Create the static html pages string base_url = RequestSpecificValues.Current_Mode.Base_URL; // Save the rest of the metadata Item_To_Complete.Source_Directory = user_in_process_directory; Item_To_Complete.Save_SobekCM_METS(); Database.SobekCM_Database.Add_Item_To_User_Folder(RequestSpecificValues.Current_User.UserID, "Submitted Items", Item_To_Complete.BibID, Item_To_Complete.VID, 0, String.Empty, Tracer); // Save Bib_Level METS? //SobekCM.Resource_Object.Writers.OAI_Writer oaiWriter = new SobekCM.Resource_Object.Writers.OAI_Writer(); //oaiWriter.Save_OAI_File(bibPackage, resource_folder + "\\oai_dc.xml", bibPackage.Processing_Parameters.Collection_Primary.ToLower(), createDate); // If there was no match, try to save to the tracking database Engine_Database.Tracking_Online_Submit_Complete(Item_To_Complete.Web.ItemID, RequestSpecificValues.Current_User.Full_Name, String.Empty); // Create the options dictionary used when saving information to the database, or writing MarcXML Dictionary <string, object> options = new Dictionary <string, object>(); if (UI_ApplicationCache_Gateway.Settings.MarcGeneration != null) { options["MarcXML_File_ReaderWriter:MARC Cataloging Source Code"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Cataloging_Source_Code; options["MarcXML_File_ReaderWriter:MARC Location Code"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Location_Code; options["MarcXML_File_ReaderWriter:MARC Reproduction Agency"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Reproduction_Agency; options["MarcXML_File_ReaderWriter:MARC Reproduction Place"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Reproduction_Place; options["MarcXML_File_ReaderWriter:MARC XSLT File"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.XSLT_File; } options["MarcXML_File_ReaderWriter:System Name"] = UI_ApplicationCache_Gateway.Settings.System.System_Name; options["MarcXML_File_ReaderWriter:System Abbreviation"] = UI_ApplicationCache_Gateway.Settings.System.System_Abbreviation; // Save the MARC file MarcXML_File_ReaderWriter marcWriter = new MarcXML_File_ReaderWriter(); string errorMessage; marcWriter.Write_Metadata(Item_To_Complete.Source_Directory + "\\marc.xml", Item_To_Complete, options, out errorMessage); // Copy all the files over to the server string serverNetworkFolder = UI_ApplicationCache_Gateway.Settings.Servers.Image_Server_Network + Item_To_Complete.Web.AssocFilePath; // Create the folder if (!Directory.Exists(serverNetworkFolder)) { Directory.CreateDirectory(serverNetworkFolder); } if (!Directory.Exists(serverNetworkFolder + "\\" + UI_ApplicationCache_Gateway.Settings.Resources.Backup_Files_Folder_Name)) { Directory.CreateDirectory(serverNetworkFolder + "\\" + UI_ApplicationCache_Gateway.Settings.Resources.Backup_Files_Folder_Name); } // Copy the static HTML page over first if (File.Exists(user_in_process_directory + "\\" + currentItem.BibID + "_" + currentItem.VID + ".html")) { File.Copy(user_in_process_directory + "\\" + currentItem.BibID + "_" + currentItem.VID + ".html", serverNetworkFolder + "\\" + UI_ApplicationCache_Gateway.Settings.Resources.Backup_Files_Folder_Name + "\\" + currentItem.BibID + "_" + currentItem.VID + ".html", true); File.Delete(user_in_process_directory + "\\" + currentItem.BibID + "_" + currentItem.VID + ".html"); } // Copy all the files string[] allFiles = Directory.GetFiles(user_in_process_directory); foreach (string thisFile in allFiles) { string destination_file = serverNetworkFolder + "\\" + (new FileInfo(thisFile)).Name; File.Copy(thisFile, destination_file, true); } // Incrememnt the count of number of items submitted by this user RequestSpecificValues.Current_User.Items_Submitted_Count++; // Delete any remaining items all_files = Directory.GetFiles(user_in_process_directory); foreach (string thisFile in all_files) { File.Delete(thisFile); } }
/// <summary> Saves this item to the SobekCM database </summary> /// <param name="NewItem"> Flag indicates this is an entirely new item </param> /// <returns> TRUE if successful, otherwise FALSE </returns> public bool Save_to_Database(bool NewItem, InstanceWide_Settings Settings) { if (Metadata == null) { return(false); } try { // save the bib package to the SobekCM database bool existed = !NewItem; DateTime createTime = packageTime; // Create the options dictionary used when saving information to the database, or writing MarcXML Dictionary <string, object> options = new Dictionary <string, object>(); if (Settings.MarcGeneration != null) { options["MarcXML_File_ReaderWriter:MARC Cataloging Source Code"] = Settings.MarcGeneration.Cataloging_Source_Code; options["MarcXML_File_ReaderWriter:MARC Location Code"] = Settings.MarcGeneration.Location_Code; options["MarcXML_File_ReaderWriter:MARC Reproduction Agency"] = Settings.MarcGeneration.Reproduction_Agency; options["MarcXML_File_ReaderWriter:MARC Reproduction Place"] = Settings.MarcGeneration.Reproduction_Place; options["MarcXML_File_ReaderWriter:MARC XSLT File"] = Settings.MarcGeneration.XSLT_File; } options["MarcXML_File_ReaderWriter:System Name"] = Settings.System.System_Name; options["MarcXML_File_ReaderWriter:System Abbreviation"] = Settings.System.System_Abbreviation; // Set the file root again Metadata.Web.File_Root = fileRoot; SobekCM_Item_Database.Save_Digital_Resource(Metadata, options, 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 ((Metadata.Behaviors.Web_Skin_Count == 1) && (Metadata.Behaviors.Web_Skins[0].ToUpper().Trim() == "UFDC")) { Metadata.Behaviors.Clear_Web_Skins(); } // Now, save the behaviors for this item SobekCM_Item_Database.Save_Behaviors(Metadata, Metadata.Behaviors.Text_Searchable, false, false); } else { // Now, save the MINIMAL behaviors for this item SobekCM_Item_Database.Save_Behaviors(Metadata, Metadata.Behaviors.Text_Searchable, false, true); } //// 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 ee) { return(false); } }
/// <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); }
/// <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); } }
/// <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); } } } }
/// <summary> Constructor for a new instance of the Edit_Group_Behaviors_MySobekViewer class </summary> /// <param name="RequestSpecificValues"> All the necessary, non-global data specific to the current request </param> public Edit_Group_Behaviors_MySobekViewer(RequestCache RequestSpecificValues) : base(RequestSpecificValues) { RequestSpecificValues.Tracer.Add_Trace("Edit_Group_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 provided RequestSpecificValues.Tracer.Add_Trace("Edit_Group_Behaviors_MySobekViewer.Constructor", "Validate provided bibid"); if (String.IsNullOrEmpty(RequestSpecificValues.Current_Mode.BibID)) { RequestSpecificValues.Tracer.Add_Trace("Edit_Group_Behaviors_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("Edit_Group_Behaviors_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("Edit_Group_Behaviors_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; } // 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 = "groupbehaviors"; completeTemplate = Template_MemoryMgmt_Utility.Retrieve_Template(TEMPLATE_CODE, RequestSpecificValues.Tracer); if (completeTemplate != null) { RequestSpecificValues.Tracer.Add_Trace("Edit_Group_Behaviors_MySobekViewer.Constructor", "Found CompleteTemplate in cache"); } else { RequestSpecificValues.Tracer.Add_Trace("Edit_Group_Behaviors_MySobekViewer.Constructor", "Reading CompleteTemplate file"); // Read this CompleteTemplate Template_XML_Reader reader = new Template_XML_Reader(); completeTemplate = new CompleteTemplate(); if (File.Exists(UI_ApplicationCache_Gateway.Settings.Servers.Base_MySobek_Directory + "templates\\user\\standard\\" + TEMPLATE_CODE + ".xml")) { reader.Read_XML(UI_ApplicationCache_Gateway.Settings.Servers.Base_MySobek_Directory + "templates\\user\\standard\\" + TEMPLATE_CODE + ".xml", completeTemplate, true); } else { reader.Read_XML(UI_ApplicationCache_Gateway.Settings.Servers.Base_MySobek_Directory + "templates\\default\\standard\\" + TEMPLATE_CODE + ".xml", 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") { // Save these changes to bib completeTemplate.Save_To_Bib(currentItem, RequestSpecificValues.Current_User, 1); // Save the group title SobekCM_Item_Database.Update_Item_Group(currentItem.BibID, currentItem.Behaviors.GroupTitle, currentItem.Bib_Info.SortSafeTitle(currentItem.Behaviors.GroupTitle, true), String.Empty, currentItem.Behaviors.Primary_Identifier.Type, currentItem.Behaviors.Primary_Identifier.Identifier); // Save the interfaces to the group currentItem as well SobekCM_Item_Database.Save_Item_Group_Web_Skins(currentItem.Web.GroupID, currentItem); // Store on the caches (to replace the other) CachedDataManager.Items.Remove_Digital_Resource_Objects(currentItem.BibID, RequestSpecificValues.Tracer); // Also remove the list of volumes, since this may have changed CachedDataManager.Items.Remove_Items_In_Title(currentItem.BibID, RequestSpecificValues.Tracer); // Also clear the engine SobekEngineClient.Items.Clear_Item_Group_Cache(currentItem.BibID, RequestSpecificValues.Tracer); // Forward RequestSpecificValues.Current_Mode.Mode = Display_Mode_Enum.Item_Display; UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode); } }
/// <summary> Constructor for a new instance of the Mass_Update_Items_MySobekViewer class </summary> /// <param name="RequestSpecificValues"> All the necessary, non-global data specific to the current request </param> public Mass_Update_Items_MySobekViewer(RequestCache RequestSpecificValues) : base(RequestSpecificValues) { RequestSpecificValues.Tracer.Add_Trace("Mass_Update_Items_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"); SobekCM_Item 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; } // 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 = currentItem.BibID }; emptyItem.Web.GroupID = currentItem.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 (!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 = "massupdate"; completeTemplate = Template_MemoryMgmt_Utility.Retrieve_Template(TEMPLATE_CODE, RequestSpecificValues.Tracer); if (completeTemplate != null) { RequestSpecificValues.Tracer.Add_Trace("Mass_Update_Items_MySobekViewer.Constructor", "Found CompleteTemplate in cache"); } else { RequestSpecificValues.Tracer.Add_Trace("Mass_Update_Items_MySobekViewer.Constructor", "Reading CompleteTemplate file"); // Read this CompleteTemplate Template_XML_Reader reader = new Template_XML_Reader(); completeTemplate = new CompleteTemplate(); reader.Read_XML(UI_ApplicationCache_Gateway.Settings.Servers.Base_MySobek_Directory + "templates\\default\\standard\\" + TEMPLATE_CODE + ".xml", 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") { // Save these changes to bib completeTemplate.Save_To_Bib(item, RequestSpecificValues.Current_User, 1); // Save the behaviors SobekCM_Item_Database.Save_Behaviors(item, false, true, false); // Store on the caches (to replace the other) CachedDataManager.Items.Remove_Digital_Resource_Objects(item.BibID, RequestSpecificValues.Tracer); // Forward RequestSpecificValues.Current_Mode.Mode = Display_Mode_Enum.Item_Display; UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode); } }
private bool complete_item_submission(SobekCM_Item Item_To_Complete, Custom_Tracer Tracer) { // Set an initial flag criticalErrorEncountered = false; string final_destination = Item_To_Complete.Source_Directory; string[] image_files = Directory.GetFiles(digitalResourceDirectory); // This package is good to go, so build it, save, etc... try { // Step through each file bool error_reading_file_occurred = false; // Add the SourceImage files first bool jpeg_added = false; bool jp2_added = false; foreach (string thisFile in image_files) { // Create the new file object and compute a label FileInfo fileInfo = new FileInfo(thisFile); SobekCM_File_Info newFile = new SobekCM_File_Info(fileInfo.Name); // Copy this file File.Copy(thisFile, final_destination + "\\" + fileInfo.Name, true); currentItem.Divisions.Physical_Tree.Add_File(newFile, "New Page"); // 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(currentItem.Source_Directory)) { error_reading_file_occurred = true; } } jp2_added = true; } else if (extension.IndexOf("JPG") >= 0) { if (!error_reading_file_occurred) { if (!newFile.Compute_Jpeg_Attributes(currentItem.Source_Directory)) { error_reading_file_occurred = true; } } jpeg_added = true; } } // Add the JPEG2000 and JPEG-specific viewers //currentItem.Behaviors.Clear_Views(); if (jpeg_added) { // Is a JPEG view already existing? bool jpeg_viewer_already_exists = false; foreach (View_Object thisViewer in currentItem.Behaviors.Views) { if (thisViewer.View_Type == "JPEG") { jpeg_viewer_already_exists = true; break; } } // Add the JPEG view if it did not already exists if (!jpeg_viewer_already_exists) { currentItem.Behaviors.Add_View("JPEG"); } } // If a JPEG2000 file was just added, ensure it exists as a view for this currentItem if (jp2_added) { // Is a JPEG view already existing? bool jpg2000_viewer_already_exists = false; foreach (View_Object thisViewer in currentItem.Behaviors.Views) { if (thisViewer.View_Type == "JPEG2000") { jpg2000_viewer_already_exists = true; break; } } // Add the JPEG2000 view if it did not already exists if (!jpg2000_viewer_already_exists) { currentItem.Behaviors.Add_View("JPEG2000"); } } // Determine the total size of the package before saving string[] all_files_final = Directory.GetFiles(final_destination); double size = all_files_final.Aggregate <string, double>(0, (Current, ThisFile) => Current + (((new FileInfo(ThisFile)).Length) / 1024)); Item_To_Complete.DiskSize_KB = size; // Create the options dictionary used when saving information to the database, or writing MarcXML Dictionary <string, object> options = new Dictionary <string, object>(); if (UI_ApplicationCache_Gateway.Settings.MarcGeneration != null) { options["MarcXML_File_ReaderWriter:MARC Cataloging Source Code"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Cataloging_Source_Code; options["MarcXML_File_ReaderWriter:MARC Location Code"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Location_Code; options["MarcXML_File_ReaderWriter:MARC Reproduction Agency"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Reproduction_Agency; options["MarcXML_File_ReaderWriter:MARC Reproduction Place"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Reproduction_Place; options["MarcXML_File_ReaderWriter:MARC XSLT File"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.XSLT_File; } options["MarcXML_File_ReaderWriter:System Name"] = UI_ApplicationCache_Gateway.Settings.System.System_Name; options["MarcXML_File_ReaderWriter:System Abbreviation"] = UI_ApplicationCache_Gateway.Settings.System.System_Abbreviation; // Save to the database try { SobekCM_Item_Database.Save_Digital_Resource(Item_To_Complete, options); } 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 + "\\"; // Save the rest of the metadata Item_To_Complete.Save_SobekCM_METS(); // Finally, set the currentItem for more processing if there were any files if ((image_files.Length > 0) && (Item_To_Complete.Web.ItemID > 0)) { SobekCM_Item_Database.Update_Additional_Work_Needed_Flag(Item_To_Complete.Web.ItemID, true); } foreach (string thisFile in image_files) { try { File.Delete(thisFile); } catch (Exception ee) { RequestSpecificValues.Tracer.Add_Trace("Page_Image_Upload_MySobekViewer.Constructor", "Error deleting uploaded file: " + ee.Message); // Do nothing - not a fatal problem } } try { Directory.Delete(digitalResourceDirectory); } catch { // Do nothing - not a fatal problem } // This may be called from QC, so check on that as well string userInProcessDirectory = UI_ApplicationCache_Gateway.Settings.Servers.In_Process_Submission_Location + "\\" + RequestSpecificValues.Current_User.UserName.Replace(".", "").Replace("@", "") + "\\qcwork\\" + Item_To_Complete.METS_Header.ObjectID; if (RequestSpecificValues.Current_User.ShibbID.Trim().Length > 0) { userInProcessDirectory = UI_ApplicationCache_Gateway.Settings.Servers.In_Process_Submission_Location + "\\" + RequestSpecificValues.Current_User.ShibbID + "\\qcwork\\" + Item_To_Complete.METS_Header.ObjectID; } // Make the folder for the RequestSpecificValues.Current_User in process directory if (Directory.Exists(userInProcessDirectory)) { foreach (string thisFile in Directory.GetFiles(userInProcessDirectory)) { try { File.Delete(thisFile); } catch { // Do nothing - not a fatal problem } } } HttpContext.Current.Session[Item_To_Complete.BibID + "_" + Item_To_Complete.VID + " QC Work"] = null; } catch (Exception ee) { // Set an initial flag criticalErrorEncountered = true; string error_body = "<strong>ERROR ENCOUNTERED DURING ONLINE PAGE IMAGE UPLOAD</strong><br /><br /><blockquote>Title: " + Item_To_Complete.Bib_Info.Main_Title.Title + "<br />Permanent Link: <a href=\"" + RequestSpecificValues.Current_Mode.Base_URL + "/" + Item_To_Complete.BibID + "/" + Item_To_Complete.VID + "\">" + RequestSpecificValues.Current_Mode.Base_URL + "/" + Item_To_Complete.BibID + "/" + Item_To_Complete.VID + "</a><br />RequestSpecificValues.Current_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 = UI_ApplicationCache_Gateway.Settings.Email.System_Error_Email; if (email_to.Length == 0) { email_to = UI_ApplicationCache_Gateway.Settings.Email.System_Email; } Email_Helper.SendEmail(email_to, error_subject, error_body, true, String.Empty); } return(criticalErrorEncountered); }