Project

General

Profile

« Previous | Next » 

Revision 58021

[Trunk | Admin tools library Service]: Initial commit of project - Common files & methods copied from admin tools service.
1. Entities: common entities are Community, Entity, Page, DivId, PageHelpContent, DivHelpContent (+ fullEntities), email: Email, EmailRecaptcha, GoogleResponse.
2. DAOs: DAOs for common entities are CommunityDAO, EntityDAO, PageDAO, DivIdDAO, PageHelpContentDAO, DivHelpContentDAO (+MongoDBDAOs).
3. Controllers: controllers for common entities are CommunityController, EntityController, PageController, DivIdController, PageHelpContentController, DivHelpContentController
(comment references to community specific entities e.g. Statistics, Subscribers, Layout).
4. Configuration: common configuration files are GoogleConfig, MailConfig.
5. For email: emailSender/EmailSender.java & handlers/InvalidReCaptchaException.java & recaptcha/VerifyRecaptcha.java.
6. Resources: log4j.properties.

View differences:

modules/uoa-admin-tools-library/trunk/src/main/java/eu/dnetlib/uoaadmintoolslibrary/configuration/properties/GoogleConfig.java
1
package eu.dnetlib.uoaadmintoolslibrary.configuration.properties;
2

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

  
5
@ConfigurationProperties("admintoolslibrary.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-admin-tools-library/trunk/src/main/java/eu/dnetlib/uoaadmintoolslibrary/emailSender/EmailSender.java
1
package eu.dnetlib.uoaadmintoolslibrary.emailSender;
2

  
3
import org.apache.log4j.Logger;
4
import org.springframework.beans.factory.annotation.Autowired;
5
import org.springframework.beans.factory.annotation.Configurable;
6
import org.springframework.stereotype.Service;
7

  
8
import javax.mail.*;
9
import javax.mail.internet.AddressException;
10
import javax.mail.internet.InternetAddress;
11
import javax.mail.internet.MimeMessage;
12
import java.util.List;
13
import java.util.Properties;
14

  
15
import eu.dnetlib.uoaadmintoolslibrary.configuration.properties.MailConfig;
16

  
17
@Service
18
@Configurable
19
public class EmailSender {
20

  
21
    private static final Logger logger = Logger.getLogger(EmailSender.class);
22

  
23
    @Autowired
24
    private MailConfig mailConfig;
25

  
26
    public boolean send(List<String> recipients, String subject, String body, Boolean bcc) {
27
        // Get system properties
28
        Properties properties = System.getProperties();
29
        properties.setProperty("mail.smtp.host", mailConfig.getHost());
30
        properties.put("mail.smtp.port", mailConfig.getPort());
31
        properties.put("mail.smtp.auth", mailConfig.getAuth()); //enable authentication
32
        properties.put("mail.smtp.starttls.enable", "true");
33
        logger.debug("Try to connect to mail sender with "+ mailConfig.getUsername());
34
        Session session = Session.getInstance(properties,
35
                new javax.mail.Authenticator() {
36
                    protected PasswordAuthentication getPasswordAuthentication() {
37
                        return new PasswordAuthentication(mailConfig.getUsername(), mailConfig.getPassword());
38
                    }
39
                });
40

  
41
        try {
42
            logger.debug("Try to sent e-mail to "+recipients.toString()+
43
                    "\nSubject: "+subject+
44
                    "\nBody:"+body);
45

  
46
            // Create a default MimeMessage object.
47
            MimeMessage message = new MimeMessage(session);
48

  
49
            // Set From: header field of the header.
50
            message.setFrom(new InternetAddress(mailConfig.getFrom()));
51

  
52
            // Set To: header field of the header.
53
            if(!bcc) {
54
                for (String to : recipients) {
55
                    message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
56
                }
57
            }else{
58
                for (String to : recipients) {
59
                    message.addRecipient(Message.RecipientType.BCC, new InternetAddress(to));
60
                }
61
            }
62

  
63
            message.addRecipient(Message.RecipientType.BCC, new InternetAddress("openaire.test@gmail.com"));
64

  
65
            // Set Subject: header field
66
            message.setSubject(subject);
67

  
68
            // For simple text setText() can be used instead of setContent()
69

  
70
            // Send the actual HTML message, as big as you like
71
            message.setContent(body, "text/html");
72

  
73
            // Send message
74
            Transport.send(message);
75
            logger.debug("Sent message successfully....\n");
76
            return true;
77
        } catch (AddressException ae) {
78
            logger.error("Email could not be send.", ae);
79
            return false;
80
        } catch (MessagingException me) {
81
            logger.error("Email could not be send.", me);
82
            return false;
83
        }
84
    }
85

  
86
}
modules/uoa-admin-tools-library/trunk/src/main/java/eu/dnetlib/uoaadmintoolslibrary/entities/fullEntities/DivIdResponse.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 java.util.List;
7

  
8
import eu.dnetlib.uoaadmintoolslibrary.entities.Page;
9
import eu.dnetlib.uoaadmintoolslibrary.entities.DivId;
10

  
11
public class DivIdResponse {
12
    @Id
13
    @JsonProperty("_id")
14
    private String id;
15

  
16
    private String name;
17
    private List<Page> pages;
18
    private Boolean connect;
19
    private Boolean communities;
20
    private Boolean openaire;
21

  
22
    public DivIdResponse() {}
23

  
24
    public DivIdResponse(DivId divId) {
25
        this.id = divId.getId();
26
        this.name = divId.getName();
27
        setConnect(divId.getConnect());
28
        setCommunities(divId.getCommunities());
29
        setOpenaire(divId.getOpenaire());
30
    }
31

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

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

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

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

  
48
    public List<Page> getPages() {
49
        return pages;
50
    }
51

  
52
    public void setPages(List<Page> pages) {
53
        this.pages = pages;
54
    }
55

  
56
    public Boolean getConnect() {
57
        return connect;
58
    }
59

  
60
    public void setConnect(Boolean connect) { this.connect = connect; }
61

  
62
    public Boolean getCommunities() { return communities; }
63

  
64
    public void setCommunities(Boolean communities) {
65
        this.communities = communities;
66
    }
67

  
68
    public Boolean getOpenaire() {
69
        return openaire;
70
    }
71

  
72
    public void setOpenaire(Boolean openaire) {
73
        this.openaire = openaire;
74
    }
75
}
modules/uoa-admin-tools-library/trunk/src/main/java/eu/dnetlib/uoaadmintoolslibrary/handlers/InvalidReCaptchaException.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.NOT_ACCEPTABLE)
7
public class InvalidReCaptchaException extends RuntimeException{
8
    public InvalidReCaptchaException(String message){
9
        super(message);
10
    }
11
}
modules/uoa-admin-tools-library/trunk/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/trunk/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/PageDAO.java
1
package eu.dnetlib.uoaadmintoolslibrary.dao;
2

  
3
import java.util.List;
4

  
5
import eu.dnetlib.uoaadmintoolslibrary.entities.Page;
6

  
7
public interface PageDAO {
8
    List<Page> findAll();
9
    List<Page> findByConnect(boolean connect);
10
    List<Page> findByCommunities(boolean communities);
11
    List<Page> findByOpenaire(boolean openaire);
12

  
13
    Page findByConnectAndRoute(boolean connect, String route);
14
    Page findByCommunitiesAndRoute(boolean communities, String route);
15
    Page findByOpenaireAndRoute(boolean openaire, String route);
16

  
17
    Page findById(String Id);
18
    Page findByRoute(String route);
19

  
20
    Page save(Page page);
21

  
22
    void deleteAll();
23

  
24
    void delete(String id);
25
}
modules/uoa-admin-tools-library/trunk/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/EntityDAO.java
1
package eu.dnetlib.uoaadmintoolslibrary.dao;
2

  
3
import java.util.List;
4

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

  
7
public interface EntityDAO {
8
    List<Entity> findAll();
9

  
10
    Entity findById(String Id);
11

  
12
    Entity findByPid(String Pid);
13

  
14
    Entity findByName(String name);
15

  
16
    Entity save(Entity entity);
17

  
18
    void deleteAll();
19

  
20
    void delete(String id);
21
}
modules/uoa-admin-tools-library/trunk/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/DivIdDAO.java
1
package eu.dnetlib.uoaadmintoolslibrary.dao;
2

  
3
import java.util.List;
4

  
5
import eu.dnetlib.uoaadmintoolslibrary.entities.DivId;
6

  
7
public interface DivIdDAO {
8
    List<DivId> findAll();
9

  
10
    List<DivId> findByPagesContaining(String page);
11

  
12
    DivId findByPagesContainingAndName(String page, String name);
13
    DivId findByName(String name);
14

  
15
    DivId findById(String Id);
16

  
17
    List<DivId> findByConnect(boolean connect);
18
    List<DivId> findByCommunities(boolean communities);
19
    List<DivId> findByOpenaire(boolean openaire);
20

  
21
    DivId save(DivId divId);
22

  
23
    void deleteAll();
24

  
25
    void delete(String id);
26
}
27

  
modules/uoa-admin-tools-library/trunk/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/PageHelpContentDAO.java
1
package eu.dnetlib.uoaadmintoolslibrary.dao;
2

  
3
import java.util.List;
4

  
5
import eu.dnetlib.uoaadmintoolslibrary.entities.PageHelpContent;
6

  
7
public interface PageHelpContentDAO {
8
    List<PageHelpContent> findAll();
9

  
10
    List<PageHelpContent> findByCommunityAndPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(String communityId, String position, boolean isActive, boolean isPriorTo);
11
    List<PageHelpContent> findByCommunityAndPlacementAndIsActiveOrderByOrderAsc(String communityId, String position, boolean isActive);
12
    List<PageHelpContent> findByCommunityAndPlacementAndIsPriorToOrderByOrderAsc(String communityId, String position, boolean isPriorTo);
13
    List<PageHelpContent> findByCommunityAndIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(String communityId, boolean isActive, boolean isPriorTo);
14
    List<PageHelpContent> findByPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(String position, boolean isActive, boolean isPriorTo);
15
    List<PageHelpContent> findByCommunityAndPlacementOrderByOrderAsc(String communityId, String postion);
16
    List<PageHelpContent> findByCommunityAndIsActiveOrderByPlacementAscOrderAsc(String communityId, boolean isActive);
17
    List<PageHelpContent> findByCommunityAndIsPriorToOrderByPlacementAscOrderAsc(String communityId, boolean isPriorTo);
18
    List<PageHelpContent> findByPlacementAndIsActiveOrderByOrderAsc(String position, boolean isActive);
19
    List<PageHelpContent> findByPlacementAndIsPriorToOrderByOrderAsc(String position, boolean isPriorTo);
20
    List<PageHelpContent> findByIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(boolean isActive, boolean isPriorTo);
21
    List<PageHelpContent> findByCommunityOrderByPlacementAscOrderAsc(String communityId);
22
    List<PageHelpContent> findByPlacementOrderByOrderAsc(String postion);
23
    List<PageHelpContent> findByIsActiveOrderByPlacementAscOrderAsc(boolean isActive);
24
    List<PageHelpContent> findByIsPriorToOrderByPlacementAscOrderAsc(boolean isPriorTo);
25
    List<PageHelpContent> findAllByOrderByPlacementAscOrderAsc();
26

  
27
    //List<PageHelpContent> findByCommunityAndPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(String communityId, String postion, boolean isActive, boolean isBefore);
28

  
29

  
30
    PageHelpContent findById(String Id);
31

  
32
    PageHelpContent findByIdOrderByOrder(String Id);
33

  
34
    PageHelpContent save(PageHelpContent pageHelpContent);
35

  
36
    void deleteAll();
37

  
38
    void delete(String id);
39
}
modules/uoa-admin-tools-library/trunk/src/main/java/eu/dnetlib/uoaadmintoolslibrary/controllers/PageController.java
1
package eu.dnetlib.uoaadmintoolslibrary.controllers;
2

  
3
import org.apache.log4j.Logger;
4
import org.springframework.beans.factory.annotation.Autowired;
5
import org.springframework.web.bind.annotation.*;
6

  
7
import java.util.*;
8

  
9
import eu.dnetlib.uoaadmintoolslibrary.dao.CommunityDAO;
10
import eu.dnetlib.uoaadmintoolslibrary.dao.DivIdDAO;
11
import eu.dnetlib.uoaadmintoolslibrary.dao.PageDAO;
12
import eu.dnetlib.uoaadmintoolslibrary.entities.Community;
13
import eu.dnetlib.uoaadmintoolslibrary.entities.DivId;
14
import eu.dnetlib.uoaadmintoolslibrary.entities.Entity;
15
import eu.dnetlib.uoaadmintoolslibrary.entities.Page;
16
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.CommunityPage;
17
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.DivHelpContentResponse;
18
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PageHelpContentResponse;
19

  
20
@RestController
21
@CrossOrigin(origins = "*")
22
public class PageController {
23
    private final Logger log = Logger.getLogger(this.getClass());
24

  
25
    @Autowired
26
    private PageDAO pageDAO;
27

  
28
    @Autowired
29
    private CommunityDAO communityDAO;
30

  
31
    @Autowired
32
    private DivIdDAO divIdDAO;
33

  
34
    @Autowired
35
    private PageHelpContentController pageHelpContentController;
36

  
37
    @Autowired
38
    private DivHelpContentController divHelpContentController;
39

  
40
    @Autowired
41
    private DivIdController divIdController;
42

  
43
    @Autowired
44
    private EntityController entityController;
45

  
46
    @RequestMapping(value = "/pageFull", method = RequestMethod.GET)
47
    public List<CommunityPage> getPagesFull(@RequestParam(value="pid", required=false) String pid,
48
                                            @RequestParam(value="page_route", required=false) String page_route) {
49

  
50
        List<Page> pages = this.getAllPages(pid, page_route, null);
51

  
52
        List<CommunityPage> communityPages = new ArrayList<>();
53
        for(Page page : pages) {
54
            CommunityPage communityPage = new CommunityPage(page);
55
            List<Entity> entities = new ArrayList<>();
56
            for(String entityId : page.getEntities()) {
57
                entities.add(entityController.getEntity(entityId));
58
            }
59
            communityPage.setEntities(entities);
60

  
61
            communityPages.add(communityPage);
62
        }
63

  
64
        return communityPages;
65
    }
66

  
67
    @RequestMapping(value = "/page", method = RequestMethod.GET)
68
    public List<Page> getAllPages(@RequestParam(value="pid", required=false) String pid,
69
                                  @RequestParam(value="page_route", required=false) String page_route,
70
                                  @RequestParam(value="with_positions", required=false) String with_positions) {
71
        List<Page> pages;
72
        if (pid != null) {
73
            if (pid.equals("openaire")) {
74
                if (page_route != null) {
75
                    pages = new ArrayList<Page>();
76
                    pages.add(pageDAO.findByOpenaireAndRoute(true, page_route));
77
                } else {
78
                    pages = pageDAO.findByOpenaire(true);
79
                }
80
            } else if (pid.equals("connect")) {
81
                if (page_route != null) {
82
                    pages = new ArrayList<Page>();
83
                    pages.add(pageDAO.findByConnectAndRoute(true, page_route));
84
                } else {
85
                    pages = pageDAO.findByConnect(true);
86
                }
87
            } else {
88
                if (page_route != null) {
89
                    pages = new ArrayList<Page>();
90
                    pages.add(pageDAO.findByCommunitiesAndRoute(true, page_route));
91
                } else {
92
                    pages = pageDAO.findByCommunities(true);
93
                }
94
            }
95
        } else if (page_route != null) {
96
            pages = new ArrayList<Page>();
97
            pages.add(pageDAO.findByRoute(page_route));
98
        } else {
99
            pages = pageDAO.findAll();
100
        }
101

  
102
        if (with_positions != null) {
103
            boolean at_least_one_position = Boolean.parseBoolean(with_positions);
104

  
105
            Iterator<Page> iteratorPages = pages.iterator();
106
            while(iteratorPages.hasNext()) {
107
                Page page = iteratorPages.next();
108

  
109
                if(at_least_one_position) {
110
                    if(!page.getTop() && !page.getBottom() && !page.getLeft() && !page.getRight()) {
111
                        iteratorPages.remove();
112
                    }
113
                } else {
114
                    if(page.getTop() || page.getBottom() || page.getLeft() || page.getRight()) {
115
                        iteratorPages.remove();
116
                    }
117
                }
118
            }
119
        }
120
        pages.sort(Comparator.comparing(Page::getName));
121
        return pages;
122
    }
123

  
124
    @RequestMapping(value = "/page", method = RequestMethod.DELETE)
125
    public void deleteAllPages() {
126
        pageDAO.deleteAll();
127
    }
128

  
129
    @RequestMapping(value = "/page/update", method = RequestMethod.POST)
130
    public CommunityPage updatePage(@RequestBody CommunityPage communityPage) {
131
        this.deletePageHelpContentsForPositionsIfDisabled(communityPage);
132
        Page page = this.getPageByCommunityPage(communityPage);
133
        pageDAO.save(page);
134
        return communityPage;
135
    }
136

  
137
    @RequestMapping(value = "/page/save", method = RequestMethod.POST)
138
    public CommunityPage insertPage(@RequestBody CommunityPage communityPage) {
139
        Page page = this.getPageByCommunityPage(communityPage);
140
        Page savedPage = pageDAO.save(page);
141
        communityPage.setId(savedPage.getId());
142

  
143
        // add page in communities
144
        List<Community> communities = communityDAO.findAll();
145
        for( Community community : communities ) {
146
            Map<String, Boolean> pages = community.getPages();
147
            pages.put(page.getId(), true);
148
            community.setPages(pages);
149
            communityDAO.save(community);
150
        }
151

  
152
        return communityPage;
153
    }
154

  
155
    private Page getPageByCommunityPage(CommunityPage communityPage) {
156
        Page page = new Page();
157
        page.setId(communityPage.getId());
158
        page.setRoute(communityPage.getRoute());
159
        page.setName(communityPage.getName());
160
        page.setType(communityPage.getType());
161
        page.setConnect(communityPage.getConnect());
162
        page.setCommunities(communityPage.getCommunities());
163
        page.setOpenaire(communityPage.getOpenaire());
164
        page.setTop(communityPage.getTop());
165
        page.setBottom(communityPage.getBottom());
166
        page.setLeft(communityPage.getLeft());
167
        page.setRight(communityPage.getRight());
168

  
169
        List<Entity> fullEntities = communityPage.getEntities();
170
        List<String> entities = new ArrayList<String>();
171
        for(Entity entity : fullEntities) {
172
            entities.add(entity.getId());
173
        }
174
        page.setEntities(entities);
175

  
176
        return page;
177
    }
178

  
179
    private void deletePageHelpContentsForPositionsIfDisabled(CommunityPage communityPage) {
180

  
181
        if(!communityPage.getTop()) {
182
            // delete page contents with position "top" related to this page from all communities
183
            List<PageHelpContentResponse> pageHelpContentResponses = pageHelpContentController.getPageHelpContents(null, communityPage.getRoute(), "top", null, null);
184
            for(PageHelpContentResponse pageHelpContentResponse : pageHelpContentResponses) {
185
                pageHelpContentController.deletePageHelpContent(pageHelpContentResponse.getId());
186
            }
187
        }
188

  
189
        if(!communityPage.getBottom()) {
190
            // delete page contents with position "bottom" related to this page from all communities
191
            List<PageHelpContentResponse> pageHelpContentResponses = pageHelpContentController.getPageHelpContents(null, communityPage.getRoute(), "bottom", null, null);
192
            for(PageHelpContentResponse pageHelpContentResponse : pageHelpContentResponses) {
193
                pageHelpContentController.deletePageHelpContent(pageHelpContentResponse.getId());
194
            }
195
        }
196

  
197
        if(!communityPage.getLeft()) {
198
            // delete page contents with position "left" related to this page from all communities
199
            List<PageHelpContentResponse> pageHelpContentResponses = pageHelpContentController.getPageHelpContents(null, communityPage.getRoute(), "left", null, null);
200
            for(PageHelpContentResponse pageHelpContentResponse : pageHelpContentResponses) {
201
                pageHelpContentController.deletePageHelpContent(pageHelpContentResponse.getId());
202
            }
203
        }
204

  
205
        if(!communityPage.getRight()) {
206
            // delete page contents with position "right" related to this page from all communities
207
            List<PageHelpContentResponse> pageHelpContentResponses = pageHelpContentController.getPageHelpContents(null, communityPage.getRoute(), "right", null, null);
208
            for(PageHelpContentResponse pageHelpContentResponse : pageHelpContentResponses) {
209
                pageHelpContentController.deletePageHelpContent(pageHelpContentResponse.getId());
210
            }
211
        }
212
    }
213

  
214
    @RequestMapping(value = "/page/delete", method = RequestMethod.POST)
215
    public Boolean deletePages(@RequestBody List<String> pages) throws Exception {
216
        for (String id: pages) {
217
            pageDAO.delete(id);
218

  
219
            // delete divIds related only to this page from all communities, otherwise remove this page from divIds
220
            List<DivId> divIds = divIdController.getDivIds(id, null, null);
221
            for(DivId divId : divIds) {
222
                if(divId.getPages().size() == 1) {
223
                    divIdController.deleteDivId(divId.getId());
224

  
225
                    // delete div contents related to this page from all communities
226
                    List<DivHelpContentResponse> divHelpContentResponses = divHelpContentController.getDivHelpContents(null, id, divId.getId(), null);
227
                    for (DivHelpContentResponse divHelpContentResponse : divHelpContentResponses) {
228
                        divHelpContentController.deleteDivHelpContent(divHelpContentResponse.getId());
229
                    }
230
                } else {
231
                    List<String> divIdPages = divId.getPages();
232
                    divIdPages.remove(id);
233
                    divId.setPages(divIdPages);
234
                    divIdDAO.save(divId);
235
                }
236
            }
237

  
238

  
239
            // delete page contents related to this page from all communities
240
            List<PageHelpContentResponse> pageHelpContentResponses = pageHelpContentController.getPageHelpContents(null, id, null, null, null);
241
            for(PageHelpContentResponse pageHelpContentResponse : pageHelpContentResponses) {
242
                pageHelpContentController.deletePageHelpContent(pageHelpContentResponse.getId());
243
            }
244

  
245
            // delete page from communities
246
            List<Community> communities = communityDAO.findAll();
247
            for( Community community : communities ) {
248
                Map<String, Boolean> communityPages = community.getPages();
249
                communityPages.remove(id);
250
                community.setPages(communityPages);
251
                communityDAO.save(community);
252
            }
253
        }
254

  
255
        return true;
256
    }
257

  
258
    @RequestMapping(value = "/page/{id}", method = RequestMethod.GET)
259
    public Page getPage(@PathVariable(value = "id") String id) {
260
        return pageDAO.findById(id);
261
    }
262

  
263
    @RequestMapping(value = "/page/{id}", method = RequestMethod.DELETE)
264
    public void deletePage(@PathVariable(value = "id") String id) {
265
        pageDAO.delete(id);
266
    }
267

  
268
    @RequestMapping(value = "/page/{id}/entity", method = RequestMethod.GET)
269
    public List<String> getPageEntities(@PathVariable(value = "id") String id) {
270
        return pageDAO.findById(id).getEntities();
271
    }
272

  
273
    @RequestMapping(value = "page/{id}/entity/toggle", method = RequestMethod.POST)
274
    public Page togglePageEntity(@PathVariable(value = "id") String id, @RequestParam String entityId, @RequestParam String status) throws Exception {
275
        log.debug("Toggle entity : "+entityId +" of page: "+id+" to "+status);
276
        Page page = pageDAO.findById(id);
277
        List<String> entities = page.getEntities();
278
        if(Boolean.parseBoolean(status) && !entities.contains(entityId)) {
279
            entities.add(entityId);
280
        } else if (!Boolean.parseBoolean(status)) {
281
            entities.remove(entityId);
282
        }
283
        page.setEntities(entities);
284
        return pageDAO.save(page);
285
    }
286
}
modules/uoa-admin-tools-library/trunk/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/CommunityDAO.java
1
package eu.dnetlib.uoaadmintoolslibrary.dao;
2

  
3
import java.util.List;
4

  
5
import eu.dnetlib.uoaadmintoolslibrary.entities.Community;
6

  
7
public interface CommunityDAO {
8
    List<Community> findAll();
9

  
10
    Community findById(String Id);
11

  
12
    Community findByPid(String Pid);
13

  
14
    Community findByName(String Name);
15

  
16
    Community save(Community community);
17

  
18
    void deleteAll();
19

  
20
    void delete(String id);
21
}
modules/uoa-admin-tools-library/trunk/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/DivHelpContentDAO.java
1
package eu.dnetlib.uoaadmintoolslibrary.dao;
2

  
3
import java.util.List;
4

  
5
import eu.dnetlib.uoaadmintoolslibrary.entities.DivHelpContent;
6

  
7
public interface DivHelpContentDAO {
8
    List<DivHelpContent> findAll();
9

  
10
    List<DivHelpContent> findByCommunity(String community);
11
    List<DivHelpContent> findByDivId(String divId);
12
    List<DivHelpContent> findByIsActive(boolean isActive);
13
    List<DivHelpContent> findByCommunityAndDivId(String community, String divId);
14
    List<DivHelpContent> findByCommunityAndIsActive(String community, boolean isActive);
15
    List<DivHelpContent> findByDivIdAndIsActive(String divId, boolean isActive);
16
    List<DivHelpContent> findByCommunityAndDivIdAndIsActive(String community, String divId, boolean isActive);
17

  
18
    DivHelpContent findById(String Id);
19

  
20
    DivHelpContent save(DivHelpContent divHelpContent);
21

  
22
    void deleteAll();
23

  
24
    void delete(String id);
25
}
modules/uoa-admin-tools-library/trunk/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> findByCommunity(String community);
14
    List<DivHelpContent> findByDivId(String divId);
15
    List<DivHelpContent> findByIsActive(boolean isActive);
16
    List<DivHelpContent> findByCommunityAndDivId(String community, String divId);
17
    List<DivHelpContent> findByCommunityAndIsActive(String community, boolean isActive);
18
    List<DivHelpContent> findByDivIdAndIsActive(String divId, boolean isActive);
19
    List<DivHelpContent> findByCommunityAndDivIdAndIsActive(String community, String divId, boolean isActive);
20

  
21
    DivHelpContent findById(String Id);
22

  
23
    DivHelpContent save(DivHelpContent divHelpContent);
24

  
25
    void deleteAll();
26

  
27
    void delete(String id);
28
}
modules/uoa-admin-tools-library/trunk/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> findByConnect(boolean connect);
13
    List<Page> findByCommunities(boolean communities);
14
    List<Page> findByOpenaire(boolean openaire);
15

  
16
    Page findByConnectAndRoute(boolean connect, String route);
17
    Page findByCommunitiesAndRoute(boolean communities, String route);
18
    Page findByOpenaireAndRoute(boolean openaire, String route);
19

  
20
    Page findById(String Id);
21
    Page findByRoute(String route);
22

  
23
    Page save(Page page);
24

  
25
    void deleteAll();
26

  
27
    void delete(String id);
28
}
modules/uoa-admin-tools-library/trunk/src/main/java/eu/dnetlib/uoaadmintoolslibrary/controllers/PageHelpContentController.java
1
package eu.dnetlib.uoaadmintoolslibrary.controllers;
2

  
3
import org.apache.log4j.Logger;
4
import org.springframework.beans.factory.annotation.Autowired;
5
import org.springframework.web.bind.annotation.*;
6

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

  
10
import eu.dnetlib.uoaadmintoolslibrary.dao.CommunityDAO;
11
import eu.dnetlib.uoaadmintoolslibrary.dao.PageHelpContentDAO;
12
import eu.dnetlib.uoaadmintoolslibrary.entities.Community;
13
import eu.dnetlib.uoaadmintoolslibrary.entities.Page;
14
import eu.dnetlib.uoaadmintoolslibrary.entities.PageHelpContent;
15
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PageHelpContentResponse;
16

  
17
@RestController
18
@CrossOrigin(origins = "*")
19
public class PageHelpContentController {
20
    private final Logger log = Logger.getLogger(this.getClass());
21

  
22
    @Autowired
23
    private PageHelpContentDAO pageHelpContentDAO;
24

  
25
    @Autowired
26
    private PageController pageController;
27

  
28
    @Autowired
29
    private CommunityController communityController;
30

  
31
    @Autowired
32
    private CommunityDAO communityDAO;
33

  
34
    @RequestMapping(value = "/pagehelpcontent", method = RequestMethod.GET)
35
    public List<PageHelpContentResponse> getPageHelpContents(@RequestParam(required=false) String community,
36
                                                             @RequestParam(required=false) String page,
37
                                                             @RequestParam(required=false) String position,
38
                                                             @RequestParam(required=false) String active,
39
                                                             @RequestParam(required=false) String before) {
40
        List<PageHelpContent> pageHelpContents = null;
41

  
42
        Community _community = null;
43
        String communityId = null;
44
        if(community != null) {
45
            _community = communityController.getCommunity(community);
46
            if(_community != null) {
47
                communityId = _community.getId();
48
            }
49
        }
50
        //pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementAndIsActiveAndisPriorToOrderByOrderAsc(community, position, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
51

  
52
        if(community != null && position != null && active != null && before != null) {
53
            pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(communityId, position, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
54
        } else if(community != null && position != null && active != null) {
55
            pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementAndIsActiveOrderByOrderAsc(communityId, position, Boolean.parseBoolean(active));
56
        } else if(community != null && position != null && before != null) {
57
            pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementAndIsPriorToOrderByOrderAsc(communityId, position, Boolean.parseBoolean(before));
58
        } else if(community != null && active != null && before != null) {
59
            pageHelpContents = pageHelpContentDAO.findByCommunityAndIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(communityId, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
60
        } else if(position != null && active != null && before != null) {
61
            pageHelpContents = pageHelpContentDAO.findByPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(position, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
62
        } else if(community != null && position != null ) {
63
            pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementOrderByOrderAsc(communityId, position);
64
        } else if(community != null && active != null ) {
65
            pageHelpContents = pageHelpContentDAO.findByCommunityAndIsActiveOrderByPlacementAscOrderAsc(communityId, Boolean.parseBoolean(active));
66
        } else if(community != null && before != null) {
67
            pageHelpContents = pageHelpContentDAO.findByCommunityAndIsPriorToOrderByPlacementAscOrderAsc(communityId, Boolean.parseBoolean(before));
68
        } else if(position != null && active != null) {
69
            pageHelpContents = pageHelpContentDAO.findByPlacementAndIsActiveOrderByOrderAsc(position, Boolean.parseBoolean(active));
70
        } else if(position != null && before != null) {
71
            pageHelpContents = pageHelpContentDAO.findByPlacementAndIsPriorToOrderByOrderAsc(position,  Boolean.parseBoolean(before));
72
        } else if(active != null && before != null) {
73
            pageHelpContents = pageHelpContentDAO.findByIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(Boolean.parseBoolean(active), Boolean.parseBoolean(before));
74
        } else if(community != null) {
75
            pageHelpContents = pageHelpContentDAO.findByCommunityOrderByPlacementAscOrderAsc(communityId);
76
        } else if(position != null) {
77
            pageHelpContents = pageHelpContentDAO.findByPlacementOrderByOrderAsc(position);
78
        } else if(active != null) {
79
            pageHelpContents = pageHelpContentDAO.findByIsActiveOrderByPlacementAscOrderAsc(Boolean.parseBoolean(active));
80
        } else if(before != null) {
81
            pageHelpContents = pageHelpContentDAO.findByIsPriorToOrderByPlacementAscOrderAsc(Boolean.parseBoolean(before));
82
        } else {
83
            pageHelpContents = pageHelpContentDAO.findAllByOrderByPlacementAscOrderAsc();
84
        }
85

  
86
        List<PageHelpContentResponse> pageHelpContentResponses = new ArrayList<>();
87
        for (PageHelpContent pageHelpContent : pageHelpContents) {
88
            Page _page = pageController.getPage(pageHelpContent.getPage());
89
            if(page == null || page.equals(_page.getRoute())) {
90
                PageHelpContentResponse pageHelpContentResponse = new PageHelpContentResponse(pageHelpContent);
91

  
92
                pageHelpContentResponse.setPage(_page);
93
                pageHelpContentResponse.setCommunity(communityDAO.findById(pageHelpContent.getCommunity()));
94
                pageHelpContentResponses.add(pageHelpContentResponse);
95
            }
96
        }
97
        return pageHelpContentResponses;
98
    }
99
    /*
100
        @RequestMapping(value = "/pagehelpcontent/community/{id}", method = RequestMethod.GET)
101
        public List<PageHelpContentResponse> getCommunityPageHelpContents(@PathVariable(value = "id") String communityId) {
102
            List<PageHelpContent> pageHelpContents =  pageHelpContentDAO.findByCommunity(communityId);
103
            List<PageHelpContentResponse> pageHelpContentResponses = new ArrayList<>();
104
            for (PageHelpContent pageHelpContent : pageHelpContents) {
105
                PageHelpContentResponse pageHelpContentResponse = new PageHelpContentResponse(pageHelpContent);
106
                pageHelpContentResponse.setPage(pageDAO.findById(pageHelpContent.getPage()));
107
                pageHelpContentResponse.setCommunity(communityDAO.findById(pageHelpContent.getCommunity()));
108
                pageHelpContentResponses.add(pageHelpContentResponse);
109
            }
110
            return pageHelpContentResponses;
111
        }
112
    */
113
    @RequestMapping(value = "/pagehelpcontent", method = RequestMethod.DELETE)
114
    public void deleteAllPageHelpContents() {
115
        pageHelpContentDAO.deleteAll();
116
    }
117

  
118
    @RequestMapping(value = "/pagehelpcontent/save", method = RequestMethod.POST)
119
    public PageHelpContent insertPageHelpContent(@RequestBody PageHelpContent pageHelpContent) {
120
        String communityId = communityController.getCommunity(pageHelpContent.getCommunity()).getId();
121
        pageHelpContent.setCommunity(communityId);
122
        return pageHelpContentDAO.save(pageHelpContent);
123
    }
124

  
125
    @RequestMapping(value = "/pagehelpcontent/update", method = RequestMethod.POST)
126
    public PageHelpContent updatePageHelpContent(@RequestBody PageHelpContent pageHelpContent) {
127
        return pageHelpContentDAO.save(pageHelpContent);
128
    }
129

  
130
    @RequestMapping(value = "/pagehelpcontent/{id}", method = RequestMethod.GET)
131
    public PageHelpContent getPageHelpContent(@PathVariable(value = "id") String id) {
132
        return pageHelpContentDAO.findById(id);
133
    }
134

  
135
    @RequestMapping(value = "/pagehelpcontent/toggle", method = RequestMethod.POST)
136
    public List<String> togglePageHelpContent(@RequestBody List<String> pageHelpContents, @RequestParam String status) throws Exception {
137
        for (String id: pageHelpContents) {
138
            log.debug("Id of pageHelpContent: "+id);
139
            PageHelpContent pageHelpContent = pageHelpContentDAO.findById(id);
140
            pageHelpContent.setIsActive(Boolean.parseBoolean(status));
141
            pageHelpContentDAO.save(pageHelpContent);
142
        }
143
        return pageHelpContents;
144
    }
145

  
146
    @RequestMapping(value = "/pagehelpcontent/{id}", method = RequestMethod.DELETE)
147
    public void deletePageHelpContent(@PathVariable(value = "id") String id) {
148
        pageHelpContentDAO.delete(id);
149
    }
150

  
151
    @RequestMapping(value = "/pagehelpcontent/delete", method = RequestMethod.POST)
152
    public Boolean deletePageHelpContents(@RequestBody List<String> pageHelpContents) throws Exception {
153
        for (String id: pageHelpContents) {
154
            pageHelpContentDAO.delete(id);
155
        }
156
        return true;
157
    }
158

  
159
    public void addPageHelpContentsInCommunity(String pid, String communityId) {
160
        if (pid != "connect" && pid != "openaire") {
161
            String organizations_page_content = "<div> <p>Here you can write more details about the organizations related to your community.</p> </div>";
162
            Page organizationsPage = (pageController.getAllPages(null, "/organizations", null)).get(0);
163

  
164
            PageHelpContent organizations_pageHelpContent = new PageHelpContent(organizationsPage.getId(), pid, "top", 1, organizations_page_content, false, false);
165
            this.insertPageHelpContent(organizations_pageHelpContent);
166

  
167
            String depositLearnHow_page_content = "" +
168
                    "<div class=\"uk-width-3-5 uk-align-center\"> " +
169
                    " <div class=\"uk-text-bold\">How to comply with funder Open Access policies</div> " +
170
                    " <ul class=\"uk-list uk-list-bullet\"> " +
171
                    "   <li>Read the <a class=\"custom-external\" href=\"https://www.openaire.eu/how-to-comply-to-h2020-mandates-for-publications\" target=\"_blank\"> OpenAIRE guide to learn how to comply with EC H2020 Open Access policy on publications </a></li> " +
172
                    "   <li>Read the <a class=\"custom-external\" href=\"https://www.openaire.eu/how-to-comply-to-h2020-mandates-for-data\" target=\"_blank\"> OpenAIRE guide to learn how to comply with EC H2020 Open Access policy on research data </a></li> " +
173
                    "   <li>If you want to know about National Open Access policies, please check them out <a class=\"custom-external\" href=\"https://www.openaire.eu/frontpage/country-pages\" target=\"_blank\">here</a></li> " +
174
                    "   <li>All OpenAIRE guides can be found <a class=\"custom-external\" href=\"https://www.openaire.eu/guides\" target=\"_blank\">here</a></li> " +
175
                    " </ul> " +
176
                    "</div>";
177
            Page depositLearnHowPage = (pageController.getAllPages(null, "/participate/deposit/learn-how", null)).get(0);
178

  
179
            PageHelpContent depositLearnHow_pageHelpContent = new PageHelpContent(depositLearnHowPage.getId(), pid, "bottom", 1, depositLearnHow_page_content, true, false);
180
            this.insertPageHelpContent(depositLearnHow_pageHelpContent);
181
        }
182
    }
183
}
modules/uoa-admin-tools-library/trunk/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/MongoDBDAOs/MongoDBEntityDAO.java
1
package eu.dnetlib.uoaadmintoolslibrary.dao.MongoDBDAOs;
2

  
3
import eu.dnetlib.uoaadmintoolslibrary.dao.EntityDAO;
4
import eu.dnetlib.uoaadmintoolslibrary.entities.Entity;
5
import org.springframework.data.mongodb.repository.MongoRepository;
6

  
7
import java.util.List;
8

  
9
public interface MongoDBEntityDAO extends EntityDAO, MongoRepository<Entity, String> {
10
    List<Entity> findAll();
11

  
12
    Entity findById(String Id);
13

  
14
    Entity findByPid(String Pid);
15

  
16
    Entity findByName(String name);
17

  
18
    Entity save(Entity entity);
19

  
20
    void deleteAll();
21

  
22
    void delete(String id);
23
}
modules/uoa-admin-tools-library/trunk/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/MongoDBDAOs/MongoDBDivIdDAO.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.DivIdDAO;
8
import eu.dnetlib.uoaadmintoolslibrary.entities.DivId;
9

  
10
public interface MongoDBDivIdDAO extends DivIdDAO, MongoRepository<DivId, String> {
11
    List<DivId> findAll();
12

  
13
    List<DivId> findByPagesContaining(String page);
14

  
15
    DivId findByPagesContainingAndName(String page, String name);
16
    DivId findByName(String name);
17

  
18
    DivId findById(String Id);
19

  
20
    List<DivId> findByConnect(boolean connect);
21
    List<DivId> findByCommunities(boolean communities);
22
    List<DivId> findByOpenaire(boolean openaire);
23

  
24
    DivId save(DivId divId);
25

  
26
    void deleteAll();
27

  
28
    void delete(String id);
29
}
modules/uoa-admin-tools-library/trunk/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/MongoDBDAOs/MongoDBPageHelpContentDAO.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.PageHelpContentDAO;
8
import eu.dnetlib.uoaadmintoolslibrary.entities.PageHelpContent;
9

  
10
public interface MongoDBPageHelpContentDAO extends PageHelpContentDAO, MongoRepository<PageHelpContent, String> {
11
    List<PageHelpContent> findAll();
12

  
13
    List<PageHelpContent> findByCommunityAndPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(String communityId, String position, boolean isActive, boolean isPriorTo);
14
    List<PageHelpContent> findByCommunityAndPlacementAndIsActiveOrderByOrderAsc(String communityId, String position, boolean isActive);
15
    List<PageHelpContent> findByCommunityAndPlacementAndIsPriorToOrderByOrderAsc(String communityId, String position, boolean isPriorTo);
16
    List<PageHelpContent> findByCommunityAndIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(String communityId, boolean isActive, boolean isPriorTo);
17
    List<PageHelpContent> findByPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(String position, boolean isActive, boolean isPriorTo);
18
    List<PageHelpContent> findByCommunityAndPlacementOrderByOrderAsc(String communityId, String postion);
19
    List<PageHelpContent> findByCommunityAndIsActiveOrderByPlacementAscOrderAsc(String communityId, boolean isActive);
20
    List<PageHelpContent> findByCommunityAndIsPriorToOrderByPlacementAscOrderAsc(String communityId, boolean isPriorTo);
21
    List<PageHelpContent> findByPlacementAndIsActiveOrderByOrderAsc(String position, boolean isActive);
22
    List<PageHelpContent> findByPlacementAndIsPriorToOrderByOrderAsc(String position, boolean isPriorTo);
23
    List<PageHelpContent> findByIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(boolean isActive, boolean isPriorTo);
24
    List<PageHelpContent> findByCommunityOrderByPlacementAscOrderAsc(String communityId);
25
    List<PageHelpContent> findByPlacementOrderByOrderAsc(String postion);
26
    List<PageHelpContent> findByIsActiveOrderByPlacementAscOrderAsc(boolean isActive);
27
    List<PageHelpContent> findByIsPriorToOrderByPlacementAscOrderAsc(boolean isPriorTo);
28
    List<PageHelpContent> findAllByOrderByPlacementAscOrderAsc();
29

  
30

  
31
    //List<PageHelpContent> findByCommunityAndPlacementAndIsActiveAndBeforeOrderByOrderAsc(String communityId, String postion, boolean isActive, boolean before);
32

  
33
    PageHelpContent findById(String Id);
34

  
35
    PageHelpContent findByIdOrderByOrder(String Id);
36

  
37
    PageHelpContent save(PageHelpContent pageHelpContent);
38

  
39
    void deleteAll();
40

  
41
    void delete(String id);
42
}
modules/uoa-admin-tools-library/trunk/src/main/java/eu/dnetlib/uoaadmintoolslibrary/controllers/DivHelpContentController.java
1
package eu.dnetlib.uoaadmintoolslibrary.controllers;
2

  
3
import org.apache.log4j.Logger;
4
import org.springframework.beans.factory.annotation.Autowired;
5
import org.springframework.web.bind.annotation.*;
6

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

  
10
import eu.dnetlib.uoaadmintoolslibrary.dao.CommunityDAO;
11
import eu.dnetlib.uoaadmintoolslibrary.dao.DivHelpContentDAO;
12
import eu.dnetlib.uoaadmintoolslibrary.dao.DivIdDAO;
13
import eu.dnetlib.uoaadmintoolslibrary.entities.Community;
14
import eu.dnetlib.uoaadmintoolslibrary.entities.DivHelpContent;
15
import eu.dnetlib.uoaadmintoolslibrary.entities.DivId;
16
import eu.dnetlib.uoaadmintoolslibrary.entities.Page;
17
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.DivHelpContentResponse;
18
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.DivIdResponse;
19

  
20
@RestController
21
@CrossOrigin(origins = "*")
22
public class DivHelpContentController {
23
    private final Logger log = Logger.getLogger(this.getClass());
24

  
25
    @Autowired
26
    DivIdController divIdController;
27

  
28
    @Autowired
29
    private DivHelpContentDAO divHelpContentDAO;
30

  
31
    @Autowired
32
    private DivIdDAO divIdDAO;
33

  
34
    @Autowired
35
    private CommunityDAO communityDAO;
36

  
37
    @RequestMapping(value = "/divhelpcontent", method = RequestMethod.GET)
38
    public List<DivHelpContentResponse> getDivHelpContents(@RequestParam(required = false) String community,
39
                                                           @RequestParam(required = false) String page,
40
                                                           @RequestParam(required = false) String div,
41
                                                           @RequestParam(required = false) String active) {
42

  
43
        Community _community = communityDAO.findByPid(community);
44
        String communityId = null;
45
        if(_community != null) {
46
            communityId = _community.getId();
47
        }
48

  
49
        DivId divId = divIdDAO.findByName(div);
50
        String divIdId = null;
51
        if(divId != null) {
52
            divIdId = divId.getId();
53
        }
54

  
55
        List<DivHelpContentResponse> divHelpContentResponses = new ArrayList<>();
56

  
57
        List<DivHelpContent> divHelpContents = null;
58
        if(community != null && div != null && active != null) {
59
            divHelpContents = divHelpContentDAO.findByCommunityAndDivIdAndIsActive(communityId, divIdId, Boolean.parseBoolean(active));
60
        } else if(community != null && div != null) {
61
            divHelpContents = divHelpContentDAO.findByCommunityAndDivId(communityId, divIdId);
62
        } else if(community != null && active != null) {
63
            divHelpContents = divHelpContentDAO.findByCommunityAndIsActive(communityId, Boolean.parseBoolean(active));
64
        } else if(div != null && active != null) {
65
            divHelpContents = divHelpContentDAO.findByDivIdAndIsActive(divIdId, Boolean.parseBoolean(active));
66
        } else if(community != null) {
67
            divHelpContents = divHelpContentDAO.findByCommunity(communityId);
68
        } else if(div != null) {
69
            divHelpContents = divHelpContentDAO.findByDivId(divIdId);
70
        } else if(active != null){
71
            divHelpContents = divHelpContentDAO.findByIsActive(Boolean.parseBoolean(active));
72
        } else {
73
            divHelpContents = divHelpContentDAO.findAll();
74
        }
75

  
76
        for (DivHelpContent divHelpContent : divHelpContents) {
77
            DivIdResponse divIdResponse = null;
78
            if(div == null) {
79
                divId = divIdDAO.findById(divHelpContent.getDivId());
80
            }
81
            divIdResponse = divIdController.divIdResponseFromDivId(divId);
82

  
83
            if(community == null) {
84
                _community = communityDAO.findById(divHelpContent.getCommunity());
85
            }
86

  
87
            for(Page p : divIdResponse.getPages()) {
88
                if (page == null || p.getRoute().equals(page)) {
89
                    DivHelpContentResponse divHelpContentResponse = new DivHelpContentResponse(divHelpContent);
90
                    divHelpContentResponse.setDivId(divIdResponse);
91
                    divHelpContentResponse.setCommunity(_community);
92
                    divHelpContentResponses.add(divHelpContentResponse);
93
                    break;
94
                }
95
            }
96
        }
97

  
98
        return divHelpContentResponses;
99
    }
100

  
101
    @RequestMapping(value = "/divhelpcontent/{id}", method = RequestMethod.GET)
102
    public DivHelpContent getDivHelpContent(@PathVariable(value = "id") String id) {
103
        return divHelpContentDAO.findById(id);
104
    }
105

  
106
    @RequestMapping(value = "/divhelpcontent", method = RequestMethod.POST)
107
    public DivHelpContent insertOrUpdateDivHelpContent(@RequestBody DivHelpContent divHelpContent) {
108
        return divHelpContentDAO.save(divHelpContent);
109
    }
110

  
111
    @RequestMapping(value = "/divhelpcontent/{id}", method = RequestMethod.DELETE)
112
    public void deleteDivHelpContent(@PathVariable(value = "id") String id) {
113
        divHelpContentDAO.delete(id);
114
    }
115

  
116
    @RequestMapping(value = "/divhelpcontent/delete", method = RequestMethod.POST)
117
    public Boolean deleteDivHelpContents(@RequestBody List<String> divHelpContents) throws Exception {
118
        for (String id: divHelpContents) {
119
            divHelpContentDAO.delete(id);
120
        }
121
        return true;
122
    }
123

  
124
    @RequestMapping(value = "/divhelpcontent/toggle", method = RequestMethod.POST)
125
    public List<String> toggleDivHelpContent(@RequestBody List<String> divHelpContents, @RequestParam String status) throws Exception {
126
        for (String id: divHelpContents) {
127
            log.debug("Id of divHelpContent: "+id);
128
            DivHelpContent divHelpContent = divHelpContentDAO.findById(id);
129
            divHelpContent.setIsActive(Boolean.parseBoolean(status));
130
            divHelpContentDAO.save(divHelpContent);
131
        }
132
        return divHelpContents;
133
    }
134

  
135
    public void addDivHelpContentsInCommunity(String pid, String communityId, String divIdName) {
136
        //String organizations_class_content = "<div> <p>Here you can write more details about the organizations related to your community.</p> </div>";
137
        String link_context_form_content = "<div> <div><span class=\"uk-text-bold\"><span uk-icon=\"icon: info\">&nbsp;</span> Information:</span> Select a research community and/or a category and search for a community concept, or browse to the community tree through the categories</div> </div>";
138
        String link_project_form_content = "<div> <div><span class=\"uk-text-bold\"><span uk-icon=\"icon: info\">&nbsp;</span> Information:</span> Search for projects using project name or grant id. Limit results filtering by funder.</div> </div>";
139
        String link_result_form_content = "<div> <div><span class=\"uk-text-bold\"><span uk-icon=\"icon: info\">&nbsp;</span> Information:</span></div> Search for research results in OpenAIRE information space, Datacite, CrossRef or ORCID. <div class=\"uk-text-small\">Use keywords, DOI (more than one - space separated), author&#39;s ORCID</div> </div>";
140
        String link_result_bulk_content = "<div> <div><span class=\"uk-text-bold\"><span uk-icon=\"icon: info\">&nbsp;</span> Information:</span> Upload a csv file containing a list of DOIs. For each DOI found in the file, metadata will be fetched from CrossRef or Datacite and will be added to your selected research results.</div> <div class=\"uk-margin-top uk-text-small\"><span class=\"uk-text-bold\">CSV format:</span> <ul class=\"uk-list\"> <li>The format of CSV file should be &quot;DOI&quot;,&quot;ACCESS_MODE&quot;,&quot;DATE&quot;.</li> <li>The value &quot;DOI&quot; is required</li> <li>Access mode column should have values: &quot;OPEN&quot;,&quot;CLOSED&quot; or &quot;EMBARGO&quot;.</li> <li>Date column valid format is YYYY-MM-DD and is required when access mode has value EMBARGO.</li> <li>In case access mode is not available default value is &quot;OPEN&quot;.</li> </ul> </div> </div>";
141
        String link_metadata_content = "<div> <div><span class=\"uk-text-bold\"><span uk-icon=\"icon: info\">&nbsp;</span> Information:</span> Manage access mode &amp; type of selected research results. For OpenAIRE this functionality isn&#39;t available.</div> </div>";
142

  
143
        List<DivId> divIds = divIdController.getDivIds(null, divIdName, null);
144

  
145
        for( DivId div : divIds ) {
146
            if (div != null && (
147
                    (div.getOpenaire() && pid.equals("openaire")) ||
148
                            (div.getConnect() && pid.equals("connect")) ||
149
                            (div.getCommunities() && !pid.equals("openaire") && !pid.equals("connect"))
150
            )) {
151
                /*
152
                if (div.getName().equals("organizations")) {
153
                    this.insertOrUpdateDivHelpContent(new DivHelpContent(div.getId(), communityId, organizations_class_content, false));
154
                } else
155
                */
156
                if (div.getName().equals("link-context-form")) {
157
                    this.insertOrUpdateDivHelpContent(new DivHelpContent(div.getId(), communityId, link_context_form_content, false));
158
                } else if (div.getName().equals("link-project-form")) {
159
                    this.insertOrUpdateDivHelpContent(new DivHelpContent(div.getId(), communityId, link_project_form_content, false));
160
                } else if (div.getName().equals("link-result-form")) {
161
                    this.insertOrUpdateDivHelpContent(new DivHelpContent(div.getId(), communityId, link_result_form_content, false));
162
                } else if (div.getName().equals("link-result-bulk")) {
163
                    this.insertOrUpdateDivHelpContent(new DivHelpContent(div.getId(), communityId, link_result_bulk_content, false));
164
                } else if (div.getName().equals("link-metadata")) {
165
                    this.insertOrUpdateDivHelpContent(new DivHelpContent(div.getId(), communityId, link_metadata_content, false));
166
                }
167
            }
168
        }
169
    }
170

  
171
}
modules/uoa-admin-tools-library/trunk/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/MongoDBDAOs/MongoDBCommunityDAO.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.CommunityDAO;
8
import eu.dnetlib.uoaadmintoolslibrary.entities.Community;
9

  
10
public interface MongoDBCommunityDAO extends CommunityDAO, MongoRepository<Community, String> {
11
    List<Community> findAll();
12

  
13
    Community findById(String Id);
14

  
15
    Community findByPid(String Pid);
16

  
17
    Community findByName(String Name);
18

  
19
    Community save(Community community);
20

  
21
    void deleteAll();
22

  
23
    void delete(String id);
24
}
modules/uoa-admin-tools-library/trunk/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 Boolean connect;
16
    private Boolean communities;
17
    private Boolean openaire;
18

  
19
    public DivId() {}
20

  
21
    public DivId(DivId divId) {
22
        setName(divId.getName());
23
        setPages(divId.getPages());
24
        setConnect(divId.getConnect());
25
        setCommunities(divId.getCommunities());
26
        setOpenaire(divId.getOpenaire());
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 Boolean getConnect() {
54
        return connect;
55
    }
56

  
57
    public void setConnect(Boolean connect) { this.connect = connect; }
58

  
59
    public Boolean getCommunities() { return communities; }
60

  
61
    public void setCommunities(Boolean communities) {
62
        this.communities = communities;
63
    }
64

  
65
    public Boolean getOpenaire() {
66
        return openaire;
67
    }
68

  
69
    public void setOpenaire(Boolean openaire) {
70
        this.openaire = openaire;
71
    }
72
}
modules/uoa-admin-tools-library/trunk/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 community;
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 community, String placement, int order, String content, boolean isActive, boolean isPriorTo) {
22
        this.page = page;
23
        this.community = community;
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 getCommunity() {
48
        return community;
49
    }
50

  
51
    public void setCommunity(String community) {
52
        this.community = community;
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/trunk/src/main/java/eu/dnetlib/uoaadmintoolslibrary/entities/Community.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.Map;
7

  
8
public class Community {
9

  
10
    @Id
11
    @JsonProperty("_id")
12
    private String id;
13

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff