Project

General

Profile

« Previous | Next » 

Revision 58708

[Trunk | Monitor Service]:
1. Stakeholder.java: Field 'name' added.
2. Section.java: In method 'copyFromDefault()' initialize indicators (empty list).
3. StakeholderDAO.java & MongoDBStakeholderDAO.java: Added method 'Stakeholder findByTopicsContaining(String topic);' (needed to find in which Stakeholder a Topic belongs - section needs stakeholderAlias).
4. TopicDAO.java & MongoDBTopicDAO.java: Added method 'Topic findByCategoriesContaining(String category);' (needed to find in which Topic a Category belongs - section needs stakeholderAlias).
5. CategoryDAO.java & MongoDBCategoryDAO.java: Added method 'Category findBySubCategoriesContaining(String subCategory);' (needed to find in which Category a SubCategory belongs - section needs stakeholderAlias).
6. TopicController.java & CategoryController.java & SubCategoryController.java & SectionController.java & IndicatorController.java:
Bug fixes & changed logic for updates on default profile: When a value in a profile is same as the value in default, inherit changes in default value, otherwise keep local profile's options.

View differences:

modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBStakeholderDAO.java
15 15
    List<Stakeholder> findByDefaultIdNot(String DefaultId);
16 16
    List<Stakeholder> findByDefaultIdNotAndType(String DefaultId, String Type);
17 17

  
18
    Stakeholder findByTopicsContaining(String topic);
19

  
18 20
    Stakeholder findById(String Id);
19 21
    Stakeholder findByAlias(String Alias);
20 22

  
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/dao/CategoryDAO.java
8 8
    List<Category> findAll();
9 9
    List<Category> findByDefaultId(String DefaultId);
10 10

  
11
    Category findBySubCategoriesContaining(String subCategory);
12

  
11 13
    Category findById(String Id);
12 14

  
13 15
    void delete(String Id);
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/dao/TopicDAO.java
8 8
    List<Topic> findAll();
9 9
    List<Topic> findByDefaultId(String DefaultId);
10 10

  
11
    Topic findByCategoriesContaining(String category);
12

  
11 13
    Topic findById(String Id);
12 14

  
13 15
    void delete(String Id);
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBCategoryDAO.java
9 9
    List<Category> findAll();
10 10
    List<Category> findByDefaultId(String DefaultId);
11 11

  
12
    Category findBySubCategoriesContaining(String subCategory);
13

  
12 14
    Category findById(String Id);
13 15

  
14 16
    void delete(String Id);
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBTopicDAO.java
9 9
    List<Topic> findAll();
10 10
    List<Topic> findByDefaultId(String DefaultId);
11 11

  
12
    Topic findByCategoriesContaining(String category);
13

  
12 14
    Topic findById(String Id);
13 15

  
14 16
    void delete(String Id);
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/dao/StakeholderDAO.java
14 14
    List<Stakeholder> findByDefaultIdNot(String DefaultId);
15 15
    List<Stakeholder> findByDefaultIdNotAndType(String DefaultId, String Type);
16 16

  
17
    Stakeholder findByTopicsContaining(String topic);
18

  
17 19
    Stakeholder findById(String Id);
18 20
    Stakeholder findByAlias(String Alias);
19 21

  
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/entities/Section.java
3 3
import com.fasterxml.jackson.annotation.JsonProperty;
4 4
import org.springframework.data.annotation.Id;
5 5

  
6
import java.util.ArrayList;
6 7
import java.util.List;
7 8

  
8 9
enum SectionType {
......
35 36
        setTitle(defaultSection.getTitle());
36 37
        setType(defaultSection.getType());
37 38
        setDefaultId(defaultSection.id);
39
        setIndicators(new ArrayList<>());
38 40
    }
39 41

  
40 42
    public String getId() {
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/entities/Stakeholder.java
24 24
    private String index_name;
25 25
    private String index_shortName;
26 26
    private String logoUrl;
27
    private String name;
27 28
    private String alias;
28 29
    private String defaultId = null;
29 30
    private boolean isActive;
......
44 45
        index_name = stakeholder.getIndex_name();
45 46
        index_shortName = stakeholder.getIndex_shortName();
46 47
        logoUrl = stakeholder.getLogoUrl();
48
        name = stakeholder.getName();
47 49
        alias = stakeholder.getAlias();
48 50
        defaultId = stakeholder.getDefaultId();
49 51
        isActive = stakeholder.getIsActive();
......
117 119
        this.logoUrl = logoUrl;
118 120
    }
