launch_rules.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package service
  2. import (
  3. "net/http"
  4. "cmr-backend/internal/apperr"
  5. "cmr-backend/internal/store/postgres"
  6. )
  7. const (
  8. launchReadyReasonOK = "event is active and launchable"
  9. launchReadyReasonNotActive = "event is not active"
  10. launchReadyReasonReleaseMissing = "event does not have a published release"
  11. launchReadyReasonRuntimeMissing = "current published release is missing runtime binding"
  12. launchReadyReasonPresentationMissing = "current published release is missing presentation binding"
  13. launchReadyReasonContentMissing = "current published release is missing content bundle binding"
  14. )
  15. func evaluateEventLaunchReadiness(event *postgres.Event) (bool, string) {
  16. if event == nil {
  17. return false, launchReadyReasonReleaseMissing
  18. }
  19. if event.Status != "active" {
  20. return false, launchReadyReasonNotActive
  21. }
  22. if event.CurrentReleaseID == nil || event.CurrentReleasePubID == nil || event.ConfigLabel == nil || event.ManifestURL == nil {
  23. return false, launchReadyReasonReleaseMissing
  24. }
  25. if buildRuntimeSummaryFromEvent(event) == nil {
  26. return false, launchReadyReasonRuntimeMissing
  27. }
  28. if buildPresentationSummaryFromEvent(event) == nil {
  29. return false, launchReadyReasonPresentationMissing
  30. }
  31. if buildContentBundleSummaryFromEvent(event) == nil {
  32. return false, launchReadyReasonContentMissing
  33. }
  34. return true, launchReadyReasonOK
  35. }
  36. func launchReadinessError(reason string) error {
  37. switch reason {
  38. case launchReadyReasonNotActive:
  39. return apperr.New(http.StatusConflict, "event_not_launchable", reason)
  40. case launchReadyReasonReleaseMissing:
  41. return apperr.New(http.StatusConflict, "event_release_missing", reason)
  42. case launchReadyReasonRuntimeMissing:
  43. return apperr.New(http.StatusConflict, "event_release_runtime_missing", reason)
  44. case launchReadyReasonPresentationMissing:
  45. return apperr.New(http.StatusConflict, "event_release_presentation_missing", reason)
  46. case launchReadyReasonContentMissing:
  47. return apperr.New(http.StatusConflict, "event_release_content_bundle_missing", reason)
  48. default:
  49. return apperr.New(http.StatusConflict, "event_not_launchable", reason)
  50. }
  51. }