Revision 58708
Added by Konstantina Galouni almost 4 years ago
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 |
} |
Also available in: Unified diff
[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.