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));
        }
Beispiel #2
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));
        }