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 5, 2023
1 parent 5d6687b commit d8a86fe
Show file tree
Hide file tree
Showing 12 changed files with 196 additions and 46 deletions.
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
@@ -0,0 +1,16 @@
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,12 +23,14 @@
package nl.dtls.fairdatapoint.database.mongo.repository;

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 org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;

import java.time.Instant;
import java.util.List;
import java.util.Optional;

public interface IndexEntryRepository extends MongoRepository<IndexEntry, String> {
Expand All @@ -37,18 +39,26 @@ public interface IndexEntryRepository extends MongoRepository<IndexEntry, String

Optional<IndexEntry> findByClientUrl(String clientUrl);

Page<IndexEntry> findAllByStateEquals(Pageable pageable, IndexEntryState state);
Page<IndexEntry> findAllByStateEqualsAndPermitIn(
Pageable pageable, IndexEntryState state, List<IndexEntryPermit> permits
);

Page<IndexEntry> findAllByStateEqualsAndLastRetrievalTimeBefore(Pageable pageable, IndexEntryState state,
Instant when);
Page<IndexEntry> findAllByStateEqualsAndLastRetrievalTimeBeforeAndPermitIn(
Pageable pageable, IndexEntryState state, Instant when, List<IndexEntryPermit> permits
);

Page<IndexEntry> findAllByStateEqualsAndLastRetrievalTimeAfter(Pageable pageable, IndexEntryState state,
Instant when);
Page<IndexEntry> findAllByStateEqualsAndLastRetrievalTimeAfterAndPermitIn(
Pageable pageable, IndexEntryState state, Instant when, List<IndexEntryPermit> permits
);

long countAllByStateEquals(IndexEntryState state);
long countAllByStateEqualsAndPermitIn(IndexEntryState state, List<IndexEntryPermit> permits);

long countAllByStateEqualsAndLastRetrievalTimeAfter(IndexEntryState state, Instant when);
long countAllByStateEqualsAndLastRetrievalTimeAfterAndPermitIn(
IndexEntryState state, Instant when, List<IndexEntryPermit> permits);

long countAllByStateEqualsAndLastRetrievalTimeBefore(IndexEntryState state, Instant when);
long countAllByStateEqualsAndLastRetrievalTimeBeforeAndPermitIn(
IndexEntryState state, Instant when, List<IndexEntryPermit> permits
);

Iterable<IndexEntry> findAllByPermitIn(List<IndexEntryPermit> permits);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class IndexEntry {

private IndexEntryState state = IndexEntryState.Unknown;

private IndexEntryPermit permit = IndexEntryPermit.PENDING;

@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private Instant registrationTime;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package nl.dtls.fairdatapoint.entity.index.entry;

public enum IndexEntryPermit {
PENDING,
ACCEPTED,
REJECTED,
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ public class IndexSettings {
@NotNull
private IndexSettingsPing ping;

@NotNull
private Boolean autoPermit;

public static IndexSettings getDefault() {
final IndexSettings settings = new IndexSettings();
settings.setPing(IndexSettingsPing.getDefault());
settings.setRetrieval(IndexSettingsRetrieval.getDefault());
settings.setAutoPermit(true);
return settings;
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/nl/dtls/fairdatapoint/entity/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@ public User(
this.passwordHash = passwordHash;
this.role = role;
}

public boolean isAdmin() {
return role.equals(UserRole.ADMIN);
}
}
Loading

0 comments on commit d8a86fe

Please sign in to comment.