| Revision | 2467 (tree) |
|---|---|
| Time | 2022-10-20 19:36:20 |
| Author | t_nakayama1971 |
(empty log message)
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | package project.web.generic.master; |
| 2 | 2 | |
| 3 | 3 | import java.sql.Types; |
| 4 | +import java.util.ArrayList; | |
| 4 | 5 | |
| 5 | 6 | import core.config.Factory; |
| 6 | 7 | import core.util.bean.CamelCase; |
| @@ -8,6 +9,7 @@ | ||
| 8 | 9 | import online.annotation.SessionExit; |
| 9 | 10 | import online.annotation.SessionReserved; |
| 10 | 11 | import online.context.check.InputCheck; |
| 12 | +import online.context.check.ItemCheck; | |
| 11 | 13 | import online.struts.action.BrowseAction; |
| 12 | 14 | import online.struts.action.UniForm; |
| 13 | 15 | import project.check.TopMessage; |
| @@ -88,20 +90,15 @@ | ||
| 88 | 90 | public String update(final UniForm model) { |
| 89 | 91 | |
| 90 | 92 | // テーブル情報取得 |
| 91 | - final var dmd = Factory.create(DBMetaData.class); | |
| 92 | - final var info = dmd.getColumnInfo(this.table); | |
| 93 | + final var info = Factory.create(DBMetaData.class).getColumnInfo(this.table); | |
| 93 | 94 | |
| 94 | 95 | // 入力チェック |
| 95 | - final var ro = InstanceFactory.create(RecordOperate.class, model); | |
| 96 | 96 | final var ic = InstanceFactory.create(InputCheck.class, model); |
| 97 | 97 | ic.onError(new TopMessage("ZZ000000005")); |
| 98 | 98 | for (final var ent : info.entrySet()) { |
| 99 | 99 | final var name = CamelCase.convert(ent.getKey()); |
| 100 | - if (!ID.equals(name) && !ro.isMaintenance(name)) { | |
| 101 | - addChecks(name, ent.getValue(), ic); | |
| 102 | - } | |
| 100 | + ic.add(name, getChecks(model, name, ent.getValue())); | |
| 103 | 101 | } |
| 104 | - | |
| 105 | 102 | ic.add("FooCheck", new HankakuCheck()); |
| 106 | 103 | ic.add("FooCheck2", new HankakuCheck()); |
| 107 | 104 | ic.populate(); |
| @@ -142,31 +139,38 @@ | ||
| 142 | 139 | } |
| 143 | 140 | |
| 144 | 141 | /** |
| 145 | - * 入力チェック追加 | |
| 142 | + * 入力チェック取得 | |
| 146 | 143 | * |
| 144 | + * @param model 汎用モデル | |
| 147 | 145 | * @param name 項目名 |
| 148 | 146 | * @param info テーブル情報 |
| 149 | - * @param ic 入力チェッカー | |
| 147 | + * @return 入力チェック | |
| 150 | 148 | */ |
| 151 | - private void addChecks(final String name, final DBColumnInfo info, final InputCheck ic) { | |
| 152 | - // 必須入力 | |
| 153 | - if (info.isNotNull()) { | |
| 154 | - ic.add(name, new MustCheck("ZZ000000006", info.getComment())); | |
| 149 | + private ItemCheck[] getChecks(final UniForm model, final String name, final DBColumnInfo info) { | |
| 150 | + | |
| 151 | + final var checks = new ArrayList<ItemCheck>(); | |
| 152 | + | |
| 153 | + final var ro = InstanceFactory.create(RecordOperate.class, model); | |
| 154 | + if (!ID.equals(name) && !ro.isMaintenance(name)) { | |
| 155 | + // 必須入力 | |
| 156 | + if (info.isNotNull()) { | |
| 157 | + checks.add(new MustCheck("ZZ000000006", info.getComment())); | |
| 158 | + } | |
| 159 | + // タイプと長さ | |
| 160 | + if (info.getType() == Types.CHAR) { | |
| 161 | + checks.add(new HanEisuCheck("ZZ000000007", info.getComment())); | |
| 162 | + checks.add(new LengthRangeCheck(0, info.getSize(), "ZZ000000008", info.getComment())); | |
| 163 | + } else if (info.getType() == Types.VARCHAR) { | |
| 164 | + checks.add(new LengthRangeCheck(0, info.getSize(), "ZZ000000009", info.getComment())); | |
| 165 | + } else if (info.getType() == Types.DATE) { | |
| 166 | + checks.add(new DateCheck("ZZ000000010", info.getComment())); | |
| 167 | + } else if (info.getType() == Types.TIMESTAMP) { | |
| 168 | + checks.add(new TimestampCheck("ZZ000000011", info.getComment())); | |
| 169 | + } else { | |
| 170 | + checks.add(new DecimalCheck(info.getSize(), info.getScale(), "ZZ000000012", info.getComment())); | |
| 171 | + } | |
| 155 | 172 | } |
| 156 | 173 | |
| 157 | - // タイプと長さ | |
| 158 | - if (info.getType() == Types.CHAR) { | |
| 159 | - ic.add(name, new HanEisuCheck("ZZ000000007", info.getComment())); | |
| 160 | - ic.add(name, new LengthRangeCheck(0, info.getSize(), "ZZ000000008", info.getComment())); | |
| 161 | - } else if (info.getType() == Types.VARCHAR) { | |
| 162 | - ic.add(name, new LengthRangeCheck(0, info.getSize(), "ZZ000000009", info.getComment())); | |
| 163 | - } else if (info.getType() == Types.DATE) { | |
| 164 | - ic.add(name, new DateCheck("ZZ000000010", info.getComment())); | |
| 165 | - } else if (info.getType() == Types.TIMESTAMP) { | |
| 166 | - ic.add(name, new TimestampCheck("ZZ000000011", info.getComment())); | |
| 167 | - } else { | |
| 168 | - ic.add(name, new DecimalCheck( | |
| 169 | - info.getSize(), info.getScale(), "ZZ000000012", info.getComment())); | |
| 170 | - } | |
| 174 | + return checks.toArray(ItemCheck[]::new); | |
| 171 | 175 | } |
| 172 | 176 | } |