use of javax.ws.rs.PUT in project opennms by OpenNMS.
the class SnmpTrapNorthbounderConfigurationResource method updateSnmpTrapSink.
/**
* Update a specific SNMP trap sink.
*
* @param trapSinkName the trap sink name
* @param params the parameters map
* @return the response
*/
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("trapsinks/{trapsinkName}")
public Response updateSnmpTrapSink(@PathParam("trapsinkName") final String trapSinkName, final MultivaluedMapImpl params) {
writeLock();
try {
boolean modified = false;
SnmpTrapSink trapSink = getSnmpTrapSink(trapSinkName);
final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(trapSink);
for (final String key : params.keySet()) {
if (wrapper.isWritableProperty(key)) {
final String stringValue = params.getFirst(key);
final Object value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
wrapper.setPropertyValue(key, value);
modified = true;
}
}
if (modified) {
saveConfiguration();
return Response.noContent().build();
}
return Response.notModified().build();
} finally {
writeUnlock();
}
}
use of javax.ws.rs.PUT in project opennms by OpenNMS.
the class AbstractDaoRestService method updateProperties.
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("{id}")
public Response updateProperties(@Context final UriInfo uriInfo, @PathParam("id") final K id, final MultivaluedMapImpl params) {
writeLock();
try {
final T object = getDao().get(id);
if (object == null) {
return Response.status(Status.NOT_FOUND).build();
}
LOG.debug("update: updating object {}", object);
RestUtils.setBeanProperties(object, params);
LOG.debug("update: object {} updated", object);
getDao().saveOrUpdate(object);
return Response.noContent().build();
} finally {
writeUnlock();
}
}
use of javax.ws.rs.PUT in project OpenAM by OpenRock.
the class CoreTokenResource method updateToken.
/**
* Updates a token.
*
* @param headers HTTPHeaders object of the request.
* @param request HTTPServletRequest object of the request.
* @param tokenId value of token.id in the request path parameter.
* @param eTag value of the If-Match header in the request.
* @param msgBody Message body containing the JSON-encoded token attributes.
*/
@PUT
@Consumes("application/json")
@Path("{token.id}")
public void updateToken(@Context HttpHeaders headers, @Context HttpServletRequest request, @PathParam("token.id") String tokenId, @HeaderParam("If-Match") String eTag, String msgBody) {
try {
JSONObject jObj = new JSONObject(msgBody);
CoreTokenStoreFactory.getInstance().updateToken(CoreTokenUtils.getAdminSubject(), tokenId, eTag, jObj);
// logging
String[] data = new String[] { jObj.names().toString() };
TokenLogUtils.access(Level.INFO, TokenLogUtils.TOKEN_UPDATE_SUCCESS, data, null, tokenId);
} catch (CoreTokenException ce) {
CoreTokenUtils.debug.error("CoreTokenResource.updateToken", ce);
String[] data = new String[] { ce.getLocalizedMessage() };
TokenLogUtils.error(Level.INFO, TokenLogUtils.UNABLE_TO_UPDATE_TOKEN, data, null, tokenId);
throw getWebApplicationException(headers, ce);
} catch (JSONException je) {
CoreTokenUtils.debug.error("CoreTokenResource.updateToken", je);
String[] data = new String[] { je.getLocalizedMessage() };
TokenLogUtils.error(Level.INFO, TokenLogUtils.UNABLE_TO_UPDATE_TOKEN, data, null, tokenId);
throw getWebApplicationException(je, MimeType.PLAIN);
}
}
use of javax.ws.rs.PUT in project OpenAM by OpenRock.
the class PrivilegeResource method modifyPrivilege.
@PUT
@Produces("application/json")
@Path("/{name}")
public String modifyPrivilege(@Context HttpHeaders headers, @Context HttpServletRequest request, @FormParam("realm") @DefaultValue("/") String realm, @FormParam("privilege.json") String jsonString, @PathParam("name") String name) {
try {
Subject caller = getCaller(request);
PrivilegeManager pm = PrivilegeManager.getInstance(realm, caller);
Privilege privilege = Privilege.getNewInstance(jsonString);
pm.modify(privilege);
return createResponseJSONString(200, headers, "OK");
} catch (JSONException e) {
PrivilegeManager.debug.error("PrivilegeResource.modify", e);
throw getWebApplicationException(e, MimeType.JSON);
} catch (RestException e) {
PrivilegeManager.debug.error("PrivilegeResource.modify", e);
throw getWebApplicationException(headers, e, MimeType.JSON);
} catch (EntitlementException e) {
PrivilegeManager.debug.error("PrivilegeResource.modify", e);
throw getWebApplicationException(headers, e, MimeType.JSON);
}
}
use of javax.ws.rs.PUT in project graylog2-server by Graylog2.
the class RolesResource method update.
@PUT
@Path("{rolename}")
@ApiOperation("Update an existing role")
@AuditEvent(type = AuditEventTypes.ROLE_UPDATE)
public RoleResponse update(@ApiParam(name = "rolename", required = true) @PathParam("rolename") String name, @ApiParam(name = "JSON Body", value = "The new representation of the role", required = true) RoleResponse role) throws NotFoundException {
final Role roleToUpdate = roleService.load(name);
if (roleToUpdate.isReadOnly()) {
throw new BadRequestException("Cannot update read only role " + name);
}
roleToUpdate.setName(role.name());
roleToUpdate.setDescription(role.description().orNull());
roleToUpdate.setPermissions(role.permissions());
try {
roleService.save(roleToUpdate);
} catch (ValidationException e) {
throw new BadRequestException(e);
}
return RoleResponse.create(roleToUpdate.getName(), Optional.fromNullable(roleToUpdate.getDescription()), roleToUpdate.getPermissions(), role.readOnly());
}
Aggregations