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

RESTWS-739:Reposting metadata should not persist changes #414

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gitcliff
Copy link
Contributor

link:https://issues.openmrs.org/browse/RESTWS-739
Reposting metadata should not persist changes

@mozzy11
Copy link
Member

mozzy11 commented Nov 26, 2019

@gitcliff , can you explain what you were trying to do ?? , From looking at the tests, it seems now metada cannot be updatable after your changes ,because all tests about updating metadata return exceptions.

@@ -162,7 +162,7 @@ public void shouldCreateANewOrderType() throws Exception {
assertEquals(orderType.get("description"), Util.getByPath(newOrder, "description"));
}

@Test
@Test(expected = RuntimeException.class)
Copy link
Member

@mozzy11 mozzy11 Nov 26, 2019

Choose a reason for hiding this comment

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

@gitcliff after your changes , now these tests return Exceptions ?? Thats wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mozzy11 these tests were run against the update method in DelegatingCrudResource which was allowing reposting of changes metadata but the ticket description says this should not happen any more with metadata hence notifying the client with an exception ,,,thats why the tests that were permitiing the reposting of metadata data initially are now throwing exceptional errors

Copy link
Member

Choose a reason for hiding this comment

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

@gitcliff ,the tickect talks about forbidding re-posting metadata, not updating metadata.
So idealy updating meta-data shouldnt have any problem

Copy link
Member

Choose a reason for hiding this comment

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

Yes, @mozzy11 and @gitcliff I haven't looked deeply at the code but looking at the ticket, the idea is, for example, if you post to the Encounter endpoint, although you can change the encounter type of that encounter, you shouldn't be able to inadvertantly change any of the underlying properties (name, etc) of that encounter type. However, you should be able to post directly to the EncounterType endpoint and change the name, etc.

The idea is that you shouldn't be able to by mistake change a piece of metadata when updating some data that refers to that metadata. Hope that makes sense!

Copy link
Member

Choose a reason for hiding this comment

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

makes sense @mogoodrich

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mozzy11 u can also have a look a this , it concurs with what @mogoodrich was explaining above

@Test(expected = RuntimeException.class)
public void shouldThrowAnExceptionWhenEditingAnAnOrderType() throws Exception {
final String newName = "updated name";
SimpleObject orderType = new SimpleObject();

Choose a reason for hiding this comment

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

Suggested change
SimpleObject orderType = new SimpleObject();
final SimpleObject orderType = new SimpleObject();

final String newName = "updated name";
SimpleObject orderType = new SimpleObject();
orderType.add("name", newName);
String json = new ObjectMapper().writeValueAsString(orderType);

Choose a reason for hiding this comment

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

new ObjectMapper() is resource consuming. Therefore, create one instance for all the relevant unit tests and re-use that instance. 💭

public void shouldThrowAnExceptionWhenEditingAnAnOrderSet() throws Exception {

final String editedName = "OrderSet Edited";
String json = "{ \"name\":\"" + editedName + "\" }";

Choose a reason for hiding this comment

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

I would rename the json to something meaning like editNameJson

@Test(expected = RuntimeException.class)
public void shouldThrowAnExceptionWhenEditingAConceptSource() throws Exception {
final String newName = "updated name";
SimpleObject conceptSource = new SimpleObject();

Choose a reason for hiding this comment

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

Suggested change
SimpleObject conceptSource = new SimpleObject();
final SimpleObject conceptSource = new SimpleObject();

public void shouldThrowAnExceptionWhenEditingAConceptSource() throws Exception {
final String newName = "updated name";
SimpleObject conceptSource = new SimpleObject();
conceptSource.add("name", newName);

Choose a reason for hiding this comment

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

Can't you use a builder for SimpleObject?

"does not support editing of this type because this is metadata");
}
if (hasTypesDefined()) {
// if they specify a type discriminator it must match the expected one--type can't be modified

Choose a reason for hiding this comment

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

Please rewrite this comment in a single sentence. -- is confusing breaker for sentences

ValidateUtil.validate(delegate);
delegate = save(delegate);

SimpleObject ret = (SimpleObject) ConversionUtil.convertToRepresentation(delegate, context.getRepresentation());

Choose a reason for hiding this comment

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

what does ret means? maybe give a more self-descriptive name?

}

DelegatingResourceHandler<? extends T> handler = getResourceHandler(delegate);

Choose a reason for hiding this comment

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

remove this empty line

}
}
}

Choose a reason for hiding this comment

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

remove this empty line

delegate = save(delegate);

SimpleObject ret = (SimpleObject) ConversionUtil.convertToRepresentation(delegate, context.getRepresentation());

Choose a reason for hiding this comment

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

no need of this empty line

@ibacher ibacher force-pushed the master branch 2 times, most recently from f9c73bb to 2a4407f Compare December 14, 2020 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants