public static IamsItem GetIAMSRecords(HMDObject item)
        {
            // Remember to get the list of child records and pass this back to the image order csv somehow...
            String shelfmark = item.Shelfmark;
            String itemID    = null;

            if (item.ID != null)  // allows for some flexibility on being tied to sharepoint here
            {
                itemID = item.ID;
            }


            // build the request
            // Need to use a request with the 'None' format to get the catalogue publication status/state
            // Also need 'itemtype' field where this can be fonds etc

            // The only output format of the IAMS request that contains the catalogue publication status is "NONE"
            // So make two requests to get all the information required

            var iamsCatStatusRequest = IAMSURL + shelfmark.Replace(" ", "%20").Replace(",", "%2C") + @"&format=None";
            var iamsGetUrl           = IAMSURL + shelfmark.Replace(" ", "%20").Replace(",", "%2C") + @"&format=Qatar"; // Could use DIPS format, but Qatar gets you more information


            // Run the first request:
            var xmlTextReaderIamsNone = new XmlTextReader(iamsCatStatusRequest);
            var xmlDocumentIamsNone   = new XmlDocument();

            try
            {
                xmlDocumentIamsNone.Load(xmlTextReaderIamsNone);
            }
            catch
            {
                return(null);
            }
            var xmlNodeItemType  = xmlDocumentIamsNone.SelectSingleNode("//Header//RecordDetails//ItemType");
            var xmlNodeCatStatus = xmlDocumentIamsNone.SelectSingleNode("//Header//RecordDetails//Status");



            var iamsItemType = string.Empty;

            if (xmlNodeItemType != null)
            {
                iamsItemType = xmlNodeItemType.InnerText;
            }

            var iamsCatStatus = string.Empty;

            if (xmlNodeCatStatus != null)
            {
                iamsCatStatus = xmlNodeCatStatus.InnerText;
            }



            var xmlTextReaderIams = new XmlTextReader(iamsGetUrl);
            var xmlDocumentIams   = new XmlDocument();

            try
            {
                xmlDocumentIams.Load(xmlTextReaderIams);
            }
            catch
            {
                return(null);
            }
            var xmlNodeArk          = xmlDocumentIams.SelectSingleNode("//MDARK");
            var xmlNodeTitle        = xmlDocumentIams.SelectSingleNode("//Title");
            var xmlNodeSubSubSeries = xmlDocumentIams.SelectSingleNode("//Ancestors//Ancestor[@level='1']//Reference");
            var xmlLogicalLabel     = xmlDocumentIams.SelectSingleNode("//LogicalLabel");
            var xmlLogicalType      = xmlDocumentIams.SelectSingleNode("//LogicalType");
            var xmlChildRecords     = xmlDocumentIams.SelectNodes("//Children//Child//Reference");
            var xmlShelfmark        = xmlDocumentIams.SelectSingleNode("//Reference");


            var logicalLabel = string.Empty;
            var logicalType  = string.Empty;

            if (xmlNodeArk == null)
            {
                return(null);
            }
            var iamsArk = xmlNodeArk.InnerText;

            var  iamsRetrievedShelfmark = string.Empty;
            bool deleteFlagShelfmark    = false;

            if (xmlShelfmark != null)
            {
                iamsRetrievedShelfmark = xmlShelfmark.InnerText;
            }
            if (iamsRetrievedShelfmark.ToString().Contains("DEL") || iamsRetrievedShelfmark.ToString().Contains(@"D/"))
            {
                deleteFlagShelfmark = true;
            }

            var iamsTitle = string.Empty;

            if (xmlNodeTitle != null)
            {
                iamsTitle = xmlNodeTitle.InnerText;
            }

            var subSubSeries = string.Empty;

            if (xmlNodeSubSubSeries != null)
            {
                subSubSeries = xmlNodeSubSubSeries.InnerText;
            }

            if (xmlLogicalLabel != null)
            {
                logicalLabel = xmlLogicalLabel.InnerText;
            }

            if (xmlLogicalType != null)
            {
                logicalType = xmlLogicalType.InnerText;
            }

            List <string> childRecordTitles        = new List <String>();
            List <string> deletedChildRecordTitles = new List <String>();

            bool containsDeletedChildRecords = false;

            if (xmlChildRecords != null)
            {
                foreach (XmlNode record in xmlChildRecords)
                {
                    var innerText = record.InnerText;
                    childRecordTitles.Add(record.InnerText);
                    if (record.InnerText.ToString().Contains("DEL") || record.InnerText.ToString().Contains(@"D/"))
                    {
                        containsDeletedChildRecords = true;
                        deletedChildRecordTitles.Add(record.InnerText);
                    }
                }
            }
            bool isDeleteFlagPresent = false;

            if (containsDeletedChildRecords || deleteFlagShelfmark)
            {
                isDeleteFlagPresent = true;
            }

            var iamsItem = new IamsItem
            {
                SharepointID             = itemID,
                ItemShelfmark            = shelfmark,
                ItemDescription          = iamsTitle,
                ArkIdentifier            = iamsArk,
                SubSubSeries             = subSubSeries,
                LogicalLabel             = logicalLabel,
                LogicalType              = logicalType,
                ChildRecordTitles        = childRecordTitles,
                DeletedChildRecordTitles = deletedChildRecordTitles,
                DeleteFlagPresent        = isDeleteFlagPresent,
                ItemType        = iamsItemType,
                CatalogueStatus = iamsCatStatus
            };



            return(iamsItem);
        }
        public static List <AlephItem> GetAlephRecords(HMDObject item)
        {
            String shelfmark = item.Shelfmark;
            String itemID    = null;

            if (item.ID != null) // allows for some flexibility on being tied to sharepoint here
            {
                itemID = item.ID;
            }

            if (item.SystemNumber.Length < 1)
            {
                Console.WriteLine("No Aleph system number found when attempting to look up Aleph item for shelfmark: {0}", shelfmark);
                return(null);
            }
            var systemNumber = item.SystemNumber;


            // build the request
            var alephURL     = "http://xserver.bl.uk/X";
            var alephRequest = alephURL + "?op=find_doc&doc_num=" + systemNumber + "&base=BLL01"; // uses default BL base system number

            // Run the first request:
            var xmlTextReaderAleph = new XmlTextReader(alephRequest);
            var xmlDocumentAleph   = new XmlDocument();

            try
            {
                xmlDocumentAleph.Load(xmlTextReaderAleph);
            }
            catch
            {
                return(null);
            }
            var alephRecords = xmlDocumentAleph.SelectNodes("//find-doc//record//metadata//oai_marc");


            foreach (XmlNode element in alephRecords)

            {
                var thisvar = element.InnerText;
            }


            // this needs sorting out, but basically want a csv to write the attribute ID as a column and the value as a field
            // not sure what to do yet if the node has sub-lists, but debug this step by step and see if the node type changes?
            // nodes with sublists are all varfields!

            List <AlephItem> alephReturnedItems = new List <AlephItem>();

            var doc = XDocument.Load(alephRequest);


            var fixedfields = from @fixedfield in doc.Descendants("fixfield")
                              let fixedfieldName = (string)@fixedfield.Attribute("id")
                                                   let fixedfieldValue = (string)fixedfield.Value
                                                                         select new
            {
                FixedFieldName  = fixedfieldName,
                FixedFieldValue = fixedfieldValue
            };

            var varfields = from @varfield in doc.Descendants("varfield")
                            let varfieldName = (string)@varfield.Attribute("id")
                                               from subfield in @varfield.Descendants("subfield")
                                               select new
            {
                VarfieldName     = varfieldName,
                SubfieldLabel    = (string)subfield.Attribute("label"),
                SubfieldContents = (string)subfield.Value,
            };


            foreach (var field in fixedfields)
            {
                var alephItem = new AlephItem();
                alephItem.FieldTitle = field.FixedFieldName;
                alephItem.FieldValue = field.FixedFieldValue;
                alephReturnedItems.Add(alephItem);
            }
            foreach (var field in varfields)
            {
                var alephItem = new AlephItem();

                alephItem.FieldTitle = field.VarfieldName + field.SubfieldLabel;
                alephItem.FieldValue = field.SubfieldContents;
                alephReturnedItems.Add(alephItem);
            }

            return(alephReturnedItems);
        }
