Project

General

Profile

« Previous | Next » 

Revision 50861

1.Moving trunk folder to new branch.

View differences:

modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/shared/broker/Provenance.java
1
package eu.dnetlib.repo.manager.shared.broker;
2

  
3
import com.google.gwt.user.client.rpc.IsSerializable;
4

  
5
/**
6
 * Created by claudio on 26/07/16.
7
 */
8
public class Provenance implements IsSerializable {
9

  
10
    private String repositoryName;
11

  
12
    private String url;
13

  
14
    private String id;
15

  
16
    public Provenance() {
17
    }
18

  
19
    public String getRepositoryName() {
20
        return repositoryName;
21
    }
22

  
23
    public void setRepositoryName(String repositoryName) {
24
        this.repositoryName = repositoryName;
25
    }
26

  
27
    public String getUrl() {
28
        return url;
29
    }
30

  
31
    public void setUrl(String url) {
32
        this.url = url;
33
    }
34

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

  
39
    public void setId(String id) {
40
        this.id = id;
41
    }
42
}
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/shared/broker/EventsPage.java
1
package eu.dnetlib.repo.manager.shared.broker;
2

  
3
import com.google.gwt.user.client.rpc.IsSerializable;
4

  
5

  
6
import java.util.List;
7

  
8
/**
9
 * Created by stefanos on 26/10/2016.
10
 */
11
public class EventsPage implements IsSerializable{
12

  
13
    private String datasource;
14
    private String topic;
15
    private long currPage;
16
    private long totalPages;
17
    private long total;
18
    private List<OpenAireEventPayload> values;
19

  
20
    public EventsPage() {
21

  
22
    }
23
    public EventsPage(final String datasource, final String topic, final long currPage, final long totalPages, final long total,
24
                      final List<OpenAireEventPayload> values) {
25
        this.datasource = datasource;
26
        this.topic = topic;
27
        this.currPage = currPage;
28
        this.totalPages = totalPages;
29
        this.total = total;
30
        this.values = values;
31
    }
32

  
33
    public String getDatasource() {
34
        return datasource;
35
    }
36

  
37
    public void setDatasource(String datasource) {
38
        this.datasource = datasource;
39
    }
40

  
41
    public String getTopic() {
42
        return topic;
43
    }
44

  
45
    public void setTopic(String topic) {
46
        this.topic = topic;
47
    }
48

  
49
    public long getCurrPage() {
50
        return currPage;
51
    }
52

  
53
    public void setCurrPage(long currPage) {
54
        this.currPage = currPage;
55
    }
56

  
57
    public long getTotalPages() {
58
        return totalPages;
59
    }
60

  
61
    public void setTotalPages(long totalPages) {
62
        this.totalPages = totalPages;
63
    }
64

  
65
    public long getTotal() {
66
        return total;
67
    }
68

  
69
    public void setTotal(long total) {
70
        this.total = total;
71
    }
72

  
73
    public List<OpenAireEventPayload> getValues() {
74
        return values;
75
    }
76

  
77
    public void setValues(List<OpenAireEventPayload> values) {
78
        this.values = values;
79
    }
80
}
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/shared/broker/Instance.java
1
package eu.dnetlib.repo.manager.shared.broker;
2

  
3
import com.google.gwt.user.client.rpc.IsSerializable;
4

  
5
/**
6
 * Created by claudio on 22/07/16.
7
 */
8
public class Instance implements IsSerializable {
9

  
10
    private String url;
11

  
12
    private String license;
13

  
14
    private String hostedby;
15

  
16
    private String instancetype;
17

  
18
    public Instance() {
19
    }
20

  
21
    public String getUrl() {
22
        return url;
23
    }
24

  
25
    public void setUrl(String url) {
26
        this.url = url;
27
    }
28

  
29
    public String getLicense() {
30
        return license;
31
    }
32

  
33
    public void setLicense(String license) {
34
        this.license = license;
35
    }
36

  
37
    public String getHostedby() {
38
        return hostedby;
39
    }
40

  
41
    public void setHostedby(String hostedby) {
42
        this.hostedby = hostedby;
43
    }
44

  
45
    public String getInstancetype() {
46
        return instancetype;
47
    }
48

  
49
    public void setInstancetype(String instancetype) {
50
        this.instancetype = instancetype;
51
    }
52
}
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/shared/broker/MapConditions.java
1
package eu.dnetlib.repo.manager.shared.broker;
2

  
3
import com.google.gwt.user.client.rpc.IsSerializable;
4

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

  
8
/**
9
 * Created by stefanos on 17/3/2017.
10
 */
11
public class MapConditions implements IsSerializable {
12

  
13
    private String field;
14
    private MapValueType fieldType;
15
    private ConditionOperator operator;
16
    private List<ConditionParams> listParams = new ArrayList<>();
17

  
18
    public MapConditions() {
19
    }
20

  
21
    public String getField() {
22
        return field;
23
    }
24

  
25
    public void setField(String field) {
26
        this.field = field;
27
    }
28

  
29
    public MapValueType getFieldType() {
30
        return fieldType;
31
    }
32

  
33
    public void setFieldType(MapValueType fieldType) {
34
        this.fieldType = fieldType;
35
    }
36

  
37
    public ConditionOperator getOperator() {
38
        return operator;
39
    }
40

  
41
    public void setOperator(ConditionOperator operator) {
42
        this.operator = operator;
43
    }
44

  
45
    public List<ConditionParams> getListParams() {
46
        return listParams;
47
    }
48

  
49
    public void setListParams(List<ConditionParams> listParams) {
50
        this.listParams = listParams;
51
    }
52
}
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/shared/broker/Journal.java
1
package eu.dnetlib.repo.manager.shared.broker;
2

  
3
import com.google.gwt.user.client.rpc.IsSerializable;
4

  
5
/**
6
 * Created by claudio on 22/07/16.
7
 */
