Skip to content

Commit

Permalink
some fix
Browse files Browse the repository at this point in the history
  • Loading branch information
samlet committed Apr 24, 2021
1 parent 7c41f4d commit 9fb4521
Show file tree
Hide file tree
Showing 15 changed files with 753 additions and 15 deletions.
121 changes: 121 additions & 0 deletions doc/procs-ofbiz-graphql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# procs-ofbiz-graphql.md
## start
[graphile/postgraphile: Execute one command (or mount one Node.js middleware) and get an instant high-performance GraphQL API for your PostgreSQL database!](https://github.com/graphile/postgraphile)

```sh
npm install -g postgraphile

# 需要修改communication_event
psql ofbiz
ofbiz=# ALTER TABLE communication_event drop column to_string;

npx postgraphile -c ofbiz --watch
open http://localhost:5000/graphiql
```
```js
{allUserLogins{
nodes{
userLoginId
}
}}
```

## manual
[PostGraphile | Example queries and mutations](https://www.graphile.org/postgraphile/examples/#Mutations__Create)

[PostGraphile | Relations](https://www.graphile.org/postgraphile/relations/)

+ Example database schema for one-to-many relation

```sql
create schema a;
create schema c;

create table c.person (
id serial primary key,
name varchar not null,
about text,
email varchar not null unique,
created_at timestamp default current_timestamp
);

create table a.post (
id serial primary key,
headline text not null,
body text,
-- `references` 👇 sets up the foreign key relation
author_id int4 references c.person(id)
);
create index on a.post (author_id);
```

+ Example query against the above schema

```js
{
allPosts {
nodes {
headline
body

# this relation is automatically exposed
personByAuthorId {
id
name
about
}
}
}
}
```

[PostGraphile | Views](https://www.graphile.org/postgraphile/views/)

+ Views enable you to expose a simple "flattened" object built from multiple tables.

```sql
CREATE TABLE app_public.person (
id serial PRIMARY KEY
);

CREATE TABLE app_public.address (
person_id int PRIMARY KEY REFERENCES app_public.person,
country text,
street text,
);

CREATE VIEW person_view AS
SELECT person.id, address.country, address.street
FROM app_public.person person
INNER JOIN app_public.address
ON person.id = address.person_id;
```

The GraphQL query using this view is flatter than the query using the underlying tables:

```js
query Before {
person {
id
address {
country
street
}
}
}

query After {
personView {
id
country
street
}
}
```

## cli
[PostGraphile | Command Line Interface](https://www.graphile.org/postgraphile/usage-cli/)
--export-schema-graphql <path>
enables exporting the detected schema, in GraphQL schema format, to the given location. The directories must exist already, if the file exists it will be overwritten.


15 changes: 15 additions & 0 deletions doc/procs-ofbiz-java-routines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# procs-ofbiz-java-routines.md
+ json
[java - Convert Map to JSON using Jackson - Stack Overflow](https://stackoverflow.com/questions/29340383/convert-map-to-json-using-jackson)

```java
// You can convert Map to JSON using Jackson as follows:

Map<String,String> payload = new HashMap<>();
payload.put("key1","value1");
payload.put("key2","value2");

String json = new ObjectMapper().writeValueAsString(payload);
System.out.println(json);
```

15 changes: 15 additions & 0 deletions doc/procs-ofbiz-rest-routines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# procs-ofbiz-rest-routines.md
+ find

{{ _.ofbiz_srvs }}/performFindList
{
"entityName":"Party",
"viewIndex": 0,
"viewSize": 10,
"inputFields":{
"partyTypeId": "PERSON"
}
}
$.data.list[*].partyId


27 changes: 26 additions & 1 deletion doc/procs-ofbiz-routines.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# procs-ofbiz-model.md
## create ipython profile
[Introduction to IPython configuration — IPython 7.22.0 documentation](https://ipython.readthedocs.io/en/stable/config/intro.html)

```bash
ipython profile create bluecc # create the profile bluecc
ipython locate profile bluecc
# 在这个目录下startup子目录下创建00-first.py:
# from sagas.modules.deles import *

ipython --profile=bluecc # start IPython using the new profile
In [3]: invoices.getInvoiceTotal("demo10001")
Out[3]: Decimal('36.43')
```
```python
In [1]: e('relations').Person
```

## quick start
```python
from sagas.modules.deles import *
total=invoices.getInvoiceTotal('demo10000')
print(f"total {total}")
```

```python
#
from sagas.ofbiz.services import OfService as s, oc, track
Expand Down Expand Up @@ -57,7 +80,9 @@ model=s('model').createProductReview
print_table(model, 'engineName', 'location', 'invoke', 'defaultEntityName')

## testing service
s().testScv(defaultValue=5.5, message="hello world")
s().testScv(defaultValue=5.5, message="hello world") # with kwargs
s().testScv({'defaultValue':5.5, 'message':"hello world"}) # with dict
# Out[2]: (True, {'responseMessage': 'success', 'resp': 'service done'})

## service logs
from sagas.ofbiz.entities import OfEntity as e, oc
Expand Down
137 changes: 137 additions & 0 deletions doc/procs-ofbiz.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,40 @@
[OFBiz Tutorials | Get Started with Apache OFBiz Development](https://www.hotwaxsystems.com/ofbiz-8/tutorials/)
[What You Need to Know about Price Rules in OFBiz | HotWax](https://www.hotwaxsystems.com/ofbiz/ofbiz-tutorials/ofbiz-tutorial-price-rules/)

## framework
[SECAs and Error and Failure Management - OFBiz Project Open Wiki - Apache Software Foundation](https://cwiki.apache.org/confluence/display/OFBIZ/SECAs+and+Error+and+Failure+Management)
[Service Engine Guide - OFBiz Project Open Wiki - Apache Software Foundation](https://cwiki.apache.org/confluence/display/OFBIZ/Service+Engine+Guide#ServiceEngineGuide-ServiceEngineGuide-ecas)

## related projs
[OFBiz Migration | ScipioERP](https://www.scipioerp.com/community/developer/installation-configuration/ofbiz-migration/)
[ilscipio/scipio-erp: Your Online Business Kit - Build your own business applications. Create your own online shop. Customize to your own needs.](https://github.com/ilscipio/scipio-erp)

## build
```sh
./gradlew build
# 构建之后, build/distributions/ofbiz.zip中包含了ofbiz.jar以及所有依赖库, 其中bin下是执行脚本; build/libs/ofbiz.jar是ofbiz类;
```

+ gralde mirror (在allprojects.repositories下增加)

```js
allprojects {
repositories{
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
....
}
}
```

## unit test
[From Ant to Gradle - trunk version - OFBiz Project Open Wiki - Apache Software Foundation](https://cwiki.apache.org/confluence/display/OFBIZ/From+Ant+to+Gradle+-+trunk+version#load-data-from-an-entity-file)

```sh
$ ./gradlew "ofbiz --test component=entity --test suitename=entitytests"
$ ./gradlew "ofbiz --test component=party -test name=party-tests"
```

## Business Process Reference
[Business Process Reference Book - OFBiz Project Open Wiki - Apache Software Foundation](https://cwiki.apache.org/confluence/display/OFBIZ/Business+Process+Reference+Book)

Expand Down Expand Up @@ -31,6 +65,69 @@ Content-Type: application/json +
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJBcGFjaGVPRkJpeiIsImlhdCI6MTU0NzczOTM0OCwiZXhwIjoxNjc5Mjc1MzQ4LCJhdWQiOiJ3d3cuZXhhbXBsZS5jb20iLCJzdWIiOiJqcm9ja2V0QGV4YW1wbGUuY29tIiwiR2l2ZW5OYW1lIjoiSm9obm55IiwiU3VybmFtZSI6IlJvY2tldCIsIkVtYWlsIjoianJvY2tldEBleGFtcGxlLmNvbSIsInVzZXJMb2dpbklkIjoiYWRtaW4iLCJSb2xlIjpbIk1hbmFnZXIiLCJQcm9qZWN0IEFkbWluaXN0cmF0b3IiXX0.fwafgrgpodBJcXxNTQdZknKeWKb3sDOsQrcR2vcRw97FznD6mkE79p10Tu7cqpUx7LiXuROUAnXEgqDice-BSg
```

* 修改ModelServiceReader后用post方式访问: https://localhost:8443/rest/services/ping, bearer-token为前面获取的access_token, json内容需要是合法内容, 比如: {"x":"x"}
得到以下结果:

```json
{
"statusCode": 200,
"statusDescription": "OK",
"data": {
"message": "PONG"
}
}
```

+ 测试返回错误: https://localhost:8443/rest/services/testEntityFailure

```json
{
"statusCode": 422,
"statusDescription": "Unprocessable Entity",
"errorType": "ServiceError",
"errorMessage": "testEntityFailure returned error. The request contained invalid information and could not be processed.",
"errorDescription": "Unable to create test entity"
}
```

+ 测试携带参数: https://localhost:8443/rest/services/testScv

```json
{
"defaultValue":99.8,
"message": "hello"
}

```
```json
{
"statusCode": 200,
"statusDescription": "OK",
"data": {
"resp": "service done"
}
}
```

使用复合参数时: https://localhost:8443/rest/services/testScv
会被折叠成字符串到指定的参数中:

```json
{
"defaultValue":99.8,
"message": {
"name":"hello"
}
}
```
```ini
|I| ---- SVC-CONTEXT: message => {name=hello}
```

## debug
* 通过gradle/tasks/application/run上右击选择debug, 就可以进行断点调试;
* 见: ofbiz-dev.docx

## plugins
[From Ant to Gradle - trunk version - OFBiz Project Open Wiki - Apache Software Foundation](https://cwiki.apache.org/confluence/display/OFBIZ/From+Ant+to+Gradle+-+trunk+version#FromAnttoGradletrunkversion-Step-by-stepguide)

Expand All @@ -40,4 +137,44 @@ Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJBcGFjaGVPR
./gradlew createPlugin -PpluginId=myplugin -PpluginResourceName=MyPlugin -PwebappName=mypluginweb -PbasePermission=MYSECURITY
```

## postgres
[PostgreSQL: Documentation: 9.1: createuser](https://www.postgresql.org/docs/9.1/app-createuser.html)
[Creating user, database and adding access on PostgreSQL | by Arnav Gupta | Coding Blocks | Medium](https://medium.com/coding-blocks/creating-user-database-and-adding-access-on-postgresql-8bfcd2f4a91e)

```sh
# To create the user joe as a superuser, and assign a password immediately:

$ createuser -P -s -e ofbiz
# Enter password for new role: xyzzy
# Enter it again: xyzzy
# CREATE ROLE joe PASSWORD 'md5b5f5ba1a423792b526f799ae4eb3d59e' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;

$ createdb ofbiz
$ psql ofbiz
# psql=# grant all privileges on database <dbname> to <username> ;
ofbiz=# grant all privileges on database ofbiz to ofbiz;
```

## auth
* 可修改token的expireTime:
* ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/resources/AuthenticationResource.java
* framework/security/config/security.properties
@Path("/token")
.. EntityUtilProperties.getPropertyValue("security", "security.jwt.token.expireTime", "1800", getDelegator())

```bash
# 18000000/60/60 = 5000.0小时 = 208.3天
curl -k -X POST "https://localhost:8443/rest/auth/token" -H "accept: application/json" -H "Authorization: Basic YWRtaW46b2ZiaXo="
{
"statusCode" : 200,
"statusDescription" : "OK",
"successMessage" : "Token granted.",
"data" : {
"access_token" : "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJ1c2VyTG9naW5JZCI6ImFkbWluIiwiaXNzIjoiQXBhY2hlT0ZCaXoiLCJleHAiOjE2MzQ1OTc3NTcsImlhdCI6MTYxNjU5Nzc1N30.Luuf2bK7ZJ8KE_CtsA3iPZ189i-Qbm2qK5r5VfeQcJqIyTKy4DHf2fBAp37W8OtU6SIplwCdnbTMtHuCZ5h8cA",
"token_type" : "Bearer",
"expires_in" : "18000000"
}
}
```


23 changes: 23 additions & 0 deletions ecommerce/procs-gradle-mirror.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
# procs-gradle-mirror.md
[gradle 使用 国内镜像 - 正义的伙伴! - 博客园](https://www.cnblogs.com/whm-blog/p/12407786.html)

```js
// 在项目文件中找到build.gradle文件,修改其中的buildscript和allprojects地址:

buildscript {
repositories {
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0-alpha13'
}
}

allprojects {
repositories {
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
}
}
```

[阿里云maven镜像库配置(gradle,maven) - 迟到的月亮 - CSDN博客](https://blog.csdn.net/qq_32193151/article/details/70907037)

gradle配置:将原来的mavenCentral()直接替换掉或者放到这个的前面(默认是从上往下寻找,所以要放到mavenCentral的前面,如果加在mavenCentral后面,等同于没加)
Expand Down
3 changes: 3 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bluecc:
ipython --profile=bluecc

Loading

0 comments on commit 9fb4521

Please sign in to comment.