Search in sources :

Example 1 with ISO8601DateEditor

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();
}
Also used : ISO8601DateEditor(org.opennms.web.api.ISO8601DateEditor)

Example 2 with 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;
}
Also used : InetAddressTypeEditor(org.opennms.netmgt.model.InetAddressTypeEditor) BeanWrapper(org.springframework.beans.BeanWrapper) ISO8601DateEditor(org.opennms.web.api.ISO8601DateEditor) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) PrimaryTypeEditor(org.opennms.netmgt.model.PrimaryTypeEditor) StringXmlCalendarPropertyEditor(org.opennms.netmgt.provision.persist.StringXmlCalendarPropertyEditor) OnmsSeverityEditor(org.opennms.netmgt.model.OnmsSeverityEditor)

Example 3 with ISO8601DateEditor

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();
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) OnmsNode(org.opennms.netmgt.model.OnmsNode) ISO8601DateEditor(org.opennms.web.api.ISO8601DateEditor) OnmsAssetRecord(org.opennms.netmgt.model.OnmsAssetRecord) EventProxyException(org.opennms.netmgt.events.api.EventProxyException) OnmsGeolocation(org.opennms.netmgt.model.OnmsGeolocation) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Aggregations

ISO8601DateEditor (org.opennms.web.api.ISO8601DateEditor)3 BeanWrapper (org.springframework.beans.BeanWrapper)2 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 EventProxyException (org.opennms.netmgt.events.api.EventProxyException)1 InetAddressTypeEditor (org.opennms.netmgt.model.InetAddressTypeEditor)1 OnmsAssetRecord (org.opennms.netmgt.model.OnmsAssetRecord)1 OnmsGeolocation (org.opennms.netmgt.model.OnmsGeolocation)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 OnmsSeverityEditor (org.opennms.netmgt.model.OnmsSeverityEditor)1 PrimaryTypeEditor (org.opennms.netmgt.model.PrimaryTypeEditor)1 StringXmlCalendarPropertyEditor (org.opennms.netmgt.provision.persist.StringXmlCalendarPropertyEditor)1 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)1