-
Notifications
You must be signed in to change notification settings - Fork 513
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
388 additions
and
1 deletion.
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
51 changes: 51 additions & 0 deletions
51
...va/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/FulfillerDetails.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,51 @@ | ||
/** | ||
* 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 org.openmrs.Order; | ||
|
||
public class FulfillerDetails { | ||
|
||
private Order.FulfillerStatus fulfillerStatus; | ||
|
||
private String fulfillerComment; | ||
|
||
private Order order; | ||
|
||
public FulfillerDetails() { | ||
|
||
} | ||
|
||
public Order.FulfillerStatus getFulfillerStatus() { | ||
return fulfillerStatus; | ||
} | ||
|
||
public String getFulfillerComment() { | ||
return fulfillerComment; | ||
} | ||
|
||
public Order getOrder() { | ||
return order; | ||
} | ||
|
||
public void setFulfillerStatus(Order.FulfillerStatus fulfillerStatus) { | ||
this.fulfillerStatus = fulfillerStatus; | ||
} | ||
|
||
public void setFulfillerComment(String fulfillerComment) { | ||
this.fulfillerComment = fulfillerComment; | ||
} | ||
|
||
public void setOrder(Order order) { | ||
this.order = order; | ||
} | ||
|
||
} |
98 changes: 98 additions & 0 deletions
98
...mrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/FulfillerDetailsResource2_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,98 @@ | ||
/** | ||
* 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.Order; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty; | ||
import org.openmrs.module.webservices.rest.web.RequestContext; | ||
import org.openmrs.module.webservices.rest.web.RestConstants; | ||
import org.openmrs.module.webservices.rest.web.annotation.Resource; | ||
import org.openmrs.module.webservices.rest.web.annotation.SubResource; | ||
import org.openmrs.module.webservices.rest.web.representation.Representation; | ||
import org.openmrs.module.webservices.rest.web.resource.api.PageableResult; | ||
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; | ||
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource; | ||
import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException; | ||
import org.openmrs.module.webservices.rest.web.response.ResponseException; | ||
|
||
/** | ||
* {@link Resource} for Order, supporting standard CRUD operations on fulfiller_comment and | ||
* fulfiller_status | ||
*/ | ||
@SubResource(parent = OrderResource2_2.class, path = "fulfillerdetails", supportedClass = FulfillerDetails.class, supportedOpenmrsVersions = { | ||
"2.2.*" }) | ||
public class FulfillerDetailsResource2_2 extends DelegatingSubResource<FulfillerDetails, Order, OrderResource2_2> { | ||
|
||
@Override | ||
public FulfillerDetails newDelegate() { | ||
return new FulfillerDetails(); | ||
} | ||
|
||
@Override | ||
public FulfillerDetails save(FulfillerDetails delegate) { | ||
Context.getOrderService().updateOrderFulfillerStatus(delegate.getOrder(), delegate.getFulfillerStatus(), | ||
delegate.getFulfillerComment()); | ||
return delegate; | ||
} | ||
|
||
@Override | ||
public DelegatingResourceDescription getRepresentationDescription(Representation rep) { | ||
DelegatingResourceDescription delegatingResourceDescription = new DelegatingResourceDescription(); | ||
delegatingResourceDescription.addProperty("fulfillerStatus"); | ||
delegatingResourceDescription.addProperty("fulfillerComment"); | ||
return delegatingResourceDescription; | ||
} | ||
|
||
@Override | ||
public Model getCREATEModel(Representation rep) { | ||
return new ModelImpl() | ||
.property("fulfillerComment", new StringProperty()) | ||
.property("fulfillerStatus", new EnumProperty(null)); | ||
} | ||
|
||
@Override | ||
public Order getParent(FulfillerDetails instance) { | ||
return instance.getOrder(); | ||
} | ||
|
||
@Override | ||
public void setParent(FulfillerDetails instance, Order parent) { | ||
instance.setOrder(parent); | ||
} | ||
|
||
@Override | ||
public PageableResult doGetAll(Order parent, RequestContext context) throws ResponseException { | ||
throw new ResourceDoesNotSupportOperationException(); | ||
} | ||
|
||
@Override | ||
public FulfillerDetails getByUniqueId(String uniqueId) { | ||
throw new ResourceDoesNotSupportOperationException(); | ||
} | ||
|
||
@Override | ||
protected void delete(FulfillerDetails delegate, String reason, RequestContext context) throws ResponseException { | ||
throw new ResourceDoesNotSupportOperationException(); | ||
} | ||
|
||
@Override | ||
public void purge(FulfillerDetails delegate, RequestContext context) throws ResponseException { | ||
throw new ResourceDoesNotSupportOperationException(); | ||
} | ||
|
||
@Override | ||
public DelegatingResourceDescription getCreatableProperties() { | ||
return getRepresentationDescription(null); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...va/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/OrderResource2_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,38 @@ | ||
/** | ||
* 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 org.openmrs.Order; | ||
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_10.OrderResource1_10; | ||
|
||
@Resource(name = RestConstants.VERSION_1 + "/order", supportedClass = Order.class, supportedOpenmrsVersions = { "2.2.*" }) | ||
public class OrderResource2_2 extends OrderResource1_10 { | ||
|
||
/** | ||
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getRepresentationDescription(org.openmrs.module.webservices.rest.web.representation.Representation) | ||
*/ | ||
@Override | ||
public DelegatingResourceDescription getRepresentationDescription(Representation rep) { | ||
DelegatingResourceDescription delegatingResourceDescription = super.getRepresentationDescription(rep); | ||
|
||
if (delegatingResourceDescription != null && rep instanceof FullRepresentation) { | ||
delegatingResourceDescription.addProperty("fulfillerStatus"); | ||
delegatingResourceDescription.addProperty("fulfillerComment"); | ||
} | ||
return delegatingResourceDescription; | ||
} | ||
|
||
} |
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
74 changes: 74 additions & 0 deletions
74
...dule/webservices/rest/web/v1_0/resource/openmrs2_2/FulfillerDetailsController2_2Test.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,74 @@ | ||
/** | ||
* 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 org.junit.Test; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.openmrs.Order; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.module.webservices.rest.SimpleObject; | ||
import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException; | ||
import org.openmrs.module.webservices.rest.web.v1_0.RestTestConstants2_2; | ||
import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest; | ||
import org.springframework.mock.web.MockHttpServletRequest; | ||
|
||
public class FulfillerDetailsController2_2Test extends MainResourceControllerTest { | ||
|
||
@Test | ||
public void test_shouldSetFulfillerDetailsOfOrderByPost() throws Exception { | ||
Order.FulfillerStatus fulfillerStatus = Order.FulfillerStatus.RECEIVED; | ||
String fillerComment = "An example comment from a filler"; | ||
SimpleObject post = new SimpleObject().add("fulfillerStatus", fulfillerStatus) | ||
.add("fulfillerComment", fillerComment); | ||
MockHttpServletRequest request = newPostRequest(getURI(), post); | ||
|
||
handle(request); | ||
|
||
Order order = Context.getOrderService().getOrderByUuid(RestTestConstants2_2.ORDER_UUID); | ||
assertEquals(order.getFulfillerStatus(), fulfillerStatus); | ||
assertEquals(order.getFulfillerComment(), fillerComment); | ||
} | ||
|
||
@Test(expected = ResourceDoesNotSupportOperationException.class) | ||
public void shouldGetAll() throws Exception { | ||
super.shouldGetAll(); | ||
} | ||
|
||
@Test(expected = ResourceDoesNotSupportOperationException.class) | ||
public void shouldGetDefaultByUuid() throws Exception { | ||
super.shouldGetDefaultByUuid(); | ||
} | ||
|
||
@Test(expected = ResourceDoesNotSupportOperationException.class) | ||
public void shouldGetFullByUuid() throws Exception { | ||
super.shouldGetFullByUuid(); | ||
} | ||
|
||
@Test(expected = ResourceDoesNotSupportOperationException.class) | ||
public void shouldGetRefByUuid() throws Exception { | ||
super.shouldGetRefByUuid(); | ||
} | ||
|
||
@Override | ||
public String getURI() { | ||
return "order/" + RestTestConstants2_2.ORDER_UUID + "/fulfillerdetails"; | ||
} | ||
|
||
@Override | ||
public String getUuid() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public long getAllCount() { | ||
return 0; | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...module/webservices/rest/web/v1_0/resource/openmrs2_2/FulfillerDetailsResource2_2Test.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,75 @@ | ||
/** | ||
* 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 org.openmrs.Order; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResourceTest; | ||
import org.openmrs.module.webservices.rest.web.v1_0.RestTestConstants2_2; | ||
|
||
import static org.junit.Assert.assertThat; | ||
import static org.openmrs.module.webservices.rest.test.LinkMatcher.hasLink; | ||
|
||
public class FulfillerDetailsResource2_2Test extends BaseDelegatingResourceTest<FulfillerDetailsResource2_2, FulfillerDetails> { | ||
|
||
private String fulfillerComment = "Some example comment"; | ||
|
||
private Order.FulfillerStatus fulfillerStatus = Order.FulfillerStatus.RECEIVED; | ||
|
||
/** | ||
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResourceTest#newObject() | ||
*/ | ||
@Override | ||
public FulfillerDetails newObject() { | ||
|
||
Order order = Context.getOrderService().getOrderByUuid(RestTestConstants2_2.ORDER_UUID); | ||
FulfillerDetails fillerDetailsRepresentation = new FulfillerDetails(); | ||
fillerDetailsRepresentation.setOrder(order); | ||
fillerDetailsRepresentation.setFulfillerComment(fulfillerComment); | ||
fillerDetailsRepresentation.setFulfillerStatus(fulfillerStatus); | ||
|
||
return fillerDetailsRepresentation; | ||
} | ||
|
||
/** | ||
* @see BaseDelegatingResourceTest#validateDefaultRepresentation() | ||
*/ | ||
@Override | ||
public void validateDefaultRepresentation() throws Exception { | ||
assertPropEquals("fulfillerStatus", fulfillerStatus); | ||
assertPropEquals("fulfillerComment", fulfillerComment); | ||
} | ||
|
||
/** | ||
* @see BaseDelegatingResourceTest#validateFullRepresentation() | ||
*/ | ||
public void validateFullRepresentation() throws Exception { | ||
assertPropEquals("fulfillerStatus", fulfillerStatus); | ||
assertPropEquals("fulfillerComment", fulfillerComment); | ||
} | ||
|
||
/** | ||
* @see BaseDelegatingResourceTest#validateRefRepresentation() | ||
*/ | ||
public void validateRefRepresentation() throws Exception { | ||
assertPropEquals("fulfillerStatus", fulfillerStatus); | ||
assertPropEquals("fulfillerComment", fulfillerComment); | ||
} | ||
|
||
@Override | ||
public String getDisplayProperty() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getUuidProperty() { | ||
return null; | ||
} | ||
} |
Oops, something went wrong.