Project

General

Profile

« Previous | Next » 

Revision 55040

Release 1.0.1

View differences:

modules/uoa-repository-manager-service/tags/release-1.0.1/Dockerfile
1
FROM tomcat:7.0.90-jre8
2
MAINTAINER "pkanakakis@di.uoa.gr"
3
RUN ["rm", "-fr", "/usr/local/tomcat/webapps/ROOT"]
4
COPY ./target/uoa-repository-manager-service.war /usr/local/tomcat/webapps/uoa-repository-manager-service.war
5
COPY src/main/resources/dnet-override-new.properties /usr/local/tomcat/lib/dnet-override.properties
6
#COPY src/main/resources/application.properties /usr/local/tomcat/lib/application.properties
7
#COPY src/main/resources/email-texts.properties /usr/local/tomcat/lib/email-texts.properties
8
VOLUME /var/log/uoa-repository-manager-service:/var/log/uoa-repository-manager-service/
9
CMD ["catalina.sh", "run"]
10

  
modules/uoa-repository-manager-service/tags/release-1.0.1/src/test/java/unitest/PiwikTest.java
1
/*
2
package unitest;
3

  
4
import com.fasterxml.jackson.databind.ObjectMapper;
5
import eu.dnetlib.repo.manager.config.RepoManagerContextLoaderListener;
6
import org.apache.commons.lang.StringEscapeUtils;
7
import org.junit.Test;
8
import org.junit.runner.RunWith;
9
import org.springframework.context.annotation.ComponentScan;
10
import org.springframework.test.context.ContextConfiguration;
11
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12

  
13
import java.io.IOException;
14
import java.io.UnsupportedEncodingException;
15
import java.net.URL;
16
import java.net.URLEncoder;
17
import java.util.Map;
18

  
19
@RunWith(SpringJUnit4ClassRunner.class)
20
@ContextConfiguration(classes = RepoManagerContextLoaderListener.class)
21
public class PiwikTest {
22

  
23
    String analyticsURL = "https://analytics.openaire.eu/addsite.php?";
24

  
25
    @Test
26
    public void enableMetricsRepo1(){
27

  
28
        String officialName = "BỘ SƯU TẬP SỐ";
29
        String repoWebsite = "http://www.vnulib.edu.vn:8000/dspace/";
30

  
31
        enableMetrics(officialName, repoWebsite, analyticsURL);
32

  
33
    }
34

  
35
    @Test
36
    public void enableMetricsRepo2(){
37

  
38
        String officialName = "ILC4CLARIN repository of language resources and tools";
39
        String repoWebsite = "https://dspace-clarin-it.ilc.cnr.it/repository/xmlui";
40

  
41
        enableMetrics(officialName, repoWebsite, analyticsURL);
42
    }
43

  
44
    @Test
45
    public void enableMetricsRepo3(){
46

  
47
        String officialName = "ANSTO Publications Online";
48
        String repoWebsite = "http://apo.ansto.gov.au/dspace/";
49

  
50
        enableMetrics(officialName, repoWebsite, analyticsURL);
51
    }
52

  
53
    private void enableMetrics(String officialName, String repoWebsite, String analyticsURL) {
54
        String url;
55
        try {
56
            url = analyticsURL + "siteName=" + URLEncoder.encode(officialName, "UTF-8") + "&url="
57
                    + URLEncoder.encode(repoWebsite, "UTF-8");
58
            url = StringEscapeUtils.escapeJava(url);
59

  
60
            Map map = null;
61
            String siteId = null;
62

  
63
            URL u = new URL(url);
64
            map = new ObjectMapper().readValue(u, Map.class);
65
            if(map.get("value")!=null) {
66
                siteId = map.get("value").toString();
67
            }
68
        } catch (Exception e) {
69
            e.printStackTrace();
70
        }
71
    }
72
}*/
modules/uoa-repository-manager-service/tags/release-1.0.1/src/test/java/unitest/ValidatorTest.java
1
//package unitest;
2
//
3
//import eu.dnetlib.repo.manager.config.RepoManagerContextLoaderListener;
4
//import eu.dnetlib.repo.manager.utils.OaiTools;
5
//import org.junit.Test;
6
//import org.junit.runner.RunWith;
7
//import org.springframework.test.context.ContextConfiguration;
8
//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
9
//
10
//@RunWith(SpringJUnit4ClassRunner.class)
11
//@ContextConfiguration(classes = RepoManagerContextLoaderListener.class)
12
////@WebAppConfiguration
13
//public class ValidatorTest {
14
//
15
//
16
//    @Test
17
//    public void identiFy(){
18
//
19
//        String url = "https://repozitorij.srce.unizg.hr/oai";
20
//
21
//
22
//        System.out.println("Identify repository with url : " + url);
23
//        try {
24
//            System.out.println(OaiTools.identifyRepository(url));
25
//        } catch (Exception e) {
26
//            System.out.println(e);
27
//        }
28
//    }
29
//
30
//
31
//}
modules/uoa-repository-manager-service/tags/release-1.0.1/src/test/resources/application-context.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns="http://www.springframework.org/schema/beans"
3
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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
6
               http://www.springframework.org/schema/beans/spring-beans-4.0.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">
7

  
8

  
9
    <context:annotation-config/>
10
    <context:component-scan base-package="eu.dnetlib.repo.manager.service.*"/>
11
    <tx:annotation-driven transaction-manager="txManager"/>
12

  
13
    <bean class="eu.dnetlib.repo.manager.config.CascadingPropertyLoader"
14
          id="propertyLoader">
15
        <property name="order" value="2"/>
16
        <property name="properties">
17
            <bean class="eu.dnetlib.conf.WebappContextProperyFactory">
18
                <property name="propertyFetcher">
19
                    <bean class="eu.dnetlib.conf.PropertyFetcher"/>
20
                </property>
21
            </bean>
22
        </property>
23
        <property name="ignoreUnresolvablePlaceholders" value="true"/>
24
        <property name="locations">
25
            <list>
26
                <value>classpath*:/gr/**/springContext-*.properties</value>
27
                <value>classpath*:/eu/**/springContext-*.properties</value>
28

  
29
                <value>classpath*:/application.properties</value>
30
                <value>classpath*:/email-texts.properties</value>
31

  
32
                <value>classpath*:dnet-site-wizard.properties</value>
33
                <value>classpath*:dnet-site-override.properties</value>
34
                <value>classpath*:dnet-wizard.properties</value>
35
                <value>classpath*:dnet-override-new.properties</value>
36
                <value>classpath*:dnet-validator-wizard.properties</value>
37
                <value>classpath*:dnet-validator-override.properties</value>
38
                <value>classpath*:dnet-site-force-override.properties</value>
39
                <value>classpath*:dnet-force-override.properties</value>
40
            </list>
41
        </property>
42
    </bean>
43

  
44
    <bean id="repomanager.dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
45
        <property name="driverClassName" value="${repomanager.db.driverClassName}" />
46
        <property name="url" value="${repomanager.db.url}" />
47
        <property name="username" value="${repomanager.db.username}" />
48
        <property name="password" value="${repomanager.db.password}" />
49
        <property name="maxIdle" value="10" />
50
        <property name="maxActive" value="100" />
51
        <property name="maxWait" value="10000" />
52
        <property name="validationQuery" value="SELECT 1;" />
