Project

General

Profile

« Previous | Next » 

Revision 56761

Triggering validation job from provide on Interface Update and Interface Add

View differences:

RepositoryServiceImpl.java
152 152

  
153 153

  
154 154
    @Override
155
    public List<RepositorySnippet> getRepositoriesByCountry(@PathVariable("country") String country,
156
                                                            @PathVariable("mode") String mode,
157
                                                            @RequestParam(value = "managed",required=false) Boolean managed) throws JSONException, IOException {
155
    public List<RepositorySnippet> getRepositoriesByCountry(String country,
156
                                                            String mode,
157
                                                            Boolean managed) throws JSONException, IOException {
158 158

  
159 159
        LOGGER.debug("Getting repositories by country!");
160 160
        int page = 0;
......
251 251
    }
252 252

  
253 253
    @Override
254
    public List<Repository> getRepositoriesOfUser(@PathVariable("userEmail") String userEmail,
255
                                                  @PathVariable("page") String page,
256
                                                  @PathVariable("size") String size) throws JSONException {
254
    public List<Repository> getRepositoriesOfUser(String userEmail,
255
                                                  String page,
256
                                                  String size) throws JSONException {
257 257

  
258 258
        LOGGER.debug("Retreiving repositories of user : " + userEmail );
259 259
        UriComponents uriComponents = searchDatasource(page,size);
......
276 276
    }
277 277

  
278 278
    @Override
279
    public Repository getRepositoryById(@PathVariable("id") String id) throws JSONException,ResourceNotFoundException {
279
    public Repository getRepositoryById(String id) throws JSONException,ResourceNotFoundException {
280 280

  
281 281
        LOGGER.debug("Retreiving repositories with id : " + id );
282 282
        Repository repo = null;
......
303 303

  
304 304

  
305 305
    @Override
306
    public List<AggregationDetails> getRepositoryAggregations(@PathVariable("id") String id) throws JSONException {
306
    public List<AggregationDetails> getRepositoryAggregations(String id) throws JSONException {
307 307

  
308 308
        LOGGER.debug("Retreiving aggregations for repository with id : " + id );
309 309
        UriComponents uriComponents = searchDatasource("0","100");
......
332 332
    }
333 333

  
334 334
    @Override
335
    public Map<String, List<AggregationDetails>> getRepositoryAggregationsByYear(@PathVariable("id") String id) throws JSONException {
335
    public Map<String, List<AggregationDetails>> getRepositoryAggregationsByYear(String id) throws JSONException {
336 336
        LOGGER.debug("Retreiving aggregations (by year) for repository with id : " + id );
337 337
        UriComponents uriComponents = searchDatasource("0","100");
338 338
        RequestFilter requestFilter = new RequestFilter();
......
369 369

  
370 370

  
371 371
    @Override
372
    public List<Repository> getRepositoriesByName(@PathVariable("name") String name,
373
                                                  @PathVariable("page") String page,
374
                                                  @PathVariable("size") String size) throws JSONException {
372
    public List<Repository> getRepositoriesByName(String name,
373
                                                  String page,
374
                                                  String size) throws JSONException {
375 375

  
376 376
        LOGGER.debug("Retreiving  repositories with official name : " + name );
377 377
        UriComponents uriComponents = searchDatasource("0","100");
......
393 393
    }
394 394

  
395 395
    @Override
396
    public List<RepositoryInterface> getRepositoryInterface(@PathVariable("id") String id) throws JSONException {
396
    public List<RepositoryInterface> getRepositoryInterface(String id) throws JSONException {
397 397

  
398 398
        UriComponents uriComponents = UriComponentsBuilder
399 399
                .fromHttpUrl(baseAddress + "/ds/api/")
......
412 412
    }
413 413

  
414 414
    @Override
415
    public Repository addRepository(@RequestParam("datatype") String datatype,
416
                                    @RequestBody Repository repository) throws Exception {
415
    public Repository addRepository(String datatype,
416
                                    Repository repository) throws Exception {
417 417

  
418 418
        LOGGER.debug("storing " + datatype + " repository with id: " + repository.getId());
419 419

  
......
447 447
            String json_repository = Converter.repositoryObjectToJson(repository);
448 448
            LOGGER.debug("JSON to add(update) -> " + json_repository);
449 449

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

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

  
......
472 467
    }
473 468

  
474 469
    @Override
475
    public Repository updateRepository(@RequestBody Repository repository,Authentication authentication) throws Exception {
470
    public Repository updateRepository(Repository repository,Authentication authentication) throws Exception {
476 471
        UriComponents uriComponents = UriComponentsBuilder
477 472
                .fromHttpUrl(baseAddress + "/ds/update/")
478 473
                .build()
......
501 496
        }
502 497
    }
503 498

  
504
    private void updateInterface(String datatype,RepositoryInterface iFace) {
505
        //TODO call update base url
506
        //((DatasourceManagerService) this.dmService.getService()).updateBaseUrl(repo.getId(), iFace.getId(), iFace.getBaseUrl());
507
        if (!iFace.getAccessSet().isEmpty()) {
508
            LOGGER.debug("set not empty: " + iFace.getAccessSet());
509
            //TODO call update method for access params
510
            // ((DatasourceManagerService) this.dmService.getService()).updateAccessParam(repo.getId(), iFace.getId(), "set", iFace.getAccessSet(), false);
511
        } else {
512
            //TODO call deleteAccessParamOrExtraField
513
            //((DatasourceManagerService) this.dmService.getService()).deleteAccessParamOrExtraField(repo.getId(), iFace.getId(), "set");
514
        }
515
        //TODO update content description
516
        //((DatasourceManagerService) this.dmService.getService()).updateContentDescription(repo.getId(), iFace.getId(), "metadata");
517
        if (datatype.equals("re3data")) {
518
            //TODO call update access params
519
            //  ((DatasourceManagerService) this.dmService.getService()).updateAccessParam(repo.getId(), iFace.getId(), "format", "oai_datacite", false);
520
            iFace.setAccessFormat("oai_datacite");
521
        } else {
522
            //TODO call update access params
523
            //((DatasourceManagerService) this.dmService.getService()).updateAccessParam(repo.getId(), iFace.getId(), "format", "oai_dc", false);
524
            iFace.setAccessFormat("oai_dc");
525
        }
526

  
527
    }
528

  
529 499
    private void storeRepository(Repository repository, Authentication authentication) throws Exception {
530 500

  
531 501
        Date utilDate = new Date();
......
551 521
    }
552 522

  
553 523
    @Override
554
    public void deleteRepositoryInterface(@RequestParam("id") String id ,
555
                                          @RequestParam("registeredBy") String registeredBy){
524
    public void deleteRepositoryInterface(String id ,
525
                                          String registeredBy){
556 526
        UriComponents uriComponents = UriComponentsBuilder
557 527
                .fromHttpUrl(baseAddress + "/ds/api/")
558 528
                .path("/{id}")
......
562 532
    }
563 533

  
564 534
    @Override
565
    public RepositoryInterface addRepositoryInterface(@RequestParam("datatype") String datatype,
566
                                                      @RequestParam("repoId") String repoId,
567
                                                      @RequestParam("registeredBy") String registeredBy,
568
                                                      @RequestBody RepositoryInterface repositoryInterface) throws JSONException,ResourceNotFoundException {
535
    public RepositoryInterface addRepositoryInterface(String datatype,
536
                                                      String repoId,
537
                                                      String registeredBy,
538
                                                      RepositoryInterface repositoryInterface) throws JSONException, ResourceNotFoundException, ValidatorServiceException {
569 539
        try {
570 540
            Repository e = this.getRepositoryById(repoId);
571 541
            repositoryInterface = createRepositoryInterface(e,repositoryInterface,datatype);
......
576 546
                    .build()
577 547
                    .encode();
578 548

  
579
            HttpEntity<String> httpEntity = new HttpEntity <String> (json_interface,httpHeaders);
549
            HttpEntity<String> httpEntity = new HttpEntity <> (json_interface,httpHeaders);
580 550
            restTemplate.postForObject(uriComponents.toUri(),httpEntity,String.class);
551
            submitInterfaceValidation(e, registeredBy, repositoryInterface);
552

  
581 553
            return repositoryInterface;
582 554

  
583
        } catch (JSONException e) {
555
        } catch (JSONException | ValidatorServiceException e) {
584 556
            LOGGER.debug("Exception on addRepositoryInterface" , e);
585 557
            emailUtils.reportException(e);
586 558
            throw e;
......
588 560
    }
589 561

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

  
595 567
        this.updateBaseUrl(repoId,repositoryInterface.getId(),repositoryInterface.getBaseUrl());
596 568
        this.updateCompliance(repoId,repositoryInterface.getId(),repositoryInterface.getCompliance());
597 569
        this.updateValidationSet(repoId,repositoryInterface.getId(),repositoryInterface.getAccessSet());
570
        submitInterfaceValidation(getRepositoryById(repoId),registeredBy,repositoryInterface);
598 571
        return repositoryInterface;
599 572
    }
600 573

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

  
604 577
        job.setActivationId(UUID.randomUUID().toString());
......
607 580
        job.setDatasourceId(repo.getId());
608 581
        job.setDesiredCompatibilityLevel(iFace.getDesiredCompatibilityLevel());
609 582
        job.setInterfaceId(iFace.getId());
610
//        job.setInterfaceIdOld(null);
611 583
        job.setOfficialName(repo.getOfficialName());
612
        job.setRepoType(repoType);
584
        job.setRepoType(repo.getDatasourceType());
613 585
        job.setUserEmail(userEmail);
614
        job.setValidationSet(iFace.getAccessSet());
586
        job.setValidationSet((iFace.getAccessSet().isEmpty() ? "none" : iFace.getAccessSet()));
615 587
        job.setRecords(-1);
616 588
        job.setRegistration(true);
617 589
        job.setUpdateExisting(false);
......
645 617
        iFace.setAccessProtocol("oai");
646 618
        iFace.setMetadataIdentifierPath("//*[local-name()='header']/*[local-name()='identifier']");
647 619
        iFace.setId("api_________::" + repo.getId() + "::" + UUID.randomUUID().toString().substring(0, 8));
648
        if (iFace.getAccessSet().isEmpty()) {
620
        if (iFace.getAccessSet() == null || iFace.getAccessSet().isEmpty()) {
649 621
            LOGGER.debug("set is empty: " + iFace.getAccessSet());
650 622
            iFace.removeAccessSet();
623
            iFace.setAccessSet("none");
651 624
        }
652 625
        return iFace;
653 626
    }
......
670 643
    }
671 644

  
672 645
    @Override
673
    public List<String> getUrlsOfUserRepos(@PathVariable("user_email") String userEmail,
674
                                           @PathVariable("page") String page,
675
                                           @PathVariable("size") String size) throws JSONException {
646
    public List<String> getUrlsOfUserRepos(String userEmail,
647
                                           String page,
648
                                           String size){
676 649
        UriComponents uriComponents = UriComponentsBuilder
677 650
                .fromHttpUrl(baseAddress + "/api/baseurl/")
678 651
                .path("/{page}/{size}")
......
690 663
    }
691 664

  
692 665
    @Override
693
    public List<String> getDatasourceVocabularies(@PathVariable("mode") String mode) {
666
    public List<String> getDatasourceVocabularies(String mode) {
694 667

  
695 668
        List<String> resultSet = new ArrayList<>();
696 669
        for (Map.Entry<String, String> entry : this.getVocabulary("dnet:datasource_typologies").getAsMap().entrySet()) {
......
723 696

  
724 697

  
725 698
    @Override
726
    public Map<String, String> getCompatibilityClasses(@PathVariable("mode") String mode)  {
699
    public Map<String, String> getCompatibilityClasses(String mode)  {
727 700

  
728 701
        LOGGER.debug("Getting compatibility classes for mode: " + mode);
729 702
        Map<String, String> retMap = new HashMap<String, String>();
......
752 725
    }
753 726

  
754 727
    @Override
755
    public Map<String, String> getDatasourceClasses(@PathVariable("mode") String mode)  {
728
    public Map<String, String> getDatasourceClasses(String mode)  {
756 729

  
757 730
        LOGGER.debug("Getting datasource classes for mode: " + mode);
758 731

  
......
793 766
    }
794 767

  
795 768
    @Override
796
    public MetricsInfo getMetricsInfoForRepository(@PathVariable("repoId")  String repoId) throws RepositoryServiceException {
769
    public MetricsInfo getMetricsInfoForRepository(String repoId) throws RepositoryServiceException {
797 770
        try {
798 771

  
799 772
            MetricsInfo metricsInfo = new MetricsInfo();
......
809 782
    }
810 783

  
811 784
    @Override
812
    public Map<String, String> getListLatestUpdate(@PathVariable("mode")  String mode) throws JSONException {
785
    public Map<String, String> getListLatestUpdate(String mode) throws JSONException {
813 786
        if(mode.equals("opendoar"))
814 787
            return Collections.singletonMap("lastCollectionDate", getRepositoryInterface("openaire____::"+mode).get(0).getLastCollectionDate());
815 788
        else

Also available in: Unified diff