Search in sources :

Example 1 with OnmsGroup

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();
    }
}
Also used : OnmsGroup(org.opennms.netmgt.model.OnmsGroup) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 2 with OnmsGroup

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();
    }
}
Also used : OnmsGroupList(org.opennms.netmgt.model.OnmsGroupList) ArrayList(java.util.ArrayList) OnmsGroup(org.opennms.netmgt.model.OnmsGroup) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with OnmsGroup

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();
    }
}
Also used : OnmsGroup(org.opennms.netmgt.model.OnmsGroup) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 4 with OnmsGroup

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);
}
Also used : Group(org.opennms.netmgt.config.groups.Group) OnmsGroup(org.opennms.netmgt.model.OnmsGroup)

Example 5 with OnmsGroup

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();
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) OnmsGroup(org.opennms.netmgt.model.OnmsGroup) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Aggregations

OnmsGroup (org.opennms.netmgt.model.OnmsGroup)5 Path (javax.ws.rs.Path)3 DELETE (javax.ws.rs.DELETE)2 ArrayList (java.util.ArrayList)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 PUT (javax.ws.rs.PUT)1 Produces (javax.ws.rs.Produces)1 Group (org.opennms.netmgt.config.groups.Group)1 OnmsGroupList (org.opennms.netmgt.model.OnmsGroupList)1 BeanWrapper (org.springframework.beans.BeanWrapper)1