-
Notifications
You must be signed in to change notification settings - Fork 5
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
[NAE-1945] External resource loader #246
base: release/6.4.0
Are you sure you want to change the base?
Conversation
- implementing our own resource loader for files from directory reources/ in root
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
docs/resources/resources_loading.md
Outdated
# Resource Loading | ||
|
||
If you want to load resources, which will not be in JAR(for example big files), you can use our resource loader. | ||
ResourceLoader return InputStreamResource, from which you can use InputStream, and loading resources from directory **resource/** in root of the project. |
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.
The resource
directory is in set up working directory of the app. If you run a jar it can be configured per environment.
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.
done
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class NetgrifResource { |
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.
Rename class to ExternalResource
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.
done
import org.springframework.core.io.Resource; | ||
import org.springframework.core.io.ResourceLoader; | ||
|
||
public class NetgrifResourceLoader implements ResourceLoader { |
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.
Rename class to ExternalResourceLoader
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.
done
|
||
public class NetgrifResourceLoader implements ResourceLoader { | ||
|
||
public static final String RESOURCE_PREFIX = "resource://"; |
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.
As a resource is not a protocol the double slash is not necessary.
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.
done
|
||
public class NetgrifResourceLoader implements ResourceLoader { | ||
|
||
public static final String RESOURCE_PREFIX = "resource://"; |
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.
Add control for multiple prefixes to recognise a NAE external resource:
resource:
nae:
nae-resource:
nr:
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.
done
if(location.startsWith(RESOURCE_PREFIX)) { | ||
String path = location.substring(RESOURCE_PREFIX.length()); | ||
NetgrifResource resource = new NetgrifResource(); | ||
return resource.getResource("resources/" + path); |
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.
extract path prefix as a constant
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.
done
...ain/java/com/netgrif/application/engine/resource/service/NetgrifResourceLoaderProcessor.java
Outdated
Show resolved
Hide resolved
...ain/java/com/netgrif/application/engine/resource/service/NetgrifResourceLoaderProcessor.java
Outdated
Show resolved
Hide resolved
- changes according to PR
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
|
||
@Override | ||
public Resource resolve(String location, ResourceLoader resourceLoader) { | ||
if(location.startsWith(ExternalResourceLoader.RESOURCE_PREFIX) || |
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.
For better readability, may export this long if condition to a function.
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.
Resolved
docs/resources/resources_loading.md
Outdated
|
||
If you want to load resources, which will not be in JAR(for example big files), you can use our resource loader. | ||
ResourceLoader return InputStreamResource, from which you can use InputStream, and loading resources from directory **resource/** inworking directory of the app. | ||
The prefix for NetgrifResourceLoaser is |
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.
If you want to load resources, which are not included in the JAR (for example large files), you can use the resource loader.
ResourceLoader returns an InputStreamResource. You can turn it into an InputStream and load resources from the resource/ directory in the working directory of the app.
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.
Corrected
private Resource substringAndGetResource(String location, String prefix) { | ||
String path = location.substring(prefix.length()); | ||
ExternalResource resource = new ExternalResource(); | ||
return resource.getResource(StringUtils.chop(prefix)+ "/" + path); |
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.
shouldn't "/"
be File.pathSeparator
instead?
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.
Done
- refactor of prefix detection of external resource
- refactor of prefix detection of external resource
Description
Implements NAE-1945
Dependencies
none
Third party dependencies
No new dependencies were introduced
Blocking Pull requests
There are no dependencies on other PR
How Has Been This Tested?
manually
Test Configuration
Checklist: