Project

General

Profile

« Previous | Next » 

Revision 61803

[maven-release-plugin] copy for tag uoa-admin-tools-library-1.0.3

View differences:

modules/uoa-admin-tools-library/tags/uoa-admin-tools-library-1.0.3/src/main/java/eu/dnetlib/uoaadmintoolslibrary/entities/fullEntities/PageHelpContentResponse.java
1
package eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities;
2

  
3
import com.fasterxml.jackson.annotation.JsonProperty;
4
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
5
import org.springframework.data.annotation.Id;
6

  
7
import eu.dnetlib.uoaadmintoolslibrary.entities.Page;
8
import eu.dnetlib.uoaadmintoolslibrary.entities.PageHelpContent;
9

  
10
public class PageHelpContentResponse {
11

  
12
    @Id
13
    @JsonProperty("_id")
14
    private String id;
15

  
16
    private Page page;
17
    private Portal portal;
18
    private String placement;
19
    private int order;
20
    private String content;
21
    private boolean isActive = true;
22
    private boolean isPriorTo = false;
23

  
24
    public PageHelpContentResponse() {}
25

  
26
    public PageHelpContentResponse(PageHelpContent pageHelpContent) {
27
        this.id = pageHelpContent.getId();
28
        this.placement = pageHelpContent.getPlacement();
29
        this.order = pageHelpContent.getOrder();
30
        this.content = pageHelpContent.getContent();
31
        this.isActive = pageHelpContent.getIsActive();
32
        this.isPriorTo = pageHelpContent.getIsPriorTo();
33
    }
34

  
35
    public String getId() {
36
        return id;
37
    }
38

  
39
    public void setId(String id) {
40
        this.id = id;
41
    }
42

  
43
    public Page getPage() {
44
        return page;
45
    }
46

  
47
    public void setPage(Page page) {
48
        this.page = page;
49
    }
50

  
51
    public Portal getPortal() {
52
        return portal;
53
    }
54

  
55
    public void setPortal(Portal portal) {
56
        this.portal = portal;
57
    }
58

  
59
    public String getPlacement() {
60
        return placement;
61
    }
62

  
63
    public void setPlacement(String placement) {
64
        this.placement = placement;
65
    }
66

  
67
    public int getOrder() {
68
        return order;
69
    }
70

  
71
    public void setOrder(int order) {
72
        this.order = order;
73
    }
74

  
75
    public String getContent() {
76
        return content;
77
    }
78

  
79
    public void setContent(String content) {
80
        this.content = content;
81
    }
82

  
83
    public boolean getIsActive() {
84
        return isActive;
85
    }
86

  
87
    public void setIsActive(boolean isActive) {
88
        this.isActive = isActive;
89
    }
90

  
91
    public boolean getIsPriorTo() { return isPriorTo; }
92

  
93
    public void setIsPriorTo(boolean isPriorTo) { this.isPriorTo = isPriorTo; }
94
}
modules/uoa-admin-tools-library/tags/uoa-admin-tools-library-1.0.3/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
    <modelVersion>4.0.0</modelVersion>
4
    <artifactId>uoa-admin-tools-library</artifactId>
5
    <version>1.0.3</version>
6
    <packaging>jar</packaging>
7
    <name>uoa-admin-tools-library</name>
8
    <parent>
9
        <groupId>eu.dnetlib</groupId>
10
        <artifactId>dnet45-parent</artifactId>
11
        <version>1.0.0</version>
12
    </parent>
13
    <scm>
14
        <developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet45/modules/uoa-admin-tools-library/tags/uoa-admin-tools-library-1.0.3</developerConnection>
15
    </scm>
16
    <properties>
17
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
19
        <java.version>1.8</java.version>
20
        <timestampAdminToolsLibrary>${maven.build.timestamp}</timestampAdminToolsLibrary>
21
        <maven.build.timestamp.format>E MMM dd HH:mm:ss z yyyy</maven.build.timestamp.format>
22
    </properties>
23
    <dependencyManagement>
24
        <dependencies>
25
            <dependency>
26
                <groupId>org.springframework.boot</groupId>
27
                <artifactId>spring-boot-dependencies</artifactId>
28
                <version>1.5.8.RELEASE</version>
29
                <type>pom</type>
30
                <scope>import</scope>
31
            </dependency>
32
        </dependencies>
33
    </dependencyManagement>
34
    <dependencies>
35
        <dependency>
36
            <groupId>org.springframework.boot</groupId>
37
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
38
        </dependency>
39
        <dependency>
40
            <groupId>org.springframework.boot</groupId>
41
            <artifactId>spring-boot-starter-web</artifactId>
42
            <exclusions>
43
                <exclusion>
44
                    <groupId> org.springframework.boot</groupId>
45
                    <artifactId>spring-boot-starter-logging</artifactId>
46
                </exclusion>
47
            </exclusions>
48
        </dependency>
49
        <dependency>
50
            <groupId>org.springframework.boot</groupId>
51
            <artifactId>spring-boot-starter-tomcat</artifactId>
52
            <scope>provided</scope>
53
        </dependency>
54
        <dependency>
55
            <groupId>org.springframework.boot</groupId>
56
            <artifactId>spring-boot-starter-test</artifactId>
57
            <scope>test</scope>
58
        </dependency>
59
        <dependency>
60
            <groupId>org.springframework.boot</groupId>
61
            <artifactId>spring-boot-starter-security</artifactId>
62
        </dependency>
63
        <dependency>
64
            <groupId>log4j</groupId>
65
            <artifactId>log4j</artifactId>
66
            <version>1.2.17</version>
67
        </dependency>
68
        <dependency>
69
            <groupId>javax.mail</groupId>
70
            <artifactId>mail</artifactId>
71
            <version>1.5.0-b01</version>
72
        </dependency>
73
        <dependency>
74
            <groupId>eu.dnetlib</groupId>
75
            <artifactId>uoa-authorization-library</artifactId>
76
            <version>2.0.3</version>
77
        </dependency>
78
    </dependencies>
79
    <build>
80
        <plugins>
81
        </plugins>
82
        <finalName>uoa-admin-tools-library</finalName>
83
        <resources>
84
            <resource>
85
                <directory>src/main/resources</directory>
86
                <filtering>true</filtering>
87
            </resource>
88
        </resources>
89
    </build>
