Skip to content

Commit

Permalink
Merge pull request #5 from v8platform/MDOTypeRefList_func
Browse files Browse the repository at this point in the history
добавил новые методы
  • Loading branch information
khorevaa authored May 13, 2021
2 parents ab071b2 + 6584446 commit 1473e1f
Show file tree
Hide file tree
Showing 9 changed files with 302 additions and 8 deletions.
64 changes: 64 additions & 0 deletions ChartOfCharacteristicType.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package mdclasses

import "github.com/v8platform/mdclasses/encoding/xml"

type Predefined struct {
Items []struct {
ID string `xml:"id,attr"`
Name string `xml:"name"`
Description string `xml:"description"`
Code string `xml:"code"`
Type struct {
Types []string `xml:"types"`
} `xml:"type"`
} `xml:"items"`
}

type ChartOfCharacteristicType struct {
XMLName xml.Name `xml:"ChartOfCharacteristicTypes"`
Xsi string `xml:"xsi,attr"`
Core string `xml:"core,attr"`
Mdclass string `xml:"mdclass,attr"`
Uuid string `xml:"uuid,attr"`
ProducedTypes MDOProducedTypes `xml:"producedTypes"`
Name string `xml:"name"`
Synonym ObjectKeyValueType `xml:"synonym"`
UseStandardCommands string `xml:"useStandardCommands"`
InputByString []string `xml:"inputByString"`
FullTextSearchOnInputByString string `xml:"fullTextSearchOnInputByString"`
StandardAttributes []StandardAttribute `xml:"standardAttributes"`
Characteristics []struct {
CharacteristicTypes string `xml:"characteristicTypes"`
KeyField string `xml:"keyField"`
TypesFilterField string `xml:"typesFilterField"`
TypesFilterValue AttributeTypedValue `xml:"typesFilterValue"`
CharacteristicValues string `xml:"characteristicValues"`
ObjectField string `xml:"objectField"`
TypeField string `xml:"typeField"`
ValueField string `xml:"valueField"`
} `xml:"characteristics"`
CreateOnInput string `xml:"createOnInput"`
Help Help `xml:"help"`
FullTextSearch string `xml:"fullTextSearch"`
Type struct {
Types []string `xml:"types"`
} `xml:"type"`
Hierarchical string `xml:"hierarchical"`
FoldersOnTop string `xml:"foldersOnTop"`
CodeLength string `xml:"codeLength"`
DescriptionLength string `xml:"descriptionLength"`
CheckUnique string `xml:"checkUnique"`
Autonumbering string `xml:"autonumbering"`
DefaultPresentation string `xml:"defaultPresentation"`
Predefined Predefined `xml:"predefined"`
EditType string `xml:"editType"`
ChoiceMode string `xml:"choiceMode"`
ChoiceHistoryOnInput string `xml:"choiceHistoryOnInput"`
DefaultObjectForm string `xml:"defaultObjectForm"`
DefaultFolderForm string `xml:"defaultFolderForm"`
DefaultListForm string `xml:"defaultListForm"`
DefaultChoiceForm string `xml:"defaultChoiceForm"`
Attributes []Attribute `xml:"attributes"`
TabularSections TabularSection `xml:"tabularSections"`
Forms []Form `xml:"forms"`
}
84 changes: 84 additions & 0 deletions InformationRegister.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package mdclasses

import "github.com/v8platform/mdclasses/encoding/xml"

type ProducedTypes struct {
SelectionType ObjectTypeRef `xml:"selectionType"`
ListType ObjectTypeRef `xml:"listType"`
ManagerType ObjectTypeRef `xml:"managerType"`
RecordSetType ObjectTypeRef `xml:"recordSetType"`
RecordKeyType ObjectTypeRef `xml:"recordKeyType"`
RecordType ObjectTypeRef `xml:"recordType"`
RecordManagerType ObjectTypeRef `xml:"recordManagerType"`
}

type Resource struct {
Uuid string `xml:"uuid,attr"`
Name string `xml:"name"`
Synonym AttributeTypedValue `xml:"synonym"`
Type struct {
Types []string `xml:"types"`
} `xml:"type"`
ToolTip AttributeTypedValue `xml:"toolTip"`
MinValue struct {
Type string `xml:"type,attr"`
} `xml:"minValue"`
MaxValue struct {
Type string `xml:"type,attr"`
} `xml:"maxValue"`
FillChecking string `xml:"fillChecking"`
ChoiceParameters struct {
Name string `xml:"name"`
Value AttributeTypedValue `xml:"value"`
} `xml:"choiceParameters"`
FullTextSearch string `xml:"fullTextSearch"`
DataHistory string `xml:"dataHistory"`
FillFromFillingValue string `xml:"fillFromFillingValue"`
FillValue AttributeTypedValue `xml:"fillValue"`
}