53
        <property name="testOnBorrow" value="true" />
54
        <property name="testOnReturn" value="true" />
55
        <property name="testWhileIdle" value="true" />
56
        <property name="timeBetweenEvictionRunsMillis" value="1200000" />
57
        <property name="minEvictableIdleTimeMillis" value="1800000" />
58
        <property name="numTestsPerEvictionRun" value="5" />
59
        <property name="poolPreparedStatements" value="true" />
60
        <property name="defaultAutoCommit" value="true" />
61
    </bean>
62

  
63
    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
64
        <property name="dataSource" ref="repomanager.dataSource"/>
65
    </bean>
66

  
67
</beans>
modules/uoa-repository-manager-service/tags/release-1.0.1/src/test/resources/applicationContext.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns="http://www.springframework.org/schema/beans"
3
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
       xmlns:tx="http://www.springframework.org/schema/tx"
5
       xmlns:mvc="http://www.springframework.org/schema/mvc"
6
       xsi:schemaLocation="http://www.springframework.org/schema/beans
7

  
8
       http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
9
	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
10
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
11

  
12
    <import resource="classpath*:/application-context.xml"/>
13

  
14
    <import resource="classpath*:/eu/dnetlib/soap/cxf/applicationContext-eprbuilders.xml"/>
15
    <import resource="classpath*:/eu/dnetlib/clients/ws/springContext-locatorFactory.xml"/>
16
    <import resource="classpath*:/gr/uoa/di/driver/util/springContext-locators.xml"/>
17
    <import resource="classpath*:/gr/uoa/di/driver/app/springContext-lookupFactory.xml"/>
18
    <import resource="classpath*:/gr/uoa/di/driver/app/springContext-lookupClients.xml"/>
19
    <import resource="classpath*:/eu/dnetlib/enabling/hcm/springContext-hcmService.xml"/>
20
    <import resource="classpath*:/gr/uoa/di/driver/app/springContext-commons.xml"/>
21

  
22
    <!--<import resource="classpath*:/gr/uoa/di/driver/app/springContext-registrator.xml"/>-->
23

  
24

  
25

  
26

  
27
    <bean id="maillib" class="eu.dnetlib.utils.MailLibrary" init-method="init">
28
        <property name="mailhost" value="${services.validator.mail.host}"/>
29
        <property name="smtpPort" value="${services.validator.mail.port}"/>
30
        <property name="authenticate" value="${services.validator.mail.authenticate}"/>
31
        <property name="username" value="${services.validator.mail.username}"/>
32
        <property name="password" value="${services.validator.mail.password}"/>
33
        <property name="from" value="${services.validator.mail.fromAddress}"/>
34
        <property name="replyTo" value="${services.validator.mail.replyToAddress}"/>
35
        <property name="mode" value="${services.validator.mail.mode}"/>
36
        <property name="debug" value="${services.validator.mail.debug}"/>
37
    </bean>
38

  
39
    <bean class="eu.dnetlib.repo.manager.config.CascadingPropertyLoader"
40
          id="propertyLoader">
41
        <property name="order" value="2"/>
42
        <property name="properties">
43
            <bean class="eu.dnetlib.conf.WebappContextProperyFactory">
44
                <property name="propertyFetcher">
45
                    <bean class="eu.dnetlib.conf.PropertyFetcher"/>
46
                </property>
47
            </bean>
48
        </property>
49
        <property name="ignoreUnresolvablePlaceholders" value="true"/>
50
        <property name="locations">
51
            <list>
52
                <value>classpath*:/gr/**/springContext-*.properties</value>
53
                <value>classpath*:/eu/**/springContext-*.properties</value>
54

  
55
                <value>classpath*:/application.properties</value>
56
                <value>classpath*:/email-texts.properties</value>
57

  
58
                <value>classpath*:dnet-site-wizard.properties</value>
59
                <value>classpath*:dnet-site-override.properties</value>
60
                <value>classpath*:dnet-wizard.properties</value>
61
                <value>classpath*:dnet-override-new.properties</value>
62
                <value>classpath*:dnet-validator-wizard.properties</value>
63
                <value>classpath*:dnet-validator-override.properties</value>
64
                <value>classpath*:dnet-site-force-override.properties</value>
65
                <value>classpath*:dnet-force-override.properties</value>
66
            </list>
67
        </property>
68
    </bean>
69

  
70
    <bean id="repomanager.dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
71
        <property name="driverClassName" value="${repomanager.db.driverClassName}" />
72
        <property name="url" value="${repomanager.db.url}" />
73
        <property name="username" value="${repomanager.db.username}" />
74
        <property name="password" value="${repomanager.db.password}" />
75
        <property name="maxIdle" value="10" />
76
        <property name="maxActive" value="100" />
77
        <property name="maxWait" value="10000" />
78
        <property name="validationQuery" value="SELECT 1;" />
79
        <property name="testOnBorrow" value="true" />
80
        <property name="testOnReturn" value="true" />
81
        <property name="testWhileIdle" value="true" />
82
        <property name="timeBetweenEvictionRunsMillis" value="1200000" />
83
        <property name="minEvictableIdleTimeMillis" value="1800000" />
84
        <property name="numTestsPerEvictionRun" value="5" />
85
        <property name="poolPreparedStatements" value="true" />
86
        <property name="defaultAutoCommit" value="true" />
87
    </bean>
88

  
89
    <tx:annotation-driven transaction-manager="txManager"/>
90

  
91
    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
92
        <property name="dataSource" ref="repomanager.dataSource"/>
93
    </bean>
94

  
95
    <mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/>
96
    <mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
97
    <bean class="eu.dnetlib.repo.manager.config.SwaggerConfig"/>
