Skip to content

Commit c04e2a3

Browse files
committed
Global Enum Types for Select Items
1 parent a39f36e commit c04e2a3

4 files changed

Lines changed: 248 additions & 4 deletions

File tree

JavaSource/com/acminds/acuteauto/ui/UITypes.java

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,18 @@
33
*/
44
package com.acminds.acuteauto.ui;
55

6+
import java.util.ArrayList;
7+
import java.util.List;
8+
69
import javax.faces.bean.ApplicationScoped;
710
import javax.faces.bean.ManagedBean;
11+
import javax.faces.model.SelectItem;
12+
13+
import com.acminds.acuteauto.persistence.BaseDAO;
14+
import com.acminds.acuteauto.persistence.dto.Enum;
15+
import com.acminds.acuteauto.persistence.dto.EnumType;
16+
import com.acminds.acuteauto.utils.EnumConstants;
17+
import com.acminds.acuteauto.utils.Utils;
818

919
/**
1020
* @author Mansur
@@ -13,5 +23,203 @@
1323
@ManagedBean(eager=true, name="uiTypes")
1424
@ApplicationScoped
1525
public class UITypes {
26+
BaseDAO dao = new BaseDAO();
27+
private List<SelectItem> userTypes;
28+
private List<SelectItem> userStatuses;
29+
private List<SelectItem> locationTypes;
30+
private List<SelectItem> styleTypes;
31+
private List<SelectItem> bodyTypes;
32+
private List<SelectItem> categoryTypes;
33+
private List<SelectItem> fuelTypes;
34+
private List<SelectItem> warrantyTypes;
35+
private List<SelectItem> vehicleStatus;
36+
private List<SelectItem> vehicleConditions;
37+
private List<SelectItem> displayTypes;
38+
private List<SelectItem> imageTypes;
39+
private List<SelectItem> adStatuses;
40+
private List<SelectItem> adUnits;
41+
private List<SelectItem> loanStatuses;
42+
private List<SelectItem> financeTypes;
43+
private List<SelectItem> accountTypes;
44+
private List<SelectItem> inquiryTypes;
45+
/**
46+
* @return the userTypes
47+
*/
48+
public List<SelectItem> getUserTypes() {
49+
if(Utils.isEmpty(userTypes)) {
50+
userTypes = processEnums(EnumConstants.USER_TYPE);
51+
}
52+
return userTypes;
53+
}
54+
/**
55+
* @return the userStatuses
56+
*/
57+
public List<SelectItem> getUserStatuses() {
58+
if(Utils.isEmpty(userStatuses)) {
59+
userStatuses = processEnums(EnumConstants.USER_STATUS);
60+
}
61+
return userStatuses;
62+
}
63+
/**
64+
* @return the locationTypes
65+
*/
66+
public List<SelectItem> getLocationTypes() {
67+
if(Utils.isEmpty(locationTypes)) {
68+
locationTypes = processEnums(EnumConstants.LOCATION_TYPE);
69+
}
70+
return locationTypes;
71+
}
72+
/**
73+
* @return the styleTypes
74+
*/
75+
public List<SelectItem> getStyleTypes() {
76+
if(Utils.isEmpty(styleTypes)) {
77+
styleTypes = processEnums(EnumConstants.STYLE_TYPE);
78+
}
79+
return styleTypes;
80+
}
81+
/**
82+
* @return the bodyTypes
83+
*/
84+
public List<SelectItem> getBodyTypes() {
85+
if(Utils.isEmpty(bodyTypes)) {
86+
bodyTypes = processEnums(EnumConstants.BODY_TYPE);
87+
}
88+
return bodyTypes;
89+
}
90+
/**
91+
* @return the categoryTypes
92+
*/
93+
public List<SelectItem> getCategoryTypes() {
94+
if(Utils.isEmpty(categoryTypes)) {
95+
categoryTypes = processEnums(EnumConstants.CATEGORY_TYPE);
96+
}
97+
return categoryTypes;
98+
}
99+
/**
100+
* @return the fuelTypes
101+
*/
102+
public List<SelectItem> getFuelTypes() {
103+
if(Utils.isEmpty(fuelTypes)) {
104+
fuelTypes = processEnums(EnumConstants.FUEL_TYPE);
105+
}
106+
return fuelTypes;
107+
}
108+
/**
109+
* @return the warrantyTypes
110+
*/
111+
public List<SelectItem> getWarrantyTypes() {
112+
if(Utils.isEmpty(warrantyTypes)) {
113+
warrantyTypes = processEnums(EnumConstants.WARRANTY_TYPE);
114+
}
115+
return warrantyTypes;
116+
}
117+
/**
118+
* @return the vehicleStatus
119+
*/
120+
public List<SelectItem> getVehicleStatus() {
121+
if(Utils.isEmpty(vehicleStatus)) {
122+
vehicleStatus = processEnums(EnumConstants.VEHICLE_STATUS);
123+
}
124+
return vehicleStatus;
125+
}
126+
/**
127+
* @return the vehicleConditionTypes
128+
*/
129+
public List<SelectItem> getVehicleConditions() {
130+
if(Utils.isEmpty(vehicleConditions)) {
131+
vehicleConditions = processEnums(EnumConstants.VEHICLE_CONDITION);
132+
}
133+
return vehicleConditions;
134+
}
135+
/**
136+
* @return the displayTypes
137+
*/
138+
public List<SelectItem> getDisplayTypes() {
139+
if(Utils.isEmpty(displayTypes)) {
140+
displayTypes = processEnums(EnumConstants.DISPLAY_TYPE);
141+
}
142+
return displayTypes;
143+
}
144+
/**
145+
* @return the imageTypes
146+
*/
147+
public List<SelectItem> getImageTypes() {
148+
if(Utils.isEmpty(imageTypes)) {
149+
imageTypes = processEnums(EnumConstants.IMAGE_TYPE);
150+
}
151+
return imageTypes;
152+
}
153+
/**
154+
* @return the adStatuses
155+
*/
156+
public List<SelectItem> getAdStatuses() {
157+
if(Utils.isEmpty(adStatuses)) {
158+
adStatuses = processEnums(EnumConstants.AD_STATUS);
159+
}
160+
return adStatuses;
161+
}
162+
/**
163+
* @return the adUnits
164+
*/
165+
public List<SelectItem> getAdUnits() {
166+
if(Utils.isEmpty(adUnits)) {
167+
adUnits = processEnums(EnumConstants.AD_UNITS);
168+
}
169+
return adUnits;
170+
}
171+
/**
172+
* @return the loanStatuses
173+
*/
174+
public List<SelectItem> getLoanStatuses() {
175+
if(Utils.isEmpty(loanStatuses)) {
176+
loanStatuses = processEnums(EnumConstants.LOAN_STATUS);
177+
}
178+
return loanStatuses;
179+
}
180+
/**
181+
* @return the financeTypes
182+
*/
183+
public List<SelectItem> getFinanceTypes() {
184+
if(Utils.isEmpty(financeTypes)) {
185+
financeTypes = processEnums(EnumConstants.FINANCE_TYPE);
186+
}
187+
return financeTypes;
188+
}
189+
/**
190+
* @return the accountTypes
191+
*/
192+
public List<SelectItem> getAccountTypes() {
193+
if(Utils.isEmpty(accountTypes)) {
194+
accountTypes = processEnums(EnumConstants.ACCOUNT_TYPE);
195+
}
196+
return accountTypes;
197+
}
198+
/**
199+
* @return the inquiryTypes
200+
*/
201+
public List<SelectItem> getInquiryTypes() {
202+
if(Utils.isEmpty(inquiryTypes)) {
203+
inquiryTypes = processEnums(EnumConstants.INQUIRY_TYPE);
204+
}
205+
return inquiryTypes;
206+
}
207+
208+
private List<SelectItem> processEnums(int enumType) {
209+
List<Enum> enums = dao.get(EnumType.class, enumType).getEnums();
210+
List<SelectItem> list = new ArrayList<SelectItem>();
211+
list.add(getDefaultSelectItem());
212+
for(Enum e: enums) {
213+
list.add(new SelectItem(e.getEnumId(), e.getEnumValue()));
214+
}
215+
return list;
216+
}
217+
218+
private SelectItem getDefaultSelectItem() {
219+
SelectItem si = new SelectItem("Please Select");
220+
si.setNoSelectionOption(true);
221+
return si;
222+
}
16223