type Dimension struct {
Uuid string `xml:"uuid,attr"`
Name string `xml:"name"`
Synonym ObjectKeyValueType `xml:"synonym"`
Type struct {
Types string `xml:"types"`
} `xml:"type"`
ToolTip ObjectKeyValueType `xml:"toolTip"`
MinValue struct {
Type string `xml:"type,attr"`
} `xml:"minValue"`
MaxValue struct {
Type string `xml:"type,attr"`
} `xml:"maxValue"`
FullTextSearch string `xml:"fullTextSearch"`
DataHistory string `xml:"dataHistory"`
FillFromFillingValue string `xml:"fillFromFillingValue"`
FillValue AttributeTypedValue `xml:"fillValue"`
Master string `xml:"master"`
MainFilter string `xml:"mainFilter"`
}

type InformationRegister struct {
XMLName xml.Name `xml:"InformationRegister"`
Xsi string `xml:"xsi,attr"`
Core string `xml:"core,attr"`
Mdclass string `xml:"mdclass,attr"`
Uuid string `xml:"uuid,attr"`
ProducedTypes ProducedTypes `xml:"producedTypes"`
Name string `xml:"name"`
Synonym ObjectKeyValueType `xml:"synonym"`
UseStandardCommands string `xml:"useStandardCommands"`
DefaultRecordForm string `xml:"defaultRecordForm"`
DefaultListForm string `xml:"defaultListForm"`
StandardAttributes []StandardAttribute `xml:"standardAttributes"`
InformationRegisterPeriodicity string `xml:"informationRegisterPeriodicity"`
MainFilterOnPeriod string `xml:"mainFilterOnPeriod"`
Help Help `xml:"help"`
RecordPresentation ObjectKeyValueType `xml:"recordPresentation"`
ListPresentation ObjectKeyValueType `xml:"listPresentation"`
Explanation ObjectKeyValueType `xml:"explanation"`
Resources []Resource `xml:"resources"`
Dimensions []Dimension `xml:"dimensions"`
Forms []Form `xml:"forms"`
}
23 changes: 23 additions & 0 deletions Report.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package mdclasses

import "github.com/v8platform/mdclasses/encoding/xml"