90
</project>
modules/uoa-admin-tools-library/tags/uoa-admin-tools-library-1.0.3/src/main/java/eu/dnetlib/uoaadmintoolslibrary/entities/fullEntities/PortalEntity.java
1
package eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities;
2

  
3
import com.fasterxml.jackson.annotation.JsonProperty;
4
import org.springframework.data.annotation.Id;
5

  
6
import eu.dnetlib.uoaadmintoolslibrary.entities.Entity;
7

  
8
public class PortalEntity {
9
    @Id
10
    @JsonProperty("_id")
11
    private String id;
12

  
13
    private String pid;
14
    private String name;
15
    private Boolean isEnabled;
16

  
17
    public PortalEntity() {}
18

  
19
    public PortalEntity(Entity entity) {
20
        this.setId(entity.getId());
21
        this.setPid(entity.getPid());
22
        this.setName(entity.getName());
23
        this.setIsEnabled(true);
24
    }
25

  
26
    public String getId() {
27
        return id;
28
    }
29

  
30
    public void setId(String id) {
31
        this.id = id;
32
    }
33

  
34
    public String getPid() {
35
        return pid;
36
    }
37

  
38
    public void setPid(String pid) { this.pid = pid; }
39

  
40
    public String getName() {
41
        return name;
42
    }
43

  
44
    public void setName(String name) {
45
        this.name = name;
46
    }
47

  
48
    public Boolean getIsEnabled() { return isEnabled; }
49

  
50
    public void setIsEnabled(Boolean isEnabled) { this.isEnabled = isEnabled; }
51
}
52

  
modules/uoa-admin-tools-library/tags/uoa-admin-tools-library-1.0.3/src/main/java/eu/dnetlib/uoaadmintoolslibrary/entities/DivId.java
1
package eu.dnetlib.uoaadmintoolslibrary.entities;
2

  
3
import com.fasterxml.jackson.annotation.JsonProperty;
4
import org.springframework.data.annotation.Id;
5

  
6
import java.util.List;
7

  
8
public class DivId {
9
    @Id
10
    @JsonProperty("_id")
11
    private String id;
12

  
13
    private String name;
14
    private List<String> pages;
15
    private PortalType portalType; // explore, connect, community, monitor
16

  
17
//    private Boolean connect;
18
//    private Boolean communities;
19
//    private Boolean openaire;
20

  
21
    public DivId() {}
22

  
23
    public DivId(DivId divId) {
24
        setName(divId.getName());
25
        setPages(divId.getPages());
26
        setPortalType(divId.getPortalType());
27
    }
28

  
29
    public String getId() {
30
        return id;
31
    }
32

  
33
    public void setId(String id) {
34
        this.id = id;
35
    }
36

  
37
    public String getName() {
38
        return name;
39
    }
40

  
41
    public void setName(String name) {
42
        this.name = name;
43
    }
44

  
45
    public List<String> getPages() {
46
        return pages;
47
    }
48

  
49
    public void setPages(List<String> pages) {
50
        this.pages = pages;
51
    }
52

  
53
    public String getPortalType() {
54
        if(portalType == null) {
55
            return null;
56
        }
57
        return portalType.name();
58
    }
59

  
60
    public void setPortalType(String portalType) {
61
        if(portalType == null) {
62
            this.portalType = null;
63
        } else {
64
            PortalType pType = PortalType.valueOf(portalType);
65
            this.portalType = pType;
66
        }
67
    }
68
}
modules/uoa-admin-tools-library/tags/uoa-admin-tools-library-1.0.3/src/main/java/eu/dnetlib/uoaadmintoolslibrary/entities/PageHelpContent.java
1
package eu.dnetlib.uoaadmintoolslibrary.entities;
2

  
3
import com.fasterxml.jackson.annotation.JsonProperty;
4
import org.springframework.data.annotation.Id;
5

  
6
public class PageHelpContent {
7
    @Id
8
    @JsonProperty("_id")
9
    private String id;
10

  
11
    private String page;
12
    private String portal;
13
    private String placement;
14
    private int order;
15
    private String content;
16
    private boolean isActive = true;
17
    private boolean isPriorTo = false;
18

  
19
    public PageHelpContent() {}
20

  
21
    public PageHelpContent(String page, String portal, String placement, int order, String content, boolean isActive, boolean isPriorTo) {
22
        this.page = page;
23
        this.portal = portal;
24
        this.placement = placement;
25
        this.order = order;
26
        this.content = content;
27
        this.isActive = isActive;
28
        this.isPriorTo = isPriorTo;
29
    }
30

  
31
    public String getId() {
32
        return id;
33
    }
34

  
35
    public void setId(String id) {
36
        this.id = id;
37
    }
38

  
39
    public String getPage() {
40
        return page;
41
    }
42

  
43
    public void setPage(String page) {
44
        this.page = page;
45
    }
46

  
47
    public String getPortal() {
48
        return portal;
49
    }
50

  
51
    public void setPortal(String portal) {
52
        this.portal = portal;
53
    }
54

  
55
    public String getPlacement() {
56
        return placement;
57
    }
58

  
59
    public void setPlacement(String placement) {
60
        this.placement = placement;
61
    }
62

  
63
    public int getOrder() {
64
        return order;
65
    }
66

  
67
    public void setOrder(int order) {
68
        this.order = order;
69
    }
70

  
71
    public String getContent() {
72
        return content;
73
    }
74

  
75
    public void setContent(String content) {
76
        this.content = content;
77
    }
78

  
79
    public boolean getIsActive() {
80
        return isActive;
81
    }
82

  
83
    public void setIsActive(boolean isActive) {
84
        this.isActive = isActive;
85
    }
86

  
87
    public boolean getIsPriorTo() { return isPriorTo; }
88

  
89
    public void setIsPriorTo(boolean isPriorTo) { this.isPriorTo = isPriorTo; }
90
}
modules/uoa-admin-tools-library/tags/uoa-admin-tools-library-1.0.3/src/main/java/eu/dnetlib/uoaadmintoolslibrary/entities/email/Email.java
1
package eu.dnetlib.uoaadmintoolslibrary.entities.email;
2

  
3
import java.util.List;
4

  
5
public class Email {
6
    String subject;
7
    List<String> recipients;
8
    String body;
9

  
10
    public String getSubject() {
11
        return subject;
12
    }
13

  
14
    public void setSubject(String subject) {
15
        this.subject = subject;
16
    }
17

  
18
    public List<String> getRecipients() {
19
        return recipients;
20
    }
21

  
22
    public void setRecipients(List<String> recipients) {
23
        this.recipients = recipients;
24
    }
25

  
26
    public String getBody() {
27
        return body;
28
    }
29

  
30
    public void setBody(String body) {
31
        this.body = body;
32
    }
33
}
modules/uoa-admin-tools-library/tags/uoa-admin-tools-library-1.0.3/src/main/java/eu/dnetlib/uoaadmintoolslibrary/entities/email/EmailRecaptcha.java
1
package eu.dnetlib.uoaadmintoolslibrary.entities.email;
2

  
3
public class EmailRecaptcha {
4
    private Email email;
5
    private String recaptcha;
6

  
7
    public Email getEmail() {
8
        return email;
9
    }
10

  
11
    public void setEmail(Email email) {
12
        this.email = email;
13
    }
14

  
15
    public String getRecaptcha() {
16
        return recaptcha;
17
    }
18

  
19
    public void setRecaptcha(String recaptcha) {
20
        this.recaptcha = recaptcha;
21
    }
22
}
modules/uoa-admin-tools-library/tags/uoa-admin-tools-library-1.0.3/src/main/java/eu/dnetlib/uoaadmintoolslibrary/entities/Entity.java
1
package eu.dnetlib.uoaadmintoolslibrary.entities;
2

  
3
import com.fasterxml.jackson.annotation.JsonProperty;
4
import org.springframework.data.annotation.Id;
5

  
6
public class Entity {
7
    @Id
8
    @JsonProperty("_id")
9
    private String id;
10

  
11
    private String pid;
12
    private String name;
13

  
14
    public Entity() {}
15

  
16
    public String getId() {
17
        return id;
18
    }
19

  
20
    public void setId(String id) {
21
        this.id = id;
22
    }
23

  
24
    public String getPid() {
25
        return pid;
26
    }
27

  
28
    public void setPid(String pid) {
29
        this.pid = pid;
30
    }
31

  
32
    public String getName() {
33
        return name;
34
    }
35

  
36
    public void setName(String name) {
37
        this.name = name;
38
    }
39
}
modules/uoa-admin-tools-library/tags/uoa-admin-tools-library-1.0.3/src/main/java/eu/dnetlib/uoaadmintoolslibrary/services/PageHelpContentService.java
1
package eu.dnetlib.uoaadmintoolslibrary.services;
2

  
3
import eu.dnetlib.uoaadmintoolslibrary.dao.PageHelpContentDAO;
4
import eu.dnetlib.uoaadmintoolslibrary.entities.Page;
5
import eu.dnetlib.uoaadmintoolslibrary.entities.PageHelpContent;
6
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
7
import eu.dnetlib.uoaadmintoolslibrary.entities.PortalType;
8
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PageHelpContentResponse;
9

  
10
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
11
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
12
import org.apache.log4j.Logger;
13
import org.springframework.beans.factory.annotation.Autowired;
14
import org.springframework.stereotype.Service;
15

  
16
import java.util.ArrayList;
17
import java.util.List;
18

  
19
@Service
20
public class PageHelpContentService {
21
    private final Logger log = Logger.getLogger(this.getClass());
22

  
23
    @Autowired
24
    private PageHelpContentDAO pageHelpContentDAO;
25

  
26
    @Autowired
27
    private PageService pageService;
28

  
29
    @Autowired
30
    private PortalService portalService;
31

  
32
    public List<PageHelpContentResponse> getPageHelpContents(String pid, String portalType, String page, String position, String active, String before) {
33
        List<PageHelpContent> pageHelpContents = null;
34

  
35
        Portal _portal = null;
36
        String portalId = null;
37
        if(pid != null) {
38
            _portal = portalService.getPortal(pid);
39
            if(_portal != null) {
40
                portalId = _portal.getId();
41
            }
42
        }
43

  
44
        if(pid != null && position != null && active != null && before != null) {
45
            pageHelpContents = pageHelpContentDAO.findByPortalAndPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(portalId, position, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
46
        } else if(pid != null && position != null && active != null) {
47
            pageHelpContents = pageHelpContentDAO.findByPortalAndPlacementAndIsActiveOrderByOrderAsc(portalId, position, Boolean.parseBoolean(active));
48
        } else if(pid != null && position != null && before != null) {
49
            pageHelpContents = pageHelpContentDAO.findByPortalAndPlacementAndIsPriorToOrderByOrderAsc(portalId, position, Boolean.parseBoolean(before));
50
        } else if(pid != null && active != null && before != null) {
51
            pageHelpContents = pageHelpContentDAO.findByPortalAndIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(portalId, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
52
        } else if(position != null && active != null && before != null) {
53
            pageHelpContents = pageHelpContentDAO.findByPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(position, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
54
        } else if(pid != null && position != null ) {
55
            pageHelpContents = pageHelpContentDAO.findByPortalAndPlacementOrderByOrderAsc(portalId, position);
56
        } else if(pid != null && active != null ) {
57
            pageHelpContents = pageHelpContentDAO.findByPortalAndIsActiveOrderByPlacementAscOrderAsc(portalId, Boolean.parseBoolean(active));
58
        } else if(pid != null && before != null) {
59
            pageHelpContents = pageHelpContentDAO.findByPortalAndIsPriorToOrderByPlacementAscOrderAsc(portalId, Boolean.parseBoolean(before));
60
        } else if(position != null && active != null) {
61
            pageHelpContents = pageHelpContentDAO.findByPlacementAndIsActiveOrderByOrderAsc(position, Boolean.parseBoolean(active));
62
        } else if(position != null && before != null) {
63
            pageHelpContents = pageHelpContentDAO.findByPlacementAndIsPriorToOrderByOrderAsc(position,  Boolean.parseBoolean(before));
64
        } else if(active != null && before != null) {
65
            pageHelpContents = pageHelpContentDAO.findByIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(Boolean.parseBoolean(active), Boolean.parseBoolean(before));
66
        } else if(pid != null) {
67
            pageHelpContents = pageHelpContentDAO.findByPortalOrderByPlacementAscOrderAsc(portalId);
68
        } else if(position != null) {
69
            pageHelpContents = pageHelpContentDAO.findByPlacementOrderByOrderAsc(position);
70
        } else if(active != null) {
71
            pageHelpContents = pageHelpContentDAO.findByIsActiveOrderByPlacementAscOrderAsc(Boolean.parseBoolean(active));
72
        } else if(before != null) {
73
            pageHelpContents = pageHelpContentDAO.findByIsPriorToOrderByPlacementAscOrderAsc(Boolean.parseBoolean(before));
74
        } else {
75
            pageHelpContents = pageHelpContentDAO.findAllByOrderByPlacementAscOrderAsc();
76
        }
77

  
78
        List<PageHelpContentResponse> pageHelpContentResponses = new ArrayList<>();
79
        for (PageHelpContent pageHelpContent : pageHelpContents) {
80
            Page _page = pageService.getPage(pageHelpContent.getPage());
81
            if((page == null || page.equals(_page.getRoute())) && (portalType == null || portalType.equals(_page.getPortalType()))) {
82
                PageHelpContentResponse pageHelpContentResponse = new PageHelpContentResponse(pageHelpContent);
83

  
84
                pageHelpContentResponse.setPage(_page);
85
                pageHelpContentResponse.setPortal(portalService.getPortalById(pageHelpContent.getPortal()));
86
                pageHelpContentResponses.add(pageHelpContentResponse);
87
            }
88
        }
89
        return pageHelpContentResponses;
90
    }
91

  
92
    public List<PageHelpContent> getPageHelpContentsBasic(String pid, String portalType, String pageId) {
93
        List<PageHelpContent> pageHelpContents = null;
94

  
95
        Portal _portal = null;
96
        String portalId = null;
97
        if(pid != null) {
98
            _portal = portalService.getPortal(pid);
99
            portalService.checkPortalInfo(pid, portalType, _portal, pid, "pid");
100
            if(_portal != null) {
101
                portalId = _portal.getId();
102
            }
103
        }
104

  
105
        if(pid != null && pageId != null) {
106
            pageHelpContents = pageHelpContentDAO.findByPortalAndPageOrderByPlacementAscOrderAsc(portalId, pageId);
107
        } else if(pid != null) {
108
            pageHelpContents = pageHelpContentDAO.findByPortalOrderByPlacementAscOrderAsc(portalId);
109
        } else {
110
            pageHelpContents = pageHelpContentDAO.findAllByOrderByPlacementAscOrderAsc();
111
        }
112

  
113
        return pageHelpContents;
114
    }
115

  
116
    public void deleteAllPageHelpContents() {
117
        pageHelpContentDAO.deleteAll();
118
    }
119

  
120
//    public PageHelpContent insertPageHelpContent(PageHelpContent pageHelpContent) {
121
//        String portalId = portalService.getPortal(pageHelpContent.getPortal()).getId();
122
//        pageHelpContent.setPortal(portalId);
123
//        return pageHelpContentDAO.save(pageHelpContent);
124
//    }
125
//
126
//    public PageHelpContent updatePageHelpContent(PageHelpContent pageHelpContent) {
127
//        return pageHelpContentDAO.save(pageHelpContent);
128
//    }
129

  
130
    public PageHelpContent insertOrUpdatePageHelpContent(PageHelpContent pageHelpContent) {
131
        return pageHelpContentDAO.save(pageHelpContent);
132
    }
133

  
134
    public PageHelpContent getPageHelpContent(String id) {
135
        return pageHelpContentDAO.findById(id);
136
    }
137

  
138
    public List<String> togglePageHelpContent(List<String> pageHelpContents, String status, String pid, PortalType portalType) throws Exception {
139
        Portal portal = portalService.getPortal(pid);
140
        portalService.checkPortalInfo(pid, portalType.name(), portal, pid, "pid");
141

  
142
        for (String id: pageHelpContents) {
143
//            log.debug("Id of pageHelpContent: "+id);
144
            PageHelpContent pageHelpContent = pageHelpContentDAO.findById(id);
145
            if(pageHelpContent == null) {
146
                throw new ContentNotFoundException("Page help content with id: " + id + " not found");
147
            }
148
            if(!pageHelpContent.getPortal().equals(portal.getId())) {
149
                throw new MismatchingContentException("["+portalType+ " - "+ pid+"] Conflicting page help content: portal id: "+pageHelpContent.getPortal());
150
            }
151
            pageHelpContent.setIsActive(Boolean.parseBoolean(status));
152
            pageHelpContentDAO.save(pageHelpContent);
153
        }
154
        return pageHelpContents;
155
    }
156

  
157
    public void deletePageHelpContent(String id) {
158
        pageHelpContentDAO.delete(id);
159
    }
160

  
161
    public Boolean deletePageHelpContents(List<String> pageHelpContents, String pid, PortalType portalType) throws Exception {
162
        Portal portal = portalService.getPortal(pid);
163
        portalService.checkPortalInfo(pid, portalType.name(), portal, pid, "pid");
164

  
165
        for (String id: pageHelpContents) {
166
            PageHelpContent pageHelpContent = getPageHelpContent(id);
167
            if(pageHelpContent == null) {
168
                throw new ContentNotFoundException("Page help content with id: " + id + " not found");
169
            }
170
            if(!pageHelpContent.getPortal().equals(portal.getId())) {
171
                throw new MismatchingContentException("["+portalType+ " - "+ pid+"] Conflicting page help content: portal id: "+pageHelpContent.getPortal());
172
            }
173
            pageHelpContentDAO.delete(id);
174
        }
175
        return true;
176
    }
177

  
178
    public void addPageHelpContentsInPortal(String portalId, String portalType) {
179
        Page organizationsPage = pageService.getPageByPortalTypeAndRoute(portalType, "/organizations");
180
        if(organizationsPage != null) {
181
            String organizations_page_content = "<div> <p>Here you can write more details about the organizations related to your community.</p> </div>";
182

  
183
            PageHelpContent organizations_pageHelpContent = new PageHelpContent(organizationsPage.getId(), portalId, "top", 1, organizations_page_content, false, false);
184
            //this.insertPageHelpContent(organizations_pageHelpContent);
185
            pageHelpContentDAO.save(organizations_pageHelpContent);
186
        }
187

  
188
        Page depositLearnHowPage = pageService.getPageByPortalTypeAndRoute(portalType, "/participate/deposit/learn-how");
189
        if(depositLearnHowPage != null) {
190
            String depositLearnHow_page_content = "" +
191
                    "<div class=\"uk-width-3-5 uk-align-center\"> " +
192
                    " <div class=\"uk-text-bold\">How to comply with funder Open Access policies</div> " +
193
                    " <ul class=\"uk-list uk-list-bullet\"> " +
194
                    "   <li>Read the <a href=\"https://www.openaire.eu/how-to-comply-to-h2020-mandates-for-publications\" target=\"_blank\"> <span>OpenAIRE guide to learn how to comply with EC H2020 Open Access policy on publications>/span> <span class=\"custom-external custom-icon space\"> </span> </a></li> " +
195
                    "   <li>Read the <a href=\"https://www.openaire.eu/how-to-comply-to-h2020-mandates-for-data\" target=\"_blank\"> <span>OpenAIRE guide to learn how to comply with EC H2020 Open Access policy on research data</span> <span class=\"custom-external custom-icon space\"> </span></a></li> " +
196
                    "   <li>If you want to know about National Open Access policies, please check them out <a href=\"https://www.openaire.eu/frontpage/country-pages\" target=\"_blank\"><span>here</span> <span class=\"custom-external custom-icon space\"> </span></a></li> " +
197
                    "   <li>All OpenAIRE guides can be found <a href=\"https://www.openaire.eu/guides\" target=\"_blank\"><span>here</span> <span class=\"custom-external custom-icon space\"> </span></a></li> " +
198
                    " </ul> " +
199
                    "</div>";
200

  
201
            PageHelpContent depositLearnHow_pageHelpContent = new PageHelpContent(depositLearnHowPage.getId(), portalId, "bottom", 1, depositLearnHow_page_content, true, false);
202
            //this.insertPageHelpContent(depositLearnHow_pageHelpContent);
203
            pageHelpContentDAO.save(depositLearnHow_pageHelpContent);
204
        }
205
    }
206
}
modules/uoa-admin-tools-library/tags/uoa-admin-tools-library-1.0.3/src/main/java/eu/dnetlib/uoaadmintoolslibrary/handlers/AdminToolsLibraryExceptionsHandler.java
1
package eu.dnetlib.uoaadmintoolslibrary.handlers;
2

  
3
import eu.dnetlib.uoaadmintoolslibrary.responses.ExceptionResponse;
4
import org.apache.log4j.Logger;
5
import org.springframework.dao.DuplicateKeyException;
6
import org.springframework.data.crossstore.ChangeSetPersister;
7
import org.springframework.http.HttpStatus;
8
import org.springframework.http.ResponseEntity;
9
import org.springframework.web.bind.MissingServletRequestParameterException;
10
import org.springframework.web.bind.annotation.ControllerAdvice;
11
import org.springframework.web.bind.annotation.ExceptionHandler;
12

  
13
@ControllerAdvice
14
public class AdminToolsLibraryExceptionsHandler {
15
    private final Logger log = Logger.getLogger(this.getClass());
16

  
17
    @ExceptionHandler(MissingServletRequestParameterException.class)
18
    public ResponseEntity<ExceptionResponse> invalidInput(Exception ex) {
19
        ExceptionResponse response = new ExceptionResponse();
20
        response.setErrorCode("Validation Error");
21
        response.setErrorMessage("Invalid inputs.");
22
        response.setErrors(ex.getMessage());
23
        response.setStatus(HttpStatus.BAD_REQUEST);
24
        log.error("invalidInput exception");
25

  
26
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
27
    }
28

  
29
    @ExceptionHandler(MismatchingContentException.class)
30
    public ResponseEntity<ExceptionResponse> mismatchingContentException(Exception ex) {
31
        ExceptionResponse response = new ExceptionResponse();
32
        response.setErrorCode("Conflicting content given");
33
        response.setErrorMessage(ex.getMessage());
34
        response.setErrors(ex.getMessage());
35
        response.setStatus(HttpStatus.BAD_REQUEST);
36
        log.error("mismatchingContent exception: " + response.getErrorCode()+ " "+response.getErrorMessage());
37
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
38
    }
39

  
40
    @ExceptionHandler(ContentNotFoundException.class)
41
    public ResponseEntity<ExceptionResponse> contentNotFoundException(Exception ex) {
42
        ExceptionResponse response = new ExceptionResponse();
43
        response.setErrorCode("No content found");
44
        response.setErrorMessage(ex.getMessage());
45
        response.setErrors(ex.getMessage());
46
        response.setStatus(HttpStatus.NOT_FOUND);
47
        log.error("contentNotFound exception: " + response.getErrorCode()+ " "+response.getErrorMessage());
48
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.NOT_FOUND);
49
    }
50

  
51
    @ExceptionHandler(NullPointerException.class)
52
    public ResponseEntity<ExceptionResponse> nullPointerException(Exception ex) {
53
        ExceptionResponse response = new ExceptionResponse();
54
        response.setErrorCode("Null pointer Exception");
55
        response.setErrorMessage("Null pointer Exception");
56
        response.setErrors(ex.getMessage());
57
        response.setStatus(HttpStatus.BAD_REQUEST);
58
        log.error("nullPointerException exception");
59
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
60
    }
61

  
62
    @ExceptionHandler(InvalidReCaptchaException.class)
63
    public ResponseEntity<ExceptionResponse> invalidReCaptchaException(Exception ex) {
64
        ExceptionResponse response = new ExceptionResponse();
65
        response.setErrorCode("Invalid ReCaptcha Exception");
66
        response.setErrorMessage("Invalid ReCaptcha Exception");
67
        response.setErrors(ex.getMessage());
68
        response.setStatus(HttpStatus.BAD_REQUEST);
69
        log.error("invalidReCaptchaException exception");
70
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
71
    }
72

  
73

  
74
    @ExceptionHandler(ChangeSetPersister.NotFoundException.class)
75
    public ResponseEntity<ExceptionResponse> notFoundException(Exception ex) {
76
        ExceptionResponse response = new ExceptionResponse();
77
        response.setErrorCode("Not found Exception");
78
        response.setErrorMessage("Not found Exception");
79
        response.setErrors(ex.getMessage());
80
        response.setStatus(HttpStatus.NOT_FOUND);
81
        log.error("notFoundException exception : "+ ex.getMessage());
82
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.NOT_FOUND);
83
    }
84

  
85
    @ExceptionHandler(ForbiddenException.class)
86
    public ResponseEntity<ExceptionResponse> forbiddenException(Exception ex) {
87
        ExceptionResponse response = new ExceptionResponse();
88
        response.setErrorCode("Forbidden Exception");
89
        response.setErrorMessage("Forbidden Exception");
90
        response.setErrors(ex.getMessage());
91
        response.setStatus(HttpStatus.FORBIDDEN);
92
        log.error("forbiddenException exception: "+ ex.getMessage());
93
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.FORBIDDEN);
94
    }
95

  
96
    @ExceptionHandler(DuplicateKeyException.class)
97
    public ResponseEntity<ExceptionResponse> duplicateKeyException(Exception ex) {
98
        ExceptionResponse response = new ExceptionResponse();
99
        response.setErrorCode("DuplicateKey Exception");
100
        response.setErrorMessage("DuplicateKey Exception");
101
        response.setErrors(ex.getMessage());
102
        response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR);
103
        log.error("duplicateKeyException exception: "+ ex.getMessage());
104
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.INTERNAL_SERVER_ERROR);
105
    }
