/** * @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); } }
/** * @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; }
public T convert(SimpleObject propertiesToCreate) { DelegatingResourceHandler<? extends T> handler; if (hasTypesDefined()) { String type = (String) propertiesToCreate.remove(RestConstants.PROPERTY_FOR_TYPE); if (type == null) throw new IllegalArgumentException( "When creating a resource that supports subclasses, you must indicate the particular subclass with a " + RestConstants.PROPERTY_FOR_TYPE + " property"); handler = getResourceHandler(type); } else { handler = this; } T delegate = handler.newDelegate(propertiesToCreate); DelegatingResourceDescription description = handler.getCreatableProperties(); if (propertiesToCreate.containsKey("uuid")) { description.addProperty("uuid"); } setConvertedProperties(delegate, propertiesToCreate, description, true); return delegate; }
/** * @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; }
throw new ObjectNotFoundException(); if (hasTypesDefined()) { if (hasTypesDefined()) { ret.add(RestConstants.PROPERTY_FOR_TYPE, getTypeName(delegate));