Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The @ERXRouteParameter annotation will make the method suitable for "accepting" objects from the controller, if the annotation is not there, you won't be able to receive the object from the controller.

Using D2W rules with ERRest

This is a tip that was sent by Farrukh Ijaz in the webobjects-dev mailing list. It allow you to use D2W rules to create your filters on your REST routes.

Code Block


private D2WContext d2wContext;

protected D2WContext d2wContext() {
	if (d2wContext == null) {
		d2wContext = new D2WContext();
	}
	return d2wContext;
}

synchronized public NSArray<String> inferFilterKeysForEntity(String entityName) {
	EOEntity entity = EOModelGroup.defaultGroup().entityNamed(entityName);
	d2wContext().setEntity(entity);
	d2wContext().setTask(request().method());
	return (NSArray<String>) d2wContext().inferValueForKey("displayPropertyKeys");
}

synchronized public NSArray<String> inferFilterKeysForPage(String page) {
	d2wContext().setDynamicPage(page);
	d2wContext().setTask(request().method());
	return (NSArray<String>) d2wContext().inferValueForKey("displayPropertyKeys");
}

public ERXKeyFilter showFilter(String entityName) {
	NSArray<String> keys = inferFilterKeysForEntity(entityName);
	ERXKeyFilter filter = null;
	if (keys != null && !keys.isEmpty()) {
		filter = ERXKeyFilter.filterWithNone();
		for (String key : keys) {
			filter.include(new ERXKey<String>(key));
		}
	} else {
		filter = ERXKeyFilter.filterWithAttributesAndToOneRelationships();
	}
	return filter;
}

The D2WRule should be something like:

Code Block

LHS: entity.name = 'Employee' and task = 'GET'
RHS: displayPropertyKeys = ('firstName', 'lastName', 'position')