##### Coverage Report - jp.co.y_net.amm.dao.Org

Classes in this File | Line Coverage | Branch Coverage | Complexity

Org

0% | 0/176

0% | 0/73

0.0;0

Org$EntryDateComparator

0% | 0/13

0% | 0/10

0.0;0

1

0

     package jp.co.y_net.amm.dao;

2

3

     import java.io.Serializable;

4

     import java.text.DateFormat;

5

     import java.text.SimpleDateFormat;

6

     import java.util.ArrayList;

7

     import java.util.Collections;

8

     import java.util.Comparator;

9

     import java.util.Date;

10

     import java.util.List;

11

     import java.util.Map;

12

     import java.util.TreeMap;

13

14

     import jp.co.y_net.amm.common.AppLogger;

15

     import jp.co.y_net.amm.common.AppUtils;

16

     import jp.co.y_net.amm.common.ChoiceElement;

17

     import jp.co.y_net.amm.common.ResourceReader;

18

19

     import org.apache.commons.lang.StringUtils;

20

21

22

0

     public class Org extends AppDto implements Serializable {

23

             private static final long serialVersionUID = 1L;

24

25

             /** 申請日に使用するDateFormat */

26

0

             final DateFormat DF_YYYYMMDDHHMM = new SimpleDateFormat("yyyy/MM/dd HH:mm");

27

28

             public static final int KIND_PERSONAL = 9; // 個人会員

29

             public static final String KIND_PERSONAL_STR = "9"; // 個人会員

30

31

             public static final int KIND_運営管理 = 999;

32

33

             public static final int LIMITNUM_未指定 = -1;

34

35

         private Integer orgid;

36

         private Integer kind;

37

         private String name;

38

         private String adminname;

39

         private String adminnamekana;

40

         private String postnum;

41

         private String address;

42

         private String telnum;

43

         private String mail;

44

         private Integer fromdate;

45

         private Integer todate;

46

         private Integer limitnum;

47

         private Long entrydate;

48

         private Long approvaldate;

49

         private Long rejectdate;

50

         private String note;

51

         private Long joindate;

52

         private Integer status;

53

54

         /** 状態 */

55

         public static final int STATUS_未処理 = 0;

56

         public static final int STATUS_承認済み = 1;

57

         public static final int STATUS_拒否済み = 2;

58

         public static final int STATUS_本登録済み = 3;

59

60

         public static Map<String, String> getStatusMap() {

61

0

             Map<String, String> map = new TreeMap<String, String>();

62

0

             map.put("0", "未処理");

63

0

             map.put("1", "承認済み");

64

0

             map.put("2", "拒否済み");

65

0

             map.put("3", "本登録済み");

66

0

             return map;

67

         }

68

69

         /**

70

          * @return 状態の名称

71

          */

72

         public String getStatus_Disp() {

73

0

             if(status == null) {

74

0

                 return null;

75

             }

76

0

             switch (status) {

77

             case STATUS_未処理:

78

0

                 return "未処理";

79

             case STATUS_承認済み:

80

0

                 return "承認済み";

81

             case STATUS_拒否済み:

82

0

                 return "拒否済み";

83

             case STATUS_本登録済み:

84

0

                 return "本登録済み";

85

             default:

86

0

                 return String.valueOf(status);

87

             }

88

         }

89

90

         /** @return 機関会員の種類の名称 */

91

         public String getKind_Disp() {

92

0

             String key = getKind().toString();

93

0

             return getOrgkindMap().get(key);

94

         }

95

         /**

96

          * @return 個人会員であれば true

97

          */

98

         public boolean isPersonalOrg() {

99

0

             if(this.kind != null && this.kind == KIND_PERSONAL) {

100

0

                 return true;

101

             } else {

102

0

                 return false;

103

             }

104

         }

105

106

         /**

107

          * @return 郵便番号のハイフン付き表記

108

          */

109

         public String getPostnum_Disp() {

110

0

             String tmp = getPostnum();

111

0

             if(tmp != null && tmp.length() > 4) {

112

0

                 StringBuilder sb = new StringBuilder(tmp);

113

0

                 sb.insert(3, "-");

114

0

                 tmp = sb.toString();

115

             }

116

0

             return tmp;

117

         }

118

119

         /**

120

          * @return 機関・団体であればその名称。個人会員であれば代表者名。

121

          */

122

         public String getNameOrAdminname() {

123

             String name;

124

0

             if(this.isPersonalOrg()) {

125

0

                 name = this.getAdminname();

126

0

             } else {

127

0

                 name = this.getName();

128

             }

129

     //        if(StringUtils.isEmpty(this.getName()) == false) {

130

     //            name = this.getName();

131

     //        } else if(StringUtils.isEmpty(this.getAdminname()) == false) {

132

     //            name = this.getAdminname();

133

     //        } else {

134

     //            name = "";

135

     //        }

136

137

138

0

             String str = StringUtils.abbreviate(name, 100);

139

0

             return str;

140

         }

141

142

143

144

     //    public static void main(String[] args) {

145

     ////      Map<String, String> map = getKindMap();

146

     ////      for(Entry<String, String> e: map.entrySet()) {

147

     ////          System.out.println(e.getKey() + "=" + e.getValue());

148

     ////      }

149

     ////      System.out.println(ResourceReader.getText("message/termsofuse"));

150

     //        Org org = new Org();

151

     //        org.setPostnum("123");

152

     //        System.out.println(org.getPostnum_Disp());

153

     //        org.setPostnum("1234");

154

     //        System.out.println(org.getPostnum_Disp());

155

     //        org.setPostnum("12345");

156

     //        System.out.println(org.getPostnum_Disp());

157

     //        org.setPostnum("123456");

158

     //        System.out.println(org.getPostnum_Disp());

159

     //        org.setPostnum("1234567");

160

     //        System.out.println(org.getPostnum_Disp());

161

     //        org.setPostnum(null);

162

     //        System.out.println(org.getPostnum_Disp());

163

     //  }

164

165

         public static TreeMap<String, String> getOrgkindMap() {

166

0

             String orgkinds = ResourceReader.getStringQuick("orgkinds");

167

0

             String[] orgkindArray = orgkinds.split(",");

168

0

             TreeMap<String, String> map = new TreeMap<String, String>();

169

0

             for(String kind: orgkindArray) {

170

0

                 kind = kind.trim();

171

                 String key;

172

                 String value;

173

0

                 int index = kind.indexOf(".");

174

0

                 if(index != -1) {

175

0

                     key = kind.split("\\.")[0];

176

0

                     value = kind.split("\\.")[1];

177

0

                 } else {

178

0

                     key = kind;

179

0

                     value = "";

180

                 }

181

0

                 map.put(key, value);

182

             }

183

0

             return map;

184

         }

185

186

         /**

187

          * @return 申請日時（書式：yyyy/MM/dd HH:mm）

188

          */

189

         public String getEntrydate_Disp() {

190

             String entrydate;

191

             try {

192

0

                 Date d = AppUtils.toDate(this.getEntrydate());

193

0

                 if(d != null) {

194

0

                     entrydate = DF_YYYYMMDDHHMM.format(d);

195

0

                 } else {

196

0

                     entrydate = "";

197

                 }

198

0

             } catch (Exception e) {

199

0

                 AppLogger.error(e);

200

0

                 if (this.getEntrydate() != null) {

201

0

                     entrydate = String.valueOf(this.getEntrydate());

202

0

                 } else {

203

0

                     entrydate = "";

204

                 };

205

             }

206

0

             return entrydate;

207

         }

208

209

         /**

210

          * 申請日付のソートに用いるComparator

211

          */

212

         public static class EntryDateComparator implements Comparator<Org>{

213

             /** trueに変更すると 申請日時の新しい順 */

214

0

             private boolean desc = false;

215

216

0

             public EntryDateComparator(boolean desc) {

217

0

                 this.desc = desc;

218

0

             }

219

220

             @Override

221

             public int compare(Org o1, Org o2) {

222

0

                 int reverse = 1;

223

                 //if(sortModel.getObject().getId().equals("1")) {

224

0

                 if(desc) {

225

0

                     reverse = -1;

226

                 }

227

228

0

                 Long n1 = 0L;

229

0

                 Long n2 = 0L;

230

0

                 if(o1 != null && o1.getEntrydate() != null) n1 = o1.getEntrydate();

231

0

                 if(o2 != null && o2.getEntrydate() != null) n2 = o2.getEntrydate();

232

233

0

                 return Long.compare(n1, n2) * reverse;

234

             }

235

         }

236

237

         /** 登録可能会員数の選択肢 */

238

         public static List<ChoiceElement> createLimitChices(String limitnumValue) {

239

0

             List<Integer> limitnumList = new ArrayList<Integer>();

240

0

             limitnumList.add(LIMITNUM_未指定); // 未指定

241

             /* 設定ファイルより選択肢を取得 */

242

0

             String str = ResourceReader.getStringQuick("limitnums");

243

0

             String[] array = str.split(",");

244

0

             for (int i = 0; i < array.length; i++) {

245

                 int num;

246

                 try {

247

0

                     num = Integer.parseInt(array[i].trim());

248

0

                     limitnumList.add(num);

249

0

                 } catch (NumberFormatException e) {

250

0

                     AppLogger.info("設定値 limitnums に数値に変換できない値があります。", e);

251

                 }

252

             }

253

0

             String existValue = String.valueOf(limitnumValue);

254

0

             if(StringUtils.isEmpty(existValue) == false) {

255

                 int iExistValue;

256

                 try {

257

0

                     iExistValue = Integer.parseInt(existValue);

258

0

                     if(limitnumList.contains(iExistValue) == false) {

259

0

                         limitnumList.add(iExistValue); // 現在の値が選択肢になければ追加する

260

                     }

261

0

                 } catch (NumberFormatException e1) {

262

                     // 処理なし

263

                 }

264

             }

265

0

             Collections.sort(limitnumList);

266

0

             List<ChoiceElement> choiceLimitnum = new ArrayList<ChoiceElement>();

267

0

             for (Integer num: limitnumList) {

268

                 String label;

269

0

                 if(num == LIMITNUM_未指定) {

270

0

                     label = "指定なし";

271

0

                 } else {

272

0

                     label = num + "人";

273

                 }

274

0

                 choiceLimitnum.add(new ChoiceElement(String.valueOf(num), label));

275

             }

276

0

             return choiceLimitnum;

277

         }

278

279

         public boolean is利用可能期間内() {

280

0

             return betweenNow(this.fromdate, this.todate);

281

         }

282

283

         private static boolean betweenNow(Integer from, Integer to) {

284

0

             if(from == null || from == -1) from = Integer.MIN_VALUE;

285

0

             if(to == null || to == -1) to = Integer.MAX_VALUE;

286

0

             Integer now = AppUtils.createNowShort();

287

0

             return from <= now && now <= to;

288

         }

289

     //    public static void main(String[] args) {

290

     //        System.out.println(betweenNow(-1, -1));

291

     //        System.out.println(betweenNow(null, null));

292

     //        System.out.println(betweenNow(20150803, 20150831));

293

     //        System.out.println(betweenNow(20150804, 20150831));

294

     //        System.out.println(betweenNow(20150801, 20150802));

295

     //        System.out.println(betweenNow(20150801, 20150803));

296

     //    }

297

298

         /**

299

          * @return 利用期間（表示用）

300

          */

301

         public String getFromTodate_Disp() {

302

0

             String fromdate = AppUtils.toStrYyyyMMdd(this.getFromdate());

303

0

             if(is利用期間未指定(this.getFromdate())) {

304

0

                 fromdate = "";

305

             }

306

0

             String todate = AppUtils.toStrYyyyMMdd(this.getTodate());

307

0

             if(is利用期間未指定(this.getTodate())) {

308

0

                 todate = "";

309

             }

310

             String fromtodateStr;

311

0

             if(StringUtils.isEmpty(fromdate) && StringUtils.isEmpty(todate)) {

312

0

                 fromtodateStr = "";

313

0

             } else if (StringUtils.isEmpty(fromdate) == false && StringUtils.isEmpty(todate) == true) {

314

0

                 fromtodateStr = fromdate + "～";

315

0

             } else if (StringUtils.isEmpty(fromdate) == true && StringUtils.isEmpty(todate) == false) {

316

0

                 fromtodateStr = "～" + todate;

317

0

             } else {

318

0

                 fromtodateStr = fromdate + "～" + todate;

319

             }

320

0

             if("～".equals(fromtodateStr)) {

321

0

                 return "";

322

             }

323

0

             return fromtodateStr;

324

         }

325

326

         private boolean is利用期間未指定(Integer fromOrTo) {

327

0

             if(fromOrTo == null) {

328

0

                 return true;

329

             }

330

0

             if(LIMITNUM_未指定 == fromOrTo) {

331

0

                 return true;

332

             }

333

0

             return false;

334

         }

335

         public boolean isLimitnum指定なし() {

336

0

             return limitnum == null || LIMITNUM_未指定 == limitnum;

337

         }

338

339

         public static void main(String[] args) {

340

0

             Org org = new Org();

341

0

             System.out.println(org.getFromTodate_Disp());

342

0

             org.setFromdate(-1);

343

0

             System.out.println(org.getFromTodate_Disp());

344

0

             org.setTodate(-1);

345

0

             System.out.println(org.getFromTodate_Disp());

346

0

             org.setFromdate(20150101);

347

0

             System.out.println(org.getFromTodate_Disp());

348

0

             org.setTodate(20151212);

349

0

             System.out.println(org.getFromTodate_Disp());

350

351

0

         }

352

353

         /* -- 以下、自動生成 --*/

354

355

     //    public Integer getId() {

356

     //        return id;

357

     //    }

358

     //    public void setId(Integer id) {

359

     //        this.id = id;

360

     //    }

361

     //    public Integer getUpdatedate() {

362

     //        return updatedate;

363

     //    }

364

     //    public void setUpdatedate(Integer updatedate) {

365

     //        this.updatedate = updatedate;

366

     //    }

367

     //    public Integer getDeleted() {

368

     //        return deleted;

369

     //    }

370

     //    public void setDeleted(Integer deleted) {

371

     //        this.deleted = deleted;

372

     //    }

373

         public Integer getOrgid() {

374

0

             return orgid;

375

         }

376

         public void setOrgid(Integer orgid) {

377

0

             this.orgid = orgid;

378

0

         }

379

         public Integer getKind() {

380

0

             return kind;

381

         }

382

         public void setKind(Integer kind) {

383

0

             this.kind = kind;

384

0

         }

385

         public String getName() {

386

0

             return name;

387

         }

388

         public void setName(String name) {

389

0

             this.name = name;

390

0

         }

391

         public String getAdminname() {

392

0

             return adminname;

393

         }

394

         public void setAdminname(String adminname) {

395

0

             this.adminname = adminname;

396

0

         }

397

         public String getAdminnamekana() {

398

0

             return adminnamekana;

399

         }

400

         public void setAdminnamekana(String adminnamekana) {

401

0

             this.adminnamekana = adminnamekana;

402

0

         }

403

         public String getPostnum() {

404

0

             return postnum;

405

         }

406

         public void setPostnum(String postnum) {

407

0

             this.postnum = postnum;

408

0

         }

409

         public String getAddress() {

410

0

             return address;

411

         }

412

         public void setAddress(String address) {

413

0

             this.address = address;

414

0

         }

415

         public String getTelnum() {

416

0

             return telnum;

417

         }

418

         public void setTelnum(String telnum) {

419

0

             this.telnum = telnum;

420

0

         }

421

         public String getMail() {

422

0

             return mail;

423

         }

424

         public void setMail(String mail) {

425

0

             this.mail = mail;

426

0

         }

427

         public Integer getFromdate() {

428

0

             return fromdate;

429

         }

430

         public void setFromdate(Integer fromdate) {

431

0

             this.fromdate = fromdate;

432

0

         }

433

         public Integer getTodate() {

434

0

             return todate;

435

         }

436

         public void setTodate(Integer todate) {

437

0

             this.todate = todate;

438

0

         }

439

440

         public Long getEntrydate() {

441

0

             return entrydate;

442

         }

443

         public void setEntrydate(Long entrydate) {

444

0

             this.entrydate = entrydate;

445

0

         }

446

         public Long getApprovaldate() {

447

0

             return approvaldate;

448

         }

449

         public void setApprovaldate(Long approvaldate) {

450

0

             this.approvaldate = approvaldate;

451

0

         }

452

         public Long getRejectdate() {

453

0

             return rejectdate;

454

         }

455

         public void setRejectdate(Long rejectdate) {

456

0

             this.rejectdate = rejectdate;

457

0

         }

458

         public String getNote() {

459

0

             return note;

460

         }

461

         public void setNote(String note) {

462

0

             this.note = note;

463

0

         }

464

         public Long getJoindate() {

465

0

             return joindate;

466

         }

467

         public void setJoindate(Long joindate) {

468

0

             this.joindate = joindate;

469

0

         }

470

         public Integer getLimitnum() {

471

0

             return limitnum;

472

         }

473

         public void setLimitnum(Integer limitnum) {

474

0

             this.limitnum = limitnum;

475

0

         }

476

         public Integer getStatus() {

477

0

             return status;

478

         }

479

         public void setStatus(Integer status) {

480

0

             this.status = status;

481

0

         }

482

483

484

     }