コード例 #1
0
        public async Task <IHttpActionResult> GetNextDigitalisierungsauftrag()
        {
            DigipoolEntry digipoolEntry = null;

            if (!ApiKeyChecker.IsCorrect(Request))
            {
                return(Unauthorized());
            }

            try
            {
                Log.Verbose("Getting next order from digipool");
                DigitalisierungsAuftrag auftrag;
                var digipoolEntryArray = await orderManagerClient.GetDigipool(1);

                if (digipoolEntryArray.Length == 0)
                {
                    return(StatusCode(HttpStatusCode.NoContent));
                }

                digipoolEntry = digipoolEntryArray[0];

                // Hat der zurückgelieferte Eintrag einen Aufbereitungsfehler, so bedeutet dies,
                // dass nur noch Aufträge mit Aufbereitungsfehlern im Digipool liegen.
                // Wir liefern einen spezifischen HTTP Code zurück um dies anzuzeigen
                if (digipoolEntry.HasAufbereitungsfehler)
                {
                    return(Content(HttpStatusCode.Forbidden, onlyFaultedItemsInDigipoolExceptionMessage));
                }

                if (digipoolEntry.VeId.HasValue)
                {
                    // Hat die Bestellung eine VE-ID, so holen wir die Details zum Record aus Elastic und
                    // bereiten die Bestellung über den Dienst auf.
                    Log.Verbose($"Fetching ve {digipoolEntry.VeId} from elastic index");
                    var orderedItemRecord = await messageBusCallHelper.GetElasticArchiveRecord(digipoolEntry.VeId.ToString());

                    if (orderedItemRecord == null)
                    {
                        throw new Exception(veNotFoundMessage);
                    }

                    Log.Verbose($"Fetching full digitization order from AIS for {orderedItemRecord.GetAuszuhebendeArchiveRecordId()}");
                    auftrag = await digitizationHelper.GetDigitalisierungsAuftrag(orderedItemRecord.GetAuszuhebendeArchiveRecordId());

                    // Lade Dossier, falls bestellte Einheit nicht das Dossier ist
                    ElasticArchiveRecord dossierRecord;
                    dossierRecord = auftrag.Dossier.VerzEinheitId.ToString() != orderedItemRecord.ArchiveRecordId
                        ? await messageBusCallHelper.GetElasticArchiveRecord(auftrag.Dossier.VerzEinheitId.ToString())
                        : orderedItemRecord;

                    if (dossierRecord.ProtectionEndDate?.Date == null)
                    {
                        throw new Exception(veHasNoProtectionEndDateMessage);
                    }

                    // Schutzfrist für Bestellungen hängen vom Schutzfrist-Enddatum des Dossiers und dem Freigabestatus ab.
                    // Der Freigabestatus ist immer derjenige der bestellten Einheit.
                    if (dossierRecord.ProtectionEndDate.Date > DateTime.Today)
                    {
                        auftrag.Dossier.InSchutzfrist = digipoolEntry.ApproveStatus != ApproveStatus.FreigegebenAusserhalbSchutzfrist;
                    }
                    else
                    {
                        auftrag.Dossier.InSchutzfrist = digipoolEntry.ApproveStatus == ApproveStatus.FreigegebenInSchutzfrist;
                    }

                    // Übertrage den Wert des Schutzfristproperties des Dossiers, auf alle enthaltenen VE (rekursiv)
                    UpdateInSchutzfrist(auftrag.Dossier.UntergeordneteVerzEinheiten, auftrag.Dossier.InSchutzfrist);
                }
                else
                {
                    // Hat die Bestellung KEINE VE-ID, so handelt es sich um ein manuell hinzugefügtes Dossier.
                    // Wir erstellen manuell ein DigitalisierungsAuftrag mit den Angaben des Benutzers.
                    auftrag = await digitizationHelper.GetManualDigitalisierungsAuftrag(digipoolEntry);

                    // Schutzfrist für manuelle Bestellungen hängen nur vom Freigabestatus des Auftrags ab.
                    auftrag.Dossier.InSchutzfrist = digipoolEntry.ApproveStatus != ApproveStatus.FreigegebenAusserhalbSchutzfrist;
                }

                // Gemeinsame Daten
                auftrag.Auftragsdaten.AuftragsId       = digipoolEntry.OrderItemId.ToString();
                auftrag.Auftragsdaten.BemerkungenBar   = digipoolEntry.InternalComment + "";
                auftrag.Auftragsdaten.BemerkungenKunde = GetBemerkungKunde(digipoolEntry) + "";
                auftrag.Auftragsdaten.Bestelldatum     = digipoolEntry.OrderDate;

                Log.Verbose("Update Benutzungskopie flag for order");
                await orderManagerClient.UpdateBenutzungskopie(digipoolEntry.OrderItemId, auftrag.Auftragsdaten.Benutzungskopie);

                var errorList = ValidateAuftrag(auftrag);

                if (errorList.Any())
                {
                    throw new XmlSchemaValidationException("The data is not valid according to the Auftragsdaten.xsd schema. " +
                                                           $"{Environment.NewLine}The errors found are:{Environment.NewLine}" +
                                                           $"{string.Join(Environment.NewLine, errorList)}");
                }

                return(Ok(auftrag));
            }
            // Request timeout --> Manager, Index or External Content Service is not running
            catch (RequestTimeoutException e)
            {
                Log.Error(e, "RequestTimeout Exception");
                return(Content(HttpStatusCode.ServiceUnavailable, serviceNotAvailableExceptionMessage));
            }
            // Something in the remote call failed.
            catch (RequestFaultException e)
            {
                Log.Error(e, "Remote call faulted");
                // if we have a remote sql db problem, then return a service unavailable
                if (e.Fault.Exceptions[0].ExceptionType == typeof(OrderDatabaseNotFoundOrNotRunningException).FullName)
                {
                    return(Content(HttpStatusCode.ServiceUnavailable, $"{serviceNotAvailableExceptionMessage} (SQL Server not running.)"));
                }

                // if we have a remote ais db problem, then return a service unavailable
                if (e.Fault.Exceptions[0].ExceptionType == typeof(AISDatabaseNotFoundOrNotRunningException).FullName)
                {
                    return(Content(HttpStatusCode.ServiceUnavailable, $"{serviceNotAvailableExceptionMessage} (AIS database not running."));
                }

                // Any other problem, mark the order as faulted.
                if (digipoolEntry != null)
                {
                    return(await ProcessFaultedItem(digipoolEntry,
                                                    $"{e.Fault.Exceptions[0].Message}{Environment.NewLine + Environment.NewLine}{e.Fault.Exceptions[0].StackTrace}"));
                }

                // If there is an error, and we do not have a digipool entry, then return internal server error
                // This should not happen
                return(InternalServerError(e));
            }
            catch (XmlSchemaValidationException e)
            {
                Log.Error(e, "Schema validation failed");
                return(await ProcessNormalError(digipoolEntry, e));
            }
            catch (Exception e)
            {
                Log.Error(e, "Unexpected error while getting next order from digipool.");
                return(await ProcessNormalError(digipoolEntry, e));
            }
        }
コード例 #2
0
 public async Task <DigipoolEntry[]> GetDigiPool(int numberOfEntries = int.MaxValue)
 {
     return(await orderManagerClient.GetDigipool(numberOfEntries));
 }