1
|
package eu.dnetlib.uoaadmintools.controllers;
|
2
|
|
3
|
import eu.dnetlib.uoaadmintools.dao.CommunityDAO;
|
4
|
import eu.dnetlib.uoaadmintools.dao.DivHelpContentDAO;
|
5
|
import eu.dnetlib.uoaadmintools.dao.DivIdDAO;
|
6
|
import eu.dnetlib.uoaadmintools.dao.PageDAO;
|
7
|
import eu.dnetlib.uoaadmintools.entities.*;
|
8
|
import org.apache.log4j.Logger;
|
9
|
import org.springframework.beans.factory.annotation.Autowired;
|
10
|
import org.springframework.web.bind.annotation.*;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.List;
|
14
|
|
15
|
@RestController
|
16
|
@CrossOrigin(origins = "*")
|
17
|
public class DivHelpContentController {
|
18
|
private final Logger log = Logger.getLogger(this.getClass());
|
19
|
|
20
|
@Autowired
|
21
|
DivIdController divIdController;
|
22
|
|
23
|
@Autowired
|
24
|
private DivHelpContentDAO divHelpContentDAO;
|
25
|
|
26
|
@Autowired
|
27
|
private DivIdDAO divIdDAO;
|
28
|
|
29
|
@Autowired
|
30
|
private PageDAO pageDAO;
|
31
|
|
32
|
@Autowired
|
33
|
private CommunityDAO communityDAO;
|
34
|
|
35
|
@RequestMapping(value = "/divhelpcontent", method = RequestMethod.GET)
|
36
|
public List<DivHelpContentResponse> getDivHelpContents(@RequestParam(required = false) String community,
|
37
|
@RequestParam(required = false) String page,
|
38
|
@RequestParam(required = false) String div,
|
39
|
@RequestParam(required = false) String active) {
|
40
|
|
41
|
Community _community = communityDAO.findByPid(community);
|
42
|
String communityId = null;
|
43
|
if(_community != null) {
|
44
|
communityId = _community.getId();
|
45
|
}
|
46
|
|
47
|
DivId divId = divIdDAO.findByName(div);
|
48
|
String divIdId = null;
|
49
|
if(divId != null) {
|
50
|
divIdId = divId.getId();
|
51
|
}
|
52
|
|
53
|
List<DivHelpContentResponse> divHelpContentResponses = new ArrayList<>();
|
54
|
|
55
|
List<DivHelpContent> divHelpContents = null;
|
56
|
if(community != null && div != null && active != null) {
|
57
|
divHelpContents = divHelpContentDAO.findByCommunityAndDivIdAndIsActive(communityId, divIdId, Boolean.parseBoolean(active));
|
58
|
} else if(community != null && div != null) {
|
59
|
divHelpContents = divHelpContentDAO.findByCommunityAndDivId(communityId, divIdId);
|
60
|
} else if(community != null && active != null) {
|
61
|
divHelpContents = divHelpContentDAO.findByCommunityAndIsActive(communityId, Boolean.parseBoolean(active));
|
62
|
} else if(div != null && active != null) {
|
63
|
divHelpContents = divHelpContentDAO.findByDivIdAndIsActive(divIdId, Boolean.parseBoolean(active));
|
64
|
} else if(community != null) {
|
65
|
divHelpContents = divHelpContentDAO.findByCommunity(communityId);
|
66
|
} else if(div != null) {
|
67
|
divHelpContents = divHelpContentDAO.findByDivId(divIdId);
|
68
|
} else if(active != null){
|
69
|
divHelpContents = divHelpContentDAO.findByIsActive(Boolean.parseBoolean(active));
|
70
|
} else {
|
71
|
divHelpContents = divHelpContentDAO.findAll();
|
72
|
}
|
73
|
|
74
|
for (DivHelpContent divHelpContent : divHelpContents) {
|
75
|
DivIdResponse divIdResponse = null;
|
76
|
if(div == null) {
|
77
|
divId = divIdDAO.findById(divHelpContent.getDivId());
|
78
|
}
|
79
|
divIdResponse = divIdController.divIdResponseFromDivId(divId);
|
80
|
|
81
|
if(community == null) {
|
82
|
_community = communityDAO.findById(divHelpContent.getCommunity());
|
83
|
}
|
84
|
|
85
|
for(Page p : divIdResponse.getPages()) {
|
86
|
if (page == null || p.getRoute().equals(page)) {
|
87
|
DivHelpContentResponse divHelpContentResponse = new DivHelpContentResponse(divHelpContent);
|
88
|
divHelpContentResponse.setDivId(divIdResponse);
|
89
|
divHelpContentResponse.setCommunity(_community);
|
90
|
divHelpContentResponses.add(divHelpContentResponse);
|
91
|
break;
|
92
|
}
|
93
|
}
|
94
|
}
|
95
|
|
96
|
return divHelpContentResponses;
|
97
|
}
|
98
|
|
99
|
@RequestMapping(value = "/divhelpcontent/{id}", method = RequestMethod.GET)
|
100
|
public DivHelpContent getDivHelpContent(@PathVariable(value = "id") String id) {
|
101
|
return divHelpContentDAO.findById(id);
|
102
|
}
|
103
|
|
104
|
@RequestMapping(value = "/divhelpcontent", method = RequestMethod.POST)
|
105
|
public DivHelpContent insertOrUpdateDivHelpContent(@RequestBody DivHelpContent divHelpContent) {
|
106
|
return divHelpContentDAO.save(divHelpContent);
|
107
|
}
|
108
|
|
109
|
@RequestMapping(value = "/divhelpcontent/{id}", method = RequestMethod.DELETE)
|
110
|
public void deleteDivHelpContent(@PathVariable(value = "id") String id) {
|
111
|
divHelpContentDAO.delete(id);
|
112
|
}
|
113
|
|
114
|
@RequestMapping(value = "/divhelpcontent/delete", method = RequestMethod.POST)
|
115
|
public Boolean deleteDivHelpContents(@RequestBody List<String> divHelpContents) throws Exception {
|
116
|
for (String id: divHelpContents) {
|
117
|
divHelpContentDAO.delete(id);
|
118
|
}
|
119
|
return true;
|
120
|
}
|
121
|
|
122
|
@RequestMapping(value = "/divhelpcontent/toggle", method = RequestMethod.POST)
|
123
|
public List<String> toggleDivHelpContent(@RequestBody List<String> divHelpContents, @RequestParam String status) throws Exception {
|
124
|
for (String id: divHelpContents) {
|
125
|
log.debug("Id of divHelpContent: "+id);
|
126
|
DivHelpContent divHelpContent = divHelpContentDAO.findById(id);
|
127
|
divHelpContent.setIsActive(Boolean.parseBoolean(status));
|
128
|
divHelpContentDAO.save(divHelpContent);
|
129
|
}
|
130
|
return divHelpContents;
|
131
|
}
|
132
|
|
133
|
public void addDivHelpContentsInCommunity(String pid, String communityId, String divIdName) {
|
134
|
//String organizations_class_content = "<div> <p>Here you can write more details about the organizations related to your community.</p> </div>";
|
135
|
String link_context_form_content = "<div> <div><span class=\"uk-text-bold\"><span uk-icon=\"icon: info\"> </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>";
|
136
|
String link_project_form_content = "<div> <div><span class=\"uk-text-bold\"><span uk-icon=\"icon: info\"> </span> Information:</span> Search for projects using project name or grant id. Limit results filtering by funder.</div> </div>";
|
137
|
String link_result_form_content = "<div> <div><span class=\"uk-text-bold\"><span uk-icon=\"icon: info\"> </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's ORCID</div> </div>";
|
138
|
String link_result_bulk_content = "<div> <div><span class=\"uk-text-bold\"><span uk-icon=\"icon: info\"> </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 "DOI","ACCESS_MODE","DATE".</li> <li>The value "DOI" is required</li> <li>Access mode column should have values: "OPEN","CLOSED" or "EMBARGO".</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 "OPEN".</li> </ul> </div> </div>";
|
139
|
String link_metadata_content = "<div> <div><span class=\"uk-text-bold\"><span uk-icon=\"icon: info\"> </span> Information:</span> Manage access mode & type of selected research results. For OpenAIRE this functionality isn't available.</div> </div>";
|
140
|
|
141
|
List<DivId> divIds = divIdController.getDivIds(null, divIdName, null);
|
142
|
|
143
|
for( DivId div : divIds ) {
|
144
|
if (div != null && (
|
145
|
(div.getOpenaire() && pid.equals("openaire")) ||
|
146
|
(div.getConnect() && pid.equals("connect")) ||
|
147
|
(div.getCommunities() && !pid.equals("openaire") && !pid.equals("connect"))
|
148
|
)) {
|
149
|
/*
|
150
|
if (div.getName().equals("organizations")) {
|
151
|
this.insertOrUpdateDivHelpContent(new DivHelpContent(div.getId(), communityId, organizations_class_content, false));
|
152
|
} else
|
153
|
*/
|
154
|
if (div.getName().equals("link-context-form")) {
|
155
|
this.insertOrUpdateDivHelpContent(new DivHelpContent(div.getId(), communityId, link_context_form_content, false));
|
156
|
} else if (div.getName().equals("link-project-form")) {
|
157
|
this.insertOrUpdateDivHelpContent(new DivHelpContent(div.getId(), communityId, link_project_form_content, false));
|
158
|
} else if (div.getName().equals("link-result-form")) {
|
159
|
this.insertOrUpdateDivHelpContent(new DivHelpContent(div.getId(), communityId, link_result_form_content, false));
|
160
|
} else if (div.getName().equals("link-result-bulk")) {
|
161
|
this.insertOrUpdateDivHelpContent(new DivHelpContent(div.getId(), communityId, link_result_bulk_content, false));
|
162
|
} else if (div.getName().equals("link-metadata")) {
|
163
|
this.insertOrUpdateDivHelpContent(new DivHelpContent(div.getId(), communityId, link_metadata_content, false));
|
164
|
}
|
165
|
}
|
166
|
}
|
167
|
}
|
168
|
|
169
|
}
|