Search in sources :

Example 1 with Aliases

use of org.opennms.web.rest.support.Aliases in project opennms by OpenNMS.

the class NodeRestService method getCriteriaBehaviors.

@Override
protected Map<String, CriteriaBehavior<?>> getCriteriaBehaviors() {
    Map<String, CriteriaBehavior<?>> map = new HashMap<>();
    // Root alias
    map.putAll(CriteriaBehaviors.NODE_BEHAVIORS);
    // 1st level JOINs
    map.putAll(CriteriaBehaviors.withAliasPrefix(Aliases.assetRecord, CriteriaBehaviors.ASSET_RECORD_BEHAVIORS));
    map.putAll(CriteriaBehaviors.withAliasPrefix(Aliases.category, CriteriaBehaviors.NODE_CATEGORY_BEHAVIORS));
    // Use join conditions for one-to-many aliases
    for (Map.Entry<String, CriteriaBehavior<?>> entry : CriteriaBehaviors.IP_INTERFACE_BEHAVIORS.entrySet()) {
        map.put(Aliases.ipInterface.prop(entry.getKey()), new CriteriaBehavior(entry.getValue().getPropertyName(), entry.getValue().getConverter(), (b, v, c, w) -> {
            b.alias("ipInterfaces", Aliases.ipInterface.toString(), JoinType.LEFT_JOIN, Restrictions.or(Restrictions.eq(Aliases.ipInterface.prop(entry.getKey()), v), Restrictions.isNull(Aliases.ipInterface.prop(entry.getKey()))));
        }));
    }
    // but is necessary here because they add BeforeVisit operations to add JOINs)
    for (String prop : new String[] { "ipHostName", "isManaged" }) {
        map.put(Aliases.ipInterface.prop(prop), new CriteriaBehavior<>((String) null, String::new, (b, v, c, w) -> {
            b.alias("ipInterfaces", Aliases.ipInterface.toString(), JoinType.LEFT_JOIN, Restrictions.or(Restrictions.eq(Aliases.ipInterface.prop(prop), v), Restrictions.isNull(Aliases.ipInterface.prop(prop))));
        }));
    }
    map.putAll(CriteriaBehaviors.withAliasPrefix(Aliases.location, CriteriaBehaviors.MONITORING_LOCATION_BEHAVIORS));
    // Use join conditions for one-to-many aliases
    for (Map.Entry<String, CriteriaBehavior<?>> entry : CriteriaBehaviors.SNMP_INTERFACE_BEHAVIORS.entrySet()) {
        map.put(Aliases.snmpInterface.prop(entry.getKey()), new CriteriaBehavior(entry.getValue().getPropertyName(), entry.getValue().getConverter(), (b, v, c, w) -> {
            b.alias("snmpInterfaces", Aliases.snmpInterface.toString(), JoinType.LEFT_JOIN, Restrictions.or(Restrictions.eq(Aliases.snmpInterface.prop(entry.getKey()), v), Restrictions.isNull(Aliases.snmpInterface.prop(entry.getKey()))));
        }));
    }
    return map;
}
Also used : OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) JoinType(org.opennms.core.criteria.Alias.JoinType) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) LoggerFactory(org.slf4j.LoggerFactory) OnmsNodeList(org.opennms.netmgt.model.OnmsNodeList) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) EventUtils(org.opennms.netmgt.model.events.EventUtils) JaxbListWrapper(org.opennms.core.config.api.JaxbListWrapper) Event(org.opennms.netmgt.xml.event.Event) Map(java.util.Map) Qualifier(org.springframework.beans.factory.annotation.Qualifier) SearchBean(org.apache.cxf.jaxrs.ext.search.SearchBean) Status(javax.ws.rs.core.Response.Status) OnmsNode(org.opennms.netmgt.model.OnmsNode) RedirectHelper(org.opennms.web.rest.support.RedirectHelper) SearchProperty(org.opennms.web.rest.support.SearchProperty) NodeDao(org.opennms.netmgt.dao.api.NodeDao) MultivaluedMapImpl(org.opennms.web.rest.support.MultivaluedMapImpl) Context(javax.ws.rs.core.Context) Logger(org.slf4j.Logger) SearchProperties(org.opennms.web.rest.support.SearchProperties) Collection(java.util.Collection) Set(java.util.Set) RestUtils(org.opennms.web.api.RestUtils) Restrictions(org.opennms.core.criteria.restrictions.Restrictions) CriteriaBehavior(org.opennms.web.rest.support.CriteriaBehavior) Component(org.springframework.stereotype.Component) Response(javax.ws.rs.core.Response) ResourceContext(javax.ws.rs.container.ResourceContext) MonitoringLocationDao(org.opennms.netmgt.dao.api.MonitoringLocationDao) UriInfo(javax.ws.rs.core.UriInfo) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) CriteriaBehaviors(org.opennms.web.rest.support.CriteriaBehaviors) Aliases(org.opennms.web.rest.support.Aliases) EventProxy(org.opennms.netmgt.events.api.EventProxy) Transactional(org.springframework.transaction.annotation.Transactional) HashMap(java.util.HashMap) CriteriaBehavior(org.opennms.web.rest.support.CriteriaBehavior) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 Path (javax.ws.rs.Path)1 ResourceContext (javax.ws.rs.container.ResourceContext)1 Context (javax.ws.rs.core.Context)1 Response (javax.ws.rs.core.Response)1 Status (javax.ws.rs.core.Response.Status)1 SecurityContext (javax.ws.rs.core.SecurityContext)1 UriInfo (javax.ws.rs.core.UriInfo)1 SearchBean (org.apache.cxf.jaxrs.ext.search.SearchBean)1 JaxbListWrapper (org.opennms.core.config.api.JaxbListWrapper)1 JoinType (org.opennms.core.criteria.Alias.JoinType)1 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)1 Restrictions (org.opennms.core.criteria.restrictions.Restrictions)1 MonitoringLocationDao (org.opennms.netmgt.dao.api.MonitoringLocationDao)1 NodeDao (org.opennms.netmgt.dao.api.NodeDao)1 EventProxy (org.opennms.netmgt.events.api.EventProxy)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1