8
public class Journal implements IsSerializable {
9

  
10
    private String name;
11

  
12
    private String issn;
13

  
14
    private String eissn;
15

  
16
    private String lissn;
17

  
18
    public Journal() {
19
    }
20

  
21
    public String getName() {
22
        return name;
23
    }
24

  
25
    public void setName(String name) {
26
        this.name = name;
27
    }
28

  
29
    public String getIssn() {
30
        return issn;
31
    }
32

  
33
    public void setIssn(String issn) {
34
        this.issn = issn;
35
    }
36

  
37
    public String getEissn() {
38
        return eissn;
39
    }
40

  
41
    public void setEissn(String eissn) {
42
        this.eissn = eissn;
43
    }
44

  
45
    public String getLissn() {
46
        return lissn;
47
    }
48

  
49
    public void setLissn(String lissn) {
50
        this.lissn = lissn;
51
    }
52
}
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/shared/broker/Publication.java
1
package eu.dnetlib.repo.manager.shared.broker;
2

  
3
import com.google.gwt.user.client.rpc.IsSerializable;
4

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

  
8
/**
9
 * Created by claudio on 22/07/16.
10
 */
11
public class Publication implements IsSerializable {
12

  
13
    private String originalId;
14

  
15
    private List<String> titles = new ArrayList<>();
16

  
17
    private List<String> abstracts = new ArrayList<>();
18

  
19
    private String language;
20

  
21
    private List<String> subjects = new ArrayList<>();
22

  
23
    private List<String> creators = new ArrayList<>();
24

  
25
    private String publicationdate;
26

  
27
    private String publisher;
28

  
29
    private String embargoenddate;
30

  
31
    private List<String> contributor = new ArrayList<>();
32

  
33
    private Journal journal;
34

  
35
    private List<String> collectedFrom = new ArrayList<>();
36

  
37
    private List<Pid> pids = new ArrayList<>();
38

  
39
    private List<Instance> instances = new ArrayList<>();
40

  
41
    private List<ExternalReference> externalReferences = new ArrayList<>();
42

  
43
    private List<Project> projects = new ArrayList<>();
44

  
45
    private List<Dataset> datasets = new ArrayList<>();
46

  
47
    public Publication() {
48
    }
49

  
50
    public String getOriginalId() {
51
        return originalId;
52
    }
53

  
54
    public void setOriginalId(String originalId) {
55
        this.originalId = originalId;
56
    }
57

  
58
    public List<String> getTitles() {
59
        return titles;
60
    }
61

  
62
    public void setTitles(List<String> titles) {
63
        this.titles = titles;
64
    }
65

  
66
    public List<String> getAbstracts() {
67
        return abstracts;
68
    }
69

  
70
    public void setAbstracts(List<String> abstracts) {
71
        this.abstracts = abstracts;
72
    }
73

  
74
    public String getLanguage() {
75
        return language;
76
    }
77

  
78
    public void setLanguage(String language) {
79
        this.language = language;
80
    }
81

  
82
    public List<String> getSubjects() {
83
        return subjects;
84
    }
85

  
86
    public void setSubjects(List<String> subjects) {
87
        this.subjects = subjects;
88
    }
89

  
90
    public List<String> getCreators() {
91
        return creators;
92
    }
93

  
94
    public void setCreators(List<String> creators) {
95
        this.creators = creators;
96
    }
97

  
98
    public String getPublicationdate() {
99
        return publicationdate;
100
    }
101

  
102
    public void setPublicationdate(String publicationdate) {
103
        this.publicationdate = publicationdate;
104
    }
105

  
106
    public String getPublisher() {
107
        return publisher;
108
    }
109

  
110
    public void setPublisher(String publisher) {
111
        this.publisher = publisher;
112
    }
113

  
114
    public String getEmbargoenddate() {
115
        return embargoenddate;
116
    }
117

  
118
    public void setEmbargoenddate(String embargoenddate) {
119
        this.embargoenddate = embargoenddate;
120
    }
121

  
122
    public List<String> getContributor() {
123
        return contributor;
124
    }
125

  
126
    public void setContributor(List<String> contributor) {
127
        this.contributor = contributor;
128
    }
129

  
130
    public Journal getJournal() {
131
        return journal;
132
    }
133

  
134
    public void setJournal(Journal journal) {
135
        this.journal = journal;
136
    }
137

  
138
    public List<String> getCollectedFrom() {
139
        return collectedFrom;
140
    }
141

  
142
    public void setCollectedFrom(List<String> collectedFrom) {
143
        this.collectedFrom = collectedFrom;
144
    }
145

  
146
    public List<Pid> getPids() {
147
        return pids;
148
    }
149

  
150
    public void setPids(List<Pid> pids) {
151
        this.pids = pids;
152
    }
153

  
154
    public List<Instance> getInstances() {
155
        return instances;
156
    }
157

  
158
    public void setInstances(List<Instance> instances) {
159
        this.instances = instances;
160
    }
161

  
162
    public List<ExternalReference> getExternalReferences() {
163
        return externalReferences;
164
    }
165

  
166
    public void setExternalReferences(List<ExternalReference> externalReferences) {
167
        this.externalReferences = externalReferences;
168
    }
169

  
170
    public List<Project> getProjects() {
171
        return projects;
172
    }
173

  
174
    public void setProjects(List<Project> projects) {
175
        this.projects = projects;
176
    }
177

  
178
    public List<Dataset> getDatasets() {
179
        return datasets;
180
    }
181

  
182
    public void setDatasets(List<Dataset> datasets) {
183
        this.datasets = datasets;
184
    }
185
}
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/shared/broker/OpenAireEventPayload.java
1
package eu.dnetlib.repo.manager.shared.broker;
2

  
3
import com.google.gwt.user.client.rpc.IsSerializable;
4

  
5
/**
6
 * Created by claudio on 11/07/16.
7
 */