106
}
modules/uoa-admin-tools-library/tags/uoa-admin-tools-library-1.0.3/src/main/java/eu/dnetlib/uoaadmintoolslibrary/handlers/utils/RolesUtils.java
1
package eu.dnetlib.uoaadmintoolslibrary.handlers.utils;
2

  
3
import eu.dnetlib.uoaauthorizationlibrary.security.AuthorizationService;
4
import org.apache.log4j.Logger;
5

  
6
import java.util.List;
7

  
8
import org.springframework.beans.factory.annotation.Autowired;
9
import org.springframework.stereotype.Component;
10

  
11
@Component
12
public class RolesUtils {
13
    @Autowired
14
    private AuthorizationService authorizationService;
15

  
16
    private final Logger log = Logger.getLogger(this.getClass());
17

  
18
    public List<String> getRoles() {
19
        return authorizationService.getRoles();
20
    }
21

  
22
    public String getEmail() {
23
        return authorizationService.getEmail();
24
    }
25

  
26
    public String getAaiId() {
27
        return authorizationService.getAaiId();
28
    }
29

  
30
    public boolean isPortalAdmin(List<String> roles) {
31
        if(roles == null) {
32
            return false;
33
        }
34
//        log.debug(authorizationService.PORTAL_ADMIN);
35
//        log.debug("PortalAdmin: "+roles.contains(authorizationService.PORTAL_ADMIN));
36
        return roles.contains(authorizationService.PORTAL_ADMIN);
37
    }
38

  
39
    public boolean isCurator(List<String> roles, String type) {
40
        if(roles == null) {
41
            return false;
42
        }
43
//        log.debug(authorizationService.curator(type));
44
//        log.debug("Curator in "+type+": "+roles.contains(authorizationService.curator(type)));
45
        return roles.contains(authorizationService.curator(type));
46
    }
47

  
48
    public boolean isManager(List<String> roles, String type, String id) {
49
        if(roles == null) {
50
            return false;
51
        }
52
//        log.debug(authorizationService.manager(type, id));
53
//        log.debug("Manager in "+type+" - "+id+": "+roles.contains(authorizationService.manager(type, id)));
54
        return roles.contains(authorizationService.manager(type, id));
55
    }
56

  
57
    public boolean isMember(List<String> roles, String type, String id) {
58
        if(roles == null) {
59
            return false;
60
        }
61
//        log.debug(authorizationService.member(type, id));
62
//        log.debug("Member in "+type+" - "+id+": "+roles.contains(authorizationService.member(type, id)));
63
        return roles.contains(authorizationService.member(type, id));
64
    }
65

  
66
    public boolean isLoggedIn(List<String> roles) {
67
        if(roles == null || roles.contains(authorizationService.ANONYMOUS_USER)) {
68
            return false;
69
        }
70
        return true;
71
    }
72

  
73
    public boolean hasUpdateAuthority(List<String> roles, String type, String id) {
74
        return isPortalAdmin(roles) || isCurator(roles, type) || isManager(roles, type, id);
75
    }
76

  
77
    public boolean hasCreateAndDeleteAuthority(List<String> roles, String type) {
78
        return isPortalAdmin(roles) || isCurator(roles, type);
79
    }
80
}
modules/uoa-admin-tools-library/tags/uoa-admin-tools-library-1.0.3/src/main/java/eu/dnetlib/uoaadmintoolslibrary/handlers/ForbiddenException.java
1
package eu.dnetlib.uoaadmintoolslibrary.handlers;
2

  
3
import org.springframework.http.HttpStatus;
4
import org.springframework.web.bind.annotation.ResponseStatus;
5

  
6
@ResponseStatus(HttpStatus.FORBIDDEN)
7
public class ForbiddenException extends RuntimeException {
8
    public ForbiddenException(String message){
9
        super(message);
10
    }
11
}
modules/uoa-admin-tools-library/tags/uoa-admin-tools-library-1.0.3/src/main/java/eu/dnetlib/uoaadmintoolslibrary/services/PageService.java
1
package eu.dnetlib.uoaadmintoolslibrary.services;
2

  
3
import eu.dnetlib.uoaadmintoolslibrary.dao.PageDAO;
4
import eu.dnetlib.uoaadmintoolslibrary.entities.DivId;
5
import eu.dnetlib.uoaadmintoolslibrary.entities.Entity;
6
import eu.dnetlib.uoaadmintoolslibrary.entities.Page;
7
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
8
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.DivHelpContentResponse;
9
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PageHelpContentResponse;
10
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalPage;
11

  
12
import org.apache.log4j.Logger;
13
import org.springframework.beans.factory.annotation.Autowired;
14
import org.springframework.stereotype.Service;
15

  
16
import java.util.*;
17

  
18
@Service
19
public class PageService {
20
    private final Logger log = Logger.getLogger(this.getClass());
21

  
22
    @Autowired
23
    private PageDAO pageDAO;
24

  
25
    @Autowired
26
    private PortalService portalService;
27

  
28
    @Autowired
29
    private PageHelpContentService pageHelpContentService;
30

  
31
    @Autowired
32
    private DivHelpContentService divHelpContentService;
33

  
34
    @Autowired
35
    private DivIdService divIdService;
36

  
37
    @Autowired
38
    private EntityService entityService;
39

  
40

  
41
    public List<PortalPage> getPagesFull(String pid, String page_route) {
42

  
43
        List<Page> pages = this.getAllPages(pid, page_route, null);
44
        if(pages == null) {
45
            return null;
46
        }
47

  
48
        List<PortalPage> portalPages = new ArrayList<>();
49
        for(Page page : pages) {
50
            PortalPage portalPage = new PortalPage(page);
51
            List<Entity> entities = new ArrayList<>();
52
            for(String entityId : page.getEntities()) {
53
                entities.add(entityService.getEntity(entityId));
54
            }
55
            portalPage.setEntities(entities);
56

  
57
            portalPages.add(portalPage);
58
        }
59

  
60
        return portalPages;
61
    }
62

  
63
    public List<Page> getAllPages(String pid, String page_route, String with_positions) {
64
        List<Page> pages = null;
65
        if (pid != null) {
66
            Portal portal = portalService.getPortal(pid);
67
            if(portal == null) {
68
                return null;
69
            }
70

  
71
            String portalType = portal.getType();
72

  
73
            if (page_route != null) {
74
                pages = new ArrayList<Page>();
75
                Page page = pageDAO.findByPortalTypeAndRoute(portalType, page_route);
76
                if(page != null) {
77
                    pages.add(page);
78
                }
79
            } else {
80
                pages = pageDAO.findByPortalType(portalType);
81
            }
82
        } else if (page_route != null) {
83
            pages = pageDAO.findByRoute(page_route);
84
        } else {
85
            pages = pageDAO.findAll();
86
        }
87

  
88
        if (with_positions != null) {
89
            if(pages == null) {
90
                return null;
91
            }
92

  
93
            boolean at_least_one_position = Boolean.parseBoolean(with_positions);
94

  
95
            Iterator<Page> iteratorPages = pages.iterator();
96
            while(iteratorPages.hasNext()) {
97
                Page page = iteratorPages.next();
98

  
99
                if(at_least_one_position) {
100
                    if(!page.getTop() && !page.getBottom() && !page.getLeft() && !page.getRight()) {
101
                        iteratorPages.remove();
102
                    }
103
                } else {
104
                    if(page.getTop() || page.getBottom() || page.getLeft() || page.getRight()) {
105
                        iteratorPages.remove();
106
                    }
107
                }
108
            }
109
        }
110
        if(pages != null) {
111
            pages.sort(Comparator.comparing(Page::getName));
112
        }
113
        return pages;
114
    }
115

  
116
    public List<Page> getPagesByPortalType(String portalType) {
117
        if (portalType == null) {
118
            return null;
119
        }
120
        return pageDAO.findByPortalType(portalType);
121
    }
122

  
123
    public Page getPageByPortalTypeAndRoute(String portalType, String page_route) {
124
        if (page_route == null || portalType == null) {
125
            return null;
126
        }
127
        return pageDAO.findByPortalTypeAndRoute(portalType, page_route);
128
    }
129

  
130
    public void deleteAllPages() {
131
        pageDAO.deleteAll();
132
    }
133

  
134
    public Page insertOrUpdatePage(Page page) {
135
        return pageDAO.save(page);
136
    }
137

  
138
    public PortalPage updatePage(PortalPage portalPage) {
139
        this.deletePageHelpContentsForPositionsIfDisabled(portalPage);
140
        Page page = this.getPageByPortalPage(portalPage);
141
        pageDAO.save(page);
142
        return portalPage;
143
    }
144

  
145
    public PortalPage insertPage(PortalPage portalPage) {
146
        Page page = this.getPageByPortalPage(portalPage);
147
        Page savedPage = pageDAO.save(page);
148
        portalPage.setId(savedPage.getId());
149

  
150
        // add page in portals
151
        List<Portal> portals = portalService.getAllPortalsByType(portalPage.getPortalType());
152
        for( Portal portal : portals ) {
153
            Map<String, Boolean> pages = portal.getPages();
154
            pages.put(page.getId(), true);
155
            portal.setPages(pages);
156
            portalService.insertOrUpdatePortal(portal);
157
        }
158

  
159
        return portalPage;
160
    }
161

  
162
    private Page getPageByPortalPage(PortalPage portalPage) {
163
        Page page = new Page();
164
        page.setId(portalPage.getId());
165
        page.setRoute(portalPage.getRoute());
166
        page.setName(portalPage.getName());
167
        page.setType(portalPage.getType());
168
        page.setPortalType(portalPage.getPortalType());
169
        page.setTop(portalPage.getTop());
170
        page.setBottom(portalPage.getBottom());
171
        page.setLeft(portalPage.getLeft());
172
        page.setRight(portalPage.getRight());
173

  
174
        List<Entity> fullEntities = portalPage.getEntities();
175
        List<String> entities = new ArrayList<String>();
176
        for(Entity entity : fullEntities) {
177
            entities.add(entity.getId());
178
        }
179
        page.setEntities(entities);
180

  
181
        return page;
182
    }
183

  
184
    private void deletePageHelpContentsForPositionsIfDisabled(PortalPage portalPage) {
185

  
186
        if(!portalPage.getTop()) {
187
            // delete page contents with position "top" related to this page from all portals
188
            List<PageHelpContentResponse> pageHelpContentResponses = pageHelpContentService.getPageHelpContents(null, portalPage.getPortalType(), portalPage.getRoute(), "top", null, null);
189
            for(PageHelpContentResponse pageHelpContentResponse : pageHelpContentResponses) {
190
                pageHelpContentService.deletePageHelpContent(pageHelpContentResponse.getId());
191
            }
192
        }
193

  
194
        if(!portalPage.getBottom()) {
195
            // delete page contents with position "bottom" related to this page from all portals
196
            List<PageHelpContentResponse> pageHelpContentResponses = pageHelpContentService.getPageHelpContents(null, portalPage.getPortalType(), portalPage.getRoute(), "bottom", null, null);
197
            for(PageHelpContentResponse pageHelpContentResponse : pageHelpContentResponses) {
198
                pageHelpContentService.deletePageHelpContent(pageHelpContentResponse.getId());
199
            }
200
        }
201

  
202
        if(!portalPage.getLeft()) {
203
            // delete page contents with position "left" related to this page from all portals
204
            List<PageHelpContentResponse> pageHelpContentResponses = pageHelpContentService.getPageHelpContents(null, portalPage.getPortalType(), portalPage.getRoute(), "left", null, null);
205
            for(PageHelpContentResponse pageHelpContentResponse : pageHelpContentResponses) {
206
                pageHelpContentService.deletePageHelpContent(pageHelpContentResponse.getId());
207
            }
208
        }
209

  
210
        if(!portalPage.getRight()) {
211
            // delete page contents with position "right" related to this page from all portals
212
            List<PageHelpContentResponse> pageHelpContentResponses = pageHelpContentService.getPageHelpContents(null, portalPage.getPortalType(), portalPage.getRoute(), "right", null, null);
213
            for(PageHelpContentResponse pageHelpContentResponse : pageHelpContentResponses) {
214
                pageHelpContentService.deletePageHelpContent(pageHelpContentResponse.getId());
215
            }
216
        }
217
    }
218

  
219
    public Boolean deletePages(List<String> pages) throws Exception {
220
        for (String id: pages) {
221
            Page page = pageDAO.findById(id);
222

  
223
            // delete divIds related only to this page from all portals, otherwise remove this page from divIds
224
            List<DivId> divIds = divIdService.getDivIds(id, null, null);
225
            for(DivId divId : divIds) {
226
                if(divId.getPages().size() == 1) {
227
                    // delete div contents related to this page from all portals
228
                    List<DivHelpContentResponse> divHelpContentResponses = divHelpContentService.getDivHelpContents(null, page.getRoute(), divId.getId(), null);
229
                    for (DivHelpContentResponse divHelpContentResponse : divHelpContentResponses) {
230
                        divHelpContentService.deleteDivHelpContent(divHelpContentResponse.getId());
231
                    }
232
                    divIdService.deleteDivId(divId.getId());
233

  
234
                } else {
235
                    List<String> divIdPages = divId.getPages();
236
                    divIdPages.remove(id);
237
                    divId.setPages(divIdPages);
238
                    divIdService.insertOrUpdateDivId(divId);
239
                }
240
            }
241

  
242

  
243
            // delete page contents related to this page from all portals
244
            List<PageHelpContentResponse> pageHelpContentResponses = pageHelpContentService.getPageHelpContents(null, page.getPortalType(), page.getRoute(), null, null, null);
245

  
246
            for(PageHelpContentResponse pageHelpContentResponse : pageHelpContentResponses) {
247
                pageHelpContentService.deletePageHelpContent(pageHelpContentResponse.getId());
248
            }
249

  
250
            // delete page from portals
251
            List<Portal> portals = portalService.getAllPortalsByType(page.getPortalType());
252
            for( Portal portal : portals ) {
253
                Map<String, Boolean> portalPages = portal.getPages();
254
                portalPages.remove(id);
255
                portal.setPages(portalPages);
256
                portalService.insertOrUpdatePortal(portal);
257
            }
258

  
259
            pageDAO.delete(id);
260
        }
261

  
262
        return true;
263
    }
264

  
265
    public Page getPage(String id) {
266
        return pageDAO.findById(id);
267
    }
268

  
269
    public void deletePage(String id) {
270
        pageDAO.delete(id);
271
    }
272

  
273
    public List<String> getPageEntities(String id) {
274
        return pageDAO.findById(id).getEntities();
275
    }
276

  
277
    public Page togglePageEntity(String id, String entityId, String status) throws Exception {
278
        log.debug("Toggle entity : "+entityId +" of page: "+id+" to "+status);
279
        Page page = pageDAO.findById(id);
280
        List<String> entities = page.getEntities();
281
        if(Boolean.parseBoolean(status) && !entities.contains(entityId)) {
282
            entities.add(entityId);
283
        } else if (!Boolean.parseBoolean(status)) {
284
            entities.remove(entityId);
285
        }
286
        page.setEntities(entities);
287
        return pageDAO.save(page);
288
    }
289
}
modules/uoa-admin-tools-library/tags/uoa-admin-tools-library-1.0.3/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/MongoDBDAOs/MongoDBDivHelpContentDAO.java
1
package eu.dnetlib.uoaadmintoolslibrary.dao.MongoDBDAOs;
2

  
3
import org.springframework.data.mongodb.repository.MongoRepository;
4

  
5
import java.util.List;
6

  
7
import eu.dnetlib.uoaadmintoolslibrary.dao.DivHelpContentDAO;
8
import eu.dnetlib.uoaadmintoolslibrary.entities.DivHelpContent;
9

  
10
public interface MongoDBDivHelpContentDAO extends DivHelpContentDAO, MongoRepository<DivHelpContent, String> {
11
    List<DivHelpContent> findAll();
12

  
13
    List<DivHelpContent> findByPortal(String portalId);
14
    List<DivHelpContent> findByDivId(String divId);
15
    List<DivHelpContent> findByIsActive(boolean isActive);
16
    List<DivHelpContent> findByPortalAndDivId(String portalId, String divId);
17
    List<DivHelpContent> findByPortalAndIsActive(String portalId, boolean isActive);
18
    List<DivHelpContent> findByDivIdAndIsActive(String divId, boolean isActive);
19
    List<DivHelpContent> findByPortalAndDivIdAndIsActive(String portalId, String divId, boolean isActive);
20
//    List<DivHelpContent> findByPortalAndPage(String portalId, String page);
21

  
22
    DivHelpContent findById(String Id);
23

  
24
    DivHelpContent save(DivHelpContent divHelpContent);
25

  
26
    void deleteAll();
27

  
28
    void delete(String id);
29
}
modules/uoa-admin-tools-library/tags/uoa-admin-tools-library-1.0.3/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/MongoDBDAOs/MongoDBPageDAO.java
1
package eu.dnetlib.uoaadmintoolslibrary.dao.MongoDBDAOs;
2

  
3
import org.springframework.data.mongodb.repository.MongoRepository;
4

  
5
import java.util.List;
6

  
7
import eu.dnetlib.uoaadmintoolslibrary.dao.PageDAO;
8
import eu.dnetlib.uoaadmintoolslibrary.entities.Page;
9

  
10
public interface MongoDBPageDAO extends PageDAO, MongoRepository<Page, String> {
11
    List<Page> findAll();
12
    List<Page> findByPortalType(String portalType);
13
    List<Page> findByRoute(String route);
14

  
15
    Page findByPortalTypeAndRoute(String portalType, String route);
16
    Page findById(String Id);
17

  
18
    Page save(Page page);
19

  
20
    void deleteAll();
21

  
22
    void delete(String id);
23
}
modules/uoa-admin-tools-library/tags/uoa-admin-tools-library-1.0.3/src/main/java/eu/dnetlib/uoaadmintoolslibrary/services/PortalService.java
1
package eu.dnetlib.uoaadmintoolslibrary.services;
2

  
3
import eu.dnetlib.uoaadmintoolslibrary.dao.PortalDAO;
4
import eu.dnetlib.uoaadmintoolslibrary.entities.DivId;
5
import eu.dnetlib.uoaadmintoolslibrary.entities.Entity;
6
import eu.dnetlib.uoaadmintoolslibrary.entities.Page;
7
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
8
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.*;
9

  
10
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
11
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
12
import org.apache.log4j.Logger;
13
import org.springframework.beans.factory.annotation.Autowired;
14
import org.springframework.stereotype.Service;
15

  
16
import java.util.*;
17

  
18
@Service
19
public class PortalService {
20
    private final Logger log = Logger.getLogger(this.getClass());
21

  
22
    @Autowired
23
    private PortalDAO portalDAO;
24

  
25
    @Autowired
26
    private PageService pageService;
27

  
28
    @Autowired
29
    private EntityService entityService;
30

  
31
    @Autowired
32
    private DivIdService divIdService;
33

  
34
    @Autowired
35
    private PageHelpContentService pageHelpContentService;
36

  
37
    @Autowired
38
    private DivHelpContentService divHelpContentService;
39

  
40
    public List<Portal> getAllPortals() {
41
        List<Portal> portals = portalDAO.findAll();
42

  
43
        return portals;
44
    }
45

  
46
    public List<Portal> getAllPortalsByType(String type) {
47
        List<Portal> portals = portalDAO.findByType(type);
48

  
49
        return portals;
50
    }
51

  
52
    public List<PortalResponse> getPortalsFull(List<Portal> portals) {
53
        List<PortalResponse> portalsResponse = new ArrayList<>();
54
        for(Portal portal : portals) {
55
            PortalResponse portalResponse = new PortalResponse(portal);
56

  
57
            setEnabledPagesForPortalByType(portal, portalResponse);
58
            setEnabledEntitiesForPortalByType(portal, portalResponse);
59

  
60
            //Layout layout = layoutDAO.findById(portal.getLayout());
61
            //portalResponse.setLayout(layout);
62

  
63
            portalsResponse.add(portalResponse);
64
        }
65
        return portalsResponse;
66
    }
67

  
68
    public List<PortalResponse> getAllPortalsFull() {
69
        List<Portal> portals = this.getAllPortals();
70
        return this.getPortalsFull(portals);
71
    }
72

  
73
    public List<PortalResponse> getAllPortalsFullByType(String type) {
74
        List<Portal> portals = this.getAllPortalsByType(type);
75
        return this.getPortalsFull(portals);
76
    }
77

  
78
    private void setEnabledPagesForPortalByType(Portal portal, PortalResponse portalResponse) {
79
        List<PortalPage> pages = this.getPagesForPortalByType(portal.getPid(), null, null, null, null);
80
//        log.debug("PAGES number="+pages.size());
81
        Iterator<PortalPage> iteratorPages = pages.iterator();
82
        while(iteratorPages.hasNext()) {
83
            PortalPage page = iteratorPages.next();
84
            if(!page.getIsEnabled()) {
85
                iteratorPages.remove();
86
            }
87
        }
88
        portalResponse.setPages(pages);
89
//        log.debug("PAGES set");
90
    }
91

  
92
    private void setEnabledEntitiesForPortalByType(Portal portal, PortalResponse portalResponse) {
93
        List<PortalEntity> entities = this.getEntitiesForPortal(portal.getPid(), null);
94
//        log.debug("ENTITIES number="+entities.size());
95
        Iterator<PortalEntity> iteratorEntities = entities.iterator();
96
        while(iteratorEntities.hasNext()) {
97
            PortalEntity entity = iteratorEntities.next();
98
            if(!entity.getIsEnabled()) {
99
                iteratorEntities.remove();
100
            }
101
        }
102
        portalResponse.setEntities(entities);
103
//        log.debug("ENTITIES set");
104
    }
105

  
106
    public PortalResponse getPortalFull(String pid) {
107
        Portal portal = portalDAO.findByPid(pid);
108
        if(pid != null && portal == null) {
109
            return null;
110
        }
111
        PortalResponse portalResponse = new PortalResponse(portal);
112

  
113
        setEnabledPagesForPortalByType(portal, portalResponse);
114
        setEnabledEntitiesForPortalByType(portal, portalResponse);
115

  
116
        //Layout layout = layoutDAO.findById(portal.getLayout());
117
        //portalResponse.setLayout(layout);
118

  
119
        return portalResponse;
120
    }
121

  
122
    public PortalResponse updatePortal(Portal portal) {
123
        Portal com = portalDAO.findById(portal.getId());
124

  
125
//        Statistics statistics = statisticsDAO.findByPid(com.getPid());
126
//        statistics.setPid(portal.getPid());
127
//        statisticsDAO.save(statistics);
128
//
129
//        PortalSubscribers portalSubscribers =  communitySubscribersDAO.findByPid(com.getPid());
130
//        portalSubscribers.setPid(portal.getPid());
131
//        communitySubscribersDAO.save(portalSubscribers);
132

  
133
        com.setName(portal.getName());
134
        com.setPid(portal.getPid());
135
        com.setPiwik(portal.getPiwik());
136
        com.setTwitterAccount(portal.getTwitterAccount());
137

  
138
        portalDAO.save(com);
139
        PortalResponse portalResponse = this.getPortalFull(portal.getPid());
140

  
141
        return portalResponse;
142
    }
143

  
144
    public PortalResponse insertPortal(Portal portal) {
145
        List<PortalEntity> portalEntities = new ArrayList<>();
146
        List<PortalPage> portalPages = new ArrayList<>();
147
        Map<String, Boolean> entities = new HashMap<>();
148
        Map<String, Boolean> pages = new HashMap<>();
149

  
150
        for(Entity entity : entityService.getAllEntities()) {
151
            entities.put(entity.getId(), true);
152

  
153
            PortalEntity portalEntity = new PortalEntity(entity);
154
            portalEntity.setIsEnabled(true);
155
            portalEntities.add(portalEntity);
156
        }
157

  
158
        for(Page page : pageService.getPagesByPortalType(portal.getType())) {
159
            pages.put(page.getId(), true);
160

  
161
            PortalPage portalPage = new PortalPage(page);
162
            if(page.getRoute().equals("/curators") || page.getRoute().equals("/organizations")) {
163
                portalPage.setIsEnabled(false);
164
            } else {
165
                portalPage.setIsEnabled(true);
166
            }
167

  
168
            portalPages.add(portalPage);
169
        }
170

  
171
        portal.setEntities(entities);
172
        portal.setPages(pages);
173
//        Statistics statistics =  new Statistics(portal.getPid());
174
//        statisticsDAO.save(statistics);
175
//        PortalSubscribers portalSubscribers =  new PortalSubscribers(portal.getPid());
176
//        communitySubscribersDAO.save(portalSubscribers);
177
        Portal savedPortal = portalDAO.save(portal);
178
        PortalResponse portalResponse = this.getPortalFull(savedPortal.getPid());
179

  
180
//        log.debug("pid of saved portal: "+ savedPortal.getPid());
181

  
182
        String id = savedPortal.getId();
183

  
184
        divHelpContentService.addDivHelpContentsInPortal(id, savedPortal.getType());
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff