-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
External tools #11
Open
jp-tosca
wants to merge
30
commits into
main
Choose a base branch
from
external_tools
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
External tools #11
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
5b3f9d5
Add ExternalTool, MarketplaceItem, and MarketplaceItemImage models wi…
jp-tosca 957f7ae
Add @Lob annotation to image field in MarketplaceItemImage model
jp-tosca 4197258
Add repository and service classes for ExternalTool and MarketplaceIt…
jp-tosca 7e5108f
Add ExternalToolManifest repository and update ExternalTool service f…
jp-tosca 2ea83a9
Update ExternalToolService to extract content type from JSON manifest
jp-tosca 0d56e1e
Add repository and service classes for resource storage, including da…
jp-tosca 555a30d
Refactor ExternalToolService and ResourceStorageService to integrate …
jp-tosca 7ab76ff
Refactor resource storage handling to support MultipartFile and updat…
jp-tosca a8d37a7
Implement StoredResourceController and enhance ResourceStorageService…
jp-tosca 7ac4db9
Add support for uploading item images in AddToolRequest and update Ex…
jp-tosca c8fc697
Add MarketplaceItemImage repository and update ExternalToolService to…
jp-tosca fa95d8b
Refactor ExternalToolController and OpenAPI annotations to enhance ad…
jp-tosca 436e36e
Update ExternalToolSamples to refine sample data and enhance clarity …
jp-tosca 0a64824
Refactor AuthAPIDocs to simplify schema references for SignupRequest …
jp-tosca 5359cc3
Add retrieval functionality for external tools and enhance API docume…
jp-tosca aa6efe2
Add functionality to manage external tool versions and update API doc…
jp-tosca 0fd36f2
Add functionality to manage external tool versions, including new req…
jp-tosca 3e03936
Add image management functionality for external tools, including uplo…
jp-tosca a1437b7
Fix null return in ExternalToolController to ensure proper response h…
jp-tosca f44775c
Refactor external tool models and services to enhance image managemen…
jp-tosca c8f1b1a
Refactor ExternalToolDTO and ExternalToolController for improved imag…
jp-tosca 5d25e7d
Add caching support with Ehcache configuration and enhance external t…
jp-tosca 7c9879d
Enhance ExternalToolController and payload classes for improved tool …
jp-tosca 3e74a8e
Add image handling support and refactor models for serialization in e…
jp-tosca 1ac43fc
Add toString methods for ExternalToolManifestDTO and ExternalToolVers…
jp-tosca 370d9ad
Remove altText field from MarketplaceItemImage and update correspondi…
jp-tosca 812fa92
Remove altText assignment from newImage in ExternalToolService
jp-tosca e354820
Rename resourceId to storedResourceId in StoredResourceController and…
jp-tosca 765550e
Update password size validation and enhance external tool update func…
jp-tosca c71cd2c
Refactor AddToolRequest to remove commented-out ArraySchema for image…
jp-tosca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,6 @@ build/ | |
### VS Code ### | ||
.vscode/ | ||
|
||
|
||
/storage/* | ||
docker-dev-volumes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/org/dataverse/marketplace/config/cache/CacheConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.dataverse.marketplace.config.cache; | ||
|
||
import org.springframework.cache.annotation.EnableCaching; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@EnableCaching | ||
public class CacheConfig { | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/org/dataverse/marketplace/config/cache/CacheEventLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.dataverse.marketplace.config.cache; | ||
|
||
import org.ehcache.event.CacheEvent; | ||
import org.ehcache.event.CacheEventListener; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class CacheEventLogger implements CacheEventListener<Object, Object> { | ||
|
||
Logger logger = LoggerFactory.getLogger(CacheEventLogger.class); | ||
|
||
@Override | ||
public void onEvent( | ||
CacheEvent<? extends Object, ? extends Object> cacheEvent) { | ||
logger.info(cacheEvent.getType().toString(), | ||
cacheEvent.getKey(), cacheEvent.getOldValue(), cacheEvent.getNewValue()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 195 additions & 0 deletions
195
src/main/java/org/dataverse/marketplace/controller/api/ExternalToolController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
package org.dataverse.marketplace.controller.api; | ||
|
||
import jakarta.validation.Valid; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.dataverse.marketplace.model.*; | ||
import org.dataverse.marketplace.openapi.annotations.ExternalToolsAPIDocs; | ||
import org.dataverse.marketplace.payload.*; | ||
import org.dataverse.marketplace.security.ApplicationRoles; | ||
import org.dataverse.marketplace.service.ExternalToolService; | ||
import org.dataverse.marketplace.service.ResourceStorageService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.*; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
|
||
@RestController | ||
@RequestMapping("/api/tools") | ||
public class ExternalToolController { | ||
|
||
@Autowired | ||
private ExternalToolService externalToolService; | ||
|
||
@Autowired | ||
private ResourceStorageService resourceStorageService; | ||
|
||
/** | ||
* Method to retrieve all external tools | ||
*/ | ||
@GetMapping() | ||
@ExternalToolsAPIDocs.ExternalToolsListDoc | ||
public ResponseEntity<?> getAllTools() { | ||
|
||
return ResponseEntity.ok(externalToolService.getAllTools()); | ||
} | ||
|
||
/** | ||
* Method to add a new external tool | ||
*/ | ||
@PreAuthorize(ApplicationRoles.ADMIN_ROLE) | ||
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) | ||
@ExternalToolsAPIDocs.AddExternalToolsRequestDoc | ||
public ResponseEntity<?> addNewTool(@Valid AddToolRequest addToolRequest) { | ||
|
||
try { | ||
return ResponseEntity.ok(externalToolService.addTool(addToolRequest)); | ||
} catch (IOException e) { | ||
ServerMessageResponse messageResponse | ||
= new ServerMessageResponse(HttpStatus.INTERNAL_SERVER_ERROR, | ||
"Error adding tool", | ||
e.getMessage()); | ||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(messageResponse); | ||
} | ||
} | ||
|
||
/** | ||
* Method to retrieve all external tools | ||
*/ | ||
@GetMapping("/{toolId}") | ||
@ExternalToolsAPIDocs.GetExternalToolByIdDoc | ||
public ResponseEntity<?> getToolById(@PathVariable("toolId") Integer toolId) { | ||
|
||
ExternalTool tool = externalToolService.getToolById(toolId); | ||
return ResponseEntity.ok(new ExternalToolDTO(tool)); | ||
} | ||
|
||
@PreAuthorize(ApplicationRoles.ADMIN_ROLE) | ||
@PutMapping("/{toolId}") | ||
@ExternalToolsAPIDocs.UpdateExternalToolDoc | ||
public ResponseEntity<?> updateTool(@PathVariable("toolId") Integer toolId, @Valid UpdateToolRequest updateToolRequest) { | ||
|
||
ExternalTool tool = externalToolService.getToolById(toolId); | ||
|
||
if(tool == null){ | ||
ServerMessageResponse messageResponse = new ServerMessageResponse(HttpStatus.NOT_FOUND, | ||
"Resource not found", | ||
String.format("The requested external tool with ID %d was not found.", toolId)); | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(messageResponse); | ||
} | ||
|
||
try { | ||
ServerMessageResponse messageResponse = new ServerMessageResponse(HttpStatus.OK, | ||
"Tool updated", | ||
String.format("The tool with ID %d was updated.", toolId)); | ||
externalToolService.updateTool(tool, updateToolRequest); | ||
return ResponseEntity.ok(messageResponse); | ||
} catch (Exception e) { | ||
ServerMessageResponse messageResponse | ||
= new ServerMessageResponse(HttpStatus.INTERNAL_SERVER_ERROR, | ||
"Error updating tool", | ||
e.getMessage()); | ||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(messageResponse); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Method to retrieve the images of an external tool. | ||
*/ | ||
@GetMapping("/{toolId}/images") | ||
@ExternalToolsAPIDocs.GetToolImagesDoc | ||
public ResponseEntity<?> getToolImages(@PathVariable("toolId") Integer toolId) { | ||
|
||
ExternalTool tool = externalToolService.getToolById(toolId); | ||
|
||
if(tool == null){ | ||
ServerMessageResponse messageResponse = new ServerMessageResponse(HttpStatus.NOT_FOUND, | ||
"Resource not found", | ||
String.format("The requested external tool with ID %d was not found.", toolId)); | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(messageResponse); | ||
} | ||
|
||
List<MarketplaceItemImageDTO> imagesResourceId = new ArrayList<>(); | ||
for (MarketplaceItemImage image : tool.getImages()) { | ||
imagesResourceId.add(new MarketplaceItemImageDTO(image)); | ||
} | ||
|
||
return ResponseEntity.ok(imagesResourceId); | ||
} | ||
|
||
/** | ||
* Method to add images to an external tool. | ||
*/ | ||
@PreAuthorize(ApplicationRoles.ADMIN_ROLE) | ||
@PostMapping(path = "/{toolId}/images", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) | ||
@ExternalToolsAPIDocs.AddToolImagesDoc | ||
public ResponseEntity<?> addToolImages( | ||
@PathVariable("toolId") Integer toolId, | ||
@RequestBody List<MultipartFile> images) throws IOException { | ||
|
||
ExternalTool tool = externalToolService.getToolById(toolId); | ||
|
||
if(tool == null){ | ||
ServerMessageResponse messageResponse = new ServerMessageResponse(HttpStatus.NOT_FOUND, | ||
"Resource not found", | ||
String.format("The requested external tool with ID %d was not found.", toolId)); | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(messageResponse); | ||
} | ||
|
||
externalToolService.addItemImages(tool, images); | ||
|
||
ServerMessageResponse messageResponse = new ServerMessageResponse(HttpStatus.OK, | ||
"Images added", | ||
String.format("The images were added to the tool with ID %d.", toolId)); | ||
|
||
return ResponseEntity.ok(messageResponse); | ||
} | ||
|
||
/** | ||
* Method to delete an image from an external tool. | ||
*/ | ||
@PreAuthorize(ApplicationRoles.ADMIN_ROLE) | ||
@DeleteMapping("/{toolId}/images/{imageId}") | ||
@ExternalToolsAPIDocs.DeleteToolImageDoc | ||
public ResponseEntity<?> deleteToolImage( | ||
@PathVariable("toolId") Integer toolId, | ||
@PathVariable("imageId") Integer imageId) { | ||
|
||
MarketplaceItemImage image = externalToolService.getItemImage(imageId, toolId); | ||
|
||
if(image == null){ | ||
ServerMessageResponse messageResponse = new ServerMessageResponse(HttpStatus.NOT_FOUND, | ||
"Resource not found", | ||
String.format("The requested image with ID %d was not found.", imageId)); | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(messageResponse); | ||
} | ||
|
||
try { | ||
|
||
resourceStorageService.deleteResourceContent(image.getImageStoredResourceId()); | ||
externalToolService.deleteToolImage(image); | ||
return ResponseEntity.ok(new ServerMessageResponse(HttpStatus.OK, | ||
"Image deleted", | ||
String.format("The image with ID %d was deleted.", imageId))); | ||
|
||
} catch (IOException e) { | ||
|
||
ServerMessageResponse messageResponse = new ServerMessageResponse(HttpStatus.INTERNAL_SERVER_ERROR, | ||
"Error deleting image", | ||
e.getMessage()); | ||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(messageResponse); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API endpoint doesn't seem to work for me. Getting just one tool works, but not all. I just get an empty array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is weird, I been using that endpoint for the main page and it works fine, I will do a fresh test soon and post back.