Skip to content

Commit

Permalink
Add permits for index entries
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekSuchanek committed Oct 3, 2023
1 parent 5d6687b commit a8c86ea
Show file tree
Hide file tree
Showing 32 changed files with 894 additions and 123 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 @@ -23,17 +23,26 @@
package nl.dtls.fairdatapoint.api.controller.index;

import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
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.api.dto.index.ping.PingDTO;
import nl.dtls.fairdatapoint.database.rdf.repository.exception.MetadataRepositoryException;
import nl.dtls.fairdatapoint.entity.index.entry.IndexEntryPermit;
import nl.dtls.fairdatapoint.entity.index.event.Event;
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.eclipse.rdf4j.model.Model;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
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 @@ -47,19 +56,55 @@ public class IndexEntryController {
@Autowired
private IndexEntryService service;

@Autowired
private HarvesterService harvesterService;

@Autowired
private EventService eventService;

@Autowired
private WebhookService webhookService;

@Autowired
private IndexEntryService indexEntryService;

@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,
HttpServletRequest request
) throws MetadataRepositoryException {
final Optional<IndexEntryDetailDTO> resDto = service.updateEntry(uuid, reqDto);
if (resDto.isPresent()) {
final String clientUrl = resDto.get().getClientUrl();
if (resDto.get().getPermit().equals(IndexEntryPermit.ACCEPTED)) {
final Event event = eventService.acceptAdminTrigger(request, new PingDTO(clientUrl));
webhookService.triggerWebhooks(event);
eventService.triggerMetadataRetrieval(event);
indexEntryService.harvest(clientUrl);
}
else {
harvesterService.deleteHarvestedData(clientUrl);
}
}
return resDto;
}

@GetMapping(path = "/{uuid}/data", produces = "!application/json")
public Model getEntryData(@PathVariable final String uuid) throws MetadataRepositoryException {
return service.getEntryHarvestedData(uuid);
Expand All @@ -72,12 +117,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 @@ -100,7 +100,7 @@ public ResponseEntity<Void> receivePing(
final Event event = eventService.acceptIncomingPing(reqDto, request);
log.info("Triggering metadata retrieval for {}", event.getRelatedTo().getClientUrl());
eventService.triggerMetadataRetrieval(event);
harvesterService.harvest(reqDto.getClientUrl());
indexEntryService.harvest(reqDto.getClientUrl());
webhookService.triggerWebhooks(event);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
Expand Down
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class InstanceProperties {
private boolean behindProxy = true;
private String persistentUrl;
private boolean index;
private boolean indexAutoPermit;

private String title = "FAIR Data Point";
private String subtitle = "Metadata for machines";
Expand Down
Loading

0 comments on commit a8c86ea

Please sign in to comment.