mirror of
https://github.com/sismics/docs.git
synced 2024-11-21 21:47:57 +01:00
Edition of tag name (server)
This commit is contained in:
parent
4dc5cb12b3
commit
6c1354a2f6
@ -1,3 +1,3 @@
|
||||
- Client side search on tags
|
||||
- Client/server side edition of existing tag names
|
||||
- Client side edition of existing tag names
|
||||
- Server side reordering files
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.FormParam;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
@ -74,7 +75,7 @@ public class TagResource extends BaseResource {
|
||||
}
|
||||
|
||||
// Validate input data
|
||||
name = ValidationUtil.validateLength(name, "title", 1, 36, false);
|
||||
name = ValidationUtil.validateLength(name, "name", 1, 36, false);
|
||||
|
||||
// Get the tag
|
||||
TagDao tagDao = new TagDao();
|
||||
@ -94,6 +95,41 @@ public class TagResource extends BaseResource {
|
||||
return Response.ok().entity(response).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a tag tag.
|
||||
*
|
||||
* @param name Name
|
||||
* @return Response
|
||||
* @throws JSONException
|
||||
*/
|
||||
@POST
|
||||
@Path("{id: [a-z0-9\\-]+}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response update(
|
||||
@PathParam("id") String id,
|
||||
@FormParam("name") String name) throws JSONException {
|
||||
if (!authenticate()) {
|
||||
throw new ForbiddenClientException();
|
||||
}
|
||||
|
||||
// Validate input data
|
||||
name = ValidationUtil.validateLength(name, "name", 1, 36, false);
|
||||
|
||||
// Get the tag
|
||||
TagDao tagDao = new TagDao();
|
||||
Tag tag = tagDao.getByUserIdAndTagId(principal.getId(), id);
|
||||
if (tag == null) {
|
||||
throw new ClientException("TagNotFound", MessageFormat.format("Tag not found: {0}", id));
|
||||
}
|
||||
|
||||
// Update the tag
|
||||
tag.setName(name);
|
||||
|
||||
JSONObject response = new JSONObject();
|
||||
response.put("id", id);
|
||||
return Response.ok().entity(response).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a tag.
|
||||
*
|
||||
|
@ -51,6 +51,26 @@ public class TestTagResource extends BaseJerseyTest {
|
||||
JSONArray tags = json.getJSONArray("tags");
|
||||
Assert.assertTrue(tags.length() > 0);
|
||||
|
||||
// Update a document
|
||||
tagResource = resource().path("/tag/" + tag3Id);
|
||||
tagResource.addFilter(new CookieAuthenticationFilter(tag1Token));
|
||||
postParams = new MultivaluedMapImpl();
|
||||
postParams.add("name", "Updated name");
|
||||
response = tagResource.post(ClientResponse.class, postParams);
|
||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||
json = response.getEntity(JSONObject.class);
|
||||
Assert.assertEquals(tag3Id, json.getString("id"));
|
||||
|
||||
// Get all tags
|
||||
tagResource = resource().path("/tag/list");
|
||||
tagResource.addFilter(new CookieAuthenticationFilter(tag1Token));
|
||||
response = tagResource.get(ClientResponse.class);
|
||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||
json = response.getEntity(JSONObject.class);
|
||||
tags = json.getJSONArray("tags");
|
||||
Assert.assertTrue(tags.length() > 0);
|
||||
Assert.assertEquals("Updated name", tags.getJSONObject(0).getString("name"));
|
||||
|
||||
// Deletes a tag
|
||||
tagResource = resource().path("/tag/" + tag3Id);
|
||||
tagResource.addFilter(new CookieAuthenticationFilter(tag1Token));
|
||||
|
Loading…
Reference in New Issue
Block a user