##### Coverage Report - com.ctrip.apollo.biz.service.ItemSetService

Classes in this File | Line Coverage | Branch Coverage | Complexity
ItemSetService |
3% | 1/27
0% | 0/12
| 7.0;7

1 |  |
     package com.ctrip.apollo.biz.service;
2 |  |
3 |  |
     import org.springframework.beans.factory.annotation.Autowired;
4 |  |
     import org.springframework.stereotype.Service;
5 |  |
     import org.springframework.transaction.annotation.Transactional;
6 |  |
7 |  |
     import com.ctrip.apollo.biz.entity.Audit;
8 |  |
     import com.ctrip.apollo.biz.entity.Item;
9 |  |
     import com.ctrip.apollo.biz.repository.ItemRepository;
10 |  |
     import com.ctrip.apollo.common.utils.BeanUtils;
11 |  |
     import com.ctrip.apollo.core.dto.ItemChangeSets;
12 |  |
     import com.ctrip.apollo.core.dto.ItemDTO;
13 |  |
14 |  |
     @Service
15 | 1 |
     public class ItemSetService {
16 |  |
17 |  |
       @Autowired
18 |  |
       private ItemRepository itemRepository;
19 |  |
20 |  |
       @Autowired
21 |  |
       private AuditService auditService;
22 |  |
23 |  |
       @Transactional
24 |  |
       public void updateSet(ItemChangeSets changeSet, String owner) {
25 | 0 |
         if (changeSet.getCreateItems() != null) {
26 | 0 |
           for (ItemDTO item : changeSet.getCreateItems()) {
27 | 0 |
             Item entity = BeanUtils.transfrom(Item.class, item);
28 | 0 |
             entity.setDataChangeCreatedBy(owner);
29 | 0 |
             entity.setDataChangeLastModifiedBy(owner);
30 | 0 |
             itemRepository.save(entity);
31 | 0 |
           }
32 | 0 |
           auditService.audit("ItemSet", null, Audit.OP.INSERT, owner);
33 |  |
         }
34 |  |
35 | 0 |
         if (changeSet.getUpdateItems() != null) {
36 | 0 |
           for (ItemDTO item : changeSet.getUpdateItems()) {
37 | 0 |
             Item entity = BeanUtils.transfrom(Item.class, item);
38 | 0 |
             Item managedItem = itemRepository.findOne(entity.getId());
39 | 0 |
             BeanUtils.copyEntityProperties(entity, managedItem);
40 | 0 |
             managedItem.setDataChangeLastModifiedBy(owner);
41 | 0 |
             itemRepository.save(managedItem);
42 | 0 |
           }
43 | 0 |
           auditService.audit("ItemSet", null, Audit.OP.UPDATE, owner);
44 |  |
         }
45 |  |
46 | 0 |
         if (changeSet.getDeleteItems() != null) {
47 | 0 |
           for (ItemDTO item : changeSet.getDeleteItems()) {
48 | 0 |
             Item entity = BeanUtils.transfrom(Item.class, item);
49 | 0 |
             entity.setDataChangeLastModifiedBy(owner);
50 | 0 |
             itemRepository.save(entity);
51 | 0 |
             itemRepository.delete(item.getId());
52 | 0 |
           }
53 | 0 |
           auditService.audit("ItemSet", null, Audit.OP.DELETE, owner);
54 |  |
         }
55 | 0 |
       }
56 |  |
     }