Ejemplo n.º 1
0
 @PUT
 @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
 @Path("{userCriteria}")
 public Response updateUser(
     @PathParam("userCriteria") final String userCriteria, final MultivaluedMapImpl params) {
   OnmsUser user = null;
   writeLock();
   try {
     try {
       user = m_userManager.getOnmsUser(userCriteria);
     } catch (final Throwable t) {
       throw getException(Status.BAD_REQUEST, t);
     }
     if (user == null)
       throw getException(Status.BAD_REQUEST, "updateUser: User does not exist: " + userCriteria);
     log().debug("updateUser: updating user " + user);
     final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(user);
     for (final String key : params.keySet()) {
       if (wrapper.isWritableProperty(key)) {
         final String stringValue = params.getFirst(key);
         @SuppressWarnings("unchecked")
         final Object value =
             wrapper.convertIfNecessary(stringValue, wrapper.getPropertyType(key));
         wrapper.setPropertyValue(key, value);
       }
     }
     log().debug("updateUser: user " + user + " updated");
     try {
       m_userManager.save(user);
     } catch (final Throwable t) {
       throw getException(Status.INTERNAL_SERVER_ERROR, t);
     }
     return Response.seeOther(getRedirectUri(m_uriInfo)).build();
   } finally {
     writeUnlock();
   }
 }