98

  
99
</beans>
modules/uoa-repository-manager-service/tags/release-1.0.1/src/main/java/eu/dnetlib/repo/manager/service/UserService.java
1
package eu.dnetlib.repo.manager.service;
2

  
3
import org.springframework.http.ResponseEntity;
4

  
5

  
6
public interface UserService {
7

  
8
    ResponseEntity<Object> login();
9
}
modules/uoa-repository-manager-service/tags/release-1.0.1/src/main/java/eu/dnetlib/repo/manager/service/RepositoryService.java
1
package eu.dnetlib.repo.manager.service;
2

  
3
import eu.dnetlib.domain.data.Repository;
4
import eu.dnetlib.domain.data.RepositoryInterface;
5
import eu.dnetlib.repo.manager.domain.RepositorySnippet;
6
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
7
import eu.dnetlib.repo.manager.shared.*;
8
import org.json.JSONException;
9
import org.springframework.security.core.Authentication;
10
import java.io.IOException;
11
import java.util.List;
12
import java.util.Map;
13

  
14
public interface RepositoryService {
15

  
16

  
17
    Country[] getCountries() ;
18

  
19
    List<RepositorySnippet> getRepositoriesByCountry(String country, String mode, Boolean managed) throws JSONException, IOException;
20

  
21
    List<Repository> getRepositoriesOfUser(String userEmail,
22
                                           String page,
23
                                           String size) throws JSONException;
24

  
25
    Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException;
26

  
27
    List<AggregationDetails> getRepositoryAggregations(String id) throws JSONException;
28

  
29
    Map<String,List<AggregationDetails>> getRepositoryAggregationsByYear(String id) throws JSONException;
30

  
31
    List<Repository> getRepositoriesByName(String name,
32
                                           String page,
33
                                           String size) throws JSONException;
34

  
35
    List<RepositoryInterface> getRepositoryInterface(String id) throws JSONException;
36

  
37
    Repository addRepository(String datatype, Repository repository) throws Exception;
38

  
39
    void deleteRepositoryInterface(String id, String registeredBy);
40

  
41
    RepositoryInterface addRepositoryInterface(String datatype,
42
                                               String repoId,
43
                                               String registeredBy,
44
                                               RepositoryInterface iFace) throws JSONException,ResourceNotFoundException;
45

  
46
    List<String> getDnetCountries();
47

  
48
    List<String> getTypologies();
49

  
50
    List<Timezone> getTimezones();
51

  
52
    Repository updateRepository(Repository repository, Authentication authentication) throws Exception;
53

  
54
    List<String> getUrlsOfUserRepos(String user_email,
55
                                    String page,
56
                                    String size) throws JSONException;
57

  
58
    List<String> getDatasourceVocabularies(String mode);
59

  
60
    Map<String, String> getCompatibilityClasses(String mode);
61

  
62
    Map<String, String> getDatasourceClasses(String mode);
63

  
64
    String getCountryName(String countryCode);
65

  
66
    MetricsInfo getMetricsInfoForRepository(String repoId) throws RepositoryServiceException;
67

  
68
    Map<String, String> getListLatestUpdate(String mode) throws RepositoryServiceException, JSONException;
69

  
70
    RepositoryInterface updateRepositoryInterface(String repositoryId, String registeredBy, RepositoryInterface repositoryInterface) throws Exception;
71

  
72
}
modules/uoa-repository-manager-service/tags/release-1.0.1/src/main/java/eu/dnetlib/repo/manager/service/StatsServiceImpl.java
1
package eu.dnetlib.repo.manager.service;
2

  
3
import eu.dnetlib.repo.manager.service.customHystrixCommands.*;
4
import org.springframework.beans.factory.annotation.Autowired;
5
import org.springframework.beans.factory.annotation.Value;
6
import org.springframework.stereotype.Service;
7
import org.springframework.web.client.RestTemplate;
8

  
9
import java.util.HashMap;
10
import java.util.Map;
11

  
12
@Service("statsService")
13
public class StatsServiceImpl implements StatsService {
14

  
15
    @Autowired
16
    RestTemplate restTemplate;
17

  
18
    @Value("${search.api.baseAddress}")
19
    private String baseAddress;
20
    @Value("${search.api.usagestats}")
21
    private String usagestatsBaseAddress;
22
    @Value("${search.api.usageEvents}")
23
    private String usagestatsEvents;
24

  
25
    @Override
26
    public Map getStatistics()  {
27

  
28
        UsageStatsTotalHystrixCommand usageStatsTotalHystrixCommand = new UsageStatsTotalHystrixCommand(usagestatsEvents,restTemplate);
29
        DataRepositoriesHystrixCommand dataRepositoriesHystrixCommand = new DataRepositoriesHystrixCommand(baseAddress,restTemplate);
30
        AggregatorsHystrixCommand aggregatorsHystrixCommand = new AggregatorsHystrixCommand(baseAddress,restTemplate);
31
        LiteratureHystrixCommand literatureHystrixCommand = new LiteratureHystrixCommand(baseAddress,restTemplate);
32
        JournalHystrixCommand journalHystrixCommand = new JournalHystrixCommand(baseAddress,restTemplate);
33
        PublicationHystrixCommand publicationHystrixCommand = new PublicationHystrixCommand(baseAddress,restTemplate);
34
        DatasetsHystrixCommand datasetsHystrixCommand = new DatasetsHystrixCommand(baseAddress,restTemplate);
35
        SoftwareHystrixCommand softwareHystrixCommand = new SoftwareHystrixCommand(baseAddress,restTemplate);
36
        LastYearUsageStatsHystrixCommand lastYearUsageStatsHystrixCommand = new LastYearUsageStatsHystrixCommand(usagestatsBaseAddress,restTemplate);
37

  
38
        Map<String,Object> stats = new HashMap<>();
39
        stats.put("aggregators",aggregatorsHystrixCommand.execute());
40
        stats.put("dataRepositories",dataRepositoriesHystrixCommand.execute());
41
        stats.put("literature",literatureHystrixCommand.execute());
42
        stats.put("journal",journalHystrixCommand.execute());
43
        stats.put("publications",publicationHystrixCommand.execute());
44
        stats.put("datasets",datasetsHystrixCommand.execute());
45
        stats.put("software",softwareHystrixCommand.execute());
46
        stats.put("lastYearUsagestats", lastYearUsageStatsHystrixCommand.execute());
47
        stats.put("usagestats",usageStatsTotalHystrixCommand.execute());
48
        return stats;
49
    }
50
}
modules/uoa-repository-manager-service/tags/release-1.0.1/src/main/java/eu/dnetlib/repo/manager/service/PiWikService.java
1
package eu.dnetlib.repo.manager.service;
2

  
3

  
4
import eu.dnetlib.domain.data.PiwikInfo;
5
import eu.dnetlib.repo.manager.shared.RepositoryServiceException;
6
import org.springframework.http.ResponseEntity;
7

  
8
import java.util.List;
9

  
10

  
11
public interface PiWikService {
12

  
13
    PiwikInfo getPiwikSiteForRepo(String repositoryId);
14

  
15
    PiwikInfo savePiwikInfo(PiwikInfo piwikInfo);
16

  
17
    List<PiwikInfo> getPiwikSitesForRepos();
18

  
19
    ResponseEntity<Object> approvePiwikSite(String repositoryId);
20

  
21
    String getOpenaireId(String repositoryid);
22

  
23
    ResponseEntity<Object> markPiwikSiteAsValidated(String repositoryId) throws RepositoryServiceException;
24

  
25
    PiwikInfo enableMetricsForRepository(String officialName, String repoWebsite, PiwikInfo piwikInfo) throws RepositoryServiceException;
26
}
modules/uoa-repository-manager-service/tags/release-1.0.1/src/main/java/eu/dnetlib/repo/manager/service/BrokerService.java
1
package eu.dnetlib.repo.manager.service;
2

  
3
import eu.dnetlib.repo.manager.shared.BrokerException;
4
import eu.dnetlib.repo.manager.shared.Term;
5
import eu.dnetlib.repo.manager.shared.broker.*;
6
import io.swagger.annotations.Api;
7
import org.json.JSONException;
8
import org.springframework.http.MediaType;
9
import org.springframework.http.ResponseEntity;
10
import org.springframework.web.bind.annotation.RequestMapping;
11
import org.springframework.web.bind.annotation.RequestMethod;
12
import org.springframework.web.bind.annotation.ResponseBody;
13
import org.springframework.web.bind.annotation.RestController;
14

  
15
import java.io.IOException;
16
import java.util.List;
17
import java.util.Map;
18

  
19

  
20
public interface BrokerService {
21

  
22
    DatasourcesBroker getDatasourcesOfUser(String user, String includeShared, String includeByOthers) throws BrokerException, JSONException;
23

  
24
    List<BrowseEntry> getTopicsForDatasource(String datasourceName) throws BrokerException;
25

  
26
    EventsPage advancedShowEvents(String page,
27
                                  String size,
28
                                  AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException;
29

  
30
    EventsPage showEvents(String datasourceName,
31
                          String topic,
32
                          String page,
33
                          String size) throws BrokerException, JSONException;
34

  
35
    Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(String userEmail) throws BrokerException;
36

  
37
    Subscription subscribe(OpenaireSubscription obj) throws BrokerException;
38

  
39
    ResponseEntity<Object> unsubscribe(String subscriptionId) throws BrokerException;
40

  
41
    Subscription getSubscription(String subscriptionId) throws BrokerException;
42

  
43
    Map<String, Term> getDnetTopics() throws BrokerException;
44

  
45
    EventsPage getNotificationsBySubscriptionId(String subscriptionId, String page, String size) throws BrokerException;
46

  
47
    Map<String, List<Subscription>> getSubscriptionsOfUser(String userEmail) throws BrokerException;
48
}
modules/uoa-repository-manager-service/tags/release-1.0.1/src/main/java/eu/dnetlib/repo/manager/service/ValidatorService.java
1
package eu.dnetlib.repo.manager.service;
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 org.json.JSONException;
10
import org.springframework.http.ResponseEntity;
11

  
12
import java.util.List;
13

  
14

  
15

  
16
public interface ValidatorService {
17

  
18

  
19
    JobForValidation submitJobForValidation(JobForValidation jobForValidation) throws ValidatorServiceException;
20

  
21
    ResponseEntity<Object> reSubmitJobForValidation(String email, String jobId) throws JSONException, ValidatorServiceException;
22

  
23
    List<RuleSet> getRuleSets(String mode);
24

  
25
    List<String> getSetsOfRepository(String url);
26

  
27
    boolean identifyRepo(String url);
28

  
29
    RuleSet getRuleSet(String acronym);
30

  
31
    List<StoredJob> getStoredJobsNew(String user,
32
                                     String jobType,
33
                                     String offset,
34
                                     String limit,
35
                                     String dateFrom,
36
                                     String dateTo,
37
                                     String validationStatus) throws ValidatorServiceException;
38

  
39
    int getStoredJobsTotalNumberNew(String user, String jobType, String validationStatus) throws ValidatorServiceException;
40

  
41
    InterfaceInformation getInterfaceInformation(String baseUrl) throws ValidationServiceException;
42
}
modules/uoa-repository-manager-service/tags/release-1.0.1/src/main/java/eu/dnetlib/repo/manager/service/customHystrixCommands/AggregatorsHystrixCommand.java
1
package eu.dnetlib.repo.manager.service.customHystrixCommands;
2

  
3
import com.netflix.hystrix.HystrixCommand;
4
import com.netflix.hystrix.HystrixCommandGroupKey;
5
import org.springframework.http.HttpMethod;
6
import org.springframework.http.ResponseEntity;
7
import org.springframework.web.client.RestTemplate;
8
import org.springframework.web.util.UriComponents;
9
import org.springframework.web.util.UriComponentsBuilder;
10

  
11
import java.util.Map;
12

  
13
public class AggregatorsHystrixCommand extends HystrixCommand<String> {
14

  
15
    RestTemplate restTemplate;
16
    String baseAddress;
17

  
18
    public AggregatorsHystrixCommand(String baseAddress, RestTemplate restTemplate) {
19
        super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
20
        this.baseAddress = baseAddress;
21
        this.restTemplate = restTemplate;
22
    }
23

  
24
    @Override
25
    protected String run() throws Exception {
26
        String url = baseAddress + "/resources" +
27
                "?query= " +
28
                " oaftype exact datasource and " +
29
                " ( datasourcetypename exact Institutional Repository Aggregator " +
30
                "     or datasourcetypename exact Publication Repository Aggregator )";
31

  
32
        UriComponents uriComponents = UriComponentsBuilder
33
                .fromHttpUrl(url)
34
                .queryParam("page", 0)
35
                .queryParam("size", 0)
36
                .queryParam("format", "json")
37
                .build().encode();
38

  
39
        ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
40
        Map metadata = (Map) ((Map) rs.getBody()).get("meta");
41
        return String.valueOf(metadata.get("total"));
42
    }
43

  
44
    @Override
45
    protected String getFallback() {
46
        return null;
47
    }
48
}
modules/uoa-repository-manager-service/tags/release-1.0.1/src/main/java/eu/dnetlib/repo/manager/service/customHystrixCommands/UsageStatsTotalHystrixCommand.java
1
package eu.dnetlib.repo.manager.service.customHystrixCommands;
2

  
3
import com.netflix.hystrix.HystrixCommand;
4
import com.netflix.hystrix.HystrixCommandGroupKey;
5
import org.springframework.http.HttpMethod;
6
import org.springframework.http.ResponseEntity;
7
import org.springframework.web.client.RestTemplate;
8
import org.springframework.web.util.UriComponents;
9
import org.springframework.web.util.UriComponentsBuilder;
10

  
11
import java.util.Map;
12

  
13
public class UsageStatsTotalHystrixCommand extends HystrixCommand<Integer> {
14

  
15
    RestTemplate restTemplate ;
16
    String usagestatsEvents;
17

  
18
    public UsageStatsTotalHystrixCommand(String usagestatsEvents,RestTemplate restTemplate) {
19
        super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
20
        this.usagestatsEvents = usagestatsEvents;
21
        this.restTemplate = restTemplate;
22
    }
23

  
24
    @Override
25
    protected Integer run() {
26
        UriComponents uriComponents = UriComponentsBuilder
27
                .fromHttpUrl(usagestatsEvents)
28
                .build().encode();
29

  
30
        ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET,null,Map.class);
31
        Map metadata = (Map) ((Map)rs.getBody()).get("totals");
32
//        String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
33
//        JSONObject resultSet = new JSONObject(rs);
34
//        JSONObject totals = resultSet.getJSONObject("totals");
35
        return (Integer) metadata.get("events");
36
    }
37

  
38
    @Override
39
    protected Integer getFallback() {
40
        return null;
41
    }
42

  
43
}
modules/uoa-repository-manager-service/tags/release-1.0.1/src/main/java/eu/dnetlib/repo/manager/service/customHystrixCommands/DatasetsHystrixCommand.java
1
package eu.dnetlib.repo.manager.service.customHystrixCommands;
2

  
3
import com.netflix.hystrix.HystrixCommand;
4
import com.netflix.hystrix.HystrixCommandGroupKey;
5
import org.springframework.http.HttpMethod;
6
import org.springframework.http.ResponseEntity;
7
import org.springframework.web.client.RestTemplate;
8
import org.springframework.web.util.UriComponents;
9
import org.springframework.web.util.UriComponentsBuilder;
10

  
11
import java.util.Map;
12

  
13
public class DatasetsHystrixCommand extends HystrixCommand<String> {
14

  
15
    RestTemplate restTemplate;
16
    String baseAddress;
17

  
18
    public DatasetsHystrixCommand(String baseAddress,RestTemplate restTemplate) {
19
        super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
20
        this.restTemplate = restTemplate;
21
        this.baseAddress = baseAddress;
22
    }
23

  
24
    @Override
25
    protected String run() throws Exception {
26
        String url = baseAddress+"/datasets/count";
27

  
28
        UriComponents uriComponents = UriComponentsBuilder
29
                .fromHttpUrl(url)
30
                .queryParam("page", 0)
31
                .queryParam("size", 0)
32
                .queryParam("format", "json")
33
                .build().encode();
34

  
35
        ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
36
        Map metadata = (Map) (rs.getBody());
37
        return String.valueOf(metadata.get("total"));
38
    }
39

  
40
    @Override
41
    protected String getFallback() {
42
        return null;
43
    }
44
}
modules/uoa-repository-manager-service/tags/release-1.0.1/src/main/java/eu/dnetlib/repo/manager/service/customHystrixCommands/LastYearUsageStatsHystrixCommand.java
1
package eu.dnetlib.repo.manager.service.customHystrixCommands;
2

  
3
import com.netflix.hystrix.HystrixCommand;
4
import com.netflix.hystrix.HystrixCommandGroupKey;
5
import org.springframework.http.HttpMethod;
6
import org.springframework.http.ResponseEntity;
7
import org.springframework.web.client.RestTemplate;
8
import org.springframework.web.util.UriComponents;
9
import org.springframework.web.util.UriComponentsBuilder;
10

  
11
import java.util.HashMap;
12
import java.util.List;
13
import java.util.Map;
14

  
15
public class LastYearUsageStatsHystrixCommand extends HystrixCommand<Map> {
16

  
17
    RestTemplate restTemplate;
18
    String usagestatsBaseAddress;
19

  
20
    public LastYearUsageStatsHystrixCommand(String usagestatsBaseAddress,RestTemplate restTemplate) {
21
        super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
22
        this.usagestatsBaseAddress = usagestatsBaseAddress;
23
        this.restTemplate = restTemplate;
24
    }
25

  
26
    @Override
27
    protected Map run() throws Exception {
28
        UriComponents uriComponents = UriComponentsBuilder
29
                .fromHttpUrl(usagestatsBaseAddress + "/totals")
30
                .build().encode();
31

  
32
        ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET,null,Map.class);
33

  
34
        List yearly_stats = (List) ((Map)rs.getBody()).get("yearly_stats");
35
        Map lastYear = (Map) yearly_stats.get(yearly_stats.size()-1);
36
        Integer downloads = (Integer) lastYear.get("downloads");
37
        Integer views = (Integer) lastYear.get("views");
38
        Integer year = (Integer) lastYear.get("year");
39

  
40
        Map<String,Object> usagestats = new HashMap<>();
41
        usagestats.put("number",String.valueOf(downloads+views));
42
        usagestats.put("year",year);
43

  
44
        return usagestats;
45
    }
