github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/model/package.go (about)

     1  package model
     2  
     3  import (
     4  	"encoding/json"
     5  	"strconv"
     6  
     7  	"github.com/kyma-incubator/compass/components/director/pkg/resource"
     8  
     9  	"github.com/kyma-incubator/compass/components/director/pkg/str"
    10  )
    11  
    12  // Package missing godoc
    13  type Package struct {
    14  	ID                           string
    15  	ApplicationID                *string
    16  	ApplicationTemplateVersionID *string
    17  	OrdID                        string
    18  	Vendor                       *string
    19  	Title                        string
    20  	ShortDescription             string
    21  	Description                  string
    22  	Version                      string
    23  	PackageLinks                 json.RawMessage
    24  	Links                        json.RawMessage
    25  	LicenseType                  *string
    26  	SupportInfo                  *string
    27  	Tags                         json.RawMessage
    28  	Countries                    json.RawMessage
    29  	Labels                       json.RawMessage
    30  	PolicyLevel                  string
    31  	CustomPolicyLevel            *string
    32  	PartOfProducts               json.RawMessage
    33  	LineOfBusiness               json.RawMessage
    34  	Industry                     json.RawMessage
    35  	ResourceHash                 *string
    36  	DocumentationLabels          json.RawMessage
    37  }
    38  
    39  // PackageInput missing godoc
    40  type PackageInput struct {
    41  	OrdID               string          `json:"ordId"`
    42  	Vendor              *string         `json:"vendor"`
    43  	Title               string          `json:"title"`
    44  	ShortDescription    string          `json:"shortDescription"`
    45  	Description         string          `json:"description"`
    46  	Version             string          `json:"version" hash:"ignore"`
    47  	PackageLinks        json.RawMessage `json:"packageLinks"`
    48  	Links               json.RawMessage `json:"links"`
    49  	LicenseType         *string         `json:"licenseType"`
    50  	SupportInfo         *string         `json:"supportInfo"`
    51  	Tags                json.RawMessage `json:"tags"`
    52  	Countries           json.RawMessage `json:"countries"`
    53  	Labels              json.RawMessage `json:"labels"`
    54  	PolicyLevel         string          `json:"policyLevel"`
    55  	CustomPolicyLevel   *string         `json:"customPolicyLevel"`
    56  	PartOfProducts      json.RawMessage `json:"partOfProducts"`
    57  	LineOfBusiness      json.RawMessage `json:"lineOfBusiness"`
    58  	Industry            json.RawMessage `json:"industry"`
    59  	DocumentationLabels json.RawMessage `json:"documentationLabels"`
    60  }
    61  
    62  // ToPackage missing godoc
    63  func (i *PackageInput) ToPackage(id string, resourceType resource.Type, resourceID string, pkgHash uint64) *Package {
    64  	if i == nil {
    65  		return nil
    66  	}
    67  
    68  	var hash *string
    69  	if pkgHash != 0 {
    70  		hash = str.Ptr(strconv.FormatUint(pkgHash, 10))
    71  	}
    72  
    73  	pkg := &Package{
    74  		ID:                  id,
    75  		OrdID:               i.OrdID,
    76  		Vendor:              i.Vendor,
    77  		Title:               i.Title,
    78  		ShortDescription:    i.ShortDescription,
    79  		Description:         i.Description,
    80  		Version:             i.Version,
    81  		PackageLinks:        i.PackageLinks,
    82  		Links:               i.Links,
    83  		LicenseType:         i.LicenseType,
    84  		SupportInfo:         i.SupportInfo,
    85  		Tags:                i.Tags,
    86  		Countries:           i.Countries,
    87  		Labels:              i.Labels,
    88  		PolicyLevel:         i.PolicyLevel,
    89  		CustomPolicyLevel:   i.CustomPolicyLevel,
    90  		PartOfProducts:      i.PartOfProducts,
    91  		LineOfBusiness:      i.LineOfBusiness,
    92  		Industry:            i.Industry,
    93  		DocumentationLabels: i.DocumentationLabels,
    94  		ResourceHash:        hash,
    95  	}
    96  
    97  	if resourceType.IsTenantIgnorable() {
    98  		pkg.ApplicationTemplateVersionID = &resourceID
    99  	} else if resourceType == resource.Application {
   100  		pkg.ApplicationID = &resourceID
   101  	}
   102  
   103  	return pkg
   104  }
   105  
   106  // SetFromUpdateInput missing godoc
   107  func (p *Package) SetFromUpdateInput(update PackageInput, pkgHash uint64) {
   108  	var hash *string
   109  	if pkgHash != 0 {
   110  		hash = str.Ptr(strconv.FormatUint(pkgHash, 10))
   111  	}
   112  
   113  	p.Vendor = update.Vendor
   114  	p.Title = update.Title
   115  	p.ShortDescription = update.ShortDescription
   116  	p.Description = update.Description
   117  	p.Version = update.Version
   118  	p.PackageLinks = update.PackageLinks
   119  	p.Links = update.Links
   120  	p.LicenseType = update.LicenseType
   121  	p.SupportInfo = update.SupportInfo
   122  	p.Tags = update.Tags
   123  	p.Countries = update.Countries
   124  	p.Labels = update.Labels
   125  	p.PolicyLevel = update.PolicyLevel
   126  	p.CustomPolicyLevel = update.CustomPolicyLevel
   127  	p.PartOfProducts = update.PartOfProducts
   128  	p.LineOfBusiness = update.LineOfBusiness
   129  	p.Industry = update.Industry
   130  	p.DocumentationLabels = update.DocumentationLabels
   131  	p.ResourceHash = hash
   132  }