224+
17225
}

JavaSource/com/acminds/acuteauto/utils/EnumConstants.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
package com.acminds.acuteauto.utils;
22
/** AUTO GENERATED **/
33
public class EnumConstants {
4+
public static final int USER_TYPE = 1;
45
public static class UserType{
56
public static final int CLIENT = 1;
67
public static final int CUSTOMER = 2;
78
}
9+
10+
public static final int USER_STATUS = 2;
811
public static class UserStatus{
912
public static final int ACTIVE = 10;
1013
public static final int INACTIVE = 11;
1114
public static final int SUSPENDED = 12;
1215
}
16+
17+
public static final int LOCATION_TYPE = 3;
1318
public static class LocationType{
1419
public static final int PRIMARY = 20;
1520
public static final int SECONDARY = 21;
1621
}
22+
23+
public static final int STYLE_TYPE = 4;
1724
public static class StyleType{
1825
public static final int TRIM = 30;
1926
public static final int PACKAGE = 31;
2027
}
28+
29+
public static final int BODY_TYPE = 5;
2130
public static class BodyType{
2231
public static final int SEDAN = 40;
2332
public static final int WAGON = 41;
@@ -32,61 +41,88 @@ public static class BodyType{
3241
public static final int MINIVAN = 50;
3342
public static final int TRUCK = 51;
3443
}
44+
45+
public static final int CATEGORY_TYPE = 6;
3546
public static class CategoryType{
3647
public static final int RESERVED = 60;
3748
}
49+
50+
public static final int FUEL_TYPE = 7;
3851
public static class FuelType{
3952
public static final int GASOLINE = 70;
4053
public static final int PREMIUM_GASOLINE = 71;
4154
public static final int DIESEL = 72;
4255
}
56+
57+
public static final int WARRANTY_TYPE = 8;
4358
public static class WarrantyType{
4459
public static final int STANDARD = 80;
4560
public static final int EXTENDED = 81;
4661
}
62+
63+
public static final int VEHICLE_STATUS = 9;
4764
public static class VehicleStatus{
4865
public static final int AVAILABLE = 90;
4966
public static final int SOLD = 91;
5067
public static final int ONHOLD = 92;
5168
}
69+
70+
public static final int VEHICLE_CONDITION = 10;
5271
public static class VehicleCondition{
5372
public static final int NEW = 100;
5473
public static final int USED = 101;
5574
public static final int CERTIFIED = 102;
5675
}
76+
77+
public static final int DISPLAY_TYPE = 11;
5778
public static class DisplayType{
5879
public static final int SELECT_ONE = 110;
5980
public static final int SELECT_MANY = 111;
6081
}
82+
83+
public static final int IMAGE_TYPE = 12;
6184
public static class ImageType{
6285
public static final int PRIMARY = 120;
6386
}
87+
88+
public static final int AD_STATUS = 13;
6489
public static class AdStatus{
6590
public static final int ACTIVE = 130;
6691
public static final int SUSPENDED = 131;
6792
public static final int EXPIRED = 132;
6893
}
94+
95+
public static final int AD_UNITS = 14;
6996
public static class AdUnits{
7097
public static final int HOURLY = 140;
7198
public static final int DAILY = 141;
7299
public static final int WEEKLY = 142;
73100
public static final int MONTHLY = 143;
74101
public static final int YEARLY = 144;
75102
}
103+
104+
public static final int LOAN_STATUS = 15;
76105
public static class LoanStatus{
77106
public static final int SUBMITTED = 150;
78107
public static final int UNDER_REVIEW = 151;
79108
public static final int APPROVED = 152;
80109
}
110+
111+
public static final int FINANCE_TYPE = 16;
81112
public static class FinanceType{
82113
public static final int PURCHASE = 160;
83114
public static final int LEASE = 161;
84115
}
116+
117+
public static final int ACCOUNT_TYPE = 17;
85118
public static class AccountType{
86119
public static final int CHECKING = 170;
87120
public static final int SAVINGS = 171;
88121
}
122+
123+
public static final int INQUIRY_TYPE = 18;
89124
public static class InquiryType{
90125
public static final int RESERVED = 180;
91126
}
127+
92128
}

JavaSource/com/acminds/acuteauto/utils/EnumGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public static void main(String[] args) throws Exception {
3939
.append("\n");
4040
List<EnumType> types = eg.getEnumTypes();
4141
for(EnumType et:types) {
42+
sb.append("\t").append(MessageFormat.format(FIELD_DECL, new Object[]{et.getCodeName().toUpperCase(), et.getEnumTypeId()})).append("\n");
4243
sb.append(eg.getClassAsString(et)).append("\n");
4344
}
4445
sb.append(BRAC_CLOSE);
45-
System.out.println(sb.toString());
4646
FileUtils.writeStringToFile(new File(javaPath), sb.toString());
4747
}
4848

@@ -54,7 +54,7 @@ private String getClassAsString(EnumType type) {
5454
.append("\t\t")
5555
.append(MessageFormat.format(FIELD_DECL, new Object[]{e.getEnumValue().toUpperCase().replace(" ", "_"), e.getEnumId()}));
5656
}
57-
sb.append("\n\t").append(BRAC_CLOSE);
57+
sb.append("\n\t").append(BRAC_CLOSE).append("\n");
5858
return sb.toString();
5959
}
6060

