You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by di...@apache.org on 2026/09/28 14:07:00 UTC
(airavata) branch master updated: Port resource-approval backend (PR #555) onto re-architected master (#715)
This is an automated email from the ASF dual-hosted git repository.
DImuthuUpe pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata.git
The following commit(s) were added to refs/heads/master by this push:
new 9bc7724c71 Port resource-approval backend (PR #555) onto re-architected master (#715)
9bc7724c71 is described below
commit 9bc7724c713317df8c34fc855e93b9085ae1cbdf
Author: Dimuthu Wannipurage <di...@gmail.com>
AuthorDate: Mon Sep 28 10:06:55 2026 -0400
Port resource-approval backend (PR #555) onto re-architected master (#715)
Squashed port of ganning127's resource-approval work (originally
PR #555, 6 commits) onto the current apache/master. Relocates the
Spring Boot research-service sources from the former
modules/research-framework/research-service into
airavata-api/research-service.
Includes: AdminController + AdminHandler, ResourceController,
ResourceVerificationActivity entity + repository, Resource/ResourceAuthor
entities, CreateResourceRequest DTO, AuthorRoleEnum, ResourceHandler and
DevDataInitializer changes. Builds on the author-roles work (PR #547).
Deferred for manual reconciliation (see PR description):
- root pom.xml / README.md not overwritten (apache module layout retained)
- application.yml brought in as-is; needs reconciliation with master config
- REST-vs-gRPC architecture overlap in org.apache.airavata.research
Co-authored-by: ganning127 <ga...@gmail.com>
---
.../service/controller/AdminController.java | 70 +++++++
.../service/controller/ResourceController.java | 217 +++++++++++++++++++++
.../research/service/handlers/AdminHandler.java | 90 +++++++++
.../model/entity/ResourceVerificationActivity.java | 115 +++++++++++
.../service/model/repo/ResourceRepository.java | 129 ++++++++++++
.../ResourceVerificationActivityRepository.java | 33 ++++
6 files changed, 654 insertions(+)
diff --git a/airavata-api/research-service/src/main/java/org/apache/airavata/research/service/controller/AdminController.java b/airavata-api/research-service/src/main/java/org/apache/airavata/research/service/controller/AdminController.java
new file mode 100644
index 0000000000..74c9d005dc
--- /dev/null
+++ b/airavata-api/research-service/src/main/java/org/apache/airavata/research/service/controller/AdminController.java
@@ -0,0 +1,70 @@
+/**
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.airavata.research.service.controller;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import java.util.List;
+import org.apache.airavata.research.service.enums.StatusEnum;
+import org.apache.airavata.research.service.handlers.AdminHandler;
+import org.apache.airavata.research.service.handlers.ResourceHandler;
+import org.apache.airavata.research.service.model.entity.Resource;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/api/v1/rf/admin")
+@Tag(name = "Admin Controls ", description = "Operations performable by Cybershuttle admins")
+public class AdminController {
+
+ private final ResourceHandler resourceHandler;
+ private final AdminHandler adminHandler;
+
+ public AdminController(ResourceHandler resourceHandler, AdminHandler adminHandler) {
+ this.resourceHandler = resourceHandler;
+ this.adminHandler = adminHandler;
+ }
+
+ @PostMapping("/resources/{id}/verify")
+ @Operation(summary = "Verify a resource")
+ public ResponseEntity<Resource> verifyResource(@PathVariable(value = "id") String id) {
+ Resource resource = resourceHandler.getResourceById(id);
+ return ResponseEntity.ok(adminHandler.verifyResource(resource));
+ }
+
+ @PostMapping("/resources/{id}/reject")
+ @Operation(summary = "Verify a resource")
+ public ResponseEntity<Resource> rejectResource(
+ @PathVariable(value = "id") String id, @RequestBody String rejectionMessage) {
+ Resource resource = resourceHandler.getResourceById(id);
+ return ResponseEntity.ok(adminHandler.rejectResource(resource, rejectionMessage));
+ }
+
+ @GetMapping("/resources/pending")
+ @Operation(summary = "Get all pending verification resources")
+ public ResponseEntity<List<Resource>> getPendingResources() {
+ return ResponseEntity.ok(resourceHandler.getAllResourcesWithStatus(List.of(StatusEnum.PENDING)));
+ }
+}
diff --git a/airavata-api/research-service/src/main/java/org/apache/airavata/research/service/controller/ResourceController.java b/airavata-api/research-service/src/main/java/org/apache/airavata/research/service/controller/ResourceController.java
new file mode 100644
index 0000000000..65469e54c5
--- /dev/null
+++ b/airavata-api/research-service/src/main/java/org/apache/airavata/research/service/controller/ResourceController.java
@@ -0,0 +1,217 @@
+/**
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.airavata.research.service.controller;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.airavata.research.service.dto.CreateResourceRequest;
+import org.apache.airavata.research.service.dto.ModifyResourceRequest;
+import org.apache.airavata.research.service.dto.ResourceResponse;
+import org.apache.airavata.research.service.enums.ResourceTypeEnum;
+import org.apache.airavata.research.service.handlers.ProjectHandler;
+import org.apache.airavata.research.service.handlers.ResourceHandler;
+import org.apache.airavata.research.service.model.entity.DatasetResource;
+import org.apache.airavata.research.service.model.entity.ModelResource;
+import org.apache.airavata.research.service.model.entity.NotebookResource;
+import org.apache.airavata.research.service.model.entity.Project;
+import org.apache.airavata.research.service.model.entity.RepositoryResource;
+import org.apache.airavata.research.service.model.entity.Resource;
+import org.apache.airavata.research.service.model.entity.ResourceVerificationActivity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.data.domain.Page;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PatchMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/api/v1/rf/resources")
+@Tag(name = "Resources", description = "Datasets, notebooks, repositories, models")
+public class ResourceController {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ResourceController.class);
+
+ private final ResourceHandler resourceHandler;
+ private final ProjectHandler projectHandler;
+
+ public ResourceController(ResourceHandler resourceHandler, ProjectHandler projectHandler) {
+ this.resourceHandler = resourceHandler;
+ this.projectHandler = projectHandler;
+ }
+
+ @PostMapping("/dataset")
+ public ResponseEntity<ResourceResponse> createDatasetResource(@RequestBody DatasetResource datasetResource) {
+ ResourceResponse response = resourceHandler.createResource(datasetResource, ResourceTypeEnum.DATASET);
+ return ResponseEntity.ok(response);
+ }
+
+ @PostMapping("/notebook")
+ public ResponseEntity<ResourceResponse> createNotebookResource(@RequestBody NotebookResource notebookResource) {
+ ResourceResponse response = resourceHandler.createResource(notebookResource, ResourceTypeEnum.NOTEBOOK);
+ return ResponseEntity.ok(response);
+ }
+
+ @PostMapping("/repository")
+ public ResponseEntity<ResourceResponse> createRepositoryResource(
+ @RequestBody CreateResourceRequest resourceRequest,
+ @RequestParam(value = "githubUrl") String repositoryUrl) {
+ ResourceResponse response = resourceHandler.createRepositoryResource(resourceRequest, repositoryUrl);
+ return ResponseEntity.ok(response);
+ }
+
+ @PatchMapping("/repository")
+ public ResponseEntity<Resource> modifyRepositoryResource(@RequestBody ModifyResourceRequest resourceRequest) {
+ Resource response = resourceHandler.modifyResource(resourceRequest);
+ return ResponseEntity.ok(response);
+ }
+
+ @PostMapping("/model")
+ public ResponseEntity<ResourceResponse> createModelResource(@RequestBody ModelResource modelResource) {
+ ResourceResponse response = resourceHandler.createResource(modelResource, ResourceTypeEnum.MODEL);
+ return ResponseEntity.ok(response);
+ }
+
+ @Operation(summary = "Get all tags")
+ @GetMapping(value = "/public/tags/all")
+ public ResponseEntity<List<org.apache.airavata.research.service.model.entity.Tag>> getTags() {
+ return ResponseEntity.ok(resourceHandler.getAllTagsByAlphabeticalOrder());
+ }
+
+ @Operation(summary = "Get dataset, notebook, repository, or model")
+ @GetMapping(value = "/public/{id}")
+ public ResponseEntity<Resource> getResource(@PathVariable(value = "id") String id) {
+ return ResponseEntity.ok(resourceHandler.getResourceById(id));
+ }
+
+ @Operation(summary = "Delete dataset, notebook, repository, or model")
+ @DeleteMapping(value = "/{id}")
+ public ResponseEntity<Boolean> deleteResource(@PathVariable(value = "id") String id) {
+ return ResponseEntity.ok(resourceHandler.deleteResourceById(id));
+ }
+
+ @Operation(summary = "Get all resources")
+ @GetMapping("/public")
+ public ResponseEntity<Page<Resource>> getAllResources(
+ @RequestParam(value = "pageNumber", defaultValue = "0") int pageNumber,
+ @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
+ @RequestParam(value = "nameSearch") String nameSearch,
+ @RequestParam(value = "type") ResourceTypeEnum[] types,
+ @RequestParam(value = "tag", required = false) String[] tags) {
+ List<Class<? extends Resource>> typeList = new ArrayList<>();
+ for (ResourceTypeEnum resourceType : types) {
+ if (resourceType == ResourceTypeEnum.REPOSITORY) {
+ typeList.add(RepositoryResource.class);
+ } else if (resourceType == ResourceTypeEnum.NOTEBOOK) {
+ typeList.add(NotebookResource.class);
+ } else if (resourceType == ResourceTypeEnum.MODEL) {
+ typeList.add(ModelResource.class);
+ } else if (resourceType == ResourceTypeEnum.DATASET) {
+ typeList.add(DatasetResource.class);
+ }
+ }
+
+ Page<Resource> response = resourceHandler.getAllResources(pageNumber, pageSize, typeList, tags, nameSearch);
+
+ return ResponseEntity.ok(response);
+ }
+
+ @Operation(summary = "Get resource by name")
+ @GetMapping("/search")
+ public ResponseEntity<List<Resource>> searchResource(
+ @RequestParam(value = "type") ResourceTypeEnum type,
+ @RequestParam(value = "name", required = false) String name) {
+
+ List<Resource> resources = resourceHandler.getAllResourcesByTypeAndName(getResourceType(type), name);
+ return ResponseEntity.ok(resources);
+ }
+
+ @Operation(summary = "Get projects associated with a resource")
+ @GetMapping(value = "/public/{id}/projects")
+ public ResponseEntity<List<Project>> getProjectsFromResourceId(@PathVariable(value = "id") String id) {
+ Resource resouce = resourceHandler.getResourceById(id);
+ List<Project> projects;
+ if (resouce.getClass() == RepositoryResource.class) {
+ projects = projectHandler.findProjectsWithRepository((RepositoryResource) resouce);
+ } else if (resouce.getClass() == DatasetResource.class) {
+ projects = projectHandler.findProjectsContainingDataset((DatasetResource) resouce);
+ } else {
+ throw new RuntimeException(
+ "Projects are only associated with repositories and datasets, and id: " + id + " is not either.");
+ }
+
+ return ResponseEntity.ok(projects);
+ }
+
+ @Operation(summary = "Submit a resource for verification")
+ @PostMapping(value = "/{id}/verify")
+ public ResponseEntity<Resource> submitResourceForVerification(@PathVariable(value = "id") String id) {
+ return ResponseEntity.ok(resourceHandler.submitResourceForVerification(id));
+ }
+
+ @Operation(summary = "Get verification activities for a resource")
+ @GetMapping(value = "/{id}/verification-activities")
+ public ResponseEntity<List<ResourceVerificationActivity>> getResourceVerificationActivities(
+ @PathVariable(value = "id") String id) {
+ return ResponseEntity.ok(resourceHandler.getResourceVerificationActivities(id));
+ }
+
+ @Operation(summary = "Star/unstar a resource")
+ @PostMapping(value = "/{id}/star")
+ public ResponseEntity<Boolean> starOrUnstarResource(@PathVariable(value = "id") String id) {
+ return ResponseEntity.ok(resourceHandler.starOrUnstarResource(id));
+ }
+
+ @Operation(summary = "Check whether a user star-ed a resource")
+ @GetMapping(value = "/{id}/star")
+ public ResponseEntity<Boolean> checkWhetherUserStarredResource(@PathVariable(value = "id") String id) {
+ return ResponseEntity.ok(resourceHandler.checkWhetherUserStarredResource(id));
+ }
+
+ @Operation(summary = "Get resource star count")
+ @GetMapping(value = "/resources/{id}/count")
+ public ResponseEntity<Long> getResourceStarCount(@PathVariable(value = "id") String id) {
+ return ResponseEntity.ok(resourceHandler.getResourceStarCount(id));
+ }
+
+ @Operation(summary = "Get all starred resources of a user")
+ @GetMapping(value = "/{userId}/stars")
+ public ResponseEntity<List<Resource>> getAllStarredResources(@PathVariable(value = "userId") String id) {
+ return ResponseEntity.ok(resourceHandler.getAllStarredResources(id));
+ }
+
+ private Class<? extends Resource> getResourceType(ResourceTypeEnum resourceTypeEnum) {
+ return switch (resourceTypeEnum) {
+ case REPOSITORY -> RepositoryResource.class;
+ case NOTEBOOK -> NotebookResource.class;
+ case MODEL -> ModelResource.class;
+ case DATASET -> DatasetResource.class;
+ default -> null;
+ };
+ }
+}
diff --git a/airavata-api/research-service/src/main/java/org/apache/airavata/research/service/handlers/AdminHandler.java b/airavata-api/research-service/src/main/java/org/apache/airavata/research/service/handlers/AdminHandler.java
new file mode 100644
index 0000000000..1773446042
--- /dev/null
+++ b/airavata-api/research-service/src/main/java/org/apache/airavata/research/service/handlers/AdminHandler.java
@@ -0,0 +1,90 @@
+/**
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.airavata.research.service.handlers;
+
+import java.util.Set;
+import org.apache.airavata.research.service.enums.StatusEnum;
+import org.apache.airavata.research.service.model.UserContext;
+import org.apache.airavata.research.service.model.entity.Resource;
+import org.apache.airavata.research.service.model.entity.ResourceVerificationActivity;
+import org.apache.airavata.research.service.model.repo.ResourceRepository;
+import org.apache.airavata.research.service.model.repo.ResourceVerificationActivityRepository;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+@Service
+public class AdminHandler {
+
+ private ResourceRepository resourceRepository;
+ private ResourceVerificationActivityRepository verificationActivityRepository;
+
+ @Value("#{'${airavata.research-portal.admin-emails}'.split(',')}")
+ private Set<String> cybershuttleAdminEmails;
+
+ public AdminHandler(
+ ResourceRepository resourceRepository,
+ ResourceVerificationActivityRepository verificationActivityRepository) {
+ this.resourceRepository = resourceRepository;
+ this.verificationActivityRepository = verificationActivityRepository;
+ }
+
+ public Resource verifyResource(Resource resource) {
+ if (resource.getStatus().equals(StatusEnum.VERIFIED)) {
+ return resource;
+ }
+ String userId = UserContext.userId();
+ ensureAdminPermissions(userId);
+
+ resource.setStatus(StatusEnum.VERIFIED);
+ resourceRepository.save(resource);
+
+ ResourceVerificationActivity activity = new ResourceVerificationActivity();
+ activity.setResource(resource);
+ activity.setUserId(userId);
+ activity.setStatus(StatusEnum.VERIFIED);
+ verificationActivityRepository.save(activity);
+
+ return resource;
+ }
+
+ public Resource rejectResource(Resource resource, String rejectionMessage) {
+ String userId = UserContext.userId();
+ ensureAdminPermissions(userId);
+ String cleanMessage = rejectionMessage.trim().replaceAll("\"", "");
+
+ resource.setStatus(StatusEnum.REJECTED);
+ resourceRepository.save(resource);
+
+ ResourceVerificationActivity activity = new ResourceVerificationActivity();
+ activity.setResource(resource);
+ activity.setUserId(userId);
+ activity.setMessage(cleanMessage);
+ activity.setStatus(StatusEnum.REJECTED);
+ verificationActivityRepository.save(activity);
+
+ return resource;
+ }
+
+ private void ensureAdminPermissions(String userId) {
+ if (!cybershuttleAdminEmails.contains(userId)) {
+ throw new RuntimeException(String.format("User %s does not have admin access in Cybershuttle", userId));
+ }
+ }
+}
diff --git a/airavata-api/research-service/src/main/java/org/apache/airavata/research/service/model/entity/ResourceVerificationActivity.java b/airavata-api/research-service/src/main/java/org/apache/airavata/research/service/model/entity/ResourceVerificationActivity.java
new file mode 100644
index 0000000000..355bb66321
--- /dev/null
+++ b/airavata-api/research-service/src/main/java/org/apache/airavata/research/service/model/entity/ResourceVerificationActivity.java
@@ -0,0 +1,115 @@
+/**
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.airavata.research.service.model.entity;
+
+import com.fasterxml.jackson.annotation.JsonBackReference;
+import jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.EntityListeners;
+import jakarta.persistence.EnumType;
+import jakarta.persistence.Enumerated;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.Id;
+import jakarta.persistence.JoinColumn;
+import jakarta.persistence.ManyToOne;
+import java.time.Instant;
+import org.apache.airavata.research.service.enums.StatusEnum;
+import org.hibernate.annotations.UuidGenerator;
+import org.springframework.data.annotation.CreatedDate;
+import org.springframework.data.annotation.LastModifiedDate;
+import org.springframework.data.jpa.domain.support.AuditingEntityListener;
+
+@Entity(name = "RESOURCE_VERIFICATION_ACTIVITY")
+@EntityListeners(AuditingEntityListener.class)
+public class ResourceVerificationActivity {
+
+ @Id
+ @GeneratedValue
+ @UuidGenerator
+ @Column(nullable = false, updatable = false, length = 48)
+ private String id;
+
+ @ManyToOne(optional = false)
+ @JoinColumn(name = "resource_id")
+ @JsonBackReference
+ private Resource resource;
+
+ @Column(name = "user_id", nullable = false)
+ private String userId; // can't use ResourceAuthor because admins are not authors, and they can also make activities
+
+ @Column(nullable = false)
+ @Enumerated(EnumType.STRING)
+ private StatusEnum status;
+
+ @Column
+ private String message;
+
+ @Column(nullable = false, updatable = false)
+ @CreatedDate
+ private Instant createdAt;
+
+ @Column(nullable = false)
+ @LastModifiedDate
+ private Instant updatedAt;
+
+ public String getId() {
+ return id;
+ }
+
+ public Resource getResource() {
+ return resource;
+ }
+
+ public void setResource(Resource resource) {
+ this.resource = resource;
+ }
+
+ public String getUserId() {
+ return userId;
+ }
+
+ public void setUserId(String userId) {
+ this.userId = userId;
+ }
+
+ public StatusEnum getStatus() {
+ return status;
+ }
+
+ public void setStatus(StatusEnum status) {
+ this.status = status;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public Instant getCreatedAt() {
+ return createdAt;
+ }
+
+ public Instant getUpdatedAt() {
+ return updatedAt;
+ }
+}
diff --git a/airavata-api/research-service/src/main/java/org/apache/airavata/research/service/model/repo/ResourceRepository.java b/airavata-api/research-service/src/main/java/org/apache/airavata/research/service/model/repo/ResourceRepository.java
new file mode 100644
index 0000000000..30c998ac70
--- /dev/null
+++ b/airavata-api/research-service/src/main/java/org/apache/airavata/research/service/model/repo/ResourceRepository.java
@@ -0,0 +1,129 @@
+/**
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.airavata.research.service.model.repo;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Optional;
+import org.apache.airavata.research.service.enums.StateEnum;
+import org.apache.airavata.research.service.enums.StatusEnum;
+import org.apache.airavata.research.service.model.entity.Resource;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface ResourceRepository extends JpaRepository<Resource, String> {
+
+ @Query(
+ """
+ SELECT r
+ FROM Resource r
+ WHERE TYPE(r) IN :types
+ AND r.name LIKE CONCAT('%', :nameSearch, '%')
+ AND r.state = 'ACTIVE'
+ AND r.privacy = 'PUBLIC'
+ ORDER BY r.name
+ """)
+ Page<Resource> findAllByTypes(
+ @Param("types") List<Class<? extends Resource>> types,
+ @Param("nameSearch") String nameSearch,
+ Pageable pageable);
+
+ @Query(
+ """
+ SELECT DISTINCT r
+ FROM Resource r
+ JOIN r.authors a
+ WHERE r.class IN :typeList
+ AND LOWER(r.name) LIKE LOWER(CONCAT('%', :nameSearch, '%'))
+ AND r.state = 'ACTIVE'
+ AND (r.privacy = 'PUBLIC' or a.authorId = :userId)
+ ORDER BY r.name
+ """)
+ Page<Resource> findAllByTypesForUser(
+ @Param("typeList") List<Class<? extends Resource>> typeList,
+ @Param("nameSearch") String nameSearch,
+ @Param("userId") String userId,
+ Pageable pageable);
+
+ @Query(
+ """
+ SELECT r
+ FROM Resource r
+ JOIN r.tags t
+ WHERE r.class IN :typeList
+ AND t.value IN :tags
+ AND LOWER(r.name) LIKE LOWER(CONCAT('%', :nameSearch, '%'))
+ AND r.state = 'ACTIVE'
+ AND r.privacy = 'PUBLIC'
+ GROUP BY r
+ HAVING COUNT(DISTINCT t.value) = :tagCount
+ ORDER BY r.name
+ """)
+ Page<Resource> findAllByTypesAndAllTags(
+ @Param("typeList") List<Class<? extends Resource>> typeList,
+ @Param("tags") String[] tags,
+ @Param("tagCount") long tagCount,
+ @Param("nameSearch") String nameSearch,
+ Pageable pageable);
+
+ @Query(
+ """
+ SELECT r
+ FROM Resource r
+ JOIN r.tags t
+ JOIN r.authors a
+ WHERE r.class IN :typeList
+ AND t.value IN :tags
+ AND LOWER(r.name) LIKE LOWER(CONCAT('%', :nameSearch, '%'))
+ AND r.state = 'ACTIVE'
+ AND (r.privacy = 'PUBLIC' OR a.authorId = :userId)
+ GROUP BY r
+ HAVING COUNT(DISTINCT t.value) = :tagCount
+ ORDER BY r.name
+ """)
+ Page<Resource> findAllByTypesAndAllTagsForUser(
+ @Param("typeList") List<Class<? extends Resource>> typeList,
+ @Param("tags") String[] tags,
+ @Param("tagCount") Long tagCount,
+ @Param("nameSearch") String nameSearch,
+ @Param("userId") String userId,
+ Pageable pageable);
+
+ @Query(
+ """
+ SELECT r
+ FROM Resource r
+ JOIN r.authors a
+ WHERE TYPE(r) = :type AND r.state = 'ACTIVE'
+ AND LOWER(r.name) LIKE LOWER(CONCAT('%', :name, '%'))
+ AND (r.privacy = "PUBLIC" OR a.authorId = :userId)
+ """)
+ List<Resource> findByTypeAndNameContainingIgnoreCase(
+ @Param("type") Class<? extends Resource> type, @Param("name") String name, @Param("userId") String userId);
+
+ Optional<Resource> findByIdAndState(String id, StateEnum state);
+
+ List<Resource> findAllByStatusInOrderByCreatedAtDesc(Collection<StatusEnum> statuses);
+}
diff --git a/airavata-api/research-service/src/main/java/org/apache/airavata/research/service/model/repo/ResourceVerificationActivityRepository.java b/airavata-api/research-service/src/main/java/org/apache/airavata/research/service/model/repo/ResourceVerificationActivityRepository.java
new file mode 100644
index 0000000000..a9ca261844
--- /dev/null
+++ b/airavata-api/research-service/src/main/java/org/apache/airavata/research/service/model/repo/ResourceVerificationActivityRepository.java
@@ -0,0 +1,33 @@
+/**
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.airavata.research.service.model.repo;
+
+import java.util.List;
+import org.apache.airavata.research.service.model.entity.Resource;
+import org.apache.airavata.research.service.model.entity.ResourceVerificationActivity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+
+public interface ResourceVerificationActivityRepository
+ extends JpaRepository<ResourceVerificationActivity, String>,
+ JpaSpecificationExecutor<ResourceVerificationActivity> {
+
+ List<ResourceVerificationActivity> findAllByResourceOrderByUpdatedAtDesc(Resource resource);
+}