46

  
47
    @Override
48
    protected Map getFallback() {
49
        return null;
50
    }
51

  
52
}
modules/uoa-repository-manager-service/tags/release-1.0.1/src/main/java/eu/dnetlib/repo/manager/service/customHystrixCommands/PublicationHystrixCommand.java
1
package eu.dnetlib.repo.manager.service.customHystrixCommands;
2

  
3
import com.netflix.hystrix.HystrixCommand;
4
import com.netflix.hystrix.HystrixCommandGroupKey;
5
import org.springframework.http.HttpMethod;
6
import org.springframework.http.ResponseEntity;
7
import org.springframework.web.client.RestTemplate;
8
import org.springframework.web.util.UriComponents;
9
import org.springframework.web.util.UriComponentsBuilder;
10

  
11
import java.util.Map;
12

  
13
public class PublicationHystrixCommand extends HystrixCommand<String> {
14

  
15
    RestTemplate restTemplate;
16
    private String baseAddress;
17

  
18
    public PublicationHystrixCommand(String baseAddress, RestTemplate restTemplate) {
19
        super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
20
        this.baseAddress = baseAddress;
21
        this.restTemplate = restTemplate;
22
    }
23

  
24
    @Override
25
    protected String run() throws Exception {
26
        String url = baseAddress + "/publications/count";
27

  
28
        UriComponents uriComponents = UriComponentsBuilder
29
                .fromHttpUrl(url)
30
                .queryParam("page", 0)
31
                .queryParam("size", 0)
32
                .queryParam("format", "json")
33
                .build().encode();
34

  
35
        ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
36
        Map metadata = (Map) (rs.getBody());
37
        return String.valueOf(metadata.get("total"));
38
    }
39

  
40
    @Override
41
    protected String getFallback() {
42
        return null;
43
    }
44

  
45
}
modules/uoa-repository-manager-service/tags/release-1.0.1/src/main/java/eu/dnetlib/repo/manager/service/customHystrixCommands/JournalHystrixCommand.java
1
package eu.dnetlib.repo.manager.service.customHystrixCommands;
2

  
3
import com.netflix.hystrix.HystrixCommand;
4
import com.netflix.hystrix.HystrixCommandGroupKey;
5
import org.springframework.http.HttpMethod;
6
import org.springframework.http.ResponseEntity;
7
import org.springframework.web.client.RestTemplate;
8
import org.springframework.web.util.UriComponents;
9
import org.springframework.web.util.UriComponentsBuilder;
10

  
11
import java.util.Map;
12

  
13
public class JournalHystrixCommand extends HystrixCommand<String> {
14

  
15
    RestTemplate restTemplate;
16
    private String baseAddress;
17

  
18
    public JournalHystrixCommand(String baseAddress, RestTemplate restTemplate) {
19
        super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
20
        this.baseAddress = baseAddress;
21
        this.restTemplate = restTemplate;
22
    }
23

  
24
    @Override
25
    protected String run() throws Exception {
26
        String url = baseAddress+"/resources"+
27
                "?query= " +
28
                " oaftype exact datasource and " +
29
                " datasourcetypename exact Journal";
30

  
31
        UriComponents uriComponents = UriComponentsBuilder
32
                .fromHttpUrl(url)
33
                .queryParam("page", 0)
34
                .queryParam("size", 0)
35
                .queryParam("format", "json")
36
                .build().encode();
37

  
38
        ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
39
        Map metadata = (Map) ((Map) rs.getBody()).get("meta");
40
        return String.valueOf(metadata.get("total"));
41
    }
42

  
43
    @Override
44
    protected String getFallback() {
45
        return null;
46
    }
47

  
48
}
modules/uoa-repository-manager-service/tags/release-1.0.1/src/main/java/eu/dnetlib/repo/manager/service/customHystrixCommands/SoftwareHystrixCommand.java
1
package eu.dnetlib.repo.manager.service.customHystrixCommands;
2

  
3
import com.netflix.hystrix.HystrixCommand;
4
import com.netflix.hystrix.HystrixCommandGroupKey;
5
import org.springframework.http.HttpMethod;
6
import org.springframework.http.ResponseEntity;
7
import org.springframework.web.client.RestTemplate;
8
import org.springframework.web.util.UriComponents;
9
import org.springframework.web.util.UriComponentsBuilder;
10

  
11
import java.util.Map;
12

  
13
public class SoftwareHystrixCommand extends HystrixCommand<String> {
14

  
15
    String baseAddress;
16
    RestTemplate restTemplate;
17

  
18
    public SoftwareHystrixCommand(String baseAddress, RestTemplate restTemplate) {
19
        super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
20
        this.baseAddress = baseAddress;
21
        this.restTemplate = restTemplate;
22
    }
23

  
24
    @Override
25
    protected String run() {
26
        String url = baseAddress + "/software/count";
27

  
28
        UriComponents uriComponents = UriComponentsBuilder
29
                .fromHttpUrl(url)
30
                .queryParam("page", 0)
31
                .queryParam("size", 0)
32
                .queryParam("format", "json")
33
                .build().encode();
34

  
35
        ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
36
        Map metadata = (Map) (rs.getBody());
37
        return String.valueOf(metadata.get("total"));
38
    }
39

  
40
    @Override
41
    protected String getFallback() {
42
        return null;
43
    }
44
}
modules/uoa-repository-manager-service/tags/release-1.0.1/src/main/java/eu/dnetlib/repo/manager/service/customHystrixCommands/LiteratureHystrixCommand.java
1
package eu.dnetlib.repo.manager.service.customHystrixCommands;
2

  
3
import com.netflix.hystrix.HystrixCommand;
4
import com.netflix.hystrix.HystrixCommandGroupKey;
5
import org.springframework.http.HttpMethod;
6
import org.springframework.http.ResponseEntity;
7
import org.springframework.web.client.RestTemplate;
8
import org.springframework.web.util.UriComponents;
9
import org.springframework.web.util.UriComponentsBuilder;
10

  
11
import java.util.Map;
12

  
13
public class LiteratureHystrixCommand extends HystrixCommand<String> {
14

  
15
    RestTemplate restTemplate;
16
    private String baseAddress;
17

  
18
    public LiteratureHystrixCommand(String baseAddress , RestTemplate restTemplate) {
19
        super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
20
        this.baseAddress = baseAddress;
21
        this.restTemplate = restTemplate;
22
    }
23

  
24
    @Override
25
    protected String run() throws Exception {
26
        String url = baseAddress+"/resources"+
27
                "?query= " +
28
                " oaftype exact datasource and " +
29
                " ( datasourcetypename exact Institutional Repository  " +
30
                "     or datasourcetypename exact Publication Repository )";
31

  
32
        UriComponents uriComponents = UriComponentsBuilder
33
                .fromHttpUrl(url)
34
                .queryParam("page", 0)
35
                .queryParam("size", 0)
36
                .queryParam("format", "json")
37
                .build().encode();
38

  
39
        ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
40
        Map metadata = (Map) ((Map) rs.getBody()).get("meta");
41
        return String.valueOf(metadata.get("total"));
42
    }
43

  
44
    @Override
45
    protected String getFallback() {
46
        return null;
47
    }
48

  
49
}
modules/uoa-repository-manager-service/tags/release-1.0.1/src/main/java/eu/dnetlib/repo/manager/service/customHystrixCommands/DataRepositoriesHystrixCommand.java
1
package eu.dnetlib.repo.manager.service.customHystrixCommands;
2

  
3
import com.netflix.hystrix.HystrixCommand;
4
import com.netflix.hystrix.HystrixCommandGroupKey;
5
import org.springframework.http.HttpMethod;
6
import org.springframework.http.ResponseEntity;
7
import org.springframework.web.client.RestTemplate;
8
import org.springframework.web.util.UriComponents;
9
import org.springframework.web.util.UriComponentsBuilder;
10

  
11
import java.util.Map;
12

  
13
public class DataRepositoriesHystrixCommand extends HystrixCommand<String> {
14

  
15
    RestTemplate restTemplate ;
16
    private String baseAddress;
17

  
18
    public DataRepositoriesHystrixCommand(String baseAddress,RestTemplate restTemplate) {
19
        super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
20
        this.baseAddress = baseAddress;
21
        this.restTemplate = restTemplate;
22
    }
23

  
24
    @Override
25
    protected String run() {
26
        String url = baseAddress+"/resources" +
27
                "?query= " +
28
                " oaftype exact datasource and " +
29
                " datasourcetypename exact Data Repository ";
30

  
31
        UriComponents uriComponents = UriComponentsBuilder
32
                .fromHttpUrl(url)
33
                .queryParam("page",0)
34
                .queryParam("size",0)
35
                .queryParam("format","json")
36
                .build().encode();
37

  
38
        ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET,null,Map.class);
39
        Map metadata = (Map) ((Map)rs.getBody()).get("meta");
40
        return String.valueOf(metadata.get("total"));
41
    }