119 121

  
122
    public String getName() { return name; }
123

  
124
    public void setName(String name) { this.name = name; }
125
    
120 126
    public String getAlias() {
121 127
        return alias;
122 128
    }
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java
12 12
import java.io.UnsupportedEncodingException;
13 13
import java.net.URLEncoder;
14 14
import java.util.ArrayList;
15
import java.util.HashMap;
15 16
import java.util.List;
16 17
import java.util.Map;
17 18

  
......
51 52

  
52 53
        Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType());
53 54

  
55
        Indicator oldIndicator = null;
56
        if(indicator.getId() != null) {
57
            oldIndicator = indicatorDAO.findById(indicator.getId());
58
        }
59

  
54 60
        String indicatorId = indicator.getId();
55 61
        indicatorDAO.save(indicator);
56 62

  
......
61 67
                onSaveDefaultIndicator(indicator, sectionId);
62 68
            }
63 69
            else {
64
                onUpdateDefaultIndicator(indicator, stakeholder);
70
                onUpdateDefaultIndicator(indicator, stakeholder, oldIndicator);
65 71
            }
66 72
        }
67 73

  
......
100 106
        }
101 107
    }
102 108

  
103
    public void onUpdateDefaultIndicator(Indicator indicator, Stakeholder stakeholder) throws UnsupportedEncodingException {
109
    public void onUpdateDefaultIndicator(Indicator indicator, Stakeholder stakeholder, Indicator oldIndicator) throws UnsupportedEncodingException {
104 110
        log.debug("On update default indicator");
105 111

  
106 112
        // indicator already exists - check if changed and update all indicators based on it
......
109 115
        List<Indicator> indicators = indicatorDAO.findByDefaultId(indicator.getId());
110 116

  
111 117
        for(Indicator indicatorBasedOnDefault : indicators) {
118
            if(indicator.getName() != null && !indicator.getName().equals(indicatorBasedOnDefault.getName())
119
                    && (oldIndicator.getName() == null || oldIndicator.getName().equals(indicatorBasedOnDefault.getName()))) {
120

  
121
                indicatorBasedOnDefault.setName(indicator.getName());
122
                changed = true;
123
            }
124

  
125
            if(indicator.getDescription() != null && !indicator.getDescription().equals(indicatorBasedOnDefault.getDescription())
126
                    && (oldIndicator.getDescription() == null || oldIndicator.getDescription().equals(indicatorBasedOnDefault.getDescription()))) {
127

  
128
                indicatorBasedOnDefault.setName(indicator.getName());
129
                changed = true;
130
            }
131

  
112 132
            int i = 0;
113 133
            List<IndicatorPath> indicatorPaths = indicatorBasedOnDefault.getIndicatorPaths();
114 134

  
......
122 142
                    indicatorPaths.add(indicatorPathNew);
123 143
                    changed = true;
124 144
                } else {
145
                    IndicatorPath oldIndicatorPath = oldIndicator.getIndicatorPaths().get(i);
146

  
125 147
                    // Check if there are changes in indicator path and update existing indicators if needed
126
                    if(!indicatorPath.getType().equals(indicatorPathBasedOnDefault.getType())) {
148
                    log.debug("update indicator path: "+i);
149
                    if(!indicatorPath.getType().equals(indicatorPathBasedOnDefault.getType())
150
                            && (oldIndicatorPath.getType().equals(indicatorPathBasedOnDefault.getType()))) {
151

  
127 152
                        indicatorPathBasedOnDefault.setType(indicatorPath.getType());
128
                        changed = true;
153
                        changed = true; // parameter "type" needs to be changed as well
129 154
                    }
130
                    if(!indicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource())) {
155
                    log.debug("After type check: "+changed);
156

  
157
                    if(!indicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource())
158
                            && (oldIndicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource()))) {
159

  
131 160
                        indicatorPathBasedOnDefault.setSource(indicatorPath.getSource());
132 161
                        changed = true;
133 162
                    }
134
                    if(!indicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl())) {
163
                    log.debug("After source check: "+changed);
164

  
165
                    if(!indicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl())
166
                            && (oldIndicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl()))) {
167

  
135 168
                        indicatorPathBasedOnDefault.setUrl(indicatorPath.getUrl());
136 169
                        changed = true;
137 170
                    }
