Search in sources :

Example 1 with KeyValueParameter

use of org.candlepin.resteasy.parameter.KeyValueParameter in project candlepin by candlepin.

the class ConsumerCurator method searchOwnerConsumers.

@SuppressWarnings("checkstyle:indentation")
public CandlepinQuery<Consumer> searchOwnerConsumers(Owner owner, String userName, Collection<ConsumerType> types, List<String> uuids, List<String> hypervisorIds, List<KeyValueParameter> factFilters, List<String> skus, List<String> subscriptionIds, List<String> contracts) {
    DetachedCriteria crit = super.createSecureDetachedCriteria();
    if (owner != null) {
        crit.add(Restrictions.eq("ownerId", owner.getId()));
    }
    if (userName != null && !userName.isEmpty()) {
        crit.add(Restrictions.eq("username", userName));
    }
    if (types != null && !types.isEmpty()) {
        Collection<String> typeIds = types.stream().filter(t -> t.getId() != null).map(t -> t.getId()).collect(Collectors.toList());
        crit.add(CPRestrictions.in("typeId", typeIds));
    }
    if (uuids != null && !uuids.isEmpty()) {
        crit.add(CPRestrictions.in("uuid", uuids));
    }
    if (hypervisorIds != null && !hypervisorIds.isEmpty()) {
        // Cannot use Restrictions.in here because hypervisorId is case insensitive
        Set<Criterion> ors = new HashSet<>();
        for (String hypervisorId : hypervisorIds) {
            ors.add(Restrictions.eq("hvsr.hypervisorId", hypervisorId.toLowerCase()));
        }
        crit.createAlias("hypervisorId", "hvsr");
        crit.add(Restrictions.or(ors.toArray(new Criterion[ors.size()])));
    }
    if (factFilters != null && !factFilters.isEmpty()) {
        // Process the filters passed for the attributes
        FilterBuilder factFilter = new FactFilterBuilder();
        for (KeyValueParameter filterParam : factFilters) {
            factFilter.addAttributeFilter(filterParam.key(), filterParam.value());
        }
        factFilter.applyTo(crit);
    }
    boolean hasSkus = (skus != null && !skus.isEmpty());
    boolean hasSubscriptionIds = (subscriptionIds != null && !subscriptionIds.isEmpty());
    boolean hasContractNumbers = (contracts != null && !contracts.isEmpty());
    if (hasSkus || hasSubscriptionIds || hasContractNumbers) {
        if (hasSkus) {
            for (String sku : skus) {
                DetachedCriteria subCrit = DetachedCriteria.forClass(Consumer.class, "subquery_consumer");
                if (owner != null) {
                    subCrit.add(Restrictions.eq("ownerId", owner.getId()));
                }
                subCrit.createCriteria("entitlements").createCriteria("pool").createCriteria("product").createAlias("attributes", "attrib").add(Restrictions.eq("id", sku)).add(Restrictions.eq("attrib.indices", "type")).add(Restrictions.eq("attrib.elements", "MKT"));
                subCrit.add(Restrictions.eqProperty("this.id", "subquery_consumer.id"));
                crit.add(Subqueries.exists(subCrit.setProjection(Projections.property("subquery_consumer.name"))));
            }
        }
        if (hasSubscriptionIds) {
            for (String subId : subscriptionIds) {
                DetachedCriteria subCrit = DetachedCriteria.forClass(Consumer.class, "subquery_consumer");
                if (owner != null) {
                    subCrit.add(Restrictions.eq("ownerId", owner.getId()));
                }
                subCrit.createCriteria("entitlements").createCriteria("pool").createCriteria("sourceSubscription").add(Restrictions.eq("subscriptionId", subId));
                subCrit.add(Restrictions.eqProperty("this.id", "subquery_consumer.id"));
                crit.add(Subqueries.exists(subCrit.setProjection(Projections.property("subquery_consumer.name"))));
            }
        }
        if (hasContractNumbers) {
            for (String contract : contracts) {
                DetachedCriteria subCrit = DetachedCriteria.forClass(Consumer.class, "subquery_consumer");
                if (owner != null) {
                    subCrit.add(Restrictions.eq("ownerId", owner.getId()));
                }
                subCrit.createCriteria("entitlements").createCriteria("pool").add(Restrictions.eq("contractNumber", contract));
                subCrit.add(Restrictions.eqProperty("this.id", "subquery_consumer.id"));
                crit.add(Subqueries.exists(subCrit.setProjection(Projections.property("subquery_consumer.name"))));
            }
        }
    }
    return this.cpQueryFactory.<Consumer>buildQuery(this.currentSession(), crit);
}
Also used : Iterables(com.google.common.collect.Iterables) Criteria(org.hibernate.Criteria) Restrictions(org.hibernate.criterion.Restrictions) KeyValueParameter(org.candlepin.resteasy.parameter.KeyValueParameter) Date(java.util.Date) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) TypedQuery(javax.persistence.TypedQuery) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Order(org.hibernate.criterion.Order) CollectionUtils(org.apache.commons.collections.CollectionUtils) BadRequestException(org.candlepin.common.exceptions.BadRequestException) Map(java.util.Map) Query(org.hibernate.Query) LinkedList(java.util.LinkedList) Configuration(org.candlepin.common.config.Configuration) NotFoundException(org.candlepin.common.exceptions.NotFoundException) Criterion(org.hibernate.criterion.Criterion) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) FactValidator(org.candlepin.util.FactValidator) Projections(org.hibernate.criterion.Projections) Collectors(java.util.stream.Collectors) Disjunction(org.hibernate.criterion.Disjunction) Property(org.hibernate.criterion.Property) List(java.util.List) DetachedCriteria(org.hibernate.criterion.DetachedCriteria) FetchMode(org.hibernate.FetchMode) Entry(java.util.Map.Entry) LockModeType(javax.persistence.LockModeType) ReplicationMode(org.hibernate.ReplicationMode) Collections(java.util.Collections) Hibernate(org.hibernate.Hibernate) Subqueries(org.hibernate.criterion.Subqueries) Util(org.candlepin.util.Util) Criterion(org.hibernate.criterion.Criterion) DetachedCriteria(org.hibernate.criterion.DetachedCriteria) KeyValueParameter(org.candlepin.resteasy.parameter.KeyValueParameter) HashSet(java.util.HashSet)