42

  
43
    @Override
44
    protected String getFallback() {
45
        return null;
46
    }
47
}
modules/uoa-repository-manager-service/tags/release-1.0.1/src/main/java/eu/dnetlib/repo/manager/service/MonitorService.java
1
package eu.dnetlib.repo.manager.service;
2

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

  
11

  
12
public interface MonitorService {
13

  
14

  
15
    JobsOfUser getJobsOfUser(String user,
16
                             String jobType,
17
                             String offset,
18
                             String limit,
19
                             String dateFrom,
20
                             String dateTo,
21
                             String validationStatus,
22
                             String includeJobsTotal) throws JSONException, ValidatorServiceException;
23

  
24
    int getJobsOfUserPerValidationStatus(String user,
25
                                         String jobType,
26
                                         String validationStatus) throws JSONException;
27

  
28

  
29
    StoredJob getJobSummary(String jobId,
30
                            String groupBy) throws JSONException;
31

  
32
}
modules/uoa-repository-manager-service/tags/release-1.0.1/src/main/java/eu/dnetlib/repo/manager/service/EmailUtils.java
1
package eu.dnetlib.repo.manager.service;
2

  
3
import eu.dnetlib.domain.data.PiwikInfo;
4
import eu.dnetlib.domain.data.Repository;
5
import eu.dnetlib.domain.functionality.validator.JobForValidation;
6
import org.springframework.security.core.Authentication;
7

  
8
public interface EmailUtils {
9

  
10

  
11
    void reportException(Exception exception);
12

  
13
    void sendAdministratorRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception;
14

  
15
    void sendUserRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception;
16

  
17
    void sendAdministratorMetricsEnabled(PiwikInfo piwikInfo) throws Exception;
18

  
19
    void sendUserMetricsEnabled(PiwikInfo piwikInfo) throws Exception;
20

  
21
    void sendUserRegistrationEmail(Repository repository, Authentication authentication) throws Exception;
22

  
23
    void sendUserUpdateRepositoryEmail(Repository repository, Authentication authentication) throws Exception;
24

  
25
    void sendSubmitJobForValidationEmail(Authentication authentication, JobForValidation jobForValidation) throws Exception;
26
}
modules/uoa-repository-manager-service/tags/release-1.0.1/src/main/java/eu/dnetlib/repo/manager/service/SushiliteServiceImpl.java
1
package eu.dnetlib.repo.manager.service;
2

  
3
import eu.dnetlib.usagestats.sushilite.domain.ReportItem;
4
import eu.dnetlib.usagestats.sushilite.domain.ReportResponseWrapper;
5
import org.springframework.beans.factory.annotation.Autowired;
6
import org.springframework.beans.factory.annotation.Value;
7
import org.springframework.core.ParameterizedTypeReference;
8
import org.springframework.http.HttpMethod;
9
import org.springframework.http.ResponseEntity;
10
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
11
import org.springframework.security.access.prepost.PreAuthorize;
12
import org.springframework.stereotype.Service;
13
import org.springframework.web.bind.annotation.PathVariable;
14
import org.springframework.web.bind.annotation.RequestParam;
15
import org.springframework.web.client.RestClientException;
16
import org.springframework.web.client.RestTemplate;
17
import org.springframework.web.util.UriComponentsBuilder;
18

  
19
import java.util.ArrayList;
20
import java.util.List;
21

  
22
@Service("sushiliteService")
23
public class SushiliteServiceImpl implements SushiliteService {
24

  
25

  
26
    @Value("${services.repomanager.usagestats.sushiliteEndpoint}")
27
    private String usagestatsSushiliteEndpoint;
28

  
29
    @Autowired
30
    private EmailUtils emailUtils;
31

  
32
    private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger.getLogger(SushiliteServiceImpl.class);
33

  
34

  
35
    @Override
36
    @PreAuthorize("hasRole('ROLE_USER')")
37
    public ReportResponseWrapper getReportResults(@PathVariable("page") String page,
38
                                                  @PathVariable("pageSize") String pageSize,
39
                                                  @RequestParam(value = "Report") String Report,
40
                                                  @RequestParam(value = "Release",defaultValue="4") String Release,
41
                                                  @RequestParam(value = "RequestorID",required=false,defaultValue="anonymous") String RequestorID,
42
                                                  @RequestParam(value = "BeginDate",required=false,defaultValue="") String BeginDate,
43
                                                  @RequestParam(value = "EndDate",required=false,defaultValue="") String EndDate,
44
                                                  @RequestParam(value = "RepositoryIdentifier") String RepositoryIdentifier,
45
                                                  @RequestParam(value = "ItemIdentifier",required=false,defaultValue="") String ItemIdentifier,
46
                                                  @RequestParam(value = "ItemDataType",required=false,defaultValue="") String ItemDataType,
47
                                                  @RequestParam(value = "Granularity") String Granularity,
48
                                                  @RequestParam(value = "Pretty",required=false,defaultValue="") String Pretty) {
49

  
50
            //build the uri params
51
            UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.usagestatsSushiliteEndpoint + "GetReport/")
52
                                                                .queryParam("Report", Report)
53
                                                                .queryParam("Release", Release)
54
                                                                .queryParam("RequestorID", RequestorID)
55
                                                                .queryParam("BeginDate", BeginDate)
56
                                                                .queryParam("EndDate", EndDate)
57
                                                                .queryParam("RepositoryIdentifier", RepositoryIdentifier)
58
                                                                .queryParam("ItemIdentifier", ItemIdentifier)
59
                                                                .queryParam("ItemDataType", ItemDataType)
60
                                                                .queryParam("Granularity", Granularity)
61
                                                                .queryParam("Pretty", Pretty);
62

  
63
            //create new template engine
64
            RestTemplate template = new RestTemplate();
65
            template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
66

  
67
            ResponseEntity<ReportResponseWrapper> resp;
68
            try {
69
                //communicate with endpoint
70
                resp = template.exchange(
71
                        builder.build().encode().toUri(),
72
                        HttpMethod.GET,
73
                        null,
74
                        new ParameterizedTypeReference<ReportResponseWrapper>() {
75
                        });
76
            } catch (RestClientException e) {
77
                LOGGER.debug("Exception on getReportResults" , e);
78
                emailUtils.reportException(e);
79
                throw e;
80
            }
81

  
82
            // check remote api's response
83
            System.out.println("sushi responded status " + resp.getStatusCode());
84

  
85
            // get the items corresponding to the requested page
86
            List<ReportItem> requestedItemList = new ArrayList<>();
87
            if (resp.getBody().getReportResponse().getReportWrapper().getReport().getCustomer().getReportItems() != null) {
88
                try {
89
                    int totalItems = resp.getBody().getReportResponse().getReportWrapper().getReport().getCustomer().getReportItems().size();
90
                    int size = Integer.parseInt(pageSize);
91
                    int offset = Integer.parseInt(page)*size;
92

  
93
                    if (offset < totalItems ) {
94
                        int upperIndex = offset+size;
95
                        if (upperIndex > totalItems) {
96
                            upperIndex = totalItems;
97
                        }
98
                        requestedItemList = resp.getBody().getReportResponse().getReportWrapper().getReport().getCustomer().getReportItems().subList(offset,upperIndex);
99
                    }
100

  
101
                } catch (NumberFormatException e) {
102
                    LOGGER.debug("Exception on getReportResults - trying to cast strings to integers", e);
103
                    //emailUtils.reportException(e);
104
                    throw e;
105
                }
106

  
107
            }
108

  
109
            ReportResponseWrapper newReportResponse = resp.getBody();
110
            newReportResponse.getReportResponse().getReportWrapper().getReport().getCustomer().setReportItems(requestedItemList);
111

  
112

  
113
            return newReportResponse;
114
    }
115

  
116
}
modules/uoa-repository-manager-service/tags/release-1.0.1/src/main/java/eu/dnetlib/repo/manager/service/StatsService.java
1
package eu.dnetlib.repo.manager.service;
2

  
3
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
4
import eu.dnetlib.repo.manager.exception.EndPointException;
5
import org.json.JSONException;
6

  
7
import java.util.Map;
8

  
9

  
10
public interface StatsService {
11

  
12
    Map getStatistics() ;
13
}
modules/uoa-repository-manager-service/tags/release-1.0.1/src/main/java/eu/dnetlib/repo/manager/service/UserServiceImpl.java
1
package eu.dnetlib.repo.manager.service;
2

  
3
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
4
import org.springframework.beans.factory.annotation.Value;
5
import org.springframework.http.HttpStatus;
6
import org.springframework.http.ResponseEntity;
7
import org.springframework.security.core.GrantedAuthority;
8
import org.springframework.security.core.context.SecurityContextHolder;
9
import org.springframework.stereotype.Service;
10

  
11
import java.util.HashMap;
12
import java.util.List;
13
import java.util.Map;
14
import java.util.stream.Collectors;
15

  
16
@Service("userService")
17
public class UserServiceImpl implements UserService {
18

  
19
    private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
20
            .getLogger(UserServiceImpl.class);
21

  
22
    @Value("${oidc.issuer}")
23
    private String oidc_issuer;
24

  
25
    @Override
26
    public ResponseEntity<Object> login() {
27
        OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
28
        LOGGER.debug("User authentication : " + authentication);
29
        Map<String,Object> body = new HashMap<>();
30
        body.put("sub",authentication.getSub());
31
        if(authentication.getUserInfo().getName() == null || authentication.getUserInfo().getName().equals(""))
32
            body.put("name",authentication.getUserInfo().getGivenName() + " " + authentication.getUserInfo().getFamilyName());
33
        else
34
            body.put("name",authentication.getUserInfo().getName());
35

  
36
        body.put("email",authentication.getUserInfo().getEmail());
37
        List<String> roles = authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList());
38
        body.put("role",roles);
39

  
40
        return new ResponseEntity<>(body, HttpStatus.OK);
41
    }
