public async Task <HttpResponseMessage> Get(string repo = "", string barcode = "")
        {
            if (repo == "")
            {
                repo = ASpace_Aeon_Middleware.Configuration.DefaultSite;
            }
            var activeService = await _serviceHandler.GetArchivesSpaceServiceAsync(repo);

            var tcManager  = new ArchivesSpaceTopContainerManager(activeService);
            var vapiClient = new VoyagerApiClient();
            var resultList = new List <CombinedBarcodeResponseItem>();

            if (!String.IsNullOrWhiteSpace(barcode))
            {
                var tc = tcManager.GetTopContainerByBarcodeAsync(barcode);
                var vi = vapiClient.GetBibItemByBarcodeAsync(barcode);
                await Task.WhenAll(tc, vi);

                var tcEntry = await FormatTcEntryAsync(tc.Result, activeService);

                var viEntry = FormatViEntry(vi.Result, barcode);
                if (!String.IsNullOrWhiteSpace(tcEntry.Origin)) // this always set if there's a result
                {
                    resultList.Add(tcEntry);
                }
                if (!String.IsNullOrWhiteSpace(viEntry.Origin))
                {
                    resultList.Add(viEntry);
                }
                return(Request.CreateResponse(HttpStatusCode.OK, resultList));
            }
            return(Request.CreateResponse(HttpStatusCode.OK, resultList));
        }
