Last active
August 29, 2015 14:03
-
-
Save jbrisbin/99f86ce4ee136aa668b8 to your computer and use it in GitHub Desktop.
Sample Reactive Resource Framework Code
This file contains hidden or 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
routing { | |
include SpringConfig | |
http { | |
route("/path/to/{resourceId}") to CustomResource | |
} | |
} | |
interface Context extends AbstractMutableMap<String, Object> { | |
UriPath getPath() | |
Principal getPrincipal() | |
void notify(String topic, Object data) | |
} | |
interface Patch<T> extends Function<T, T>, Iterable<Diff<?>> { | |
int size() | |
} | |
interface Diff<V> extends Function<V, Boolean> { | |
String getPath() | |
} | |
class CustomResource { | |
static allowedMethods = [ | |
HttpMethods.GET, | |
HttpMethods.PUT, | |
HttpMethods.POST, | |
HttpMethods.DELETE, | |
StompMethods.SUBSCRIBE | |
] | |
static acceptableTypes = { supertype, subtype -> subtype.endsWith("json") } | |
// alternative | |
//static authorized = [ "ROLE1", "ROLE2" ] | |
AvailabilityService sys | |
SecurityService security | |
ResourceOrm orm | |
def available(Context ctx) { | |
sys.available | |
} | |
def exists(Context ctx) { | |
orm.findOne(ctx.path.resourceId)) { obj -> | |
ctx.domainObj = obj | |
ctx.notify 'exists', (null != obj) | |
} | |
} | |
def authorized(Context ctx) { | |
security.isAuthorized(ctx.principal) { result -> | |
ctx.notify 'authorized', result | |
} | |
} | |
def conflict(Context ctx) { | |
} | |
def create(Context ctx, DomainObject obj) { | |
} | |
def merge(Context ctx, Patch patch) { | |
patch.apply(ctx.domainObj) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment