-
Notifications
You must be signed in to change notification settings - Fork 529
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-755: Modify user resource to include email property which would enable a user email to be edited from reference application #404
Open
tenas97
wants to merge
1
commit into
openmrs:master
Choose a base branch
from
tenas97:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Modify user resource to include email property which would enable a u…
…ser email to be edited from reference application, fixed failing tests.
- Loading branch information
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...ava/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/UserResource2_2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_2; | ||
|
||
import io.swagger.models.Model; | ||
import io.swagger.models.ModelImpl; | ||
import io.swagger.models.properties.StringProperty; | ||
import org.openmrs.User; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.module.webservices.rest.web.RestConstants; | ||
import org.openmrs.module.webservices.rest.web.annotation.Resource; | ||
import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation; | ||
import org.openmrs.module.webservices.rest.web.representation.FullRepresentation; | ||
import org.openmrs.module.webservices.rest.web.representation.Representation; | ||
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; | ||
import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.UserResource1_8; | ||
import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_0.UserResource2_0; | ||
import org.openmrs.module.webservices.rest.web.v1_0.wrapper.openmrs1_8.UserAndPassword1_8; | ||
|
||
/** | ||
* {@link Resource} for User, supporting standard CRUD operations | ||
*/ | ||
@Resource(name = RestConstants.VERSION_1 + "/user", supportedClass = UserAndPassword1_8.class, supportedOpenmrsVersions = { | ||
"2.2.*", "2.3.*" }) | ||
public class UserResource2_2 extends UserResource1_8 { | ||
|
||
/** | ||
* @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#getRepresentationDescription(org.openmrs.module.webservices.rest.web.representation.Representation) | ||
*/ | ||
@Override | ||
public DelegatingResourceDescription getRepresentationDescription(Representation rep) { | ||
DelegatingResourceDescription description = super.getRepresentationDescription(rep); | ||
if (rep instanceof DefaultRepresentation) { | ||
description.addProperty("email"); | ||
} | ||
else if (rep instanceof FullRepresentation) { | ||
description.addProperty("email"); | ||
} | ||
return description; | ||
} | ||
|
||
@Override | ||
public DelegatingResourceDescription getCreatableProperties() { | ||
DelegatingResourceDescription description = super.getCreatableProperties(); | ||
description.addRequiredProperty("email"); | ||
return description; | ||
} | ||
|
||
@Override | ||
public Model getGETModel(Representation rep) { | ||
ModelImpl model = (ModelImpl) super.getGETModel(rep); | ||
if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { | ||
model.property("email", new StringProperty()); | ||
} | ||
return model; | ||
} | ||
|
||
@Override | ||
public Model getCREATEModel(Representation rep) { | ||
return ((ModelImpl) super.getCREATEModel(rep)) | ||
.property("email", new StringProperty()); | ||
} | ||
|
||
/** | ||
* @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#save(java.lang.Object) | ||
*/ | ||
@Override | ||
public UserAndPassword1_8 save(UserAndPassword1_8 user) { | ||
User openmrsUser = new User(); | ||
if (user.getUser().getUserId() == null) { | ||
openmrsUser = Context.getUserService().createUser(user.getUser(), user.getPassword()); | ||
} else { | ||
openmrsUser = Context.getUserService().saveUser(user.getUser()); | ||
Context.refreshAuthenticatedUser(); | ||
} | ||
|
||
return new UserAndPassword1_8(openmrsUser); | ||
|
||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Whats the purpose of adding these if else conditions ? Both conditions are doing the same thing.
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 first condition checks for defaultRepresentation, second condition checks for Full representation
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 but after checking its doing the same thing
description.addProperty("email");