Skip to content
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

GEODE-1993: postprocess region/key #276

Closed
wants to merge 15 commits into from
Closed

GEODE-1993: postprocess region/key #276

wants to merge 15 commits into from

Conversation

kjduling
Copy link

Add post processing to the GET {region}/{key..key} endpoint
precheckin running

@jinmeiliao
Copy link
Member

jinmeiliao commented Oct 28, 2016

A few things:

  1. In your RestSecurityPostProcessorTest, in the before method, you can get ahold of the region you created and pre populate the regions with a few keys and values, this way, you don't need to worry about putting in values in your tests.
  2. Looks like /{regions} end point also retrieves the values of the entire region, you need to post process the values there as well.
  3. query end points definitely return region values as well.
  4. SecurityUtils.getSecurityService will definitely get the security service, but let's do it the spring way, I have a component called RestSecurityService, use that instead, and add the needed postProcess method there.

Kevin Duling added 4 commits November 1, 2016 13:47
Changed test to initialize region without REST calls.
PostProcess query endpoints
Load the RestSecurityService the Spring way
Postprocess an adhoc query
Fixed some spelling errors
Fixed issue with parametrized queries throwing an NPE
Removed System.outs that were put in during analysis
Fixed code formatting after merge from develop
Fixed @return without comment
@kjduling
Copy link
Author

kjduling commented Nov 2, 2016

Don't accept this PR yet. This is just a checkin to preserve work.

Addressed all of the issues listed above. Added test for adhoc queries. Still need a test for named queries. Also need to verify functions won't return any region data without being post-processed.

Have not run precheckin yet, either.

@kjduling
Copy link
Author

kjduling commented Nov 4, 2016

precheckin running

@kjduling
Copy link
Author

kjduling commented Nov 7, 2016

Precheckin successful except for one flaky test, QueueCommandsDUnitTest.testCreateUpdatesSharedConfig which doesn't appear to be related to this change.

Region region =
serverStarter.cache.createRegionFactory(RegionShortcut.REPLICATE).create(REGION_NAME);
region.put("key1",
"{\"@type\":\"com.gemstone.gemfire.web.rest.domain.Order\",\"purchaseOrderNo\":1121,\"customerId\":1012,\"description\":\"Order for XYZ Corp\",\"orderDate\":\"02/10/2014\",\"deliveryDate\":\"02/20/2014\",\"contact\":\"Jelly Bean\",\"email\":\"jelly.bean@example.com\",\"phone\":\"01-2048096\",\"items\":[{\"itemNo\":1,\"description\":\"Product-100\",\"quantity\":12,\"unitPrice\":5,\"totalPrice\":60}],\"totalPrice\":225}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could create an Order object and put it as an java object instead of using json. This would be much readable.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. The tests don't use the object, so I'll remove it for clarity.

assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, getContentType(response));

String body = IOUtils.toString(response.getEntity().getContent(), "UTF-8");
assertTrue(body.startsWith("\"key1User/" + REGION_NAME + "/key1/"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the key1User is quoted?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because PdxBasedCrudController.read(region, keys, boolean) returns the value as a quoted string. E.g., "key1User/AuthRegion/key1/key1Value"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please verify if without the postProcessor, what it is returning? Does it still contain the quotes? This might be because you are using SamplePostProcessor which turns any object into a String result. Consider use a different post processor, that is specific to your "customers" region data.


@BeforeClass
public static void before() throws Exception {
serverStarter.startServer();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I just made a change in the rule that you don't need to call startServer anymore if you are using is as a rule.

HttpResponse response =
restClient.doPost("/queries?id=selectCustomer&q=" + URLEncoder.encode(namedQuery, "UTF-8"),
"dataReader", "1234567", "");
assertEquals(201, getCode(response));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there anyway to crate the named query using java api instead of rest api?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to insert it via the API. When I did, my call to list queries always came up empty and I got a 404 when attempting to run it.

assertEquals(200, getCode(response));
assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, getContentType(response));

String customerJson =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use java api to put the data in the regions instead of using rest api.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks from the pattern RestAPIsQueryAndFEJUnitTest follows. But as you said in an earlier comment about the Orders, it will read cleaner.

@@ -87,6 +89,12 @@
Object postProcess(Object principal, String regionPath, Object key, Object value,
boolean valueIsSerialized);

Collection<Object> postProcess(Query query, Collection<String> regionNames,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Collection<Object> postProcess(Query query, Collection<String> regionNames,
Collection<Object> results);

Collection<Object> postProcess(Object principal, Query query, Collection<String> regionNames,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

@Override
public Collection<Object> postProcess(Object principal, Query query,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

@Override
public Collection<Object> postProcess(Query query, Collection<String> regionNames,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -50,6 +52,11 @@

protected static final String REST_API_VERSION = "/v1";

public BaseControllerAdvice(final RestSecurityService securityService,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BaseControllerAdvice extends AbstractBaseController. Since the RestSecurityService lives in AbstractBaseController, yes. Otherwise, we define separate member variables in PdxBasedCrudController, CommonCrudController, and QueryAccessContoller.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use Autowire inside AbstractBaseController to auto wire the RestSecurityService instead of using constructors.

Removed functions.
Removed postProcess(query, regions, results) method
Cleaned up testing
@kjduling
Copy link
Author

kjduling commented Nov 8, 2016

precheckin successful

@jinmeiliao
Copy link
Member

A few changes requested:

  1. use Autowire to auto wire the RestSecurityService.
  2. In your RestSecurityPostProcessorTest, considering only using "customers" region for readability. You don't needs all these "/" + REGION_NAME +"/key1" at all.
  3. Then you can use a customer domain object specific PostProcessor to change the field values and assert for the value returned.

@kjduling
Copy link
Author

kjduling commented Nov 8, 2016

  1. I am using Autowire, the annotation is on the base class's constructor. But as for the injection via the constructor, please review https://spring.io/blog/2015/11/29/how-not-to-hate-spring-in-2016 which references http://olivergierke.de/2013/11/why-field-injection-is-evil/ and http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/htmlsingle/#beans-constructor-injection

Do you think it would be better to only add the RestSecurityService to the controllers that actually need it instead of adding it to the base class? I think that would complicate the constructors.

2 & 3. Agreed, that'll make the test cleaner.

@kjduling
Copy link
Author

Precheckin successful

@asfgit asfgit closed this in bd229d7 Nov 10, 2016
PurelyApplied pushed a commit to PurelyApplied/geode that referenced this pull request Mar 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants