Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

Let's

...

start

...

with

...

a

...

short

...

comparison

...

of

...

Webservices.rest

...

1.x

...

and

...

Webservices.rest

...

2.x:

...

  1. 2.x

...

  1. supports

...

  1. OpenMRS

...

  1. 1.9

...

  1. without

...

  1. installing

...

  1. the

...

  1. Webservices.rest

...

  1. 1.9

...

  1. extension

...

  1. module,

...

  1. which

...

  1. was

...

  1. needed

...

  1. when

...

  1. using

...

  1. 1.x.

...

  1. 2.x

...

  1. exposes

...

  1. the

...

  1. same

...

  1. resources

...

  1. as

...

  1. 1.x

...

  1. and

...

  1. preserves

...

  1. the

...

  1. JSON

...

  1. format,

...

  1. but

...

  1. adds

...

  1. a

...

  1. better

...

  1. support

...

  1. for

...

  1. Concept

...

  1. mappings.

...

  1. 2.x

...

  1. has

...

  1. a

...

  1. single

...

  1. controller,

...

  1. which

...

  1. serves

...

  1. all

...

  1. resources.

...

  1. You

...

  1. do

...

  1. not

...

  1. have

...

  1. to

...

  1. create

...

  1. controllers

...

  1. for

...

  1. your

...

  1. custom

...

  1. resources

...

  1. as

...

  1. it

...

  1. was

...

  1. in

...

  1. 1.x.

...

  1. The

...

  1. 2.x

...

  1. @Resource

...

  1. annotation

...

  1. includes

...

  1. name,

...

  1. supportedClass,

...

  1. supportedOpenmrsVersions

...

  1. and

...

  1. order

...

  1. in

...

  1. comparison

...

  1. to

...

  1. 1.x

...

  1. which

...

  1. only

...

  1. had

...

  1. value

...

  1. (name).

...

  1. The

...

  1. 2.x

...

  1. @SubResource

...

  1. annotation

...

  1. includes

...

  1. parent,

...

  1. path,

...

  1. supportedClass,

...

  1. supportedOpenmrsVersions

...

  1. and

...

  1. order

...

  1. in

...

  1. comparison

...

  1. to

...

  1. 1.x

...

  1. which

...

  1. only

...

  1. had

...

  1. parent

...

  1. and

...

  1. path.

...

  1. 2.x

...

  1. reorganizes

...

  1. java

...

  1. packaging

...

  1. of

...

  1. resource

...

  1. classes

...

  1. and

...

  1. class

...

  1. names

...

  1. to

...

  1. include

...

  1. a

...

  1. corresponding

...

  1. version

...

  1. of

...

  1. OpenMRS

...

  1. i.e.

...

  1. 1_8

...

  1. or

...

  1. 1_9.

...

  1. 2.x

...

  1. introduces

...

  1. new

...

  1. SearchHandlers,

...

  1. which

...

  1. allow

...

  1. you

...

  1. to

...

  1. implement

...

  1. custom

...

  1. searches

...

  1. for

...

  1. any

...

  1. resource.

...

  1. 2.x

...

  1. tests

...

  1. resources

...

  1. by

...

  1. accessing

...

  1. actual

...

  1. URLs

...

  1. instead

...

  1. of

...

  1. controller

...

  1. methods.

...

  1. 2.x

...

  1. is

...

  1. now

...

  1. officially

...

  1. supported

...

  1. version

...

  1. of

...

  1. the

...

  1. Webservices.rest

...

  1. module.

...

  1. We

...

  1. will

...

  1. not

...

  1. add

...

  1. new

...

  1. features

...

  1. or

...

  1. fix

...

  1. bugs

...

  1. in

...

  1. 1.x.

...

If

...

you

...

didn't

...

implement

...

any

...

custom

...

resources

...

or

...

subresources

...

and

...

you

...

were

...

just

...

a

...

consumer

...

of

...

JSON,

...

the

...

migration

...

will

...

not

...

require

...

from

...

you

...

any

...

work

...

other

...

than

...

uninstalling

...

1.x

...

and

...

installing

...

2.x.

...

We

...

have

...

not

...

changed

...

any

...

resources

...

aside

...

from

...

Concept,

...

which only received one new property for mappings. We also corrected a path for the location resource in OpenMRS 1.9,

...

which

...

was

...

wrongly

...

exposed

...

at

...

/rest/ws/

...

v2

...

/location

...

instead

...

of

...

/rest/ws/

...

v1

...

/location.

...

If

...

you

...

did

...

implement

...

custom

...

resources

...

in

...

your

...

own

...

module,

...

then

...

you

...

will

...

have

...

to

...

adjust

...

to

...

new

...

packaging,

...

resource/subresource

...

annotations and remove resource controllers.

...

It

...

is pretty straightforward, yet it can be tedious depending on how many custom resources you have.

Let's consider a specific example. We want to move ObsResource to 2.x. You need to start from changing dependencies in your poms and creating a single controller to define your module namespace. See Adding a Web Service Step by Step Guide for Core Developers.

  1. Open ObsResource.java and remove @Handler. Change the resource annotation to @Resource(name = "obs", supportedClass = Obs.class, supportedOpenmrsVersions = { "1.8.

...

  1. ",

...

  1. "1.9.

...

  1. " }).

...

  1. Fix

...

  1. imports

...

  1. if

...

  1. any.

...

  1. Open ObsController.java

...

  1. .

...

  1. You

...

  1. can

...

  1. see

...

  1. that

...

  1. it

...

  1. has

...

  1. two

...

  1. custom

...

  1. search

...

  1. methods.

...

  1. Create

...

  1. ObsSearchHandler

...

  1. implementing

...

  1. SearchHandler,

...

  1. which

...

  1. can

...

  1. do

...

  1. the

...

  1. same

...

  1. searches

...

  1. depending

...

  1. on

...

  1. which

...

  1. request

...

  1. parameter

...

  1. is

...

  1. given.

...

  1. The

...

  1. alternative

...

  1. is

...

  1. to

...

  1. implement

...

  1. searches

...

  1. directly

...

  1. in

...

  1. the

...

  1. resource

...

  1. by

...

  1. overriding

...

  1. the

...

  1. doSearch

...

  1. method.

...

  1. We

...

  1. recommend

...

  1. SearchHandler

...

  1. as

...

  1. it

...

  1. is

...

  1. more

...

  1. robust.

...

  1. Remove

...

  1. ObsController.java.

...

  1. It

...

  1. is

...

  1. no

...

  1. longer

...

  1. necessary

...

  1. since

...

  1. all

...

  1. requests

...

  1. are

...

  1. handled

...

  1. by

...

  1. the

...

  1. main

...

  1. controller

...

  1. and

...

  1. you

...

  1. moved

...

  1. custom

...

  1. searches

...

  1. to

...

  1. ObsSearchHandler.

...

  1. If

...

  1. you

...

  1. had

...

  1. ObsControllerTest.java

...

  1. which

...

  1. called

...

  1. ObsController

...

  1. methods,

...

  1. then

...

  1. you

...

  1. need

...

  1. to

...

  1. change

...

  1. it

...

  1. to extend MainResourceControllerTest and call newGetRequest,

...

  1. newPostRequest

...

  1. or

...

  1. newDeleteRequest

...

  1. with

...

  1. the

...

  1. correct

...

  1. URL.

...

  1. See

...

  1. the

...

  1. new

...

  1. ObsController1_8Test.java

...

  1. for

...

  1. example.

...

That's

...

it

...

!

...

Let

...

us

...

know

...

if

...

you

...

have

...

any

...

questions.