-
Notifications
You must be signed in to change notification settings - Fork 44
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
ATT-42: AttachmentResource* to be documented in Swagger #48
base: master
Are you sure you want to change the base?
Conversation
@@ -44,7 +44,7 @@ | |||
<appframeworkVersion>2.2.1</appframeworkVersion> | |||
<uiframeworkVersion>3.3.1</uiframeworkVersion> | |||
<uicommonsVersion>1.4</uicommonsVersion> | |||
<webservices.restVersion>2.17</webservices.restVersion> | |||
<webservices.restVersion>2.21.0</webservices.restVersion> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you now test this with the latest version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh yeah let me do but i was following @mks-d ideal that it may come up with many dependencies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately i tested this on webservices.rest 2.28.0 but i got error invalidActivationKeyException which means that some methods are not yet introduced into 2.28.0, like how @mks-d suggested in talk thread, upgrading to 2.28.0 would bring such an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sherrif10 That is alittle strange...How uniques are the pom depepndencies here and the ones i used in this Pull Request
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When i run them on my machine i got the similar error i stated above invalidActivationKeyException .
omod-2.0/pom.xml
Outdated
<artifactId>webservices.rest-omod</artifactId> | ||
<version>${webservices.restVersion}</version> | ||
<artifactId>webservices.rest-omod-common</artifactId> | ||
<version>2.21.0</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you hard coding the version here yet you have already declared it on line 19?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
${webservices.restVersion} acts as a variable of its version , inotherwords hardcoding it by replacing the reall version doesnot make much difference. i can replace it back without hardcoding it
omod-2.0/pom.xml
Outdated
</dependency> | ||
<dependency> | ||
<groupId>org.openmrs.module</groupId> | ||
<artifactId>webservices.rest-omod-common</artifactId> | ||
<version>${webservices.restVersion}</version> | ||
<version>2.21.0</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you hard coding the version here yet you have already declared it on line 19?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
${webservices.restVersion} acts as a variable of its version , inotherwords hardcoding it by replacing the reall version doesnot make much difference. i can replace it back without hardcoding it
@@ -16,7 +16,7 @@ | |||
<properties> | |||
<openMRSVersion>${openMRS2_0Version}</openMRSVersion> | |||
<emrapiVersion>1.19</emrapiVersion> | |||
<webservices.restVersion>2.17</webservices.restVersion> | |||
<webservices.restVersion>2.21.0</webservices.restVersion> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to redeclare this property when it is already in the parent pom unless if you want to override the version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first glance i thought of it, however let me try undeclaring it thanks @reagan-meant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@reagan-meant i undeclared that thanks
cc @mks-d @ibacher @reagan-meant i think this is ready to be merged,Anything missing please will be highly appreciated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a bunch for working on this.
This is close to complete, I think we need to add some test coverage, and be sure you run:
> mvn clean package
For proper formatting.
// @Override | ||
// public Attachment save(Attachment delegate) { | ||
// Obs obs = Context.getObsService().saveObs(delegate.getObs(), REASON); | ||
// return new Attachment(obs); | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you intend to the leave commented code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These were earlier in the commit before my changes, except if am to remove it
omod-2.0/src/main/java/org/openmrs/module/attachments/rest/AttachmentResource2_0.java
Show resolved
Hide resolved
@dkayiwa: How does it look now, here is the screen shot of documentation |
cc @mozzy11 @sacull, @gitcliff @HerbertYiga , @tendomart , feel free to review since reviewing tickets is part of learning thanks |
.property("preferredName", new StringProperty().example("uuid")) | ||
.property("preferredAddress", new StringProperty().example("uuid")) | ||
.property("attributes", new ArrayProperty(new RefProperty("#/definitions/AttachmentAttributeCreate"))) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this space necessary ?
omod-2.0/src/main/java/org/openmrs/module/attachments/rest/AttachmentResource2_0.java
Outdated
Show resolved
Hide resolved
omod-2.0/src/main/java/org/openmrs/module/attachments/rest/AttachmentResource2_0.java
Outdated
Show resolved
Hide resolved
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import org.hibernate.FlushMode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import org.hibernate.FlushMode; |
You have added an import that you are not using.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @sacull ,Actually am using this import, let me know if there is something else please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oddly, I'm sure these two imports weren't used before and the save(Attachement)
method looked different, however, I can't find it in history. Maybe something just happened to me. Bravo for vigilance. ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After the last commit (464f5aa) the save(Attachment)
method looks like I remembered it, so again these imports are not used:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @sacull, shall we go with this idea??, I included screenshots for verification
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sherrif10 It's not my decision whether to leave it or not, I'm not important enough here. ;)
In addition, I would like to take a better look at this PR to be able to click "Approve" with full responsibility, unfortunately, until the end of the week, I am not able to do it due to lack of time. I'm sorry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haa you are more important @sacull, we have learnt clean code from you , keep up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you do as @sacull suggested above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes i responded to his comments above
import org.hibernate.FlushMode; | ||
import org.openmrs.Obs; | ||
import org.openmrs.module.attachments.AttachmentsConstants; | ||
import org.openmrs.module.emrapi.db.DbSessionUtil; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import org.openmrs.module.emrapi.db.DbSessionUtil; |
Same as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @sacull, actually i used this package on line 214
omod-2.0/src/main/java/org/openmrs/module/attachments/rest/AttachmentResource2_0.java
Outdated
Show resolved
Hide resolved
public void purge(Attachment delegate, RequestContext context) throws ResponseException { | ||
String encounterUuid = delegate.getObs().getEncounter() != null ? delegate.getObs().getEncounter().getUuid() : null; | ||
Context.getObsService().purgeObs(delegate.getObs()); | ||
voidEncounterIfEmpty(Context.getEncounterService(), encounterUuid); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this also required for Swagger documentation? If not, why did you override this? I see your doing great stuff here but I think it maybe out of scope.
Same case for: newDelegate(...)
, delete(...)
, getByUniqueId(...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@samuelmale thanks , let me cross check that code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have resolved that , take a look
@Override | ||
public List<String> getPropertiesToExposeAsSubResources() { | ||
return Arrays.asList("comment", "complexData", "Attributes"); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this method, is the override required for Swagger docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes , @samuelmale , this method exposes subresource classes as a resource in swagger docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only one approval from either @sacull @tendomart ,will rescue me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Nice work @sherrif10
Thanks @Akayeshmantha @dkayiwa any cool response from you, can we merge this please |
@sherrif10 great work done. |
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getUpdatableProperties() | ||
*/ | ||
@Override | ||
public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoesNotSupportOperationException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sherrif10 , can you create test for this Update method ??
omod-2.0/src/main/java/org/openmrs/module/attachments/rest/AttachmentResource2_0.java
Show resolved
Hide resolved
well done @sherrif10 . can you also write some more tests units for the Attachment Resource Rest Controller ?? like here, |
String uuid = (String) attachment.get("uuid"); | ||
Assert.assertNotNull("uuid", obs.getUuid()); | ||
Assert.assertNotNull("comment", obs.getComment()); | ||
Assert.assertEquals("complexData", obs.getComplexData(), null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sherrif10 , you instead need to check the deserialised response , not the very json object you posted
req.setContent(json.getBytes()); | ||
|
||
String editedAttachment = obs.getUuid(); | ||
Assert.assertNotEquals("Updated complexData ", editedAttachment.equalsIgnoreCase(editedAttachment)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sherrif10 , same here , you need to check the deserialized response , not the OBS object you posted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mozzy11 ok no problem
cc @mozzy11 this LGTM |
cc @dkayiwa @mozzy11 This ticket has been the one delaying the release of attachment module even now. We have done necessary work for it to be merged at least. The work being done can enable this ticket to be merged. So am suggesting we finish this by today because personally am too fixed with other tickets in current ongoing sprint thanks |
@sherrif10 have u responded to all the review comments? |
@dkayiwa i have responded to every comment above |
@@ -110,7 +110,7 @@ | |||
|
|||
<dependency> | |||
<groupId>org.openmrs.module</groupId> | |||
<artifactId>webservices.rest-omod</artifactId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you change this accidentally? If not, what was the reason behind the change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved thanks
@@ -16,7 +16,7 @@ | |||
<properties> | |||
<openMRSVersion>${openMRS2_0Version}</openMRSVersion> | |||
<emrapiVersion>1.19</emrapiVersion> | |||
<webservices.restVersion>2.17</webservices.restVersion> | |||
<webservices.restVersion>2.21.0</webservices.restVersion> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already saw this in the root pom. Do you need to duplicate it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved thanks
@@ -124,10 +217,10 @@ public void doSearch_shouldReturnResults() { | |||
RequestContext requestContext = new RequestContext(); | |||
requestContext.setRequest(request); | |||
|
|||
// Replay | |||
// // Replay |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
BasePageableResult response = (BasePageableResult) res.doSearch(requestContext); | ||
List<Attachment> actualAttachments = response.getPageOfResults(); | ||
|
||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
result = deserialize(handle(req)); | ||
} | ||
catch (Exception e) { | ||
// TODO Auto-generated catch block |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
json = new ObjectMapper().writeValueAsString(attributes); | ||
} | ||
catch (IOException e) { | ||
// TODO Auto-generated catch block |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result = deserialize(handle(req)); | ||
} | ||
catch (Exception e) { | ||
// TODO Auto-generated catch block |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
json = new ObjectMapper().writeValueAsString(attachment); | ||
} | ||
catch (IOException e) { | ||
// TODO Auto-generated catch block |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hope using logs to catch exception would work here
|
||
@Override | ||
public String getDisplayProperty() { | ||
// TODO Auto-generated method stub |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you suggesting i remove these methods above or whole class ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved thanks
|
||
@Override | ||
public Attachment newObject() { | ||
return new Attachment(Context.getObsService().getObsByUuid("9b6639b2-5785-4603-a364-075c2d61cd51")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you already have a constant for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True dat, will resolve it soon
String uuid = (String) attachment.get("uuid"); | ||
Assert.assertNull(result); | ||
String createdAttachment = obs.getUuid(); | ||
Assert.assertNotEquals("Created complexData ", createdAttachment.equalsIgnoreCase(createdAttachment)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sherrif10 what are you trying to test here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The created Attachment , so basically this tests above string
// Check existence in database | ||
String uuid = (String) attachment.get("uuid"); | ||
Assert.assertNull(result); | ||
String createdAttachment = obs.getUuid(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sherrif10 ,is this really the created attachment obj??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah i actually tested the created attachment below with ignorecase character
} | ||
|
||
Assert.assertNull(result); | ||
String editedAttachment = obs.getUuid(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sherrif10 ,is this the edited attachment object ??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this is the editted attachment, the editted attachment was initialised as a getUuid() then i tested it ignoring the case case character, if i had not used the ignoreCaseMethod, the test would fail in this context
Is this still available. |
Yes thanks. WIll look through and update the need branch. |
https://issues.openmrs.org/browse/ATT-42
cc @dkayiwa @ibacher @mks-d kindly review thanks alot