/** * @see org.openmrs.module.webservices.rest.web.resource.api.Creatable#create(org.springframework.web.context.request.WebRequest) */ @Override public Object create(SimpleObject propertiesToCreate, RequestContext context) throws ResponseException { T delegate = convert(propertiesToCreate); ValidateUtil.validate(delegate); delegate = save(delegate); SimpleObject ret = (SimpleObject) ConversionUtil.convertToRepresentation(delegate, context.getRepresentation()); // add the 'type' discriminator if we support subclasses if (hasTypesDefined()) { ret.add(RestConstants.PROPERTY_FOR_TYPE, getTypeName(delegate)); } return ret; }
/** * @see org.openmrs.module.webservices.rest.web.resource.api.Retrievable#retrieve(java.lang.String, * org.openmrs.module.webservices.rest.web.representation.Representation) */ @Override public Object retrieve(String uuid, RequestContext context) throws ResponseException { T delegate = getByUniqueId(uuid); if (delegate == null) throw new ObjectNotFoundException(); SimpleObject ret = asRepresentation(delegate, context.getRepresentation()); if (hasTypesDefined()) ret.add(RestConstants.PROPERTY_FOR_TYPE, getTypeName(delegate)); return ret; }
/** * @see org.openmrs.module.webservices.rest.web.resource.api.Deletable#delete(java.lang.String) */ @Override public void delete(String uuid, String reason, RequestContext context) throws ResponseException { T delegate = getByUniqueId(uuid); if (delegate == null) throw new ObjectNotFoundException(); delete(delegate, reason, context); }
@Override public Model getGETModel(Representation rep) { return ((ModelImpl) super.getGETModel(rep)) .property("uuid", new StringProperty()) .property("value", new StringProperty()); }
/** * @see org.openmrs.module.webservices.rest.web.resource.api.Listable#getAll(org.openmrs.module.webservices.rest.web.RequestContext) */ @Override public SimpleObject getAll(RequestContext context) throws ResponseException { if (context.getType() != null) { if (!hasTypesDefined()) throw new IllegalArgumentException(getClass() + " does not support " + RestConstants.REQUEST_PROPERTY_FOR_TYPE); if (context.getType().equals(getResourceName())) throw new IllegalArgumentException("You may not specify " + RestConstants.REQUEST_PROPERTY_FOR_TYPE + "=" + context.getType() + " because it is the default behavior for this resource"); DelegatingSubclassHandler<T, ? extends T> handler = getSubclassHandler(context.getType()); if (handler == null) throw new IllegalArgumentException("No handler is specified for " + RestConstants.REQUEST_PROPERTY_FOR_TYPE + "=" + context.getType()); PageableResult result = handler.getAllByType(context); return result.toSimpleObject(this); } else { PageableResult result = doGetAll(context); return result.toSimpleObject(this); } }
@Test public void convert_shouldConvertASimpleObjectThatIncludesAUuid() { final String uuid = "91f6c840-da25-11e8-ae91-0242ac110002"; SimpleObject so = new SimpleObject(); so.add("uuid", uuid); so.add("name", "Location name"); so.add("description", "Location description"); DelegatingCrudResource<Location> resource = new LocationResource1_8(); Location location = resource.convert(so); Assert.assertEquals(uuid, location.getUuid()); }
/** * @see org.openmrs.module.webservices.rest.web.resource.api.Searchable#search(org.openmrs.module.webservices.rest.web.RequestContext) */ @Override public SimpleObject search(RequestContext context) throws ResponseException { PageableResult result = doSearch(context); return result.toSimpleObject(this); }
/** * Assumes we can get a "display" property * * @param delegate * @return standard REF representation of delegate * @throws ConversionException */ @RepHandler(RefRepresentation.class) public SimpleObject convertToRef(Subclass delegate) throws ConversionException { DelegatingResourceDescription rep = new DelegatingResourceDescription(); rep.addProperty("uuid"); rep.addProperty("display"); if (delegate instanceof OpenmrsData) { if (((OpenmrsData) delegate).isVoided()) rep.addProperty("voided"); } else if (delegate instanceof OpenmrsMetadata) { if (((OpenmrsMetadata) delegate).isRetired()) rep.addProperty("retired"); } rep.addSelfLink(); return getResource().convertDelegateToRepresentation(delegate, rep); }
@Override public Model getGETModel(Representation rep) { ModelImpl modelImpl = ((ModelImpl) super.getGETModel(rep)) .property("uuid", new StringProperty()) .property("display", new StringProperty()); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { modelImpl .property("value", new StringProperty()) .property("locale", new StringProperty().example("en")); //FIXME type } return modelImpl; }
@Override public Model getGETModel(Representation rep) { ModelImpl model = ((ModelImpl) super.getGETModel(rep)) .property("uuid", new StringProperty()) .property("display", new StringProperty()); if (rep instanceof FullRepresentation) { model .property("name", new StringProperty()) .property("description", new StringProperty()) .property("retired", new BooleanProperty()); } return model; }
@Override public Model getGETModel(Representation rep) { ModelImpl model = (ModelImpl) super.getGETModel(rep); if (rep instanceof DefaultRepresentation) { model .property("termA", new RefProperty("#/definitions/ConceptreferencetermGetRef")) .property("termB", new RefProperty("#/definitions/ConceptreferencetermGetRef")) .property("conceptMapType", new RefProperty("#/definitions/ConceptmaptypeGetRef")); } else if (rep instanceof FullRepresentation) { model .property("termA", new RefProperty("#/definitions/ConceptreferencetermGet")) .property("termB", new RefProperty("#/definitions/ConceptreferencetermGet")) .property("conceptMapType", new RefProperty("#/definitions/ConceptmaptypeGet")); } return model; }
@Override public Model getGETModel(Representation rep) { ModelImpl model = (ModelImpl) super.getGETModel(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { model .property("uuid", new StringProperty()) .property("display", new StringProperty()) .property("datatypeClassname", new StringProperty()); } if (rep instanceof DefaultRepresentation) { model .property("handlers", new ArrayProperty(new RefProperty("#/definitions/CustomdatatypeHandlersGetRef"))); } else if (rep instanceof FullRepresentation) { model .property("handlers", new ArrayProperty(new RefProperty("#/definitions/CustomdatatypeHandlersGet"))); } return model; }
@Override public Model getGETModel(Representation rep) { ModelImpl model = ((ModelImpl) super.getGETModel(rep)); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { model .property("uuid", new StringProperty()) .property("property", new StringProperty()) .property("value", new StringProperty()) .property("description", new StringProperty()) .property("display", new StringProperty()); } if (rep instanceof FullRepresentation) { model .property("datatypeClassname", new StringProperty()) .property("datatypeConfig", new StringProperty()) .property("preferredHandlerClassname", new StringProperty()) .property("handlerConfig", new StringProperty()); } return model; }
public Model getGETModel(Representation rep) { ModelImpl modelImpl = ((ModelImpl) super.getGETModel(rep)) .property("uuid", new StringProperty()) .property("display", new StringProperty()); if (rep instanceof DefaultRepresentation) { modelImpl .property("name", new RefProperty("#/definitions/ConceptNameGet")) .property("datatype", new RefProperty("#/definitions/ConceptdatatypeGetRef")) .property("conceptClass", new RefProperty("#/definitions/ConceptclassGetRef")) .property("set", new BooleanProperty()) .property("version", new StringProperty()) .property("retired", new BooleanProperty()) .property("names", new ArrayProperty(new RefProperty("#/definitions/ConceptNameGetRef"))) //FIXME .property("descriptions", new ArrayProperty(new RefProperty("#/definitions/ConceptDescriptionGetRef"))) //FIXME .property("mappings", new ArrayProperty(new RefProperty("#/definitions/ConceptMappingGetRef"))) //FIXME .property("answers", new ArrayProperty(new ObjectProperty())) //FIXME .property("setMembers", new ArrayProperty(new ObjectProperty())); //FIXME } return modelImpl; }