Search in sources :

Example 41 with PUT

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();
    }
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 42 with PUT

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();
    }
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 43 with PUT

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();
    }
}
Also used : Setting(org.nhindirect.config.model.Setting) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 44 with PUT

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();
}
Also used : ChildEdgeRequestDTO(org.opennms.web.rest.v2.bsm.model.edge.ChildEdgeRequestDTO) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) IpServiceEdgeRequestDTO(org.opennms.web.rest.v2.bsm.model.edge.IpServiceEdgeRequestDTO) EdgeRequestDTOVisitor(org.opennms.web.rest.v2.bsm.model.edge.EdgeRequestDTOVisitor) ReductionKeyEdgeRequestDTO(org.opennms.web.rest.v2.bsm.model.edge.ReductionKeyEdgeRequestDTO) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 45 with PUT

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();
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) OnmsUser(org.opennms.netmgt.model.OnmsUser) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Aggregations

PUT (javax.ws.rs.PUT)203 Path (javax.ws.rs.Path)172 Consumes (javax.ws.rs.Consumes)108 Produces (javax.ws.rs.Produces)72 ApiOperation (io.swagger.annotations.ApiOperation)70 ApiResponses (io.swagger.annotations.ApiResponses)53 Timed (com.codahale.metrics.annotation.Timed)36 AuditEvent (org.graylog2.audit.jersey.AuditEvent)36 URI (java.net.URI)24 Response (javax.ws.rs.core.Response)23 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)19 IOException (java.io.IOException)18 BeanWrapper (org.springframework.beans.BeanWrapper)16 BadRequestException (javax.ws.rs.BadRequestException)14 NotFoundException (javax.ws.rs.NotFoundException)14 WebApplicationException (javax.ws.rs.WebApplicationException)12 UriBuilder (javax.ws.rs.core.UriBuilder)12 UUID (java.util.UUID)11 GET (javax.ws.rs.GET)11 POST (javax.ws.rs.POST)11