takuminのブログ

Java/PHP/JavaScript

Jhipsterのアプリケーションの作成

アプリケーションの拡張

Jhipsterでプロジェクトを生成したのでアプリケーションを拡張していきます

Entityの作成

http://www.jhipster.tech/creating-an-entity/

どうやら、entityの実行をオプションなしで実行すると基本的なCRUDのすべてをバックエンド&フロントエンドで全部作ってくれるらしい。しかし、サービス層は作成されない。
サービス層を作るかentity追加時に聞かれた。 f:id:takumin03:20180123011402p:plain

[takumiMac:jhipster]./node_modules/.bin/yo jhipster:entity author                                       (git)-[p_1]
The entity author is being created.
Generating field #1
? Do you want to add a field to your entity? Yes
? What is the name of your field? name
? What is the type of your field? String
? Do you want to add validation rules to your field? Yes
? Which validation rules do you want to add? Maximum length
? What is the maximum length of your field? 100
================= Author =================
Fields
name (String) maxlength='100'
Generating field #2
? Do you want to add a field to your entity? Yes
? What is the name of your field? birthDate
? What is the type of your field? LocalDate
? Do you want to add validation rules to your field? Yes
? Which validation rules do you want to add? Required

================= Author =================
Fields
name (String) maxlength='100'
birthDate (LocalDate) required

Generating field #3

? Do you want to add a field to your entity? No

================= Author =================
Fields
name (String) maxlength='100'
birthDate (LocalDate) required

Generating relationships to other entities

? Do you want to add a relationship to another entity? No

================= Author =================
Fields
name (String) maxlength='100'
birthDate (LocalDate) required


? Do you want to use separate service class for your business logic? Yes, generate a separate service class
? Do you want to use a Data Transfer Object (DTO)? No, use the entity directly
? Do you want to add filtering? Not needed
? Do you want pagination on your entity? Yes, with pagination links

生成されたファイル

create mode 100644 .jhipster/Author.json
 create mode 100644 src/main/java/jp/co/corp/jhipster/domain/Author.java
 create mode 100644 src/main/java/jp/co/corp/jhipster/repository/AuthorRepository.java
 create mode 100644 src/main/java/jp/co/corp/jhipster/repository/search/AuthorSearchRepository.java
 create mode 100644 src/main/java/jp/co/corp/jhipster/service/AuthorService.java
 create mode 100644 src/main/java/jp/co/corp/jhipster/web/rest/AuthorResource.java
 create mode 100644 src/main/resources/config/liquibase/changelog/20180122091305_added_entity_Author.xml
 create mode 100644 src/main/webapp/app/entities/author/author-delete-dialog.component.html
 create mode 100644 src/main/webapp/app/entities/author/author-delete-dialog.component.ts
 create mode 100644 src/main/webapp/app/entities/author/author-detail.component.html
 create mode 100644 src/main/webapp/app/entities/author/author-detail.component.ts
 create mode 100644 src/main/webapp/app/entities/author/author-dialog.component.html
 create mode 100644 src/main/webapp/app/entities/author/author-dialog.component.ts
 create mode 100644 src/main/webapp/app/entities/author/author-popup.service.ts
 create mode 100644 src/main/webapp/app/entities/author/author.component.html
 create mode 100644 src/main/webapp/app/entities/author/author.component.ts
 create mode 100644 src/main/webapp/app/entities/author/author.model.ts
 create mode 100644 src/main/webapp/app/entities/author/author.module.ts
 create mode 100644 src/main/webapp/app/entities/author/author.route.ts
 create mode 100644 src/main/webapp/app/entities/author/author.service.t
 create mode 100644 src/main/webapp/app/entities/author/index.ts
 create mode 100644 src/main/webapp/i18n/en/author.json
 create mode 100644 src/main/webapp/i18n/ja/author.json
 create mode 100644 src/test/gatling/user-files/simulations/AuthorGatlingTest.scala
 create mode 100644 src/test/java/jp/co/corp/jhipster/web/rest/AuthorResourceIntTest.java
 create mode 100644 src/test/javascript/e2e/entities/author.spec.ts
 create mode 100644 src/test/javascript/spec/app/entities/author/author-delete-dialog.component.spec.ts
 create mode 100644 src/test/javascript/spec/app/entities/author/author-detail.component.spec.ts
 create mode 100644 src/test/javascript/spec/app/entities/author/author-dialog.component.spec.ts
 create mode 100644 src/test/javascript/spec/app/entities/author/author.component.spec.ts
 create mode 100644 src/test/javascript/spec/app/entities/author/author.service.spec.ts

