From 55a4f3b353a2a094a043a32beacbd6567f45a6ff Mon Sep 17 00:00:00 2001 From: Pham Anh Quoc Phien Date: Thu, 1 Nov 2018 14:28:34 +0700 Subject: [PATCH 1/8] 0.9.2v_issues_fix: Column shift when exporting files in SJIS --- export.go | 6 ++++-- main.go | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/export.go b/export.go index 9cfca2f..29c2f1c 100644 --- a/export.go +++ b/export.go @@ -268,7 +268,8 @@ func writeCsv(app *kintone.App, _writer io.Writer) error { return err } } - fmt.Fprint(writer, "\""+escapeCol(toString(subField, "\n"))+"\"") + subFieldEncoding, _ := transformStringFromEncoding(toString(subField, "\n")) + fmt.Fprint(writer, "\""+escapeCol(subFieldEncoding)+"\"") } } else { field := record.Fields[f.Code] @@ -280,7 +281,8 @@ func writeCsv(app *kintone.App, _writer io.Writer) error { return err } } - fmt.Fprint(writer, "\""+escapeCol(toString(field, "\n"))+"\"") + fieldEncoding, _ := transformStringFromEncoding(toString(field, "\n")) + fmt.Fprint(writer, "\""+escapeCol(fieldEncoding)+"\"") } } k++ diff --git a/main.go b/main.go index 4d7a844..533a7d9 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,8 @@ package main import ( "fmt" + "io" + "io/ioutil" "log" "os" "strings" @@ -11,6 +13,7 @@ import ( "golang.org/x/text/encoding" "golang.org/x/text/encoding/japanese" "golang.org/x/text/encoding/unicode" + "golang.org/x/text/transform" flags "github.com/jessevdk/go-flags" ) @@ -269,3 +272,20 @@ func importDataFromFile(app *kintone.App) error { } return err } + +func transformStringFromEncoding(str string) (string, error) { + transformString := str + encoding := getEncoding() + if encoding != nil { + return transformEncoding(strings.NewReader(str), encoding.NewEncoder()) + } + return transformString, nil +} + +func transformEncoding(rawReader io.Reader, trans transform.Transformer) (string, error) { + ret, err := ioutil.ReadAll(transform.NewReader(rawReader, trans)) + if err == nil { + return string(ret), nil + } + return string(ret), err +} From a684fbbd328d4ea914f61bc0ba35280a9c09ad48 Mon Sep 17 00:00:00 2001 From: Pham Anh Quoc Phien Date: Tue, 27 Nov 2018 17:12:05 +0700 Subject: [PATCH 2/8] 0.9.2v_issues: Fix JSON Value --- export.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/export.go b/export.go index 29c2f1c..94284db 100644 --- a/export.go +++ b/export.go @@ -80,8 +80,11 @@ func writeJSON(app *kintone.App, _writer io.Writer) error { } } + subTableValue.Fields[fieldCodeInSubTable] = transformEncodingJSONValue(fieldValueInSubTable) } } + } else { + record.Fields[fieldCode] = transformEncodingJSONValue(fieldInfo) } } jsonArray, _ := record.MarshalJSON() @@ -97,6 +100,41 @@ func writeJSON(app *kintone.App, _writer io.Writer) error { return nil } +func transformEncodingJSONValue(fields interface{}) interface{} { + var fieldEncodingValues interface{} + switch fields.(type) { + case kintone.SingleLineTextField: + fieldStringValues, _ := transformStringFromEncoding(toString(fields, "\n")) + fieldEncodingValues = kintone.SingleLineTextField(fieldStringValues) + case kintone.MultiLineTextField: + fieldStringValues, _ := transformStringFromEncoding(toString(fields, "\n")) + fieldEncodingValues = kintone.MultiLineTextField(fieldStringValues) + case kintone.RichTextField: + fieldStringValues, _ := transformStringFromEncoding(toString(fields, "\n")) + fieldEncodingValues = kintone.RichTextField(fieldStringValues) + case kintone.SingleSelectField: + fieldStringValues, _ := transformStringFromEncoding(toString(fields, "\n")) + if fieldStringValues == "" { + fieldEncodingValues = kintone.SingleSelectField{Valid: false} + } else { + fieldEncodingValues = kintone.SingleSelectField{fieldStringValues, true} + } + case kintone.CheckBoxField: + fieldStringValues, _ := transformStringFromEncoding(toString(fields, "\n")) + fieldStringValuesArray := strings.Split(fieldStringValues, "\n") + fieldEncodingValues = kintone.CheckBoxField(fieldStringValuesArray) + case kintone.RadioButtonField: + fieldStringValues, _ := transformStringFromEncoding(toString(fields, "\n")) + fieldEncodingValues = kintone.RadioButtonField(fieldStringValues) + case kintone.MultiSelectField: + fieldStringValues, _ := transformStringFromEncoding(toString(fields, "\n")) + fieldStringValuesArray := strings.Split(fieldStringValues, "\n") + fieldEncodingValues = kintone.MultiSelectField(fieldStringValuesArray) + default: + fieldEncodingValues = fields + } + return fieldEncodingValues +} func makeColumns(fields map[string]*kintone.FieldInfo) Columns { columns := make([]*Column, 0) From 508f9dd7fda1c478133a53a704ed46ed5e687f25 Mon Sep 17 00:00:00 2001 From: Pham Anh Quoc Phien Date: Tue, 27 Nov 2018 17:16:23 +0700 Subject: [PATCH 3/8] 0.9.2v_issues: Refactor code --- export.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/export.go b/export.go index 94284db..d71f8bf 100644 --- a/export.go +++ b/export.go @@ -83,9 +83,9 @@ func writeJSON(app *kintone.App, _writer io.Writer) error { subTableValue.Fields[fieldCodeInSubTable] = transformEncodingJSONValue(fieldValueInSubTable) } } - } else { - record.Fields[fieldCode] = transformEncodingJSONValue(fieldInfo) } + record.Fields[fieldCode] = transformEncodingJSONValue(fieldInfo) + } jsonArray, _ := record.MarshalJSON() json := string(jsonArray) From c60c918a73b40712297a04bb011795f20aa2c247 Mon Sep 17 00:00:00 2001 From: Pham Anh Quoc Phien Date: Mon, 14 Jan 2019 16:29:20 +0700 Subject: [PATCH 4/8] Update README --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2ee870d..c15c1c3 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Getting the source code Install dependencies - $ export GOPATH=/path/to/your/Go/project/folder + $ cd ${GOPATH}/src/cli-kintone $ go get github.com/mattn/gom $ sudo ln -s $GOPATH/bin/gom /usr/local/bin/gom $ gom -production install @@ -30,6 +30,7 @@ Install dependencies build $ cd ${GOPATH}/src/cli-kintone + $ sudo mv vendor/ src $ gom build ## Downloads From 77322b01b6839870824edfea0e961c8fef337c52 Mon Sep 17 00:00:00 2001 From: Pham Anh Quoc Phien Date: Mon, 14 Jan 2019 17:08:05 +0700 Subject: [PATCH 5/8] Update selection field --- export.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/export.go b/export.go index d71f8bf..8b652e4 100644 --- a/export.go +++ b/export.go @@ -552,6 +552,8 @@ func toString(f interface{}, delimiter string) string { userField := f.(kintone.UserField) users := make([]string, 0, len(userField)) for _, user := range userField { + user.Code, _ = transformStringFromEncoding(user.Code) + user.Name, _ = transformStringFromEncoding(user.Name) users = append(users, user.Code) } return strings.Join(users, delimiter) @@ -559,6 +561,8 @@ func toString(f interface{}, delimiter string) string { organizationField := f.(kintone.OrganizationField) organizations := make([]string, 0, len(organizationField)) for _, organization := range organizationField { + organization.Code, _ = transformStringFromEncoding(organization.Code) + organization.Name, _ = transformStringFromEncoding(organization.Name) organizations = append(organizations, organization.Code) } return strings.Join(organizations, delimiter) @@ -566,6 +570,8 @@ func toString(f interface{}, delimiter string) string { groupField := f.(kintone.GroupField) groups := make([]string, 0, len(groupField)) for _, group := range groupField { + group.Code, _ = transformStringFromEncoding(group.Code) + group.Name, _ = transformStringFromEncoding(group.Name) groups = append(groups, group.Code) } return strings.Join(groups, delimiter) From d5f34c07c5c667b2cfa059c00b51c3eb042a67b4 Mon Sep 17 00:00:00 2001 From: Pham Anh Quoc Phien Date: Mon, 14 Jan 2019 19:22:14 +0700 Subject: [PATCH 6/8] Update fix json scope --- export.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/export.go b/export.go index 8b652e4..3338ccf 100644 --- a/export.go +++ b/export.go @@ -130,6 +130,33 @@ func transformEncodingJSONValue(fields interface{}) interface{} { fieldStringValues, _ := transformStringFromEncoding(toString(fields, "\n")) fieldStringValuesArray := strings.Split(fieldStringValues, "\n") fieldEncodingValues = kintone.MultiSelectField(fieldStringValuesArray) + case kintone.UserField: + var userList []kintone.User + userField := fields.(kintone.UserField) + for _, user := range userField { + user.Code, _ = transformStringFromEncoding(user.Code) + user.Name, _ = transformStringFromEncoding(user.Name) + userList = append(userList, user) + } + fieldEncodingValues = kintone.UserField(userList) + case kintone.OrganizationField: + var organizations []kintone.Organization + organizationField := fields.(kintone.OrganizationField) + for _, organization := range organizationField { + organization.Code, _ = transformStringFromEncoding(organization.Code) + organization.Name, _ = transformStringFromEncoding(organization.Name) + organizations = append(organizations, organization) + } + fieldEncodingValues = kintone.OrganizationField(organizations) + case kintone.GroupField: + var groups []kintone.Group + groupField := fields.(kintone.GroupField) + for _, group := range groupField { + group.Code, _ = transformStringFromEncoding(group.Code) + group.Name, _ = transformStringFromEncoding(group.Name) + groups = append(groups, group) + fieldEncodingValues = kintone.GroupField(groupField) + } default: fieldEncodingValues = fields } From c76e019e110c9f44a0963eb2ed1c20a3b4b3e372 Mon Sep 17 00:00:00 2001 From: Pham Anh Quoc Phien Date: Tue, 15 Jan 2019 15:25:36 +0700 Subject: [PATCH 7/8] Update fix Rich Text Editor --- export.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/export.go b/export.go index 3338ccf..ba3cc5e 100644 --- a/export.go +++ b/export.go @@ -155,8 +155,8 @@ func transformEncodingJSONValue(fields interface{}) interface{} { group.Code, _ = transformStringFromEncoding(group.Code) group.Name, _ = transformStringFromEncoding(group.Name) groups = append(groups, group) - fieldEncodingValues = kintone.GroupField(groupField) } + fieldEncodingValues = kintone.GroupField(groupField) default: fieldEncodingValues = fields } @@ -334,7 +334,9 @@ func writeCsv(app *kintone.App, _writer io.Writer) error { } } subFieldEncoding, _ := transformStringFromEncoding(toString(subField, "\n")) - fmt.Fprint(writer, "\""+escapeCol(subFieldEncoding)+"\"") + fmt.Fprint(writer, "\"") + fmt.Fprint(writer, escapeCol(subFieldEncoding)) + fmt.Fprint(writer, "\"") } } else { field := record.Fields[f.Code] @@ -347,7 +349,9 @@ func writeCsv(app *kintone.App, _writer io.Writer) error { } } fieldEncoding, _ := transformStringFromEncoding(toString(field, "\n")) - fmt.Fprint(writer, "\""+escapeCol(fieldEncoding)+"\"") + fmt.Fprint(writer, "\"") + fmt.Fprint(writer, escapeCol(fieldEncoding)) + fmt.Fprint(writer, "\"") } } k++ From ffa24cf6af26f5e55415c60d928a3dfab488a01f Mon Sep 17 00:00:00 2001 From: Pham Anh Quoc Phien Date: Fri, 18 Jan 2019 13:48:14 +0700 Subject: [PATCH 8/8] Update fix encoding for Creator & ModifierField --- export.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/export.go b/export.go index ba3cc5e..23e454c 100644 --- a/export.go +++ b/export.go @@ -157,6 +157,16 @@ func transformEncodingJSONValue(fields interface{}) interface{} { groups = append(groups, group) } fieldEncodingValues = kintone.GroupField(groupField) + case kintone.CreatorField: + creatorField := fields.(kintone.CreatorField) + creatorField.Code, _ = transformStringFromEncoding(creatorField.Code) + creatorField.Name, _ = transformStringFromEncoding(creatorField.Name) + fieldEncodingValues = kintone.CreatorField(creatorField) + case kintone.ModifierField: + modifierField := fields.(kintone.ModifierField) + modifierField.Code, _ = transformStringFromEncoding(modifierField.Code) + modifierField.Name, _ = transformStringFromEncoding(modifierField.Name) + fieldEncodingValues = kintone.ModifierField(modifierField) default: fieldEncodingValues = fields }