use of org.opennms.netmgt.model.OnmsGroup in project opennms by OpenNMS.
the class GroupRestService method deleteGroup.
@DELETE
@Path("{groupName}")
public Response deleteGroup(@PathParam("groupName") final String groupName) {
writeLock();
try {
final OnmsGroup group = getOnmsGroup(groupName);
LOG.debug("deleteGroup: deleting group {}", group);
m_groupService.deleteGroup(groupName);
return Response.noContent().build();
} finally {
writeUnlock();
}
}
use of org.opennms.netmgt.model.OnmsGroup in project opennms by OpenNMS.
the class GroupRestService method getGroups.
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
public OnmsGroupList getGroups() {
readLock();
try {
final OnmsGroupList list = m_groupService.getOnmsGroupList();
final List<OnmsGroup> groups = new ArrayList<OnmsGroup>(list.getGroups());
Collections.sort(groups, new Comparator<OnmsGroup>() {
@Override
public int compare(final OnmsGroup a, final OnmsGroup b) {
return a.getName().compareTo(b.getName());
}
});
list.setGroups(groups);
return list;
} finally {
readUnlock();
}
}
use of org.opennms.netmgt.model.OnmsGroup in project opennms by OpenNMS.
the class GroupRestService method removeUser.
@DELETE
@Path("{groupName}/users/{userName}")
public Response removeUser(@PathParam("groupName") final String groupName, @PathParam("userName") final String userName) {
writeLock();
try {
final OnmsGroup group = getOnmsGroup(groupName);
if (group.getUsers().contains(userName)) {
group.removeUser(userName);
m_groupService.saveGroup(group);
return Response.noContent().build();
} else {
throw getException(Status.BAD_REQUEST, "User with name '{}' does not exist in group '{}'", userName, groupName);
}
} finally {
writeUnlock();
}
}
use of org.opennms.netmgt.model.OnmsGroup in project opennms by OpenNMS.
the class GroupManager method save.
public synchronized void save(final OnmsGroup group) throws Exception {
Group xmlGroup = getGroup(group.getName());
if (xmlGroup == null) {
xmlGroup = new Group();
xmlGroup.setName(group.getName());
}
xmlGroup.setComments(group.getComments());
xmlGroup.setUsers(group.getUsers());
saveGroup(group.getName(), xmlGroup);
}
use of org.opennms.netmgt.model.OnmsGroup in project opennms by OpenNMS.
the class GroupRestService method updateGroup.
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("{groupName}")
public Response updateGroup(@PathParam("groupName") final String groupName, final MultivaluedMapImpl params) {
writeLock();
try {
OnmsGroup group = getOnmsGroup(groupName);
LOG.debug("updateGroup: updating group {}", group);
boolean modified = false;
final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(group);
for (final String key : params.keySet()) {
if (wrapper.isWritableProperty(key)) {
final String stringValue = params.getFirst(key);
final Object value = wrapper.convertIfNecessary(stringValue, wrapper.getPropertyType(key));
wrapper.setPropertyValue(key, value);
modified = true;
}
}
if (modified) {
LOG.debug("updateGroup: group {} updated", group);
m_groupService.saveGroup(group);
return Response.noContent().build();
}
return Response.notModified().build();
} finally {
writeUnlock();
}
}
Aggregations