diff --git a/src/main/java/eu/sshopencloud/marketplace/controllers/actors/ActorController.java b/src/main/java/eu/sshopencloud/marketplace/controllers/actors/ActorController.java index f76108a1eb2e17cbe5f6fc065a9223dc71eaadfd..6e067b15979349caaf4983734c188a20021e7374 100644 --- a/src/main/java/eu/sshopencloud/marketplace/controllers/actors/ActorController.java +++ b/src/main/java/eu/sshopencloud/marketplace/controllers/actors/ActorController.java @@ -5,7 +5,6 @@ import eu.sshopencloud.marketplace.dto.actors.ActorCore; import eu.sshopencloud.marketplace.dto.actors.ActorDto; import eu.sshopencloud.marketplace.dto.actors.ActorHistoryDto; import eu.sshopencloud.marketplace.dto.actors.PaginatedActors; -import eu.sshopencloud.marketplace.dto.items.ItemBasicDto; import eu.sshopencloud.marketplace.services.actors.ActorService; import eu.sshopencloud.marketplace.validators.PageCoordsValidator; import io.swagger.v3.oas.annotations.Operation; diff --git a/src/main/java/eu/sshopencloud/marketplace/controllers/datasets/DatasetController.java b/src/main/java/eu/sshopencloud/marketplace/controllers/datasets/DatasetController.java index c4cfdddf9d9781d49029a324e35cdf909e7b597c..7800c33ad7a31806c5de7ebbbe5cf673fba9bfdf 100644 --- a/src/main/java/eu/sshopencloud/marketplace/controllers/datasets/DatasetController.java +++ b/src/main/java/eu/sshopencloud/marketplace/controllers/datasets/DatasetController.java @@ -157,7 +157,7 @@ public class DatasetController { return ResponseEntity.ok(datasetService.getSources(persistentId)); } - @Operation(summary = "Getting differences between dataset and target version of item", operationId = "getDatasetAndVersionedItemDifferences") + @Operation(summary = "Getting differences between dataset and target version of item, ('unaltered' string response means for the single field that remained unchanged)", operationId = "getDatasetAndVersionedItemDifferences") @GetMapping(path = "/{persistentId}/diff", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity getDatasetVersionedItemDifferences(@PathVariable("persistentId") String persistentId, @RequestParam(required = true) String with, @@ -167,7 +167,7 @@ public class DatasetController { } - @Operation(summary = "Getting differences between target version of dataset and target version of item", operationId = "getVersionedDatasetAndVersionedItemDifferences") + @Operation(summary = "Getting differences between target version of dataset and target version of item ('unaltered' string response means for the single field that remained unchanged)", operationId = "getVersionedDatasetAndVersionedItemDifferences") @GetMapping(path = "/{persistentId}/versions/{versionId}/diff", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity getVersionedDatasetVersionedItemDifferences(@PathVariable("persistentId") String persistentId, @PathVariable("versionId") long versionId, diff --git a/src/main/java/eu/sshopencloud/marketplace/controllers/publications/PublicationController.java b/src/main/java/eu/sshopencloud/marketplace/controllers/publications/PublicationController.java index c7cd400fafd3516895d1b26419808ad67f8ccb11..2e0c3bdbe42fe18a44d098d9962df5d1fd2890e1 100644 --- a/src/main/java/eu/sshopencloud/marketplace/controllers/publications/PublicationController.java +++ b/src/main/java/eu/sshopencloud/marketplace/controllers/publications/PublicationController.java @@ -158,7 +158,7 @@ public class PublicationController { } - @Operation(summary = "Getting differences between publication and target version of item", operationId = "getPublicationAndVersionedItemDifferences") + @Operation(summary = "Getting differences between publication and target version of item ('unaltered' string response means for the single field that remained unchanged)", operationId = "getPublicationAndVersionedItemDifferences") @GetMapping(path = "/{persistentId}/diff", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity getPublicationVersionedItemDifferences(@PathVariable("persistentId") String persistentId, @RequestParam(required = true) String with, @@ -168,7 +168,7 @@ public class PublicationController { } - @Operation(summary = "Getting differences between target version of publication and target version of item", operationId = "getVersionedPublicationAndVersionedItemDifferences") + @Operation(summary = "Getting differences between target version of publication and target version of item ('unaltered' string response means for the single field that remained unchanged)", operationId = "getVersionedPublicationAndVersionedItemDifferences") @GetMapping(path = "/{persistentId}/versions/{versionId}/diff", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity getVersionedPublicationVersionedItemDifferences(@PathVariable("persistentId") String persistentId, @PathVariable("versionId") long versionId, diff --git a/src/main/java/eu/sshopencloud/marketplace/controllers/search/SearchController.java b/src/main/java/eu/sshopencloud/marketplace/controllers/search/SearchController.java index 31418370e704f25eda1ddde1a95ba681aff24f7a..e69e046415643f86de9554fa21e4c18cffca1c4b 100644 --- a/src/main/java/eu/sshopencloud/marketplace/controllers/search/SearchController.java +++ b/src/main/java/eu/sshopencloud/marketplace/controllers/search/SearchController.java @@ -51,8 +51,12 @@ class SearchController { + SearchFilter.ITEMS_INDEX_TYPE_FILTERS + ".", schema = @Schema(type = "string")) @RequestParam(required = false) MultiValueMap f) throws PageTooLargeException, IllegalFilterException { + if(!d.containsKey("d.status")) + d.add("d.status", "approved"); + Map expressionParams = UrlParamsExtractor.extractExpressionParams(d); Map> filterParams = UrlParamsExtractor.extractFilterParams(f); + return ResponseEntity.ok(searchService.searchItems(q, advanced, includeSteps, expressionParams, categories, filterParams, order, pageCoordsValidator.validate(page, perpage))); } diff --git a/src/main/java/eu/sshopencloud/marketplace/controllers/search/UrlParamsExtractor.java b/src/main/java/eu/sshopencloud/marketplace/controllers/search/UrlParamsExtractor.java index 4c3a4ad6ab76836c7ad098e417e8b28dbab6242f..b0d0f236d3fb85603b9a1e85b4d613b1d953db86 100644 --- a/src/main/java/eu/sshopencloud/marketplace/controllers/search/UrlParamsExtractor.java +++ b/src/main/java/eu/sshopencloud/marketplace/controllers/search/UrlParamsExtractor.java @@ -11,7 +11,7 @@ import java.util.Map; public class UrlParamsExtractor { public Map> extractFilterParams(MultiValueMap params) { - Map> filterParams = new HashMap>(); + Map> filterParams = new HashMap<>(); for (Map.Entry> entry: params.entrySet()) { String key = entry.getKey(); if (key.startsWith("f.")) { @@ -22,11 +22,12 @@ public class UrlParamsExtractor { } public Map extractExpressionParams(MultiValueMap params) { - Map expressionParams = new HashMap(); + Map expressionParams = new HashMap<>(); for (Map.Entry> entry: params.entrySet()) { String key = entry.getKey(); if (key.startsWith("d.")) { - expressionParams.put(key.substring(2), entry.getValue().get(0)); + if(!entry.getValue().get(0).isEmpty()) + expressionParams.put(key.substring(2), entry.getValue().get(0)); } } return expressionParams; diff --git a/src/main/java/eu/sshopencloud/marketplace/controllers/sources/SourceController.java b/src/main/java/eu/sshopencloud/marketplace/controllers/sources/SourceController.java index bcde7222a89643331463d922f9037c25b600cf7a..691c422c72af15ab3412d626886602311ee6e0bb 100644 --- a/src/main/java/eu/sshopencloud/marketplace/controllers/sources/SourceController.java +++ b/src/main/java/eu/sshopencloud/marketplace/controllers/sources/SourceController.java @@ -67,7 +67,6 @@ public class SourceController { } - @Operation(summary = "Get list of items for given source") @GetMapping(path = "/{sourceId}/items", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity getItemsForSource(@PathVariable("sourceId") Long sourceId, diff --git a/src/main/java/eu/sshopencloud/marketplace/controllers/tools/ToolController.java b/src/main/java/eu/sshopencloud/marketplace/controllers/tools/ToolController.java index 2a2cb11daeb2fb717feb1183b760c5139e51c032..6b739bfd699e44eb478f6058cc6827abb61abe98 100644 --- a/src/main/java/eu/sshopencloud/marketplace/controllers/tools/ToolController.java +++ b/src/main/java/eu/sshopencloud/marketplace/controllers/tools/ToolController.java @@ -32,7 +32,7 @@ public class ToolController { private final ToolService toolService; - @Operation(summary = "Retrieve all tools in pages") + @Operation(summary = "Retrieve all tools services in pages") @GetMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity getTools(@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "perpage", required = false) Integer perpage, @@ -157,7 +157,7 @@ public class ToolController { return ResponseEntity.ok(toolService.getSources(persistentId)); } - @Operation(summary = "Getting differences between tool and target version of item", operationId = "getToolAndVersionedItemDifferences") + @Operation(summary = "Getting differences between tool and target version of item ('unaltered' string response means for the single field that remained unchanged)", operationId = "getToolAndVersionedItemDifferences") @GetMapping(path = "/{persistentId}/diff", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity getToolVersionedItemDifferences(@PathVariable("persistentId") String persistentId, @RequestParam(required = true) String with, @@ -167,7 +167,7 @@ public class ToolController { } - @Operation(summary = "Getting differences between target version of tool and target version of item", operationId = "getVersionedToolAndVersionedItemDifferences") + @Operation(summary = "Getting differences between target version of tool and target version of item ('unaltered' string response means for the single field that remained unchanged)", operationId = "getVersionedToolAndVersionedItemDifferences") @GetMapping(path = "/{persistentId}/versions/{versionId}/diff", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity getVersionedToolVersionedItemDifferences(@PathVariable("persistentId") String persistentId, @PathVariable("versionId") long versionId, diff --git a/src/main/java/eu/sshopencloud/marketplace/controllers/trainings/TrainingMaterialController.java b/src/main/java/eu/sshopencloud/marketplace/controllers/trainings/TrainingMaterialController.java index 97405ba2220c619d1fbd65681458cc5c5c503be0..92f5c260710e4089d8b59ce15eb4da175daaede1 100644 --- a/src/main/java/eu/sshopencloud/marketplace/controllers/trainings/TrainingMaterialController.java +++ b/src/main/java/eu/sshopencloud/marketplace/controllers/trainings/TrainingMaterialController.java @@ -161,7 +161,7 @@ public class TrainingMaterialController { return ResponseEntity.ok(trainingMaterialService.getSources(persistentId)); } - @Operation(summary = "Getting differences between training material and target version of item", operationId = "getTrainingMaterialAndVersionedItemDifferences") + @Operation(summary = "Getting differences between training material and target version of item ('unaltered' string response means for the single field that remained unchanged)", operationId = "getTrainingMaterialAndVersionedItemDifferences") @GetMapping(path = "/{persistentId}/diff", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity getTrainingMaterialVersionedItemDifferences(@PathVariable("persistentId") String persistentId, @RequestParam(required = true) String with, @@ -171,7 +171,7 @@ public class TrainingMaterialController { } - @Operation(summary = "Getting differences between target version of training material and target version of item", operationId = "getVersionedTrainingMaterialAndVersionedItemDifferences") + @Operation(summary = "Getting differences between target version of training material and target version of item ('unaltered' string response means for the single field that remained unchanged)", operationId = "getVersionedTrainingMaterialAndVersionedItemDifferences") @GetMapping(path = "/{persistentId}/versions/{versionId}/diff", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity getVersionedTrainingMaterialVersionedItemDifferences(@PathVariable("persistentId") String persistentId, @PathVariable("versionId") long versionId, diff --git a/src/main/java/eu/sshopencloud/marketplace/controllers/workflows/WorkflowController.java b/src/main/java/eu/sshopencloud/marketplace/controllers/workflows/WorkflowController.java index 9a27038456453d998b965c005d5f8a8a93730776..d760c5ced158d50d155c13e7e35604925531ad8a 100644 --- a/src/main/java/eu/sshopencloud/marketplace/controllers/workflows/WorkflowController.java +++ b/src/main/java/eu/sshopencloud/marketplace/controllers/workflows/WorkflowController.java @@ -297,7 +297,7 @@ public class WorkflowController { return ResponseEntity.ok(stepService.getSources(workflowPersistentId, stepPersistentId)); } - @Operation(summary = "Getting differences between workflow and target version of item", operationId = "getWorkflowAndVersionedItemDifferences") + @Operation(summary = "Getting differences between workflow and target version of item ('unaltered' string response means for the single field that remained unchanged)", operationId = "getWorkflowAndVersionedItemDifferences") @GetMapping(path = "/{persistentId}/diff", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity getWorkflowVersionedItemDifferences(@PathVariable("persistentId") String persistentId, @RequestParam(required = true) String with, @@ -307,7 +307,7 @@ public class WorkflowController { } - @Operation(summary = "Getting differences between target version of workflow and target version of item", operationId = "getVersionedWorkflowAndVersionedItemDifferences") + @Operation(summary = "Getting differences between target version of workflow and target version of item ('unaltered' string response means for the single field that remained unchanged)", operationId = "getVersionedWorkflowAndVersionedItemDifferences") @GetMapping(path = "/{persistentId}/versions/{versionId}/diff", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity getVersionedWorkflowVersionedItemDifferences(@PathVariable("persistentId") String persistentId, @PathVariable("versionId") long versionId, @@ -318,7 +318,7 @@ public class WorkflowController { } - @Operation(summary = "Getting differences between step and target version of item", operationId = "getStepAndVersionedItemDifferences") + @Operation(summary = "Getting differences between step and target version of item ('unaltered' string response means for the single field that remained unchanged)", operationId = "getStepAndVersionedItemDifferences") @GetMapping(path = "/{persistentId}/steps/{stepPersistentId}/diff", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity getStepVersionedItemDifferences(@PathVariable("persistentId") String persistentId, @PathVariable("stepPersistentId") String stepPersistentId, @@ -329,7 +329,7 @@ public class WorkflowController { } - @Operation(summary = "Getting differences between target version of step and target version of item", operationId = "getVersionedStepAndVersionedItemDifferences") + @Operation(summary = "Getting differences between target version of step and target version of item ('unaltered' string response means for the single field that remained unchanged)", operationId = "getVersionedStepAndVersionedItemDifferences") @GetMapping(path = "/{persistentId}/steps/{stepPersistentId}/versions/{versionId}/diff", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity getVersionedStepVersionedItemDifferences(@PathVariable("persistentId") String persistentId, @PathVariable("stepPersistentId") String stepPersistentId, diff --git a/src/main/java/eu/sshopencloud/marketplace/dto/search/SearchConcept.java b/src/main/java/eu/sshopencloud/marketplace/dto/search/SearchConcept.java index ade43938c2016543878aec42aa3f6999e7e7e6c1..2e7a62043307a45fb9aa354e70599431f1e4769e 100644 --- a/src/main/java/eu/sshopencloud/marketplace/dto/search/SearchConcept.java +++ b/src/main/java/eu/sshopencloud/marketplace/dto/search/SearchConcept.java @@ -29,4 +29,6 @@ public class SearchConcept { private List types; + private boolean candidate; + } diff --git a/src/main/java/eu/sshopencloud/marketplace/model/workflows/StepsTree.java b/src/main/java/eu/sshopencloud/marketplace/model/workflows/StepsTree.java index 764325dadfab0d50c6370eaac02f3185dcf9628c..2c46c93522daf180ee54d88d90abdb6d3f7db0cd 100644 --- a/src/main/java/eu/sshopencloud/marketplace/model/workflows/StepsTree.java +++ b/src/main/java/eu/sshopencloud/marketplace/model/workflows/StepsTree.java @@ -165,6 +165,15 @@ public class StepsTree { // renumberSubTrees(); } + public void removePreviousDraftStep(Step step) { + String persistentId = step.getVersionedItem().getPersistentId(); + subTrees.removeIf( + st -> st.getStep().getVersionedItem().getPersistentId().equals(persistentId) + && st.getStep().getId().equals(step.getId()) + ); + + } + public void removeStep(Step step) { String persistentId = step.getVersionedItem().getPersistentId(); subTrees.removeIf(st -> st.getStep().getVersionedItem().getPersistentId().equals(persistentId)); diff --git a/src/main/java/eu/sshopencloud/marketplace/repositories/items/ItemRepository.java b/src/main/java/eu/sshopencloud/marketplace/repositories/items/ItemRepository.java index 149a0e1064b6e772855301c6db413fafec08376e..d4d14ba960f7815e6dd9264bf8c07c78272e3a73 100644 --- a/src/main/java/eu/sshopencloud/marketplace/repositories/items/ItemRepository.java +++ b/src/main/java/eu/sshopencloud/marketplace/repositories/items/ItemRepository.java @@ -86,4 +86,7 @@ public interface ItemRepository extends ItemVersionRepository { @Query("select i from Item i inner join ItemContributor c ON c.item.id = i.id WHERE c.actor.id = :id ORDER BY i.label") List findAllByContributorsActorId(@Param("id") Long id); + @Query("select i from Item i left join VersionedItem v ON i.versionedItem = v WHERE (i.status = 'APPROVED' AND v.active = true) OR (i.proposedVersion = true AND v.active = true)") + List findAllItemsToReindex(); + } diff --git a/src/main/java/eu/sshopencloud/marketplace/repositories/search/IndexItemRepository.java b/src/main/java/eu/sshopencloud/marketplace/repositories/search/IndexItemRepository.java index 55ec84a652e3b816ca82059fd6f634929ce91874..da2a7c1aed9e0bbd9679f79595352625a1d21d0d 100644 --- a/src/main/java/eu/sshopencloud/marketplace/repositories/search/IndexItemRepository.java +++ b/src/main/java/eu/sshopencloud/marketplace/repositories/search/IndexItemRepository.java @@ -8,4 +8,6 @@ import org.springframework.stereotype.Repository; public interface IndexItemRepository extends SolrCrudRepository { void deleteByPersistentId(String persistentId); + + } diff --git a/src/main/java/eu/sshopencloud/marketplace/services/actors/ActorHistoryService.java b/src/main/java/eu/sshopencloud/marketplace/services/actors/ActorHistoryService.java index cf38a333b98b0eddca86d78e187c1ec52b97cc5d..ffcc6acbc0e06e294cdd64be9eba3b81becfbc28 100644 --- a/src/main/java/eu/sshopencloud/marketplace/services/actors/ActorHistoryService.java +++ b/src/main/java/eu/sshopencloud/marketplace/services/actors/ActorHistoryService.java @@ -7,6 +7,7 @@ import eu.sshopencloud.marketplace.mappers.actors.ActorHistoryMapper; import eu.sshopencloud.marketplace.model.actors.Actor; import eu.sshopencloud.marketplace.model.actors.ActorHistory; import eu.sshopencloud.marketplace.repositories.actors.ActorHistoryRepository; +import eu.sshopencloud.marketplace.services.auth.LoggedInUserHolder; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -22,7 +23,7 @@ public class ActorHistoryService { private final ActorHistoryRepository actorHistoryRepository; - public ActorHistory createActorHistory(Actor actor, Actor mergeActor){ + public ActorHistory createActorHistory(Actor actor, Actor mergeActor) { Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().setPrettyPrinting().create(); String jsonHistoryString = gson.toJson(mergeActor); @@ -39,9 +40,15 @@ public class ActorHistoryService { } - public List findHistory(Actor actor){ + public List findHistory(Actor actor) { List history = actorHistoryRepository.findActorHistoryByActor(actor); - if(history==null) return new ArrayList<>(); - else return ActorHistoryMapper.INSTANCE.toDto(history); + if (history == null) { + return new ArrayList<>(); + } else { + List actorHistoryDtos = ActorHistoryMapper.INSTANCE.toDto(history); + if (!LoggedInUserHolder.getLoggedInUser().isModerator()) + actorHistoryDtos.forEach(actorHistoryDto -> actorHistoryDto.getActor().setEmail(null)); + return actorHistoryDtos; + } } } diff --git a/src/main/java/eu/sshopencloud/marketplace/services/actors/ActorService.java b/src/main/java/eu/sshopencloud/marketplace/services/actors/ActorService.java index ee140da29de54b14106c513d7020252f73a0d1a3..9db58009768bb6b6e01b6c8daae60b8f2034f59e 100644 --- a/src/main/java/eu/sshopencloud/marketplace/services/actors/ActorService.java +++ b/src/main/java/eu/sshopencloud/marketplace/services/actors/ActorService.java @@ -11,6 +11,7 @@ import eu.sshopencloud.marketplace.model.actors.Actor; import eu.sshopencloud.marketplace.model.actors.ActorExternalId; import eu.sshopencloud.marketplace.repositories.actors.ActorRepository; import eu.sshopencloud.marketplace.services.actors.event.ActorChangedEvent; +import eu.sshopencloud.marketplace.services.auth.LoggedInUserHolder; import eu.sshopencloud.marketplace.services.items.ItemsService; import eu.sshopencloud.marketplace.services.search.IndexActorService; import eu.sshopencloud.marketplace.validators.actors.ActorFactory; @@ -52,6 +53,8 @@ public class ActorService { List actors = actorsPage.stream().map(ActorMapper.INSTANCE::toDto).collect(Collectors.toList()); + if(LoggedInUserHolder.getLoggedInUser() ==null || !LoggedInUserHolder.getLoggedInUser().isModerator()) actors.forEach(actorDto -> actorDto.setEmail(null)); + return PaginatedActors.builder().actors(actors).count(actorsPage.getContent().size()) .hits(actorsPage.getTotalElements()).page(pageCoords.getPage()).perpage(pageCoords.getPerpage()) .pages(actorsPage.getTotalPages()).build(); @@ -69,6 +72,7 @@ public class ActorService { if (items) { actorDto.setItems(getItemsByActor(id)); } + if (LoggedInUserHolder.getLoggedInUser() ==null || !LoggedInUserHolder.getLoggedInUser().isModerator()) actorDto.setEmail(null); return actorDto; } @@ -77,7 +81,9 @@ public class ActorService { Actor actor = actorFactory.create(actorCore, null); actorRepository.save(actor); indexActorService.indexActor(actor); - return ActorMapper.INSTANCE.toDto(actor); + ActorDto actorDto = ActorMapper.INSTANCE.toDto(actor); + if (LoggedInUserHolder.getLoggedInUser() ==null || !LoggedInUserHolder.getLoggedInUser().isModerator()) actorDto.setEmail(null); + return actorDto; } @@ -91,7 +97,9 @@ public class ActorService { eventPublisher.publishEvent(new ActorChangedEvent(id, false)); - return ActorMapper.INSTANCE.toDto(actor); + ActorDto actorDto = ActorMapper.INSTANCE.toDto(actor); + if (LoggedInUserHolder.getLoggedInUser() ==null || !LoggedInUserHolder.getLoggedInUser().isModerator()) actorDto.setEmail(null); + return actorDto; } @@ -102,7 +110,8 @@ public class ActorService { actorRepository.deleteById(id); indexActorService.removeActor(id); - eventPublisher.publishEvent(new ActorChangedEvent(id, true)); + //TODO - rethink + // eventPublisher.publishEvent(new ActorChangedEvent(id, true)); } @@ -145,7 +154,9 @@ public class ActorService { with.forEach(this::deleteActor); - return ActorMapper.INSTANCE.toDto(actor); + ActorDto actorDto = ActorMapper.INSTANCE.toDto(actor); + if (LoggedInUserHolder.getLoggedInUser() ==null || !LoggedInUserHolder.getLoggedInUser().isModerator()) actorDto.setEmail(null); + return actorDto; } diff --git a/src/main/java/eu/sshopencloud/marketplace/services/items/DatasetService.java b/src/main/java/eu/sshopencloud/marketplace/services/items/DatasetService.java index 6ddbda0c851480f11ea9bb7fb54841541e9843f1..2800d26a9c80de55be8f1932dab23e64d2151def 100644 --- a/src/main/java/eu/sshopencloud/marketplace/services/items/DatasetService.java +++ b/src/main/java/eu/sshopencloud/marketplace/services/items/DatasetService.java @@ -16,6 +16,7 @@ import eu.sshopencloud.marketplace.repositories.items.DatasetRepository; import eu.sshopencloud.marketplace.repositories.items.DraftItemRepository; import eu.sshopencloud.marketplace.repositories.items.ItemRepository; import eu.sshopencloud.marketplace.repositories.items.VersionedItemRepository; +import eu.sshopencloud.marketplace.services.auth.LoggedInUserHolder; import eu.sshopencloud.marketplace.services.auth.UserService; import eu.sshopencloud.marketplace.services.items.exception.ItemIsAlreadyMergedException; import eu.sshopencloud.marketplace.services.items.exception.VersionNotChangedException; @@ -139,13 +140,23 @@ public class DatasetService extends ItemCrudService contributor.getActor().setEmail(null)); + } + return dto; } @Override public DatasetDto convertToDto(Item dataset) { - return DatasetMapper.INSTANCE.toDto(dataset); + DatasetDto dto = DatasetMapper.INSTANCE.toDto(dataset); + if(LoggedInUserHolder.getLoggedInUser() == null || !LoggedInUserHolder.getLoggedInUser().isModerator()) { + dto.getInformationContributor().setEmail(null); + dto.getContributors().forEach(contributor -> contributor.getActor().setEmail(null)); + } + return dto; } diff --git a/src/main/java/eu/sshopencloud/marketplace/services/items/ItemCrudService.java b/src/main/java/eu/sshopencloud/marketplace/services/items/ItemCrudService.java index 0b1dc291e012855bec89a00b41609bfb57a54589..1059d64fb1d44aa87aba6c0cd9f99b98252a1afd 100644 --- a/src/main/java/eu/sshopencloud/marketplace/services/items/ItemCrudService.java +++ b/src/main/java/eu/sshopencloud/marketplace/services/items/ItemCrudService.java @@ -9,6 +9,7 @@ import eu.sshopencloud.marketplace.dto.auth.UserDto; import eu.sshopencloud.marketplace.dto.items.*; import eu.sshopencloud.marketplace.dto.sources.SourceDto; import eu.sshopencloud.marketplace.dto.vocabularies.PropertyDto; +import eu.sshopencloud.marketplace.dto.workflows.WorkflowDto; import eu.sshopencloud.marketplace.mappers.items.ItemExtBasicConverter; import eu.sshopencloud.marketplace.model.auth.User; import eu.sshopencloud.marketplace.model.items.*; @@ -466,7 +467,6 @@ abstract class ItemCrudService relatedItems = new ArrayList<>(); List subjectRelations = itemRelatedItemRepository.findAllBySubjectId(itemId).stream() - .filter(relatedItem -> itemVisibilityService.shouldCurrentUserSeeItem(relatedItem.getObject())) + .filter(relatedItem -> itemVisibilityService.shouldCurrentUserSeeItem(relatedItem.getObject()) && itemVisibilityService.isTheLatestVersion(relatedItem.getObject())) .map(relatedItemsConverter::convertRelatedItemFromSubject) .collect(Collectors.toList()); List objectRelations = itemRelatedItemRepository.findAllByObjectId(itemId).stream() - .filter(relatedItem -> itemVisibilityService.shouldCurrentUserSeeItem(relatedItem.getSubject())) + .filter(relatedItem -> itemVisibilityService.shouldCurrentUserSeeItem(relatedItem.getSubject()) && itemVisibilityService.isTheLatestVersion(relatedItem.getSubject())) .map(relatedItemsConverter::convertRelatedItemFromObject) .collect(Collectors.toList()); diff --git a/src/main/java/eu/sshopencloud/marketplace/services/items/ItemVisibilityService.java b/src/main/java/eu/sshopencloud/marketplace/services/items/ItemVisibilityService.java index eb81127ac5681cb3c6bee125002a9929f3079a53..50e5ebae73be58a057f400e50c971e3774d806d3 100644 --- a/src/main/java/eu/sshopencloud/marketplace/services/items/ItemVisibilityService.java +++ b/src/main/java/eu/sshopencloud/marketplace/services/items/ItemVisibilityService.java @@ -56,8 +56,7 @@ class ItemVisibilityService { version.setStatus(SUGGESTED); versionedItem.setStatus(VersionedItemStatus.SUGGESTED); } - } - else if (currentUser.isSystemContributor()) { + } else if (currentUser.isSystemContributor()) { version.setStatus(ItemStatus.INGESTED); versionedItem.setStatus(VersionedItemStatus.INGESTED); } else if (currentUser.isContributor()) { @@ -75,11 +74,12 @@ class ItemVisibilityService { public boolean shouldSeeItem(Item item, User user) { if (item.getStatus().equals(ItemStatus.DEPRECATED)) return false; - return hasAccessToVersion(item, user); } + public boolean hasAccessToVersion(Item version, User user) { + ItemStatus itemStatus = version.getStatus(); if (itemStatus.equals(ItemStatus.APPROVED)) @@ -95,4 +95,22 @@ class ItemVisibilityService { && user.isContributor() && user.equals(version.getInformationContributor()); } + + + public boolean isTheLatestVersion(Item item) { + User currentUser = LoggedInUserHolder.getLoggedInUser(); + if (currentUser != null) { + if (currentUser.equals(item.getInformationContributor())) { + return item.getVersionedItem().getCurrentVersion().getId().equals(item.getId()); + } else { + if(currentUser.isModerator() && item.getVersionedItem().getCurrentVersion().getId().equals(item.getId())) + return true; + if(currentUser.isModerator() && !item.getVersionedItem().getCurrentVersion().getId().equals(item.getId())) + return false; + if(currentUser.isContributor() && !currentUser.isModerator() && !currentUser.isSystemContributor()) + return false; + } + } + return true; + } } diff --git a/src/main/java/eu/sshopencloud/marketplace/services/items/ItemsComparator.java b/src/main/java/eu/sshopencloud/marketplace/services/items/ItemsComparator.java index ae7f2e3f5942ac5f37f29ec90374b650f586f764..9408470286db6c2fdde4251587a79dde608acdf2 100644 --- a/src/main/java/eu/sshopencloud/marketplace/services/items/ItemsComparator.java +++ b/src/main/java/eu/sshopencloud/marketplace/services/items/ItemsComparator.java @@ -9,6 +9,7 @@ import eu.sshopencloud.marketplace.dto.vocabularies.*; import eu.sshopencloud.marketplace.dto.workflows.StepCore; import eu.sshopencloud.marketplace.dto.workflows.StepDto; import eu.sshopencloud.marketplace.dto.workflows.WorkflowCore; +import eu.sshopencloud.marketplace.dto.workflows.WorkflowDto; import eu.sshopencloud.marketplace.mappers.datasets.DatasetMapper; import eu.sshopencloud.marketplace.mappers.publications.PublicationMapper; import eu.sshopencloud.marketplace.mappers.tools.ToolMapper; @@ -25,10 +26,17 @@ import eu.sshopencloud.marketplace.model.workflows.Step; import eu.sshopencloud.marketplace.model.workflows.Workflow; import lombok.experimental.UtilityClass; +import java.time.ZoneId; +import java.time.ZonedDateTime; + @UtilityClass public class ItemsComparator { + private static final String notChangedField = "unaltered"; + + private static final ZonedDateTime notChangedDate = ZonedDateTime.of(0, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC")); + @SuppressWarnings(value = "rawtypes") public ItemsDifferencesDto differentiateItems(ItemDto item, ItemDto other) { ItemsDifferencesDto differences = createItemsDifferenceDto(item, other); @@ -119,11 +127,10 @@ public class ItemsComparator { } } - private void differentiateVersions(ItemDto item, ItemDto other, ItemsDifferencesDto differences) { if (item.getVersion() != null) { if (item.getVersion().equals(other.getVersion())) - other.setVersion(null); + other.setVersion(notChangedField); else differences.setEqual(false); } else { @@ -135,7 +142,7 @@ public class ItemsComparator { private void differentiateVersions(ItemCore item, ItemDto other, ItemDifferencesCore differences) { if (item.getVersion() != null) { if (item.getVersion().equals(other.getVersion())) - other.setVersion(null); + other.setVersion(notChangedField); else differences.setEqual(false); } else { @@ -178,7 +185,7 @@ public class ItemsComparator { if (item.getSourceItemId() != null) { if (item.getSourceItemId().equals(other.getSourceItemId())) - other.setSourceItemId(null); + other.setSourceItemId(notChangedField); else differences.setEqual(false); } else { @@ -213,7 +220,7 @@ public class ItemsComparator { for (i = 0; i < itemSize; i++) { if (i < otherSize) { if (item.getContributors().get(i).getActor().getId().equals(other.getContributors().get(i).getActor().getId()) - && item.getContributors().get(i).getRole().getCode().equals(other.getContributors().get(i).getRole().getCode())) { + && item.getContributors().get(i).getRole().getCode().equals(other.getContributors().get(i).getRole().getCode())) { other.getContributors().set(i, null); } else { differences.setEqual(false); @@ -292,7 +299,7 @@ public class ItemsComparator { for (i = 0; i < itemSize; i++) { if (i < otherSize) { if (item.getExternalIds().get(i).getIdentifierService().getCode().equals(other.getExternalIds().get(i).getIdentifierService().getCode()) - && item.getExternalIds().get(i).getIdentifier().equals(other.getExternalIds().get(i).getIdentifier())) { + && item.getExternalIds().get(i).getIdentifier().equals(other.getExternalIds().get(i).getIdentifier())) { other.getExternalIds().set(i, null); } else { differences.setEqual(false); @@ -345,26 +352,18 @@ public class ItemsComparator { } private boolean arePropertiesEqual(PropertyCore propertyCore, PropertyDto propertyDto) { - if ((propertyCore.getType().getCode().equals(propertyDto.getType().getCode())) + return (propertyCore.getType().getCode().equals(propertyDto.getType().getCode())) && ((propertyCore.getValue() != null && propertyCore.getValue().equals(propertyDto.getValue())) - || (propertyCore.getValue() == null && propertyDto.getValue() == null)) - && (areConceptsEqual(propertyCore.getConcept(), propertyDto.getConcept()))) { - return true; - } else { - return false; - } + || (propertyCore.getValue() == null && propertyDto.getValue() == null)) + && (areConceptsEqual(propertyCore.getConcept(), propertyDto.getConcept())); } private boolean areConceptsEqual(ConceptId conceptId, ConceptBasicDto conceptDto) { - if ((conceptId == null && conceptDto == null) - || ( - (conceptId != null && conceptId.getCode() != null && conceptId.getCode().equals(conceptDto.getCode())) - && (conceptId != null && conceptId.getVocabulary() != null && conceptId.getVocabulary().getCode() != null && conceptId.getVocabulary().getCode().equals(conceptDto.getVocabulary().getCode())) - && (conceptId != null && conceptId.getUri() != null && conceptId.getUri().equals(conceptDto.getUri())))) { - return true; - } else { - return false; - } + return !(!(conceptId == null && conceptDto == null) + && !( + (conceptId != null && conceptId.getCode() != null && conceptId.getCode().equals(conceptDto.getCode())) + && (conceptId != null && conceptId.getVocabulary() != null && conceptId.getVocabulary().getCode() != null && conceptId.getVocabulary().getCode().equals(conceptDto.getVocabulary().getCode())) + && (conceptId != null && conceptId.getUri() != null && conceptId.getUri().equals(conceptDto.getUri())))); } @@ -394,7 +393,7 @@ public class ItemsComparator { for (i = 0; i < itemSize; i++) { if (i < otherSize) { if (item.getRelatedItems().get(i).getPersistentId().equals(other.getRelatedItems().get(i).getPersistentId()) - && item.getRelatedItems().get(i).getRelation().getCode().equals(other.getRelatedItems().get(i).getRelation().getCode())) { + && item.getRelatedItems().get(i).getRelation().getCode().equals(other.getRelatedItems().get(i).getRelation().getCode())) { other.getRelatedItems().set(i, null); } else { differences.setEqual(false); @@ -467,14 +466,10 @@ public class ItemsComparator { } private boolean areMediaEqual(ItemMediaCore itemMediaCore, ItemMediaDto itemMediaDto) { - if (itemMediaCore.getInfo().getMediaId().equals(itemMediaDto.getInfo().getMediaId()) - && ((itemMediaCore.getCaption() != null && itemMediaCore.getCaption().equals(itemMediaDto.getCaption())) + return itemMediaCore.getInfo().getMediaId().equals(itemMediaDto.getInfo().getMediaId()) + && ((itemMediaCore.getCaption() != null && itemMediaCore.getCaption().equals(itemMediaDto.getCaption())) || (itemMediaCore.getCaption() == null && itemMediaDto.getCaption() == null)) - && (areConceptsEqual(itemMediaCore.getConcept(), itemMediaDto.getConcept()))) { - return true; - } else { - return false; - } + && (areConceptsEqual(itemMediaCore.getConcept(), itemMediaDto.getConcept())); } @@ -485,7 +480,7 @@ public class ItemsComparator { DigitalObjectDto otherDigitalObject = (DigitalObjectDto) other; if (itemDigitalObject.getDateCreated() != null) { if (itemDigitalObject.getDateCreated().equals(otherDigitalObject.getDateCreated())) - otherDigitalObject.setDateCreated(null); + otherDigitalObject.setDateCreated(notChangedDate); else differences.setEqual(false); } else { @@ -493,9 +488,9 @@ public class ItemsComparator { differences.setEqual(false); } if (itemDigitalObject.getDateLastUpdated() != null) { - if (itemDigitalObject.getDateLastUpdated().equals(otherDigitalObject.getDateLastUpdated())) - otherDigitalObject.setDateLastUpdated(null); - else + if (itemDigitalObject.getDateLastUpdated().equals(otherDigitalObject.getDateLastUpdated())) { + otherDigitalObject.setDateLastUpdated(notChangedDate); + } else differences.setEqual(false); } else { if (otherDigitalObject.getDateLastUpdated() != null) @@ -601,4 +596,37 @@ public class ItemsComparator { } } + public ItemsDifferencesDto differentiateComposedOf(WorkflowDto item, WorkflowDto other, ItemsDifferencesDto differences) { + + int itemSize = item.getComposedOf() != null ? item.getComposedOf().size() : 0; + int otherSize = other.getComposedOf() != null ? other.getComposedOf().size() : 0; + int i; + if (item.getComposedOf() != null) { + for (i = 0; i < itemSize; i++) { + if (i < otherSize) { + if (areStepsEqual(item.getComposedOf().get(i), other.getComposedOf().get(i))) { + other.getComposedOf().set(i, null); + } else { + differences.setEqual(false); + } + } else { + differences.setEqual(false); + } + } + if (itemSize != otherSize) + differences.setEqual(false); + } else { + if (other.getComposedOf() != null) { + differences.setEqual(false); + } + } + differences.setOther(other); + return differences; + } + + private boolean areStepsEqual(StepDto itemStepDto, StepDto otherStepDto) { + return itemStepDto.getId().equals(otherStepDto.getId()) && + itemStepDto.getPersistentId().equals(otherStepDto.getPersistentId()); + } + } diff --git a/src/main/java/eu/sshopencloud/marketplace/services/items/ItemsService.java b/src/main/java/eu/sshopencloud/marketplace/services/items/ItemsService.java index 85d79b2bfeb3ee3e7a81182e7e245a0fef311031..c02843a89ac3be85901212faade87259867cc756 100644 --- a/src/main/java/eu/sshopencloud/marketplace/services/items/ItemsService.java +++ b/src/main/java/eu/sshopencloud/marketplace/services/items/ItemsService.java @@ -82,7 +82,7 @@ public class ItemsService extends ItemVersionService { Page draftItemsPage = draftItemRepository.findByOwner(LoggedInUserHolder.getLoggedInUser(), PageRequest.of(pageCoords.getPage() - 1, pageCoords.getPerpage(), Sort.by(getSortOrderByItemOrder(order)))); - List items = draftItemsPage.stream().map(draftItem -> ItemConverter.convertItem(draftItem.getItem())).collect(Collectors.toList()); + List items = draftItemsPage.stream().filter(draftItem -> !draftItem.getItem().getCategory().equals(ItemCategory.STEP)).map(draftItem -> ItemConverter.convertItem(draftItem.getItem())).collect(Collectors.toList()); return PaginatedItemsBasic.builder().items(items) .count(draftItemsPage.getContent().size()).hits(draftItemsPage.getTotalElements()) diff --git a/src/main/java/eu/sshopencloud/marketplace/services/items/PublicationService.java b/src/main/java/eu/sshopencloud/marketplace/services/items/PublicationService.java index de8414d9fc8d3df4fafcfb4436bdc84acebfead6..f6820020580c949d04a7a6abc90d82b778b1b196 100644 --- a/src/main/java/eu/sshopencloud/marketplace/services/items/PublicationService.java +++ b/src/main/java/eu/sshopencloud/marketplace/services/items/PublicationService.java @@ -3,16 +3,19 @@ package eu.sshopencloud.marketplace.services.items; import eu.sshopencloud.marketplace.domain.media.MediaStorageService; import eu.sshopencloud.marketplace.dto.PageCoords; import eu.sshopencloud.marketplace.dto.auth.UserDto; +import eu.sshopencloud.marketplace.dto.datasets.DatasetDto; import eu.sshopencloud.marketplace.dto.items.ItemExtBasicDto; import eu.sshopencloud.marketplace.dto.items.ItemsDifferencesDto; import eu.sshopencloud.marketplace.dto.publications.PaginatedPublications; import eu.sshopencloud.marketplace.dto.publications.PublicationCore; import eu.sshopencloud.marketplace.dto.publications.PublicationDto; import eu.sshopencloud.marketplace.dto.sources.SourceDto; +import eu.sshopencloud.marketplace.mappers.datasets.DatasetMapper; import eu.sshopencloud.marketplace.mappers.publications.PublicationMapper; import eu.sshopencloud.marketplace.model.items.Item; import eu.sshopencloud.marketplace.model.publications.Publication; import eu.sshopencloud.marketplace.repositories.items.*; +import eu.sshopencloud.marketplace.services.auth.LoggedInUserHolder; import eu.sshopencloud.marketplace.services.auth.UserService; import eu.sshopencloud.marketplace.services.items.exception.ItemIsAlreadyMergedException; import eu.sshopencloud.marketplace.services.items.exception.VersionNotChangedException; @@ -131,12 +134,22 @@ public class PublicationService extends ItemCrudService contributor.getActor().setEmail(null)); + } + return dto; } @Override protected PublicationDto convertToDto(Item item) { - return PublicationMapper.INSTANCE.toDto(item); + PublicationDto dto = PublicationMapper.INSTANCE.toDto(item); + if(LoggedInUserHolder.getLoggedInUser() ==null || !LoggedInUserHolder.getLoggedInUser().isModerator()) { + dto.getInformationContributor().setEmail(null); + dto.getContributors().forEach(contributor -> contributor.getActor().setEmail(null)); + } + return dto; } @Override diff --git a/src/main/java/eu/sshopencloud/marketplace/services/items/StepService.java b/src/main/java/eu/sshopencloud/marketplace/services/items/StepService.java index 1ccfc4fc711de9c41cbaa608293167f9e8ca481b..a124ccc5d1f3e899cc114319236e8dd5dc0b54d9 100644 --- a/src/main/java/eu/sshopencloud/marketplace/services/items/StepService.java +++ b/src/main/java/eu/sshopencloud/marketplace/services/items/StepService.java @@ -90,14 +90,14 @@ public class StepService extends ItemCrudService contributor.getActor().setEmail(null)); + } + return dto; } @Override protected StepDto convertToDto(Item item) { - return StepMapper.INSTANCE.toDto(item); + StepDto dto = StepMapper.INSTANCE.toDto(item); + if (LoggedInUserHolder.getLoggedInUser() == null || !LoggedInUserHolder.getLoggedInUser().isModerator()) { + dto.getInformationContributor().setEmail(null); + dto.getContributors().forEach(contributor -> contributor.getActor().setEmail(null)); + } + return dto; } @@ -456,7 +471,7 @@ public class StepService extends ItemCrudService getInformationContributors(String workflowId, String stepId) { validateWorkflowAndStepVersionConsistency(workflowId, stepId, - getLatestStep(workflowId, stepId, false, true,false).getId()); + getLatestStep(workflowId, stepId, false, true, false).getId()); return super.getInformationContributors(stepId); } @@ -472,7 +487,7 @@ public class StepService extends ItemCrudService tmpMergingList = new ArrayList<>(mergeList); tmpMergingList.add(persistentId); - if (!checkMergeStepConsistency(tmpMergingList)) + if (checkMergeStepConsistency(tmpMergingList)) throw new IllegalArgumentException("Steps to merge are from different workflows!"); return prepareMergeItems(persistentId, mergeList); @@ -480,7 +495,7 @@ public class StepService extends ItemCrudService mergeList) throws ItemIsAlreadyMergedException { - if (!checkMergeStepConsistency(mergeList)) + if (checkMergeStepConsistency(mergeList)) throw new IllegalArgumentException("Steps to merge are from different workflows!"); checkIfMergeIsPossible(mergeList); StepDto stepDto; @@ -512,13 +527,13 @@ public class StepService extends ItemCrudService contributor.getActor().setEmail(null)); + } + return dto; } @Override protected ToolDto convertToDto(Item item) { - return ToolMapper.INSTANCE.toDto(item); + ToolDto dto = ToolMapper.INSTANCE.toDto(item); + if(LoggedInUserHolder.getLoggedInUser() ==null || !LoggedInUserHolder.getLoggedInUser().isModerator()){ + dto.getInformationContributor().setEmail(null); + dto.getContributors().forEach(contributor -> contributor.getActor().setEmail(null)); + } + return dto; } @Override diff --git a/src/main/java/eu/sshopencloud/marketplace/services/items/TrainingMaterialService.java b/src/main/java/eu/sshopencloud/marketplace/services/items/TrainingMaterialService.java index ecd70f0d2544d429c5f85b26850755d276d47eea..fe3351fa561a37f6a51be4b0888222fd0825b9b0 100644 --- a/src/main/java/eu/sshopencloud/marketplace/services/items/TrainingMaterialService.java +++ b/src/main/java/eu/sshopencloud/marketplace/services/items/TrainingMaterialService.java @@ -3,16 +3,19 @@ package eu.sshopencloud.marketplace.services.items; import eu.sshopencloud.marketplace.domain.media.MediaStorageService; import eu.sshopencloud.marketplace.dto.PageCoords; import eu.sshopencloud.marketplace.dto.auth.UserDto; +import eu.sshopencloud.marketplace.dto.datasets.DatasetDto; import eu.sshopencloud.marketplace.dto.items.ItemExtBasicDto; import eu.sshopencloud.marketplace.dto.items.ItemsDifferencesDto; import eu.sshopencloud.marketplace.dto.sources.SourceDto; import eu.sshopencloud.marketplace.dto.trainings.PaginatedTrainingMaterials; import eu.sshopencloud.marketplace.dto.trainings.TrainingMaterialCore; import eu.sshopencloud.marketplace.dto.trainings.TrainingMaterialDto; +import eu.sshopencloud.marketplace.mappers.datasets.DatasetMapper; import eu.sshopencloud.marketplace.mappers.trainings.TrainingMaterialMapper; import eu.sshopencloud.marketplace.model.items.Item; import eu.sshopencloud.marketplace.model.trainings.TrainingMaterial; import eu.sshopencloud.marketplace.repositories.items.*; +import eu.sshopencloud.marketplace.services.auth.LoggedInUserHolder; import eu.sshopencloud.marketplace.services.auth.UserService; import eu.sshopencloud.marketplace.services.items.exception.ItemIsAlreadyMergedException; import eu.sshopencloud.marketplace.services.items.exception.VersionNotChangedException; @@ -137,12 +140,22 @@ public class TrainingMaterialService @Override protected TrainingMaterialDto convertItemToDto(TrainingMaterial trainingMaterial) { - return TrainingMaterialMapper.INSTANCE.toDto(trainingMaterial); + TrainingMaterialDto trainingMaterialDto = TrainingMaterialMapper.INSTANCE.toDto(trainingMaterial); + if(LoggedInUserHolder.getLoggedInUser() ==null || !LoggedInUserHolder.getLoggedInUser().isModerator()){ + trainingMaterialDto.getInformationContributor().setEmail(null); + trainingMaterialDto.getContributors().forEach(contributor -> contributor.getActor().setEmail(null)); + } + return trainingMaterialDto; } @Override protected TrainingMaterialDto convertToDto(Item item) { - return TrainingMaterialMapper.INSTANCE.toDto(item); + TrainingMaterialDto trainingMaterialDto = TrainingMaterialMapper.INSTANCE.toDto(item); + if(LoggedInUserHolder.getLoggedInUser() ==null || !LoggedInUserHolder.getLoggedInUser().isModerator()){ + trainingMaterialDto.getInformationContributor().setEmail(null); + trainingMaterialDto.getContributors().forEach(contributor -> contributor.getActor().setEmail(null)); + } + return trainingMaterialDto; } @Override diff --git a/src/main/java/eu/sshopencloud/marketplace/services/items/WorkflowService.java b/src/main/java/eu/sshopencloud/marketplace/services/items/WorkflowService.java index 36f9c79e29cd52b9beae5ef009e89aabe4470de5..ca47e0c3c92eafee9738a1de3e96f926ae191127 100644 --- a/src/main/java/eu/sshopencloud/marketplace/services/items/WorkflowService.java +++ b/src/main/java/eu/sshopencloud/marketplace/services/items/WorkflowService.java @@ -13,6 +13,7 @@ import eu.sshopencloud.marketplace.dto.workflows.WorkflowDto; import eu.sshopencloud.marketplace.mappers.workflows.WorkflowMapper; import eu.sshopencloud.marketplace.model.auth.User; import eu.sshopencloud.marketplace.model.items.Item; +import eu.sshopencloud.marketplace.model.items.ItemCategory; import eu.sshopencloud.marketplace.model.items.ItemStatus; import eu.sshopencloud.marketplace.model.workflows.Step; import eu.sshopencloud.marketplace.model.workflows.StepsTree; @@ -77,7 +78,7 @@ public class WorkflowService extends ItemCrudService contributor.getActor().setEmail(null)); + } + collectSteps(dto, workflow); return dto; @@ -299,7 +308,13 @@ public class WorkflowService extends ItemCrudService contributor.getActor().setEmail(null)); + } + return dto; } @@ -343,7 +358,7 @@ public class WorkflowService extends ItemCrudService 0) { - stepService.addStepToTree(s.getStep(), null, parent); + stepService.addStepToTree(s.getStep(), null, parent, false); Step step = s.getStep(); List nextParentList = parent.getSubTrees().stream().filter(c -> c.getStep().equals(step)).collect(Collectors.toList()); StepsTree nextParent = nextParentList.get(0); @@ -351,7 +366,7 @@ public class WorkflowService extends ItemCrudService> results = sourceRepository.findDetailedSourcesOfItem(item.getPersistentId()); - List detailedSources = results.stream().map(DetailedSourceView::new) - .collect(Collectors.toList()); + List detailedSources = results.stream().map(DetailedSourceView::new).collect(Collectors.toList()); IndexItem indexedItem = IndexConverter.convertItem(item, itemRelatedItemService.countAllRelatedItems(item), detailedSources); + return indexItemRepository.save(indexedItem); } + public IndexItem indexItemAfterReindex(Item item) { + + List detailedSources = sourceRepository.findDetailedSourcesOfItem(item.getPersistentId()).stream().map(DetailedSourceView::new).collect(Collectors.toList()); + + return indexItemRepository.save(IndexConverter.convertItem(item, itemRelatedItemService.countAllRelatedItems(item), + detailedSources)); + } + + public void reindexItems() { + log.debug("Before item reindex."); clearItemIndex(); - for (Item item : itemRepository.findAll()) { - indexItem(item); + for (Item item : itemRepository.findAllItemsToReindex()) { + indexItemAfterReindex(item); } + log.debug("After item reindex."); } public void clearItemIndex() { @@ -76,8 +90,6 @@ public class IndexItemService { } - - @Async @TransactionalEventListener(classes = {SourceChangedEvent.class}, phase = TransactionPhase.AFTER_COMMIT) public void handleChangedSource(SourceChangedEvent event) { diff --git a/src/main/java/eu/sshopencloud/marketplace/services/search/SearchConverter.java b/src/main/java/eu/sshopencloud/marketplace/services/search/SearchConverter.java index 884a79455ac82c5071278c7e7688aab57109e3d4..4ca40fb796f49e5da8e0d055d274809cf60e16cb 100644 --- a/src/main/java/eu/sshopencloud/marketplace/services/search/SearchConverter.java +++ b/src/main/java/eu/sshopencloud/marketplace/services/search/SearchConverter.java @@ -10,6 +10,7 @@ import eu.sshopencloud.marketplace.model.search.IndexConcept; import eu.sshopencloud.marketplace.model.search.IndexItem; import eu.sshopencloud.marketplace.model.vocabularies.PropertyType; import eu.sshopencloud.marketplace.mappers.items.ItemCategoryConverter; +import eu.sshopencloud.marketplace.services.auth.LoggedInUserHolder; import lombok.experimental.UtilityClass; import org.springframework.data.solr.core.query.result.FacetFieldEntry; @@ -44,7 +45,7 @@ public class SearchConverter { .build(); } - public SearchActor convertIndexActor(IndexActor indexActor) { + public SearchActor convertNotRestrictedIndexActor(IndexActor indexActor) { return SearchActor.builder() .id(Long.valueOf(indexActor.getId())) .name(indexActor.getName()) @@ -53,6 +54,22 @@ public class SearchConverter { .build(); } + public SearchActor convertRestrictedIndexActor(IndexActor indexActor) { + return SearchActor.builder() + .id(Long.valueOf(indexActor.getId())) + .name(indexActor.getName()) + .website(indexActor.getWebsite()) + .build(); + } + + + public SearchActor convertIndexActor(IndexActor indexActor) { + if(LoggedInUserHolder.getLoggedInUser() ==null || !LoggedInUserHolder.getLoggedInUser().isModerator()) return convertRestrictedIndexActor(indexActor); + else + return convertNotRestrictedIndexActor(indexActor); + + } + public LabeledCheckedCount convertCategoryFacet(FacetFieldEntry entry, List categories) { String code = entry.getValue(); ItemCategory category = ItemCategoryConverter.convertCategory(code); @@ -76,6 +93,7 @@ public class SearchConverter { return SearchConcept.builder() .code(indexConcept.getCode()).vocabulary(vocabulary).label(indexConcept.getLabel()).notation(indexConcept.getNotation()).definition(indexConcept.getDefinition()) .uri(indexConcept.getUri()) + .candidate(indexConcept.getCandidate()) .types(indexConcept.getTypes().stream() .map(type -> { PropertyTypeId propertyType = new PropertyTypeId(); diff --git a/src/main/java/eu/sshopencloud/marketplace/services/search/SearchService.java b/src/main/java/eu/sshopencloud/marketplace/services/search/SearchService.java index b0efd2455e359b3e1c7cda097f7fc9911da716e3..4daf11774bb3fb08e338b66e725b1ec2c53d2648 100644 --- a/src/main/java/eu/sshopencloud/marketplace/services/search/SearchService.java +++ b/src/main/java/eu/sshopencloud/marketplace/services/search/SearchService.java @@ -301,7 +301,7 @@ public class SearchService { private SearchExpressionCriteria createExpressionCriteria(String code, String expression) { - if(expression.contains("/")) expression = ClientUtils.escapeQueryChars(expression); + if (expression.contains("/")) expression = ClientUtils.escapeQueryChars(expression); PropertyType propertyType = propertyTypeService.loadPropertyTypeOrNull(code); if (propertyType != null) { @@ -330,6 +330,7 @@ public class SearchService { .pages(facetPage.getTotalPages()) .build(); + // TODO index affiliations directly in SOLR in nested docs (?) - // TODO in a similar way add external identifiers to the result for (SearchActor searchActor : result.getActors()) { @@ -337,8 +338,10 @@ public class SearchService { searchActor.setExternalIds(ActorExternalIdMapper.INSTANCE.toDto(actor.getExternalIds())); searchActor.setAffiliations(ActorMapper.INSTANCE.toDto(actor.getAffiliations())); - } + if (LoggedInUserHolder.getLoggedInUser() == null || !LoggedInUserHolder.getLoggedInUser().isModerator()) + searchActor.getAffiliations().forEach(affiliation -> affiliation.setEmail(null)); + } return result; } diff --git a/src/main/java/eu/sshopencloud/marketplace/services/sources/SourceService.java b/src/main/java/eu/sshopencloud/marketplace/services/sources/SourceService.java index 7931b8ddd885b5440a2df1d6779134fa42089092..8d117f555db41176bce48a357bb35f36efdb4712 100644 --- a/src/main/java/eu/sshopencloud/marketplace/services/sources/SourceService.java +++ b/src/main/java/eu/sshopencloud/marketplace/services/sources/SourceService.java @@ -89,8 +89,6 @@ public class SourceService { throw new EntityNotFoundException("Unable to find " + Source.class.getName() + " with id " + id); } sourceRepository.deleteById(id); - - eventPublisher.publishEvent(new SourceChangedEvent(id, true)); } private Sort.Order getSortOrderBySourceOrder(SourceOrder sourceOrder) { diff --git a/src/test/java/eu/sshopencloud/marketplace/controllers/actors/ActorControllerITCase.java b/src/test/java/eu/sshopencloud/marketplace/controllers/actors/ActorControllerITCase.java index 7b293d71b5923af922ddb16d60bc300555a82409..e13c742914456af9fe05f50edce7b417f3289c93 100644 --- a/src/test/java/eu/sshopencloud/marketplace/controllers/actors/ActorControllerITCase.java +++ b/src/test/java/eu/sshopencloud/marketplace/controllers/actors/ActorControllerITCase.java @@ -72,13 +72,29 @@ public class ActorControllerITCase { .andExpect(jsonPath("id", is(actorId))) .andExpect(jsonPath("name", is("John Smith"))) .andExpect(jsonPath("website", is("https://example.com/"))) - .andExpect(jsonPath("email", is("john@example.com"))) .andExpect(jsonPath("affiliations", hasSize(1))) .andExpect(jsonPath("affiliations[0].id", is(3))) .andExpect(jsonPath("affiliations[0].name", is("SSHOC project consortium"))) .andExpect(jsonPath("affiliations[0].website", is("https://sshopencloud.eu/"))); } + @Test + public void shouldReturnActorForModerator() throws Exception { + Integer actorId = 5; + + mvc.perform(get("/api/actors/{id}", actorId) + .header("Authorization", MODERATOR_JWT) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("id", is(actorId))) + .andExpect(jsonPath("name", is("John Smith"))) + .andExpect(jsonPath("website", is("https://example.com/"))) + .andExpect(jsonPath("email", is("john@example.com"))) + .andExpect(jsonPath("affiliations", hasSize(1))) + .andExpect(jsonPath("affiliations[0].id", is(3))) + .andExpect(jsonPath("affiliations[0].name", is("SSHOC project consortium"))) + .andExpect(jsonPath("affiliations[0].website", is("https://sshopencloud.eu/"))); + } @Test public void shouldReturnActorWithItems() throws Exception { Integer actorId = 5; @@ -90,7 +106,6 @@ public class ActorControllerITCase { .andExpect(jsonPath("id", is(actorId))) .andExpect(jsonPath("name", is("John Smith"))) .andExpect(jsonPath("website", is("https://example.com/"))) - .andExpect(jsonPath("email", is("john@example.com"))) .andExpect(jsonPath("affiliations", hasSize(1))) .andExpect(jsonPath("affiliations[0].id", is(3))) .andExpect(jsonPath("affiliations[0].name", is("SSHOC project consortium"))) @@ -117,7 +132,6 @@ public class ActorControllerITCase { .andExpect(jsonPath("id", is(actorId))) .andExpect(jsonPath("name", is("John Smith"))) .andExpect(jsonPath("website", is("https://example.com/"))) - .andExpect(jsonPath("email", is("john@example.com"))) .andExpect(jsonPath("affiliations", hasSize(1))) .andExpect(jsonPath("affiliations[0].id", is(3))) .andExpect(jsonPath("affiliations[0].name", is("SSHOC project consortium"))) @@ -151,7 +165,6 @@ public class ActorControllerITCase { .andExpect(status().isOk()) .andExpect(jsonPath("name", is("Test actor"))) .andExpect(jsonPath("website", is("http://www.example.org"))) - .andExpect(jsonPath("email", is("test@example.org"))) .andExpect(jsonPath("affiliations", hasSize(0))); } @@ -178,7 +191,6 @@ public class ActorControllerITCase { .header("Authorization", CONTRIBUTOR_JWT)) .andExpect(status().isOk()) .andExpect(jsonPath("name", is("Test actor"))) - .andExpect(jsonPath("email", is("test@example.org"))) .andExpect(jsonPath("affiliations", hasSize(2))) .andExpect(jsonPath("affiliations[0].name", is("Austrian Academy of Sciences"))) .andExpect(jsonPath("affiliations[1].name", is("CESSDA"))) @@ -206,7 +218,6 @@ public class ActorControllerITCase { .andExpect(status().isOk()) .andExpect(jsonPath("id", notNullValue())) .andExpect(jsonPath("name", is("Test actor"))) - .andExpect(jsonPath("email", is("test@example.org"))) .andExpect(jsonPath("externalIds", hasSize(1))) .andExpect(jsonPath("externalIds[0].identifierService.code", is("DBLP"))) .andExpect(jsonPath("externalIds[0].identifierService.label", is("DBLP"))) @@ -222,7 +233,6 @@ public class ActorControllerITCase { .andExpect(status().isOk()) .andExpect(jsonPath("id", is(actorDto.getId().intValue()))) .andExpect(jsonPath("name", is("Test actor"))) - .andExpect(jsonPath("email", is("test@example.org"))) .andExpect(jsonPath("externalIds", hasSize(1))) .andExpect(jsonPath("externalIds[0].identifierService.code", is("DBLP"))) .andExpect(jsonPath("externalIds[0].identifierService.label", is("DBLP"))) @@ -254,7 +264,6 @@ public class ActorControllerITCase { .andExpect(status().isOk()) .andExpect(jsonPath("id", notNullValue())) .andExpect(jsonPath("name", is("Test actor"))) - .andExpect(jsonPath("email", is("test@example.org"))) .andExpect(jsonPath("externalIds", hasSize(2))) .andExpect(jsonPath("externalIds[0].identifierService.code", is("ORCID"))) .andExpect(jsonPath("externalIds[0].identifierService.label", is("ORCID"))) @@ -275,7 +284,6 @@ public class ActorControllerITCase { .andExpect(status().isOk()) .andExpect(jsonPath("id", is(actorDto.getId().intValue()))) .andExpect(jsonPath("name", is("Test actor"))) - .andExpect(jsonPath("email", is("test@example.org"))) .andExpect(jsonPath("externalIds", hasSize(2))) .andExpect(jsonPath("externalIds[0].identifierService.code", is("ORCID"))) .andExpect(jsonPath("externalIds[0].identifierService.label", is("ORCID"))) @@ -449,12 +457,12 @@ public class ActorControllerITCase { ActorCore actor = new ActorCore(); actor.setName("Test actor"); actor.setEmail("test@example.org"); - List affiliations = new ArrayList(); + List affiliations = new ArrayList<>(); ActorId affiliation1 = new ActorId(); - affiliation1.setId(100l); + affiliation1.setId(100L); affiliations.add(affiliation1); ActorId affiliation2 = new ActorId(); - affiliation2.setId(4l); + affiliation2.setId(4L); affiliations.add(affiliation2); actor.setAffiliations(affiliations); @@ -591,7 +599,7 @@ public class ActorControllerITCase { ActorCore actor = new ActorCore(); actor.setName("Actor to delete"); actor.setEmail("test@example.org"); - List affiliations = new ArrayList(); + List affiliations = new ArrayList<>(); ActorId affiliation1 = new ActorId(); affiliation1.setId(1L); affiliations.add(affiliation1); @@ -644,7 +652,6 @@ public class ActorControllerITCase { .andExpect(status().isOk()) .andExpect(jsonPath("id", notNullValue())) .andExpect(jsonPath("name", is("Test actor"))) - .andExpect(jsonPath("email", is("test@example.org"))) .andExpect(jsonPath("externalIds", hasSize(2))) .andExpect(jsonPath("externalIds[0].identifierService.code", is("ORCID"))) .andExpect(jsonPath("externalIds[0].identifierService.label", is("ORCID"))) @@ -665,7 +672,6 @@ public class ActorControllerITCase { .andExpect(status().isOk()) .andExpect(jsonPath("id", is(actorDto.getId().intValue()))) .andExpect(jsonPath("name", is("Test actor"))) - .andExpect(jsonPath("email", is("test@example.org"))) .andExpect(jsonPath("externalIds", hasSize(2))) .andExpect(jsonPath("externalIds[0].identifierService.code", is("ORCID"))) .andExpect(jsonPath("externalIds[0].identifierService.label", is("ORCID"))) @@ -698,7 +704,6 @@ public class ActorControllerITCase { .andExpect(status().isOk()) .andExpect(jsonPath("id", notNullValue())) .andExpect(jsonPath("name", is(actor2.getName()))) - .andExpect(jsonPath("email", is(actor2.getEmail()))) .andExpect(jsonPath("externalIds", hasSize(1))) .andExpect(jsonPath("externalIds[0].identifierService.code", is("ORCID"))) .andExpect(jsonPath("externalIds[0].identifierService.label", is("ORCID"))) diff --git a/src/test/java/eu/sshopencloud/marketplace/controllers/datasets/DatasetControllerITCase.java b/src/test/java/eu/sshopencloud/marketplace/controllers/datasets/DatasetControllerITCase.java index 1090e8c90da8b79dc058b28d5b01b82c1cb5ec12..db8d8503c4188787a48fb9886d94e07c12da3574 100644 --- a/src/test/java/eu/sshopencloud/marketplace/controllers/datasets/DatasetControllerITCase.java +++ b/src/test/java/eu/sshopencloud/marketplace/controllers/datasets/DatasetControllerITCase.java @@ -2023,7 +2023,7 @@ public class DatasetControllerITCase { String responseDataset = mvc.perform( get("/api/datasets/{id}",datasetPersistentId) .param("approved", "false") - .header("Authorization", IMPORTER_JWT) + .header("Authorization", ADMINISTRATOR_JWT) ) .andExpect(status().isOk()) .andExpect(jsonPath("persistentId", is(datasetPersistentId))) @@ -2076,7 +2076,7 @@ public class DatasetControllerITCase { mvc.perform( get("/api/tools-services/{id}", otherToolPersistentId ) .param("approved", "false") - .header("Authorization", IMPORTER_JWT) + .header("Authorization", ADMINISTRATOR_JWT) ) .andExpect(status().isOk()) .andExpect(jsonPath("persistentId", is(otherToolPersistentId))) @@ -2097,7 +2097,7 @@ public class DatasetControllerITCase { mvc.perform(get("/api/datasets/{persistentId}/diff", datasetPersistentId) .contentType(MediaType.APPLICATION_JSON) .param("with", otherToolPersistentId) - .header("Authorization", MODERATOR_JWT)) + .header("Authorization", ADMINISTRATOR_JWT)) .andExpect(status().isOk()) .andExpect(jsonPath("item.persistentId", is(datasetPersistentId))) .andExpect(jsonPath("item.category", is("dataset"))) diff --git a/src/test/java/eu/sshopencloud/marketplace/controllers/search/SearchControllerITCase.java b/src/test/java/eu/sshopencloud/marketplace/controllers/search/SearchControllerITCase.java index 562b6a76aaadfaa007e3e44d44d9ba932ea1b8da..c62fa4b1cf1a84a37e640768290bfdb1b2f6c6cb 100644 --- a/src/test/java/eu/sshopencloud/marketplace/controllers/search/SearchControllerITCase.java +++ b/src/test/java/eu/sshopencloud/marketplace/controllers/search/SearchControllerITCase.java @@ -50,14 +50,14 @@ public class SearchControllerITCase { @Before public void init() throws Exception { CONTRIBUTOR_JWT = LogInTestClient.getJwt(mvc, "Contributor", "q1w2e3r4t5"); - MODERATOR_JWT = LogInTestClient.getJwt(mvc, "Moderator", "q1w2e3r4t5"); + MODERATOR_JWT = LogInTestClient.getJwt(mvc, "Moderator", "q1w2e3r4t5"); } @Test public void shouldReturnAllItems() throws Exception { mvc.perform(get("/api/item-search") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); } @@ -65,7 +65,7 @@ public class SearchControllerITCase { public void shouldReturnItemsByWord() throws Exception { mvc.perform(get("/api/item-search?q=gephi") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("items", hasSize(3))) .andExpect(jsonPath("items[0].id", is(1))) @@ -108,11 +108,11 @@ public class SearchControllerITCase { String payload = mapper.writeValueAsString(dataset); mvc.perform( - put("/api/datasets/{datasetId}", datasetId) - .contentType(MediaType.APPLICATION_JSON) - .content(payload) - .header("Authorization", CONTRIBUTOR_JWT) - ) + put("/api/datasets/{datasetId}", datasetId) + .contentType(MediaType.APPLICATION_JSON) + .content(payload) + .header("Authorization", CONTRIBUTOR_JWT) + ) .andExpect(status().isOk()) .andExpect(jsonPath("persistentId", is(datasetId))) .andExpect(jsonPath("id", not(is(datasetVersionId)))) @@ -124,9 +124,9 @@ public class SearchControllerITCase { solrTemplate.commit(IndexItem.COLLECTION_NAME); mvc.perform( - get("/api/item-search?q=test") - .header("Authorization", CONTRIBUTOR_JWT) - ) + get("/api/item-search?q=test&d.status=(suggested OR approved)") + .header("Authorization", CONTRIBUTOR_JWT) + ) .andExpect(status().isOk()) .andExpect(jsonPath("items", hasSize(2))) .andExpect(jsonPath("items[0].id", not(is(datasetVersionId)))) @@ -157,7 +157,7 @@ public class SearchControllerITCase { public void shouldReturnItemsByPhrase() throws Exception { mvc.perform(get("/api/item-search?q=\"dummy text ever\"") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("items", hasSize(1))) .andExpect(jsonPath("items[0].id", is(7))) @@ -179,7 +179,7 @@ public class SearchControllerITCase { public void shouldReturnItemsByKeyword() throws Exception { mvc.perform(get("/api/item-search?q=topic modeling") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("items", hasSize(2))) .andExpect(jsonPath("items[0].id", is(2))) @@ -207,7 +207,7 @@ public class SearchControllerITCase { public void shouldReturnItemsByKeywordAndFilterByCategories() throws Exception { mvc.perform(get("/api/item-search?q=topic modeling&categories=tool-or-service,training-material") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("items", hasSize(1))) .andExpect(jsonPath("items[0].id", is(2))) @@ -232,7 +232,7 @@ public class SearchControllerITCase { public void shouldReturnItemsByKeywordPhrase() throws Exception { mvc.perform(get("/api/item-search?q=\"topic modeling\"") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("items", hasSize(2))) .andExpect(jsonPath("items[*].id", containsInAnyOrder(11, 2))) @@ -256,7 +256,7 @@ public class SearchControllerITCase { public void shouldReturnItemsWildcardPhrase() throws Exception { mvc.perform(get("/api/item-search?q=(topi* OR \"Introduction to GEPHI\")&advanced=true") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("items", hasSize(4))) .andExpect(jsonPath("items[*].id", containsInAnyOrder(7, 2, 11, 8))) @@ -280,7 +280,7 @@ public class SearchControllerITCase { public void shouldReturnItemsByKeywordPhraseAndFilterByCategories() throws Exception { mvc.perform(get("/api/item-search?q=\"topic modeling\"&categories=tool-or-service,training-material") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("items", hasSize(1))) .andExpect(jsonPath("items[0].id", is(2))) @@ -306,7 +306,7 @@ public class SearchControllerITCase { public void shouldReturnItemsByKeywordPart() throws Exception { mvc.perform(get("/api/item-search?q=topic") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("items", hasSize(3))) .andExpect(jsonPath("items[*].id", containsInAnyOrder(8, 11, 2))) @@ -334,7 +334,7 @@ public class SearchControllerITCase { public void shouldReturnItemsByKeywordPartAndFilterByCategories() throws Exception { mvc.perform(get("/api/item-search?q=topic&categories=tool-or-service,training-material") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("items", hasSize(2))) .andExpect(jsonPath("items[0].id", is(8))) @@ -365,7 +365,7 @@ public class SearchControllerITCase { public void shouldReturnItemsByKeywordPartAndFilterBySubfilters() throws Exception { mvc.perform(get("/api/item-search?q=topic&f.keyword=Lorem ipsum&f.keyword=topic modeling") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("items", hasSize(2))) .andExpect(jsonPath("items[*].id", containsInAnyOrder(2, 11))) @@ -391,7 +391,7 @@ public class SearchControllerITCase { public void shouldReturnItemsByKeywordPartAndFilterByCategoriesAndSubfilters() throws Exception { mvc.perform(get("/api/item-search?q=topic&categories=tool-or-service,training-material&f.keyword=Lorem ipsum&f.keyword=topic modeling") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("items", hasSize(1))) .andExpect(jsonPath("items[0].id", is(2))) @@ -418,7 +418,7 @@ public class SearchControllerITCase { public void shouldReturnItemsByWordAndSortedByLabel() throws Exception { mvc.perform(get("/api/item-search?q=gephi&order=label") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("items", hasSize(3))) .andExpect(jsonPath("items[0].id", is(1))) @@ -448,7 +448,7 @@ public class SearchControllerITCase { public void shouldReturnItemsByWordAndFilteredByCategories() throws Exception { mvc.perform(get("/api/item-search?q=gephi&categories=tool-or-service,dataset") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("items", hasSize(1))) .andExpect(jsonPath("items[0].id", is(1))) @@ -472,7 +472,7 @@ public class SearchControllerITCase { public void shouldReturnItemsByWordAndFilteredBySubfilters() throws Exception { mvc.perform(get("/api/item-search?q=gephi&f.keyword=social network analysis") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("items", hasSize(1))) .andExpect(jsonPath("items[0].id", is(1))) @@ -497,7 +497,7 @@ public class SearchControllerITCase { public void shouldReturnItemsByWordAndFilteredByCategoriesAndSubfilters() throws Exception { mvc.perform(get("/api/item-search?q=gephi&categories=tool-or-service,dataset&f.keyword=social network analysis") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("items", hasSize(1))) .andExpect(jsonPath("items[0].id", is(1))) @@ -522,7 +522,7 @@ public class SearchControllerITCase { public void shouldReturnItemsByWordAndFilteredByCategoriesAndSubfiltersWithNonExistentValue() throws Exception { mvc.perform(get("/api/item-search?q=gephi&categories=tool-or-service,dataset&f.keyword=non_existent_value") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("items", hasSize(0))) .andExpect(jsonPath("categories.tool-or-service.count", is(0))) @@ -544,7 +544,7 @@ public class SearchControllerITCase { public void shouldReturnItemsByExpressionOnContributors() throws Exception { mvc.perform(get("/api/item-search?d.contributor=(+CESSDE~ -*Academy*)") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("items", hasSize(3))) .andExpect(jsonPath("items[0].id", is(10))) @@ -579,7 +579,7 @@ public class SearchControllerITCase { public void shouldReturnItemsByExpressionOnContributorsAndExpressionOnLanguage() throws Exception { mvc.perform(get("/api/item-search?d.contributor=(+CESSDE~ -*Academy*)&d.language=(en?)") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("items", hasSize(1))) .andExpect(jsonPath("items[0].id", is(4))) @@ -602,7 +602,7 @@ public class SearchControllerITCase { public void shouldReturnAllConcepts() throws Exception { mvc.perform(get("/api/concept-search") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); } @@ -610,11 +610,12 @@ public class SearchControllerITCase { public void shouldReturnConceptsByWordAndFilteredByTypes() throws Exception { mvc.perform(get("/api/concept-search?q=software&types=object-type,activity") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("concepts[0].code", is("83"))) .andExpect(jsonPath("concepts[0].vocabulary.code", is("tadirah-activity"))) .andExpect(jsonPath("concepts[0].label", is("Software"))) + .andExpect(jsonPath("concepts[0].candidate", is(false))) .andExpect(jsonPath("types.activity.count", is(7))) .andExpect(jsonPath("types.activity.checked", is(true))) .andExpect(jsonPath("facets.candidate.['false'].count", is(7))) @@ -622,23 +623,22 @@ public class SearchControllerITCase { } - @Test public void shouldNotCrashWhenSearchingItemsForASlash() throws Exception { mvc.perform( - get("/api/item-search") - .param("q", " / ") - // .param("advanced", "true") - ) + get("/api/item-search") + .param("q", " / ") + // .param("advanced", "true") + ) .andExpect(status().isOk()); } @Test public void shouldNotCrashWhenSearchingConceptsForASlash() throws Exception { mvc.perform( - get("/api/concept-search") - .param("q", "teaching / learning") - ) + get("/api/concept-search") + .param("q", "teaching / learning") + ) .andExpect(status().isOk()); } @@ -646,7 +646,7 @@ public class SearchControllerITCase { public void shouldReturnConceptsWithCandidateFacet() throws Exception { mvc.perform(get("/api/concept-search?q=new&f.candidate=false") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("concepts", hasSize(9))) .andExpect(jsonPath("facets.candidate.['false'].count", is(9))) @@ -658,7 +658,7 @@ public class SearchControllerITCase { public void shouldReturnAllActors() throws Exception { mvc.perform(get("/api/actor-search") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); } @@ -666,10 +666,9 @@ public class SearchControllerITCase { public void shouldReturnActorsByWebsite() throws Exception { mvc.perform(get("/api/actor-search?q=CESSDA") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("actors[0].id", is(4))) - .andExpect(jsonPath("actors[0].email", is("cessda@cessda.eu"))) .andExpect(jsonPath("actors[0].name", is("CESSDA"))) .andExpect(jsonPath("actors[0].website", is("https://www.cessda.eu/"))) .andExpect(jsonPath("actors[0].externalIds", hasSize(0))) @@ -681,7 +680,8 @@ public class SearchControllerITCase { public void shouldReturnActorsByDynamicParametersEmail() throws Exception { mvc.perform(get("/api/actor-search?d.email=cessda@cessda.eu") - .contentType(MediaType.APPLICATION_JSON)) + .header("Authorization", MODERATOR_JWT) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("actors[0].id", is(4))) .andExpect(jsonPath("actors[0].email", is("cessda@cessda.eu"))) @@ -695,7 +695,8 @@ public class SearchControllerITCase { public void shouldReturnActorsByEmailExpression() throws Exception { mvc.perform(get("/api/actor-search?d.email=(*@*)") - .contentType(MediaType.APPLICATION_JSON)) + .header("Authorization", MODERATOR_JWT) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("hits", is(2))) .andExpect(jsonPath("actors[0].id", is(4))) @@ -720,10 +721,10 @@ public class SearchControllerITCase { .andExpect(status().isOk()) .andExpect(jsonPath("phrase", is("gep"))) .andExpect(jsonPath("suggestions", hasSize(3))) - .andExpect(jsonPath("suggestions[0].phrase", is("Gephi"))) - .andExpect(jsonPath("suggestions[0].persistentId", is("n21Kfc"))) - .andExpect(jsonPath("suggestions[1].phrase", is("Gephi: an open source software for exploring and manipulating networks."))) - .andExpect(jsonPath("suggestions[1].persistentId", is("heBAGQ"))) + .andExpect(jsonPath("suggestions[0].phrase", is("Gephi: an open source software for exploring and manipulating networks."))) + .andExpect(jsonPath("suggestions[0].persistentId", is("heBAGQ"))) + .andExpect(jsonPath("suggestions[1].phrase", is("Gephi"))) + .andExpect(jsonPath("suggestions[1].persistentId", is("n21Kfc"))) .andExpect(jsonPath("suggestions[2].phrase", is("Introduction to GEPHI"))) .andExpect(jsonPath("suggestions[2].persistentId", is("WfcKvG"))); } @@ -732,7 +733,7 @@ public class SearchControllerITCase { public void shouldReturnAutocompleteSuggestionWithCategoryForItems() throws Exception { mvc.perform(get("/api/item-search/autocomplete?q=gep&category=training-material") - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("phrase", is("gep"))) .andExpect(jsonPath("suggestions", hasSize(2))) diff --git a/src/test/java/eu/sshopencloud/marketplace/controllers/trainings/TrainingMaterialControllerITCase.java b/src/test/java/eu/sshopencloud/marketplace/controllers/trainings/TrainingMaterialControllerITCase.java index 2db419e0e7a5f61967b0f628d8637ea09c79c4b6..0d5959b0e1797b0c382c1a4fdf8ddbc38440d753 100644 --- a/src/test/java/eu/sshopencloud/marketplace/controllers/trainings/TrainingMaterialControllerITCase.java +++ b/src/test/java/eu/sshopencloud/marketplace/controllers/trainings/TrainingMaterialControllerITCase.java @@ -2209,7 +2209,7 @@ public class TrainingMaterialControllerITCase { } @Test - public void shouldApproveTrainingMaterialRelatedToAToolMultipleTimes() throws Exception { + public void shouldApproveTrainingMaterialRelatedToATool() throws Exception { String trainingMaterialId = "heBAGQ"; String relatedObjectId = "n21Kfc"; @@ -2240,14 +2240,10 @@ public class TrainingMaterialControllerITCase { ) .andExpect(status().isOk()) .andExpect(jsonPath("persistentId", is(relatedObjectId))) - .andExpect(jsonPath("relatedItems", hasSize(3))) - .andExpect(jsonPath("relatedItems[0].persistentId", is("Xgufde"))) - .andExpect(jsonPath("relatedItems[1].persistentId", is(trainingMaterialId))) - .andExpect(jsonPath("relatedItems[1].id", is(4))) - .andExpect(jsonPath("relatedItems[1].relation.code", is("is-documented-by"))) - .andExpect(jsonPath("relatedItems[2].persistentId", is(trainingMaterialId))) - .andExpect(jsonPath("relatedItems[2].id", not(is(4)))) - .andExpect(jsonPath("relatedItems[2].relation.code", is("is-documented-by"))); + .andExpect(jsonPath("relatedItems", hasSize(1))) + .andExpect(jsonPath("relatedItems[0].persistentId", is(trainingMaterialId))) + .andExpect(jsonPath("relatedItems[0].relation.code", is("is-documented-by"))); + trainingMaterial.setLabel("Gephi: explore the networks!"); @@ -2297,14 +2293,10 @@ public class TrainingMaterialControllerITCase { ) .andExpect(status().isOk()) .andExpect(jsonPath("persistentId", is(relatedObjectId))) - .andExpect(jsonPath("relatedItems", hasSize(3))) + .andExpect(jsonPath("relatedItems", hasSize(2))) .andExpect(jsonPath("relatedItems[0].persistentId", is("Xgufde"))) .andExpect(jsonPath("relatedItems[1].persistentId", is(trainingMaterialId))) - .andExpect(jsonPath("relatedItems[1].id", is(4))) - .andExpect(jsonPath("relatedItems[1].relation.code", is("is-documented-by"))) - .andExpect(jsonPath("relatedItems[2].persistentId", is(trainingMaterialId))) - .andExpect(jsonPath("relatedItems[2].id", not(is(4)))) - .andExpect(jsonPath("relatedItems[2].relation.code", is("is-documented-by"))); + .andExpect(jsonPath("relatedItems[1].relation.code", is("is-documented-by"))); ToolCore tool = new ToolCore(); tool.setLabel("Gephi: lonline"); diff --git a/src/test/java/eu/sshopencloud/marketplace/controllers/vocabularies/VocabularyControllerITCase.java b/src/test/java/eu/sshopencloud/marketplace/controllers/vocabularies/VocabularyControllerITCase.java index 94a820fe60d4f4362ae80f3e401f41805bbc2a0c..d18bb1c9280c53dd38070ac3ba581acadda8474d 100644 --- a/src/test/java/eu/sshopencloud/marketplace/controllers/vocabularies/VocabularyControllerITCase.java +++ b/src/test/java/eu/sshopencloud/marketplace/controllers/vocabularies/VocabularyControllerITCase.java @@ -685,6 +685,7 @@ public class VocabularyControllerITCase { ItemMediaCore seriouscat = new ItemMediaCore(new MediaDetailsId(seriouscatId), "Serious Cat", new ConceptId(conceptCode, new VocabularyId(vocabularyCode), null)); mvc.perform(get("/api/datasets") + .header("Authorization", contributorJwt) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("datasets", hasSize(3))) @@ -740,6 +741,7 @@ public class VocabularyControllerITCase { get("/api/training-materials/{id}", persistenId) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) + .header("Authorization", contributorJwt) ) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) diff --git a/src/test/java/eu/sshopencloud/marketplace/controllers/workflows/WorkflowControllerITCase.java b/src/test/java/eu/sshopencloud/marketplace/controllers/workflows/WorkflowControllerITCase.java index aa4a39fe9cefa5b314ced30aa7aae190deb63d13..5632d69531bc877f331a2e2eaf9e18ca7c7b2c9a 100644 --- a/src/test/java/eu/sshopencloud/marketplace/controllers/workflows/WorkflowControllerITCase.java +++ b/src/test/java/eu/sshopencloud/marketplace/controllers/workflows/WorkflowControllerITCase.java @@ -2950,4 +2950,58 @@ public class WorkflowControllerITCase { } + @Test + public void shouldReturnDifferenceBetweenWorkflows() throws Exception { + String workflowPersistentId = "tqmbGY"; + Integer workflowId = 12; + String otherWorkflowPersistentId = "vHQEhe"; + Integer otherWorkflowId = 21; + + mvc.perform(get("/api/workflows/{persistentId}/diff", workflowPersistentId) + .contentType(MediaType.APPLICATION_JSON) + .param("with", otherWorkflowPersistentId) + .header("Authorization", MODERATOR_JWT)) + .andExpect(status().isOk()) + .andExpect(jsonPath("item.persistentId", is(workflowPersistentId))) + .andExpect(jsonPath("item.id", is(workflowId))) + .andExpect(jsonPath("item.category", is("workflow"))) + .andExpect(jsonPath("item.label", is("Creation of a dictionary"))) + .andExpect(jsonPath("item.informationContributor.id", is(3))) + .andExpect(jsonPath("item.properties[0].type.code", is("language"))) + .andExpect(jsonPath("item.properties[0].concept.code", is("eng"))) + .andExpect(jsonPath("item.composedOf", hasSize(4))) + .andExpect(jsonPath("equal", is(false))) + .andExpect(jsonPath("other.persistentId", is(otherWorkflowPersistentId))) + .andExpect(jsonPath("other.id", is(otherWorkflowId))) + .andExpect(jsonPath("other.category", is("workflow"))) + .andExpect(jsonPath("other.label", is("Evaluation of an inflectional analyzer"))) + .andExpect(jsonPath("other.composedOf", hasSize(3))) + .andExpect(jsonPath("other.informationContributor.id", is(1))); + } + + @Test + public void shouldNotReturnDifferenceBetweenComposedOf() throws Exception { + String workflowPersistentId = "tqmbGY"; + Integer workflowId = 12; + + mvc.perform(get("/api/workflows/{persistentId}/diff", workflowPersistentId) + .contentType(MediaType.APPLICATION_JSON) + .param("with", workflowPersistentId) + .header("Authorization", MODERATOR_JWT)) + .andExpect(status().isOk()) + .andExpect(jsonPath("item.persistentId", is(workflowPersistentId))) + .andExpect(jsonPath("item.id", is(workflowId))) + .andExpect(jsonPath("item.category", is("workflow"))) + .andExpect(jsonPath("item.label", is("Creation of a dictionary"))) + .andExpect(jsonPath("item.informationContributor.id", is(3))) + .andExpect(jsonPath("item.properties[0].type.code", is("language"))) + .andExpect(jsonPath("item.properties[0].concept.code", is("eng"))) + .andExpect(jsonPath("item.composedOf", hasSize(4))) + .andExpect(jsonPath("equal", is(true))) + .andExpect(jsonPath("other.composedOf[0]", nullValue())) + .andExpect(jsonPath("other.composedOf[1]", nullValue())) + .andExpect(jsonPath("other.composedOf[2]", nullValue())) + .andExpect(jsonPath("other.composedOf[3]", nullValue())); + } + }