8
public class OpenAireEventPayload implements IsSerializable {
9

  
10
    private Publication publication;
11

  
12
    private Publication highlight;
13

  
14
    private Provenance provenance;
15

  
16
    private float trust;
17

  
18
    public OpenAireEventPayload() {
19
    }
20

  
21
    public Publication getPublication() {
22
        return publication;
23
    }
24

  
25
    public void setPublication(Publication publication) {
26
        this.publication = publication;
27
    }
28

  
29
    public Publication getHighlight() {
30
        return highlight;
31
    }
32

  
33
    public void setHighlight(Publication highlight) {
34
        this.highlight = highlight;
35
    }
36

  
37
    public Provenance getProvenance() {
38
        return provenance;
39
    }
40

  
41
    public void setProvenance(Provenance provenance) {
42
        this.provenance = provenance;
43
    }
44

  
45
    public float getTrust() {
46
        return trust;
47
    }
48

  
49
    public void setTrust(float trust) {
50
        this.trust = trust;
51
    }
52
}
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/shared/broker/Pid.java
1
package eu.dnetlib.repo.manager.shared.broker;
2

  
3
import com.google.gwt.user.client.rpc.IsSerializable;
4

  
5
/**
6
 * Created by claudio on 22/07/16.
7
 */
8
public class Pid implements IsSerializable {
9

  
10
    private String value;
11

  
12
    private String type;
13

  
14
    public Pid() {
15
    }
16

  
17
    public String getValue() {
18
        return value;
19
    }
20

  
21
    public void setValue(String value) {
22
        this.value = value;
23
    }
24

  
25
    public String getType() {
26
        return type;
27
    }
28

  
29
    public void setType(String type) {
30
        this.type = type;
31
    }
32
}
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/shared/broker/Dataset.java
1
package eu.dnetlib.repo.manager.shared.broker;
2

  
3
import com.google.gwt.user.client.rpc.IsSerializable;
4

  
5
import java.util.List;
6

  
7
public class Dataset implements IsSerializable {
8

  
9
    private List<String> titles;
10

  
11
    private List<String> collectedFrom;
12

  
13
    private List<Pid> pids;
14

  
15
    private List<Instance> instances;
16

  
17
    public Dataset() {
18
    }
19

  
20
    public Dataset(final List<String> titles, final List<String> collectedFrom, final List<Pid> pids, final List<Instance> instances) {
21
        this.titles = titles;
22
        this.collectedFrom = collectedFrom;
23
        this.pids = pids;
24
        this.instances = instances;
25
    }
26

  
27
    public List<String> getTitles() {
28
        return titles;
29
    }
30

  
31
    public void setTitles(List<String> titles) {
32
        this.titles = titles;
33
    }
34

  
35
    public List<String> getCollectedFrom() {
36
        return collectedFrom;
37
    }
38

  
39
    public void setCollectedFrom(List<String> collectedFrom) {
40
        this.collectedFrom = collectedFrom;
41
    }
42

  
43
    public List<Pid> getPids() {
44
        return pids;
45
    }
46

  
47
    public void setPids(List<Pid> pids) {
48
        this.pids = pids;
49
    }
50

  
51
    public List<Instance> getInstances() {
52
        return instances;
53
    }
54

  
55
    public void setInstances(List<Instance> instances) {
56
        this.instances = instances;
57
    }
58
}
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/shared/broker/NotificationMode.java
1
package eu.dnetlib.repo.manager.shared.broker;
2

  
3
import com.google.gwt.user.client.rpc.IsSerializable;
4

  
5
/**
6
 * Created by stefanos on 10-Mar-17.
7
 */
8
public enum NotificationMode implements IsSerializable {
9
    MOCK, EMAIL
10
}
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/shared/MetricsNumbers.java
1
package eu.dnetlib.repo.manager.shared;
2

  
3
import com.fasterxml.jackson.annotation.JsonProperty;
4
import com.google.gwt.user.client.rpc.IsSerializable;
5

  
6
import java.util.List;
7

  
8
/**
9
 * Created by stefania on 11/7/17.
10
 */
