use of org.candlepin.common.exceptions.BadRequestException in project candlepin by candlepin.
the class ContentOverrideValidatorTest method testValidateCollectionBothInvalid.
@Test
public void testValidateCollectionBothInvalid() {
when(config.getBoolean(eq(ConfigProperties.STANDALONE))).thenReturn(false);
List<ContentOverride> overrides = new LinkedList<>();
overrides.add(new ContentOverride("label", "baseurl", "value"));
overrides.add(new ContentOverride("other label", "name", "other value"));
try {
validator.validate(overrides);
fail("Expected exception \"BadRequestException\" was not thrown.");
} catch (BadRequestException bre) {
assertTrue(bre.getMessage().matches("^Not allowed to override values for: (?:baseurl, name|name, baseurl)"));
}
}
use of org.candlepin.common.exceptions.BadRequestException in project candlepin by candlepin.
the class EntitlementCurator method listFilteredPages.
private Page<List<Entitlement>> listFilteredPages(AbstractHibernateObject object, String objectType, String productId, EntitlementFilterBuilder filters, PageRequest pageRequest) {
Page<List<Entitlement>> entitlementsPage;
String ownerId = null;
if (object != null) {
ownerId = (object instanceof Owner) ? ((Owner) object).getId() : ((Consumer) object).getOwnerId();
}
// No need to add filters when matching by product.
if (object != null && productId != null) {
Product p = this.ownerProductCurator.getProductById(ownerId, productId);
if (p == null) {
throw new BadRequestException(i18n.tr("Product with ID \"{0}\" could not be found.", productId));
}
entitlementsPage = listByProduct(object, objectType, productId, pageRequest);
} else {
// Build up any provided entitlement filters from query params.
Criteria criteria = this.createCriteriaFromFilters(filters);
if (object != null) {
criteria.add(Restrictions.eq(objectType, object));
}
List<String> entitlementIds = criteria.list();
if (entitlementIds != null && !entitlementIds.isEmpty()) {
criteria = this.currentSession().createCriteria(Entitlement.class).add(CPRestrictions.in("id", entitlementIds));
entitlementsPage = listByCriteria(criteria, pageRequest);
} else {
entitlementsPage = new Page<>();
entitlementsPage.setPageData(Collections.<Entitlement>emptyList());
entitlementsPage.setMaxRecords(0);
}
}
return entitlementsPage;
}
use of org.candlepin.common.exceptions.BadRequestException in project candlepin by candlepin.
the class PageRequestFilter method filter.
@Override
public void filter(ContainerRequestContext requestContext) {
PageRequest p = null;
MultivaluedMap<String, String> params = requestContext.getUriInfo().getQueryParameters();
String page = params.getFirst(PageRequest.PAGE_PARAM);
String perPage = params.getFirst(PageRequest.PER_PAGE_PARAM);
String order = params.getFirst(PageRequest.ORDER_PARAM);
String sortBy = params.getFirst(PageRequest.SORT_BY_PARAM);
if (page != null || perPage != null || order != null || sortBy != null) {
p = new PageRequest();
if (order == null) {
p.setOrder(PageRequest.DEFAULT_ORDER);
} else {
p.setOrder(readOrder(order));
}
/* We'll leave it to the curator layer to figure out what to sort by if
* sortBy is null. */
p.setSortBy(sortBy);
try {
if (page == null && perPage != null) {
p.setPage(PageRequest.DEFAULT_PAGE);
p.setPerPage(readInteger(perPage));
} else if (page != null && perPage == null) {
p.setPage(readInteger(page));
p.setPerPage(PageRequest.DEFAULT_PER_PAGE);
} else {
p.setPage(readInteger(page));
p.setPerPage(readInteger(perPage));
}
} catch (NumberFormatException nfe) {
I18n i18n = this.i18nProvider.get();
throw new BadRequestException(i18n.tr("offset and limit parameters" + " must be positive integers"), nfe);
}
}
ResteasyProviderFactory.pushContext(PageRequest.class, p);
}
use of org.candlepin.common.exceptions.BadRequestException in project candlepin by candlepin.
the class UeberCertificateGenerator method generate.
@Transactional
public UeberCertificate generate(String ownerKey, Principal principal) {
Owner owner = this.ownerCurator.lookupByKey(ownerKey);
if (owner == null) {
throw new NotFoundException(i18n.tr("Unable to find an owner with key: {0}", ownerKey));
}
this.ownerCurator.lock(owner);
try {
// There can only be one ueber certificate per owner, so delete the existing and regenerate it.
this.ueberCertCurator.deleteForOwner(owner);
return this.generateUeberCert(owner, principal.getUsername());
} catch (Exception e) {
log.error("Problem generating ueber cert for owner: {}", ownerKey, e);
throw new BadRequestException(i18n.tr("Problem generating ueber cert for owner {0}", ownerKey), e);
}
}
use of org.candlepin.common.exceptions.BadRequestException in project candlepin by candlepin.
the class HypervisorResourceTest method ensureFailureWhenAutobindIsDisabledOnOwner.
@Test
public void ensureFailureWhenAutobindIsDisabledOnOwner() {
Owner owner = new Owner("test_admin");
owner.setAutobindDisabled(true);
Map<String, List<GuestIdDTO>> hostGuestMap = new HashMap<>();
hostGuestMap.put("HYPERVISOR_A", new ArrayList());
when(ownerCurator.lookupByKey(eq(owner.getKey()))).thenReturn(owner);
try {
hypervisorResource.hypervisorUpdate(hostGuestMap, principal, owner.getKey(), true);
fail("Exception should have been thrown since autobind was disabled for the owner.");
} catch (BadRequestException bre) {
assertEquals("Could not update host/guest mapping. Auto-attach is disabled for owner test_admin.", bre.getMessage());
}
}
Aggregations