コード例 #2
0
        public async Task <HttpResponseMessage> Get(string repo = "", string type = "", string q = "")
        {
            //Type is maintained for signature consistency but is not used
            var reqId = Guid.NewGuid().ToString("D");
            var sw    = new Stopwatch();

            sw.Start();
            _logger.Trace("Request for URI [ {0} ] received and assigned ID [ {1} ]", Request.RequestUri, reqId);

            if (repo == "")
            {
                repo = ASpace_Aeon_Middleware.Configuration.DefaultSite;
            }
            var activeService = await _serviceHandler.GetArchivesSpaceServiceAsync(repo);

            var searchEngine  = new ArchivesSpaceSearch(activeService);
            var searchOptions = new SearchOptions
            {
                Query = q //note this is not scrubbed for stopwords since the SOLR index will handle that
            };

            if (String.IsNullOrWhiteSpace(q))
            {
                _logger.Trace("Request [ {0} ] finished in [ {1} ] ms", reqId, sw.ElapsedMilliseconds);
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            var result = await searchEngine.ResourceSearchAsync(searchOptions, false); //since this is a quick search we only want page one of search results

            if (result.TotalHits < 0)
            {
                _logger.Trace("Request [ {0} ] finished in [ {1} ] ms", reqId, sw.ElapsedMilliseconds);
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            var formattedResult = ResultsToPipeSeparatedFormat(result.Results, q);

            _logger.Trace("Request [ {0} ] finished in [ {1} ] ms", reqId, sw.ElapsedMilliseconds);
            return(Request.CreateResponse(HttpStatusCode.OK, formattedResult, "text/plain"));
        }
コード例 #3
0
        public async Task <HttpResponseMessage> Get(string repo = "", string barcode = ""
                                                    , [FromUri(Name = "item_id")] int?topContainerIdNullable = 0)
        {
            var topContainerId = topContainerIdNullable ?? 0; //if a querystring specifies the parameter with no value the binding fails with a "non-nullable type" error even if a default is specified. Int params must be nullable ints.

            if (repo == "")
            {
                repo = ASpace_Aeon_Middleware.Configuration.DefaultSite;
            }
            var activeService = await _serviceHandler.GetArchivesSpaceServiceAsync(repo);

            var tcManager  = new ArchivesSpaceTopContainerManager(activeService);
            var resultList = new List <BarcodeResponseItem>();

            if (topContainerId != 0)
            {
                var tc = await tcManager.GetTopContainerByIdAsync(topContainerId);

                var tcEntry = await FormatEntry(tc, activeService);

                resultList.Add(tcEntry);
                return(Request.CreateResponse(HttpStatusCode.OK, resultList));
            }
            if (!String.IsNullOrWhiteSpace(barcode))
            {
                var tc = await tcManager.GetTopContainerByBarcodeAsync(barcode);

                if (tc == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, resultList));
                }
                var tcEntry = await FormatEntry(tc, activeService);

                resultList.Add(tcEntry);
                return(Request.CreateResponse(HttpStatusCode.OK, resultList));
            }
            return(Request.CreateResponse(HttpStatusCode.OK, resultList));
        }
        public async Task <HttpResponseMessage> Get(string repo = ""
                                                    , [FromUri(Name = "bib_id")] int?bibIdNullable  = 0
                                                    , [FromUri(Name = "call_no")] string callNumber = "")
        {
            var reqId = Guid.NewGuid().ToString("D");
            var sw    = new Stopwatch();

            sw.Start();
            _logger.Trace("Request for URI [ {0} ] received and assigned ID [ {1} ]", Request.RequestUri, reqId);
            var bibId = bibIdNullable ?? 0;

            if (repo == "")
            {
                repo = ASpace_Aeon_Middleware.Configuration.DefaultSite;
            }
            var resourceId = bibId; //parameters have to be named so for querystring binding with legacy client
            var resultList = new List <SeriesResponseItem>();
            ArchivesSpaceService activeService;

            try
            {
                activeService = await _serviceHandler.GetArchivesSpaceServiceAsync(repo);
            }
            catch (InvalidOperationException ex)
            {
                _logger.Trace("Request [ {0} ] finished in [ {1} ] ms", reqId, sw.ElapsedMilliseconds);
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, String.Format("repository [ {0} ] is not a valid repository", repo), ex));
            }
            if (resourceId == 0)
            {
                if (callNumber == "" || callNumber == String.Empty)
                {
                    _logger.Trace("Request [ {0} ] finished in [ {1} ] ms", reqId, sw.ElapsedMilliseconds);
                    return(Request.CreateResponse(HttpStatusCode.OK, resultList));
                }
                var aspaceHelper = new AspaceHelpers(activeService);
                var searchResult = await aspaceHelper.GetResourceIdFromCallNumber(callNumber);

                if (searchResult == 0)
                {
                    _logger.Trace("Request [ {0} ] finished in [ {1} ] ms", reqId, sw.ElapsedMilliseconds);
                    return(Request.CreateResponse(HttpStatusCode.OK, resultList));
                }
                resourceId = searchResult;
            }
            var resourceService    = new ArchivesSpaceResourceManager(activeService);
            var resourceRecordTask = resourceService.GetResourceByIdAsync(resourceId);
            var seriesRecords      = await resourceService.GetTopLevelSeriesArchivalObjects(resourceId);

            if (seriesRecords.Count > 0)
            {
                var resourceRecord = await resourceRecordTask;
                foreach (var archivalObject in seriesRecords)
                {
                    var resultEntry = new SeriesResponseItem
                    {
                        CollectionTitle = resourceRecord.Title,
                        EadLocation     = resourceRecord.EadLocation,
                        SeriesId        = archivalObject.Id,
                        SeriesDiv       = archivalObject.ComponentId.FormatSeriesDivision(),
                        SeriesTitle     = archivalObject.DisplayString //The title omits some information
                    };
                    resultList.Add(resultEntry);
                }
            }
            _logger.Trace("Request [ {0} ] finished in [ {1} ] ms", reqId, sw.ElapsedMilliseconds);
            return(Request.CreateResponse(HttpStatusCode.OK, resultList));
        }
        public async Task <HttpResponseMessage> Get(string repo = ""
                                                    , [FromUri(Name = "mfhd_id")] int?mfhdIdNullable     = 0
                                                    , [FromUri(Name = "bib_id")] int?bibIdNullable       = 0
                                                    , [FromUri(Name = "call_no")] string callNumber      = ""
                                                    , [FromUri(Name = "series_id")] int?seriesIdNullable = 0)
        {
            var reqId = Guid.NewGuid().ToString("D");
            var sw    = new Stopwatch();

            sw.Start();
            _logger.Trace("Request for URI [ {0} ] received and assigned ID [ {1} ]", Request.RequestUri, reqId);
            var mfhdId   = mfhdIdNullable ?? 0; //avoid null type errors if a querystring with ?id=&otherId=3 is sent
            var bibId    = bibIdNullable ?? 0;
            var seriesId = seriesIdNullable ?? 0;

            repo = repo == "" ? ASpace_Aeon_Middleware.Configuration.DefaultSite : repo;
            var activeService = await _serviceHandler.GetArchivesSpaceServiceAsync(repo); //call this anyway to make sure it's ready for the next request

            var responseList = new List <EnumResponseItem>();

            if (seriesId == 0 && bibId == 0 && mfhdId == 0 && String.IsNullOrWhiteSpace(callNumber))
            {
                _logger.Trace("Request [ {0} ] finished in [ {1} ] ms", reqId, sw.ElapsedMilliseconds);
                return(Request.CreateResponse(HttpStatusCode.OK, responseList));
            }
            if (seriesId != 0)
            {
                await GetContainersForSeriesId(activeService, seriesId, responseList);
            }
            else //if a series is provided the bib
            {
                var resourceId = bibId == 0 ? mfhdId : bibId; //original webservice declared bibId and mfhdId to be the same
                if (resourceId != 0)
                {
                    await GetContainersForResourceId(activeService, resourceId, responseList);
                }
                else if (callNumber != "")
                {
                    //resource ID was empty but a call number was provided
                    var aspaceHelper = new AspaceHelpers(activeService);
                    resourceId = await aspaceHelper.GetResourceIdFromCallNumber(callNumber);

                    if (resourceId == 0)
                    {
                        // no matching resource found; give up
                        _logger.Trace("Request [ {0} ] finished in [ {1} ] ms", reqId, sw.ElapsedMilliseconds);
                        return(Request.CreateResponse(HttpStatusCode.OK, responseList));
                    }
                    await GetContainersForResourceId(activeService, resourceId, responseList);
                }
                else
                {
                    //still no hits; give up
                    _logger.Trace("Request [ {0} ] finished in [ {1} ] ms", reqId, sw.ElapsedMilliseconds);
                    return(Request.CreateResponse(HttpStatusCode.OK, responseList));
                }
            }
            var sortedList = responseList.OrderBy(x => x.BoxNumber, new NaturalComparer()).ToList(); //serializer doesn't like the IOrderedEnumerable returned by orderby

            _logger.Trace("Request [ {0} ] finished in [ {1} ] ms", reqId, sw.ElapsedMilliseconds);
            return(Request.CreateResponse(HttpStatusCode.OK, sortedList));
        }