1 /*
2 * Copyright 2007 The International Moth Class Association (IMCA)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sf.imca.model;
17
18 import java.util.Date;
19
20 import net.sf.imca.model.entities.MembershipEntity;
21
22 /**
23 * Business Object representing the properties, persistence and functionality of
24 * the IMCA domain object.
25 *
26 * @author dougculnane
27 */
28 public class MembershipBO {
29
30 public static final String STATUS_UNPAID = "not paid";
31 public static final String STATUS_ACTIVE = "active";
32 public static final String STATUS_EXPIRED = "expired";
33 public static final String STATUS_FUTURE = "future";
34
35 /**
36 * Constructor with persistence entity.
37 *
38 * @param entity
39 */
40 public MembershipBO(MembershipEntity entity){
41 this.setEntity(entity);
42 }
43
44 /**
45 * Entity for persisting this Business Object.
46 */
47 private MembershipEntity entity;
48
49 /**
50 * Get the persistence entity.
51 *
52 * @return The persistence entity for this Business Object.
53 */
54 public MembershipEntity getEntity() {
55 return entity;
56 }
57
58 /**
59 * Set the persistence entity.
60 *
61 * @param entity The new persistence entity for this Business Object.
62 */
63 public void setEntity(MembershipEntity entity) {
64 this.entity = entity;
65 }
66
67 public String getStatus(){
68 if (getEntity().getPaid()){
69 Date now = new Date();
70 if (now.before(getEntity().getType().getValidFrom())) {
71 return STATUS_FUTURE;
72 } else if (now.after(getEntity().getType().getValidTo())) {
73 return STATUS_EXPIRED;
74 } else {
75 return STATUS_ACTIVE;
76 }
77 } else {
78 return STATUS_UNPAID;
79 }
80 }
81
82 }