11
public class MetricsNumbers implements IsSerializable {
12

  
13
    private List<String> downloads;
14
    private List<String> views;
15

  
16
    @JsonProperty("total_downloads")
17
    private String totalDownloads;
18

  
19
    @JsonProperty("total_views")
20
    private String totalViews;
21

  
22
    @JsonProperty("total_openaire_downloads")
23
    private String totalOpenAIREDownloads;
24

  
25
    @JsonProperty("total_openaire_views")
26
    private String totalOpenAIREViews;
27

  
28
    @JsonProperty("pageviews")
29
    private String pageViews;
30

  
31
    public MetricsNumbers() {
32
    }
33

  
34
    public MetricsNumbers(List<String> downloads, List<String> views, String totalDownloads, String totalViews,
35
                          String totalOpenAIREDownloads, String totalOpenAIREViews, String pageViews) {
36
        this.downloads = downloads;
37
        this.views = views;
38
        this.totalDownloads = totalDownloads;
39
        this.totalViews = totalViews;
40
        this.totalOpenAIREDownloads = totalOpenAIREDownloads;
41
        this.totalOpenAIREViews = totalOpenAIREViews;
42
        this.pageViews = pageViews;
43
    }
44

  
45
    public List<String> getDownloads() {
46
        return downloads;
47
    }
48

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

  
53
    public List<String> getViews() {
54
        return views;
55
    }
56

  
57
    public void setViews(List<String> views) {
58
        this.views = views;
59
    }
60

  
61
    public String getTotalDownloads() {
62
        return totalDownloads;
63
    }
64

  
65
    public void setTotalDownloads(String totalDownloads) {
66
        this.totalDownloads = totalDownloads;
67
    }
68

  
69
    public String getTotalViews() {
70
        return totalViews;
71
    }
72

  
73
    public void setTotalViews(String totalViews) {
74
        this.totalViews = totalViews;
75
    }
76

  
77
    public String getTotalOpenAIREDownloads() {
78
        return totalOpenAIREDownloads;
79
    }
80

  
81
    public void setTotalOpenAIREDownloads(String totalOpenAIREDownloads) {
82
        this.totalOpenAIREDownloads = totalOpenAIREDownloads;
83
    }
84

  
85
    public String getTotalOpenAIREViews() {
86
        return totalOpenAIREViews;
87
    }
88

  
89
    public void setTotalOpenAIREViews(String totalOpenAIREViews) {
90
        this.totalOpenAIREViews = totalOpenAIREViews;
91
    }
92

  
93
    public String getPageViews() {
94
        return pageViews;
95
    }
96

  
97
    public void setPageViews(String pageViews) {
98
        this.pageViews = pageViews;
99
    }
100
}
101

  
modules/uoa-repository-manager-service/branches/dev-api/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.dao.EmptyResultDataAccessException;
8
import org.springframework.jdbc.core.JdbcTemplate;
9
import org.springframework.jdbc.core.RowMapper;
10
import org.springframework.stereotype.Component;
11
import org.springframework.web.bind.annotation.PathVariable;
12
import org.springframework.web.bind.annotation.RequestBody;
13

  
14
import javax.annotation.PostConstruct;
15
import javax.sql.DataSource;
16
import java.security.NoSuchAlgorithmException;
17
import java.sql.ResultSet;
18
import java.sql.SQLException;
19
import java.sql.Types;
20
import java.util.List;
21

  
22
@Component
23
public class PiWikApiImpl implements PiWikApi{
24

  
25
    @Autowired
26
    @Qualifier("repomanager.dataSource")
27
    private DataSource dataSource;
28

  
29
    private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
30
            .getLogger(PiWikApiImpl.class);
31

  
32
    private final static String GET_PIWIK_SITE = "select repositoryid, siteid, authenticationtoken, creationdate, requestorname, requestoremail, validated, validationdate, comment, repositoryname, country from piwik_site where repositoryid = ?;";
33

  
34
    private final static String INSERT_PIWIK_INFO = "insert into piwik_site (repositoryid, siteid, creationdate, requestorname, requestoremail, validated, repositoryname, country, authenticationtoken) values (?, ?, now(), ?, ?, ?, ?, ?, ?)";
35

  
36
    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";
37

  
38
    private final static String APPROVE_PIWIK_SITE = "update piwik_site set validated=true, validationdate=now() where repositoryid = ?;";
39

  
40

  
41
    private RowMapper<PiwikInfo> piwikRowMapper = (rs, i) -> new PiwikInfo(rs.getString("repositoryid"), getOpenaireId(rs.getString("repositoryid")), rs.getString("repositoryname"), rs.getString("country"),
42
            rs.getString("siteid"), rs.getString("authenticationtoken"), rs.getTimestamp("creationdate"), rs.getString("requestorname"), rs.getString("requestoremail"),
43
            rs.getBoolean("validated"), rs.getTimestamp("validationdate"), rs.getString("comment"));
44

  
45

  
46
    @Override
47
    public PiwikInfo getPiwikSiteForRepo(@PathVariable("repositoryId") String repositoryId) {
48
        try{
49
            return new JdbcTemplate(dataSource).queryForObject(GET_PIWIK_SITE, new String[]{repositoryId}, new int[]{Types.VARCHAR}, piwikRowMapper);
50
        }catch (EmptyResultDataAccessException e){
51
            return null;
52
        }
53
    }
54

  
55
    @Override
56
    public PiwikInfo savePiwikInfo(@RequestBody PiwikInfo piwikInfo) {
57
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
58
        jdbcTemplate.update(INSERT_PIWIK_INFO, new Object[]{piwikInfo.getRepositoryId(), piwikInfo.getSiteId(), piwikInfo.getRequestorName(),
59
                        piwikInfo.getRequestorEmail(), piwikInfo.isValidated(), piwikInfo.getRepositoryName(), piwikInfo.getCountry(), piwikInfo.getAuthenticationToken()},
60
                new int[]{Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BOOLEAN, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR});
61
        return piwikInfo;
62
    }
63

  
64
    @Override
65
    public List<PiwikInfo> getPiwikSitesForRepos() {
66
        LOGGER.debug("Getting piwik sites for repos! ");
67
        try{
68
            return new JdbcTemplate(dataSource).query(GET_PIWIK_SITES, piwikRowMapper);
69
        }catch (EmptyResultDataAccessException e){
70
            return null;
71
        }
72

  
73
    }
74

  
75
    @Override
76
    public void approvePiwikSite(@PathVariable("repositoryId") String repositoryId) {
77
        new JdbcTemplate(dataSource).update(APPROVE_PIWIK_SITE, new Object[] {repositoryId}, new int[] {Types.VARCHAR});
78
    }
79

  
80
    @Override
81
    public String getOpenaireId(@PathVariable("repositoryId") String repositoryId) {
82
        LOGGER.debug("Getting openaire id for repository: " + repositoryId);
83
        try {
84
            if (repositoryId != null && repositoryId.contains("::")) {
85
                return repositoryId.split("::")[0] + "::" + MD5.encrypt2Hex(repositoryId.split("::")[1]);
86
            }
87
            else
88
                return null;
89
        } catch (NoSuchAlgorithmException e) {
90
            LOGGER.debug(e);
91
        }
92
        return null;
93
    }
94

  
95

  
96
}
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/shared/Term.java
1
package eu.dnetlib.repo.manager.shared;
2

  
3
import com.google.gwt.user.client.rpc.IsSerializable;
4

  
5
/**
6
 * Created by panagiotis on 15/1/2018.
7
 */
