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);
}
}
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();
}
}
Aggregations