Revision 49898
Added by Panagiotis Kanakakis over 6 years ago
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/PiWiApi.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.controllers; |
|
2 |
|
|
3 |
|
|
4 |
import eu.dnetlib.domain.data.PiwikInfo; |
|
5 |
import org.springframework.http.MediaType; |
|
6 |
import org.springframework.web.bind.annotation.*; |
|
7 |
|
|
8 |
import java.util.List; |
|
9 |
|
|
10 |
@RestController |
|
11 |
@RequestMapping(value = "/piwi") |
|
12 |
public interface PiWiApi { |
|
13 |
|
|
14 |
|
|
15 |
@RequestMapping(value = "/getPiwikSiteForRepo/{repositoryId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) |
|
16 |
@ResponseBody |
|
17 |
PiwikInfo getPiwikSiteForRepo(String repositoryId); |
|
18 |
|
|
19 |
@RequestMapping(value = "/savePiwikInfo" , method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE) |
|
20 |
PiwikInfo savePiwikInfo(@RequestBody PiwikInfo piwikInfo); |
|
21 |
|
|
22 |
@RequestMapping(value = "/getPiwikSitesForRepos" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) |
|
23 |
List<PiwikInfo> getPiwikSitesForRepos(); |
|
24 |
|
|
25 |
@RequestMapping(value = "/approvePiwikSite/{repositoryId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) |
|
26 |
@ResponseBody |
|
27 |
void approvePiwikSite(String repositoryId); |
|
28 |
|
|
29 |
@RequestMapping(value = "/getOpenaireId/{repositoryid}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) |
|
30 |
@ResponseBody |
|
31 |
String getOpenaireId(String repositoryid); |
|
32 |
} |
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/PiWiApiImpl.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.controllers; |
|
2 |
|
|
3 |
import eu.dnetlib.domain.data.PiwikInfo; |
|
4 |
import eu.dnetlib.utils.md5.MD5; |
|
5 |
import org.springframework.beans.factory.annotation.Autowired; |
|
6 |
import org.springframework.beans.factory.annotation.Qualifier; |
|
7 |
import org.springframework.jdbc.core.JdbcTemplate; |
|
8 |
import org.springframework.jdbc.core.RowMapper; |
|
9 |
import org.springframework.stereotype.Component; |
|
10 |
import org.springframework.web.bind.annotation.PathVariable; |
|
11 |
|
|
12 |
import javax.sql.DataSource; |
|
13 |
import java.security.NoSuchAlgorithmException; |
|
14 |
import java.sql.ResultSet; |
|
15 |
import java.sql.SQLException; |
|
16 |
import java.sql.Types; |
|
17 |
import java.util.List; |
|
18 |
|
|
19 |
@Component |
|
20 |
public class PiWiApiImpl implements PiWiApi{ |
|
21 |
|
|
22 |
@Autowired |
|
23 |
@Qualifier("repomanager.dataSource") |
|
24 |
private DataSource dataSource; |
|
25 |
|
|
26 |
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger |
|
27 |
.getLogger(BrokerApiImpl.class); |
|
28 |
|
|
29 |
private final static String GET_PIWIK_SITE = "select repositoryid, siteid, authenticationtoken, creationdate, requestorname, requestoremail, approved, approvaldate, comment, repositoryname, country from piwik_site where repositoryid = ?;"; |
|
30 |
|
|
31 |
private final static String INSERT_PIWIK_INFO = "insert into piwik_site (repositoryid, siteid, creationdate, requestorname, requestoremail, approved, repositoryname, country, authenticationtoken) values (?, ?, now(), ?, ?, ?, ?, ?, ?)"; |
|
32 |
|
|
33 |
private final static String GET_PIWIK_SITES = "select repositoryid, siteid, authenticationtoken, creationdate, requestorname, requestoremail, approved, approvaldate, comment, repositoryname, country from piwik_site order by repositoryname"; |
|
34 |
|
|
35 |
private final static String APPROVE_PIWIK_SITE = "update piwik_site set approved=true, approvaldate=now() where repositoryid = ?;"; |
|
36 |
|
|
37 |
private RowMapper<PiwikInfo> piwikRowMapper = new RowMapper<PiwikInfo>() { |
|
38 |
@Override |
|
39 |
public PiwikInfo mapRow(ResultSet rs, int i) throws SQLException { |
|
40 |
return new PiwikInfo(rs.getString("repositoryid"), getOpenaireId(rs.getString("repositoryid")), rs.getString("repositoryname"), rs.getString("country"), |
|
41 |
rs.getString("siteid"), rs.getString("authenticationtoken"), rs.getTimestamp("creationdate"), rs.getString("requestorname"), rs.getString("requestoremail"), |
|
42 |
rs.getBoolean("approved"), rs.getTimestamp("approvaldate"), rs.getString("comment")); |
|
43 |
} |
|
44 |
}; |
|
45 |
|
|
46 |
|
|
47 |
@Override |
|
48 |
public PiwikInfo getPiwikSiteForRepo(@PathVariable("repositoryId") String repositoryId) { |
|
49 |
try { |
|
50 |
LOGGER.debug("URL -> " + dataSource.getConnection()); |
|
51 |
} catch (SQLException e) { |
|
52 |
LOGGER.debug("error on connection",e); |
|
53 |
} |
|
54 |
return new JdbcTemplate(dataSource).queryForObject(GET_PIWIK_SITE, new String[]{repositoryId}, new int[]{Types.VARCHAR}, piwikRowMapper); |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
public PiwikInfo savePiwikInfo(PiwikInfo piwikInfo) { |
|
59 |
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); |
|
60 |
jdbcTemplate.update(INSERT_PIWIK_INFO, new Object[]{piwikInfo.getRepositoryId(), piwikInfo.getSiteId(), piwikInfo.getRequestorName(), |
|
61 |
piwikInfo.getRequestorEmail(), piwikInfo.isValidated(), piwikInfo.getRepositoryName(), piwikInfo.getCountry(), piwikInfo.getAuthenticationToken()}, |
|
62 |
new int[]{Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BOOLEAN, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR}); |
|
63 |
return piwikInfo; |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
public List<PiwikInfo> getPiwikSitesForRepos() { |
|
68 |
return new JdbcTemplate(dataSource).query(GET_PIWIK_SITES, piwikRowMapper); |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public void approvePiwikSite(@PathVariable("repositoryId") String repositoryId) { |
|
73 |
new JdbcTemplate(dataSource).update(APPROVE_PIWIK_SITE, new Object[] {repositoryId}, new int[] {Types.VARCHAR}); |
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
public String getOpenaireId(@PathVariable("repositoryId") String repositoryid) { |
|
78 |
try { |
|
79 |
if (repositoryid != null && repositoryid.contains("::")) |
|
80 |
return repositoryid.split("::")[0] + "::" + MD5.encrypt2Hex(repositoryid.split("::")[1]); |
|
81 |
else |
|
82 |
return null; |
|
83 |
} catch (NoSuchAlgorithmException e) { |
|
84 |
e.printStackTrace(); |
|
85 |
} |
|
86 |
return null; |
|
87 |
} |
|
88 |
|
|
89 |
|
|
90 |
} |
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/utils/Converter.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import eu.dnetlib.domain.data.Repository; |
4 | 4 |
import eu.dnetlib.domain.data.RepositoryInterface; |
5 |
import eu.dnetlib.repo.manager.service.controllers.RepositoryApi; |
|
5 | 6 |
import eu.dnetlib.repo.manager.shared.*; |
6 | 7 |
import org.apache.log4j.Logger; |
7 | 8 |
import org.json.JSONArray; |
8 | 9 |
import org.json.JSONException; |
9 | 10 |
import org.json.JSONObject; |
11 |
import org.springframework.beans.factory.annotation.Autowired; |
|
10 | 12 |
|
11 | 13 |
import java.io.*; |
12 | 14 |
import java.text.ParseException; |
... | ... | |
16 | 18 |
public class Converter { |
17 | 19 |
|
18 | 20 |
private static final Logger LOGGER = Logger.getLogger(Converter.class); |
19 |
|
|
21 |
|
|
20 | 22 |
public static Repository jsonToRepositoryObject(JSONObject repositoryObject) throws JSONException { |
21 | 23 |
|
22 | 24 |
Repository repository = new Repository(); |
... | ... | |
31 | 33 |
repository.setCertificates(datasource.get("certificates").toString()); |
32 | 34 |
repository.setCitationGuidelineUrl(datasource.get("citationguidelineurl").toString()); |
33 | 35 |
repository.setCollectedFrom( datasource.get("collectedfrom").toString()); |
36 |
|
|
34 | 37 |
repository.setContactEmail(datasource.get("contactemail").toString()); |
38 |
if(repository.getContactEmail().equals("null")) |
|
39 |
repository.setContactEmail(""); |
|
40 |
|
|
35 | 41 |
repository.setDatabaseAccessRestriction(datasource.get("databaseaccessrestriction").toString()); |
36 | 42 |
repository.setDatabaseAccessType(datasource.get("databaseaccesstype").toString()); |
37 | 43 |
repository.setDataUploadRestriction(datasource.get("datauploadrestriction").toString()); |
38 | 44 |
repository.setDataUploadType(datasource.get("datauploadtype").toString()); |
39 | 45 |
repository.setDateOfCollection(convertStringToDate( datasource.get("dateofcollection").toString())); |
40 | 46 |
repository.setDateOfValidation(convertStringToDate( datasource.get("dateofvalidation").toString())); |
47 |
|
|
41 | 48 |
repository.setDescription(datasource.get("description").toString()); |
49 |
if(repository.getDescription().equals("null")) |
|
50 |
repository.setDescription(""); |
|
51 |
|
|
42 | 52 |
repository.setEissn(datasource.get("eissn").toString()); |
53 |
|
|
43 | 54 |
repository.setEnglishName( datasource.get("englishname").toString()); |
55 |
if(repository.getEnglishName().equals("null")) |
|
56 |
repository.setEnglishName(""); |
|
57 |
|
|
58 |
|
|
44 | 59 |
repository.setId(datasource.get("id").toString()); |
45 | 60 |
repository.setIssn(datasource.get("issn").toString()); |
46 | 61 |
repository.setOdLanguages(datasource.get("languages").toString()); |
47 | 62 |
repository.setLatitude( toDouble(datasource.get("latitude").toString())); |
48 | 63 |
repository.setLissn(datasource.get("lissn").toString()); |
64 |
|
|
49 | 65 |
repository.setLogoUrl(datasource.get("logourl").toString()); |
66 |
if(repository.getLogoUrl().equals("null")) |
|
67 |
repository.setLogoUrl(""); |
|
68 |
|
|
50 | 69 |
repository.setLongitude(toDouble(datasource.get("longitude").toString())); |
51 | 70 |
//datasource.get("managed"); |
52 | 71 |
repository.setMissionStatementUrl(datasource.get("missionstatementurl").toString()); |
53 | 72 |
repository.setNamespacePrefix(datasource.get("namespaceprefix").toString()); |
54 | 73 |
repository.setOdContentTypes(datasource.get("od_contenttypes").toString()); |
55 | 74 |
repository.setOfficialName(datasource.get("officialname").toString()); |
75 |
if(repository.getOfficialName().equals("null")) |
|
76 |
repository.setOfficialName(""); |
|
77 |
|
|
56 | 78 |
repository.setPidSystems(datasource.get("pidsystems").toString()); |
57 | 79 |
//datasource.get("platform"); |
58 | 80 |
repository.setProvenanceActionClass( datasource.get("provenanceaction").toString()); |
... | ... | |
64 | 86 |
//datasource.get("subjects"); |
65 | 87 |
Double timezone = toDouble(datasource.get("timezone").toString()); |
66 | 88 |
repository.setTimezone(timezone!=null?timezone:0.0); |
67 |
repository.setTypology(datasource.get("typology").toString());
|
|
89 |
repository.setTypology(datasource.get("platform").toString());
|
|
68 | 90 |
repository.setVersioning(Boolean.valueOf(datasource.get("versioning").toString())); |
69 | 91 |
repository.setWebsiteUrl(datasource.get("websiteurl").toString()); |
92 |
repository.setDatasourceClass(datasource.get("typology").toString()); |
|
93 |
|
|
94 |
//TODO change organization to list |
|
95 |
repository.setOrganization( ((JSONArray)datasource.get("organizations")).getJSONObject(0).get("legalname").toString()); |
|
96 |
String countryCode = ((JSONArray)datasource.get("organizations")).getJSONObject(0).get("country").toString(); |
|
97 |
repository.setCountryCode(countryCode); |
|
98 |
|
|
70 | 99 |
return repository; |
71 | 100 |
} |
72 | 101 |
|
102 |
|
|
103 |
|
|
73 | 104 |
public static Date convertStringToDate(String date){ |
74 | 105 |
|
75 | 106 |
if(Objects.equals(date, "null")) |
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/PiWikApiImpl.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.controllers; |
|
2 |
|
|
3 |
import eu.dnetlib.domain.data.PiwikInfo; |
|
4 |
import eu.dnetlib.utils.md5.MD5; |
|
5 |
import org.springframework.beans.factory.annotation.Autowired; |
|
6 |
import org.springframework.beans.factory.annotation.Qualifier; |
|
7 |
import org.springframework.jdbc.core.JdbcTemplate; |
|
8 |
import org.springframework.jdbc.core.RowMapper; |
|
9 |
import org.springframework.stereotype.Component; |
|
10 |
import org.springframework.web.bind.annotation.PathVariable; |
|
11 |
|
|
12 |
import javax.annotation.PostConstruct; |
|
13 |
import javax.sql.DataSource; |
|
14 |
import java.security.NoSuchAlgorithmException; |
|
15 |
import java.sql.ResultSet; |
|
16 |
import java.sql.SQLException; |
|
17 |
import java.sql.Types; |
|
18 |
import java.util.List; |
|
19 |
|
|
20 |
@Component |
|
21 |
public class PiWikApiImpl implements PiWikApi{ |
|
22 |
|
|
23 |
@Autowired |
|
24 |
@Qualifier("repomanager.dataSource") |
|
25 |
private DataSource dataSource; |
|
26 |
|
|
27 |
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger |
|
28 |
.getLogger(PiWikApiImpl.class); |
|
29 |
|
|
30 |
private final static String GET_PIWIK_SITE = "select repositoryid, siteid, authenticationtoken, creationdate, requestorname, requestoremail, validated, validationdate, comment, repositoryname, country from piwik_site where repositoryid = ?;"; |
|
31 |
|
|
32 |
private final static String INSERT_PIWIK_INFO = "insert into piwik_site (repositoryid, siteid, creationdate, requestorname, requestoremail, validated, repositoryname, country, authenticationtoken) values (?, ?, now(), ?, ?, ?, ?, ?, ?)"; |
|
33 |
|
|
34 |
private final static String GET_PIWIK_SITES = "select repositoryid, siteid, authenticationtoken, creationdate, requestorname, requestoremail, validated, validationdate, comment, repositoryname, country from piwik_site order by repositoryname"; |
|
35 |
|
|
36 |
private final static String APPROVE_PIWIK_SITE = "update piwik_site set approved=true, approvaldate=now() where repositoryid = ?;"; |
|
37 |
|
|
38 |
|
|
39 |
private RowMapper<PiwikInfo> piwikRowMapper = (rs, i) -> new PiwikInfo(rs.getString("repositoryid"), getOpenaireId(rs.getString("repositoryid")), rs.getString("repositoryname"), rs.getString("country"), |
|
40 |
rs.getString("siteid"), rs.getString("authenticationtoken"), rs.getTimestamp("creationdate"), rs.getString("requestorname"), rs.getString("requestoremail"), |
|
41 |
rs.getBoolean("validated"), rs.getTimestamp("validationdate"), rs.getString("comment")); |
|
42 |
|
|
43 |
|
|
44 |
@Override |
|
45 |
public PiwikInfo getPiwikSiteForRepo(@PathVariable("repositoryId") String repositoryId) { |
|
46 |
return new JdbcTemplate(dataSource).queryForObject(GET_PIWIK_SITE, new String[]{repositoryId}, new int[]{Types.VARCHAR}, piwikRowMapper); |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
public PiwikInfo savePiwikInfo(PiwikInfo piwikInfo) { |
|
51 |
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); |
|
52 |
jdbcTemplate.update(INSERT_PIWIK_INFO, new Object[]{piwikInfo.getRepositoryId(), piwikInfo.getSiteId(), piwikInfo.getRequestorName(), |
|
53 |
piwikInfo.getRequestorEmail(), piwikInfo.isValidated(), piwikInfo.getRepositoryName(), piwikInfo.getCountry(), piwikInfo.getAuthenticationToken()}, |
|
54 |
new int[]{Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BOOLEAN, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR}); |
|
55 |
return piwikInfo; |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public List<PiwikInfo> getPiwikSitesForRepos() { |
|
60 |
LOGGER.debug("Getting piwik sites for repos! "); |
|
61 |
return new JdbcTemplate(dataSource).query(GET_PIWIK_SITES, piwikRowMapper); |
|
62 |
} |
|
63 |
|
|
64 |
@Override |
|
65 |
public void approvePiwikSite(@PathVariable("repositoryId") String repositoryId) { |
|
66 |
new JdbcTemplate(dataSource).update(APPROVE_PIWIK_SITE, new Object[] {repositoryId}, new int[] {Types.VARCHAR}); |
|
67 |
} |
|
68 |
|
|
69 |
@Override |
|
70 |
public String getOpenaireId(@PathVariable("repositoryId") String repositoryid) { |
|
71 |
try { |
|
72 |
if (repositoryid != null && repositoryid.contains("::")) |
|
73 |
return repositoryid.split("::")[0] + "::" + MD5.encrypt2Hex(repositoryid.split("::")[1]); |
|
74 |
else |
|
75 |
return null; |
|
76 |
} catch (NoSuchAlgorithmException e) { |
|
77 |
e.printStackTrace(); |
|
78 |
} |
|
79 |
return null; |
|
80 |
} |
|
81 |
|
|
82 |
|
|
83 |
} |
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApiImpl.java | ||
---|---|---|
165 | 165 |
|
166 | 166 |
private List<Repository> getRepositoriesOfUser(String userEmail) throws JSONException { |
167 | 167 |
|
168 |
int page = 1;
|
|
169 |
int size = 10;
|
|
168 |
int page = 0;
|
|
169 |
int size = 50;
|
|
170 | 170 |
List<Repository> rs = null; |
171 | 171 |
List<Repository> resultSet = new ArrayList<>(); |
172 | 172 |
|
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApi.java | ||
---|---|---|
24 | 24 |
@ResponseBody |
25 | 25 |
Country[] getCountries() ; |
26 | 26 |
|
27 |
@RequestMapping(value = "/getRepositoriesByCountry/{country}", method = RequestMethod.GET, |
|
27 |
@RequestMapping(value = "/getRepositoriesByCountry/{country}/{mode}", method = RequestMethod.GET,
|
|
28 | 28 |
produces = MediaType.APPLICATION_JSON_VALUE) |
29 | 29 |
@ResponseBody |
30 | 30 |
List<Repository> getRepositoriesByCountry(String country,String mode) throws JSONException; |
... | ... | |
62 | 62 |
@RequestMapping(value = "/addRepository", method = RequestMethod.POST, |
63 | 63 |
consumes = MediaType.APPLICATION_JSON_VALUE) |
64 | 64 |
@ResponseBody |
65 |
String addRepository(Repository repository) throws JSONException;
|
|
65 |
void addRepository(Repository repository) throws JSONException;
|
|
66 | 66 |
|
67 | 67 |
@RequestMapping(value = "/deleteInterface", method = RequestMethod.DELETE) |
68 | 68 |
@ResponseBody |
... | ... | |
113 | 113 |
@ResponseBody |
114 | 114 |
String updateOfficialName(String id, String officialName); |
115 | 115 |
|
116 |
@RequestMapping(value = "/updateTimezone", method = RequestMethod.POST, |
|
117 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
118 |
@ResponseBody |
|
119 |
String updateTimezone(String id, String timezone); |
|
120 |
|
|
121 |
@RequestMapping(value = "/updateTypology", method = RequestMethod.POST, |
|
122 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
123 |
@ResponseBody |
|
124 |
String updateTypology(String id, String typology); |
|
125 |
|
|
126 |
@RequestMapping(value = "/updateTypology", method = RequestMethod.POST, |
|
127 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
128 |
@ResponseBody |
|
129 |
String updateLogoUrl(String id, String logoUrl); |
|
130 |
|
|
131 |
|
|
116 | 132 |
@RequestMapping(value = "/getUrlsOfUserRepos/{user_email}/{page}/{size}/",method = RequestMethod.GET, |
117 | 133 |
produces = MediaType.APPLICATION_JSON_VALUE) |
118 | 134 |
@ResponseBody |
... | ... | |
136 | 152 |
Map<String, String> getDatasourceClasses(String mode); |
137 | 153 |
|
138 | 154 |
|
139 |
|
|
155 |
String getCountryName(String countryCode); |
|
140 | 156 |
} |
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApiImpl.java | ||
---|---|---|
41 | 41 |
|
42 | 42 |
private Map<String, Vocabulary> vocabularyMap = new ConcurrentHashMap<String, Vocabulary>(); |
43 | 43 |
|
44 |
private Map<String,String> countriesMap = new HashMap<>(); |
|
45 |
private Map<String,String> inverseCountriesMap = new HashMap<>(); |
|
44 | 46 |
|
47 |
|
|
45 | 48 |
@PostConstruct |
46 | 49 |
private void init(){ |
47 | 50 |
LOGGER.debug("Initialization method of repository api!"); |
... | ... | |
53 | 56 |
vocabularyMap.put(vocName, vocabularyLoader.getVocabulary(vocName, Locale.ENGLISH, Locale.ROOT)); |
54 | 57 |
} |
55 | 58 |
|
59 |
Country[] countries = getCountries(); |
|
60 |
for(Country c: countries){ |
|
61 |
countriesMap.put(c.getName(),c.getCode()); |
|
62 |
inverseCountriesMap.put(c.getCode(),c.getName()); |
|
63 |
} |
|
64 |
|
|
65 |
|
|
56 | 66 |
} |
57 | 67 |
|
58 | 68 |
@Override |
... | ... | |
109 | 119 |
|
110 | 120 |
@Override |
111 | 121 |
public List<Repository> getRepositoriesByCountry(@PathVariable("country") String country, |
112 |
@PathVariable("country") String mode) throws JSONException {
|
|
122 |
@PathVariable("mode") String mode) throws JSONException {
|
|
113 | 123 |
|
114 | 124 |
LOGGER.debug("Getting repositories by country!"); |
115 |
int page = 1; |
|
116 |
int size = 10; |
|
117 |
String countryCode = getCountryCode(country); |
|
125 |
int page = 0; |
|
126 |
int size = 100; |
|
127 |
|
|
128 |
String countryCode = countriesMap.get(country); |
|
118 | 129 |
String filterKey = "UNKNOWN"; |
119 | 130 |
if(mode.equalsIgnoreCase("opendoar")) { |
120 | 131 |
filterKey = "openaire____::opendoar"; |
... | ... | |
138 | 149 |
List<Repository> rep = Converter.jsonToRepositoryList(new JSONArray(rs)); |
139 | 150 |
|
140 | 151 |
Collection<Repository> repos = this.getRepositoriesByMode(filterKey,rep); |
141 |
this.addRepos(resultSet,repos); |
|
142 |
//resultSet.addAll(repos); |
|
152 |
resultSet.addAll(repos); |
|
143 | 153 |
|
144 | 154 |
page+=1; |
145 | 155 |
uriComponents = UriComponentsBuilder |
... | ... | |
149 | 159 |
.build().expand(page,size).encode(); |
150 | 160 |
rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
151 | 161 |
} |
162 |
for(Repository r : resultSet) |
|
163 |
r.setCountryName(getCountryName(r.getCountryCode())); |
|
152 | 164 |
return resultSet; |
153 | 165 |
} |
154 | 166 |
|
155 |
private String getCountryCode(String country) { |
|
156 | 167 |
|
157 |
Country[] countries = getCountries(); |
|
158 |
for(Country c : countries) |
|
159 |
if(c.getName().equals(country)) |
|
160 |
return c.getCode(); |
|
161 |
return country; |
|
162 |
} |
|
163 |
|
|
164 |
private void addRepos(List<Repository> resultSet, Collection<Repository> repos) { |
|
165 |
for(Repository r : repos) |
|
166 |
if(!resultSet.contains(r)) |
|
167 |
resultSet.add(r); |
|
168 |
} |
|
169 |
|
|
170 | 168 |
private Collection<Repository> getRepositoriesByMode(String mode, List<Repository> rs) { |
171 | 169 |
|
172 | 170 |
List<Repository> reps = new ArrayList<>(); |
... | ... | |
190 | 188 |
.build().expand(page,size).encode(); |
191 | 189 |
|
192 | 190 |
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
193 |
return Converter.jsonToRepositoryList(new JSONArray(rs)); |
|
191 |
List<Repository> repos = Converter.jsonToRepositoryList(new JSONArray(rs)); |
|
192 |
for(Repository r : repos) |
|
193 |
r.setCountryName(getCountryName(r.getCountryCode())); |
|
194 |
return repos; |
|
194 | 195 |
} |
195 | 196 |
|
196 | 197 |
@Override |
... | ... | |
202 | 203 |
.build().expand(id).encode(); |
203 | 204 |
|
204 | 205 |
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
205 |
return Converter.jsonToRepositoryObject(new JSONObject(rs)); |
|
206 |
Repository repo = Converter.jsonToRepositoryObject(new JSONObject(rs)); |
|
207 |
if (repo != null) |
|
208 |
repo.setCountryName(getCountryName(repo.getCountryCode())); |
|
209 |
return repo; |
|
206 | 210 |
} |
207 | 211 |
|
208 | 212 |
@Override |
... | ... | |
235 | 239 |
.build().expand(page,size).encode(); |
236 | 240 |
|
237 | 241 |
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
238 |
return Converter.jsonToRepositoryList(new JSONArray(rs)); |
|
242 |
List<Repository> repos = Converter.jsonToRepositoryList(new JSONArray(rs)); |
|
243 |
for(Repository r : repos) |
|
244 |
r.setCountryName(getCountryName(r.getCountryCode())); |
|
245 |
return repos; |
|
239 | 246 |
} |
240 | 247 |
|
241 | 248 |
@Override |
... | ... | |
251 | 258 |
} |
252 | 259 |
|
253 | 260 |
@Override |
254 |
public String addRepository(@RequestBody Repository repository) throws JSONException { |
|
261 |
public void addRepository(@RequestBody Repository repository) throws JSONException { |
|
262 |
|
|
263 |
LOGGER.debug("Adding repository with name : " + repository.getOfficialName()); |
|
264 |
|
|
255 | 265 |
UriComponents uriComponents = UriComponentsBuilder |
256 | 266 |
.fromHttpUrl(baseAddress + "/ds/add/") |
257 | 267 |
.build() |
258 | 268 |
.encode(); |
259 |
return restTemplate.postForObject(uriComponents.toUri(),Converter.repositoryObjectToJson(repository),String.class); |
|
269 |
|
|
270 |
LOGGER.debug("Repository equals : " + Converter.repositoryObjectToJson(repository)); |
|
271 |
restTemplate.postForObject(uriComponents.toUri(),Converter.repositoryObjectToJson(repository),String.class); |
|
260 | 272 |
} |
261 | 273 |
|
262 | 274 |
@Override |
... | ... | |
360 | 372 |
} |
361 | 373 |
|
362 | 374 |
@Override |
375 |
public String updateTimezone(@RequestParam(value = "id") String id, |
|
376 |
@RequestParam(value = "timezone") String timezone) { |
|
377 |
UriComponents uriComponents = UriComponentsBuilder |
|
378 |
.fromHttpUrl(baseAddress + "/ds/update/timezone") |
|
379 |
.queryParam("dsId",id) |
|
380 |
.queryParam("timezone",timezone) |
|
381 |
.build().encode(); |
|
382 |
return restTemplate.postForObject(uriComponents.toUri(), null,String.class); |
|
383 |
} |
|
384 |
|
|
385 |
@Override |
|
386 |
public String updateTypology(@RequestParam(value = "id") String id, |
|
387 |
@RequestParam(value = "typology") String typology) { |
|
388 |
UriComponents uriComponents = UriComponentsBuilder |
|
389 |
.fromHttpUrl(baseAddress + "/ds/update/typology") |
|
390 |
.queryParam("dsId",id) |
|
391 |
.queryParam("typology",typology) |
|
392 |
.build().encode(); |
|
393 |
return restTemplate.postForObject(uriComponents.toUri(), null,String.class); |
|
394 |
} |
|
395 |
|
|
396 |
@Override |
|
397 |
public String updateLogoUrl(@RequestParam(value = "id") String id, |
|
398 |
@RequestParam(value = "logoUrl") String logoUrl) { |
|
399 |
UriComponents uriComponents = UriComponentsBuilder |
|
400 |
.fromHttpUrl(baseAddress + "/ds/update/logourl") |
|
401 |
.queryParam("dsId",id) |
|
402 |
.queryParam("logourl",logoUrl) |
|
403 |
.build().encode(); |
|
404 |
return restTemplate.postForObject(uriComponents.toUri(), null,String.class); |
|
405 |
} |
|
406 |
|
|
407 |
@Override |
|
363 | 408 |
public List<String> getUrlsOfUserRepos(@PathVariable("user_email") String user_email, |
364 | 409 |
@PathVariable("page") String page, |
365 | 410 |
@PathVariable("size") String size) throws JSONException { |
... | ... | |
459 | 504 |
|
460 | 505 |
} |
461 | 506 |
|
507 |
@Override |
|
508 |
public String getCountryName(String countryCode) { |
|
509 |
return inverseCountriesMap.get(countryCode); |
|
510 |
} |
|
511 |
|
|
462 | 512 |
} |
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/PiWikApi.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.service.controllers; |
|
2 |
|
|
3 |
|
|
4 |
import eu.dnetlib.domain.data.PiwikInfo; |
|
5 |
import org.springframework.http.MediaType; |
|
6 |
import org.springframework.web.bind.annotation.*; |
|
7 |
|
|
8 |
import java.util.List; |
|
9 |
|
|
10 |
@RestController |
|
11 |
@RequestMapping(value = "/piwi") |
|
12 |
public interface PiWikApi { |
|
13 |
|
|
14 |
|
|
15 |
@RequestMapping(value = "/getPiwikSiteForRepo/{repositoryId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) |
|
16 |
@ResponseBody |
|
17 |
PiwikInfo getPiwikSiteForRepo(String repositoryId); |
|
18 |
|
|
19 |
@RequestMapping(value = "/savePiwikInfo" , method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE) |
|
20 |
PiwikInfo savePiwikInfo(@RequestBody PiwikInfo piwikInfo); |
|
21 |
|
|
22 |
@RequestMapping(value = "/getPiwikSitesForRepos" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) |
|
23 |
List<PiwikInfo> getPiwikSitesForRepos(); |
|
24 |
|
|
25 |
@RequestMapping(value = "/approvePiwikSite/{repositoryId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) |
|
26 |
@ResponseBody |
|
27 |
void approvePiwikSite(String repositoryId); |
|
28 |
|
|
29 |
@RequestMapping(value = "/getOpenaireId/{repositoryid}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) |
|
30 |
@ResponseBody |
|
31 |
String getOpenaireId(String repositoryid); |
|
32 |
} |
modules/uoa-repository-manager-service/src/main/resources/application-context.xml | ||
---|---|---|
2 | 2 |
<beans xmlns="http://www.springframework.org/schema/beans" |
3 | 3 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" |
4 | 4 |
xmlns:context="http://www.springframework.org/schema/context" |
5 |
xmlns:task="http://www.springframework.org/schema/task" |
|
5 |
xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx"
|
|
6 | 6 |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd |
7 |
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> |
|
7 |
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
|
|
8 | 8 |
|
9 |
<import resource="classpath:META-INF/cxf/cxf.xml"/> |
|
10 |
<!-- <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>--> |
|
11 |
<import resource="classpath:META-INF/cxf/cxf-extension-jaxws.xml"/> |
|
12 |
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/> |
|
13 |
<import resource="classpath*:/cxf.xml"/> |
|
14 |
<import resource="classpath*:/eu/dnetlib/repos/ehcacher/springContext-repos-ehcacher.xml"/> |
|
15 |
<import resource="classpath*:/eu/dnetlib/soap/cxf/applicationContext-eprbuilders.xml"/> |
|
16 |
<import resource="classpath*:/eu/dnetlib/clients/ws/springContext-locatorFactory.xml"/> |
|
17 |
<import resource="classpath*:/eu/dnetlib/users/springContext-users-ldap.xml"/> |
|
18 |
<import resource="classpath*:/gr/uoa/di/driver/util/springContext-locators.xml"/> |
|
19 |
<import resource="classpath*:/gr/uoa/di/driver/app/springContext-lookupFactory.xml"/> |
|
20 |
<import resource="classpath*:/gr/uoa/di/driver/app/springContext-lookupClients.xml"/> |
|
21 |
<import resource="classpath*:/eu/dnetlib/enabling/hcm/springContext-hcmService.xml"/> |
|
22 |
<import resource="classpath*:/gr/uoa/di/driver/app/springContext-commons.xml"/> |
|
23 |
<import resource="classpath*:/gr/uoa/di/driver/app/springContext-registrator.xml"/> |
|
24 |
<import resource="classpath*:/eu/dnetlib/repos/springContext-repos-dms-cached.xml"/> |
|
9 | 25 |
|
26 |
<context:property-placeholder location="classpath*:/eu/**/application.properties" /> |
|
27 |
<tx:annotation-driven transaction-manager="txManager"/> |
|
28 |
|
|
29 |
<bean class="eu.dnetlib.repo.manager.service.config.CascadingPropertyLoader" id="propertyLoader"> |
|
30 |
<property name="order" value="2" /> |
|
31 |
<property name="properties"> |
|
32 |
<bean class="eu.dnetlib.conf.WebappContextProperyFactory"> |
|
33 |
<property name="propertyFetcher"> |
|
34 |
<bean class="eu.dnetlib.conf.PropertyFetcher" /> |
|
35 |
</property> |
|
36 |
</bean> |
|
37 |
</property> |
|
38 |
<property name="ignoreUnresolvablePlaceholders" value="true" /> |
|
39 |
<property name="locations"> |
|
40 |
<list> |
|
41 |
<value>classpath*:/gr/**/springContext-*.properties</value> |
|
42 |
<value>classpath*:/eu/**/springContext-*.properties</value> |
|
43 |
|
|
44 |
<value>classpath*:/eu/dnetlib/repo/manager/service/email-texts.properties</value> |
|
45 |
|
|
46 |
<value>classpath*:dnet-site-wizard.properties</value> |
|
47 |
<value>classpath*:dnet-site-override.properties</value> |
|
48 |
<value>classpath*:dnet-wizard.properties</value> |
|
49 |
<value>classpath*:dnet-override.properties</value> |
|
50 |
<value>classpath*:dnet-validator-wizard.properties</value> |
|
51 |
<value>classpath*:dnet-validator-override.properties</value> |
|
52 |
<value>classpath*:dnet-site-force-override.properties</value> |
|
53 |
<value>classpath*:dnet-force-override.properties</value> |
|
54 |
</list> |
|
55 |
</property> |
|
56 |
</bean> |
|
57 |
|
|
10 | 58 |
<bean id="repomanager.dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> |
11 | 59 |
<property name="driverClassName" value="${repomanager.db.driverClassName}" /> |
12 | 60 |
<property name="url" value="${repomanager.db.url}" /> |
... | ... | |
26 | 74 |
<property name="defaultAutoCommit" value="true" /> |
27 | 75 |
</bean> |
28 | 76 |
|
29 |
<context:property-placeholder location="classpath*:/eu/**/application.properties" /> |
|
77 |
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> |
|
78 |
<property name="dataSource" ref="repomanager.dataSource"/> |
|
79 |
</bean> |
|
30 | 80 |
|
81 |
|
|
31 | 82 |
</beans> |
modules/uoa-repository-manager-service/src/main/webapp/WEB-INF/applicationContext.xml | ||
---|---|---|
1 | 1 |
<?xml version="1.0" encoding="UTF-8"?> |
2 | 2 |
<beans xmlns="http://www.springframework.org/schema/beans" |
3 | 3 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
4 |
xmlns:context="http://www.springframework.org/schema/context" |
|
5 |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> |
|
4 |
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
|
|
5 |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
|
|
6 | 6 |
|
7 | 7 |
<import resource="classpath*:/application-context.xml"/> |
8 | 8 |
|
... | ... | |
25 | 25 |
|
26 | 26 |
<import resource="classpath*:/eu/dnetlib/repos/springContext-repos-dms-cached.xml"/> |
27 | 27 |
|
28 |
|
|
29 | 28 |
<context:property-placeholder location="classpath*:/eu/**/application.properties" /> |
30 | 29 |
|
31 | 30 |
<bean class="eu.dnetlib.repo.manager.service.config.CascadingPropertyLoader" id="propertyLoader"> |
... | ... | |
57 | 56 |
</property> |
58 | 57 |
</bean> |
59 | 58 |
|
59 |
<bean id="repomanager.dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> |
|
60 |
<property name="driverClassName" value="${repomanager.db.driverClassName}" /> |
|
61 |
<property name="url" value="${repomanager.db.url}" /> |
|
62 |
<property name="username" value="${repomanager.db.username}" /> |
|
63 |
<property name="password" value="${repomanager.db.password}" /> |
|
64 |
<property name="maxIdle" value="10" /> |
|
65 |
<property name="maxActive" value="100" /> |
|
66 |
<property name="maxWait" value="10000" /> |
|
67 |
<property name="validationQuery" value="SELECT 1;" /> |
|
68 |
<property name="testOnBorrow" value="true" /> |
|
69 |
<property name="testOnReturn" value="true" /> |
|
70 |
<property name="testWhileIdle" value="true" /> |
|
71 |
<property name="timeBetweenEvictionRunsMillis" value="1200000" /> |
|
72 |
<property name="minEvictableIdleTimeMillis" value="1800000" /> |
|
73 |
<property name="numTestsPerEvictionRun" value="5" /> |
|
74 |
<property name="poolPreparedStatements" value="true" /> |
|
75 |
<property name="defaultAutoCommit" value="true" /> |
|
76 |
</bean> |
|
77 |
|
|
78 |
<tx:annotation-driven transaction-manager="txManager"/> |
|
79 |
|
|
80 |
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> |
|
81 |
<property name="dataSource" ref="repomanager.dataSource"/> |
|
82 |
</bean> |
|
83 |
|
|
60 | 84 |
</beans> |
Also available in: Unified diff
1. Create new update methods for repository api
2. Rename piwik file.
3. Create bean repomanager.datasource
4. Update converter methods ( typology, datasourceClass )