8
public class Term implements IsSerializable {
9

  
10
    public String englishName;
11
    public String nativeName;
12
    public String encoding;
13
    public String code;
14

  
15
    public Term(String englishName, String nativeName, String encoding, String code) {
16
        this.englishName = englishName;
17
        this.nativeName = nativeName;
18
        this.encoding = encoding;
19
        this.code = code;
20
    }
21

  
22
    public String getEnglishName() {
23
        return englishName;
24
    }
25

  
26
    public void setEnglishName(String englishName) {
27
        this.englishName = englishName;
28
    }
29

  
30
    public String getNativeName() {
31
        return nativeName;
32
    }
33

  
34
    public void setNativeName(String nativeName) {
35
        this.nativeName = nativeName;
36
    }
37

  
38
    public String getEncoding() {
39
        return encoding;
40
    }
41

  
42
    public void setEncoding(String encoding) {
43
        this.encoding = encoding;
44
    }
45

  
46
    public String getCode() {
47
        return code;
48
    }
49

  
50
    public void setCode(String code) {
51
        this.code = code;
52
    }
53
}
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/shared/broker/AdvQueryObject.java
1
package eu.dnetlib.repo.manager.shared.broker;
2

  
3
import com.google.gwt.user.client.rpc.IsSerializable;
4

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

  
8
public class AdvQueryObject implements IsSerializable {
9

  
10
    private String datasource = "";
11
    private String topic = "";
12
    private List<String> titles = new ArrayList<>();
13
    private List<String> subjects = new ArrayList<>();
14
    private List<String> authors = new ArrayList<>();
15
    private List<Range> dates = new ArrayList<>();
16
    private Range trust = new Range("0", "1");
17

  
18
    private long page = 0;
19

  
20
    public AdvQueryObject() {
21
    }
22

  
23
    public AdvQueryObject(String datasource, String topic, List<String> titles, List<String> subjects, List<String> authors,
24
                          List<Range> dates, Range trust, long page) {
25
        this.datasource = datasource;
26
        this.topic = topic;
27
        this.titles = titles;
28
        this.subjects = subjects;
29
        this.authors = authors;
30
        this.dates = dates;
31
        this.trust = trust;
32
        this.page = page;
33
    }
34

  
35
    public String getDatasource() {
36
        return datasource;
37
    }
38

  
39
    public void setDatasource(String datasource) {
40
        this.datasource = datasource;
41
    }
42

  
43
    public String getTopic() {
44
        return topic;
45
    }
46

  
47
    public void setTopic(String topic) {
48
        this.topic = topic;
49
    }
50

  
51
    public List<String> getTitles() {
52
        return titles;
53
    }
54

  
55
    public void setTitles(List<String> titles) {
56
        this.titles = titles;
57
    }
58

  
59
    public List<String> getSubjects() {
60
        return subjects;
61
    }
62

  
63
    public void setSubjects(List<String> subjects) {
64
        this.subjects = subjects;
65
    }
66

  
67
    public List<String> getAuthors() {
68
        return authors;
69
    }
70

  
71
    public void setAuthors(List<String> authors) {
72
        this.authors = authors;
73
    }
74

  
75
    public List<Range> getDates() {
76
        return dates;
77
    }
78

  
79
    public void setDates(List<Range> dates) {
80
        this.dates = dates;
81
    }
82

  
83
    public Range getTrust() {
84
        return trust;
85
    }
86

  
87
    public void setTrust(Range trust) {
88
        this.trust = trust;
89
    }
90

  
91
    public long getPage() {
92
        return page;
93
    }
94

  
95
    public void setPage(long page) {
96
        this.page = page;
97
    }
98
}
99

  
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/service/controllers/ValidatorApi.java
1
package eu.dnetlib.repo.manager.service.controllers;
2

  
3
import eu.dnetlib.api.functionality.ValidatorServiceException;
4
import eu.dnetlib.domain.functionality.validator.JobForValidation;
5
import eu.dnetlib.domain.functionality.validator.RuleSet;
6
import eu.dnetlib.domain.functionality.validator.StoredJob;
7
import eu.dnetlib.repo.manager.shared.InterfaceInformation;
8
import eu.dnetlib.repo.manager.shared.ValidationServiceException;
9
import io.swagger.annotations.Api;
10
import org.json.JSONException;
11
import org.springframework.http.MediaType;
12
import org.springframework.web.bind.annotation.*;
13

  
14
import java.util.List;
15

  
16

  
17
@RestController
18
@RequestMapping(value = "/validator")
19
@Api(description = "Validator API",  tags = {"validator"})
20
public interface ValidatorApi {
21

  
22
    @RequestMapping(value = "/submitJobForValidation",method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE )
23
    @ResponseBody
24
    void submitJobForValidation(JobForValidation jobForValidation);
25

  
26
    @RequestMapping(value = "/reSubmitJobForValidation/{jobId}",method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE )
27
    @ResponseBody
28
    void reSubmitJobForValidation(String jobId) throws JSONException;
29

  
30
    @RequestMapping(value = "/getRuleSets/{mode}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
31
    @ResponseBody
32
    List<RuleSet> getRuleSets(String mode);
33

  
34
    @RequestMapping(value = "/getSetsOfRepository" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
35
    @ResponseBody
36
    List<String> getSetsOfRepository(String url);
37

  
38
    @RequestMapping(value = "/identifyRepository" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
39
    @ResponseBody
40
    boolean identifyRepo(String url);
41

  
42
    @RequestMapping(value = "/getRuleSet/{acronym}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
43
    @ResponseBody
44
    RuleSet getRuleSet(String acronym);
45

  
46
    @RequestMapping(value = "/getStoredJobsNew" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
47
    @ResponseBody
48
    List<StoredJob> getStoredJobsNew(String user,
49
                                     String jobType,
50
                                     String offset,
51
                                     String limit,
52
                                     String dateFrom,
53
                                     String dateTo,
54
                                     String validationStatus) throws ValidatorServiceException;
55

  
56

  
57
    @RequestMapping(value = "/getStoredJobsTotalNumberNew" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
58
    @ResponseBody
59
    int getStoredJobsTotalNumberNew(String user, String jobType, String validationStatus) throws ValidatorServiceException;
60

  
61
    @RequestMapping(value = "/getInterfaceInformation/" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
62
    @ResponseBody
63
    InterfaceInformation getInterfaceInformation(String baseUrl) throws ValidationServiceException;
64
}
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/shared/Aggregations.java
1
package eu.dnetlib.repo.manager.shared;
2

  
3
import com.google.gwt.user.client.rpc.IsSerializable;
4

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

  
8
public class Aggregations implements IsSerializable{
9

  
10
    private List<AggregationDetails> aggregationHistory = new ArrayList<>();
11
    private AggregationDetails lastCollection;
12
    private AggregationDetails lastTransformation;
13

  
14
    public Aggregations() {
15
    }
16

  
17
    public List<AggregationDetails> getAggregationHistory() {
18
        return aggregationHistory;
19
    }
20

  
21
    public void setAggregationHistory(List<AggregationDetails> aggregationHistory) {
22
        this.aggregationHistory = aggregationHistory;
23
    }
24

  
25
    public AggregationDetails getLastCollection() {
26
        return lastCollection;
27
    }
28

  
29
    public void setLastCollection(AggregationDetails lastCollection) {
30
        this.lastCollection = lastCollection;
31
    }
32

  
33
    public AggregationDetails getLastTransformation() {
34
        return lastTransformation;
35
    }
36

  
37
    public void setLastTransformation(AggregationDetails lastTransformation) {
38
        this.lastTransformation = lastTransformation;
39
    }
40
}
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/shared/WizardState.java
1
package eu.dnetlib.repo.manager.shared;
2

  
3
import com.google.gwt.user.client.rpc.IsSerializable;
4

  
5
/**
6
 * Created by stefania on 2/10/16.
7
 */
8
public class WizardState implements IsSerializable {
9
}
modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApiImpl.java
1
package eu.dnetlib.repo.manager.service.controllers;
2

  
3
import com.fasterxml.jackson.databind.JsonNode;
4
import com.fasterxml.jackson.databind.ObjectMapper;
5
import eu.dnetlib.domain.data.Repository;
6
import eu.dnetlib.repo.manager.shared.BrokerException;
7
import eu.dnetlib.repo.manager.shared.Term;
8
import eu.dnetlib.repo.manager.shared.Tuple;
9
import eu.dnetlib.repo.manager.shared.broker.*;
10
import io.swagger.annotations.ApiParam;
11
import org.json.JSONException;
12
import org.json.JSONObject;
13
import org.springframework.beans.factory.annotation.Autowired;
14
import org.springframework.beans.factory.annotation.Value;
15
import org.springframework.core.ParameterizedTypeReference;
16
import org.springframework.http.HttpEntity;
17
import org.springframework.http.HttpHeaders;
18
import org.springframework.http.HttpMethod;
19
import org.springframework.http.ResponseEntity;
20
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
21
import org.springframework.stereotype.Component;
22
import org.springframework.util.LinkedMultiValueMap;
23
import org.springframework.util.MultiValueMap;
24
import org.springframework.web.bind.annotation.PathVariable;
25
import org.springframework.web.bind.annotation.RequestBody;
26
import org.springframework.web.bind.annotation.RequestParam;
27
import org.springframework.web.client.RestClientException;
28
import org.springframework.web.client.RestTemplate;
29
import org.springframework.web.util.UriComponents;
30
import org.springframework.web.util.UriComponentsBuilder;
31

  
32
import javax.annotation.PostConstruct;
33
import java.io.IOException;
34
import java.io.InputStream;
35
import java.net.URL;
36
import java.util.*;
37

  
38
@Component
39
public class BrokerApiImpl implements BrokerApi {
40

  
41
    @Autowired
42
    private RepositoryApiImpl repoAPI;
43
    @Value("${services.broker.url}:${services.broker.port}/${services.broker.api}${services.broker.openaire}")
44
    private String openairePath;
45
    @Value("${services.broker.url}:${services.broker.port}/${services.broker.api}")
46
    private String apiPath;
47
    @Value("${topic_types.url}")
48
    private String topicsURL;
49

  
50
    private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
51
            .getLogger(BrokerApiImpl.class);
52

  
53
    private RestTemplate restTemplate = null;
54

  
55
    private HttpHeaders httpHeaders;
56

  
57
    private HashMap<String,Term> topics = new HashMap<String, Term>();
58

  
59
    @PostConstruct
60
    private void initDnetTopicsMap() {
61

  
62
        restTemplate = new RestTemplate();
63
        restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
64

  
65
        httpHeaders = new HttpHeaders();
66
        httpHeaders.set("Content-Type", "application/json");
67

  
68
        LOGGER.debug("Init dnet topics!");
69
        InputStream is = null;
70
        try {
71
            is = new URL(topicsURL).openStream();
72
            ObjectMapper mapper = new ObjectMapper();
73
            JsonNode root = mapper.readTree(is);
74
            for (JsonNode term : root.path("terms") )
75
                topics.put(term.path("code").textValue(), parseTerm(term));
76
        } catch (IOException e) {
77
            LOGGER.debug(e);
78
            e.printStackTrace();
79
        }
80
    }
81

  
82
    private Term parseTerm(JsonNode term) {
83
        return new Term(term.path("englishName").textValue(),term.path("nativeName").textValue(),
84
                term.path("encoding").textValue(),term.path("code").textValue());
85
    }
86

  
87

  
88
    @Override
89
    public DatasourcesBroker getDatasourcesOfUser(@RequestParam("user")
90
                                                    @ApiParam(value = "User email", required = true) String user,
91
                                                  @RequestParam("includeShared")
92
                                                    @ApiParam(value = "Include shared datasources", required = true , defaultValue = "false") String includeShared,
93
                                                  @RequestParam("includeByOthers")
94
                                                    @ApiParam(value = "Include datasources of other", required = true,defaultValue = "false") String includeByOthers) throws JSONException {
95

  
96
        DatasourcesBroker ret = new DatasourcesBroker();
97
        try {
98
            ret.setDatasourcesOfUser(getDatasourcesOfUserType(getRepositoriesOfUser(user)));
99
            //TODO fix bug when values are true
100
            if (Boolean.parseBoolean(includeShared)) {
101
                List<String> sharedDatasourceIds = new ArrayList<String>();
102
                ret.setSharedDatasources(getDatasourcesOfUserType(getRepositoriesByIds(sharedDatasourceIds)));
103
            }
104

  
105
            if (Boolean.parseBoolean(includeByOthers)) {
106
                ret.setDatasourcesOfOthers(getDatasourcesOfUserType(getRepositoriesOfUser(user)));
107
            }
108
        } catch (BrokerException e) {
109
            e.printStackTrace();
110
        }
111

  
112
        return ret;
113
    }
114

  
115
    @Override
116
    public List<BrowseEntry> getTopicsForDatasource(@PathVariable("datasourceName")  String datasourceName) throws BrokerException {
117
        final String service = "/topicsForDatasource";
118

  
119
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service)
120
                .queryParam("ds", datasourceName);
121

  
122
        ResponseEntity<List<BrowseEntry>> resp;
123
        try {
124
            resp = restTemplate.exchange(
125
                    builder.build().encode().toUri(),
126
                    HttpMethod.GET,
127
                    null,
128
                    new ParameterizedTypeReference<List<BrowseEntry>>() {
129
                    });
130
        } catch (RestClientException e) {
131
            throw new BrokerException(e);
132
        }
133

  
134
        return resp.getBody();
135
    }
136

  
137
    @Override
138
    public EventsPage advancedShowEvents(@PathVariable("page") String page,
139
                                         @PathVariable("size") String size,
140
                                         @RequestBody AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException {
141

  
142
        final String service = "/events/{page}/{pageSize}";
143

  
144
        Map<String, Long> uriParams = new HashMap<>();
145
        uriParams.put("page", Long.parseLong(page));
146
        uriParams.put("pageSize", Long.parseLong(size));
147

  
148
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service);
149

  
150
        MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
151
        advQueryObject.setPage(Long.parseLong(page));
152
        HttpEntity<AdvQueryObject> entity = new HttpEntity<>(advQueryObject, httpHeaders);
153
        ResponseEntity<EventsPage> resp;
154
        try {
155
            resp = restTemplate.exchange(
156
                    builder.buildAndExpand(uriParams).encode().toUri(),
157
                    HttpMethod.POST,
158
                    entity,
159
                    new ParameterizedTypeReference<EventsPage>() {
160
                    }
161
            );
162
        } catch (RestClientException e) {
163
            throw new BrokerException(e);
164
        }
165
        return resp.getBody();
166

  
167

  
168
    }
169

  
170

  
171
    private List<Tuple<BrowseEntry, String>> getDatasourcesOfUserType(List<Repository> repositories) throws BrokerException {
172

  
173
        List<Tuple<BrowseEntry, String>> entries = new ArrayList<>();
174
        for (Repository repo : repositories) {
175
            BrowseEntry temp = new BrowseEntry();
176
            temp.setValue(repo.getOfficialName());
177
            temp.setSize(new Long(0));
178
            for (BrowseEntry e : getTopicsForDatasource(repo.getOfficialName())) {
179
                temp.setSize(temp.getSize() + e.getSize());
180
            }
181
            Tuple<BrowseEntry, String> tup = new Tuple<>(temp, repo.getLogoUrl());
182
            entries.add(tup);
183
        }
184

  
185
        // sort the collection by the second field of the tuple which is size
186
        Collections.sort(entries, new Comparator<Tuple<BrowseEntry, String>>() {
187
            @Override
188
            public int compare(Tuple<BrowseEntry, String> e1, Tuple<BrowseEntry, String> e2) {
189
                return (int) (e2.getFirst().getSize().longValue() - e1.getFirst().getSize().longValue());
190
            }
191
        });
192

  
193
        return entries;
194
    }
195

  
196

  
197

  
198
    private List<Repository> getRepositoriesOfUser(String userEmail) throws JSONException {
199

  
200
        int page = 0;
201
        int size = 50;
202
        List<Repository> rs ;
203
        List<Repository> resultSet = new ArrayList<>();
204

  
205
        while (true){
206
            rs = repoAPI.getRepositoriesOfUser(userEmail, String.valueOf(page), String.valueOf(size));
207
            resultSet.addAll(rs);
208
            page+=1;
209
            if(rs.size() == 0) break;
210
        }
211
        return resultSet;
212
    }
213

  
214
    private List<Repository> getRepositoriesByIds(List<String> sharedDatasourceIds) {
215
        return null;
216
    }
217

  
218
    @Override
219
    public EventsPage showEvents(@RequestParam("datasourceName") String datasourceName,
220
                                 @RequestParam("topic") String topic,
221
                                 @RequestParam("page") String page,
222
                                 @RequestParam("size") String size) throws BrokerException, JSONException {
223

  
224
        final String service = "/events";
225

  
226
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service)
227
                .queryParam("ds", datasourceName)
228
                .queryParam("topic", topic)
229
                .path("/{page}/{size}/");
230

  
231
        ResponseEntity<EventsPage> resp;
232
        try {
233
            resp = restTemplate.exchange(
234
                    builder.build().expand(page, size).encode().toUri(),
235
                    HttpMethod.GET,
236
                    null,
237
                    new ParameterizedTypeReference<EventsPage>() {
238
                    });
239
        } catch (RestClientException e) {
240
            throw new BrokerException(e);
241
        }
242
        return resp.getBody();
243
    }
244

  
245
    @Override
246
    public Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(@PathVariable("userEmail")  String userEmail)
247
            throws BrokerException {
248

  
249
        final String service = "/subscriptions";
250

  
251
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service)
252
                .queryParam("email", userEmail);
253

  
254
        LOGGER.debug(builder.build().encode().toUri());
255
        ResponseEntity<Map<String, List<SimpleSubscriptionDesc>>> resp;
256
        try {
257
            resp = restTemplate.exchange(
258
                    builder.build().encode().toUri(),
259
                    HttpMethod.GET,
260
                    null,
261
                    new ParameterizedTypeReference<Map<String, List<SimpleSubscriptionDesc>>>() {
262
                    });
263
        } catch (RestClientException e) {
264
            LOGGER.debug("Error " , e);
265
            throw new BrokerException(e);
266
        }
267
        return resp.getBody();
268
    }
269

  
270
    @Override
271
    public Subscription subscribe(@RequestBody  OpenaireSubscription obj) throws BrokerException {
272
        final String service = "/subscribe";
273

  
274
        //build the uri params
275
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service);
276

  
277
        HttpEntity<OpenaireSubscription> entity = new HttpEntity<>(obj, httpHeaders);
278

  
279
        //create new template engine
280
        RestTemplate template = new RestTemplate();
281
        template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
282
        ResponseEntity<Subscription> resp;
283
        try {
284
            //communicate with endpoint
285
            resp = restTemplate.exchange(
286
                    builder.build().encode().toUri(),
287
                    HttpMethod.POST,
288
                    entity,
289
                    new ParameterizedTypeReference<Subscription>() {
290
                    });
291
        } catch (RestClientException e) {
292
            throw new BrokerException(e);
293
        }
294

  
295
        return resp.getBody();
296
    }
297

  
298
    @Override
299
    public void unsubscribe(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException {
300
        final String service = "/subscriptions/" + subscriptionId;
301

  
302
        //build the uri params
303
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(apiPath + service);
304

  
305
        try {
306
            //communicate with endpoint
307
            restTemplate.exchange(
308
                    builder.build().encode().toUri(),
309
                    HttpMethod.DELETE,
310
                    null,
311
                    new ParameterizedTypeReference<Void>() {
312
                    });
313
        } catch (RestClientException e) {
314
            throw new BrokerException(e);
315
        }
316
    }
317

  
318
    @Override
319
    public Subscription getSubscription(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException {
320
        final String service = "/subscriptions/" + subscriptionId;
321

  
322
        //build the uri params
323
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(apiPath + service);
324

  
325
        ResponseEntity<Subscription> resp;
326
        try {
327
            //communicate with endpoint
328
            resp = restTemplate.exchange(
329
                    builder.build().encode().toUri(),
330
                    HttpMethod.GET,
331
                    null,
332
                    new ParameterizedTypeReference<Subscription>() {
333
                    });
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff