2022-04-27 13:30:43 +02:00
package abaputils
import (
"reflect"
"github.com/SAP/jenkins-library/pkg/log"
)
2022-11-08 09:47:38 +02:00
// ObjectSet in form of packages and software components to be checked
2022-04-27 13:30:43 +02:00
type ObjectSet struct {
PackageNames [ ] Package ` json:"packages,omitempty" `
SoftwareComponents [ ] SoftwareComponents ` json:"softwarecomponents,omitempty" `
2022-04-29 16:50:57 +02:00
PackageTrees [ ] PackageTree ` json:"packagetrees,omitempty" `
2022-04-27 13:30:43 +02:00
Type string ` json:"type,omitempty" `
MultiPropertySet MultiPropertySet ` json:"multipropertyset,omitempty" `
Set [ ] Set ` json:"set,omitempty" `
}
2022-11-08 09:47:38 +02:00
// MultiPropertySet that can possibly contain any subsets/object of the OSL
2022-04-27 13:30:43 +02:00
type MultiPropertySet struct {
Type string ` json:"type,omitempty" `
PackageNames [ ] Package ` json:"packages,omitempty" `
PackageTrees [ ] PackageTree ` json:"packagetrees,omitempty" `
ObjectTypeGroups [ ] ObjectTypeGroup ` json:"objecttypegroups,omitempty" `
ObjectTypes [ ] ObjectType ` json:"objecttypes,omitempty" `
Owners [ ] Owner ` json:"owners,omitempty" `
ReleaseStates [ ] ReleaseState ` json:"releasestates,omitempty" `
Versions [ ] Version ` json:"versions,omitempty" `
ApplicationComponents [ ] ApplicationComponent ` json:"applicationcomponents,omitempty" `
SoftwareComponents [ ] SoftwareComponents ` json:"softwarecomponents,omitempty" `
TransportLayers [ ] TransportLayer ` json:"transportlayers,omitempty" `
Languages [ ] Language ` json:"languages,omitempty" `
SourceSystems [ ] SourceSystem ` json:"sourcesystems,omitempty" `
}
2022-11-08 09:47:38 +02:00
// Set
2022-04-27 13:30:43 +02:00
type Set struct {
Type string ` json:"type,omitempty" `
Set [ ] Set ` json:"set,omitempty" `
PackageSet [ ] PackageSet ` json:"package,omitempty" `
FlatObjectSet [ ] FlatObjectSet ` json:"object,omitempty" `
ComponentSet [ ] ComponentSet ` json:"component,omitempty" `
TransportSet [ ] TransportSet ` json:"transport,omitempty" `
ObjectTypeSet [ ] ObjectTypeSet ` json:"objecttype,omitempty" `
}
2022-11-08 09:47:38 +02:00
// PackageSet in form of packages to be checked
2022-04-27 13:30:43 +02:00
type PackageSet struct {
Name string ` json:"name,omitempty" `
IncludeSubpackages * bool ` json:"includesubpackages,omitempty" `
}
2022-11-08 09:47:38 +02:00
// FlatObjectSet
2022-04-27 13:30:43 +02:00
type FlatObjectSet struct {
Name string ` json:"name,omitempty" `
Type string ` json:"type,omitempty" `
}
2022-11-08 09:47:38 +02:00
// ComponentSet in form of software components to be checked
2022-04-27 13:30:43 +02:00
type ComponentSet struct {
Name string ` json:"name,omitempty" `
}
2022-11-08 09:47:38 +02:00
// TransportSet in form of transports to be checked
2022-04-27 13:30:43 +02:00
type TransportSet struct {
Number string ` json:"number,omitempty" `
}
2022-11-08 09:47:38 +02:00
// ObjectTypeSet
2022-04-27 13:30:43 +02:00
type ObjectTypeSet struct {
Name string ` json:"name,omitempty" `
}
2022-11-08 09:47:38 +02:00
// Package for MPS
2022-04-27 13:30:43 +02:00
type Package struct {
Name string ` json:"name,omitempty" `
}
2022-11-08 09:47:38 +02:00
// Packagetree for MPS
2022-04-27 13:30:43 +02:00
type PackageTree struct {
Name string ` json:"name,omitempty" `
}
2022-11-08 09:47:38 +02:00
// ObjectTypeGroup
2022-04-27 13:30:43 +02:00
type ObjectTypeGroup struct {
Name string ` json:"name,omitempty" `
}
2022-11-08 09:47:38 +02:00
// ObjectType
2022-04-27 13:30:43 +02:00
type ObjectType struct {
Name string ` json:"name,omitempty" `
}
2022-11-08 09:47:38 +02:00
// Owner
2022-04-27 13:30:43 +02:00
type Owner struct {
Name string ` json:"name,omitempty" `
}
2022-11-08 09:47:38 +02:00
// ReleaseState
2022-04-27 13:30:43 +02:00
type ReleaseState struct {
Value string ` json:"value,omitempty" `
}
2022-11-08 09:47:38 +02:00
// Version
2022-04-27 13:30:43 +02:00
type Version struct {
Value string ` json:"value,omitempty" `
}
2022-11-08 09:47:38 +02:00
// ApplicationComponent
2022-04-27 13:30:43 +02:00
type ApplicationComponent struct {
Name string ` json:"name,omitempty" `
}
2022-11-08 09:47:38 +02:00
// SoftwareComponents
2022-04-27 13:30:43 +02:00
type SoftwareComponents struct {
Name string ` json:"name,omitempty" `
}
2022-11-08 09:47:38 +02:00
// TransportLayer
2022-04-27 13:30:43 +02:00
type TransportLayer struct {
Name string ` json:"name,omitempty" `
}
2022-11-08 09:47:38 +02:00
// Language
2022-04-27 13:30:43 +02:00
type Language struct {
Value string ` json:"value,omitempty" `
}
2022-11-08 09:47:38 +02:00
// SourceSystem
2022-04-27 13:30:43 +02:00
type SourceSystem struct {
Name string ` json:"name,omitempty" `
}
func BuildOSLString ( OSLConfig ObjectSet ) ( objectSetString string ) {
//Build ObjectSets
s := OSLConfig
if s . Type == "" {
s . Type = "multiPropertySet"
}
switch s . Type {
case "multiPropertySet" :
objectSetString += ` <osl:objectSet xsi:type=" ` + s . Type + ` " xmlns:osl="http://www.sap.com/api/osl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> `
if ! ( reflect . DeepEqual ( s . PackageNames , Package { } ) ) || ! ( reflect . DeepEqual ( s . SoftwareComponents , SoftwareComponents { } ) ) {
//To ensure Scomps and packages can be assigned on this level
mps := MultiPropertySet {
PackageNames : s . PackageNames ,
SoftwareComponents : s . SoftwareComponents ,
}
objectSetString += writeObjectSetProperties ( mps )
}
objectSetString += writeObjectSetProperties ( s . MultiPropertySet )
if ! ( reflect . DeepEqual ( s . MultiPropertySet , MultiPropertySet { } ) ) {
log . Entry ( ) . Info ( "Wrong configuration has been detected: MultiPropertySet has been used. Please note that there is no official documentation for this usage. Please check the step documentation for more information" )
}
for _ , t := range s . Set {
log . Entry ( ) . Infof ( "Wrong configuration has been detected: %s has been used. This is currently not supported and this set will not be included in this run. Please check the step documentation for more information" , t . Type )
}
objectSetString += ` </osl:objectSet> `
default :
log . Entry ( ) . Infof ( "Wrong configuration has been detected: %s has been used. This is currently not supported and this set will not be included in this run. Please check the step documentation for more information" , s . Type )
}
return objectSetString
}
func writeObjectSetProperties ( set MultiPropertySet ) ( objectSetString string ) {
for _ , packages := range set . PackageNames {
objectSetString += ` <osl:package name=" ` + packages . Name + ` "/> `
}
for _ , packagetrees := range set . PackageTrees {
objectSetString += ` <osl:package name=" ` + packagetrees . Name + ` " includeSubpackages="true"/> `
}
for _ , objectTypeGroup := range set . ObjectTypeGroups {
objectSetString += ` <osl:objectTypeGroup name=" ` + objectTypeGroup . Name + ` "/> `
}
for _ , objectType := range set . ObjectTypes {
objectSetString += ` <osl:objectType name=" ` + objectType . Name + ` "/> `
}
for _ , owner := range set . Owners {
objectSetString += ` <osl:owner name=" ` + owner . Name + ` "/> `
}
for _ , releaseState := range set . ReleaseStates {
objectSetString += ` <osl:releaseState value=" ` + releaseState . Value + ` "/> `
}
for _ , version := range set . Versions {
objectSetString += ` <osl:version value=" ` + version . Value + ` "/> `
}
for _ , applicationComponent := range set . ApplicationComponents {
objectSetString += ` <osl:applicationComponent name=" ` + applicationComponent . Name + ` "/> `
}
for _ , component := range set . SoftwareComponents {
objectSetString += ` <osl:softwareComponent name=" ` + component . Name + ` "/> `
}
for _ , transportLayer := range set . TransportLayers {
objectSetString += ` <osl:transportLayer name=" ` + transportLayer . Name + ` "/> `
}
for _ , language := range set . Languages {
objectSetString += ` <osl:language value=" ` + language . Value + ` "/> `
}
for _ , sourceSystem := range set . SourceSystems {
objectSetString += ` <osl:sourceSystem name=" ` + sourceSystem . Name + ` "/> `
}
return objectSetString
}