use of org.opennms.web.api.ISO8601DateEditor in project opennms by OpenNMS.
the class ISO8601DateEditorTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
editor = new ISO8601DateEditor();
}
use of org.opennms.web.api.ISO8601DateEditor in project opennms by OpenNMS.
the class OnmsRestService method getBeanWrapperForClass.
protected static BeanWrapper getBeanWrapperForClass(final Class<?> criteriaClass) {
final BeanWrapper wrapper = new BeanWrapperImpl(criteriaClass);
wrapper.registerCustomEditor(XMLGregorianCalendar.class, new StringXmlCalendarPropertyEditor());
wrapper.registerCustomEditor(java.util.Date.class, new ISO8601DateEditor());
wrapper.registerCustomEditor(java.net.InetAddress.class, new InetAddressTypeEditor());
wrapper.registerCustomEditor(OnmsSeverity.class, new OnmsSeverityEditor());
wrapper.registerCustomEditor(PrimaryType.class, new PrimaryTypeEditor());
return wrapper;
}
use of org.opennms.web.api.ISO8601DateEditor in project opennms by OpenNMS.
the class AssetRecordResource method updateAssetRecord.
/**
* <p>updateAssetRecord</p>
*
* @param nodeCriteria a {@link java.lang.String} object.
* @param params a {@link org.opennms.web.rest.support.MultivaluedMapImpl} object.
* @return a {@link javax.ws.rs.core.Response} object.
*/
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response updateAssetRecord(@PathParam("nodeCriteria") final String nodeCriteria, final MultivaluedMapImpl params) {
OnmsNode node = m_nodeDao.get(nodeCriteria);
if (node == null) {
throw getException(Status.BAD_REQUEST, "updateAssetRecord: Can't find node " + nodeCriteria);
}
OnmsAssetRecord assetRecord = getAssetRecord(node);
if (assetRecord == null) {
throw getException(Status.BAD_REQUEST, "updateAssetRecord: Node " + node + " could not update ");
}
if (assetRecord.getGeolocation() == null) {
assetRecord.setGeolocation(new OnmsGeolocation());
}
LOG.debug("updateAssetRecord: updating asset {}", assetRecord);
boolean modified = false;
BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(assetRecord);
wrapper.registerCustomEditor(Date.class, new ISO8601DateEditor());
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);
modified = true;
}
}
if (modified) {
LOG.debug("updateAssetRecord: assetRecord {} updated", assetRecord);
m_assetRecordDao.saveOrUpdate(assetRecord);
try {
sendEvent(EventConstants.ASSET_INFO_CHANGED_EVENT_UEI, node.getId());
} catch (EventProxyException e) {
throw getException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
}
return Response.noContent().build();
}
return Response.notModified().build();
}
Aggregations