バックエンド側はドメインリポジトリ、サービス、コントローラが生成された。

サービスが生成された理由は、entity生成時に「サービスを生成する」を選択したから。たぶん中身は大したことしてない。検証のためにまずはサービスなしで生成すればよかった。。。

SpringContorollerの作成

http://www.jhipster.tech/creating-a-spring-controller/

[takumiMac:jhipster]./node_modules/.bin/jhipster spring-controller takumi                               (git)-[p_1]
Using JHipster version installed globally
Executing jhipster:spring-controller takumi
Options: 
The spring-controller takumi is being created.
? Do you want to add an action to your controller? Yes
? What is the name of your action? takumi
? What is the HTTP method of your action? GET
? Do you want to add an action to your controller? No
adding Get action 'takumi' for /api/takumi/takumi
   create src/main/java/jp/co/corp/jhipster/web/rest/TakumiResource.java
   create src/test/java/jp/co/corp/jhipster/web/rest/TakumiResourceIntTest.java
Congratulations, JHipster execution is complete!

生成されたファイル

create src/main/java/jp/co/corp/jhipster/web/rest/TakumiResource.java
   create src/test/java/jp/co/corp/jhipster/web/rest/TakumiResourceIntTest.java

controllerクラス、そのテストクラスが生成された。

f:id:takumin03:20180123011942p:plain

SpringServiceの生成

http://www.jhipster.tech/creating-a-spring-service/

Entityの生成時に一緒に生成できたので今回は飛ばします。 複数のデータソースを扱うようなビジネスロジックを作成するときに使うんでしょう。(たぶん)

次回はJDLを試してみます。 そのまえに公式ドキュメントをもう少しちゃんと読んできます・・・

jhipster導入

 

業務でJava(Springboot) + Angularでの開発にjoinしました。

Jhipsterで勉強していきます。

 

インストール

gインストールはしたくないので

$ cd project/git/
$ mkdir jhipster
$ cd jhipster
$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (jhipster) 
version: (1.0.0) 
description: 
entry point: (index.js) 
test command: 
git repository: 
keywords: 
author: 
license: (ISC) 
About to write to /Users/takumi/project/git/jhipster/package.json:

{
  "name": "jhipster",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}


Is this ok? (yes) 

yoのインストール

$ npm i yo

> spawn-sync@1.0.15 postinstall /Users/takumi/project/git/jhipster/node_modules/spawn-sync
> node postinstall


> yo@2.0.0 postinstall /Users/takumi/project/git/jhipster/node_modules/yo
> yodoctor


Yeoman Doctor
Running sanity checks on your system

✔ Global configuration file is valid
✔ NODE_PATH matches the npm root
✔ Node.js version
✔ No .bowerrc file in home directory
✔ No .yo-rc.json file in home directory
✔ npm version

Everything looks all right!
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN jhipster@1.0.0 No description
npm WARN jhipster@1.0.0 No repository field.

+ yo@2.0.0
added 385 packages in 11.991s

jhipsterのインストール

$ npm i generator-jhipster

> generator-jhipster@4.13.3 postinstall /Users/takumi/project/git/jhipster/node_modules/generator-jhipster
> opencollective postinstall


                   Thanks for installing generator-jhipster 🙏
                 Please consider donating to our open collective
                        to help us maintain this package.

                           Number of contributors: 366
                              Number of backers: 21
                              Annual budget: $10,923
                             Current balance: $1,019

     👉  Donate: https://opencollective.com/generator-jhipster/donate

npm WARN jhipster@1.0.0 No description
npm WARN jhipster@1.0.0 No repository field.

+ generator-jhipster@4.13.3
added 136 packages in 13.69s

yarnのインストール

$ npm i yarn

npm WARN deprecated yarn@1.3.2: It is recommended to install Yarn using the native installation method for your environment. See https://yarnpkg.com/en/docs/install
npm WARN jhipster@1.0.0 No description
npm WARN jhipster@1.0.0 No repository field.

+ yarn@1.3.2
added 1 package in 4.659s

プロジェクトの作成

jhipsterを使ってプロジェクトを作成していきます。

$ node_modules/.bin/yo jhipster

対話式でプロジェクトを作っていきます。

