Skip to content

Commit

Permalink
WIP: Add permits for index entries
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekSuchanek committed Sep 15, 2023
1 parent 5d6687b commit e740014
Show file tree
Hide file tree
Showing 25 changed files with 741 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import nl.dtls.fairdatapoint.database.rdf.repository.exception.MetadataRepositoryException;
import nl.dtls.fairdatapoint.entity.index.event.Event;
import nl.dtls.fairdatapoint.service.UtilityService;
import nl.dtls.fairdatapoint.service.index.entry.IndexEntryService;
import nl.dtls.fairdatapoint.service.index.event.EventService;
import nl.dtls.fairdatapoint.service.index.harvester.HarvesterService;
import nl.dtls.fairdatapoint.service.index.webhook.WebhookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
Expand All @@ -57,7 +57,7 @@ public class IndexAdminController {
private WebhookService webhookService;

@Autowired
private HarvesterService harvesterService;
private IndexEntryService indexEntryService;

@Operation(hidden = true)
@PostMapping("/trigger")
Expand All @@ -72,7 +72,7 @@ public void triggerMetadataRetrieve(
final Event event = eventService.acceptAdminTrigger(request, reqDto);
webhookService.triggerWebhooks(event);
eventService.triggerMetadataRetrieval(event);
harvesterService.harvest(reqDto.getClientUrl());
indexEntryService.harvest(reqDto.getClientUrl());
}

@Operation(hidden = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import nl.dtls.fairdatapoint.api.dto.index.entry.IndexEntryDTO;
import nl.dtls.fairdatapoint.api.dto.index.entry.IndexEntryDetailDTO;
import nl.dtls.fairdatapoint.api.dto.index.entry.IndexEntryInfoDTO;
import nl.dtls.fairdatapoint.api.dto.index.entry.IndexEntryUpdateDTO;
import nl.dtls.fairdatapoint.database.rdf.repository.exception.MetadataRepositoryException;
import nl.dtls.fairdatapoint.service.index.entry.IndexEntryService;
import org.eclipse.rdf4j.model.Model;
Expand All @@ -34,6 +35,7 @@
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand All @@ -50,16 +52,26 @@ public class IndexEntryController {
@GetMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE)
public Page<IndexEntryDTO> getEntriesPage(
Pageable pageable,
@RequestParam(required = false, defaultValue = "") String state
@RequestParam(required = false, defaultValue = "") String state,
@RequestParam(required = false, defaultValue = "accepted") String permit
) {
return service.getEntriesPageDTOs(pageable, state);
return service.getEntriesPageDTOs(pageable, state, permit);
}

@GetMapping(path = "/{uuid}", produces = MediaType.APPLICATION_JSON_VALUE)
public Optional<IndexEntryDetailDTO> getEntry(@PathVariable final String uuid) {
return service.getEntryDetailDTO(uuid);
}

@PutMapping(path = "/{uuid}", produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasRole('ADMIN')")
public Optional<IndexEntryDetailDTO> updateEntry(
@PathVariable final String uuid,
@RequestBody IndexEntryUpdateDTO reqDto
) {
return service.updateEntry(uuid, reqDto);
}

@GetMapping(path = "/{uuid}/data", produces = "!application/json")
public Model getEntryData(@PathVariable final String uuid) throws MetadataRepositoryException {
return service.getEntryHarvestedData(uuid);
Expand All @@ -72,12 +84,16 @@ public void deleteEntry(@PathVariable final String uuid) throws MetadataReposito
}

@GetMapping(path = "/all", produces = MediaType.APPLICATION_JSON_VALUE)
public List<IndexEntryDTO> getEntriesAll() {
return service.getAllEntriesAsDTOs();
public List<IndexEntryDTO> getEntriesAll(
@RequestParam(required = false, defaultValue = "accepted") String permit
) {
return service.getAllEntriesAsDTOs(permit);
}

@GetMapping(path = "/info", produces = MediaType.APPLICATION_JSON_VALUE)
public IndexEntryInfoDTO getEntriesInfo() {
return service.getEntriesInfo();
public IndexEntryInfoDTO getEntriesInfo(
@RequestParam(required = false, defaultValue = "accepted") String permit
) {
return service.getEntriesInfo(permit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import nl.dtls.fairdatapoint.database.rdf.repository.exception.MetadataRepositoryException;
import nl.dtls.fairdatapoint.entity.index.event.Event;
import nl.dtls.fairdatapoint.service.UtilityService;
import nl.dtls.fairdatapoint.service.index.entry.IndexEntryService;
import nl.dtls.fairdatapoint.service.index.event.EventService;
import nl.dtls.fairdatapoint.service.index.harvester.HarvesterService;
import nl.dtls.fairdatapoint.service.index.webhook.WebhookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
Expand All @@ -57,7 +57,7 @@ public class IndexPingController {
private WebhookService webhookService;

@Autowired
private HarvesterService harvesterService;
private IndexEntryService indexEntryService;

@Autowired
private UtilityService utilityService;
Expand Down Expand Up @@ -96,12 +96,12 @@ public ResponseEntity<Void> receivePing(
@RequestBody @Valid PingDTO reqDto,
HttpServletRequest request
) throws MetadataRepositoryException {
log.info("Received ping from {}", utilityService.getRemoteAddr(request));
//log.info("Received ping from {}", utilityService.getRemoteAddr(request));
final Event event = eventService.acceptIncomingPing(reqDto, request);
log.info("Triggering metadata retrieval for {}", event.getRelatedTo().getClientUrl());
eventService.triggerMetadataRetrieval(event);
harvesterService.harvest(reqDto.getClientUrl());
webhookService.triggerWebhooks(event);
//eventService.triggerMetadataRetrieval(event);
//indexEntryService.harvest(reqDto.getClientUrl());
//webhookService.triggerWebhooks(event);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import nl.dtls.fairdatapoint.entity.index.entry.IndexEntryPermit;
import org.hibernate.validator.constraints.URL;

@NoArgsConstructor
Expand All @@ -45,6 +46,9 @@ public class IndexEntryDTO {
@NotNull
private IndexEntryStateDTO state;

@NotNull
private IndexEntryPermit permit;

@NotNull
private String registrationTime;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import lombok.NoArgsConstructor;
import lombok.Setter;
import nl.dtls.fairdatapoint.api.dto.index.event.EventDTO;
import nl.dtls.fairdatapoint.entity.index.entry.IndexEntryPermit;
import nl.dtls.fairdatapoint.entity.index.entry.RepositoryMetadata;
import org.hibernate.validator.constraints.URL;

Expand All @@ -49,6 +50,9 @@ public class IndexEntryDetailDTO {
@NotNull
private IndexEntryStateDTO state;

@NotNull
private IndexEntryPermit permit;

@NotNull
private RepositoryMetadata currentMetadata;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* The MIT License
* Copyright © 2017 DTL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package nl.dtls.fairdatapoint.api.dto.index.entry;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import nl.dtls.fairdatapoint.entity.index.entry.IndexEntryPermit;

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
public class IndexEntryUpdateDTO {

private IndexEntryPermit permit;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class IndexSettingsDTO {
@NotNull
private IndexSettingsPingDTO ping;

@NotNull
private Boolean autoPermit;

@NotNull
private Boolean isDefault;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ public class IndexSettingsUpdateDTO {
@Valid
@NotNull
private IndexSettingsPingDTO ping;

@NotNull
private Boolean autoPermit;
}
Loading

0 comments on commit e740014

Please sign in to comment.