[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.
This commit is contained in:
Konstantina Galouni 2020-05-18 09:17:05 +00:00
parent f522d373ed
commit 67cf2d9812
13 changed files with 197 additions and 48 deletions

View File

@ -66,6 +66,10 @@ public class CategoryController {
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
if(stakeholder != null) {
Category<String> oldCategory = null;
if(categoryFull.getId() != null) {
oldCategory = categoryDAO.findById(categoryFull.getId());
}
Topic<String> topic = topicDAO.findById(topicId);
if(topic != null) {
@ -95,7 +99,7 @@ public class CategoryController {
if(categoryFull.getId() == null) {
onSaveDefaultCategory(category, topicId);
} else {
onUpdateDefaultCategory(category);
onUpdateDefaultCategory(category, oldCategory);
}
}
@ -146,24 +150,32 @@ public class CategoryController {
subCategoryController.onSaveDefaultSubCategory(subCategoryOverview, category.getId());
}
public void onUpdateDefaultCategory(Category category) {
public void onUpdateDefaultCategory(Category category, Category oldCategory) {
log.debug("On update default category");
List<Category> categories = categoryDAO.findByDefaultId(category.getId());
boolean changed = false;
for(Category categoryBasedOnDefault : categories) {
if(category.getName() != null && !category.getName().equals(categoryBasedOnDefault.getName())) {
if(category.getName() != null && !category.getName().equals(categoryBasedOnDefault.getName())
&& (oldCategory.getName() == null || oldCategory.getName().equals(categoryBasedOnDefault.getName()))) {
categoryBasedOnDefault.setName(category.getName());
changed = true;
}
if(category.getDescription() != null && !category.getDescription().equals(categoryBasedOnDefault.getDescription())) {
if(category.getDescription() != null && !category.getDescription().equals(categoryBasedOnDefault.getDescription())
&& (oldCategory.getDescription() == null || oldCategory.getDescription().equals(categoryBasedOnDefault.getDescription()))) {
categoryBasedOnDefault.setDescription(category.getDescription());
changed = true;
}
if(!changed) {
break;
// break;
continue;
}
categoryBasedOnDefault.setName(category.getName());
categoryBasedOnDefault.setDescription(category.getDescription());
// categoryBasedOnDefault.setName(category.getName());
// categoryBasedOnDefault.setDescription(category.getDescription());
categoryDAO.save(categoryBasedOnDefault);
}
}

View File

@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.*;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -51,6 +52,11 @@ public class IndicatorController {
Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType());
Indicator oldIndicator = null;
if(indicator.getId() != null) {
oldIndicator = indicatorDAO.findById(indicator.getId());
}
String indicatorId = indicator.getId();
indicatorDAO.save(indicator);
@ -61,7 +67,7 @@ public class IndicatorController {
onSaveDefaultIndicator(indicator, sectionId);
}
else {
onUpdateDefaultIndicator(indicator, stakeholder);
onUpdateDefaultIndicator(indicator, stakeholder, oldIndicator);
}
}
@ -100,7 +106,7 @@ public class IndicatorController {
}
}
public void onUpdateDefaultIndicator(Indicator indicator, Stakeholder stakeholder) throws UnsupportedEncodingException {
public void onUpdateDefaultIndicator(Indicator indicator, Stakeholder stakeholder, Indicator oldIndicator) throws UnsupportedEncodingException {
log.debug("On update default indicator");
// indicator already exists - check if changed and update all indicators based on it
@ -109,6 +115,20 @@ public class IndicatorController {
List<Indicator> indicators = indicatorDAO.findByDefaultId(indicator.getId());
for(Indicator indicatorBasedOnDefault : indicators) {
if(indicator.getName() != null && !indicator.getName().equals(indicatorBasedOnDefault.getName())
&& (oldIndicator.getName() == null || oldIndicator.getName().equals(indicatorBasedOnDefault.getName()))) {
indicatorBasedOnDefault.setName(indicator.getName());
changed = true;
}
if(indicator.getDescription() != null && !indicator.getDescription().equals(indicatorBasedOnDefault.getDescription())
&& (oldIndicator.getDescription() == null || oldIndicator.getDescription().equals(indicatorBasedOnDefault.getDescription()))) {
indicatorBasedOnDefault.setName(indicator.getName());
changed = true;
}
int i = 0;
List<IndicatorPath> indicatorPaths = indicatorBasedOnDefault.getIndicatorPaths();
@ -122,47 +142,102 @@ public class IndicatorController {
indicatorPaths.add(indicatorPathNew);
changed = true;
} else {
IndicatorPath oldIndicatorPath = oldIndicator.getIndicatorPaths().get(i);
// Check if there are changes in indicator path and update existing indicators if needed
if(!indicatorPath.getType().equals(indicatorPathBasedOnDefault.getType())) {
log.debug("update indicator path: "+i);
if(!indicatorPath.getType().equals(indicatorPathBasedOnDefault.getType())
&& (oldIndicatorPath.getType().equals(indicatorPathBasedOnDefault.getType()))) {
indicatorPathBasedOnDefault.setType(indicatorPath.getType());
changed = true;
changed = true; // parameter "type" needs to be changed as well
}
if(!indicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource())) {
log.debug("After type check: "+changed);
if(!indicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource())
&& (oldIndicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource()))) {
indicatorPathBasedOnDefault.setSource(indicatorPath.getSource());
changed = true;
}
if(!indicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl())) {
log.debug("After source check: "+changed);
if(!indicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl())
&& (oldIndicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl()))) {
indicatorPathBasedOnDefault.setUrl(indicatorPath.getUrl());
changed = true;
}
if(!indicatorPath.getChartObject().equals(indicatorPathBasedOnDefault.getChartObject())) {
log.debug("After url check: "+changed);
if(!indicatorPath.getChartObject().equals(indicatorPathBasedOnDefault.getChartObject())
&& (oldIndicatorPath.getChartObject().equals(indicatorPathBasedOnDefault.getChartObject()))) {
indicatorPathBasedOnDefault.setChartObject(indicatorPath.getChartObject());
changed = true;
}
if(indicatorPath.getParameters().size() != indicatorPathBasedOnDefault.getParameters().size()) {
for (Map.Entry<String, String> parameter : indicatorPath.getParameters().entrySet()) {
if(!indicatorPathBasedOnDefault.getParameters().containsKey(parameter.getKey())) {
indicatorPathBasedOnDefault.getParameters().put(parameter.getKey(), parameter.getValue());
log.debug("After chartObject check: "+changed);
if(indicatorPath.getParameters() != null) {
if (indicatorPathBasedOnDefault.getParameters() == null) {
indicatorPathBasedOnDefault.setParameters(new HashMap<>());
}
//if (indicatorPath.getParameters().size() != indicatorPathBasedOnDefault.getParameters().size()) {
//log.debug("Different number of parameters");
for (Map.Entry<String, String> parameter : indicatorPath.getParameters().entrySet()) {
log.debug("\nindicatorPath: parameter.getKey(): "+parameter.getKey()+" - value: "+parameter.getValue()
+"\nindicatorPathBasedOnDefault:parameters:key: "+ indicatorPathBasedOnDefault.getParameters().get(parameter.getKey())
+"\noldIndicatorPath:parameters:key: "+ oldIndicatorPath.getParameters().get(parameter.getKey()));
if (!indicatorPathBasedOnDefault.getParameters().containsKey(parameter.getKey())
|| (oldIndicatorPath.getParameters() == null
|| (oldIndicatorPath.getParameters().get(parameter.getKey()).equals(indicatorPathBasedOnDefault.getParameters().get(parameter.getKey()))
&& !parameter.getValue().equals(indicatorPathBasedOnDefault.getParameters().get(parameter.getKey()))))
) {
indicatorPathBasedOnDefault.getParameters().put(parameter.getKey(), parameter.getValue());
changed = true;
}
// else if(parameter.getKey().equals("type")) {
// indicatorPathBasedOnDefault.getParameters().put(parameter.getKey(), parameter.getValue());
// changed = true;
// }
}
}
parameterMapping(indicatorPathBasedOnDefault, stakeholder);
changed = true;
parameterMapping(indicatorPathBasedOnDefault, stakeholder);
//}
log.debug("After parameters check: " + changed);
}
int j=0;
for(String jsonString : indicatorPath.getJsonPath()) {
String jsonStringBasedOnDefault = indicatorPathBasedOnDefault.getJsonPath().get(j);
if(!jsonString.equals(jsonStringBasedOnDefault)) {
indicatorPathBasedOnDefault.getJsonPath().set(j, jsonString);
changed = true;
if(indicatorPath.getJsonPath() != null) {
int j = 0;
for (String jsonString : indicatorPath.getJsonPath()) {
log.debug("indicatorPath.getJsonPath(): " + jsonString);
String jsonStringBasedOnDefault = null;
if(indicatorPathBasedOnDefault.getJsonPath() != null ) {
jsonStringBasedOnDefault = indicatorPathBasedOnDefault.getJsonPath().get(j);
} else {
indicatorPathBasedOnDefault.setJsonPath(new ArrayList<>());
}
log.debug("indicatorPathBasedOnDefault.getJsonPath().get(" + j + "): " + jsonStringBasedOnDefault);
if (!jsonString.equals(jsonStringBasedOnDefault)
&& (oldIndicatorPath.getJsonPath() == null
|| oldIndicatorPath.getJsonPath().get(i).equals(jsonStringBasedOnDefault))
) {
indicatorPathBasedOnDefault.getJsonPath().set(j, jsonString);
changed = true;
}
j++;
}
j++;
log.debug("After jsonPath check: " + changed);
}
}
i++;
}
if(!changed) {
break;
// break;
continue;
}
indicatorDAO.save(indicatorBasedOnDefault);
}
}

View File

@ -65,6 +65,12 @@ public class SectionController {
log.debug("Name: "+sectionFull.getTitle() + " - Id: "+sectionFull.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
SubCategory<String> subCategory = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId);
Section<String> oldSection = null;
if(sectionFull.getId() != null) {
oldSection = sectionDAO.findById(sectionFull.getId());
}
Section<String> section = new Section<>(sectionFull);
String sectionId = sectionFull.getId();
@ -82,7 +88,7 @@ public class SectionController {
onSaveDefaultSection(section, topicId, categoryId, subcategoryId, stakeholder);
}
else {
onUpdateDefaultSection(section, stakeholder);
onUpdateDefaultSection(section, stakeholder, oldSection);
}
}
@ -119,9 +125,15 @@ public class SectionController {
List<SubCategory> subCategories = subCategoryDAO.findByDefaultId(defaultSubcategoryId);
for (SubCategory subCategory : subCategories) {
Category parentCategory = categoryDAO.findBySubCategoriesContaining(subCategory.getId());
Topic parentTopic = topicDAO.findByCategoriesContaining(parentCategory.getId());
Stakeholder parentStakeholder = stakeholderDAO.findByTopicsContaining(parentTopic.getId());
Section sectionNew = new Section();
sectionNew.copyFromDefault(section);
sectionNew.setStakeholderAlias(parentStakeholder.getAlias());
sectionDAO.save(sectionNew);
List<String> sections = null;
@ -136,7 +148,7 @@ public class SectionController {
}
}
public void onUpdateDefaultSection(Section section, Stakeholder stakeholder) {
public void onUpdateDefaultSection(Section section, Stakeholder stakeholder, Section oldSection) {
log.debug("On update default section");
// section already exists - check if changed and update all sections based on it
@ -145,15 +157,19 @@ public class SectionController {
List<Section> sections = sectionDAO.findByDefaultId(section.getId());
for(Section sectionBasedOnDefault : sections) {
if(section.getTitle() != null && !section.getTitle().equals(sectionBasedOnDefault.getTitle())) {
if(section.getTitle() != null && !section.getTitle().equals(sectionBasedOnDefault.getTitle())
&& (oldSection.getTitle() == null || oldSection.getTitle().equals(sectionBasedOnDefault.getTitle()))) {
sectionBasedOnDefault.setTitle(section.getTitle());
changed = true;
}
if(!changed) {
break;
// break;
continue;
}
sectionBasedOnDefault.setTitle(section.getTitle());
// sectionBasedOnDefault.setTitle(section.getTitle());
sectionDAO.save(sectionBasedOnDefault);
}
}

View File

@ -77,6 +77,12 @@ public class SubCategoryController {
log.debug("Alias: "+subcategoryFull.getAlias() + " - Id: "+subcategoryFull.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId);
Category category = checkForExceptions(stakeholderId, topicId, categoryId);
SubCategory<String> oldSubcategory = null;
if(subcategoryFull.getId() != null) {
oldSubcategory = subCategoryDAO.findById(subcategoryFull.getId());
}
SubCategory<String> subCategory = new SubCategory<>(subcategoryFull);
// List<String> charts = new ArrayList<>();
@ -110,7 +116,7 @@ public class SubCategoryController {
if(subcategoryFull.getId() == null) {
onSaveDefaultSubCategory(subCategory, categoryId);
} else {
onUpdateDefaultSubCategory(subCategory);
onUpdateDefaultSubCategory(subCategory, oldSubcategory);
}
}
@ -148,24 +154,32 @@ public class SubCategoryController {
}
}
public void onUpdateDefaultSubCategory(SubCategory subCategory) {
public void onUpdateDefaultSubCategory(SubCategory subCategory, SubCategory oldSubcategory) {
log.debug("On update default subCategory");
List<SubCategory> subCategories = subCategoryDAO.findByDefaultId(subCategory.getId());
boolean changed = false;
for(SubCategory subCategoryBasedOnDefault : subCategories) {
if(subCategory.getName() != null && !subCategory.getName().equals(subCategoryBasedOnDefault.getName())) {
if(subCategory.getName() != null && !subCategory.getName().equals(subCategoryBasedOnDefault.getName())
&& (oldSubcategory.getName() == null || oldSubcategory.getName().equals(subCategoryBasedOnDefault.getName()))) {
subCategoryBasedOnDefault.setName(subCategory.getName());
changed = true;
}
if(subCategory.getDescription() != null && !subCategory.getDescription().equals(subCategoryBasedOnDefault.getDescription())) {
if(subCategory.getDescription() != null && !subCategory.getDescription().equals(subCategoryBasedOnDefault.getDescription())
&& (oldSubcategory.getDescription() == null || oldSubcategory.getDescription().equals(subCategoryBasedOnDefault.getDescription()))) {
subCategoryBasedOnDefault.setDescription(subCategory.getDescription());
changed = true;
}
if(!changed) {
break;
// break;
continue;
}
subCategoryBasedOnDefault.setName(subCategory.getName());
subCategoryBasedOnDefault.setDescription(subCategory.getDescription());
// subCategoryBasedOnDefault.setName(subCategory.getName());
// subCategoryBasedOnDefault.setDescription(subCategory.getDescription());
subCategoryDAO.save(subCategoryBasedOnDefault);
}
}

View File

@ -65,6 +65,10 @@ public class TopicController {
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
if(stakeholder != null) {
Topic<String> oldTopic = null;
if(topicFull.getId() != null) {
oldTopic = topicDAO.findById(topicFull.getId());
}
Topic<String> topic = new Topic<>(topicFull);
@ -80,7 +84,7 @@ public class TopicController {
if(topicFull.getId() == null) {
onSaveDefaultTopic(topic, stakeholderId);
} else {
onUpdateDefaultTopic(topic);
onUpdateDefaultTopic(topic, oldTopic);
}
}
@ -120,24 +124,32 @@ public class TopicController {
}
}
public void onUpdateDefaultTopic(Topic topic) {
public void onUpdateDefaultTopic(Topic topic, Topic oldTopic) {
log.debug("On update default topic");
List<Topic> topics = topicDAO.findByDefaultId(topic.getId());
boolean changed = false;
for(Topic topicBasedOnDefault : topics) {
if(topic.getName() != null && !topic.getName().equals(topicBasedOnDefault.getName())) {
if(topic.getName() != null && !topic.getName().equals(topicBasedOnDefault.getName())
&& (oldTopic.getName() == null || oldTopic.getName().equals(topicBasedOnDefault.getName()))) {
topicBasedOnDefault.setName(topic.getName());
changed = true;
}
if(topic.getDescription() != null && !topic.getDescription().equals(topicBasedOnDefault.getDescription())) {
if(topic.getDescription() != null && !topic.getDescription().equals(topicBasedOnDefault.getDescription())
&& (oldTopic.getDescription() == null || oldTopic.getDescription().equals(topicBasedOnDefault.getDescription()))) {
topicBasedOnDefault.setDescription(topic.getDescription());
changed = true;
}
if(!changed) {
break;
// break;
continue;
}
topicBasedOnDefault.setName(topic.getName());
topicBasedOnDefault.setDescription(topic.getDescription());
// topicBasedOnDefault.setName(topic.getName());
// topicBasedOnDefault.setDescription(topic.getDescription());
topicDAO.save(topicBasedOnDefault);
}
}

View File

@ -8,6 +8,8 @@ public interface CategoryDAO {
List<Category> findAll();
List<Category> findByDefaultId(String DefaultId);
Category findBySubCategoriesContaining(String subCategory);
Category findById(String Id);
void delete(String Id);

View File

@ -9,6 +9,8 @@ public interface MongoDBCategoryDAO extends CategoryDAO, MongoRepository<Categor
List<Category> findAll();
List<Category> findByDefaultId(String DefaultId);
Category findBySubCategoriesContaining(String subCategory);
Category findById(String Id);
void delete(String Id);

View File

@ -15,6 +15,8 @@ public interface MongoDBStakeholderDAO extends StakeholderDAO, MongoRepository<S
List<Stakeholder> findByDefaultIdNot(String DefaultId);
List<Stakeholder> findByDefaultIdNotAndType(String DefaultId, String Type);
Stakeholder findByTopicsContaining(String topic);
Stakeholder findById(String Id);
Stakeholder findByAlias(String Alias);

View File

@ -9,6 +9,8 @@ public interface MongoDBTopicDAO extends TopicDAO, MongoRepository<Topic, String
List<Topic> findAll();
List<Topic> findByDefaultId(String DefaultId);
Topic findByCategoriesContaining(String category);
Topic findById(String Id);
void delete(String Id);

View File

@ -14,6 +14,8 @@ public interface StakeholderDAO {
List<Stakeholder> findByDefaultIdNot(String DefaultId);
List<Stakeholder> findByDefaultIdNotAndType(String DefaultId, String Type);
Stakeholder findByTopicsContaining(String topic);
Stakeholder findById(String Id);
Stakeholder findByAlias(String Alias);

View File

@ -8,6 +8,8 @@ public interface TopicDAO {
List<Topic> findAll();
List<Topic> findByDefaultId(String DefaultId);
Topic findByCategoriesContaining(String category);
Topic findById(String Id);
void delete(String Id);

View File

@ -3,6 +3,7 @@ package eu.dnetlib.uoamonitorservice.entities;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.data.annotation.Id;
import java.util.ArrayList;
import java.util.List;
enum SectionType {
@ -35,6 +36,7 @@ public class Section<StringOrIndicator> {
setTitle(defaultSection.getTitle());
setType(defaultSection.getType());
setDefaultId(defaultSection.id);
setIndicators(new ArrayList<>());
}
public String getId() {

View File

@ -24,6 +24,7 @@ public class Stakeholder<StringOrTopic> {
private String index_name;
private String index_shortName;
private String logoUrl;
private String name;
private String alias;
private String defaultId = null;
private boolean isActive;
@ -44,6 +45,7 @@ public class Stakeholder<StringOrTopic> {
index_name = stakeholder.getIndex_name();
index_shortName = stakeholder.getIndex_shortName();
logoUrl = stakeholder.getLogoUrl();
name = stakeholder.getName();
alias = stakeholder.getAlias();
defaultId = stakeholder.getDefaultId();
isActive = stakeholder.getIsActive();
@ -117,6 +119,10 @@ public class Stakeholder<StringOrTopic> {
this.logoUrl = logoUrl;
}
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getAlias() {
return alias;
}