Search in sources :

Example 1 with OnmsCategory

use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.

the class GroupRestService method getCategoryForGroup.

@GET
@Path("{groupName}/categories/{categoryName}")
public OnmsCategory getCategoryForGroup(@PathParam("groupName") final String groupName, @PathParam("categoryName") final String categoryName) {
    // check if group exists.
    getOnmsGroup(groupName);
    List<OnmsCategory> categories = m_groupService.getAuthorizedCategories(groupName);
    for (OnmsCategory eachCategory : categories) {
        if (eachCategory.getName().equals(categoryName))
            return eachCategory;
    }
    throw getException(Status.NOT_FOUND, "Category with name '{}' does not exist for group '{}'.", categoryName, groupName);
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with OnmsCategory

use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.

the class NodeRestService method removeCategoryFromNode.

@DELETE
@Path("/{nodeCriteria}/categories/{categoryName}")
public Response removeCategoryFromNode(@PathParam("nodeCriteria") String nodeCriteria, @PathParam("categoryName") String categoryName) {
    writeLock();
    try {
        OnmsNode node = m_nodeDao.get(nodeCriteria);
        if (node == null) {
            throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
        }
        OnmsCategory category = getCategory(node, categoryName);
        if (category == null) {
            throw getException(Status.BAD_REQUEST, "Category {} not found on node {}", categoryName, nodeCriteria);
        }
        LOG.debug("deleteCaegory: deleting category {} from node {}", categoryName, nodeCriteria);
        node.getCategories().remove(category);
        m_nodeDao.saveOrUpdate(node);
        return Response.noContent().build();
    } finally {
        writeUnlock();
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 3 with OnmsCategory

use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.

the class NodeRestService method updateCategoryForNode.

@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("/{nodeCriteria}/categories/{categoryName}")
public Response updateCategoryForNode(@PathParam("nodeCriteria") final String nodeCriteria, @PathParam("categoryName") final String categoryName, MultivaluedMapImpl params) {
    writeLock();
    try {
        OnmsNode node = m_nodeDao.get(nodeCriteria);
        if (node == null) {
            throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
        }
        OnmsCategory category = getCategory(node, categoryName);
        if (category == null) {
            throw getException(Status.BAD_REQUEST, "Category {} not found on node {}", categoryName, nodeCriteria);
        }
        LOG.debug("updateCategory: updating category {}", category);
        BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(category);
        boolean updated = false;
        for (String key : params.keySet()) {
            if (wrapper.isWritableProperty(key)) {
                String stringValue = params.getFirst(key);
                Object value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
                wrapper.setPropertyValue(key, value);
                updated = true;
            }
        }
        if (updated) {
            LOG.debug("updateCategory: category {} updated", category);
            m_categoryDao.saveOrUpdate(category);
        } else {
            LOG.debug("updateCategory: no fields updated in category {}", category);
        }
        return Response.noContent().build();
    } finally {
        writeUnlock();
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 4 with OnmsCategory

use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.

the class AvailabilityDatabasePopulator method getCategory.

private OnmsCategory getCategory(String categoryName) {
    OnmsCategory cat = getCategoryDao().findByName(categoryName);
    if (cat == null) {
        cat = new OnmsCategory(categoryName);
        cat.getAuthorizedGroups().add(categoryName + "Group");
        getCategoryDao().save(cat);
        getCategoryDao().flush();
    }
    return cat;
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory)

Example 5 with OnmsCategory

use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.

the class DatabasePopulator method doResetDatabase.

private void doResetDatabase() {
    LOG.debug("==== DatabasePopulator Reset ====");
    for (final OnmsOutage outage : m_outageDao.findAll()) {
        m_outageDao.delete(outage);
    }
    for (final OnmsUserNotification not : m_userNotificationDao.findAll()) {
        m_userNotificationDao.delete(not);
    }
    for (final OnmsNotification not : m_notificationDao.findAll()) {
        m_notificationDao.delete(not);
    }
    for (final OnmsAlarm alarm : m_alarmDao.findAll()) {
        m_alarmDao.delete(alarm);
    }
    for (final OnmsEvent event : m_eventDao.findAll()) {
        m_eventDao.delete(event);
    }
    for (final OnmsSnmpInterface snmpIface : m_snmpInterfaceDao.findAll()) {
        for (OnmsIpInterface eachIf : snmpIface.getIpInterfaces()) {
            eachIf.setSnmpInterface(null);
            snmpIface.getNode().getIpInterfaces().remove(eachIf);
        }
        snmpIface.getNode().getSnmpInterfaces().remove(snmpIface);
        m_snmpInterfaceDao.delete(snmpIface);
    }
    for (final OnmsIpInterface iface : m_ipInterfaceDao.findAll()) {
        iface.setSnmpInterface(null);
        iface.getNode().getIpInterfaces().remove(iface);
        m_ipInterfaceDao.delete(iface);
    }
    for (final OnmsNode node : m_nodeDao.findAll()) {
        m_nodeDao.delete(node);
    }
    for (final OnmsServiceType service : m_serviceTypeDao.findAll()) {
        m_serviceTypeDao.delete(service);
    }
    for (final OnmsMonitoringLocation location : m_monitoringLocationDao.findAll()) {
        // Don't delete the default localhost monitoring location
        if (!MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID.equals(location.getLocationName())) {
            m_monitoringLocationDao.delete(location);
        }
    }
    for (final OnmsCategory category : m_categoryDao.findAll()) {
        m_categoryDao.delete(category);
    }
    LOG.debug("= DatabasePopulatorExtension Reset Starting =");
    for (Extension eachExtension : extensions) {
        DaoSupport daoSupport = eachExtension.getDaoSupport();
        OnmsDao<?, ?> dao = daoSupport != null && daoSupport.getDaoClass() != null ? lookupDao(daoSupport.getDaoClass()) : null;
        eachExtension.onShutdown(this, dao);
        if (dao != null) {
            dao.flush();
        }
    }
    LOG.debug("= DatabasePopulatorExtension Reset Finished =");
    m_outageDao.flush();
    m_userNotificationDao.flush();
    m_notificationDao.flush();
    m_alarmDao.flush();
    m_eventDao.flush();
    m_snmpInterfaceDao.flush();
    m_ipInterfaceDao.flush();
    m_nodeDao.flush();
    m_serviceTypeDao.flush();
    LOG.debug("==== DatabasePopulator Reset Finished ====");
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsUserNotification(org.opennms.netmgt.model.OnmsUserNotification) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)

Aggregations

OnmsCategory (org.opennms.netmgt.model.OnmsCategory)63 OnmsNode (org.opennms.netmgt.model.OnmsNode)29 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)9 Path (javax.ws.rs.Path)7 LinkedHashSet (java.util.LinkedHashSet)6 HashSet (java.util.HashSet)5 AggregateStatusDefinition (org.opennms.netmgt.model.AggregateStatusDefinition)4 AggregateStatusView (org.opennms.netmgt.model.AggregateStatusView)4 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)4 Transactional (org.springframework.transaction.annotation.Transactional)4 GET (javax.ws.rs.GET)3 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)3 SearchResult (org.opennms.features.topology.api.topo.SearchResult)3 RowDef (org.opennms.netmgt.config.siteStatusViews.RowDef)3 NetworkBuilder (org.opennms.netmgt.model.NetworkBuilder)3 OnmsAssetRecord (org.opennms.netmgt.model.OnmsAssetRecord)3 OnmsGeolocation (org.opennms.netmgt.model.OnmsGeolocation)3 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)3 AggregateStatus (org.opennms.web.svclayer.model.AggregateStatus)3