use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSource in project opennms by OpenNMS.
the class ForeignSourceRestService method deletePolicy.
/**
* <p>deletePolicy</p>
*
* @param foreignSource a {@link java.lang.String} object.
* @param policy a {@link java.lang.String} object.
* @return a {@link javax.ws.rs.core.Response} object.
*/
@DELETE
@Path("{foreignSource}/policies/{policy}")
@Transactional
public Response deletePolicy(@PathParam("foreignSource") final String foreignSource, @PathParam("policy") final String policy) {
writeLock();
try {
ForeignSource fs = getActiveForeignSource(foreignSource);
List<PluginConfig> policies = fs.getPolicies();
PluginConfig removed = removeEntry(policies, policy);
if (removed != null) {
fs.updateDateStamp();
fs.setPolicies(policies);
m_pendingForeignSourceRepository.save(fs);
return Response.accepted().build();
}
return Response.notModified().build();
} finally {
writeUnlock();
}
}
use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSource in project opennms by OpenNMS.
the class ForeignSourceRestService method updateForeignSource.
/**
* <p>updateForeignSource</p>
*
* @param foreignSource 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
@Path("{foreignSource}")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Transactional
public Response updateForeignSource(@Context final UriInfo uriInfo, @PathParam("foreignSource") String foreignSource, MultivaluedMapImpl params) {
writeLock();
try {
ForeignSource fs = getActiveForeignSource(foreignSource);
LOG.debug("updateForeignSource: updating foreign source {}", foreignSource);
if (params.isEmpty())
return Response.notModified().build();
boolean modified = false;
final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(fs);
wrapper.registerCustomEditor(Duration.class, new StringIntervalPropertyEditor());
for (final String key : params.keySet()) {
if (wrapper.isWritableProperty(key)) {
Object value = null;
String stringValue = params.getFirst(key);
value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
wrapper.setPropertyValue(key, value);
modified = true;
}
}
if (modified) {
LOG.debug("updateForeignSource: foreign source {} updated", foreignSource);
fs.updateDateStamp();
m_pendingForeignSourceRepository.save(fs);
return Response.accepted().header("Location", getRedirectUri(uriInfo)).build();
} else {
return Response.notModified().build();
}
} finally {
writeUnlock();
}
}
Aggregations