Example #3
0
        public static List <HMDObject> CheckSourceFolderExists(List <HMDSPObject> itemList)
        {
            // Need to translate the source folder paths retrieved from Sharepoint
            // into the actual source folder locations including the shelfmarks
            // Shelfmarks need to be transformed as per the DIPS naming requirements


            List <HMDObject> folderExistenceStatus = new List <HMDObject>();

            Console.WriteLine("=======================================\nValidating Source Folder Paths\n=======================================");
            var thisItem = 1;

            foreach (var item in itemList)
            {
                if (itemList.Count > 20)
                {
                    if (thisItem % 10 == 0)
                    {
                        Console.WriteLine("Processing item {0} of {1}", thisItem, itemList.Count);
                    }
                }
                else
                {
                    Console.WriteLine("Processing item {0} of {1}", thisItem, itemList.Count);
                }
                thisItem += 1;
                HMDObject HMDItem = new HMDObject(); // initialise new HMD object with null vals

                bool sourceFolderValid          = false;
                bool sourceFolderValidElsewhere = false;

                string fullSourceFolderPath = "";

                string ID             = item.ID;
                string Shelfmark      = item.Title;
                string sourceFolderSP = item.Location;
                string metadataSource = item.MetadataSource;
                string sysno          = item.SystemNumber;

                if (!String.IsNullOrEmpty(sourceFolderSP))
                {
                    string sourceFolder = sourceFolderSP.Replace("////", "//");
                    sourceFolder = sourceFolder.TrimEnd(); // trims whitespace from end
                    var sf1 = sourceFolder;
                    sourceFolder = sourceFolder.Replace("/", @"\");
                    var sf2 = sourceFolder;
                    sourceFolder = sourceFolder.Replace(@"file:", @"");
                    var sf3 = sourceFolder;
                    if (sourceFolder.Contains(@"\\\"))
                    {
                        // I haven't seen a case where this makes the source folder fail yet, so this isn't fatal
                        sourceFolder = sourceFolder.Replace(@"\\\", @"\\"); // this is there in some cases...
                        var sf4 = sourceFolder;
                    }
                    if (sourceFolder.Contains(@"%20"))
                    {
                        sourceFolder = sourceFolder.Replace(@"%20", @" ");
                    }

                    var sfAlt2 = sourceFolder.Split('\\')[2]; // Get the part of the string with server name in

                    try
                    {
                        string sfAlt              = sourceFolder.Replace(sfAlt2, @"ad\collections");
                        bool   DirectoryExists    = false;
                        bool   altDirectoryExists = false;
                        if (Directory.Exists(sourceFolder)) // Optimal case - the URL in sharepoint is correct!
                        {
                            sourceFolderValid    = true;
                            DirectoryExists      = true;
                            fullSourceFolderPath = ConstructFullFolderName(Shelfmark, sourceFolder);
                        }
                        else
                        {
                            altDirectoryExists = Directory.Exists(sfAlt);
                            if (altDirectoryExists) // Next most-optimal case - URL in sharepoint is wrong but it's just the server
                            {
                                sourceFolderValidElsewhere = true;
                                fullSourceFolderPath       = ConstructFullFolderName(Shelfmark, sfAlt);
                            }
                            else
                            {
                                fullSourceFolderPath = "";
                            }
                        }

                        if (!DirectoryExists && altDirectoryExists)
                        {
                            Console.WriteLine("Folder: {0} \t Exists at {1}: {2}", sourceFolder, sfAlt, altDirectoryExists);
                        }
                        else if (!DirectoryExists && !altDirectoryExists)
                        {
                            Console.WriteLine("ERROR: Folder {0} not found", sourceFolder);
                        }
                        string folderStatus = DirectoryExists.ToString();
                        HMDItem.ID                             = ID;
                        HMDItem.Shelfmark                      = Shelfmark;
                        HMDItem.SourceFolderPath               = sourceFolder;
                        HMDItem.FolderStatus                   = folderStatus;
                        HMDItem.AltDirectoryExists             = altDirectoryExists;
                        HMDItem.SourceFolderValid              = sourceFolderValid;
                        HMDItem.FullSourceFolderPath           = fullSourceFolderPath;
                        HMDItem.SourceFolderPathValidElsewhere = sourceFolderValidElsewhere;
                        HMDItem.MetadataSource                 = metadataSource;
                        HMDItem.SystemNumber                   = sysno;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("ERROR: Shelfmark {0}\n Exception: {1}", Shelfmark, ex);
                        bool DirectoryStatus    = false;
                        bool altDirectoryStatus = false;
                        HMDItem.ID                             = ID;
                        HMDItem.Shelfmark                      = Shelfmark;
                        HMDItem.SourceFolderPath               = sourceFolder;
                        HMDItem.FolderStatus                   = DirectoryStatus.ToString();
                        HMDItem.AltDirectoryExists             = altDirectoryStatus;
                        HMDItem.SourceFolderValid              = sourceFolderValid;
                        HMDItem.FullSourceFolderPath           = fullSourceFolderPath;
                        HMDItem.SourceFolderPathValidElsewhere = sourceFolderValidElsewhere;
                        HMDItem.MetadataSource                 = metadataSource;
                        HMDItem.SystemNumber                   = sysno;
                        folderExistenceStatus.Add(HMDItem);
                        continue;

                        // really need to handle this exception properly!
                    }
                }
                else // in case you're passed something with a null value for source folder
                {
                    bool DirectoryStatus    = false;
                    bool altDirectoryStatus = false;
                    HMDItem.ID                             = ID;
                    HMDItem.Shelfmark                      = Shelfmark;
                    HMDItem.SourceFolderPath               = null;
                    HMDItem.FolderStatus                   = DirectoryStatus.ToString();
                    HMDItem.AltDirectoryExists             = altDirectoryStatus;
                    HMDItem.SourceFolderValid              = false;
                    HMDItem.FullSourceFolderPath           = null;
                    HMDItem.SourceFolderPathValidElsewhere = false;
                    HMDItem.MetadataSource                 = metadataSource;
                    HMDItem.SystemNumber                   = sysno;
                }
                folderExistenceStatus.Add(HMDItem);
            }
            return(folderExistenceStatus);
        }