Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/modules/commandcenter/service_adopt.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 255e7d1d420abf5e277d0cd8c9b14f6f72b6acb9 |
| Branch | workstream-d-command-center |
| Path or archive member | internal/modules/commandcenter/service_adopt.go |
| Original SHA-256 | 97bc670fd68b89ad024e4213481d55634411c01e01e12ff0e3853c2e37bf70a0 |
| Git blob SHA | 0222de735d97e130371c670d698f7ac4110111ef |
| Reading-copy SHA-256 | 97bc670fd68b89ad024e4213481d55634411c01e01e12ff0e3853c2e37bf70a0 |
Every recorded occurrence
These 3 records contain identical original source bytes. Their paths and revisions remain part of the archive.
| Original record | Branch or archive | Revision / identifier | Original location |
|---|---|---|---|
| Janady13/missionmatch / internal/modules/commandcenter/service_adopt.go | workstream-d-command-center | 255e7d1d420abf5e277d0cd8c9b14f6f72b6acb9 | Open original |
| Janady13/missionmatch / internal/modules/commandcenter/service_adopt.go | workstream-e-commercial-stubs | 4437da660539284a400ee380b9b427a300c369ee | Open original |
| Janady13/missionmatch / internal/modules/commandcenter/service_adopt.go | workstream-d-command-center | 255e7d1d420abf5e277d0cd8c9b14f6f72b6acb9 | Open original |
Recovered source transcript
Download complete source text ↓142 lines · 4.1 KB
package commandcenter
import (
"context"
"encoding/json"
"errors"
"strings"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/missionworkforce/missionmatch/internal/platform/audit"
"github.com/missionworkforce/missionmatch/internal/platform/database/dbgen"
"github.com/missionworkforce/missionmatch/internal/platform/tenant"
)
var validLevels = map[string]bool{"none": true, "confidential": true, "secret": true, "top_secret": true, "ts_sci": true}
var validPolys = map[string]bool{"none": true, "ci": true, "full_scope": true}
// AdoptForecast turns a planning stage forecast into a real, tracked requirement the shared engine then
// scores like any other (the adopt to score path; no parallel scoring). It reads the public forecast for
// its title, agency, and place of performance, then creates a standalone requirement (no opportunity)
// with the clearance, years, and mandatory skills the operator supplies, all inside one tenant
// transaction so the new requirement is RLS scoped to the caller's org. The create is recorded to the
// append only audit trail.
func (s *Service) AdoptForecast(ctx context.Context, recordID string, in AdoptForecastInput) (AdoptForecastResult, error) {
if s.db == nil {
return AdoptForecastResult{}, ErrNoDatabase
}
actor, ok := tenant.UserFromContext(ctx)
if !ok {
return AdoptForecastResult{}, tenant.ErrNoTenant
}
orgStr, ok := tenant.OrgFromContext(ctx)
if !ok {
return AdoptForecastResult{}, tenant.ErrNoTenant
}
orgID, err := uuid.Parse(orgStr)
if err != nil {
return AdoptForecastResult{}, tenant.ErrNoTenant
}
level := "none"
if l := strings.TrimSpace(strings.ToLower(in.RequiredLevel)); validLevels[l] {
level = l
}
poly := "none"
if p := strings.TrimSpace(strings.ToLower(in.RequiredPoly)); validPolys[p] {
poly = p
}
years := in.RequiredYears
if years < 0 {
years = 0
}
var res AdoptForecastResult
err = s.db.RunInTenantTx(ctx, func(ctx context.Context, tx pgx.Tx) error {
q := dbgen.New(tx)
var kind, title, agency, popState, popCity string
rerr := tx.QueryRow(ctx, `SELECT record_kind, title, agency, COALESCE(pop_state,''), COALESCE(pop_city,'')
FROM opportunity_records WHERE id = $1`, recordID).Scan(&kind, &title, &agency, &popState, &popCity)
if errors.Is(rerr, pgx.ErrNoRows) {
return ErrForecastNotFound
}
if rerr != nil {
return rerr
}
if kind != "forecast" {
return ErrNotAForecast
}
reqTitle := strings.TrimSpace(title)
if reqTitle == "" {
reqTitle = "Adopted forecast requirement"
}
loc := strings.TrimSpace(strings.TrimSpace(popCity) + " " + strings.TrimSpace(popState))
row, cerr := q.CreateRequirement(ctx, dbgen.CreateRequirementParams{
OrganizationID: orgID,
OpportunityID: nil,
Title: reqTitle,
CustomerAgency: strNonEmpty(agency),
RequiredLevel: level,
RequiredPoly: poly,
RequiredYears: int32(years),
WorkLocation: strNonEmpty(loc),
RemoteAllowed: false,
KeyPersonnel: in.KeyPersonnel,
})
if cerr != nil {
return cerr
}
res.RequirementID = row.ID.String()
res.Title = reqTitle
for _, name := range in.Skills {
name = strings.TrimSpace(name)
if name == "" {
continue
}
sk, serr := q.UpsertSkill(ctx, dbgen.UpsertSkillParams{Name: name})
if serr != nil {
return serr
}
if aerr := q.AddRequiredSkill(ctx, dbgen.AddRequiredSkillParams{
OrganizationID: orgID, RequirementID: row.ID, SkillID: sk.ID, Mandatory: true,
}); aerr != nil {
return aerr
}
}
if s.audit != nil {
nv, _ := json.Marshal(map[string]string{"source": "forecast", "forecast_record_id": recordID})
if aerr := s.audit.OnTx(ctx, tx, audit.Event{
Action: "requirement.adopted_from_forecast", ActorUserID: actorPtr(actor.UserID),
EntityType: "requirement", EntityID: row.ID.String(), NewValues: nv,
}); aerr != nil {
return aerr
}
}
return nil
})
return res, err
}
func strNonEmpty(s string) *string {
s = strings.TrimSpace(s)
if s == "" {
return nil
}
return &s
}
func actorPtr(s string) *uuid.UUID {
id, err := uuid.Parse(s)
if err != nil {
return nil
}
return &id
}