Skip to content

Commit 94e3f19

Browse files
admin: Tax Zones
1 parent 1859f70 commit 94e3f19

File tree

6 files changed

+127
-396
lines changed

6 files changed

+127
-396
lines changed

src/main/java/org/woehlke/greenshop/admin/AdminLocationTaxesController.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import javax.validation.Valid;
2020
import java.util.Date;
2121
import java.util.List;
22+
import java.util.Map;
2223

2324
/**
2425
* Created by tw on 04.01.15.
@@ -246,6 +247,10 @@ public String taxZoneInsertForm(@PathVariable long taxZoneId, Model model){
246247
thisZone = zones.iterator().next();
247248
}
248249
model.addAttribute("thisZone",thisZone);
250+
Map<Long,List<Zone>> zoneMap = adminService.getZoneMap();
251+
model.addAttribute("zoneMap",zoneMap);
252+
List<Country> countries = customerService.findAllCountriesOrderByName();
253+
model.addAttribute("countries",countries);
249254
return "admin/taxZoneInsertForm";
250255
}
251256

@@ -315,6 +320,10 @@ public String taxZoneWithZoneIdEditForm(@PathVariable long taxZoneId, @PathVaria
315320
model.addAttribute("zones",zones);
316321
TaxZone2Zone thisZone = adminService.findTaxZone2ZoneById(zoneId);
317322
model.addAttribute("thisZone",thisZone);
323+
Map<Long,List<Zone>> zoneMap = adminService.getZoneMap();
324+
model.addAttribute("zoneMap",zoneMap);
325+
List<Country> countries = customerService.findAllCountriesOrderByName();
326+
model.addAttribute("countries",countries);
318327
return "admin/taxZoneEditForm";
319328
}
320329

src/main/java/org/woehlke/greenshop/admin/AdminService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
import org.woehlke.greenshop.checkout.entities.OrderStatus;
1212
import org.woehlke.greenshop.checkout.entities.OrderStatusId;
1313
import org.woehlke.greenshop.customer.entities.Customer;
14+
import org.woehlke.greenshop.customer.entities.Zone;
1415
import org.woehlke.greenshop.customer.model.CustomerBean;
1516

1617
import java.util.List;
18+
import java.util.Map;
1719

1820
/**
1921
* Created by tw on 31.12.14.
@@ -89,4 +91,7 @@ public interface AdminService extends UserDetailsService {
8991
void deleteTaxZone2Zone(TaxZone2Zone thisZone);
9092

9193
void updateTaxZone2Zone(TaxZone2Zone thisZone);
94+
95+
Map<Long, List<Zone>> getZoneMap();
96+
9297
}

src/main/java/org/woehlke/greenshop/admin/AdminServiceImpl.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,15 @@
2121
import org.woehlke.greenshop.checkout.repository.OrderTotalRepository;
2222
import org.woehlke.greenshop.customer.entities.Customer;
2323
import org.woehlke.greenshop.customer.entities.CustomerInfo;
24+
import org.woehlke.greenshop.customer.entities.Zone;
2425
import org.woehlke.greenshop.customer.model.CustomerBean;
2526
import org.woehlke.greenshop.customer.repository.CustomerInfoRepository;
2627
import org.woehlke.greenshop.customer.repository.CustomerRepository;
2728
import org.woehlke.greenshop.customer.repository.ZoneRepository;
2829

2930
import javax.inject.Inject;
3031
import javax.inject.Named;
31-
import java.util.ArrayList;
32-
import java.util.Date;
33-
import java.util.List;
32+
import java.util.*;
3433

3534
/**
3635
* Created by tw on 31.12.14.
@@ -368,4 +367,23 @@ public void deleteTaxZone2Zone(TaxZone2Zone thisZone) {
368367
public void updateTaxZone2Zone(TaxZone2Zone thisZone) {
369368
taxZone2ZoneRepository.save(thisZone);
370369
}
370+
371+
@Override
372+
public Map<Long, List<Zone>> getZoneMap() {
373+
List<Zone> zones = zoneRepository.findAll();
374+
Map<Long, List<Zone>> zoneMap = new LinkedHashMap<>();
375+
List<Zone> subZoneList = new ArrayList<>();
376+
long countryId = 0;
377+
for(Zone zone: zones){
378+
if(countryId != zone.getCountry().getId()){
379+
if(subZoneList.size()>0){
380+
zoneMap.put(countryId,subZoneList);
381+
subZoneList = new ArrayList<>();
382+
}
383+
countryId = zone.getCountry().getId();
384+
}
385+
subZoneList.add(zone);
386+
}
387+
return zoneMap;
388+
}
371389
}

src/main/webapp/WEB-INF/jsp/admin/taxZoneEditForm.jsp

Lines changed: 35 additions & 197 deletions
Large diffs are not rendered by default.

src/main/webapp/WEB-INF/jsp/admin/taxZoneInsertForm.jsp

Lines changed: 13 additions & 196 deletions
Large diffs are not rendered by default.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.woehlke.greenshop.admin;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
import org.junit.runner.RunWith;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
import org.springframework.test.context.ContextConfiguration;
9+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
10+
import org.springframework.test.context.web.WebAppConfiguration;
11+
import org.woehlke.greenshop.customer.entities.Zone;
12+
13+
import javax.inject.Inject;
14+
import java.util.List;
15+
import java.util.Map;
16+
17+
/**
18+
* Created by tw on 29.01.15.
19+
*/
20+
@WebAppConfiguration
21+
@RunWith(SpringJUnit4ClassRunner.class)
22+
@ContextConfiguration("classpath:/servlet-context.xml")
23+
public class AdminServiceImplTest {
24+
25+
private static final Logger logger = LoggerFactory.getLogger(AdminServiceImplTest.class);
26+
27+
@Inject
28+
private AdminService adminService;
29+
30+
@Test
31+
public void getZoneMapTest() throws Exception {
32+
logger.info("------------------------------------------------------");
33+
Map<Long, List<Zone>> zoneMap = adminService.getZoneMap();
34+
logger.info("------------------------------------------------------");
35+
for(Long countryId:zoneMap.keySet()){
36+
logger.info("## CountryId: "+countryId+" ##");
37+
for(Zone zone: zoneMap.get(countryId)){
38+
logger.info("#### Zone: "+zone.toString());
39+
Assert.assertEquals(countryId,zone.getCountry().getId());
40+
}
41+
}
42+
logger.info("------------------------------------------------------");
43+
}
44+
}

0 commit comments

Comments
 (0)