JavaSource/sql/db-data.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ INSERT INTO ENUM VALUES ('46', '5', 'SUV', null, null);
128128
INSERT INTO ENUM VALUES ('47', '5', 'Hybrid', null, null);
129129
INSERT INTO ENUM VALUES ('48', '5', 'Convertible', null, null);
130130
INSERT INTO ENUM VALUES ('49', '5', 'Pickup', null, null);
131-
INSERT INTO ENUM VALUES ('50', '5', 'Van/Minivan', null, null);
131+
INSERT INTO ENUM VALUES ('50', '5', 'Minivan', null, null);
132132
INSERT INTO ENUM VALUES ('51', '5', 'Truck', null, null);
133133
-- CATEGORY_TYPE
134134
INSERT INTO ENUM VALUES ('60', '6', 'RESERVED', 'Reserved for Future Use', null);
@@ -168,7 +168,7 @@ INSERT INTO ENUM VALUES ('151', '15', 'Under Review', null, null);
168168
INSERT INTO ENUM VALUES ('152', '15', 'Approved', null, null);
169169
-- FINANCE_TYPE
170170
INSERT INTO ENUM VALUES ('160', '16', 'Purchase', null, null);
171-
INSERT INTO ENUM VALUES ('161', '17', 'Lease', null, null);
171+
INSERT INTO ENUM VALUES ('161', '16', 'Lease', null, null);
172172
-- ACCOUNT_TYPE
173173
INSERT INTO ENUM VALUES ('170', '17', 'Checking', null, null);
174174
INSERT INTO ENUM VALUES ('171', '17', 'Savings', null, null);

0 commit comments

Comments
 (0)