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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations