Project

General

Profile

« Previous | Next » 

Revision 56636

View differences:

RepositoryServiceImpl.java
3 3
import com.fasterxml.jackson.core.JsonProcessingException;
4 4
import com.fasterxml.jackson.databind.ObjectMapper;
5 5
import com.fasterxml.jackson.databind.SerializationFeature;
6
import eu.dnetlib.api.functionality.ValidatorServiceException;
6 7
import eu.dnetlib.domain.data.Repository;
7 8
import eu.dnetlib.domain.data.RepositoryInterface;
8 9
import eu.dnetlib.domain.enabling.Vocabulary;
10
import eu.dnetlib.domain.functionality.validator.JobForValidation;
9 11
import eu.dnetlib.repo.manager.domain.RepositorySnippet;
10 12
import eu.dnetlib.repo.manager.domain.RequestFilter;
11 13
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
12 14
import eu.dnetlib.repo.manager.shared.*;
13 15
import eu.dnetlib.repo.manager.utils.Converter;
14 16
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader;
17
import gr.uoa.di.driver.xml.repository.INTERFACE;
15 18
import org.apache.commons.codec.digest.DigestUtils;
16 19
import org.apache.log4j.Logger;
17 20
import org.json.JSONArray;
......
46 49
    @Value("${api.baseAddress}")
47 50
    private String baseAddress;
48 51

  
52
    @Value("${services.repo-manager.adminEmail}")
53
    private String adminEmail;
54

  
49 55
    @Autowired
50 56
    RestTemplate restTemplate;
51 57

  
......
70 76
    @Autowired
71 77
    private EmailUtils emailUtils;
72 78

  
79
    @Autowired
80
    ValidatorService validatorService;
73 81

  
82

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

  
76 85
    private Map<String, String> countriesMap = new HashMap<>();
......
185 194
//            emailUtils.reportException(e);
186 195
            throw e;
187 196
        }
197
    }
188 198

  
199
    public List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName,
200
            String officialName, String requestSortBy, String order, int page, int pageSize) throws Exception {
189 201

  
202
        LOGGER.debug("Searching registered repositories");
203

  
204
        List<RepositorySnippet> resultSet = new ArrayList<>();
205
        ObjectMapper mapper = new ObjectMapper();
206

  
207
        UriComponents uriComponents = searchRegisteredDatasource(requestSortBy, order, Integer.toString(page), Integer.toString(pageSize));
208

  
209
        RequestFilter requestFilter = new RequestFilter();
210
        requestFilter.setCountry(country);
211
        requestFilter.setTypology(typology);
212
        requestFilter.setOfficialname(officialName);
213
        requestFilter.setEnglishname(englishName);
214

  
215
        try {
216
            String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
217
            JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
218

  
219
            resultSet.addAll(mapper.readValue(String.valueOf(jsonArray),  mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
220

  
221
             return resultSet;
222
        }catch (Exception e){
223
            LOGGER.error("Error searching registered datasources" , e);
224
            throw e;
225
        }
190 226
    }
191 227

  
192 228
    private Repository updateRepositoryInfo(Repository r) throws JSONException {
......
411 447
            String json_repository = Converter.repositoryObjectToJson(repository);
412 448
            LOGGER.debug("JSON to add(update) -> " + json_repository);
413 449

  
450
//
451
//            // TODO delete these 3 lines
452
//            HttpHeaders temp = new HttpHeaders();
453
//            temp.setContentType(MediaType.APPLICATION_JSON_UTF8);
454

  
414 455
            HttpEntity<String> httpEntity = new HttpEntity<String>(json_repository, httpHeaders);
415 456
            ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(),HttpMethod.POST, httpEntity, ResponseEntity.class);
416 457

  
417 458
            if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
418 459
                emailUtils.sendUserRegistrationEmail(repository, authentication);
419
            }else
460
                emailUtils.sendAdminRegistrationEmail(repository, authentication);
461
            } else
420 462
                LOGGER.debug(responseEntity.getBody().toString());
421 463

  
422 464
            return repository;
......
442 484
            LOGGER.debug("JSON to update -> " + json_repository);
443 485

  
444 486
            HttpEntity<String> httpEntity = new HttpEntity<String>(json_repository, httpHeaders);
445
            ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(),HttpMethod.POST, httpEntity, ResponseEntity.class);
487
            ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(),HttpMethod.POST, httpEntity
488
                    , ResponseEntity.class);
446 489

  
447
            if (responseEntity.getStatusCode().equals(HttpStatus.OK))
490
            if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
448 491
                emailUtils.sendUserUpdateRepositoryEmail(repository, authentication);
449
            else
492
                emailUtils.sendAdminUpdateRepositoryEmail(repository, authentication);
493
            } else
450 494
                LOGGER.debug(responseEntity.getBody().toString());
451 495

  
452 496
            return repository;
......
498 542
        HttpEntity<String> httpEntity = new HttpEntity <String> (json_repository,httpHeaders);
499 543
        ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(),HttpMethod.POST, httpEntity, ResponseEntity.class);
500 544

  
501
        if(responseEntity.getStatusCode().equals(HttpStatus.OK))
502
            emailUtils.sendUserRegistrationEmail(repository,authentication);
503
        else {
545
        if(responseEntity.getStatusCode().equals(HttpStatus.OK)) {
546
            emailUtils.sendUserRegistrationEmail(repository, authentication);
547
            emailUtils.sendAdminRegistrationEmail(repository, authentication);
548
        } else {
504 549
            LOGGER.debug(responseEntity.getBody().toString());
505 550
        }
506 551
    }
......
542 587
        }
543 588
    }
544 589

  
590
    @Override
591
    public RepositoryInterface updateRepositoryInterface(@RequestParam("repoId") String repoId,
592
                                                         @RequestParam("registeredBy") String registeredBy,
593
                                                         @RequestBody RepositoryInterface repositoryInterface) throws Exception {
594

  
595
        this.updateBaseUrl(repoId,repositoryInterface.getId(),repositoryInterface.getBaseUrl());
596
        this.updateCompliance(repoId,repositoryInterface.getId(),repositoryInterface.getCompliance());
597
        this.updateValidationSet(repoId,repositoryInterface.getId(),repositoryInterface.getAccessSet());
598
        return repositoryInterface;
599
    }
600

  
601
    private void submitInterfaceValidation(Repository repo, String repoType, String userEmail, RepositoryInterface iFace) throws ValidatorServiceException {
602
        JobForValidation job = new JobForValidation();
603

  
604
        job.setActivationId(UUID.randomUUID().toString());
605
        job.setAdminEmails(Collections.singletonList(this.adminEmail));
606
        job.setBaseUrl(iFace.getBaseUrl());
607
        job.setDatasourceId(repo.getId());
608
        job.setDesiredCompatibilityLevel(iFace.getDesiredCompatibilityLevel());
609
        job.setInterfaceId(iFace.getId());
610
//        job.setInterfaceIdOld(null);
611
        job.setOfficialName(repo.getOfficialName());
612
        job.setRepoType(repoType);
613
        job.setUserEmail(userEmail);
614
        job.setValidationSet(iFace.getAccessSet());
615
        job.setRecords(-1);
616
        job.setRegistration(true);
617
        job.setUpdateExisting(false);
618

  
619
        this.validatorService.submitJobForValidation(job);
620
    }
621

  
545 622
    private RepositoryInterface createRepositoryInterface(Repository repo, RepositoryInterface iFace, String datatype) {
546 623

  
547 624
        iFace.setContentDescription("metadata");
......
742 819
            return Collections.singletonMap("lastCollectionDate", getRepositoryInterface("openaire____::"+mode).get(1).getLastCollectionDate());
743 820
    }
744 821

  
745
    @Override
746
    public RepositoryInterface updateRepositoryInterface(@RequestParam("repoId") String repoId,
747
                                                         @RequestParam("registeredBy") String registeredBy,
748
                                                         @RequestBody RepositoryInterface repositoryInterface) throws Exception {
749

  
750
        this.updateBaseUrl(repoId,repositoryInterface.getId(),repositoryInterface.getBaseUrl());
751
        this.updateCompliance(repoId,repositoryInterface.getId(),repositoryInterface.getCompliance());
752
        this.updateValidationSet(repoId,repositoryInterface.getId(),repositoryInterface.getAccessSet());
753
        return repositoryInterface;
754
    }
755

  
756 822
    private void updateValidationSet(String repositoryId, String repositoryInterfaceId, String validationSet) throws Exception {
757 823
        UriComponents uriComponents = UriComponentsBuilder
758 824
                .fromHttpUrl(baseAddress + "/ds/api/oaiset")
......
840 906
                .build().expand(page, size).encode();
841 907
    }
842 908

  
909
    private UriComponents searchRegisteredDatasource(String requestSortBy, String order, String page,String size){
910

  
911
        return UriComponentsBuilder
912
                .fromHttpUrl(baseAddress + "/ds/searchregistered/")
913
                .path("/{page}/{size}/")
914
                .queryParam("requestSortBy",requestSortBy)
915
                .queryParam("order",order)
916
                .build().expand(page, size).encode();
917
    }
918

  
843 919
    private String getRepositoryType(String typology){
844 920
        return invertedDataSourceClass.get(typology);
845 921
    }

Also available in: Unified diff