Search in sources :

Example 1 with OnmsHwEntityAttribute

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

the class HardwareInventoryResource method updateTypes.

/**
 * Update types.
 *
 * @param typesMap the types map
 * @param entity the entity
 */
private void updateTypes(Map<String, HwEntityAttributeType> typesMap, OnmsHwEntity entity) {
    for (OnmsHwEntityAttribute a : entity.getHwEntityAttributes()) {
        final String typeName = a.getTypeName();
        if (!typesMap.containsKey(typeName)) {
            HwEntityAttributeType t = m_hwEntityAttribTypeDao.findTypeByName(typeName);
            if (t == null) {
                t = a.getType();
                m_hwEntityAttribTypeDao.save(t);
            }
            typesMap.put(t.getName(), t);
        }
        a.setType(typesMap.get(typeName));
    }
    for (OnmsHwEntity child : entity.getChildren()) {
        updateTypes(typesMap, child);
    }
}
Also used : OnmsHwEntity(org.opennms.netmgt.model.OnmsHwEntity) OnmsHwEntityAttribute(org.opennms.netmgt.model.OnmsHwEntityAttribute) HwEntityAttributeType(org.opennms.netmgt.model.HwEntityAttributeType)

Example 2 with OnmsHwEntityAttribute

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

the class HardwareInventoryResource method updateHwEntity.

/**
 * Update hardware entity.
 *
 * @param nodeCriteria the node criteria
 * @param entPhysicalIndex the entity physical index
 * @param params the parameters
 * @return the response
 */
@PUT
@Path("{entPhysicalIndex}")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response updateHwEntity(@PathParam("nodeCriteria") String nodeCriteria, @PathParam("entPhysicalIndex") Integer entPhysicalIndex, MultivaluedMapImpl params) {
    writeLock();
    try {
        final OnmsNode node = getOnmsNode(nodeCriteria);
        final OnmsHwEntity entity = getHwEntity(node.getId(), entPhysicalIndex);
        boolean modified = true;
        BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(entity);
        for (String key : params.keySet()) {
            if (key.startsWith("entPhysical")) {
                if (wrapper.isWritableProperty(key)) {
                    String stringValue = params.getFirst(key);
                    Object value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
                    wrapper.setPropertyValue(key, value);
                    modified = true;
                }
            } else {
                OnmsHwEntityAttribute attr = entity.getAttribute(key);
                if (attr != null) {
                    attr.setValue(params.getFirst(key));
                    modified = true;
                }
            }
        }
        if (modified) {
            m_hwEntityDao.save(entity);
            return Response.noContent().build();
        }
        return Response.notModified().build();
    } finally {
        writeUnlock();
    }
}
Also used : OnmsHwEntity(org.opennms.netmgt.model.OnmsHwEntity) BeanWrapper(org.springframework.beans.BeanWrapper) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsHwEntityAttribute(org.opennms.netmgt.model.OnmsHwEntityAttribute) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Aggregations

OnmsHwEntity (org.opennms.netmgt.model.OnmsHwEntity)2 OnmsHwEntityAttribute (org.opennms.netmgt.model.OnmsHwEntityAttribute)2 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 HwEntityAttributeType (org.opennms.netmgt.model.HwEntityAttributeType)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 BeanWrapper (org.springframework.beans.BeanWrapper)1