138
                    if(!indicatorPath.getChartObject().equals(indicatorPathBasedOnDefault.getChartObject())) {
171
                    log.debug("After url check: "+changed);
172

  
173
                    if(!indicatorPath.getChartObject().equals(indicatorPathBasedOnDefault.getChartObject())
174
                            && (oldIndicatorPath.getChartObject().equals(indicatorPathBasedOnDefault.getChartObject()))) {
175

  
139 176
                        indicatorPathBasedOnDefault.setChartObject(indicatorPath.getChartObject());
140 177
                        changed = true;
141 178
                    }
142
                    if(indicatorPath.getParameters().size() != indicatorPathBasedOnDefault.getParameters().size()) {
143
                        for (Map.Entry<String, String> parameter : indicatorPath.getParameters().entrySet()) {
144
                            if(!indicatorPathBasedOnDefault.getParameters().containsKey(parameter.getKey())) {
145
                                indicatorPathBasedOnDefault.getParameters().put(parameter.getKey(), parameter.getValue());
179
                    log.debug("After chartObject check: "+changed);
180

  
181
                    if(indicatorPath.getParameters() != null) {
182
                        if (indicatorPathBasedOnDefault.getParameters() == null) {
183
                            indicatorPathBasedOnDefault.setParameters(new HashMap<>());
184
                        }
185
                        //if (indicatorPath.getParameters().size() != indicatorPathBasedOnDefault.getParameters().size()) {
186
                            //log.debug("Different number of parameters");
187
                            for (Map.Entry<String, String> parameter : indicatorPath.getParameters().entrySet()) {
188
                                log.debug("\nindicatorPath: parameter.getKey(): "+parameter.getKey()+" - value: "+parameter.getValue()
189
                                        +"\nindicatorPathBasedOnDefault:parameters:key: "+  indicatorPathBasedOnDefault.getParameters().get(parameter.getKey())
190
                                        +"\noldIndicatorPath:parameters:key: "+  oldIndicatorPath.getParameters().get(parameter.getKey()));
191
                                if (!indicatorPathBasedOnDefault.getParameters().containsKey(parameter.getKey())
192
                                        || (oldIndicatorPath.getParameters() == null
193
                                            || (oldIndicatorPath.getParameters().get(parameter.getKey()).equals(indicatorPathBasedOnDefault.getParameters().get(parameter.getKey()))
194
                                                && !parameter.getValue().equals(indicatorPathBasedOnDefault.getParameters().get(parameter.getKey()))))
195
                                ) {
196
                                    indicatorPathBasedOnDefault.getParameters().put(parameter.getKey(), parameter.getValue());
197
                                    changed = true;
198
                                }
199
//                                else if(parameter.getKey().equals("type")) {
200
//                                    indicatorPathBasedOnDefault.getParameters().put(parameter.getKey(), parameter.getValue());
201
//                                    changed = true;
202
//                                }
146 203
                            }
147
                        }
148
                        parameterMapping(indicatorPathBasedOnDefault, stakeholder);
149
                        changed = true;
204
                            parameterMapping(indicatorPathBasedOnDefault, stakeholder);
205
                        //}
206
                        log.debug("After parameters check: " + changed);
150 207
                    }
151
                    int j=0;
152
                    for(String jsonString : indicatorPath.getJsonPath()) {
153
                        String jsonStringBasedOnDefault = indicatorPathBasedOnDefault.getJsonPath().get(j);
154
                        if(!jsonString.equals(jsonStringBasedOnDefault)) {
155
                            indicatorPathBasedOnDefault.getJsonPath().set(j, jsonString);
156
                            changed = true;
208

  
209
                    if(indicatorPath.getJsonPath() != null) {
210
                        int j = 0;
211
                        for (String jsonString : indicatorPath.getJsonPath()) {
212
                            log.debug("indicatorPath.getJsonPath(): " + jsonString);
213
                            String jsonStringBasedOnDefault = null;
214
                            if(indicatorPathBasedOnDefault.getJsonPath() != null ) {
215
                                jsonStringBasedOnDefault = indicatorPathBasedOnDefault.getJsonPath().get(j);
216
                            } else {
217
                                indicatorPathBasedOnDefault.setJsonPath(new ArrayList<>());
218
                            }
219
                            log.debug("indicatorPathBasedOnDefault.getJsonPath().get(" + j + "): " + jsonStringBasedOnDefault);
220

  
221
                            if (!jsonString.equals(jsonStringBasedOnDefault)
222
                                    && (oldIndicatorPath.getJsonPath() == null
223
                                    || oldIndicatorPath.getJsonPath().get(i).equals(jsonStringBasedOnDefault))
224
                            ) {
225
                                indicatorPathBasedOnDefault.getJsonPath().set(j, jsonString);
226
                                changed = true;
227
                            }
228
                            j++;
157 229
                        }
158
                        j++;
230
                        log.debug("After jsonPath check: " + changed);
159 231
                    }
160 232
                }
161 233
                i++;
162 234
            }
235

  
163 236
            if(!changed) {
164
                break;
237
//                break;
238
                continue;
165 239
            }
240

  
166 241
            indicatorDAO.save(indicatorBasedOnDefault);
167 242
        }
168 243
    }
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java
66 66
        Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
67 67

  
68 68
        if(stakeholder != null) {
69
            Category<String> oldCategory = null;
70
            if(categoryFull.getId() != null) {
71
                oldCategory = categoryDAO.findById(categoryFull.getId());
72
            }
69 73

  
70 74
            Topic<String> topic = topicDAO.findById(topicId);
71 75
            if(topic != null) {
......
95 99
                        if(categoryFull.getId() == null) {
96 100
                            onSaveDefaultCategory(category, topicId);
97 101
                        } else {
98
                            onUpdateDefaultCategory(category);
102
                            onUpdateDefaultCategory(category, oldCategory);
99 103
                        }
100 104
                    }
101 105

  
......
146 150
        subCategoryController.onSaveDefaultSubCategory(subCategoryOverview, category.getId());
147 151
    }
148 152

  
149
    public void onUpdateDefaultCategory(Category category) {
153
    public void onUpdateDefaultCategory(Category category, Category oldCategory) {
150 154
        log.debug("On update default category");
151 155

  
152 156
        List<Category> categories = categoryDAO.findByDefaultId(category.getId());
153 157
        boolean changed = false;
154 158
        for(Category categoryBasedOnDefault : categories) {
155
            if(category.getName() != null && !category.getName().equals(categoryBasedOnDefault.getName())) {
159
            if(category.getName() != null && !category.getName().equals(categoryBasedOnDefault.getName())
160
                    && (oldCategory.getName() == null || oldCategory.getName().equals(categoryBasedOnDefault.getName()))) {
161

  
162
                categoryBasedOnDefault.setName(category.getName());
156 163
                changed = true;
157 164
            }
158
            if(category.getDescription() != null && !category.getDescription().equals(categoryBasedOnDefault.getDescription())) {
165
            if(category.getDescription() != null && !category.getDescription().equals(categoryBasedOnDefault.getDescription())
166
                    && (oldCategory.getDescription() == null || oldCategory.getDescription().equals(categoryBasedOnDefault.getDescription()))) {
167

  
168
                categoryBasedOnDefault.setDescription(category.getDescription());
159 169
                changed = true;
160 170
            }
161 171

  
162 172
            if(!changed) {
163
                break;
173
//                break;
174
                continue;
164 175
            }
165
            categoryBasedOnDefault.setName(category.getName());
166
            categoryBasedOnDefault.setDescription(category.getDescription());
176

  
177
//            categoryBasedOnDefault.setName(category.getName());
178
//            categoryBasedOnDefault.setDescription(category.getDescription());
167 179
            categoryDAO.save(categoryBasedOnDefault);
168 180
        }
169 181
    }
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TopicController.java
65 65
        Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
66 66

  
67 67
        if(stakeholder != null) {
68
            Topic<String> oldTopic = null;
69
            if(topicFull.getId() != null) {
70
                oldTopic = topicDAO.findById(topicFull.getId());
71
            }
68 72

  
69 73
            Topic<String> topic = new Topic<>(topicFull);
70 74

  
......
80 84
                if(topicFull.getId() == null) {
81 85
                    onSaveDefaultTopic(topic, stakeholderId);
82 86
                } else {
83
                    onUpdateDefaultTopic(topic);
87
                    onUpdateDefaultTopic(topic, oldTopic);
84 88
                }
85 89
            }
86 90

  
......
120 124
        }
121 125
    }
122 126

  
123
    public void onUpdateDefaultTopic(Topic topic) {
127
    public void onUpdateDefaultTopic(Topic topic, Topic oldTopic) {
124 128
        log.debug("On update default topic");
125 129

  
126 130
        List<Topic> topics = topicDAO.findByDefaultId(topic.getId());
127 131
        boolean changed = false;
128 132
        for(Topic topicBasedOnDefault : topics) {
129
            if(topic.getName() != null && !topic.getName().equals(topicBasedOnDefault.getName())) {
133
            if(topic.getName() != null && !topic.getName().equals(topicBasedOnDefault.getName())
134
                    && (oldTopic.getName() == null || oldTopic.getName().equals(topicBasedOnDefault.getName()))) {
135

  
136
                topicBasedOnDefault.setName(topic.getName());
130 137
                changed = true;
131 138
            }
132
            if(topic.getDescription() != null && !topic.getDescription().equals(topicBasedOnDefault.getDescription())) {
139
            if(topic.getDescription() != null && !topic.getDescription().equals(topicBasedOnDefault.getDescription())
140
                    && (oldTopic.getDescription() == null || oldTopic.getDescription().equals(topicBasedOnDefault.getDescription()))) {
141

  
142
                topicBasedOnDefault.setDescription(topic.getDescription());
133 143
                changed = true;
134 144
            }
135 145

  
136 146
            if(!changed) {
137
                break;
147
//                break;
148
                continue;
138 149
            }
139
            topicBasedOnDefault.setName(topic.getName());
140
            topicBasedOnDefault.setDescription(topic.getDescription());
150

  
151
//            topicBasedOnDefault.setName(topic.getName());
152
//            topicBasedOnDefault.setDescription(topic.getDescription());
141 153
            topicDAO.save(topicBasedOnDefault);
142 154
        }
143 155
    }
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SectionController.java
65 65
        log.debug("Name: "+sectionFull.getTitle() + " - Id: "+sectionFull.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
66 66

  
67 67
        SubCategory<String> subCategory = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId);
68

  
69
        Section<String> oldSection = null;
70
        if(sectionFull.getId() != null) {
71
            oldSection = sectionDAO.findById(sectionFull.getId());
72
        }
73

  
68 74
        Section<String> section = new Section<>(sectionFull);
69 75

  
70 76
        String sectionId = sectionFull.getId();
......
82 88
                onSaveDefaultSection(section, topicId, categoryId, subcategoryId, stakeholder);
83 89
            }
84 90
            else {
85
                onUpdateDefaultSection(section, stakeholder);
91
                onUpdateDefaultSection(section, stakeholder, oldSection);
86 92
            }
87 93
        }
88 94

  
......
119 125
        List<SubCategory> subCategories = subCategoryDAO.findByDefaultId(defaultSubcategoryId);
120 126

  
121 127
        for (SubCategory subCategory : subCategories) {
128
            Category parentCategory = categoryDAO.findBySubCategoriesContaining(subCategory.getId());
129
            Topic parentTopic = topicDAO.findByCategoriesContaining(parentCategory.getId());
130
            Stakeholder parentStakeholder = stakeholderDAO.findByTopicsContaining(parentTopic.getId());
131

  
122 132
            Section sectionNew = new Section();
123 133
            sectionNew.copyFromDefault(section);
124 134

  
135
            sectionNew.setStakeholderAlias(parentStakeholder.getAlias());
136

  
125 137
            sectionDAO.save(sectionNew);
126 138

  
127 139
            List<String> sections = null;
......
136 148
        }
137 149
    }
138 150

  
139
    public void onUpdateDefaultSection(Section section, Stakeholder stakeholder) {
151
    public void onUpdateDefaultSection(Section section, Stakeholder stakeholder, Section oldSection) {
140 152
        log.debug("On update default section");
141 153

  
142 154
        // section already exists - check if changed and update all sections based on it
......
145 157
        List<Section> sections = sectionDAO.findByDefaultId(section.getId());
146 158

  
147 159
        for(Section sectionBasedOnDefault : sections) {
148
            if(section.getTitle() != null && !section.getTitle().equals(sectionBasedOnDefault.getTitle())) {
160
            if(section.getTitle() != null && !section.getTitle().equals(sectionBasedOnDefault.getTitle())
161
                    && (oldSection.getTitle() == null || oldSection.getTitle().equals(sectionBasedOnDefault.getTitle()))) {
162

  
163
                sectionBasedOnDefault.setTitle(section.getTitle());
149 164
                changed = true;
150 165
            }
151 166

  
152 167
            if(!changed) {
153
                break;
168
//                break;
169
                continue;
154 170
            }
155 171

  
156
            sectionBasedOnDefault.setTitle(section.getTitle());
172
//            sectionBasedOnDefault.setTitle(section.getTitle());
157 173
            sectionDAO.save(sectionBasedOnDefault);
158 174
        }
159 175
    }
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SubCategoryController.java
77 77
        log.debug("Alias: "+subcategoryFull.getAlias() + " - Id: "+subcategoryFull.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId);
78 78

  
79 79
        Category category = checkForExceptions(stakeholderId, topicId, categoryId);
80

  
81
        SubCategory<String> oldSubcategory = null;
82
        if(subcategoryFull.getId() != null) {
83
            oldSubcategory = subCategoryDAO.findById(subcategoryFull.getId());
84
        }
85

  
80 86
        SubCategory<String> subCategory = new SubCategory<>(subcategoryFull);
81 87

  
82 88
//        List<String> charts = new ArrayList<>();
......
110 116
            if(subcategoryFull.getId() == null) {
111 117
                onSaveDefaultSubCategory(subCategory, categoryId);
112 118
            } else {
113
                onUpdateDefaultSubCategory(subCategory);
119
                onUpdateDefaultSubCategory(subCategory, oldSubcategory);
114 120
            }
115 121
        }
116 122

  
......
148 154
        }
149 155
    }
150 156

  
151
    public void onUpdateDefaultSubCategory(SubCategory subCategory) {
157
    public void onUpdateDefaultSubCategory(SubCategory subCategory, SubCategory oldSubcategory) {
152 158
        log.debug("On update default subCategory");
153 159

  
154 160
        List<SubCategory> subCategories = subCategoryDAO.findByDefaultId(subCategory.getId());
155 161
        boolean changed = false;
156 162
        for(SubCategory subCategoryBasedOnDefault : subCategories) {
157
            if(subCategory.getName() != null && !subCategory.getName().equals(subCategoryBasedOnDefault.getName())) {
163
            if(subCategory.getName() != null && !subCategory.getName().equals(subCategoryBasedOnDefault.getName())
164
                    && (oldSubcategory.getName() == null || oldSubcategory.getName().equals(subCategoryBasedOnDefault.getName()))) {
165

  
166
                subCategoryBasedOnDefault.setName(subCategory.getName());
158 167
                changed = true;
159 168
            }
160
            if(subCategory.getDescription() != null && !subCategory.getDescription().equals(subCategoryBasedOnDefault.getDescription())) {
169
            if(subCategory.getDescription() != null && !subCategory.getDescription().equals(subCategoryBasedOnDefault.getDescription())
170
                    && (oldSubcategory.getDescription() == null || oldSubcategory.getDescription().equals(subCategoryBasedOnDefault.getDescription()))) {
171

  
172
                subCategoryBasedOnDefault.setDescription(subCategory.getDescription());
161 173
                changed = true;
162 174
            }
163 175

  
164 176
            if(!changed) {
165
                break;
177
//                break;
178
                continue;
166 179
            }
167
            subCategoryBasedOnDefault.setName(subCategory.getName());
168
            subCategoryBasedOnDefault.setDescription(subCategory.getDescription());
180

  
181
//            subCategoryBasedOnDefault.setName(subCategory.getName());
182
//            subCategoryBasedOnDefault.setDescription(subCategory.getDescription());
169 183
            subCategoryDAO.save(subCategoryBasedOnDefault);
170 184
        }
171 185
    }

Also available in: Unified diff