42
}
modules/uoa-repository-manager-service/tags/release-1.0.1/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java
1
package eu.dnetlib.repo.manager.service;
2

  
3
import com.fasterxml.jackson.core.JsonProcessingException;
4
import com.fasterxml.jackson.databind.ObjectMapper;
5
import com.fasterxml.jackson.databind.SerializationFeature;
6
import eu.dnetlib.domain.data.Repository;
7
import eu.dnetlib.domain.data.RepositoryInterface;
8
import eu.dnetlib.domain.enabling.Vocabulary;
9
import eu.dnetlib.repo.manager.domain.RepositorySnippet;
10
import eu.dnetlib.repo.manager.domain.RequestFilter;
11
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
12
import eu.dnetlib.repo.manager.shared.*;
13
import eu.dnetlib.repo.manager.utils.Converter;
14
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader;
15
import org.apache.commons.codec.digest.DigestUtils;
16
import org.apache.log4j.Logger;
17
import org.json.JSONArray;
18
import org.json.JSONException;
19
import org.json.JSONObject;
20
import org.springframework.beans.factory.annotation.Autowired;
21
import org.springframework.beans.factory.annotation.Value;
22
import org.springframework.core.ParameterizedTypeReference;
23
import org.springframework.http.*;
24
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
25
import org.springframework.security.core.Authentication;
26
import org.springframework.security.core.context.SecurityContextHolder;
27
import org.springframework.stereotype.Service;
28
import org.springframework.web.bind.annotation.PathVariable;
29
import org.springframework.web.bind.annotation.RequestBody;
30
import org.springframework.web.bind.annotation.RequestParam;
31
import org.springframework.web.client.RestClientException;
32
import org.springframework.web.client.RestTemplate;
33
import org.springframework.web.util.UriComponents;
34
import org.springframework.web.util.UriComponentsBuilder;
35

  
36
import javax.annotation.PostConstruct;
37
import java.io.IOException;
38
import java.sql.Timestamp;
39
import java.util.*;
40
import java.util.concurrent.ConcurrentHashMap;
41
import java.util.stream.Collectors;
42

  
43
@Service("repositoryService")
44
public class RepositoryServiceImpl implements RepositoryService {
45

  
46
    @Value("${api.baseAddress}")
47
    private String baseAddress;
48

  
49
    @Autowired
50
    RestTemplate restTemplate;
51

  
52
    private HttpHeaders httpHeaders;
53

  
54
    private final String[] vocabularyNames = {"dnet:countries", "dnet:datasource_typologies", "dnet:compatibilityLevel"};
55

  
56
    private static final Logger LOGGER = Logger.getLogger(RepositoryServiceImpl.class);
57

  
58
    @Value("${services.repomanager.usageStatisticsDiagramsBaseURL}")
59
    private String usageStatisticsDiagramsBaseURL;
60

  
61
    @Value("${services.repomanager.usageStatisticsNumbersBaseURL}")
62
    private String usageStatisticsNumbersBaseURL;
63

  
64
    @Autowired
65
    private VocabularyLoader vocabularyLoader;
66

  
67
    @Autowired
68
    private PiWikService piWikService;
69

  
70
    @Autowired
71
    private EmailUtils emailUtils;
72

  
73

  
74
    private Map<String, Vocabulary> vocabularyMap = new ConcurrentHashMap<String, Vocabulary>();
75

  
76
    private Map<String, String> countriesMap = new HashMap<>();
77
    private Map<String, String> inverseCountriesMap = new HashMap<>();
78

  
79
    private static Map<String,List<String>> dataSourceClass = new HashMap<String,List<String>>(){{
80
        put("opendoar",new ArrayList<String>(){{ add("pubsrepository::institutional");
81
                                                    add("pubsrepository::thematic");
82
                                                    add("pubsrepository::unknown");
83
                                                    add("pubsrepository::mock");
84
        }});
85
        put("re3data",new ArrayList<String>(){{ add("datarepository::unknown");
86
        }});
87
        put("journal",new ArrayList<String>(){{ add("pubsrepository::journal");
88
        }});
89
        put("aggregator",new ArrayList<String>(){{ add("aggregator::pubsrepository::institutional");
90
                                                        add("aggregator::pubsrepository::journals");
91
                                                        add("aggregator::datarepository");
92
                                                        add("aggregator::pubsrepository::unknown");
93
        }});
94
    }};
95

  
96
    private static Map<String,String> invertedDataSourceClass = new HashMap<String,String>(){{
97
        put("pubsrepository::institutional","opendoar");
98
        put("pubsrepository::thematic","opendoar");
99
        put("pubsrepository::unknown","opendoar");
100
        put("pubsrepository::mock","opendoar");
101

  
102
        put("datarepository::unknown","re3data");
103

  
104
        put("pubsrepository::journal","journal");
105

  
106
        put("aggregator::pubsrepository::institutional","aggregator");
107
        put("aggregator::pubsrepository::journals","aggregator");
108
        put("aggregator::datarepository","aggregator");
109
        put("aggregator::pubsrepository::unknown","aggregator");
110

  
111
    }};
112

  
113

  
114

  
115
    @PostConstruct
116
    private void init() {
117
        LOGGER.debug("Initialization method of repository api!");
118
        LOGGER.debug("Updated version!");
119

  
120
        httpHeaders = new HttpHeaders();
121
        httpHeaders.set("Content-Type", "application/json");
122

  
123
        for (String vocName : vocabularyNames) {
124
            vocabularyMap.put(vocName, vocabularyLoader.getVocabulary(vocName, Locale.ENGLISH, Locale.ROOT));
125
        }
126

  
127
        Country[] countries = getCountries();
128
        for (Country c : countries) {
129
            countriesMap.put(c.getName(), c.getCode());
130
            inverseCountriesMap.put(c.getCode(), c.getName());
131
        }
132

  
133

  
134
    }
135

  
136
    @Override
137
    public Country[] getCountries() {
138
        UriComponents uriComponents = UriComponentsBuilder
139
                .fromHttpUrl(baseAddress + "/ds/countries")
140
                .build().encode();
141
        return restTemplate.getForObject(uriComponents.toUri(), Country[].class);
142
    }
143

  
144

  
145
    @Override
146
    public List<RepositorySnippet> getRepositoriesByCountry(@PathVariable("country") String country,
147
                                                            @PathVariable("mode") String mode,
148
                                                            @RequestParam(value = "managed",required=false) Boolean managed) throws JSONException, IOException {
149

  
150
        LOGGER.debug("Getting repositories by country!");
151
        int page = 0;
152
        int size = 100;
153
        List<RepositorySnippet> resultSet = new ArrayList<>();
154
        ObjectMapper mapper = new ObjectMapper();
155

  
156
        String filterKey = "UNKNOWN";
157
        if (mode.equalsIgnoreCase("opendoar"))
158
            filterKey = "openaire____::opendoar";
159
        else if (mode.equalsIgnoreCase("re3data"))
160
            filterKey = "openaire____::re3data";
161

  
162

  
163
        LOGGER.debug("Country code equals : " + country);
164
        LOGGER.debug("Filter mode equals : " + filterKey);
165

  
166
        UriComponents uriComponents = searchSnipperDatasource(String.valueOf(page),String.valueOf(size));
167
        RequestFilter requestFilter = new RequestFilter();
168
        requestFilter.setCountry(country);
169
        requestFilter.setCollectedfrom(filterKey);
170

  
171
        try{
172
            String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
173
            JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
174
            while (jsonArray.length() > 0 ) {
175
                resultSet.addAll(mapper.readValue(String.valueOf(jsonArray),
176
                        mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
177
                page += 1;
178
                uriComponents = searchSnipperDatasource(String.valueOf(page),String.valueOf(size));
179
                rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
180
                jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
181
            }
182
            return resultSet;
183
        }catch (Exception e){
184
            LOGGER.debug("Exception on getRepositoriesByCountry" , e);
185
//            emailUtils.reportException(e);
186
            throw e;
187
        }
188

  
189

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

Also available in: Unified diff