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

ATT-42: AttachmentResource* to be documented in Swagger #48

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

ATT-42: AttachmentResource* to be documented in Swagger #48

wants to merge 10 commits into from

Conversation

sherrif10
Copy link
Member

@sherrif10
Copy link
Member Author

We need to test this such that we can be on the right truck. If there is more guidance needed, i will humbly welcome them thanks here is the screen shot
att

@@ -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>
Copy link
Contributor

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

Copy link
Member Author

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

Copy link
Member Author

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

Copy link
Contributor

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

Copy link
Member Author

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>
Copy link
Contributor

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?

Copy link
Member Author

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>
Copy link
Contributor

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?

Copy link
Member Author

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>
Copy link
Contributor

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?

Copy link
Member Author

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

Copy link
Member Author

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

@sherrif10
Copy link
Member Author

sherrif10 commented Jun 15, 2020

cc @mks-d @ibacher @reagan-meant i think this is ready to be merged,Anything missing please will be highly appreciated

@sherrif10
Copy link
Member Author

We still need this documentation however so i would like more suggestions here cc @mks-d @ibacher

@mks-d mks-d requested a review from samuelmale July 2, 2020 10:27
Copy link
Member

@samuelmale samuelmale left a 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.

Comment on lines 164 to 168
// @Override
// public Attachment save(Attachment delegate) {
// Obs obs = Context.getObsService().saveObs(delegate.getObs(), REASON);
// return new Attachment(obs);
// }
Copy link
Member

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?

Copy link
Member Author

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

@sherrif10
Copy link
Member Author

@dkayiwa: How does it look now, here is the screen shot of documentation

attach

@sherrif10
Copy link
Member Author

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")))

Choose a reason for hiding this comment

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

Is this space necessary ?


import java.util.Arrays;
import java.util.List;
import org.hibernate.FlushMode;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
import org.hibernate.FlushMode;

You have added an import that you are not using.

Copy link
Member Author

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

Copy link
Member

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. ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you too @sacull , if you approve this , then we can ping @dkayiwa for final remarks ,actually after this merge, am releasing attachment module asap

Copy link
Member

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:
image

Copy link
Member Author

@sherrif10 sherrif10 Sep 30, 2020

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

Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

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?

Copy link
Member Author

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;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
import org.openmrs.module.emrapi.db.DbSessionUtil;

Same as above.

Copy link
Member Author

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

Comment on lines 188 to 192
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);
}
Copy link
Member

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(...)

Copy link
Member Author

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

Copy link
Member Author

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

Comment on lines +158 to +163
@Override
public List<String> getPropertiesToExposeAsSubResources() {
return Arrays.asList("comment", "complexData", "Attributes");
}

Copy link
Member

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?

Copy link
Member Author

@sherrif10 sherrif10 Sep 30, 2020

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

Copy link
Member Author

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

Copy link
Member

@samuelmale samuelmale left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@Akayeshmantha Akayeshmantha left a 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

@sherrif10
Copy link
Member Author

Thanks @Akayeshmantha @dkayiwa any cool response from you, can we merge this please

@mozzy11
Copy link
Member

mozzy11 commented Oct 4, 2020

@sherrif10 great work done.
i can see some tests already written for the initial work that was done around the Attachments Resource, can you also write more test units for the extra work done here??

* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getUpdatableProperties()
*/
@Override
public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoesNotSupportOperationException {
Copy link
Member

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 ??

@sherrif10
Copy link
Member Author

cc @mozzy11 @dkayiwa , i added some tests to confirm . kindly take a look FYI we need to release attachments with this work thanks

@mozzy11
Copy link
Member

mozzy11 commented Oct 7, 2020

well done @sherrif10 .

can you also write some more tests units for the Attachment Resource Rest Controller ?? like here,
especially for Creating and Updating the attachment with complex data ,

String uuid = (String) attachment.get("uuid");
Assert.assertNotNull("uuid", obs.getUuid());
Assert.assertNotNull("comment", obs.getComment());
Assert.assertEquals("complexData", obs.getComplexData(), null);
Copy link
Member

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));
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

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

@mozzy11 ok no problem

@sherrif10
Copy link
Member Author

cc @mozzy11 this LGTM

@sherrif10
Copy link
Member Author

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

@dkayiwa
Copy link
Member

dkayiwa commented Oct 22, 2020

@sherrif10 have u responded to all the review comments?

@sherrif10
Copy link
Member Author

@dkayiwa i have responded to every comment above

@@ -110,7 +110,7 @@

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>webservices.rest-omod</artifactId>
Copy link
Member

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?

Copy link
Member Author

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>
Copy link
Member

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?

Copy link
Member Author

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
Copy link
Member

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();

//
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

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
Copy link
Member

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?

Copy link
Member Author

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 ?

Copy link
Member Author

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"));
Copy link
Member

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?

Copy link
Member Author

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

@sherrif10
Copy link
Member Author

sherrif10 commented Oct 26, 2020

cc @dkayiwa @mozzy11 feel free to have a look at my new commits

@sherrif10
Copy link
Member Author

cc @dkayiwa, @mozzy11 : kindly review this ticket thanks

String uuid = (String) attachment.get("uuid");
Assert.assertNull(result);
String createdAttachment = obs.getUuid();
Assert.assertNotEquals("Created complexData ", createdAttachment.equalsIgnoreCase(createdAttachment));
Copy link
Member

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

Copy link
Member Author

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();
Copy link
Member

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??

Copy link
Member Author

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();
Copy link
Member

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 ??

Copy link
Member Author

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

@sherrif10
Copy link
Member Author

cc @dkayiwa @mozzy11 any more comments on this

@Muta-Jonathan
Copy link

Is this still available.

@sherrif10
Copy link
Member Author

Yes thanks. WIll look through and update the need branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants