Project

General

Profile

« Previous | Next » 

Revision 57923

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.

View differences:

modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/configuration/properties/MailConfig.java
1
package eu.dnetlib.uoamonitorservice.configuration.properties;
2

  
3
import org.springframework.boot.context.properties.ConfigurationProperties;
4

  
5
@ConfigurationProperties("monitorservice.mail")
6
public class MailConfig {
7

  
8
    private String host;
9
    private String port;
10
    private String auth;
11
    private String from;
12
    private String username;
13
    private String password;
14

  
15

  
16
    public void setHost(String host) {
17
        this.host = host;
18
    }
19

  
20
    public void setPort(String port) {
21
        this.port = port;
22
    }
23

  
24
    public void setAuth(String auth) {
25
        this.auth = auth;
26
    }
27

  
28
    public void setFrom(String from) {
29
        this.from = from;
30
    }
31

  
32
    public void setUsername(String username) {
33
        this.username = username;
34
    }
35

  
36
    public void setPassword(String password) {
37
        this.password = password;
38
    }
39

  
40
    public String getHost() {
41
        return host;
42
    }
43

  
44
    public String getPort() {
45
        return port;
46
    }
47

  
48
    public String getAuth() {
49
        return auth;
50
    }
51

  
52
    public String getFrom() {
53
        return from;
54
    }
55

  
56
    public String getUsername() {
57
        return username;
58
    }
59

  
60
    public String getPassword() {
61
        return password;
62
    }
63

  
64

  
65
}
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/configuration/properties/GoogleConfig.java
1
package eu.dnetlib.uoamonitorservice.configuration.properties;
2

  
3
import org.springframework.boot.context.properties.ConfigurationProperties;
4

  
5
@ConfigurationProperties("monitorservice.google")
6
public class GoogleConfig {
7

  
8
    private String secret;
9

  
10
    public String getSecret() {
11
        return secret;
12
    }
13

  
14
    public void setSecret(String secret) {
15
        this.secret = secret;
16
    }
17
}
modules/uoa-monitor-service/trunk/pom.xml
18 18
        <relativePath/> <!-- lookup parent from repository -->
19 19
    </parent>
20 20

  
21
<!--    <parent>-->
22
<!--        <groupId>eu.dnetlib</groupId>-->
23
<!--        <artifactId>dnet45-parent</artifactId>-->
24
<!--        <version>1.0.0-SNAPSHOT</version>-->
25
<!--    </parent>-->
26

  
21 27
    <properties>
22 28
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23 29
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
......
56 62
            <artifactId>gson</artifactId>
57 63
            <version>2.8.2</version>
58 64
        </dependency>
65
        <dependency>
66
            <groupId>eu.dnetlib</groupId>
67
            <artifactId>uoa-help-texts-library</artifactId>
68
            <version>2.0.0-SNAPSHOT</version>
69
        </dependency>
59 70
    </dependencies>
60 71

  
61 72
    <build>
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/handlers/ExceptionsHandler.java
22 22
        response.setErrorMessage("Invalid inputs");
23 23
        response.setErrors(ex.getMessage());
24 24
        response.setStatus(HttpStatus.BAD_REQUEST);
25
        log.debug("invalidInput exception");
25
        log.debug("invalidInput exception : "+ ex.getMessage());
26 26
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
27 27
    }
28 28

  
......
33 33
        response.setErrorMessage("Null pointer Exception");
34 34
        response.setErrors(ex.getMessage());
35 35
        response.setStatus(HttpStatus.BAD_REQUEST);
36
        log.debug("nullPointerException exception");
36
        log.debug("nullPointerException exception : "+ ex.getMessage());
37 37
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
38 38
    }
39 39

  
......
44 44
        response.setErrorMessage("Not found Exception");
45 45
        response.setErrors(ex.getMessage());
46 46
        response.setStatus(HttpStatus.NOT_FOUND);
47
        log.debug("notFoundException exception");
47
        log.debug("notFoundException exception : "+ ex.getMessage());
48 48
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.NOT_FOUND);
49 49
    }
50 50

  
......
55 55
        response.setErrorMessage("Entity not found Exception");
56 56
        response.setErrors(ex.getMessage());
57 57
        response.setStatus(HttpStatus.NOT_FOUND);
58
        log.debug("entityNotFoundException exception");
58
        log.debug("entityNotFoundException exception : "+ ex.getMessage());
59 59
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.NOT_FOUND);
60 60
    }
61 61

  
......
66 66
        response.setErrorMessage("Path not valid Exception");
67 67
        response.setErrors(ex.getMessage());
68 68
        response.setStatus(HttpStatus.NOT_FOUND);
69
        log.debug("pathNotValidException exception");
69
        log.debug("pathNotValidException exception : "+ ex.getMessage());
70 70
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.NOT_FOUND);
71 71
    }
