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)); }