Search in sources :

Example 46 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project nhin-d by DirectProject.

the class AddressResource method addAddress.

/**
     * Adds an address to the system and associates it with a domain.
     * @param uriInfo Injected URI context used for building the location URI.
     * @param address The address to add.
     * @return Returns status 201 if added successfully, 404 if the domain does not exist, or 409 if
     * the address already exists.
     */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
public Response addAddress(@Context UriInfo uriInfo, Address address) {
    // make sure the domain exists
    if (address.getDomainName() == null || address.getDomainName().isEmpty())
        return Response.status(Status.BAD_REQUEST).cacheControl(noCache).build();
    org.nhindirect.config.store.Domain domain;
    try {
        domain = domainDao.getDomainByName(address.getDomainName());
        if (domain == null)
            return Response.status(Status.NOT_FOUND).cacheControl(noCache).build();
    } catch (Exception e) {
        log.error("Error looking up existing domain.", e);
        return Response.serverError().cacheControl(noCache).build();
    }
    // check to see if it already exists
    try {
        if (dao.get(address.getEmailAddress()) != null)
            return Response.status(Status.CONFLICT).cacheControl(noCache).build();
    } catch (Exception e) {
        log.error("Error looking up existing address.", e);
        return Response.serverError().cacheControl(noCache).build();
    }
    final org.nhindirect.config.store.Address toAdd = EntityModelConversion.toEntityAddress(address);
    toAdd.setDomain(domain);
    try {
        dao.add(toAdd);
        final UriBuilder newLocBuilder = uriInfo.getBaseUriBuilder();
        final URI newLoc = newLocBuilder.path("address/" + address.getEmailAddress()).build();
        return Response.created(newLoc).cacheControl(noCache).build();
    } catch (Exception e) {
        log.error("Error adding address.", 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 47 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project nhin-d by DirectProject.

the class AnchorResource method addAnchor.

/**
     * Adds an anchor to the system.
     * @param uriInfo Injected URI context used for building the location URI.
     * @param anchor The anchor to add to the system.
     * @return Returns a status of 201 if the anchor was added, or a status of 409 if the anchor already exists for 
     * a specific owner.
     */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
public Response addAnchor(@Context UriInfo uriInfo, Anchor anchor) {
    // check to see if it already exists
    try {
        final String thumbprint = (anchor.getThumbprint() == null || anchor.getThumbprint().isEmpty()) ? Thumbprint.toThumbprint(anchor.getAnchorAsX509Certificate()).toString() : anchor.getThumbprint();
        final Collection<org.nhindirect.config.store.Anchor> existingAnchors = anchorDao.list(Arrays.asList(anchor.getOwner()));
        for (org.nhindirect.config.store.Anchor existingAnchor : existingAnchors) {
            if (existingAnchor.getThumbprint().equalsIgnoreCase(thumbprint))
                return Response.status(Status.CONFLICT).cacheControl(noCache).build();
        }
    } catch (Exception e) {
        log.error("Error looking up existing anchor.", e);
        return Response.serverError().cacheControl(noCache).build();
    }
    try {
        anchorDao.add(EntityModelConversion.toEntityAnchor(anchor));
        final UriBuilder newLocBuilder = uriInfo.getBaseUriBuilder();
        final URI newLoc = newLocBuilder.path("anchor/" + anchor.getOwner()).build();
        return Response.created(newLoc).cacheControl(noCache).build();
    } catch (Exception e) {
        log.error("Error adding anchor.", e);
        return Response.serverError().cacheControl(noCache).build();
    }
}
Also used : Anchor(org.nhindirect.config.model.Anchor) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 48 with UriBuilder

use of javax.ws.rs.core.UriBuilder 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 49 with UriBuilder

use of javax.ws.rs.core.UriBuilder 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 50 with UriBuilder

use of javax.ws.rs.core.UriBuilder 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)

Aggregations

UriBuilder (javax.ws.rs.core.UriBuilder)167 URI (java.net.URI)78 Test (org.junit.Test)58 HashMap (java.util.HashMap)21 Consumes (javax.ws.rs.Consumes)15 Link (org.eclipse.che.api.core.rest.shared.dto.Link)15 IOException (java.io.IOException)12 Path (javax.ws.rs.Path)12 PUT (javax.ws.rs.PUT)11 Produces (javax.ws.rs.Produces)9 URL (java.net.URL)8 ArrayList (java.util.ArrayList)8 GET (javax.ws.rs.GET)8 LinksHelper.createLink (org.eclipse.che.api.core.util.LinksHelper.createLink)8 Timed (com.codahale.metrics.annotation.Timed)7 POST (javax.ws.rs.POST)7 Map (java.util.Map)6 Response (javax.ws.rs.core.Response)6 ServerException (org.eclipse.che.api.core.ServerException)6 List (java.util.List)5