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 Sep 8, 2023
1 parent 5d6687b commit be7f777
Show file tree
Hide file tree
Showing 23 changed files with 735 additions and 106 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 @@ -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 @@ -23,14 +23,14 @@
package nl.dtls.fairdatapoint.database.mongo.migration.development.index.entry.data;

import nl.dtls.fairdatapoint.entity.index.entry.IndexEntry;
import nl.dtls.fairdatapoint.entity.index.entry.IndexEntryPermit;
import nl.dtls.fairdatapoint.entity.index.entry.IndexEntryState;
import nl.dtls.fairdatapoint.entity.index.entry.RepositoryMetadata;
import org.springframework.stereotype.Service;

import java.time.Instant;
import java.util.HashMap;

import static nl.dtls.fairdatapoint.entity.index.entry.IndexEntryState.*;

@Service
public class IndexEntryFixtures {

Expand All @@ -41,10 +41,16 @@ public IndexEntry entryActive() {
clientUri,
new HashMap<>()
);
return new IndexEntry(
"8987abc1-15a4-4752-903c-8f8a5882cca6", clientUri,
Valid, Instant.now(), Instant.now(), Instant.now(), repositoryData
);
return IndexEntry.builder()
.uuid("8987abc1-15a4-4752-903c-8f8a5882cca6")
.clientUrl(clientUri)
.state(IndexEntryState.Valid)
.permit(IndexEntryPermit.ACCEPTED)
.registrationTime(Instant.now())
.modificationTime(Instant.now())
.lastRetrievalTime(Instant.now())
.currentMetadata(repositoryData)
.build();
}

public IndexEntry entryActive2() {
Expand All @@ -55,10 +61,16 @@ public IndexEntry entryActive2() {
new HashMap<>()
);
final Instant date = Instant.parse("2020-05-30T23:38:31.085Z");
return new IndexEntry(
"c912331f-4a77-4300-a469-dbaf5fc0b4e2", clientUri,
Valid, date, date, date, repositoryData
);
return IndexEntry.builder()
.uuid("c912331f-4a77-4300-a469-dbaf5fc0b4e2")
.clientUrl(clientUri)
.state(IndexEntryState.Valid)
.permit(IndexEntryPermit.ACCEPTED)
.registrationTime(date)
.modificationTime(date)
.lastRetrievalTime(date)
.currentMetadata(repositoryData)
.build();
}

public IndexEntry entryInactive() {
Expand All @@ -69,9 +81,16 @@ public IndexEntry entryInactive() {
new HashMap<>()
);
final Instant date = Instant.parse("2020-05-30T23:38:23.085Z");
return new IndexEntry("b5851ebe-aacf-4de9-bf0a-3686e9256e73", clientUri,
Valid, date, date, date, repositoryData
);
return IndexEntry.builder()
.uuid("b5851ebe-aacf-4de9-bf0a-3686e9256e73")
.clientUrl(clientUri)
.state(IndexEntryState.Valid)
.permit(IndexEntryPermit.ACCEPTED)
.registrationTime(date)
.modificationTime(date)
.lastRetrievalTime(date)
.currentMetadata(repositoryData)
.build();
}

public IndexEntry entryUnreachable() {
Expand All @@ -81,10 +100,16 @@ public IndexEntry entryUnreachable() {
clientUri,
new HashMap<>()
);
return new IndexEntry(
"dae46b47-87fb-4fdf-995c-8aa3739a27fc", clientUri,
Unreachable, Instant.now(), Instant.now(), Instant.now(), repositoryData
);
return IndexEntry.builder()
.uuid("dae46b47-87fb-4fdf-995c-8aa3739a27fc")
.clientUrl(clientUri)
.state(IndexEntryState.Unreachable)
.permit(IndexEntryPermit.ACCEPTED)
.registrationTime(Instant.now())
.modificationTime(Instant.now())
.lastRetrievalTime(Instant.now())
.currentMetadata(repositoryData)
.build();
}

public IndexEntry entryInvalid() {
Expand All @@ -94,10 +119,16 @@ public IndexEntry entryInvalid() {
clientUri,
new HashMap<>()
);
return new IndexEntry(
"b37e8c1f-ac0e-49f8-8e07-35571c4f8235", clientUri,
Invalid, Instant.now(), Instant.now(), Instant.now(), repositoryData
);
return IndexEntry.builder()
.uuid("b37e8c1f-ac0e-49f8-8e07-35571c4f8235")
.clientUrl(clientUri)
.state(IndexEntryState.Invalid)
.permit(IndexEntryPermit.ACCEPTED)
.registrationTime(Instant.now())
.modificationTime(Instant.now())
.lastRetrievalTime(Instant.now())
.currentMetadata(repositoryData)
.build();
}

public IndexEntry entryUnknown() {
Expand All @@ -107,10 +138,54 @@ public IndexEntry entryUnknown() {
clientUri,
new HashMap<>()
);
return new IndexEntry(
"4471d7c5-8c5b-4581-a9bc-d175456492c4", clientUri,
Unknown, Instant.now(), Instant.now(), Instant.now(), repositoryData
return IndexEntry.builder()
.uuid("4471d7c5-8c5b-4581-a9bc-d175456492c4")
.clientUrl(clientUri)
.state(IndexEntryState.Unknown)
.permit(IndexEntryPermit.ACCEPTED)
.registrationTime(Instant.now())
.modificationTime(Instant.now())
.lastRetrievalTime(Instant.now())
.currentMetadata(repositoryData)
.build();
}

public IndexEntry entryRejected() {
final String clientUri = "https://example.com/valid-rejected-fairdatapoint";
final RepositoryMetadata repositoryData = new RepositoryMetadata(
RepositoryMetadata.CURRENT_VERSION,
clientUri,
new HashMap<>()
);
return IndexEntry.builder()
.uuid("4471d7c5-8c5b-4581-a9bc-d175456492c5")
.clientUrl(clientUri)
.state(IndexEntryState.Valid)
.permit(IndexEntryPermit.REJECTED)
.registrationTime(Instant.now())
.modificationTime(Instant.now())
.lastRetrievalTime(Instant.now())
.currentMetadata(repositoryData)
.build();
}

public IndexEntry entryPending() {
final String clientUri = "https://example.com/valid-pending-fairdatapoint";
final RepositoryMetadata repositoryData = new RepositoryMetadata(
RepositoryMetadata.CURRENT_VERSION,
clientUri,
new HashMap<>()
);
return IndexEntry.builder()
.uuid("4471d7c5-8c5b-4581-a9bc-d175456492c6")
.clientUrl(clientUri)
.state(IndexEntryState.Valid)
.permit(IndexEntryPermit.PENDING)
.registrationTime(Instant.now())
.modificationTime(Instant.now())
.lastRetrievalTime(Instant.now())
.currentMetadata(repositoryData)
.build();
}

}
Loading

0 comments on commit be7f777

Please sign in to comment.