@@ -29,8 +29,16 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
2929 request .setCharacterEncoding ("UTF-8" );
3030 String uuid = request .getParameter ("uuid" );
3131 String fullName = request .getParameter ("fullName" );
32- Resume r = storage .get (uuid );
33- r .setFullName (fullName );
32+
33+ final boolean isCreate = (uuid == null || uuid .length () == 0 );
34+ Resume r ;
35+ if (isCreate ) {
36+ r = new Resume (fullName );
37+ } else {
38+ r = storage .get (uuid );
39+ r .setFullName (fullName );
40+ }
41+
3442 for (ContactType type : ContactType .values ()) {
3543 String value = request .getParameter (type .name ());
3644 if (HtmlUtil .isEmpty (value )) {
@@ -80,7 +88,11 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
8088 }
8189 }
8290 }
83- storage .update (r );
91+ if (isCreate ) {
92+ storage .save (r );
93+ } else {
94+ storage .update (r );
95+ }
8496 response .sendRedirect ("resume" );
8597 }
8698
@@ -101,21 +113,43 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
101113 case "view" :
102114 r = storage .get (uuid );
103115 break ;
116+ case "add" :
117+ r = Resume .EMPTY ;
118+ break ;
104119 case "edit" :
105120 r = storage .get (uuid );
106- for (SectionType type : new SectionType []{SectionType .EXPERIENCE , SectionType .EDUCATION }) {
107- OrganizationSection section = (OrganizationSection ) r .getSection (type );
108- List <Organization > emptyFirstOrganizations = new ArrayList <>();
109- emptyFirstOrganizations .add (Organization .EMPTY );
110- if (section != null ) {
111- for (Organization org : section .getOrganizations ()) {
112- List <Organization .Position > emptyFirstPositions = new ArrayList <>();
113- emptyFirstPositions .add (Organization .Position .EMPTY );
114- emptyFirstPositions .addAll (org .getPositions ());
115- emptyFirstOrganizations .add (new Organization (org .getHomePage (), emptyFirstPositions ));
116- }
121+ for (SectionType type : SectionType .values ()) {
122+ Section section = r .getSection (type );
123+ switch (type ) {
124+ case OBJECTIVE :
125+ case PERSONAL :
126+ if (section == null ) {
127+ section = TextSection .EMPTY ;
128+ }
129+ break ;
130+ case ACHIEVEMENT :
131+ case QUALIFICATIONS :
132+ if (section == null ) {
133+ section = ListSection .EMPTY ;
134+ }
135+ break ;
136+ case EXPERIENCE :
137+ case EDUCATION :
138+ OrganizationSection orgSection = (OrganizationSection ) section ;
139+ List <Organization > emptyFirstOrganizations = new ArrayList <>();
140+ emptyFirstOrganizations .add (Organization .EMPTY );
141+ if (orgSection != null ) {
142+ for (Organization org : orgSection .getOrganizations ()) {
143+ List <Organization .Position > emptyFirstPositions = new ArrayList <>();
144+ emptyFirstPositions .add (Organization .Position .EMPTY );
145+ emptyFirstPositions .addAll (org .getPositions ());
146+ emptyFirstOrganizations .add (new Organization (org .getHomePage (), emptyFirstPositions ));
147+ }
148+ }
149+ section = new OrganizationSection (emptyFirstOrganizations );
150+ break ;
117151 }
118- r .setSection (type , new OrganizationSection ( emptyFirstOrganizations ) );
152+ r .setSection (type , section );
119153 }
120154 break ;
121155 default :
0 commit comments