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 79892e1
Show file tree
Hide file tree
Showing 12 changed files with 241 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,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,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> permit
);

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

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

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

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

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

Iterable<IndexEntry> findAllByPermitIn(List<IndexEntryPermit> permit);
}
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,29 @@
/**
* 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.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 79892e1

Please sign in to comment.