type Report struct {
XMLName xml.Name `xml:"Report"`
Mdclass string `xml:"mdclass,attr"`
Uuid string `xml:"uuid,attr"`
ProducedTypes MDOProducedTypes `xml:"producedTypes"`
Name string `xml:"name"`
Synonym ObjectKeyValueType `xml:"synonym"`
DefaultForm string `xml:"defaultForm"`
MainDataCompositionSchema string `xml:"mainDataCompositionSchema"`
DefaultSettingsForm string `xml:"defaultSettingsForm"`
DefaultVariantForm string `xml:"defaultVariantForm"`
Help Help `xml:"help"`
Templates struct {
Uuid string `xml:"uuid,attr"`
Name string `xml:"name"`
Synonym ObjectKeyValueType `xml:"synonym"`
TemplateType string `xml:"templateType"`
} `xml:"templates"`
}
1 change: 1 addition & 0 deletions catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Catalog struct {
FullTextSearchOnInputByString string `xml:"fullTextSearchOnInputByString"`
StandardAttributes []StandardAttribute `xml:"standardAttributes"`
CreateOnInput string `xml:"createOnInput"`
Help Help `xml:"help"`
DataLockControlMode string `xml:"dataLockControlMode"`
FullTextSearch string `xml:"fullTextSearch"`
ObjectPresentation ObjectKeyValueType `xml:"objectPresentation"`
Expand Down
6 changes: 6 additions & 0 deletions commonTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,9 @@ type MDOProducedTypes struct {
ListType ObjectTypeRef `xml:"listType"`
ManagerType ObjectTypeRef `xml:"managerType"`
}

type Help struct {
Pages struct {
Lang string `xml:"lang"`
} `xml:"pages"`
}
30 changes: 23 additions & 7 deletions configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Configuration struct {
MDOBaseType

XMLName xml.Name `xml:"mdclass Configuration"`
Synonym ObjectKeyValueType `xml:"synonym"`
Synonym []ObjectKeyValueType `xml:"synonym"`
ContainedObjects []ContainedObject `xml:"containedObjects,allowempty"`
ConfigurationProperties

Expand Down Expand Up @@ -66,11 +66,11 @@ type Configuration struct {
// DocumentNumerators []MDOTypeRef `xml:"documentNumerators"`
// DocumentJournals []MDOTypeRef `xml:"documentJournals"`
// Enums []MDOTypeRef `xml:"enums"`
// Reports []MDOTypeRef `xml:"reports"`
Reports []*Report `xml:"-"`
// DataProcessors []MDOTypeRef `xml:"dataProcessors"`
// InformationRegisters []MDOTypeRef `xml:"informationRegisters"`
InformationRegisters []*InformationRegister `xml:"-"`
// AccumulationRegisters []MDOTypeRef `xml:"accumulationRegisters"`
// ChartsOfCharacteristicTypes []MDOTypeRef `xml:"chartsOfCharacteristicTypes"`
ChartsOfCharacteristicTypes []*ChartOfCharacteristicType `xml:"-"`
// BusinessProcesses []MDOTypeRef `xml:"businessProcesses"`
// Tasks []MDOTypeRef `xml:"tasks"`
ConfigurationChildObjects
Expand All @@ -94,24 +94,24 @@ type ConfigurationProperties struct {
DefaultRunMode string `xml:"defaultRunMode,omitempty"`
UsePurposes []string `xml:"usePurposes,omitempty"`
ScriptVariant string `xml:"scriptVariant,omitempty"`
DefaultRoles MDOTypeRefList `xml:"defaultRoles,omitempty"`
Vendor string `xml:"vendor,omitempty"`
Version string `xml:"version,omitempty"`
UpdateCatalogAddress string `xml:"updateCatalogAddress,omitempty"`
UseManagedFormInOrdinaryApplication string `xml:"useManagedFormInOrdinaryApplication,omitempty"`
UseOrdinaryFormInManagedApplication string `xml:"useOrdinaryFormInManagedApplication,omitempty"`
DefaultRoles MDOTypeRefList `xml:"defaultRoles,omitempty"`
ReportsVariantsStorage string `xml:"reportsVariantsStorage,omitempty"`
DefaultReportForm MDOTypeRef `xml:"defaultReportForm,omitempty"`
DefaultReportVariantForm MDOTypeRef `xml:"defaultReportVariantForm,omitempty"`
DefaultReportSettingsForm MDOTypeRef `xml:"defaultReportSettingsForm,omitempty"`
DefaultSearchForm MDOTypeRef `xml:"defaultSearchForm,omitempty"`
UsedMobileApplicationFunctionalities *MobileApplicationFunctionalities `xml:"usedMobileApplicationFunctionalities,omitempty"`
RequiredMobileApplicationPermissions []string `xml:"requiredMobileApplicationPermissions,omitempty"`
MainSectionPicture string `xml:"mainSectionPicture,omitempty"`
MainSectionPicture string `xml:"mainSectionPicture,allowempty"`
DefaultLanguage MDOTypeRef `xml:"defaultLanguage,omitempty"`
BriefInformation ObjectKeyValueType `xml:"briefInformation,omitempty"`
DetailedInformation ObjectKeyValueType `xml:"detailedInformation,omitempty"`
Splash string `xml:"splash,omitempty"`
Splash string `xml:"splash,omitempty,allowempty"`
Copyright ObjectKeyValueType `xml:"copyright,omitempty"`
VendorInformationAddress ObjectKeyValueType `xml:"vendorInformationAddress,omitempty"`
ConfigurationInformationAddress ObjectKeyValueType `xml:"configurationInformationAddress,omitempty"`
Expand Down Expand Up @@ -199,10 +199,26 @@ func (conf *Configuration) Unpack(cfg UnpackConfig) error {
return err
}

err = conf.ConfigurationChildObjects.Reports.Unpack(cfg, &conf.Reports)
if err != nil {
return err
}

err = conf.ConfigurationChildObjects.InformationRegisters.Unpack(cfg, &conf.InformationRegisters)
if err != nil {
return err
}

err = conf.ConfigurationChildObjects.ChartsOfCharacteristicTypes.Unpack(cfg, &conf.ChartsOfCharacteristicTypes)
if err != nil {
return err
}

err = conf.ConfigurationChildObjects.CommonModules.Unpack(cfg, &conf.CommonModules)
if err != nil {
return err
}

// for _, mdoTypeRef := range conf.ConfigurationChildObjects.Subsystems {
//
// subsystem := Subsystem{}
Expand Down
38 changes: 38 additions & 0 deletions mdoTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ func (m MDOType) Group() string {
return "CommonModules"
case FORM:
return "Forms"
case REPORT:
return "Reports"
case INFORMATION_REGISTER:
return "InformationRegisters"
case CHART_OF_CHARACTERISTIC_TYPES:
return "ChartsOfCharacteristicTypes"
//case COMMON_MODULE:
// return "CommonModules"
//case COMMON_MODULE:
Expand Down Expand Up @@ -193,6 +199,38 @@ func (e MDOTypeRefList) Unpack(cfg UnpackConfig, value interface{}) error {
return nil
}

// Проверяет существование объекта.
func (e MDOTypeRefList) Exist(typeRef MDOTypeRef) bool {
return e.GetIndex(typeRef) > -1
}

// Возвращает индекс элемента в массиве
func (e MDOTypeRefList) GetIndex(typeRef MDOTypeRef) int {
for i, t := range e {
if t.mdoType == typeRef.mdoType && t.ref == typeRef.ref {
return i
}
}
return -1
}

// Удаляет элемент по индексу
func (e MDOTypeRefList) Delete(index int) ([]MDOTypeRef, error) {
if len(e) > index {
return removeElement(e, index), nil
}
return e, errors.New(fmt.Sprintf("Error delete object from index %v", index))
}

func removeElement(list []MDOTypeRef, i int) []MDOTypeRef {
if i < len(list)-1 {
list = append(list[:i], list[i+1:]...)
} else {
list = list[:i]
}
return list
}

func reflectAlloc(typ reflect.Type) reflect.Value {
if typ.Kind() == reflect.Ptr {
return reflect.New(typ.Elem())
Expand Down
62 changes: 62 additions & 0 deletions mdoTypes_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mdclasses

import (
"github.com/stretchr/testify/require"
"reflect"
"testing"
)
Expand Down Expand Up @@ -55,3 +56,64 @@ func TestNewMDOTypeRefFromString(t *testing.T) {
})
}
}

func TestMDOTypeRefExist(t *testing.T) {
got, err := UnpackConfiguration("tests/metadata/edt/src")
if err != nil {
t.Errorf("UnpackConfiguration() error = %v", err)
return
}
subsystem := MDOTypeRef{
mdoType: "Subsystem",
ref: "ПерваяПодсистема",
parent: nil,
raw: "Subsystem.ПерваяПодсистема",
}
require.True(t, got.ConfigurationChildObjects.Subsystems.Exist(subsystem))
}

func TestMDOTypeRefGetIndex(t *testing.T) {
got, err := UnpackConfiguration("tests/metadata/edt/src")
if err != nil {
t.Errorf("UnpackConfiguration() error = %v", err)
return
}
mdo := MDOTypeRef{
mdoType: "Subsystem",
ref: "ВтораяПодсистема",
parent: nil,
raw: "",
}
index := got.ConfigurationChildObjects.Subsystems.GetIndex(mdo)
if index < 0 {
t.Errorf("Ошибка поиска дочернего объекта = %v", err)
}
require.True(t, index == 1)
}

func TestMDOTypeRefDelete(t *testing.T) {
got, err := UnpackConfiguration("tests/metadata/edt/src")
if err != nil {
t.Errorf("UnpackConfiguration() error = %v", err)
return
}
ref := got.ConfigurationChildObjects.Subsystems
newChild, err := ref.Delete(1)
if err != nil {
t.Errorf("Ошибка поиска дочернего объекта = %v", err)
}
got.ConfigurationChildObjects.Subsystems = newChild
require.True(t, len(got.ConfigurationChildObjects.Subsystems) == 1)
}

func TestMDOTypeRefCreate(t *testing.T) {
got, err := UnpackConfiguration("tests/metadata/edt/src")
if err != nil {
t.Errorf("UnpackConfiguration() error = %v", err)
return
}

MDOTypeRef := NewMDOTypeRefFromString("Subsystem.NewSubsystem")
got.ConfigurationChildObjects.Subsystems = append(got.ConfigurationChildObjects.Subsystems, MDOTypeRef)
require.True(t, true)
}
Loading

0 comments on commit 1473e1f

Please sign in to comment.