Example 2 with KeyValueParameter

use of org.candlepin.resteasy.parameter.KeyValueParameter in project candlepin by candlepin.

the class OwnerResource method listPools.

/**
 * Retrieves a list of Pools for an Owner
 *
 * @param ownerKey id of the owner whose entitlement pools are sought.
 * @param matches Find pools matching the given pattern in a variety of fields.
 * * and ? wildcards are supported.
 * @return a list of Pool objects
 * @httpcode 400
 * @httpcode 404
 * @httpcode 200
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{owner_key}/pools")
@SuppressWarnings("checkstyle:indentation")
@ApiOperation(notes = "Retrieves a list of Pools for an Owner", value = "List Pools")
@ApiResponses({ @ApiResponse(code = 404, message = "Owner not found"), @ApiResponse(code = 400, message = "Invalid request") })
public List<PoolDTO> listPools(@PathParam("owner_key") @Verify(value = Owner.class, subResource = SubResource.POOLS) String ownerKey, @QueryParam("consumer") String consumerUuid, @QueryParam("activation_key") String activationKeyName, @QueryParam("product") String productId, @QueryParam("subscription") String subscriptionId, @ApiParam("Include pools that are not suited to the unit's facts.") @QueryParam("listall") @DefaultValue("false") boolean listAll, @ApiParam("Date to use as current time for lookup criteria. Defaults" + " to current date if not specified.") @QueryParam("activeon") @DefaultValue(DateFormat.NOW) @DateFormat Date activeOn, @ApiParam("Find pools matching the given pattern in a variety of fields;" + " * and ? wildcards are supported; may be specified multiple times") @QueryParam("matches") List<String> matches, @ApiParam("The attributes to return based on the specified types.") @QueryParam("attribute") @CandlepinParam(type = KeyValueParameter.class) List<KeyValueParameter> attrFilters, @ApiParam("When set to true, it will add future dated pools to the result, " + "based on the activeon date.") @QueryParam("add_future") @DefaultValue("false") boolean addFuture, @ApiParam("When set to true, it will return only future dated pools to the result, " + "based on the activeon date.") @QueryParam("only_future") @DefaultValue("false") boolean onlyFuture, @ApiParam("Will only return pools with a start date after the supplied date. " + "Overrides the activeOn date.") @QueryParam("after") @DateFormat Date after, @ApiParam("One or more pool IDs to use to filter the output; only pools with IDs matching " + "those provided will be returned; may be specified multiple times") @QueryParam("poolid") List<String> poolIds, @Context Principal principal, @Context PageRequest pageRequest) {
    Owner owner = findOwnerByKey(ownerKey);
    Consumer c = null;
    if (consumerUuid != null) {
        c = consumerCurator.findByUuid(consumerUuid);
        if (c == null) {
            throw new NotFoundException(i18n.tr("Unit: {0} not found", consumerUuid));
        }
        if (!c.getOwnerId().equals(owner.getId())) {
            throw new BadRequestException("Consumer specified does not belong to owner on path");
        }
        if (!principal.canAccess(c, SubResource.NONE, Access.READ_ONLY)) {
            throw new ForbiddenException(i18n.tr("User {0} cannot access consumer {1}", principal.getPrincipalName(), c.getUuid()));
        }
    }
    ActivationKey key = null;
    if (activationKeyName != null) {
        key = activationKeyCurator.lookupForOwner(activationKeyName, owner);
        if (key == null) {
            throw new BadRequestException(i18n.tr("ActivationKey with id {0} could not be found.", activationKeyName));
        }
    }
    if (addFuture && onlyFuture) {
        throw new BadRequestException(i18n.tr("The flags add_future and only_future cannot be used at the same time."));
    }
    if (after != null && (addFuture || onlyFuture)) {
        throw new BadRequestException(i18n.tr("The flags add_future and only_future cannot be used with the parameter after."));
    }
    if (after != null) {
        activeOn = null;
    }
    // Process the filters passed for the attributes
    PoolFilterBuilder poolFilters = new PoolFilterBuilder();
    for (KeyValueParameter filterParam : attrFilters) {
        poolFilters.addAttributeFilter(filterParam.key(), filterParam.value());
    }
    if (matches != null) {
        matches.stream().filter(elem -> elem != null && !elem.isEmpty()).forEach(elem -> poolFilters.addMatchesFilter(elem));
    }
    if (poolIds != null && !poolIds.isEmpty()) {
        poolFilters.addIdFilters(poolIds);
    }
    Page<List<Pool>> page = poolManager.listAvailableEntitlementPools(c, key, owner.getId(), productId, subscriptionId, activeOn, listAll, poolFilters, pageRequest, addFuture, onlyFuture, after);
    List<Pool> poolList = page.getPageData();
    calculatedAttributesUtil.setCalculatedAttributes(poolList, activeOn);
    calculatedAttributesUtil.setQuantityAttributes(poolList, c, activeOn);
    // Store the page for the LinkHeaderResponseFilter
    ResteasyProviderFactory.pushContext(Page.class, page);
    List<PoolDTO> poolDTOs = new ArrayList<>();
    for (Pool pool : poolList) {
        poolDTOs.add(translator.translate(pool, PoolDTO.class));
    }
    return poolDTOs;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Arrays(java.util.Arrays) Produces(javax.ws.rs.Produces) ApiParam(io.swagger.annotations.ApiParam) CalculatedAttributesUtil(org.candlepin.resource.util.CalculatedAttributesUtil) EventSink(org.candlepin.audit.EventSink) MediaType(javax.ws.rs.core.MediaType) ImportRecordCurator(org.candlepin.model.ImportRecordCurator) PageRequest(org.candlepin.common.paging.PageRequest) ImporterException(org.candlepin.sync.ImporterException) ExporterMetadataCurator(org.candlepin.model.ExporterMetadataCurator) ActivationKeyCurator(org.candlepin.model.activationkeys.ActivationKeyCurator) ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) DateFormat(org.candlepin.resteasy.DateFormat) HealEntireOrgJob(org.candlepin.pinsetter.tasks.HealEntireOrgJob) EventCurator(org.candlepin.model.EventCurator) Feed(org.jboss.resteasy.plugins.providers.atom.Feed) ActivationKeyDTO(org.candlepin.dto.api.v1.ActivationKeyDTO) SyncDataFormatException(org.candlepin.sync.SyncDataFormatException) ResourceMovedException(org.candlepin.common.exceptions.ResourceMovedException) UeberCertificateCurator(org.candlepin.model.UeberCertificateCurator) Set(java.util.Set) PoolManager(org.candlepin.controller.PoolManager) Access(org.candlepin.auth.Access) IseException(org.candlepin.common.exceptions.IseException) Type(org.candlepin.audit.Event.Type) OwnerServiceAdapter(org.candlepin.service.OwnerServiceAdapter) PoolDTO(org.candlepin.dto.api.v1.PoolDTO) Util(org.candlepin.util.Util) I18n(org.xnap.commons.i18n.I18n) Event(org.candlepin.audit.Event) Subscription(org.candlepin.model.dto.Subscription) GET(javax.ws.rs.GET) RefreshPoolsJob(org.candlepin.pinsetter.tasks.RefreshPoolsJob) KeyValueParameter(org.candlepin.resteasy.parameter.KeyValueParameter) ContentAccessCertServiceAdapter(org.candlepin.service.ContentAccessCertServiceAdapter) EventDTO(org.candlepin.dto.api.v1.EventDTO) ArrayList(java.util.ArrayList) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) Target(org.candlepin.audit.Event.Target) Entitlement(org.candlepin.model.Entitlement) StringTokenizer(java.util.StringTokenizer) Branding(org.candlepin.model.Branding) Api(io.swagger.annotations.Api) UpstreamConsumerDTO(org.candlepin.dto.api.v1.UpstreamConsumerDTO) UeberCertificateGenerator(org.candlepin.model.UeberCertificateGenerator) CandlepinException(org.candlepin.common.exceptions.CandlepinException) OwnerInfo(org.candlepin.model.OwnerInfo) ModelTranslator(org.candlepin.dto.ModelTranslator) ExporterMetadata(org.candlepin.model.ExporterMetadata) ServiceLevelValidator(org.candlepin.util.ServiceLevelValidator) Wrapped(org.jboss.resteasy.annotations.providers.jaxb.Wrapped) IOException(java.io.IOException) CandlepinQuery(org.candlepin.model.CandlepinQuery) File(java.io.File) EntitlementCurator(org.candlepin.model.EntitlementCurator) UndoImportsJob(org.candlepin.pinsetter.tasks.UndoImportsJob) CandlepinParam(org.candlepin.resteasy.parameter.CandlepinParam) ApiResponse(io.swagger.annotations.ApiResponse) ImportRecord(org.candlepin.model.ImportRecord) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) EnvironmentDTO(org.candlepin.dto.api.v1.EnvironmentDTO) Date(java.util.Date) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) MultipartInput(org.jboss.resteasy.plugins.providers.multipart.MultipartInput) EntitlementFinderUtil(org.candlepin.resource.util.EntitlementFinderUtil) EntitlementFilterBuilder(org.candlepin.model.EntitlementFilterBuilder) ConflictOverrides(org.candlepin.sync.ConflictOverrides) ActivationKeyContentOverride(org.candlepin.model.activationkeys.ActivationKeyContentOverride) Transactional(com.google.inject.persist.Transactional) OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) ConflictException(org.candlepin.common.exceptions.ConflictException) ApiOperation(io.swagger.annotations.ApiOperation) InputPart(org.jboss.resteasy.plugins.providers.multipart.InputPart) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) ConsumerTypeCurator(org.candlepin.model.ConsumerTypeCurator) DefaultValue(javax.ws.rs.DefaultValue) ContentOverrideValidator(org.candlepin.util.ContentOverrideValidator) Product(org.candlepin.model.Product) DELETE(javax.ws.rs.DELETE) NotFoundException(org.candlepin.common.exceptions.NotFoundException) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Context(javax.ws.rs.core.Context) OwnerManager(org.candlepin.controller.OwnerManager) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) EventAdapter(org.candlepin.audit.EventAdapter) GenericType(org.jboss.resteasy.util.GenericType) Page(org.candlepin.common.paging.Page) OwnerCurator(org.candlepin.model.OwnerCurator) EntitlementDTO(org.candlepin.dto.api.v1.EntitlementDTO) OwnerProductCurator(org.candlepin.model.OwnerProductCurator) ManifestFileServiceException(org.candlepin.sync.file.ManifestFileServiceException) ConsumerCurator(org.candlepin.model.ConsumerCurator) List(java.util.List) PersistenceException(javax.persistence.PersistenceException) ProductCurator(org.candlepin.model.ProductCurator) SourceSubscription(org.candlepin.model.SourceSubscription) PathParam(javax.ws.rs.PathParam) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) Release(org.candlepin.model.Release) Verify(org.candlepin.auth.Verify) ManifestManager(org.candlepin.controller.ManifestManager) ConsumerType(org.candlepin.model.ConsumerType) PoolFilterBuilder(org.candlepin.model.PoolFilterBuilder) ApiResponses(io.swagger.annotations.ApiResponses) ConfigProperties(org.candlepin.config.ConfigProperties) Pool(org.candlepin.model.Pool) UeberCertificate(org.candlepin.model.UeberCertificate) HashSet(java.util.HashSet) SubResource(org.candlepin.auth.SubResource) PoolType(org.candlepin.model.Pool.PoolType) Owner(org.candlepin.model.Owner) CollectionUtils(org.apache.commons.collections.CollectionUtils) BadRequestException(org.candlepin.common.exceptions.BadRequestException) BrandingDTO(org.candlepin.dto.api.v1.BrandingDTO) Environment(org.candlepin.model.Environment) Principal(org.candlepin.auth.Principal) LinkedList(java.util.LinkedList) Configuration(org.candlepin.common.config.Configuration) JobDetail(org.quartz.JobDetail) OwnerInfoCurator(org.candlepin.model.OwnerInfoCurator) ResolverUtil(org.candlepin.resource.util.ResolverUtil) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) EnvironmentCurator(org.candlepin.model.EnvironmentCurator) ConsumerTypeValidator(org.candlepin.resource.util.ConsumerTypeValidator) EventFactory(org.candlepin.audit.EventFactory) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) ImportJob(org.candlepin.pinsetter.tasks.ImportJob) Level(ch.qos.logback.classic.Level) EntitlementCertificateCurator(org.candlepin.model.EntitlementCertificateCurator) PUT(javax.ws.rs.PUT) Consumer(org.candlepin.model.Consumer) Authorization(io.swagger.annotations.Authorization) Collections(java.util.Collections) ArrayUtils(org.apache.commons.lang.ArrayUtils) Owner(org.candlepin.model.Owner) ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) ArrayList(java.util.ArrayList) NotFoundException(org.candlepin.common.exceptions.NotFoundException) PoolDTO(org.candlepin.dto.api.v1.PoolDTO) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Consumer(org.candlepin.model.Consumer) BadRequestException(org.candlepin.common.exceptions.BadRequestException) PoolFilterBuilder(org.candlepin.model.PoolFilterBuilder) KeyValueParameter(org.candlepin.resteasy.parameter.KeyValueParameter) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Pool(org.candlepin.model.Pool) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with KeyValueParameter

use of org.candlepin.resteasy.parameter.KeyValueParameter in project candlepin by candlepin.

the class ConsumerResourceTest method testAsyncExport.

@Test
public void testAsyncExport() {
    CdnCurator mockCdnCurator = mock(CdnCurator.class);
    ManifestManager manifestManager = mock(ManifestManager.class);
    ConsumerResource cr = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, null, null, null, i18n, null, null, null, null, null, null, null, mockOwnerCurator, null, null, null, null, null, null, this.config, null, mockCdnCurator, null, null, manifestManager, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
    List<KeyValueParameter> extParams = new ArrayList<>();
    Owner owner = this.createOwner();
    owner.setId(TestUtil.randomString());
    when(mockOwnerCurator.findOwnerById(eq(owner.getId()))).thenReturn(owner);
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerType.ConsumerTypeEnum.CANDLEPIN));
    Consumer consumer = this.createConsumer(owner, ctype);
    Cdn cdn = new Cdn("cdn-label", "test", "url");
    when(mockCdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(cdn);
    cr.exportDataAsync(null, consumer.getUuid(), cdn.getLabel(), "prefix", cdn.getUrl(), extParams);
    verify(manifestManager).generateManifestAsync(eq(consumer.getUuid()), eq(owner.getKey()), eq(cdn.getLabel()), eq("prefix"), eq(cdn.getUrl()), any(Map.class));
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ArrayList(java.util.ArrayList) KeyValueParameter(org.candlepin.resteasy.parameter.KeyValueParameter) CdnCurator(org.candlepin.model.CdnCurator) ManifestManager(org.candlepin.controller.ManifestManager) ConsumerType(org.candlepin.model.ConsumerType) Cdn(org.candlepin.model.Cdn) Map(java.util.Map) Test(org.junit.Test)

Example 4 with KeyValueParameter

use of org.candlepin.resteasy.parameter.KeyValueParameter in project candlepin by candlepin.

the class OwnerResourceTest method createKeyValueParam.

@QueryParam("test-attr")
@CandlepinParam(type = KeyValueParameter.class)
private KeyValueParameter createKeyValueParam(String key, String val) throws Exception {
    // Can't create the KeyValueParam directly as the parse method
    // is package protected -- create one via the unmarshaller so we don't have to
    // change the visibility of the parse method.
    Annotation[] annotations = this.getClass().getDeclaredMethod("createKeyValueParam", String.class, String.class).getAnnotations();
    CandlepinParameterUnmarshaller unmarshaller = new CandlepinParameterUnmarshaller();
    unmarshaller.setAnnotations(annotations);
    return (KeyValueParameter) unmarshaller.fromString(key + ":" + val);
}
Also used : KeyValueParameter(org.candlepin.resteasy.parameter.KeyValueParameter) CandlepinParameterUnmarshaller(org.candlepin.resteasy.parameter.CandlepinParameterUnmarshaller) Matchers.anyString(org.mockito.Matchers.anyString) Annotation(java.lang.annotation.Annotation) QueryParam(javax.ws.rs.QueryParam) CandlepinParam(org.candlepin.resteasy.parameter.CandlepinParam)

Example 5 with KeyValueParameter

use of org.candlepin.resteasy.parameter.KeyValueParameter in project candlepin by candlepin.

the class OwnerResourceTest method testCanFilterOutDevPoolsByAttribute.

@Test
public void testCanFilterOutDevPoolsByAttribute() throws Exception {
    Principal principal = setupPrincipal(owner, Access.ALL);
    Product p = this.createProduct(owner);
    Pool pool1 = TestUtil.createPool(owner, p);
    pool1.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
    poolCurator.create(pool1);
    Product p2 = this.createProduct(owner);
    Pool pool2 = TestUtil.createPool(owner, p2);
    poolCurator.create(pool2);
    List<KeyValueParameter> params = new ArrayList<>();
    List<PoolDTO> pools = ownerResource.listPools(owner.getKey(), null, null, null, null, true, null, null, params, false, false, null, null, principal, null);
    assertEquals(2, pools.size());
    params = new ArrayList<>();
    params.add(createKeyValueParam(Pool.Attributes.DEVELOPMENT_POOL, "!true"));
    pools = ownerResource.listPools(owner.getKey(), null, null, null, null, true, null, null, params, false, false, null, null, principal, null);
    assertEquals(1, pools.size());
    assertModelEqualsDTO(pool2, pools.get(0));
}
Also used : ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) KeyValueParameter(org.candlepin.resteasy.parameter.KeyValueParameter) PoolDTO(org.candlepin.dto.api.v1.PoolDTO) Pool(org.candlepin.model.Pool) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Aggregations

KeyValueParameter (org.candlepin.resteasy.parameter.KeyValueParameter)6 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)3 Inject (com.google.inject.Inject)2 Transactional (com.google.inject.persist.Transactional)2 Collections (java.util.Collections)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 CollectionUtils (org.apache.commons.collections.CollectionUtils)2 ConsumerPrincipal (org.candlepin.auth.ConsumerPrincipal)2 Principal (org.candlepin.auth.Principal)2 UserPrincipal (org.candlepin.auth.UserPrincipal)2 Configuration (org.candlepin.common.config.Configuration)2 BadRequestException (org.candlepin.common.exceptions.BadRequestException)2 NotFoundException (org.candlepin.common.exceptions.NotFoundException)2 PoolDTO (org.candlepin.dto.api.v1.PoolDTO)2