72 72
}
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/UoaMonitorServiceApplication.java
1 1
package eu.dnetlib.uoamonitorservice;
2 2

  
3
import eu.dnetlib.uoamonitorservice.configuration.properties.GoogleConfig;
4
import eu.dnetlib.uoamonitorservice.configuration.properties.MailConfig;
5 3
import eu.dnetlib.uoamonitorservice.configuration.properties.MongoConfig;
6 4
import eu.dnetlib.uoamonitorservice.configuration.properties.SecurityConfig;
7 5
import org.springframework.boot.SpringApplication;
......
10 8
import org.springframework.context.annotation.PropertySource;
11 9
import org.springframework.context.annotation.PropertySources;
12 10

  
13
@SpringBootApplication
11
@SpringBootApplication(scanBasePackages = {"eu.dnetlib.uoamonitorservice", "eu.dnetlib.uoahelptexts"})
14 12
@PropertySources({
15 13
        @PropertySource("classpath:monitorservice.properties"),
16 14
        @PropertySource(value = "file:/usr/share/tomcat7/lib/dnet-override.properties", ignoreResourceNotFound = true),
17
        @PropertySource(value = "file:/var/lib/tomcat_dnet/8380/lib/dnet-override.properties", ignoreResourceNotFound = true)
15
        @PropertySource(value = "file:/var/lib/tomcat_dnet/8380/lib/dnet-override.properties", ignoreResourceNotFound = true),
16
        @PropertySource(value = "file:/var/lib/tomcat8/lib/dnet-override.properties", ignoreResourceNotFound = true)
18 17

  
19 18
})
20 19

  
21
@EnableConfigurationProperties({SecurityConfig.class, MailConfig.class, GoogleConfig.class, MongoConfig.class})
20
@EnableConfigurationProperties({SecurityConfig.class, MongoConfig.class})
22 21

  
23 22
public class UoaMonitorServiceApplication {
24 23
    public static void main(String[] args) {
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBStakeholderDAO.java
9 9
    List<Stakeholder> findAll();
10 10
    List<Stakeholder> findByType(String Type);
11 11

  
12
    List<Stakeholder> findByIsDefaultProfile(boolean IsDefaultProfile);
13
    List<Stakeholder> findByIsDefaultProfileAndType(boolean IsDefaultProfile, String Type);
12
    List<Stakeholder> findByDefaultId(String DefaultId);
13
    List<Stakeholder> findByDefaultIdAndType(String DefaultId, String Type);
14 14

  
15
    List<Stakeholder> findByDefaultIdNot(String DefaultId);
16
    List<Stakeholder> findByDefaultIdNotAndType(String DefaultId, String Type);
17

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

  
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/dao/IndicatorDAO.java
6 6

  
7 7
public interface IndicatorDAO {
8 8
    List<Indicator> findAll();
9
    List<Indicator> findByDefaultId(String DefaultId);
10

  
9 11
    Indicator findById(String Id);
10 12

  
11 13
    void delete(String Id);
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/dao/CategoryDAO.java
6 6

  
7 7
public interface CategoryDAO {
8 8
    List<Category> findAll();
9
    List<Category> findByDefaultId(String DefaultId);
10

  
9 11
    Category findById(String Id);
10 12

  
11 13
    void delete(String Id);
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBSubCategoryDAO.java
7 7

  
8 8
public interface MongoDBSubCategoryDAO extends SubCategoryDAO, MongoRepository<SubCategory, String> {
9 9
    List<SubCategory> findAll();
10
    List<SubCategory> findByDefaultId(String DefaultId);
11

  
10 12
    SubCategory findById(String Id);
11 13

  
12 14
    void delete(String Id);
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/dao/TopicDAO.java
6 6

  
7 7
public interface TopicDAO {
8 8
    List<Topic> findAll();
9
    List<Topic> findByDefaultId(String DefaultId);
10

  
9 11
    Topic findById(String Id);
10 12

  
11 13
    void delete(String Id);
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBIndicatorDAO.java
7 7

  
8 8
public interface MongoDBIndicatorDAO extends IndicatorDAO, MongoRepository<Indicator, String> {
9 9
    List<Indicator> findAll();
10
    List<Indicator> findByDefaultId(String DefaultId);
11

  
10 12
    Indicator findById(String Id);
11 13

  
12 14
    void delete(String Id);
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBCategoryDAO.java
7 7

  
8 8
public interface MongoDBCategoryDAO extends CategoryDAO, MongoRepository<Category, String> {
9 9
    List<Category> findAll();
10
    List<Category> findByDefaultId(String DefaultId);
11

  
10 12
    Category findById(String Id);
11 13

  
12 14
    void delete(String Id);
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBTopicDAO.java
7 7

  
8 8
public interface MongoDBTopicDAO extends TopicDAO, MongoRepository<Topic, String> {
9 9
    List<Topic> findAll();
10
    List<Topic> findByDefaultId(String DefaultId);
11

  
10 12
    Topic findById(String Id);
11 13

  
12 14
    void delete(String Id);
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/dao/StakeholderDAO.java
8 8
    List<Stakeholder> findAll();
9 9
    List<Stakeholder> findByType(String Type);
10 10

  
11
    List<Stakeholder> findByIsDefaultProfile(boolean IsDefaultProfile);
12
    List<Stakeholder> findByIsDefaultProfileAndType(boolean IsDefaultProfile, String Type);
11
    List<Stakeholder> findByDefaultId(String DefaultId);
12
    List<Stakeholder> findByDefaultIdAndType(String DefaultId, String Type);
13 13

  
14
    List<Stakeholder> findByDefaultIdNot(String DefaultId);
15
    List<Stakeholder> findByDefaultIdNotAndType(String DefaultId, String Type);
16

  
14 17
    Stakeholder findById(String Id);
15 18
    Stakeholder findByAlias(String Alias);
16 19

  
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/dao/SubCategoryDAO.java
6 6

  
7 7
public interface SubCategoryDAO {
8 8
    List<SubCategory> findAll();
9
    List<SubCategory> findByDefaultId(String DefaultId);
10

  
9 11
    SubCategory findById(String Id);
10 12

  
11 13
    void delete(String Id);
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/entities/Stakeholder.java
23 23
    private String index_id;
24 24
    private String index_name;
25 25
    private String index_shortName;
26
    private String logoUrl;
26 27
    private String alias;
27
    private boolean isDefaultProfile;
28
    private String defaultId = null;
28 29
    private boolean isActive;
29 30
    private boolean isPublic;
30 31
    private Date creationDate;
......
33 34

  
34 35
    private List<StringOrTopic> topics;
35 36

  
36
    public Stakeholder() {}
37
    public Stakeholder() {
38

  
39
    }
37 40
    public Stakeholder(Stakeholder stakeholder) {
38 41
        id = stakeholder.getId();
39
        type = stakeholder.getType();
42
        setType(stakeholder.getType());
40 43
        index_id = stakeholder.getIndex_id();
41 44
        index_name = stakeholder.getIndex_name();
42 45
        index_shortName = stakeholder.getIndex_shortName();
46
        logoUrl = stakeholder.getLogoUrl();
43 47
        alias = stakeholder.getAlias();
44
        isDefaultProfile = stakeholder.getIsDefaultProfile();
48
        defaultId = stakeholder.getDefaultId();
45 49
        isActive = stakeholder.getIsActive();
46 50
        isPublic = stakeholder.getIsPublic();
47 51
        creationDate = stakeholder.getCreationDate();
......
57 61
        this.id = id;
58 62
    }
59 63

  
60
    public StakeholderType getType() {
61
        return type;
64
//    public StakeholderType getType() {
65
//        return type;
66
//    }
67
//
68
//    public void setType(StakeholderType type) {
69
//        this.type = type;
70
//    }
71

  
72
    public String getType() {
73
        if(type == null) {
74
            return null;
75
        }
76
        return type.name();
62 77
    }
63 78

  
64
    public void setType(StakeholderType type) {
65
        this.type = type;
79
    public void setType(String type) {
80
        if(type == null) {
81
            this.type = null;
82
        } else {
83
            StakeholderType stakeholderType = StakeholderType.valueOf(type);
84
            this.type = stakeholderType;
85
        }
66 86
    }
67 87

  
68 88
    public String getIndex_id() {
......
89 109
        this.index_shortName = index_shortName;
90 110
    }
91 111

  
112
    public String getLogoUrl() {
113
        return logoUrl;
114
    }
115

  
116
    public void setLogoUrl(String logoUrl) {
117
        this.logoUrl = logoUrl;
118
    }
119

  
92 120
    public String getAlias() {
93 121
        return alias;
94 122
    }
......
97 125
        this.alias = alias;
98 126
    }
99 127

  
100
    public boolean getIsDefaultProfile() {
101
        return isDefaultProfile;
128
    public String getDefaultId() {
129
        return defaultId;
102 130
    }
103 131

  
104
    public void setIsDefaultProfile(boolean isDefaultProfile) {
105
        this.isDefaultProfile = isDefaultProfile;
132
    public void setDefaultId(String defaultId) {
133
        this.defaultId = defaultId;
106 134
    }
107 135

  
108 136
    public boolean getIsActive() {
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/entities/SubCategory.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
public class SubCategory<StringOrIndicator> {
......
12 13

  
13 14
    private String name;
14 15
    private String alias;
16
    private String description;
15 17
    private boolean isActive;
16 18
    private boolean isPublic;
17
    private boolean isDefault;
19
    private String defaultId;
20
    private String stakeholderId;
18 21
    private List<StringOrIndicator> charts;
19 22
    private List<StringOrIndicator> numbers;
20 23

  
......
23 26
        id = subCategory.getId();
24 27
        name = subCategory.getName();
25 28
        alias = subCategory.getAlias();
29
        description = subCategory.getDescription();
26 30
        isActive = subCategory.getIsActive();
27 31
        isPublic = subCategory.getIsPublic();
28
        isDefault = subCategory.getIsDefault();
32
        defaultId = subCategory.getDefaultId();
29 33
    }
30 34

  
35
    public void createOverviewSubCategory(Category category) {
36
        setName("Overview");
37
        setAlias("overview");
38
        setIsActive(category.getIsActive());
39
        setIsPublic(category.getIsPublic());
40
        setCharts(new ArrayList<>());
41
        setNumbers(new ArrayList<>());
42
    }
43

  
44
    public void copyFromDefault(SubCategory defaultSubCategory) {
45
        setName(defaultSubCategory.getName());
46
        setAlias(defaultSubCategory.getAlias());
47
        setDescription(defaultSubCategory.getDescription());
48
        setIsActive(false);
49
        setIsPublic(false);
50
        setDefaultId(defaultSubCategory.getId());
51
        setCharts(new ArrayList());
52
        setNumbers(new ArrayList());
53
    }
54

  
31 55
    public String getId() {
32 56
        return id;
33 57
    }
......
52 76
        this.alias = alias;
53 77
    }
54 78

  
79
    public String getDescription() {
80
        return description;
81
    }
82

  
83
    public void setDescription(String description) {
84
        this.description = description;
85
    }
86

  
55 87
    public boolean getIsActive() {
56 88
        return isActive;
57 89
    }
......
68 100
        this.isPublic = isPublic;
69 101
    }
70 102

  
71
    public boolean getIsDefault() {
72
        return isDefault;
103
    public String getDefaultId() {
104
        return defaultId;
73 105
    }
74 106

  
75
    public void setIsDefault(boolean isDefault) {
76
        this.isDefault = isDefault;
107
    public void setDefaultId(String defaultId) {
108
        this.defaultId = defaultId;
77 109
    }
78 110

  
111
    public String getStakeholderId() {
112
        return stakeholderId;
113
    }
114

  
115
    public void setStakeholderId(String stakeholderId) {
116
        this.stakeholderId = stakeholderId;
117
    }
118

  
79 119
    public List<StringOrIndicator> getCharts() {
80 120
        return charts;
81 121
    }
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/entities/IndicatorPath.java
18 18
    private Map<String, String> filters;
19 19
    //private Map<String, Map<String, String>> filters;
20 20

  
21
    public IndicatorPathType getType() {
22
        return type;
21
    public IndicatorPath() {}
22

  
23
    public IndicatorPath(IndicatorPath indicatorPath) {
24
        setType(indicatorPath.getType());
25
        source = indicatorPath.getSource();
26
        url = indicatorPath.getUrl();
27
        jsonPath = indicatorPath.getJsonPath();
28
        chartObject = indicatorPath.getChartObject();
29
        parameters = indicatorPath.getParameters();
30
        filters = indicatorPath.getFilters();
23 31
    }
24 32

  
25
    public void setType(IndicatorPathType type) {
26
        this.type = type;
33
    public String getType() {
34
        if(type == null) {
35
            return null;
36
        }
37
        return type.name();
27 38
    }
28 39

  
40
//    public IndicatorPathType getType() {
41
//        return type;
42
//    }
43

  
44
    public void setType(String type) {
45
        if(type == null) {
46
            this.type = null;
47
        } else {
48
            IndicatorPathType indicatorPathType = IndicatorPathType.valueOf(type);
49
            this.type = indicatorPathType;
50
        }
51
    }
52

  
29 53
    public String getSource() {
30 54
        return source;
31 55
    }
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/entities/Indicator.java
1 1
package eu.dnetlib.uoamonitorservice.entities;
2 2

  
3 3
import com.fasterxml.jackson.annotation.JsonProperty;
4
import org.apache.log4j.Logger;
5 4
import org.springframework.data.annotation.Id;
6 5

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

  
9 9
enum IndicatorType {
......
25 25
    private String description;
26 26
    private IndicatorType type; //number,chart
27 27
    private IndicatorWidth width; //small,medium,large
28
    private List<String> tags;
28
    private List<String> tags;  // this field is not used anywhere now
29 29
    private boolean isActive;
30 30
    private boolean isPublic;
31
    private boolean isDefault;
31
    private String defaultId;
32 32
    private List<IndicatorPath> indicatorPaths;
33 33

  
34
    public void copyFromDefault(Indicator defaultIndicator) {
35
        setName(defaultIndicator.getName());
36
        setDescription(defaultIndicator.getDescription());
37
        setType(defaultIndicator.getType()));
38
        setWidth(defaultIndicator.getWidth());
39
        setTags(defaultIndicator.getTags());
40
        setIsActive(false);
41
        setIsPublic(false);
42
        setDefaultId(defaultIndicator.id);
43
        setIndicatorPaths(defaultIndicator.getIndicatorPaths());
44
    }
45

  
34 46
    public String getId() {
35 47
        return id;
36 48
    }
......
55 67
        this.description = description;
56 68
    }
57 69

  
58
//    public IndicatorType getType() {
59
//        return type;
60
//    }
61 70
    public String getType() {
71
        if(type == null) {
72
            return null;
73
        }
62 74
        return type.name();
63 75
    }
64 76

  
65
    public void setType(IndicatorType type) {
66
        this.type = type;
77
//    public String getStringType() {
78
//        return type.name();
79
//    }
80

  
81
//    public void setType(IndicatorType type) {
82
//        this.type = type;
83
//    }
84
    public void setType(String type) {
85
        if(type == null) {
86
            this.type = null;
87
        } else {
88
            IndicatorType indicatorType = IndicatorType.valueOf(type);
89
            this.type = indicatorType;
90
        }
67 91
    }
68 92

  
69 93
    public IndicatorWidth getWidth() {
......
98 122
        this.isPublic = isPublic;
99 123
    }
100 124

  
101
    public boolean getIsDefault() {
102
        return isDefault;
125
    public String getDefaultId() {
126
        return defaultId;
103 127
    }
104 128

  
105
    public void setIsDefault(boolean isDefault) {
106
        this.isDefault = isDefault;
129
    public void setDefaultId(String defaultId) {
130
        this.defaultId = defaultId;
107 131
    }
108 132

  
109 133
    public List<IndicatorPath> getIndicatorPaths() {
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/entities/Category.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
public class Category<StringOrSubcategory> {
......
12 13

  
13 14
    private String name;
14 15
    private String alias;
16
    private String description;
15 17
    private boolean isActive;
16 18
    private boolean isPublic;
17 19
    private boolean isOverview;
18
    private boolean isDefault;
20
    private String defaultId;
19 21
    private List<StringOrSubcategory> subCategories;
20 22

  
21 23
    public Category() {}
......
23 25
        id = category.getId();
24 26
        name = category.getName();
25 27
        alias = category.getAlias();
28
        description = category.getDescription();
26 29
        isActive = category.getIsActive();
27 30
        isPublic = category.getIsPublic();
28 31
        isOverview = category.getIsOverview();
29
        isDefault = category.getIsDefault();
32
        defaultId = category.getDefaultId();
30 33
    }
31 34

  
35
    public void copyFromDefault(Category defaultCategory) {
36
        setName(defaultCategory.getName());
37
        setAlias(defaultCategory.getAlias());
38
        setDescription(defaultCategory.getDescription());
39
        setIsActive(false);
40
        setIsPublic(false);
41
        setIsOverview(defaultCategory.getIsOverview());
42
        setDefaultId(defaultCategory.getId());
43
        setSubCategories(new ArrayList());
44
    }
45

  
32 46
    public String getId() {
33 47
        return id;
34 48
    }
......
53 67
        this.alias = alias;
54 68
    }
55 69

  
70
    public String getDescription() {
71
        return description;
72
    }
73

  
74
    public void setDescription(String description) {
75
        this.description = description;
76
    }
77

  
56 78
    public boolean getIsActive() {
57 79
        return isActive;
58 80
    }
......
77 99
        this.isOverview = isOverview;
78 100
    }
79 101

  
80
    public boolean getIsDefault() {
81
        return isDefault;
102
    public String getDefaultId() {
103
        return defaultId;
82 104
    }
83 105

  
84
    public void setIsDefault(boolean isDefault) {
85
        this.isDefault = isDefault;
106
    public void setDefaultId(String defaultId) {
107
        this.defaultId = defaultId;
86 108
    }
87 109

  
88 110
    public List<StringOrSubcategory> getSubCategories() {
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/entities/Topic.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
public class Topic<StringOrCategory> {
......
15 16
    private String description;
16 17
    private boolean isActive;
17 18
    private boolean isPublic;
18
    private boolean isDefault;
19
    private String defaultId;
19 20
    private List<StringOrCategory> categories;
20 21

  
21 22
    public Topic() {}
......
26 27
        description = topic.getDescription();
27 28
        isActive = topic.getIsActive();
28 29
        isPublic = topic.getIsPublic();
29
        isDefault = topic.getIsDefault();
30
        defaultId = topic.getDefaultId();
30 31
    }
31 32

  
33
    public void copyFromDefault(Topic defaultTopic) {
34
        setName(defaultTopic.getName());
35
        setAlias(defaultTopic.getAlias());
36
        setDescription(defaultTopic.getDescription());
37
        setIsActive(false);
38
        setIsPublic(false);
39
        setDefaultId(defaultTopic.getId());
40
        setCategories(new ArrayList());
41
    }
42

  
32 43
    public String getId() {
33 44
        return id;
34 45
    }
......
77 88
        this.isPublic = isPublic;
78 89
    }
79 90

  
80
    public boolean getIsDefault() {
81
        return isDefault;
91
    public String getDefaultId() {
92
        return defaultId;
82 93
    }
83 94

  
84
    public void setIsDefault(boolean isDefault) {
85
        this.isDefault = isDefault;
95
    public void setDefaultId(String defaultId) {
96
        this.defaultId = defaultId;
86 97
    }
87 98

  
88 99
    public List<StringOrCategory> getCategories() {
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java
12 12
import java.util.ArrayList;
13 13
import java.util.Iterator;
14 14
import java.util.List;
15
import java.util.Map;
15 16

  
16 17
@RestController
17 18
@CrossOrigin(origins = "*")
......
41 42
                                   @PathVariable("subcategoryId") String subcategoryId,
42 43
                                   @RequestBody Indicator indicator) {
43 44
        log.debug("save indicator");
45
        log.debug("Name: "+indicator.getName() + " - Id: "+indicator.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
44 46

  
45 47
//        if(stakeholderId == null) {
46 48
//            // EXCEPTION - Parameter for Stakeholder is not accepted
......
73 75
                            SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId);
74 76
                            if(subcategory != null) {
75 77
                                if (category.getSubCategories().contains(subcategoryId)) {
76
                                    Indicator indicatorSaved = indicatorDAO.save(indicator);
78
                                    String indicatorId = indicator.getId();
79
                                    indicatorDAO.save(indicator);
77 80

  
81
                                    // this indicator belongs in default profile and it is new or it is updated
82
                                    if(stakeholder.getDefaultId() == null) {
83
                                        if(indicatorId == null) {
84
                                            onSaveDefaultIndicator(indicator, topicId, categoryId, subcategoryId, stakeholder);
85
                                        }
86
                                        else {
87
                                            onUpdateDefaultIndicator(indicator, stakeholder);
88
                                        }
89
                                    }
90

  
78 91
                                    List<String> indicators = null;
79 92
                                    //if(indicator.hasType("chart")) {
80 93
                                    if(indicator.getType().equals("chart")) {
......
84 97
                                        indicators = subcategory.getNumbers();
85 98
                                    }
86 99

  
87
                                    int index = indicators.indexOf(indicatorSaved.getId());
100
                                    int index = indicators.indexOf(indicator.getId());
88 101
                                    if (index == -1) {
89
                                        indicators.add(indicatorSaved.getId());
102
                                        indicators.add(indicator.getId());
90 103
                                        subCategoryDAO.save(subcategory);
91 104
                                        log.debug("Indicator saved!");
92 105

  
93
                                        indicator.setId(indicatorSaved.getId());
106
                                        indicator.setId(indicator.getId());
94 107
                                    }
95 108
                                } else {
96 109
                                    // EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias();
......
123 136
        return indicator;
124 137
    }
125 138

  
139
    public void onSaveDefaultIndicator(Indicator indicator,
140
                                       String defaultTopicId, String defaultCategoryId,
141
                                       String defaultSubcategoryId, Stakeholder defaultStakeholder) {
142
        log.debug("On save default indicator");
143

  
144
//        List<Stakeholder> stakeholders = stakeholderDAO.findByDefaultId(defaultStakeholder.getId());
145
//        for(Stakeholder stakeholder : stakeholders) {
146
//            List<String> topicIds = stakeholder.getTopics();
147
//            Topic topic = null;
148
//            for(String topicId : topicIds) {
149
//                topic = topicDAO.findById(topicId);
150
//                if(topic.getDefaultId().equals(defaultTopicId)) {
151
//                    break;
152
//                }
153
//            }
154
//
155
//            List<String> categoryIds = topic.getCategories();
156
//            Category category = null;
157
//            for(String categoryId : categoryIds) {
158
//                category = categoryDAO.findById(categoryId);
159
//                if(category.getDefaultId().equals(defaultCategoryId)) {
160
//                    break;
161
//                }
162
//            }
163
//
164
//            List<String> subCategoryIds = category.getSubCategories();
165
//            SubCategory subCategory = null;
166
//            for(String subCategoryId : subCategoryIds) {
167
//                subCategory = subCategoryDAO.findById(subCategoryId);
168
//                if(subCategory.getDefaultId().equals(defaultSubcategoryId)) {
169
//                    break;
170
//                }
171
//            }
172
//
173
//            Indicator indicatorNew = new Indicator(indicator);
174
//            //indicatorNew.setStakeholderId(defaultStakeholder.getId());
175
//            for (IndicatorPath indicatorPath : indicatorNew.getIndicatorPaths()) {
176
//                parameterMapping(indicatorPath, stakeholder);
177
//            }
178
//
179
//            indicatorDAO.save(indicatorNew);
180
//
181
//            List<String> indicators = null;
182
//            if (indicator.getType().equals("chart")) {
183
//                indicators = subCategory.getCharts();
184
//            } else if (indicator.getType().equals("number")) {
185
//                indicators = subCategory.getNumbers();
186
//            }
187
//            indicators.add(indicatorNew.getId());
188
//
189
//            subCategoryDAO.save(subCategory);
190
//        }
191

  
192

  
193
        // new indicator in default profile - add it on profiles of the same type
194
        List<SubCategory> subCategories = subCategoryDAO.findByDefaultId(defaultSubcategoryId);
195

  
196
        for (SubCategory subCategory : subCategories) {
197
            Indicator indicatorNew = new Indicator();
198
            indicatorNew.copyFromDefault(indicator);
199
            for (IndicatorPath indicatorPath : indicatorNew.getIndicatorPaths()) {
200
                Stakeholder stakeholder = stakeholderDAO.findById(subCategory.getStakeholderId());
201
                parameterMapping(indicatorPath, stakeholder);
202
            }
203

  
204
            indicatorDAO.save(indicatorNew);
205

  
206
            List<String> indicators = null;
207
            if (indicator.getType().equals("chart")) {
208
                indicators = subCategory.getCharts();
209
            } else if (indicator.getType().equals("number")) {
210
                indicators = subCategory.getNumbers();
211
            }
212
            indicators.add(indicatorNew.getId());
213

  
214
            subCategoryDAO.save(subCategory);
215
        }
216
    }
217

  
218
    public void onUpdateDefaultIndicator(Indicator indicator, Stakeholder stakeholder) {
219
        log.debug("On update default indicator");
220

  
221
        // indicator already exists - check if changed and update all indicators based on it
222

  
223
        boolean changed = false;
224
        List<Indicator> indicators = indicatorDAO.findByDefaultId(indicator.getId());
225

  
226
        for(Indicator indicatorBasedOnDefault : indicators) {
227
            int i = 0;
228
            List<IndicatorPath> indicatorPaths = indicatorBasedOnDefault.getIndicatorPaths();
229

  
230
            for (IndicatorPath indicatorPath : indicator.getIndicatorPaths()) {
231
                IndicatorPath indicatorPathBasedOnDefault = indicatorBasedOnDefault.getIndicatorPaths().get(i);
232

  
233
                if(indicatorPathBasedOnDefault == null) {
234
                    // Add new indicator path in existing indicators
235
                    IndicatorPath indicatorPathNew = new IndicatorPath(indicatorPath);
236
                    parameterMapping(indicatorPathNew, stakeholder);
237
                    indicatorPaths.add(indicatorPathNew);
238
                    changed = true;
239
                } else {
240
                    // Check if there are changes in indicator path and update existing indicators if needed
241
                    if(!indicatorPath.getType().equals(indicatorPathBasedOnDefault.getType())) {
242
                        indicatorPathBasedOnDefault.setType(indicatorPath.getType());
243
                        changed = true;
244
                    }
245
                    if(!indicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource())) {
246
                        indicatorPathBasedOnDefault.setSource(indicatorPath.getSource());
247
                        changed = true;
248
                    }
249
                    if(!indicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl())) {
250
                        indicatorPathBasedOnDefault.setUrl(indicatorPath.getUrl());
251
                        changed = true;
252
                    }
253
                    if(!indicatorPath.getChartObject().equals(indicatorPathBasedOnDefault.getChartObject())) {
254
                        indicatorPathBasedOnDefault.setChartObject(indicatorPath.getChartObject());
255
                        changed = true;
256
                    }
257
                    if(indicatorPath.getParameters().size() != indicatorPathBasedOnDefault.getParameters().size()) {
258
                        for (Map.Entry<String, String> parameter : indicatorPath.getParameters().entrySet()) {
259
                            if(!indicatorPathBasedOnDefault.getParameters().containsKey(parameter.getKey())) {
260
                                indicatorPathBasedOnDefault.getParameters().put(parameter.getKey(), parameter.getValue());
261
                            }
262
                        }
263
                        parameterMapping(indicatorPathBasedOnDefault, stakeholder);
264
                        changed = true;
265
                    }
266
                    int j=0;
267
                    for(String jsonString : indicatorPath.getJsonPath()) {
268
                        String jsonStringBasedOnDefault = indicatorPathBasedOnDefault.getJsonPath().get(j);
269
                        if(!jsonString.equals(jsonStringBasedOnDefault)) {
270
                            indicatorPathBasedOnDefault.getJsonPath().set(j, jsonString);
271
                            changed = true;
272
                        }
273
                        j++;
274
                    }
275
                }
276
                i++;
277
            }
278
            if(!changed) {
279
                break;
280
            }
281
            indicatorDAO.save(indicatorBasedOnDefault);
282
        }
283
    }
284

  
285
    public void parameterMapping(IndicatorPath indicatorPath, Stakeholder stakeholder) {
286
        if (indicatorPath.getParameters().containsKey("funder_name")) {
287
            indicatorPath.getParameters().put("funder_name", stakeholder.getIndex_name());
288
        } else if (indicatorPath.getParameters().containsKey("fsn")) {
289
            indicatorPath.getParameters().put("fsn", stakeholder.getIndex_name().toLowerCase());
290
        } else if (indicatorPath.getParameters().containsKey("funder_id")) {
291
            indicatorPath.getParameters().put("funder_id", stakeholder.getIndex_id());
292
        }
293
    }
294

  
126 295
    @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{indicatorId}/delete", method = RequestMethod.DELETE)
127 296
    public boolean deleteIndicator(@PathVariable("stakeholderId") String stakeholderId,
128 297
                                   @PathVariable("topicId") String topicId,
......
130 299
                                   @PathVariable("subcategoryId") String subcategoryId,
131 300
                                   @PathVariable("indicatorId") String indicatorId) {
132 301
        log.debug("delete indicator");
302
        log.debug("Id: "+indicatorId + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
133 303

  
134 304
        Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
135 305

  
......
204 374

  
205 375
    @RequestMapping(value = "/{stakeholderId}/charts/delete", method = RequestMethod.DELETE)
206 376
    public boolean deleteAllChartIndicators(@PathVariable("stakeholderId") String stakeholderId) {
207
        log.debug("delete indicator");
377
        log.debug("delete all chart indicators of stakeholder");
378
        log.debug("Stakeholder: "+stakeholderId);
208 379

  
209 380
        Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
210 381
        if(stakeholder != null) {
......
265 436
        return true;
266 437
    }
267 438

  
268
//    @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{type}/reorder", method = RequestMethod.POST)
269
//    public boolean reorderIndicators(@PathVariable("stakeholderId") String stakeholderId,
270
//                                             @PathVariable("topicId") String topicId,
271
//                                             @PathVariable("categoryId") String categoryId,
272
//                                             @PathVariable("subcategoryId") String subcategoryId,
273
//                                             @PathVariable("type") String type,
274
//                                             @RequestBody List<Indicator> indicatorsFull) {
275
//        log.debug("reorder indicators");
276
//
277
//        Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
278
//
279
//        if (stakeholder != null) {
280
//
281
//            Topic<String> topic = topicDAO.findById(topicId);
282
//            if (topic != null) {
283
//                if (stakeholder.getTopics().contains(topicId)) {
284
//
285
//                    Category<String> category = categoryDAO.findById(categoryId);
286
//                    if (category != null) {
287
//                        if (topic.getCategories().contains(categoryId)) {
288
//
289
//                            SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId);
290
//                            if (subcategory != null) {
291
//                                if (category.getSubCategories().contains(subcategoryId)) {
292
//
293
//                                    List<String> indicators = new ArrayList<>();
294
//                                    for(Indicator indicator : indicatorsFull) {
295
//                                        indicators.add(indicator.getId());
296
//                                    }
297
//
298
//                                    if(type.equals("chart")) {
299
//                                        subcategory.setCharts(indicators);
300
//                                    } else if(type.equals("number")) {
301
//                                        subcategory.setNumbers(indicators);
302
//                                    }
303
//
304
//                                    subCategoryDAO.save(subcategory);
305
//                                    indicators = null;
306
//                                    log.debug("Indicators reordered!");
307
//                                } else {
308
//                                    // EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias();
309
//                                    throw new PathNotValidException("Reorder indicators: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId);
310
//                                }
311
//                            } else {
312
//                                // EXCEPTION - SubCategory not found
313
//                                throw new EntityNotFoundException("Reorder indicators: SubCategory with id: "+subcategoryId+" not found");
314
//                            }
315
//                        } else {
316
//                            // EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias();
317
//                            throw new PathNotValidException("Reorder indicators: Category with id: "+categoryId+" not found in Topic: "+topicId);
318
//                        }
319
//                    } else {
320
//                        // EXCEPTION - Category not found
321
//                        throw new EntityNotFoundException("Reorder indicators: Category with id: "+categoryId+" not found");
322
//                    }
323
//                } else {
324
//                    // EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
325
//                    throw new PathNotValidException("Reorder indicators: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId);
326
//                }
327
//            } else {
328
//                // EXCEPTION - Topic not found
329
//                throw new EntityNotFoundException("Reorder indicators: Topic with id: "+topicId+" not found");
330
//            }
331
//        } else {
332
//            // EXCEPTION - Stakeholder not found
333
//            throw new EntityNotFoundException("Reorder indicators: Stakeholder with id: "+stakeholderId+" not found");
334
//        }
335
//        return true;
336
//    }
337

  
338 439
    @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{type}/reorder", method = RequestMethod.POST)
339 440
    public List<Indicator> reorderIndicators(@PathVariable("stakeholderId") String stakeholderId,
340 441
                                     @PathVariable("topicId") String topicId,
......
342 443
                                     @PathVariable("subcategoryId") String subcategoryId,
343 444
                                     @PathVariable("type") String type,
344 445
                                     @RequestBody List<String> indicators) {
345
        log.debug("reorder indicators");
446
        log.debug("reorder indicators of type: "+type);
447
        log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
346 448

  
347 449
        Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
348 450

  
......
402 504
        }
403 505
        return indicatorsFull;
404 506
    }
507

  
508
    @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{indicatorId}/toggle-status", method = RequestMethod.POST)
509
    public Boolean toggleIndicatorStatus(@PathVariable("stakeholderId") String stakeholderId,
510
                                         @PathVariable("topicId") String topicId,
511
                                         @PathVariable("categoryId") String categoryId,
512
                                         @PathVariable("subcategoryId") String subcategoryId,
513
                                         @PathVariable("indicatorId") String indicatorId) {
514
        log.debug("toggle indicator status (isActive)");
515
        log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId+ " - Indicator: "+indicatorId);
516

  
517
        Indicator indicator = indicatorDAO.findById(indicatorId);
518
        if (indicator == null) {
519
            // EXCEPTION - Indicator not found
520
            throw new EntityNotFoundException("Toggle indicator status: Indicator with id: "+indicatorId+" not found");
521
        }
522
        indicator.setIsActive(!indicator.getIsActive());
523

  
524
        this.toggleIndicator(stakeholderId, topicId, categoryId, subcategoryId, indicator);
525

  
526
        return indicator.getIsActive();
527
    }
528

  
529
    @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{indicatorId}/toggle-access", method = RequestMethod.POST)
530
    public Boolean toggleIndicatorAccess(@PathVariable("stakeholderId") String stakeholderId,
531
                                         @PathVariable("topicId") String topicId,
532
                                         @PathVariable("categoryId") String categoryId,
533
                                         @PathVariable("subcategoryId") String subcategoryId,
534
                                         @PathVariable("indicatorId") String indicatorId) {
535
        log.debug("toggle indicator access (isPublic)");
536
        log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId+ " - Indicator: "+indicatorId);
537

  
538
        Indicator indicator = indicatorDAO.findById(indicatorId);
539
        if (indicator == null) {
540
            // EXCEPTION - Indicator not found
541
            throw new EntityNotFoundException("Toggle indicator access: Indicator with id: "+indicatorId+" not found");
542
        }
543
        indicator.setIsPublic(!indicator.getIsPublic());
544

  
545
        this.toggleIndicator(stakeholderId, topicId, categoryId, subcategoryId, indicator);
546

  
547
        return indicator.getIsPublic();
548
    }
549

  
550
    public void toggleIndicator(String stakeholderId, String topicId, String categoryId, String subcategoryId, Indicator indicator) {
551
        Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
552

  
553
        if (stakeholder != null) {
554

  
555
            Topic<String> topic = topicDAO.findById(topicId);
556
            if (topic != null) {
557
                if (stakeholder.getTopics().contains(topicId)) {
558

  
559
                    Category<String> category = categoryDAO.findById(categoryId);
560
                    if (category != null) {
561
                        if (topic.getCategories().contains(categoryId)) {
562

  
563
                            SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId);
564
                            if (subcategory != null) {
565
                                if (category.getSubCategories().contains(subcategoryId)) {
566
                                    indicatorDAO.save(indicator);
567
                                    log.debug("Indicator toggled!");
568
                                } else {
569
                                    // EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias();
570
                                    throw new PathNotValidException("Reorder indicators: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId);
571
                                }
572
                            } else {
573
                                // EXCEPTION - SubCategory not found
574
                                throw new EntityNotFoundException("Reorder indicators: SubCategory with id: "+subcategoryId+" not found");
575
                            }
576
                        } else {
577
                            // EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias();
578
                            throw new PathNotValidException("Reorder indicators: Category with id: "+categoryId+" not found in Topic: "+topicId);
579
                        }
580
                    } else {
581
                        // EXCEPTION - Category not found
582
                        throw new EntityNotFoundException("Reorder indicators: Category with id: "+categoryId+" not found");
583
                    }
584
                } else {
585
                    // EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
586
                    throw new PathNotValidException("Reorder indicators: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId);
587
                }
588
            } else {
589
                // EXCEPTION - Topic not found
590
                throw new EntityNotFoundException("Reorder indicators: Topic with id: "+topicId+" not found");
591
            }
592
        } else {
593
            // EXCEPTION - Stakeholder not found
594
            throw new EntityNotFoundException("Reorder indicators: Stakeholder with id: "+stakeholderId+" not found");
595
        }
596
    }
405 597
}
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java
47 47
        categoryFull.setSubCategories(subCategoriesFull);
48 48
        category.setSubCategories(subCategories);
49 49

  
50
        Category<String> categorySaved = categoryDAO.save(category);
50
        categoryDAO.save(category);
51 51

  
52
        categoryFull.setId(categorySaved.getId());
52
        categoryFull.setId(category.getId());
53 53
        return categoryFull;
54 54
    }
55 55

  
......
58 58
                                              @PathVariable("topicId") String topicId,
59 59
                                              @RequestBody Category<SubCategory> categoryFull) {
60 60
        log.debug("save category");
61
        log.debug("Alias: "+categoryFull.getAlias() + " - Id: "+categoryFull.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId);
61 62

  
62 63
        Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
63 64

  
......
69 70
                    // if category not exists (no id), create a new default subcategory, identical to category
70 71
                    if(categoryFull.getId() == null) {
71 72
                        SubCategory<String> subCategory = new SubCategory<>();
72
                        subCategory.setName("Overview");
73
                        subCategory.setAlias("overview");
74
                        subCategory.setIsActive(categoryFull.getIsActive());
75
                        subCategory.setIsPublic(categoryFull.getIsPublic());
76
                        subCategory.setIsDefault(true);
77
                        subCategory.setCharts(new ArrayList<String>());
78
                        subCategory.setNumbers(new ArrayList<String>());
73
                        subCategory.createOverviewSubCategory(categoryFull);
79 74

  
80
                        SubCategory<String> subCategorySaved = subCategoryDAO.save(subCategory);
75
                        subCategoryDAO.save(subCategory);
81 76
                        List<SubCategory> subCategories = categoryFull.getSubCategories();
82
                        subCategories.add(subCategorySaved);
77
                        subCategories.add(subCategory);
83 78
                    }
84 79

  
85 80

  
......
91 86
                    }
92 87
                    category.setSubCategories(subCategories);
93 88

  
94
                    Category<String> categorySaved = categoryDAO.save(category);
89
                    categoryDAO.save(category);
95 90

  
91
                    if(stakeholder.getDefaultId() == null) {
92
                        if(categoryFull.getId() == null) {
93
                            onSaveDefaultCategory(category, topicId);
94
                        } else {
95
                            onUpdateDefaultCategory(category);
96
                        }
97
                    }
98

  
96 99
                    List<String> categories = topic.getCategories();
97
                    int index = categories.indexOf(categorySaved.getId());
100
                    int index = categories.indexOf(category.getId());
98 101
                    if(index == -1) {
99
                        categories.add(categorySaved.getId());
102
                        categories.add(category.getId());
100 103
                        topicDAO.save(topic);
101 104
                        log.debug("Category saved!");
102 105

  
103
                        categoryFull.setId(categorySaved.getId());
106
                        categoryFull.setId(category.getId());
104 107
                    }
105 108

  
106 109
                    subCategories = null;
......
120 123
        return categoryFull;
121 124
    }
122 125

  
126
    public void onSaveDefaultCategory(Category<String> category, String topicId) {
127
        log.debug("On save default category");
128

  
129
        List<Topic> topics = topicDAO.findByDefaultId(topicId);
130
        for(Topic topic : topics) {
131
            Category categoryNew = new Category();
132
            categoryNew.copyFromDefault(category);
133

  
134
            categoryDAO.save(categoryNew);
135

  
136
            List<String> categories = topic.getCategories();
137
            categories.add(categoryNew.getId());
138

  
139
            topicDAO.save(topic);
140
        }
141
        String subCategoryOverviewId = category.getSubCategories().get(0);
142
        SubCategory subCategoryOverview = subCategoryDAO.findById(subCategoryOverviewId);
143
        subCategoryController.onSaveDefaultSubCategory(subCategoryOverview, category.getId());
144
    }
145

  
146
    public void onUpdateDefaultCategory(Category category) {
147
        log.debug("On update default category");
148

  
149
        List<Category> categories = categoryDAO.findByDefaultId(category.getId());
150
        boolean changed = false;
151
        for(Category categoryBasedOnDefault : categories) {
152
            if(category.getName() != null && !category.getName().equals(categoryBasedOnDefault.getName())) {
153
                changed = true;
154
            }
155
            if(category.getDescription() != null && !category.getDescription().equals(categoryBasedOnDefault.getDescription())) {
156
                changed = true;
157
            }
158

  
159
            if(!changed) {
160
                break;
161
            }
162
            categoryBasedOnDefault.setName(category.getName());
163
            categoryBasedOnDefault.setDescription(category.getDescription());
164
            categoryDAO.save(categoryBasedOnDefault);
165
        }
166
    }
167

  
123 168
    @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/delete", method = RequestMethod.DELETE)
124 169
    public boolean deleteCategory(@PathVariable("stakeholderId") String stakeholderId,
125 170
                                  @PathVariable("topicId") String topicId,
126 171
                                  @PathVariable("categoryId") String categoryId) {
127 172
        log.debug("delete category");
173
        log.debug("Id: "+categoryId + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId);
128 174

  
129 175
        Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
130 176

  
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TopicController.java
50 50
        topicFull.setCategories(categoriesFull);
51 51
        topic.setCategories(categories);
52 52

  
53
        Topic<String> topicSaved = topicDAO.save(topic);
53
        topicDAO.save(topic);
54 54

  
55
        topicFull.setId(topicSaved.getId());
55
        topicFull.setId(topic.getId());
56 56
        return topicFull;
57 57
    }
58 58

  
......
60 60
    public Topic<Category> saveTopic(@PathVariable("stakeholderId") String stakeholderId,
61 61
                                     @RequestBody Topic<Category> topicFull) {
62 62
        log.debug("save topic");
63
        log.debug("Alias: "+topicFull.getAlias() + " - Id: "+topicFull.getId()+ " - Stakeholder: "+stakeholderId);
63 64

  
64 65
        Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
65 66

  
......
73 74
            }
74 75
            topic.setCategories(categories);
75 76

  
76
            Topic<String> topicSaved = topicDAO.save(topic);
77
            topicDAO.save(topic);
77 78

  
79
            if(stakeholder.getDefaultId() == null) {
80
                if(topicFull.getId() == null) {
81
                    onSaveDefaultTopic(topic, stakeholderId);
82
                } else {
83
                    onUpdateDefaultTopic(topic);
84
                }
85
            }
86

  
78 87
            List<String> topics = stakeholder.getTopics();
79
            int index = topics.indexOf(topicSaved.getId());
88
            int index = topics.indexOf(topic.getId());
80 89
            if(index == -1) {
81
                topics.add(topicSaved.getId());
90
                topics.add(topic.getId());
82 91
                stakeholderDAO.save(stakeholder);
83 92
                log.debug("Topic saved!");
84 93

  
85
                topicFull.setId(topicSaved.getId());
94
                topicFull.setId(topic.getId());
86 95
            }
87 96

  
88 97
            categories = null;
......
94 103
        return topicFull;
95 104
    }
96 105

  
106
    public void onSaveDefaultTopic(Topic topic, String stakeholderId) {
107
        log.debug("On save default topic");
108

  
109
        List<Stakeholder> stakeholders = stakeholderDAO.findByDefaultId(stakeholderId);
110
        for(Stakeholder _stakeholder : stakeholders) {
111
            Topic topicNew = new Topic();
112
            topicNew.copyFromDefault(topic);
113

  
114
            topicDAO.save(topicNew);
115

  
116
            List<String> topics = _stakeholder.getTopics();
117
            topics.add(topicNew.getId());
118

  
119
            stakeholderDAO.save(_stakeholder);
120
        }
121
    }
122

  
123
    public void onUpdateDefaultTopic(Topic topic) {
124
        log.debug("On update default topic");
125

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

  
136
            if(!changed) {
137
                break;
138
            }
139
            topicBasedOnDefault.setName(topic.getName());
140
            topicBasedOnDefault.setDescription(topic.getDescription());
141
            topicDAO.save(topicBasedOnDefault);
142
        }
143
    }
144

  
97 145
    @RequestMapping(value = "/{stakeholderId}/{topicId}/delete", method = RequestMethod.DELETE)
98 146
    public boolean deleteTopic(@PathVariable("stakeholderId") String stakeholderId,
99 147
                               @PathVariable("topicId") String topicId) {
100 148
        log.debug("delete topic");
149
        log.debug("Id: "+topicId + " - Stakeholder: "+stakeholderId);
101 150

  
102 151
        Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
103 152

  
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java
39 39
    @RequestMapping(value = "/build-stakeholder", method = RequestMethod.POST)
40 40
    public Stakeholder<Topic<Category<SubCategory<Indicator>>>> buildFullStakeholder(@RequestBody Stakeholder<Topic<Category<SubCategory<Indicator>>>> stakeholderFull) {
41 41
        log.debug("build stakeholder");
42
        log.debug("Alias: "+stakeholderFull.getAlias());
42 43

  
43 44
        Stakeholder<String> stakeholder = new Stakeholder<>(stakeholderFull);
44 45

  
......
52 53
        stakeholderFull.setTopics(topicsFull);
53 54
        stakeholder.setTopics(topics);
54 55

  
56
        Date date = new Date();
57
        stakeholder.setCreationDate(date);
58
        stakeholder.setUpdateDate(date);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff