1. pom.xml: Add dependency for "uoa-help-texts-library" (will be renamed).

2. UoaMonitorServiceApplication.java: Add @PropertySource path used in dl170.
3. MongoConnection.java: @EnableMongoRepositories not only from: eu.dnetlib.uoamonitorservice.dao, but also: eu.dnetlib.uoahelptexts.dao.
4. GoogleConfig.java & MailConfig.java: [Deleted]: Functionality available on library project.
5. EmailController.java: [New]: Used for contact-us page in portal.
6. ExceptionsHandler.java & /controllers/: Add more and detailed logs.
7. Stakeholder.java:
        a. Field 'logoUrl' added.
        b. Method 'getType()' returns type.name() and 'setType()' gets String and converts it into StakeholderType.
8. Topic.java & Category.java & SubCategory.java & Indicator.java: 
	a. Field 'boolean isDefault' changed to 'String defaultId'.
	b. Method copyFromDefault() added to create a clone from default entity (topic, category, subcategory, indicator).
9. Category.java & SubCategory.java: Field 'String description' added.
10. SubCategory.java: Field 'String stakeholderId' added | method createOverviewSubCategory(Category) added.
11. Indicator.java & IndicatorPath.java: Method 'getType()' returns type.name() and 'setType()' gets String and converts it into IndicatorType / IndicatorPathType.
12. IndicatorPath.java: Constructor and copy constructor added.
13. StakeholderDAO.java & MongoDBStakeholderDAO.java: 
	a. Method findByIsDefaultProfile() changed to: findByDefaultId() & findByDefaultIdNot().
	b. Method findByIsDefaultProfileAndType() changed to: findByDefaultIdAndType() & findByDefaultIdNotAndType().
14. SubCategoryDAO.java & MongoDBSubCategoryDAO.java & IndicatorDAO.java & MongoDBSubCategoryDAO.java: Method 'findByDefaultId()' added.
15. StakeholderController.java: Handle creationDate and updateDate | Add more exceptional cases.
16. TopicController.java:
        a. Helper method 'onSaveDefaultTopic()' added (save cloned topic on stakeholders based on this default Stakeholder).
        b. Helper method 'onUpdateDefaultTopic()' added (update cloned topics based on this default topic).
17. CategoryController.java:
        a. Remove 'subCategory.setIsDefault(true);' when a category is created.
        b. Helper method 'onSaveDefaultCategory()' added (save cloned category on topics based on this default Topic).
        c. Helper method 'onUpdateDefaultCategory()' added (update cloned categories based on this default category).
18. SubCategoryController.java:
        a. Helper method 'onSaveDefaultSubCategory()' added (save cloned subCategory on topics based on this default Category).
        b. Helper method 'onUpdateDefaultSubCategory()' added (update cloned subCategories based on this default subCategory).
19. IndicatorController.java:
        a. Helper method 'onSaveDefaultIndicator()' added (save cloned indicator on subCategories based on this default SubCategory).
        b. Helper method 'onUpdateDefaultIndicator()' added (update cloned indicators based on this default indicator).
        c. Helper method 'parameterMapping()' added to map correct parameter values on parameters depending on stakeholder info.
        d. Method 'toggleIndicatorStatus()' added to toggle 'isActive' field.
        e. Method 'toggleIndicatorAccess()' added to toggle 'isPublic' field.
        f. Helper method 'toggleIndicator()' added to update indicator when a field is toggled.
This commit is contained in:
Konstantina Galouni 2019-12-19 15:04:25 +00:00
parent 30683bdd37
commit 0ee5ff1e0e
28 changed files with 800 additions and 252 deletions

11
pom.xml
View File

@ -18,6 +18,12 @@
<relativePath/> <!-- lookup parent from repository -->
</parent>
<!-- <parent>-->
<!-- <groupId>eu.dnetlib</groupId>-->
<!-- <artifactId>dnet45-parent</artifactId>-->
<!-- <version>1.0.0-SNAPSHOT</version>-->
<!-- </parent>-->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
@ -56,6 +62,11 @@
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>eu.dnetlib</groupId>
<artifactId>uoa-help-texts-library</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>

View File

@ -1,7 +1,5 @@
package eu.dnetlib.uoamonitorservice;
import eu.dnetlib.uoamonitorservice.configuration.properties.GoogleConfig;
import eu.dnetlib.uoamonitorservice.configuration.properties.MailConfig;
import eu.dnetlib.uoamonitorservice.configuration.properties.MongoConfig;
import eu.dnetlib.uoamonitorservice.configuration.properties.SecurityConfig;
import org.springframework.boot.SpringApplication;
@ -10,15 +8,16 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
@SpringBootApplication
@SpringBootApplication(scanBasePackages = {"eu.dnetlib.uoamonitorservice", "eu.dnetlib.uoahelptexts"})
@PropertySources({
@PropertySource("classpath:monitorservice.properties"),
@PropertySource(value = "file:/usr/share/tomcat7/lib/dnet-override.properties", ignoreResourceNotFound = true),
@PropertySource(value = "file:/var/lib/tomcat_dnet/8380/lib/dnet-override.properties", ignoreResourceNotFound = true)
@PropertySource(value = "file:/var/lib/tomcat_dnet/8380/lib/dnet-override.properties", ignoreResourceNotFound = true),
@PropertySource(value = "file:/var/lib/tomcat8/lib/dnet-override.properties", ignoreResourceNotFound = true)
})
@EnableConfigurationProperties({SecurityConfig.class, MailConfig.class, GoogleConfig.class, MongoConfig.class})
@EnableConfigurationProperties({SecurityConfig.class, MongoConfig.class})
public class UoaMonitorServiceApplication {
public static void main(String[] args) {

View File

@ -16,7 +16,7 @@ import org.springframework.data.mongodb.repository.config.EnableMongoRepositorie
import java.util.Collections;
@Configuration
@EnableMongoRepositories(basePackages = {"eu.dnetlib.uoamonitorservice.dao"})
@EnableMongoRepositories(basePackages = {"eu.dnetlib.uoamonitorservice.dao", "eu.dnetlib.uoahelptexts.dao"})
public class MongoConnection {
@Autowired

View File

@ -1,17 +0,0 @@
package eu.dnetlib.uoamonitorservice.configuration.properties;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties("monitorservice.google")
public class GoogleConfig {
private String secret;
public String getSecret() {
return secret;
}
public void setSecret(String secret) {
this.secret = secret;
}
}

View File

@ -1,65 +0,0 @@
package eu.dnetlib.uoamonitorservice.configuration.properties;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties("monitorservice.mail")
public class MailConfig {
private String host;
private String port;
private String auth;
private String from;
private String username;
private String password;
public void setHost(String host) {
this.host = host;
}
public void setPort(String port) {
this.port = port;
}
public void setAuth(String auth) {
this.auth = auth;
}
public void setFrom(String from) {
this.from = from;
}
public void setUsername(String username) {
this.username = username;
}
public void setPassword(String password) {
this.password = password;
}
public String getHost() {
return host;
}
public String getPort() {
return port;
}
public String getAuth() {
return auth;
}
public String getFrom() {
return from;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
}

View File

@ -47,9 +47,9 @@ public class CategoryController {
categoryFull.setSubCategories(subCategoriesFull);
category.setSubCategories(subCategories);
Category<String> categorySaved = categoryDAO.save(category);
categoryDAO.save(category);
categoryFull.setId(categorySaved.getId());
categoryFull.setId(category.getId());
return categoryFull;
}
@ -58,6 +58,7 @@ public class CategoryController {
@PathVariable("topicId") String topicId,
@RequestBody Category<SubCategory> categoryFull) {
log.debug("save category");
log.debug("Alias: "+categoryFull.getAlias() + " - Id: "+categoryFull.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
@ -69,17 +70,11 @@ public class CategoryController {
// if category not exists (no id), create a new default subcategory, identical to category
if(categoryFull.getId() == null) {
SubCategory<String> subCategory = new SubCategory<>();
subCategory.setName("Overview");
subCategory.setAlias("overview");
subCategory.setIsActive(categoryFull.getIsActive());
subCategory.setIsPublic(categoryFull.getIsPublic());
subCategory.setIsDefault(true);
subCategory.setCharts(new ArrayList<String>());
subCategory.setNumbers(new ArrayList<String>());
subCategory.createOverviewSubCategory(categoryFull);
SubCategory<String> subCategorySaved = subCategoryDAO.save(subCategory);
subCategoryDAO.save(subCategory);
List<SubCategory> subCategories = categoryFull.getSubCategories();
subCategories.add(subCategorySaved);
subCategories.add(subCategory);
}
@ -91,16 +86,24 @@ public class CategoryController {
}
category.setSubCategories(subCategories);
Category<String> categorySaved = categoryDAO.save(category);
categoryDAO.save(category);
if(stakeholder.getDefaultId() == null) {
if(categoryFull.getId() == null) {
onSaveDefaultCategory(category, topicId);
} else {
onUpdateDefaultCategory(category);
}
}
List<String> categories = topic.getCategories();
int index = categories.indexOf(categorySaved.getId());
int index = categories.indexOf(category.getId());
if(index == -1) {
categories.add(categorySaved.getId());
categories.add(category.getId());
topicDAO.save(topic);
log.debug("Category saved!");
categoryFull.setId(categorySaved.getId());
categoryFull.setId(category.getId());
}
subCategories = null;
@ -120,11 +123,54 @@ public class CategoryController {
return categoryFull;
}
public void onSaveDefaultCategory(Category<String> category, String topicId) {
log.debug("On save default category");
List<Topic> topics = topicDAO.findByDefaultId(topicId);
for(Topic topic : topics) {
Category categoryNew = new Category();
categoryNew.copyFromDefault(category);
categoryDAO.save(categoryNew);
List<String> categories = topic.getCategories();
categories.add(categoryNew.getId());
topicDAO.save(topic);
}
String subCategoryOverviewId = category.getSubCategories().get(0);
SubCategory subCategoryOverview = subCategoryDAO.findById(subCategoryOverviewId);
subCategoryController.onSaveDefaultSubCategory(subCategoryOverview, category.getId());
}
public void onUpdateDefaultCategory(Category category) {
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())) {
changed = true;
}
if(category.getDescription() != null && !category.getDescription().equals(categoryBasedOnDefault.getDescription())) {
changed = true;
}
if(!changed) {
break;
}
categoryBasedOnDefault.setName(category.getName());
categoryBasedOnDefault.setDescription(category.getDescription());
categoryDAO.save(categoryBasedOnDefault);
}
}
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/delete", method = RequestMethod.DELETE)
public boolean deleteCategory(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId) {
log.debug("delete category");
log.debug("Id: "+categoryId + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);

View File

@ -0,0 +1,63 @@
package eu.dnetlib.uoamonitorservice.controllers;
import eu.dnetlib.uoahelptexts.emailSender.EmailSender;
import eu.dnetlib.uoahelptexts.entities.EmailRecaptcha;
import eu.dnetlib.uoahelptexts.entities.Email;
import eu.dnetlib.uoahelptexts.handlers.InvalidReCaptchaException;
import eu.dnetlib.uoahelptexts.recaptcha.VerifyRecaptcha;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.*;
@RestController
@CrossOrigin(origins = "*")
public class EmailController {
private final Logger log = Logger.getLogger(this.getClass());
@Autowired
private EmailSender emailSender;
@Autowired
private VerifyRecaptcha verifyRecaptcha;
@RequestMapping(value = "/contact", method = RequestMethod.POST)
public Boolean contact(@RequestBody EmailRecaptcha form) throws InvalidReCaptchaException {
verifyRecaptcha.processResponse(form.getRecaptcha());
Email email = form.getEmail();
ArrayList<String> sendTo = new ArrayList<>();
for(String userMail: email.getRecipients()){
sendTo.add(userMail);
}
return emailSender.send(sendTo, email.getSubject(), email.getBody(), false);
}
@RequestMapping(value = "/sendMail", method = RequestMethod.POST)
public Map<String, ArrayList<String>> sendEmail(@RequestBody Email email,
@RequestParam(required = false) Optional<Boolean> optional) {
String successString = "success";
String failureString = "failure";
Map<String, ArrayList<String>> mailResults = new HashMap<>();
boolean bcc = (optional.isPresent())?optional.get():true;
for(String userMail:email.getRecipients()){
ArrayList<String> sendTo = new ArrayList<>();
sendTo.add(userMail);
boolean success =emailSender.send(sendTo,email.getSubject(),email.getBody(), bcc);
if(success){
if(!mailResults.containsKey(successString)) {
mailResults.put(successString, new ArrayList<>());
}
mailResults.get(successString).add(userMail);
} else {
if(!mailResults.containsKey(failureString)) {
mailResults.put(failureString, new ArrayList<>());
}
mailResults.get(failureString).add(userMail);
}
}
return mailResults;
}
}

View File

@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@RestController
@CrossOrigin(origins = "*")
@ -41,6 +42,7 @@ public class IndicatorController {
@PathVariable("subcategoryId") String subcategoryId,
@RequestBody Indicator indicator) {
log.debug("save indicator");
log.debug("Name: "+indicator.getName() + " - Id: "+indicator.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
// if(stakeholderId == null) {
// // EXCEPTION - Parameter for Stakeholder is not accepted
@ -73,7 +75,18 @@ public class IndicatorController {
SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId);
if(subcategory != null) {
if (category.getSubCategories().contains(subcategoryId)) {
Indicator indicatorSaved = indicatorDAO.save(indicator);
String indicatorId = indicator.getId();
indicatorDAO.save(indicator);
// this indicator belongs in default profile and it is new or it is updated
if(stakeholder.getDefaultId() == null) {
if(indicatorId == null) {
onSaveDefaultIndicator(indicator, topicId, categoryId, subcategoryId, stakeholder);
}
else {
onUpdateDefaultIndicator(indicator, stakeholder);
}
}
List<String> indicators = null;
//if(indicator.hasType("chart")) {
@ -84,13 +97,13 @@ public class IndicatorController {
indicators = subcategory.getNumbers();
}
int index = indicators.indexOf(indicatorSaved.getId());
int index = indicators.indexOf(indicator.getId());
if (index == -1) {
indicators.add(indicatorSaved.getId());
indicators.add(indicator.getId());
subCategoryDAO.save(subcategory);
log.debug("Indicator saved!");
indicator.setId(indicatorSaved.getId());
indicator.setId(indicator.getId());
}
} else {
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias();
@ -123,6 +136,162 @@ public class IndicatorController {
return indicator;
}
public void onSaveDefaultIndicator(Indicator indicator,
String defaultTopicId, String defaultCategoryId,
String defaultSubcategoryId, Stakeholder defaultStakeholder) {
log.debug("On save default indicator");
// List<Stakeholder> stakeholders = stakeholderDAO.findByDefaultId(defaultStakeholder.getId());
// for(Stakeholder stakeholder : stakeholders) {
// List<String> topicIds = stakeholder.getTopics();
// Topic topic = null;
// for(String topicId : topicIds) {
// topic = topicDAO.findById(topicId);
// if(topic.getDefaultId().equals(defaultTopicId)) {
// break;
// }
// }
//
// List<String> categoryIds = topic.getCategories();
// Category category = null;
// for(String categoryId : categoryIds) {
// category = categoryDAO.findById(categoryId);
// if(category.getDefaultId().equals(defaultCategoryId)) {
// break;
// }
// }
//
// List<String> subCategoryIds = category.getSubCategories();
// SubCategory subCategory = null;
// for(String subCategoryId : subCategoryIds) {
// subCategory = subCategoryDAO.findById(subCategoryId);
// if(subCategory.getDefaultId().equals(defaultSubcategoryId)) {
// break;
// }
// }
//
// Indicator indicatorNew = new Indicator(indicator);
// //indicatorNew.setStakeholderId(defaultStakeholder.getId());
// for (IndicatorPath indicatorPath : indicatorNew.getIndicatorPaths()) {
// parameterMapping(indicatorPath, stakeholder);
// }
//
// indicatorDAO.save(indicatorNew);
//
// List<String> indicators = null;
// if (indicator.getType().equals("chart")) {
// indicators = subCategory.getCharts();
// } else if (indicator.getType().equals("number")) {
// indicators = subCategory.getNumbers();
// }
// indicators.add(indicatorNew.getId());
//
// subCategoryDAO.save(subCategory);
// }
// new indicator in default profile - add it on profiles of the same type
List<SubCategory> subCategories = subCategoryDAO.findByDefaultId(defaultSubcategoryId);
for (SubCategory subCategory : subCategories) {
Indicator indicatorNew = new Indicator();
indicatorNew.copyFromDefault(indicator);
for (IndicatorPath indicatorPath : indicatorNew.getIndicatorPaths()) {
Stakeholder stakeholder = stakeholderDAO.findById(subCategory.getStakeholderId());
parameterMapping(indicatorPath, stakeholder);
}
indicatorDAO.save(indicatorNew);
List<String> indicators = null;
if (indicator.getType().equals("chart")) {
indicators = subCategory.getCharts();
} else if (indicator.getType().equals("number")) {
indicators = subCategory.getNumbers();
}
indicators.add(indicatorNew.getId());
subCategoryDAO.save(subCategory);
}
}
public void onUpdateDefaultIndicator(Indicator indicator, Stakeholder stakeholder) {
log.debug("On update default indicator");
// indicator already exists - check if changed and update all indicators based on it
boolean changed = false;
List<Indicator> indicators = indicatorDAO.findByDefaultId(indicator.getId());
for(Indicator indicatorBasedOnDefault : indicators) {
int i = 0;
List<IndicatorPath> indicatorPaths = indicatorBasedOnDefault.getIndicatorPaths();
for (IndicatorPath indicatorPath : indicator.getIndicatorPaths()) {
IndicatorPath indicatorPathBasedOnDefault = indicatorBasedOnDefault.getIndicatorPaths().get(i);
if(indicatorPathBasedOnDefault == null) {
// Add new indicator path in existing indicators
IndicatorPath indicatorPathNew = new IndicatorPath(indicatorPath);
parameterMapping(indicatorPathNew, stakeholder);
indicatorPaths.add(indicatorPathNew);
changed = true;
} else {
// Check if there are changes in indicator path and update existing indicators if needed
if(!indicatorPath.getType().equals(indicatorPathBasedOnDefault.getType())) {
indicatorPathBasedOnDefault.setType(indicatorPath.getType());
changed = true;
}
if(!indicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource())) {
indicatorPathBasedOnDefault.setSource(indicatorPath.getSource());
changed = true;
}
if(!indicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl())) {
indicatorPathBasedOnDefault.setUrl(indicatorPath.getUrl());
changed = true;
}
if(!indicatorPath.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());
}
}
parameterMapping(indicatorPathBasedOnDefault, stakeholder);
changed = true;
}
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;
}
j++;
}
}
i++;
}
if(!changed) {
break;
}
indicatorDAO.save(indicatorBasedOnDefault);
}
}
public void parameterMapping(IndicatorPath indicatorPath, Stakeholder stakeholder) {
if (indicatorPath.getParameters().containsKey("funder_name")) {
indicatorPath.getParameters().put("funder_name", stakeholder.getIndex_name());
} else if (indicatorPath.getParameters().containsKey("fsn")) {
indicatorPath.getParameters().put("fsn", stakeholder.getIndex_name().toLowerCase());
} else if (indicatorPath.getParameters().containsKey("funder_id")) {
indicatorPath.getParameters().put("funder_id", stakeholder.getIndex_id());
}
}
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{indicatorId}/delete", method = RequestMethod.DELETE)
public boolean deleteIndicator(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@ -130,6 +299,7 @@ public class IndicatorController {
@PathVariable("subcategoryId") String subcategoryId,
@PathVariable("indicatorId") String indicatorId) {
log.debug("delete indicator");
log.debug("Id: "+indicatorId + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
@ -204,7 +374,8 @@ public class IndicatorController {
@RequestMapping(value = "/{stakeholderId}/charts/delete", method = RequestMethod.DELETE)
public boolean deleteAllChartIndicators(@PathVariable("stakeholderId") String stakeholderId) {
log.debug("delete indicator");
log.debug("delete all chart indicators of stakeholder");
log.debug("Stakeholder: "+stakeholderId);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
if(stakeholder != null) {
@ -265,76 +436,6 @@ public class IndicatorController {
return true;
}
// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{type}/reorder", method = RequestMethod.POST)
// public boolean reorderIndicators(@PathVariable("stakeholderId") String stakeholderId,
// @PathVariable("topicId") String topicId,
// @PathVariable("categoryId") String categoryId,
// @PathVariable("subcategoryId") String subcategoryId,
// @PathVariable("type") String type,
// @RequestBody List<Indicator> indicatorsFull) {
// log.debug("reorder indicators");
//
// Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
//
// if (stakeholder != null) {
//
// Topic<String> topic = topicDAO.findById(topicId);
// if (topic != null) {
// if (stakeholder.getTopics().contains(topicId)) {
//
// Category<String> category = categoryDAO.findById(categoryId);
// if (category != null) {
// if (topic.getCategories().contains(categoryId)) {
//
// SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId);
// if (subcategory != null) {
// if (category.getSubCategories().contains(subcategoryId)) {
//
// List<String> indicators = new ArrayList<>();
// for(Indicator indicator : indicatorsFull) {
// indicators.add(indicator.getId());
// }
//
// if(type.equals("chart")) {
// subcategory.setCharts(indicators);
// } else if(type.equals("number")) {
// subcategory.setNumbers(indicators);
// }
//
// subCategoryDAO.save(subcategory);
// indicators = null;
// log.debug("Indicators reordered!");
// } else {
// // EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias();
// throw new PathNotValidException("Reorder indicators: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId);
// }
// } else {
// // EXCEPTION - SubCategory not found
// throw new EntityNotFoundException("Reorder indicators: SubCategory with id: "+subcategoryId+" not found");
// }
// } else {
// // EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias();
// throw new PathNotValidException("Reorder indicators: Category with id: "+categoryId+" not found in Topic: "+topicId);
// }
// } else {
// // EXCEPTION - Category not found
// throw new EntityNotFoundException("Reorder indicators: Category with id: "+categoryId+" not found");
// }
// } else {
// // EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
// throw new PathNotValidException("Reorder indicators: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId);
// }
// } else {
// // EXCEPTION - Topic not found
// throw new EntityNotFoundException("Reorder indicators: Topic with id: "+topicId+" not found");
// }
// } else {
// // EXCEPTION - Stakeholder not found
// throw new EntityNotFoundException("Reorder indicators: Stakeholder with id: "+stakeholderId+" not found");
// }
// return true;
// }
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{type}/reorder", method = RequestMethod.POST)
public List<Indicator> reorderIndicators(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@ -342,7 +443,8 @@ public class IndicatorController {
@PathVariable("subcategoryId") String subcategoryId,
@PathVariable("type") String type,
@RequestBody List<String> indicators) {
log.debug("reorder indicators");
log.debug("reorder indicators of type: "+type);
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
@ -402,4 +504,94 @@ public class IndicatorController {
}
return indicatorsFull;
}
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{indicatorId}/toggle-status", method = RequestMethod.POST)
public Boolean toggleIndicatorStatus(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@PathVariable("subcategoryId") String subcategoryId,
@PathVariable("indicatorId") String indicatorId) {
log.debug("toggle indicator status (isActive)");
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId+ " - Indicator: "+indicatorId);
Indicator indicator = indicatorDAO.findById(indicatorId);
if (indicator == null) {
// EXCEPTION - Indicator not found
throw new EntityNotFoundException("Toggle indicator status: Indicator with id: "+indicatorId+" not found");
}
indicator.setIsActive(!indicator.getIsActive());
this.toggleIndicator(stakeholderId, topicId, categoryId, subcategoryId, indicator);
return indicator.getIsActive();
}
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{indicatorId}/toggle-access", method = RequestMethod.POST)
public Boolean toggleIndicatorAccess(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@PathVariable("subcategoryId") String subcategoryId,
@PathVariable("indicatorId") String indicatorId) {
log.debug("toggle indicator access (isPublic)");
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId+ " - Indicator: "+indicatorId);
Indicator indicator = indicatorDAO.findById(indicatorId);
if (indicator == null) {
// EXCEPTION - Indicator not found
throw new EntityNotFoundException("Toggle indicator access: Indicator with id: "+indicatorId+" not found");
}
indicator.setIsPublic(!indicator.getIsPublic());
this.toggleIndicator(stakeholderId, topicId, categoryId, subcategoryId, indicator);
return indicator.getIsPublic();
}
public void toggleIndicator(String stakeholderId, String topicId, String categoryId, String subcategoryId, Indicator indicator) {
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
if (stakeholder != null) {
Topic<String> topic = topicDAO.findById(topicId);
if (topic != null) {
if (stakeholder.getTopics().contains(topicId)) {
Category<String> category = categoryDAO.findById(categoryId);
if (category != null) {
if (topic.getCategories().contains(categoryId)) {
SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId);
if (subcategory != null) {
if (category.getSubCategories().contains(subcategoryId)) {
indicatorDAO.save(indicator);
log.debug("Indicator toggled!");
} else {
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias();
throw new PathNotValidException("Reorder indicators: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId);
}
} else {
// EXCEPTION - SubCategory not found
throw new EntityNotFoundException("Reorder indicators: SubCategory with id: "+subcategoryId+" not found");
}
} else {
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias();
throw new PathNotValidException("Reorder indicators: Category with id: "+categoryId+" not found in Topic: "+topicId);
}
} else {
// EXCEPTION - Category not found
throw new EntityNotFoundException("Reorder indicators: Category with id: "+categoryId+" not found");
}
} else {
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
throw new PathNotValidException("Reorder indicators: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId);
}
} else {
// EXCEPTION - Topic not found
throw new EntityNotFoundException("Reorder indicators: Topic with id: "+topicId+" not found");
}
} else {
// EXCEPTION - Stakeholder not found
throw new EntityNotFoundException("Reorder indicators: Stakeholder with id: "+stakeholderId+" not found");
}
}
}

View File

@ -39,6 +39,7 @@ public class StakeholderController {
@RequestMapping(value = "/build-stakeholder", method = RequestMethod.POST)
public Stakeholder<Topic<Category<SubCategory<Indicator>>>> buildFullStakeholder(@RequestBody Stakeholder<Topic<Category<SubCategory<Indicator>>>> stakeholderFull) {
log.debug("build stakeholder");
log.debug("Alias: "+stakeholderFull.getAlias());
Stakeholder<String> stakeholder = new Stakeholder<>(stakeholderFull);
@ -52,6 +53,13 @@ public class StakeholderController {
stakeholderFull.setTopics(topicsFull);
stakeholder.setTopics(topics);
Date date = new Date();
stakeholder.setCreationDate(date);
stakeholder.setUpdateDate(date);
stakeholderFull.setCreationDate(date);
stakeholderFull.setUpdateDate(date);
Stakeholder<String> stakeholderSaved = stakeholderDAO.save(stakeholder);
stakeholderFull.setId(stakeholderSaved.getId());
return stakeholderFull;
@ -65,29 +73,51 @@ public class StakeholderController {
for (String topicId: (List<String>)stakeholder.getTopics()) {
Topic<String> topic = topicDAO.findById(topicId);
if(topic == null) {
// EXCEPTION - Topic not found
throw new EntityNotFoundException("Get stakeholder: Topic with id: "+topicId+" not found (topic exists in stakeholder: "+stakeholder.getId()+")");
}
Topic<Category> topicFull = new Topic<Category>(topic);
List<Category> categories = new ArrayList<>();
for(String categoryId : topic.getCategories()) {
Category<String> category = categoryDAO.findById(categoryId);
if(category == null) {
// EXCEPTION - Category not found
throw new EntityNotFoundException("Get stakeholder: Category with id: "+categoryId+" not found (category exists in topic: "+topicId+")");
}
Category<SubCategory> categoryFull = new Category<SubCategory>(category);
List<SubCategory> subCategories = new ArrayList<>();
for(String subCategoryId : category.getSubCategories()) {
SubCategory<String> subCategory = subCategoryDAO.findById(subCategoryId);
if(subCategory == null) {
// EXCEPTION - SubCategory not found
throw new EntityNotFoundException("Get stakeholder: SubCategory with id: "+subCategoryId+" not found (subCategory exists in category: "+categoryId+")");
}
SubCategory subCategoryFull = new SubCategory<Indicator>(subCategory);
List<Indicator> charts = new ArrayList<>();
for(String indicatorId : subCategory.getCharts()) {
charts.add(indicatorDAO.findById(indicatorId));
Indicator indicator = indicatorDAO.findById(indicatorId);
if(indicator == null) {
// EXCEPTION - Indicator not found
throw new EntityNotFoundException("Get stakeholder: Indicator with id: "+indicatorId+" not found (indicator exists in subCategory: "+subCategoryId+")");
}
charts.add(indicator);
}
subCategoryFull.setCharts(charts);
List<Indicator> numbers = new ArrayList<>();
for(String indicatorId : subCategory.getNumbers()) {
numbers.add(indicatorDAO.findById(indicatorId));
Indicator indicator = indicatorDAO.findById(indicatorId);
if(indicator == null) {
// EXCEPTION - Indicator not found
throw new EntityNotFoundException("Get stakeholder: Indicator with id: "+indicatorId+" not found (indicator exists in subCategory: "+subCategoryId+")");
}
numbers.add(indicator);
}
subCategoryFull.setNumbers(numbers);
@ -108,6 +138,8 @@ public class StakeholderController {
@RequestMapping(value = "/stakeholder/all", method = RequestMethod.GET)
public List<Stakeholder> getAllStakeholders(@RequestParam(required = false) String type) {
log.debug("get all stakeholders" + (type != null ? " with type: "+type : ""));
List<Stakeholder> stakeholders;
if(type == null) {
stakeholders = stakeholderDAO.findAll();
@ -125,11 +157,13 @@ public class StakeholderController {
@RequestMapping(value = "/stakeholder/default", method = RequestMethod.GET)
public List<Stakeholder> getAllDefaultStakeholders(@RequestParam(required = false) String type) {
log.debug("get all default stakeholders" + (type != null ? " with type: "+type : ""));
List<Stakeholder> stakeholders;
if(type == null) {
stakeholders = stakeholderDAO.findByIsDefaultProfile(true);
stakeholders = stakeholderDAO.findByDefaultId(null);
} else {
stakeholders = stakeholderDAO.findByIsDefaultProfileAndType(true, type);
stakeholders = stakeholderDAO.findByDefaultIdAndType(null, type);
}
List<Stakeholder> stakeholdersFull = new ArrayList<>();
@ -141,11 +175,13 @@ public class StakeholderController {
@RequestMapping(value = "/stakeholder", method = RequestMethod.GET)
public List<Stakeholder> getAllRealStakeholders(@RequestParam(required = false) String type) {
log.debug("get all NOT default stakeholders" + (type != null ? " with type: "+type : ""));
List<Stakeholder> stakeholders;
if(type == null) {
stakeholders = stakeholderDAO.findByIsDefaultProfile(false);
stakeholders = stakeholderDAO.findByDefaultIdNot(null);
} else {
stakeholders = stakeholderDAO.findByIsDefaultProfileAndType(false, type);
stakeholders = stakeholderDAO.findByDefaultIdNotAndType(null, type);
}
List<Stakeholder> stakeholdersFull = new ArrayList<>();
@ -159,6 +195,8 @@ public class StakeholderController {
@RequestMapping(value = "/stakeholder/{alias}", method = RequestMethod.GET)
public Stakeholder getStakeholder(@PathVariable("alias") String alias) {
log.debug("get stakeholder: "+alias);
Stakeholder<String> stakeholder = stakeholderDAO.findByAlias(alias);
if(stakeholder == null) {
// EXCEPTION - Stakeholder not found
@ -170,6 +208,7 @@ public class StakeholderController {
@RequestMapping(value = "/save", method = RequestMethod.POST)
public Stakeholder<Topic> saveStakeholder(@RequestBody Stakeholder<Topic> stakeholderFull) {
log.debug("save stakeholder");
log.debug("Alias: "+stakeholderFull.getAlias() + " - Id: "+stakeholderFull.getId());
// if(stakeholderFull == null) {
// log.debug("stakeholder null");
@ -178,6 +217,14 @@ public class StakeholderController {
Stakeholder<String> stakeholder = new Stakeholder<>(stakeholderFull);
Date date = new Date();
stakeholder.setUpdateDate(date);
// stakeholder does not exist in DB
if(stakeholderFull.getId() == null) {
stakeholder.setCreationDate(date);
}
List<String> topics = new ArrayList<>();
for(Topic topic : stakeholderFull.getTopics()) {
topics.add(topic.getId());
@ -186,6 +233,8 @@ public class StakeholderController {
Stakeholder<String> stakeholderSaved = stakeholderDAO.save(stakeholder);
stakeholderFull.setId(stakeholderSaved.getId());
stakeholderFull.setCreationDate(stakeholderSaved.getCreationDate());
stakeholderFull.setUpdateDate(stakeholderSaved.getUpdateDate());
topics = null;
stakeholder = null;
@ -198,6 +247,7 @@ public class StakeholderController {
@RequestMapping(value = "/{stakeholderId}/delete", method = RequestMethod.DELETE)
public boolean deleteStakeholder(@PathVariable("stakeholderId") String stakeholderId) {
log.debug("delete stakeholder");
log.debug("Id: "+stakeholderId);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);

View File

@ -56,9 +56,9 @@ public class SubCategoryController {
subcategoryFull.setNumbers(numbersFull);
subCategory.setNumbers(numbers);
SubCategory<String> subCategorySaved = subCategoryDAO.save(subCategory);
subCategoryDAO.save(subCategory);
subcategoryFull.setId(subCategorySaved.getId());
subcategoryFull.setId(subCategory.getId());
return subcategoryFull;
}
@ -68,6 +68,7 @@ public class SubCategoryController {
@PathVariable("categoryId") String categoryId,
@RequestBody SubCategory<Indicator> subcategoryFull) {
log.debug("save subcategory");
log.debug("Alias: "+subcategoryFull.getAlias() + " - Id: "+subcategoryFull.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
@ -94,16 +95,24 @@ public class SubCategoryController {
}
subCategory.setNumbers(numbers);
SubCategory<String> subCategorySaved = subCategoryDAO.save(subCategory);
subCategoryDAO.save(subCategory);
if(stakeholder.getDefaultId() == null) {
if(topic.getId() == null) {
onSaveDefaultSubCategory(subCategory, categoryId);
} else {
onUpdateDefaultSubCategory(subCategory);
}
}
List<String> subcategories = category.getSubCategories();
int index = subcategories.indexOf(subCategorySaved.getId());
int index = subcategories.indexOf(subCategory.getId());
if(index == -1) {
subcategories.add(subCategorySaved.getId());
subcategories.add(subCategory.getId());
categoryDAO.save(category);
log.debug("Subcategory saved!");
subcategoryFull.setId(subCategorySaved.getId());
subcategoryFull.setId(subCategory.getId());
}
charts = null;
@ -132,12 +141,52 @@ public class SubCategoryController {
return subcategoryFull;
}
public void onSaveDefaultSubCategory(SubCategory subCategory, String categoryId) {
log.debug("On save default subCategory");
List<Category> categories = categoryDAO.findByDefaultId(categoryId);
for(Category category : categories) {
SubCategory subCategoryNew = new SubCategory();
subCategoryNew.copyFromDefault(subCategory);
subCategoryDAO.save(subCategoryNew);
List<String> subCategories = category.getSubCategories();
subCategories.add(subCategoryNew.getId());
categoryDAO.save(category);
}
}
public void onUpdateDefaultSubCategory(SubCategory subCategory) {
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())) {
changed = true;
}
if(subCategory.getDescription() != null && !subCategory.getDescription().equals(subCategoryBasedOnDefault.getDescription())) {
changed = true;
}
if(!changed) {
break;
}
subCategoryBasedOnDefault.setName(subCategory.getName());
subCategoryBasedOnDefault.setDescription(subCategory.getDescription());
subCategoryDAO.save(subCategoryBasedOnDefault);
}
}
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/delete", method = RequestMethod.DELETE)
public boolean deleteSubCategory(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@PathVariable("subcategoryId") String subcategoryId) {
log.debug("delete subcategory");
log.debug("Id: "+subcategoryId + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);

View File

@ -50,9 +50,9 @@ public class TopicController {
topicFull.setCategories(categoriesFull);
topic.setCategories(categories);
Topic<String> topicSaved = topicDAO.save(topic);
topicDAO.save(topic);
topicFull.setId(topicSaved.getId());
topicFull.setId(topic.getId());
return topicFull;
}
@ -60,6 +60,7 @@ public class TopicController {
public Topic<Category> saveTopic(@PathVariable("stakeholderId") String stakeholderId,
@RequestBody Topic<Category> topicFull) {
log.debug("save topic");
log.debug("Alias: "+topicFull.getAlias() + " - Id: "+topicFull.getId()+ " - Stakeholder: "+stakeholderId);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
@ -73,16 +74,24 @@ public class TopicController {
}
topic.setCategories(categories);
Topic<String> topicSaved = topicDAO.save(topic);
topicDAO.save(topic);
if(stakeholder.getDefaultId() == null) {
if(topicFull.getId() == null) {
onSaveDefaultTopic(topic, stakeholderId);
} else {
onUpdateDefaultTopic(topic);
}
}
List<String> topics = stakeholder.getTopics();
int index = topics.indexOf(topicSaved.getId());
int index = topics.indexOf(topic.getId());
if(index == -1) {
topics.add(topicSaved.getId());
topics.add(topic.getId());
stakeholderDAO.save(stakeholder);
log.debug("Topic saved!");
topicFull.setId(topicSaved.getId());
topicFull.setId(topic.getId());
}
categories = null;
@ -94,10 +103,50 @@ public class TopicController {
return topicFull;
}
public void onSaveDefaultTopic(Topic topic, String stakeholderId) {
log.debug("On save default topic");
List<Stakeholder> stakeholders = stakeholderDAO.findByDefaultId(stakeholderId);
for(Stakeholder _stakeholder : stakeholders) {
Topic topicNew = new Topic();
topicNew.copyFromDefault(topic);
topicDAO.save(topicNew);
List<String> topics = _stakeholder.getTopics();
topics.add(topicNew.getId());
stakeholderDAO.save(_stakeholder);
}
}
public void onUpdateDefaultTopic(Topic topic) {
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())) {
changed = true;
}
if(topic.getDescription() != null && !topic.getDescription().equals(topicBasedOnDefault.getDescription())) {
changed = true;
}
if(!changed) {
break;
}
topicBasedOnDefault.setName(topic.getName());
topicBasedOnDefault.setDescription(topic.getDescription());
topicDAO.save(topicBasedOnDefault);
}
}
@RequestMapping(value = "/{stakeholderId}/{topicId}/delete", method = RequestMethod.DELETE)
public boolean deleteTopic(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId) {
log.debug("delete topic");
log.debug("Id: "+topicId + " - Stakeholder: "+stakeholderId);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);

View File

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

View File

@ -6,6 +6,8 @@ import java.util.List;
public interface IndicatorDAO {
List<Indicator> findAll();
List<Indicator> findByDefaultId(String DefaultId);
Indicator findById(String Id);
void delete(String Id);

View File

@ -7,6 +7,8 @@ import java.util.List;
public interface MongoDBCategoryDAO extends CategoryDAO, MongoRepository<Category, String> {
List<Category> findAll();
List<Category> findByDefaultId(String DefaultId);
Category findById(String Id);
void delete(String Id);

View File

@ -7,6 +7,8 @@ import java.util.List;
public interface MongoDBIndicatorDAO extends IndicatorDAO, MongoRepository<Indicator, String> {
List<Indicator> findAll();
List<Indicator> findByDefaultId(String DefaultId);
Indicator findById(String Id);
void delete(String Id);

View File

@ -9,8 +9,11 @@ public interface MongoDBStakeholderDAO extends StakeholderDAO, MongoRepository<S
List<Stakeholder> findAll();
List<Stakeholder> findByType(String Type);
List<Stakeholder> findByIsDefaultProfile(boolean IsDefaultProfile);
List<Stakeholder> findByIsDefaultProfileAndType(boolean IsDefaultProfile, String Type);
List<Stakeholder> findByDefaultId(String DefaultId);
List<Stakeholder> findByDefaultIdAndType(String DefaultId, String Type);
List<Stakeholder> findByDefaultIdNot(String DefaultId);
List<Stakeholder> findByDefaultIdNotAndType(String DefaultId, String Type);
Stakeholder findById(String Id);
Stakeholder findByAlias(String Alias);

View File

@ -7,6 +7,8 @@ import java.util.List;
public interface MongoDBSubCategoryDAO extends SubCategoryDAO, MongoRepository<SubCategory, String> {
List<SubCategory> findAll();
List<SubCategory> findByDefaultId(String DefaultId);
SubCategory findById(String Id);
void delete(String Id);

View File

@ -7,6 +7,8 @@ import java.util.List;
public interface MongoDBTopicDAO extends TopicDAO, MongoRepository<Topic, String> {
List<Topic> findAll();
List<Topic> findByDefaultId(String DefaultId);
Topic findById(String Id);
void delete(String Id);

View File

@ -8,8 +8,11 @@ public interface StakeholderDAO {
List<Stakeholder> findAll();
List<Stakeholder> findByType(String Type);
List<Stakeholder> findByIsDefaultProfile(boolean IsDefaultProfile);
List<Stakeholder> findByIsDefaultProfileAndType(boolean IsDefaultProfile, String Type);
List<Stakeholder> findByDefaultId(String DefaultId);
List<Stakeholder> findByDefaultIdAndType(String DefaultId, String Type);
List<Stakeholder> findByDefaultIdNot(String DefaultId);
List<Stakeholder> findByDefaultIdNotAndType(String DefaultId, String Type);
Stakeholder findById(String Id);
Stakeholder findByAlias(String Alias);

View File

@ -6,6 +6,8 @@ import java.util.List;
public interface SubCategoryDAO {
List<SubCategory> findAll();
List<SubCategory> findByDefaultId(String DefaultId);
SubCategory findById(String Id);
void delete(String Id);

View File

@ -6,6 +6,8 @@ import java.util.List;
public interface TopicDAO {
List<Topic> findAll();
List<Topic> findByDefaultId(String DefaultId);
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;
public class Category<StringOrSubcategory> {
@ -12,10 +13,11 @@ public class Category<StringOrSubcategory> {
private String name;
private String alias;
private String description;
private boolean isActive;
private boolean isPublic;
private boolean isOverview;
private boolean isDefault;
private String defaultId;
private List<StringOrSubcategory> subCategories;
public Category() {}
@ -23,10 +25,22 @@ public class Category<StringOrSubcategory> {
id = category.getId();
name = category.getName();
alias = category.getAlias();
description = category.getDescription();
isActive = category.getIsActive();
isPublic = category.getIsPublic();
isOverview = category.getIsOverview();
isDefault = category.getIsDefault();
defaultId = category.getDefaultId();
}
public void copyFromDefault(Category defaultCategory) {
setName(defaultCategory.getName());
setAlias(defaultCategory.getAlias());
setDescription(defaultCategory.getDescription());
setIsActive(false);
setIsPublic(false);
setIsOverview(defaultCategory.getIsOverview());
setDefaultId(defaultCategory.getId());
setSubCategories(new ArrayList());
}
public String getId() {
@ -53,6 +67,14 @@ public class Category<StringOrSubcategory> {
this.alias = alias;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean getIsActive() {
return isActive;
}
@ -77,12 +99,12 @@ public class Category<StringOrSubcategory> {
this.isOverview = isOverview;
}
public boolean getIsDefault() {
return isDefault;
public String getDefaultId() {
return defaultId;
}
public void setIsDefault(boolean isDefault) {
this.isDefault = isDefault;
public void setDefaultId(String defaultId) {
this.defaultId = defaultId;
}
public List<StringOrSubcategory> getSubCategories() {

View File

@ -1,9 +1,9 @@
package eu.dnetlib.uoamonitorservice.entities;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.log4j.Logger;
import org.springframework.data.annotation.Id;
import java.util.ArrayList;
import java.util.List;
enum IndicatorType {
@ -25,12 +25,24 @@ public class Indicator {
private String description;
private IndicatorType type; //number,chart
private IndicatorWidth width; //small,medium,large
private List<String> tags;
private List<String> tags; // this field is not used anywhere now
private boolean isActive;
private boolean isPublic;
private boolean isDefault;
private String defaultId;
private List<IndicatorPath> indicatorPaths;
public void copyFromDefault(Indicator defaultIndicator) {
setName(defaultIndicator.getName());
setDescription(defaultIndicator.getDescription());
setType(defaultIndicator.getType()));
setWidth(defaultIndicator.getWidth());
setTags(defaultIndicator.getTags());
setIsActive(false);
setIsPublic(false);
setDefaultId(defaultIndicator.id);
setIndicatorPaths(defaultIndicator.getIndicatorPaths());
}
public String getId() {
return id;
}
@ -55,15 +67,27 @@ public class Indicator {
this.description = description;
}
// public IndicatorType getType() {
// return type;
// }
public String getType() {
if(type == null) {
return null;
}
return type.name();
}
public void setType(IndicatorType type) {
this.type = type;
// public String getStringType() {
// return type.name();
// }
// public void setType(IndicatorType type) {
// this.type = type;
// }
public void setType(String type) {
if(type == null) {
this.type = null;
} else {
IndicatorType indicatorType = IndicatorType.valueOf(type);
this.type = indicatorType;
}
}
public IndicatorWidth getWidth() {
@ -98,12 +122,12 @@ public class Indicator {
this.isPublic = isPublic;
}
public boolean getIsDefault() {
return isDefault;
public String getDefaultId() {
return defaultId;
}
public void setIsDefault(boolean isDefault) {
this.isDefault = isDefault;
public void setDefaultId(String defaultId) {
this.defaultId = defaultId;
}
public List<IndicatorPath> getIndicatorPaths() {

View File

@ -18,12 +18,36 @@ public class IndicatorPath {
private Map<String, String> filters;
//private Map<String, Map<String, String>> filters;
public IndicatorPathType getType() {
return type;
public IndicatorPath() {}
public IndicatorPath(IndicatorPath indicatorPath) {
setType(indicatorPath.getType());
source = indicatorPath.getSource();
url = indicatorPath.getUrl();
jsonPath = indicatorPath.getJsonPath();
chartObject = indicatorPath.getChartObject();
parameters = indicatorPath.getParameters();
filters = indicatorPath.getFilters();
}
public void setType(IndicatorPathType type) {
this.type = type;
public String getType() {
if(type == null) {
return null;
}
return type.name();
}
// public IndicatorPathType getType() {
// return type;
// }
public void setType(String type) {
if(type == null) {
this.type = null;
} else {
IndicatorPathType indicatorPathType = IndicatorPathType.valueOf(type);
this.type = indicatorPathType;
}
}
public String getSource() {

View File

@ -23,8 +23,9 @@ public class Stakeholder<StringOrTopic> {
private String index_id;
private String index_name;
private String index_shortName;
private String logoUrl;
private String alias;
private boolean isDefaultProfile;
private String defaultId = null;
private boolean isActive;
private boolean isPublic;
private Date creationDate;
@ -33,15 +34,18 @@ public class Stakeholder<StringOrTopic> {
private List<StringOrTopic> topics;
public Stakeholder() {}
public Stakeholder() {
}
public Stakeholder(Stakeholder stakeholder) {
id = stakeholder.getId();
type = stakeholder.getType();
setType(stakeholder.getType());
index_id = stakeholder.getIndex_id();
index_name = stakeholder.getIndex_name();
index_shortName = stakeholder.getIndex_shortName();
logoUrl = stakeholder.getLogoUrl();
alias = stakeholder.getAlias();
isDefaultProfile = stakeholder.getIsDefaultProfile();
defaultId = stakeholder.getDefaultId();
isActive = stakeholder.getIsActive();
isPublic = stakeholder.getIsPublic();
creationDate = stakeholder.getCreationDate();
@ -57,12 +61,28 @@ public class Stakeholder<StringOrTopic> {
this.id = id;
}
public StakeholderType getType() {
return type;
// public StakeholderType getType() {
// return type;
// }
//
// public void setType(StakeholderType type) {
// this.type = type;
// }
public String getType() {
if(type == null) {
return null;
}
return type.name();
}
public void setType(StakeholderType type) {
this.type = type;
public void setType(String type) {
if(type == null) {
this.type = null;
} else {
StakeholderType stakeholderType = StakeholderType.valueOf(type);
this.type = stakeholderType;
}
}
public String getIndex_id() {
@ -89,6 +109,14 @@ public class Stakeholder<StringOrTopic> {
this.index_shortName = index_shortName;
}
public String getLogoUrl() {
return logoUrl;
}
public void setLogoUrl(String logoUrl) {
this.logoUrl = logoUrl;
}
public String getAlias() {
return alias;
}
@ -97,12 +125,12 @@ public class Stakeholder<StringOrTopic> {
this.alias = alias;
}
public boolean getIsDefaultProfile() {
return isDefaultProfile;
public String getDefaultId() {
return defaultId;
}
public void setIsDefaultProfile(boolean isDefaultProfile) {
this.isDefaultProfile = isDefaultProfile;
public void setDefaultId(String defaultId) {
this.defaultId = defaultId;
}
public boolean getIsActive() {

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;
public class SubCategory<StringOrIndicator> {
@ -12,9 +13,11 @@ public class SubCategory<StringOrIndicator> {
private String name;
private String alias;
private String description;
private boolean isActive;
private boolean isPublic;
private boolean isDefault;
private String defaultId;
private String stakeholderId;
private List<StringOrIndicator> charts;
private List<StringOrIndicator> numbers;
@ -23,9 +26,30 @@ public class SubCategory<StringOrIndicator> {
id = subCategory.getId();
name = subCategory.getName();
alias = subCategory.getAlias();
description = subCategory.getDescription();
isActive = subCategory.getIsActive();
isPublic = subCategory.getIsPublic();
isDefault = subCategory.getIsDefault();
defaultId = subCategory.getDefaultId();
}
public void createOverviewSubCategory(Category category) {
setName("Overview");
setAlias("overview");
setIsActive(category.getIsActive());
setIsPublic(category.getIsPublic());
setCharts(new ArrayList<>());
setNumbers(new ArrayList<>());
}
public void copyFromDefault(SubCategory defaultSubCategory) {
setName(defaultSubCategory.getName());
setAlias(defaultSubCategory.getAlias());
setDescription(defaultSubCategory.getDescription());
setIsActive(false);
setIsPublic(false);
setDefaultId(defaultSubCategory.getId());
setCharts(new ArrayList());
setNumbers(new ArrayList());
}
public String getId() {
@ -52,6 +76,14 @@ public class SubCategory<StringOrIndicator> {
this.alias = alias;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean getIsActive() {
return isActive;
}
@ -68,12 +100,20 @@ public class SubCategory<StringOrIndicator> {
this.isPublic = isPublic;
}
public boolean getIsDefault() {
return isDefault;
public String getDefaultId() {
return defaultId;
}
public void setIsDefault(boolean isDefault) {
this.isDefault = isDefault;
public void setDefaultId(String defaultId) {
this.defaultId = defaultId;
}
public String getStakeholderId() {
return stakeholderId;
}
public void setStakeholderId(String stakeholderId) {
this.stakeholderId = stakeholderId;
}
public List<StringOrIndicator> getCharts() {

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;
public class Topic<StringOrCategory> {
@ -15,7 +16,7 @@ public class Topic<StringOrCategory> {
private String description;
private boolean isActive;
private boolean isPublic;
private boolean isDefault;
private String defaultId;
private List<StringOrCategory> categories;
public Topic() {}
@ -26,7 +27,17 @@ public class Topic<StringOrCategory> {
description = topic.getDescription();
isActive = topic.getIsActive();
isPublic = topic.getIsPublic();
isDefault = topic.getIsDefault();
defaultId = topic.getDefaultId();
}
public void copyFromDefault(Topic defaultTopic) {
setName(defaultTopic.getName());
setAlias(defaultTopic.getAlias());
setDescription(defaultTopic.getDescription());
setIsActive(false);
setIsPublic(false);
setDefaultId(defaultTopic.getId());
setCategories(new ArrayList());
}
public String getId() {
@ -77,12 +88,12 @@ public class Topic<StringOrCategory> {
this.isPublic = isPublic;
}
public boolean getIsDefault() {
return isDefault;
public String getDefaultId() {
return defaultId;
}
public void setIsDefault(boolean isDefault) {
this.isDefault = isDefault;
public void setDefaultId(String defaultId) {
this.defaultId = defaultId;
}
public List<StringOrCategory> getCategories() {

View File

@ -22,7 +22,7 @@ public class ExceptionsHandler {
response.setErrorMessage("Invalid inputs");
response.setErrors(ex.getMessage());
response.setStatus(HttpStatus.BAD_REQUEST);
log.debug("invalidInput exception");
log.debug("invalidInput exception : "+ ex.getMessage());
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
}
@ -33,7 +33,7 @@ public class ExceptionsHandler {
response.setErrorMessage("Null pointer Exception");
response.setErrors(ex.getMessage());
response.setStatus(HttpStatus.BAD_REQUEST);
log.debug("nullPointerException exception");
log.debug("nullPointerException exception : "+ ex.getMessage());
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
}
@ -44,7 +44,7 @@ public class ExceptionsHandler {
response.setErrorMessage("Not found Exception");
response.setErrors(ex.getMessage());
response.setStatus(HttpStatus.NOT_FOUND);
log.debug("notFoundException exception");
log.debug("notFoundException exception : "+ ex.getMessage());
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.NOT_FOUND);
}
@ -55,7 +55,7 @@ public class ExceptionsHandler {
response.setErrorMessage("Entity not found Exception");
response.setErrors(ex.getMessage());
response.setStatus(HttpStatus.NOT_FOUND);
log.debug("entityNotFoundException exception");
log.debug("entityNotFoundException exception : "+ ex.getMessage());
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.NOT_FOUND);
}
@ -66,7 +66,7 @@ public class ExceptionsHandler {
response.setErrorMessage("Path not valid Exception");
response.setErrors(ex.getMessage());
response.setStatus(HttpStatus.NOT_FOUND);
log.debug("pathNotValidException exception");
log.debug("pathNotValidException exception : "+ ex.getMessage());
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.NOT_FOUND);
}
}