/// <summary> Saves all of the digital resource information to solr/lucene </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) { // Save this to the Solr/Lucene database if (!String.IsNullOrEmpty(Settings.Servers.Document_Solr_Index_URL)) { if (((!Resource.Metadata.Behaviors.IP_Restriction_Membership_Is_Null) && (Resource.Metadata.Behaviors.IP_Restriction_Membership < 0)) || ((!Resource.Metadata.Behaviors.Dark_Flag_Is_Null) && (Resource.Metadata.Behaviors.Dark_Flag))) { Solr_Controller.Delete_Resource_From_Index(Settings.Servers.Document_Solr_Index_URL, Settings.Servers.Page_Solr_Index_URL, Resource.BibID, Resource.VID); return(true); } try { Solr_Controller.Update_Index(Settings.Servers.Document_Solr_Index_URL, Settings.Servers.Page_Solr_Index_URL, Resource.Metadata, true); } catch (Exception ee) { OnError("Error saving data to the Solr/Lucene index. The index may not reflect the most recent data in the METS.", Resource.BibID + ":" + Resource.VID, Resource.METS_Type_String, Resource.BuilderLogId); OnError("Solr Error: " + ee.Message, Resource.BibID + ":" + Resource.VID, Resource.METS_Type_String, Resource.BuilderLogId); } } return(true); }
private void Delete_Item() { errorCode = 0; // Get the current item details string vid_location = SobekFileSystem.Resource_Network_Uri(itemToDelete); DirectoryInfo directoryInfo = (new DirectoryInfo(vid_location)).Parent; if (directoryInfo != null) { string bib_location = directoryInfo.FullName; //if (errorCode == -1) //{ // // Get item details // DataSet itemDetails = SobekCM_Database.Get_Item_Details(currentMode.BibID, currentMode.VID, Tracer); // // If the itemdetails was null, this item is somehow invalid item then // if (itemDetails == null) // { // Tracer.Add_Trace("Delete_Item_MySobekViewer.Constructor", "Item indicated is not valid", Custom_Trace_Type_Enum.Error); // errorCode = 2; // } // else // { // // Get the location for this METS file from the returned value // DataRow mainItemRow = itemDetails.Tables[2].Rows[0]; // bib_location = UI_ApplicationCache_Gateway.Settings.Servers.Image_Server_Network + mainItemRow["File_Location"].ToString().Replace("/", "\\"); // vid_location = bib_location + "\\" + currentMode.VID; // } //} // Perform the database delete RequestSpecificValues.Tracer.Add_Trace("Delete_Item_MySobekViewer.Constructor", "Perform database update"); bool database_result2 = Engine_Database.Delete_SobekCM_Item(RequestSpecificValues.Current_Mode.BibID, RequestSpecificValues.Current_Mode.VID, RequestSpecificValues.Current_User.Is_System_Admin, String.Empty); // Perform the SOLR delete RequestSpecificValues.Tracer.Add_Trace("Delete_Item_MySobekViewer.Constructor", "Perform solr delete"); Solr_Controller.Delete_Resource_From_Index(UI_ApplicationCache_Gateway.Settings.Servers.Document_Solr_Index_URL, UI_ApplicationCache_Gateway.Settings.Servers.Page_Solr_Index_URL, RequestSpecificValues.Current_Mode.BibID, RequestSpecificValues.Current_Mode.VID); if (!database_result2) { RequestSpecificValues.Tracer.Add_Trace("Delete_Item_MySobekViewer.Constructor", "Error performing delete in the database", Custom_Trace_Type_Enum.Error); errorCode = 3; } else { // Move the folder to deletes try { RequestSpecificValues.Tracer.Add_Trace("Delete_Item_MySobekViewer.Constructor", "Move resource files to RECYCLE BIN folder"); // Make sure upper RECYCLE BIN folder exists, or create it string delete_folder = UI_ApplicationCache_Gateway.Settings.Servers.Image_Server_Network + "RECYCLE BIN"; if (!Directory.Exists(delete_folder)) { Directory.CreateDirectory(delete_folder); } // Create the bib level folder next string bib_folder = UI_ApplicationCache_Gateway.Settings.Servers.Image_Server_Network + "RECYCLE BIN\\" + RequestSpecificValues.Current_Mode.BibID; if (!Directory.Exists(bib_folder)) { Directory.CreateDirectory(bib_folder); } // Ensure the VID folder does not exist string vid_folder = UI_ApplicationCache_Gateway.Settings.Servers.Image_Server_Network + "RECYCLE BIN\\" + RequestSpecificValues.Current_Mode.BibID + "\\" + RequestSpecificValues.Current_Mode.VID; if (Directory.Exists(vid_folder)) { Directory.Move(vid_folder, vid_folder + "_OLD"); } // Move the VID folder over now Directory.Move(vid_location, vid_folder); // Check if this was the last VID under this BIB if (Directory.GetDirectories(bib_location).Length == 0) { // Move all files over to the bib folder then string[] bib_files = Directory.GetFiles(bib_location); foreach (string thisFile in bib_files) { string fileName = (new FileInfo(thisFile)).Name; string new_file = bib_folder + "\\" + fileName; File.Move(thisFile, new_file); } } } catch (Exception ee) { RequestSpecificValues.Tracer.Add_Trace("Delete_Item_MySobekViewer.Constructor", "Error moving the folder and files to the RECYCLE BIN folder", Custom_Trace_Type_Enum.Error); RequestSpecificValues.Tracer.Add_Trace("Delete_Item_MySobekViewer.Constructor", ee.Message, Custom_Trace_Type_Enum.Error); RequestSpecificValues.Tracer.Add_Trace("Delete_Item_MySobekViewer.Constructor", ee.StackTrace, Custom_Trace_Type_Enum.Error); errorCode = 4; } // Also remove from the cache CachedDataManager.Items.Remove_Digital_Resource_Object(RequestSpecificValues.Current_Mode.BibID, RequestSpecificValues.Current_Mode.VID, RequestSpecificValues.Tracer); } } }
/// <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> Performs a delete from the database and moves all digital resource /// files into the recycle bin </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) { // Read the METS and load the basic information before continuing Resource.Load_METS(); Engine_Database.Add_Minimum_Builder_Information(Resource.Metadata); Resource.BuilderLogId = OnProcess("........Processing '" + Resource.Folder_Name + "'", "Standard", Resource.BibID + ":" + Resource.VID, Resource.METS_Type_String, -1); Engine_Database.Builder_Clear_Item_Error_Log(Resource.BibID, Resource.VID, "SobekCM Builder"); Resource.File_Root = Resource.BibID.Substring(0, 2) + "\\" + Resource.BibID.Substring(2, 2) + "\\" + Resource.BibID.Substring(4, 2) + "\\" + Resource.BibID.Substring(6, 2) + "\\" + Resource.BibID.Substring(8); string existing_folder = Settings.Servers.Image_Server_Network + Resource.File_Root + "\\" + Resource.VID; // Remove from the primary collection area try { if (Directory.Exists(existing_folder)) { // Make sure the delete folder exists if (!Directory.Exists(Settings.Servers.Image_Server_Network + "\\RECYCLE BIN")) { Directory.CreateDirectory(Settings.Servers.Image_Server_Network + "\\RECYCLE BIN"); } // Create the final directory string final_folder = Settings.Servers.Image_Server_Network + "\\RECYCLE BIN\\" + Resource.File_Root + "\\" + Resource.VID; if (!Directory.Exists(final_folder)) { Directory.CreateDirectory(final_folder); } // Move each file string[] delete_files = Directory.GetFiles(existing_folder); foreach (string thisDeleteFile in delete_files) { string destination_file = final_folder + "\\" + Path.GetFileName(thisDeleteFile); if (File.Exists(destination_file)) { File.Delete(destination_file); } File.Move(thisDeleteFile, destination_file); } } } catch (Exception ee) { OnError("Unable to move resource ( " + Resource.BibID + ":" + Resource.VID + " ) to deletes", Resource.BibID + ":" + Resource.VID, Resource.METS_Type_String, Resource.BuilderLogId); OnError(ee.Message, Resource.BibID + ":" + Resource.VID, Resource.METS_Type_String, Resource.BuilderLogId); return(false); } // Delete the static page string static_page1 = Settings.Servers.Static_Pages_Location + Resource.BibID.Substring(0, 2) + "\\" + Resource.BibID.Substring(2, 2) + "\\" + Resource.BibID.Substring(4, 2) + "\\" + Resource.BibID.Substring(6, 2) + "\\" + Resource.BibID.Substring(8) + "\\" + Resource.VID + "\\" + Resource.BibID + "_" + Resource.VID + ".html"; if (File.Exists(static_page1)) { File.Delete(static_page1); } string static_page2 = Settings.Servers.Static_Pages_Location + Resource.BibID.Substring(0, 2) + "\\" + Resource.BibID.Substring(2, 2) + "\\" + Resource.BibID.Substring(4, 2) + "\\" + Resource.BibID.Substring(6, 2) + "\\" + Resource.BibID.Substring(8) + "\\" + Resource.BibID + "_" + Resource.VID + ".html"; if (File.Exists(static_page2)) { File.Delete(static_page2); } // Delete the file from the database Engine_Database.Delete_SobekCM_Item(Resource.BibID, Resource.VID, true, "Deleted upon request by builder"); // Delete from the solr/lucene indexes if (Settings.Servers.Document_Solr_Index_URL.Length > 0) { try { Solr_Controller.Delete_Resource_From_Index(Settings.Servers.Document_Solr_Index_URL, Settings.Servers.Page_Solr_Index_URL, Resource.BibID, Resource.VID); } catch (Exception ee) { OnError("Error deleting item from the Solr/Lucene index. The index may not reflect this delete.", Resource.BibID + ":" + Resource.VID, Resource.METS_Type_String, Resource.BuilderLogId); OnError("Solr Error: " + ee.Message, Resource.BibID + ":" + Resource.VID, Resource.METS_Type_String, Resource.BuilderLogId); return(false); } } // Delete the handled METS file and package Resource.Delete(); return(true); }