質問 選択項目 説明
May JHipster anonymously report usage statistics to improve the tool over time YES or NO レポート送る?
Which type of application would you like to create? Monolithic application Monolithic application モノリシックアプリ
Microservice application マイクロサービスアプリ
Microservice gateway マイクロサービスのゲートウェイ
JHipster UAA server (しらない)
What is the base name of your application? 記述 アプリケーション名
What is your default Java package name? 記述 javaパッケージ名
Do you want to use the JHipster Registry to configure, monitor and scale your application? YES or NO JHipsterレジストリ使いますか?
Which type of authentication would you like to use? JWT authentication ジョットで認証
OAuth 2.0 / OIDC Authentication OAuthで認証
HTTP Session Authentication セッションで認証
Which type of database would you like to use? SQL (H2, MySQL, MariaDB, PostgreSQL, Oracle, MSSQL) RDBでいく?
MongoDB モンゴでいく?
Cassandra カサンドラでいく?
[BETA] Couchbase (しらない)
Which production database would you like to use? MySQL どのRDBでいく?
MariaDB
PostgreSQL
Oracle
Microsoft SQL Server
Which development database would you like to use? H2 with disk-based persistence dev環境のDBはどうする?
H2 with in-memory persistence inmemoryDBでいく?
MySQL devもmysql
Do you want to use the Spring cache abstraction? Yes, with the Ehcache implementation (local cache, for a single node) どのキャッシュでいく?
Yes, with the Hazelcast implementation (distributed cache, for multiple nodes)
[BETA] Yes, with the Infinispan (hybrid cache, for multiple nodes)
No (when using an SQL database, this will also disable the Hibernate L2 cache)
Do you want to use Hibernate 2nd level cache? YES or NO L2キャッシュでいく?
Would you like to use Maven or Gradle for building the backend? Maven パッケージ管理はどっちでいく?
Gradle
Which other technologies would you like to use? (複数選択) Social login (Google, Facebook, Twitter) 他になんかいれる?
Search engine using Elasticsearch
WebSockets using Spring Websocket
API first development using swagger-codegen
Asynchronous messages using Apache Kafka
Which Framework would you like to use for the client? Angular 5 frontサイドのフレームワークは?
AngularJS 1.x
Would you like to enable SASS support using the LibSass stylesheet preprocessor? YES or NO SAAS使う?
Would you like to enable internationalization support? YES or NO 多言語いる?
Please choose the native language of the application 言語
Please choose additional languages to install 言語
Besides JUnit and Karma, which testing frameworks would you like to use? Gatling Junitとkarma以外でテストフレームワークいれる?
Cucumber
Protractor
Would you like to install other generators from the JHipster Marketplace? YES or NO marketから他のやついれる?

 

起動させてみる

$ ./gradlew

~~~略~~~
----------------------------------------------------------
        Application 'jhipster' is running! Access URLs:
        Local:          http://localhost:8080
        Profile(s):     [swagger, dev]
----------------------------------------------------------

http://localhost:8080/ にアクセスすると、、、

f:id:takumin03:20180120144633p:plain

次回は作成された中身をみていきます。

Apache2.2→Apache2.4

人生初のブログ投稿から30分ですが、

2つ目の記事として今日やったことを書いときます。

Apacheの移行です。(公式ドキュメント

それに伴い、phpも5.3から5.6に上げました。

httpd.conf周りを書きなおしたり〜

phpのdeplicatedのエラー非表示にしたり〜

ちょっとハマったのが、

php.iniに

error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED

ってきっちり書いてリロードしたのにdeplicatedが消えない!

phpinfo確認したら反映はされてる!

なんでだ!

と思ったらソースコードにベタ書きで

error_reporting(E_ALL);

って書いてあった。

おつかれ。

人生はじめてのBlogを書いてみる。

自分の頭の中のことを吐き出すためにブログを始めてみました。

これまで人生で自分の考えを文章に書き起こしたことがないので、まじで何を書いていいか今悩んでいますがとりあえず書いてみます。

まぁやるからには目標というかどんなものにしていきたいか方針を立てました。

というか、いま文章を打ちながら考えてます。

  • 当面は仕事をしている上で気になったこと、考えさせられたことをただひたすら吐き出す
  • 吐き出して、自分であとで冷静になって見なおしてちゃんと考えなおす
  • ある程度ブログを書くことに慣れたらwebエンジニアとして技術的なことをシェアできるようなそんな記事をだす

そんな感じで。

 

無理はしない。頑張って書こうとしない。気が向いたら書く。

というスタンスでいきます。

読者とかいませんが、とりあえずよろしくお願いします。