-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Port rest-data-panache to RESTEasy Reactive
- Loading branch information
Showing
41 changed files
with
555 additions
and
107 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
48 changes: 29 additions & 19 deletions
48
...me/src/main/java/io/quarkus/rest/data/panache/runtime/resource/ResourceLinksProvider.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 |
---|---|---|
@@ -1,41 +1,51 @@ | ||
package io.quarkus.rest.data.panache.runtime.resource; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.jboss.resteasy.links.LinksProvider; | ||
import org.jboss.resteasy.links.RESTServiceDiscovery; | ||
import javax.ws.rs.core.Link; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.InstanceHandle; | ||
import io.quarkus.resteasy.reactive.links.RestLinksProvider; | ||
|
||
public final class ResourceLinksProvider { | ||
|
||
private static final String SELF_REF = "self"; | ||
|
||
public Map<String, String> getClassLinks(Class<?> className) { | ||
RESTServiceDiscovery links = LinksProvider | ||
.getClassLinksProvider() | ||
.getLinks(className, Thread.currentThread().getContextClassLoader()); | ||
return linksToMap(links); | ||
return linksToMap(restLinksProvider().getTypeLinks(className)); | ||
} | ||
|
||
public Map<String, String> getInstanceLinks(Object instance) { | ||
RESTServiceDiscovery links = LinksProvider | ||
.getObjectLinksProvider() | ||
.getLinks(instance, Thread.currentThread().getContextClassLoader()); | ||
return linksToMap(links); | ||
return linksToMap(restLinksProvider().getInstanceLinks(instance)); | ||
} | ||
|
||
public String getSelfLink(Object instance) { | ||
RESTServiceDiscovery.AtomLink link = LinksProvider.getObjectLinksProvider() | ||
.getLinks(instance, Thread.currentThread().getContextClassLoader()) | ||
.getLinkForRel(SELF_REF); | ||
return link == null ? null : link.getHref(); | ||
Collection<Link> links = restLinksProvider().getInstanceLinks(instance); | ||
for (Link link : links) { | ||
if (SELF_REF.equals(link.getRel())) { | ||
return link.getUri().toString(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private RestLinksProvider restLinksProvider() { | ||
InstanceHandle<RestLinksProvider> instance = Arc.container().instance(RestLinksProvider.class); | ||
if (instance.isAvailable()) { | ||
return instance.get(); | ||
} | ||
throw new IllegalStateException("Invalid use of '" + this.getClass().getName() | ||
+ "'. No request scope bean found for type '" + ResourceLinksProvider.class.getName() + "'"); | ||
} | ||
|
||
private Map<String, String> linksToMap(RESTServiceDiscovery serviceDiscovery) { | ||
Map<String, String> links = new HashMap<>(serviceDiscovery.size()); | ||
for (RESTServiceDiscovery.AtomLink atomLink : serviceDiscovery) { | ||
links.put(atomLink.getRel(), atomLink.getHref()); | ||
private Map<String, String> linksToMap(Collection<Link> links) { | ||
Map<String, String> result = new HashMap<>(); | ||
for (Link link : links) { | ||
result.put(link.getRel(), link.getUri().toString()); | ||
} | ||
return links; | ||
return result; | ||
} | ||
} |
Oops, something went wrong.