use of javax.ws.rs.PUT in project nhin-d by DirectProject.
the class CertPolicyResource method addPolicy.
/**
* Adds a certificate policy to the system.
* @param uriInfo Injected URI context used for building the location URI.
* @param policy The certificate policy to add.
* @return A status of 201 if the policy was added or a status of 409 if the policy already exists.
*/
@PUT
@Consumes(MediaType.APPLICATION_JSON)
public Response addPolicy(@Context UriInfo uriInfo, CertPolicy policy) {
// make sure it doesn't exist
try {
if (policyDao.getPolicyByName(policy.getPolicyName()) != null)
return Response.status(Status.CONFLICT).cacheControl(noCache).build();
} catch (Exception e) {
log.error("Error looking up cert policy.", e);
return Response.serverError().cacheControl(noCache).build();
}
try {
final org.nhindirect.config.store.CertPolicy entityPolicy = EntityModelConversion.toEntityCertPolicy(policy);
policyDao.addPolicy(entityPolicy);
final UriBuilder newLocBuilder = uriInfo.getBaseUriBuilder();
final URI newLoc = newLocBuilder.path("certpolicy/" + policy.getPolicyName()).build();
return Response.created(newLoc).cacheControl(noCache).build();
} catch (Exception e) {
log.error("Error adding trust cert policy.", e);
return Response.serverError().cacheControl(noCache).build();
}
}
use of javax.ws.rs.PUT in project nhin-d by DirectProject.
the class CertPolicyResource method addPolicyGroup.
/**
* Adds a policy group to the system.
* @param uriInfo Injected URI context used for building the location URI.
* @param group The policy group to add.
* @return Status of 201 if the policy group was added or a status of 409 if the policy group
* already exists.
*/
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Path("groups")
public Response addPolicyGroup(@Context UriInfo uriInfo, CertPolicyGroup group) {
// make sure it doesn't exist
try {
if (policyDao.getPolicyGroupByName(group.getPolicyGroupName()) != null)
return Response.status(Status.CONFLICT).cacheControl(noCache).build();
} catch (Exception e) {
log.error("Error looking up cert policy group.", e);
return Response.serverError().cacheControl(noCache).build();
}
try {
final org.nhindirect.config.store.CertPolicyGroup entityGroup = EntityModelConversion.toEntityCertPolicyGroup(group);
policyDao.addPolicyGroup(entityGroup);
final UriBuilder newLocBuilder = uriInfo.getBaseUriBuilder();
final URI newLoc = newLocBuilder.path("certpolicy/group+/" + group.getPolicyGroupName()).build();
return Response.created(newLoc).cacheControl(noCache).build();
} catch (Exception e) {
log.error("Error adding trust cert policy group.", e);
return Response.serverError().cacheControl(noCache).build();
}
}
use of javax.ws.rs.PUT in project nhin-d by DirectProject.
the class SettingResource method addSetting.
/**
* Adds a setting to the system.
* @param uriInfo Injected URI context used for building the location URI.
* @param name The name of the setting to add.
* @param value The value of the setting.
* @return Status of 201 if the setting was created or a status of 409 if a setting with the same name
* already exists.
*/
@PUT
@Path("{name}/{value}")
public Response addSetting(@Context UriInfo uriInfo, @PathParam("name") String name, @PathParam("value") String value) {
// check to see if it already exists
try {
final Collection<org.nhindirect.config.store.Setting> retSettings = settingDao.getByNames(Arrays.asList(name));
if (!retSettings.isEmpty())
return Response.status(Status.CONFLICT).cacheControl(noCache).build();
} catch (Exception e) {
log.error("Error looking up setting.", e);
return Response.serverError().cacheControl(noCache).build();
}
try {
settingDao.add(name, value);
final UriBuilder newLocBuilder = uriInfo.getBaseUriBuilder();
final URI newLoc = newLocBuilder.path("setting/" + name).build();
return Response.created(newLoc).cacheControl(noCache).build();
} catch (Exception e) {
log.error("Error adding setting.", e);
return Response.serverError().cacheControl(noCache).build();
}
}
use of javax.ws.rs.PUT in project opennms by OpenNMS.
the class BusinessServiceRestService method update.
@PUT
@Path("{id}")
public Response update(@PathParam("id") final Long id, final BusinessServiceRequestDTO request) {
final BusinessService service = getManager().getBusinessServiceById(id);
service.setName(request.getName());
service.setAttributes(request.getAttributes());
service.setReduceFunction(transform(request.getReduceFunction()));
service.setReductionKeyEdges(Sets.newHashSet());
service.setIpServiceEdges(Sets.newHashSet());
service.setChildEdges(Sets.newHashSet());
request.getEdges().forEach(eachEdge -> eachEdge.accept(new EdgeRequestDTOVisitor() {
@Override
public void visit(IpServiceEdgeRequestDTO ipEdge) {
getManager().addIpServiceEdge(service, getManager().getIpServiceById(ipEdge.getIpServiceId()), transform(ipEdge.getMapFunction()), ipEdge.getWeight(), ipEdge.getFriendlyName());
}
@Override
public void visit(ChildEdgeRequestDTO childEdge) {
getManager().addChildEdge(service, getManager().getBusinessServiceById(childEdge.getChildId()), transform(childEdge.getMapFunction()), childEdge.getWeight());
}
@Override
public void visit(ReductionKeyEdgeRequestDTO rkEdge) {
getManager().addReductionKeyEdge(service, rkEdge.getReductionKey(), transform(rkEdge.getMapFunction()), rkEdge.getWeight(), rkEdge.getFriendlyName());
}
}));
getManager().saveBusinessService(service);
return Response.noContent().build();
}
use of javax.ws.rs.PUT in project opennms by OpenNMS.
the class UserRestService method updateUser.
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("{userCriteria}")
public Response updateUser(@Context final SecurityContext securityContext, @PathParam("userCriteria") final String userCriteria, final MultivaluedMapImpl params) {
writeLock();
try {
if (!hasEditRights(securityContext)) {
throw getException(Status.BAD_REQUEST, "User {} does not have write access to users!", securityContext.getUserPrincipal().getName());
}
final OnmsUser user = getOnmsUser(userCriteria);
LOG.debug("updateUser: updating user {}", user);
boolean modified = false;
final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(user);
for (final String key : params.keySet()) {
if (wrapper.isWritableProperty(key)) {
final String stringValue = params.getFirst(key);
final Object value = wrapper.convertIfNecessary(stringValue, wrapper.getPropertyType(key));
wrapper.setPropertyValue(key, value);
modified = true;
}
}
if (modified) {
LOG.debug("updateUser: user {} updated", user);
try {
m_userManager.save(user);
} catch (final Throwable t) {
throw getException(Status.INTERNAL_SERVER_ERROR, t);
}
return Response.noContent().build();
}
return Response.notModified().build();
} finally {
writeUnlock();
}
}
Aggregations