Project

General

Profile

« Previous | Next » 

Revision 49813

1. New method ( delete repository interface ) on repo api.
2. New method ( get ruleset with acronym ) on validator api.
3. Log messages in every api.

View differences:

modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/utils/Converter.java
193 193
        ArrayList<String> list = new ArrayList<String>();
194 194
        try {
195 195
            //InputStream in = Converter.class.getResourceAsStream("resources/eu/dnetlib/repo/manager/service/utils/"+filename);
196
            InputStream in = Converter.class.getClass().getResourceAsStream(filename);
196
            InputStream in = Converter.class.getClass().getResourceAsStream("/eu/**/" + filename);
197 197
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
198 198
            while((line = br.readLine()) != null) {
199 199
                list.add(line.trim());
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/ValidatorApi.java
29 29
    @ResponseBody
30 30
    List<String> getSetsOfRepository(@RequestBody String url);
31 31

  
32
    @RequestMapping(value = "/identifyRepository/{url}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
33
    @ResponseBody
34
    boolean identifyRepo(String url);
32 35

  
36
    @RequestMapping(value = "/getRuleSet/{acronym}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
37
    @ResponseBody
38
    RuleSet getRuleSet(String acronym);
33 39

  
34

  
35 40
}
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/ValidatorApiImpl.java
3 3
import eu.dnetlib.api.functionality.ValidatorServiceException;
4 4
import eu.dnetlib.domain.functionality.validator.StoredJob;
5 5
import eu.dnetlib.repo.manager.service.utils.OaiTools;
6
import eu.dnetlib.repo.manager.shared.ValidationServiceException;
6 7
import gr.uoa.di.driver.util.ServiceLocator;
7 8
import eu.dnetlib.domain.functionality.validator.JobForValidation;
8 9
import eu.dnetlib.domain.functionality.validator.RuleSet;
......
16 17
import org.springframework.beans.factory.annotation.Autowired;
17 18
import org.springframework.stereotype.Component;
18 19
import org.springframework.web.bind.annotation.PathVariable;
20
import sun.rmi.runtime.Log;
19 21

  
20 22
import javax.annotation.PostConstruct;
21 23
import javax.annotation.Resource;
......
49 51

  
50 52
    @PostConstruct
51 53
    private void loadRules(){
52

  
54
        LOGGER.debug("PostConstruct method! Load rules!");
53 55
        try {
54 56
            for (RuleSet ruleSet : getValidationService().getRuleSets()) {
55 57
                if (ruleSet.getVisibility() != null && ruleSet.getVisibility().contains("development")) {
......
78 80

  
79 81
    @Override
80 82
    public void submitJobForValidation(JobForValidation jobForValidation) {
83
        LOGGER.debug("Submit job for validation with id : " + jobForValidation.getDatasourceId());
81 84
        try {
82 85
            this.getValidationService().submitValidationJob(jobForValidation);
83 86
        } catch (ValidatorServiceException e) {
......
87 90

  
88 91
    @Override
89 92
    public void reSubmitJobForValidation(String jobId) throws JSONException {
90

  
93
        LOGGER.debug("Resubmit validation job with id : " + jobId);
91 94
        StoredJob job = monitorApi.getJobSummary(jobId,"all");
92 95
        Set<Integer> contentRules = new HashSet<Integer>();
93 96
        Set<Integer> usageRules = new HashSet<Integer>();
......
116 119

  
117 120
    @Override
118 121
    public List<RuleSet> getRuleSets(@PathVariable("mode") String mode) {
122
        LOGGER.info("Getting rulesets for mode: " + mode);
119 123
        return rulesetMap.get(mode);
120 124
    }
121 125

  
122 126
    @Override
123 127
    public List<String> getSetsOfRepository(String url) {
128
        LOGGER.debug("Getting sets of repository with url : " + url);
124 129
        try {
125 130
            return OaiTools.getSetsOfRepo(url);
126 131
        } catch (Exception e) {
......
129 134
        return null;
130 135
    }
131 136

  
137
    @Override
138
    public boolean identifyRepo(String url) {
139
        LOGGER.debug("Identify repository with url : " + url);
140
        try {
141
            return OaiTools.identifyRepository(url);
142
        } catch (Exception e) {
143
            LOGGER.error("Error while identifying repository with url: " + url, e);
144
            return false;
145
        }
146
    }
147

  
148
    @Override
149
    public RuleSet getRuleSet(String acronym) {
150
        LOGGER.debug("Getting ruleset with acronym : " + acronym);
151
        RuleSet ruleSet = null;
152
        try {
153
            for (List<RuleSet> ruleSets : this.rulesetMap.values()) {
154
                for (RuleSet rSet : ruleSets)
155
                    if (rSet.getGuidelinesAcronym().equals(acronym)) {
156
                        ruleSet = rSet;
157
                        break;
158
                    }
159
            }
160
            return ruleSet;
161
        } catch (Exception e) {
162
            LOGGER.error("Error getting ruleset", e);
163
            return null;
164
        }
165
    }
166

  
132 167
}
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/MonitorApiImpl.java
43 43
                                         String validationStatus,
44 44
                                         String includeJobsTotal) throws JSONException, ValidatorServiceException {
45 45

  
46
        if (jobType.equals(""))
47
            jobType = null;
48
        if(dateFrom.equals(""))
49
            dateFrom = null;
50
        if(dateTo.equals(""))
51
            dateTo = null;
52
        if(validationStatus.equals(""))
53
            validationStatus = null;
54

  
55

  
46
        LOGGER.debug("Getting jobs of user : " + user);
56 47
        JobsOfUser retJobs = new JobsOfUser();
57 48
        retJobs.setJobs(getValidationService().getStoredJobsNew(user, jobType, Integer.parseInt(offset),
58 49
                Integer.parseInt(limit), dateFrom, dateTo, validationStatus));
......
74 65
    public int getJobsOfUserPerValidationStatus(String user,
75 66
                                                String jobType,
76 67
                                                String validationStatus) throws JSONException {
77

  
68
        LOGGER.debug("Getting job with validation status : " + validationStatus);
78 69
        try {
79 70
            return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus);
80 71
        } catch (ValidatorServiceException e) {
......
86 77
    @Override
87 78
    public StoredJob getJobSummary(String jobId,
88 79
                                   String groupBy) throws JSONException {
89

  
80
        LOGGER.debug("Getting job summary with id : " + jobId);
90 81
        try {
91 82
            return getValidationService().getStoredJob(Integer.parseInt(jobId), groupBy);
92 83
        } catch (ValidatorServiceException e) {
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApi.java
5 5
import eu.dnetlib.repo.manager.shared.*;
6 6
import org.json.JSONException;
7 7
import org.springframework.http.MediaType;
8
import org.springframework.web.bind.annotation.RequestMapping;
9
import org.springframework.web.bind.annotation.RequestMethod;
10
import org.springframework.web.bind.annotation.ResponseBody;
11
import org.springframework.web.bind.annotation.RestController;
8
import org.springframework.web.bind.annotation.*;
9

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

  
......
66 64
    @ResponseBody
67 65
    String addRepository(Repository repository) throws JSONException;
68 66

  
67
    @RequestMapping(value = "/deleteInterface", method = RequestMethod.DELETE)
68
    @ResponseBody
69
    void deleteRepositoryInterface(String id);
70

  
69 71
    @RequestMapping(value = "/addInterface", method = RequestMethod.POST,
70 72
            consumes = MediaType.APPLICATION_JSON_VALUE)
71 73
    @ResponseBody
72
    String addRepositoryInterface(RepositoryInterface repositoryInterface) throws JSONException;
74
    RepositoryInterface addRepositoryInterface(RepositoryInterface repositoryInterface) throws JSONException;
73 75

  
74 76
    @RequestMapping(value = "/getDnetCountries", method = RequestMethod.GET,
75 77
            produces = MediaType.APPLICATION_JSON_VALUE)
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApiImpl.java
115 115
        int page = 1;
116 116
        int size = 10;
117 117
        String countryCode = getCountryCode(country);
118
        String filterKey = "UNKNOWN";
119
        if(mode.equalsIgnoreCase("opendoar")) {
120
            filterKey = "openaire____::opendoar";
121
        } else if(mode.equalsIgnoreCase("re3data")) {
122
            filterKey = "openaire____::re3data";
123
        } else if(mode.equalsIgnoreCase("jour_aggr")) {
124
            filterKey = "infrastruct_::openaire";
125
        }
118 126

  
119

  
120 127
        LOGGER.debug("Country code equals : " + countryCode);
128
        LOGGER.debug("Filter mode equals : " + filterKey);
121 129
        UriComponents uriComponents = UriComponentsBuilder
122 130
                                            .fromHttpUrl(baseAddress + "/ds/search/country/")
123 131
                                            .path("/{page}/{size}/")
124
                                            .queryParam("country",country)
132
                                            .queryParam("country",countryCode)
125 133
                                            .build().expand(page,size).encode();
126 134

  
127 135
        String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
......
129 137
        while(!rs.equals("[]")){
130 138
            List<Repository> rep = Converter.jsonToRepositoryList(new JSONArray(rs));
131 139

  
132
            Collection<Repository> repos = this.getRepositoriesByMode(mode,rep);
133
            //this.addRepos(repIDs,repos);
134
            resultSet.addAll(repos);
140
            Collection<Repository> repos = this.getRepositoriesByMode(filterKey,rep);
141
            this.addRepos(resultSet,repos);
142
            //resultSet.addAll(repos);
135 143

  
136 144
            page+=1;
137 145
            uriComponents = UriComponentsBuilder
......
153 161
        return country;
154 162
    }
155 163

  
156
    private void addRepos(Set<String> resultSet, Collection<String> repos) {
157
        for(String s : repos)
158
            if(!resultSet.contains(s))
159
                resultSet.add(s);
164
    private void addRepos(List<Repository> resultSet, Collection<Repository> repos) {
165
        for(Repository r : repos)
166
            if(!resultSet.contains(r))
167
                resultSet.add(r);
160 168
    }
161 169

  
162 170
    private Collection<Repository> getRepositoriesByMode(String mode, List<Repository> rs) {
163 171

  
164 172
        List<Repository> reps = new ArrayList<>();
165

  
166
        for(Repository r : rs)
173
        for(Repository r : rs){
167 174
            if(r.getCollectedFrom().equals(mode))
168 175
                reps.add(r);
169

  
176
        }
170 177
        return reps;
171 178
    }
172 179

  
......
235 242
    public RepositoryInterface getRepositoyInterface(@PathVariable("id") String id) throws JSONException {
236 243

  
237 244
        UriComponents uriComponents = UriComponentsBuilder
238
                .fromHttpUrl(baseAddress + "/ds/service/")
245
                .fromHttpUrl(baseAddress + "/ds/api/")
239 246
                .path("/{id}/")
240 247
                .build().expand(id).encode();
241 248

  
......
253 260
    }
254 261

  
255 262
    @Override
256
    public String addRepositoryInterface(RepositoryInterface repositoryInterface) throws JSONException {
263
    public void deleteRepositoryInterface(@PathVariable("id") String id){
257 264
        UriComponents uriComponents = UriComponentsBuilder
258
                .fromHttpUrl(baseAddress + "/ds/service/add/")
265
                .fromHttpUrl(baseAddress + "/ds/api/")
266
                .path("/{id}/")
267
                .build().expand(id).encode();
268
        restTemplate.delete(uriComponents.toUri());
269
    }
270

  
271
    @Override
272
    public RepositoryInterface addRepositoryInterface(RepositoryInterface iFace) throws JSONException {
273

  
274
        UriComponents uriComponents = UriComponentsBuilder
275
                .fromHttpUrl(baseAddress + "/ds/api/add/")
259 276
                .build()
260 277
                .encode();
261
        return restTemplate.postForObject(uriComponents.toUri(), Converter.repositoryInterfaceObjectToJson(repositoryInterface),String.class);
278
        String rs =  restTemplate.postForObject(uriComponents.toUri(), Converter.repositoryInterfaceObjectToJson(iFace),String.class);
279
        return Converter.jsonToRepositoryInterfaceObject(new JSONArray(rs).getJSONObject(0));
262 280
    }
263 281

  
264 282
    @Override

Also available in: Unified diff