Search in sources :

Example 1 with Wrapped

use of org.jboss.resteasy.annotations.providers.jaxb.Wrapped in project candlepin by candlepin.

the class ConsumerResource method list.

@ApiOperation(notes = "Retrieves a list of the Consumers", value = "list", response = Consumer.class, responseContainer = "list")
@ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 404, message = "") })
@GET
@Produces(MediaType.APPLICATION_JSON)
@Wrapped(element = "consumers")
@SuppressWarnings("checkstyle:indentation")
public CandlepinQuery<ConsumerDTO> list(@QueryParam("username") String userName, @QueryParam("type") Set<String> typeLabels, @QueryParam("owner") String ownerKey, @QueryParam("uuid") List<String> uuids, @QueryParam("hypervisor_id") List<String> hypervisorIds, @QueryParam("fact") @CandlepinParam(type = KeyValueParameter.class) List<KeyValueParameter> attrFilters, @Context PageRequest pageRequest) {
    if (userName == null && (typeLabels == null || typeLabels.isEmpty()) && ownerKey == null && (uuids == null || uuids.isEmpty()) && (hypervisorIds == null || hypervisorIds.isEmpty()) && (attrFilters == null || attrFilters.isEmpty())) {
        throw new BadRequestException(i18n.tr("Must specify at least one search criteria."));
    }
    Owner owner = null;
    if (ownerKey != null) {
        owner = ownerCurator.lookupByKey(ownerKey);
        if (owner == null) {
            throw new NotFoundException(i18n.tr("owner with key: {0} was not found.", ownerKey));
        }
    }
    List<ConsumerType> types = consumerTypeValidator.findAndValidateTypeLabels(typeLabels);
    CandlepinQuery<Consumer> query = this.consumerCurator.searchOwnerConsumers(owner, userName, types, uuids, hypervisorIds, attrFilters, Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList());
    return this.translator.translateQuery(query, ConsumerDTO.class);
}
Also used : Owner(org.candlepin.model.Owner) DeletedConsumer(org.candlepin.model.DeletedConsumer) Consumer(org.candlepin.model.Consumer) BadRequestException(org.candlepin.common.exceptions.BadRequestException) NotFoundException(org.candlepin.common.exceptions.NotFoundException) ConsumerType(org.candlepin.model.ConsumerType) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Wrapped(org.jboss.resteasy.annotations.providers.jaxb.Wrapped) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with Wrapped

use of org.jboss.resteasy.annotations.providers.jaxb.Wrapped in project candlepin by candlepin.

the class ConsumerResource method getEntitlementCertificateSerials.

@ApiOperation(notes = "Retrieves a list of Certiticate Serials Return the " + "client certificate metadata a for the given consumer. This is a small" + " subset of data clients can use to determine which certificates they" + " need to update/fetch.", value = "getEntitlementCertificateSerials")
@ApiResponses({ @ApiResponse(code = 404, message = "") })
@GET
@Path("{consumer_uuid}/certificates/serials")
@Produces(MediaType.APPLICATION_JSON)
@Wrapped(element = "serials")
@UpdateConsumerCheckIn
public List<CertificateSerialDto> getEntitlementCertificateSerials(@PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid) {
    log.debug("Getting client certificate serials for consumer: {}", consumerUuid);
    Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid);
    ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
    if (ctype.isType(ConsumerTypeEnum.SHARE)) {
        logShareConsumerRequestWarning("cert serial fetch", consumer);
        return new ArrayList<>();
    }
    revokeOnGuestMigration(consumer);
    poolManager.regenerateDirtyEntitlements(consumer);
    List<CertificateSerialDto> allCerts = new LinkedList<>();
    for (Long id : entCertService.listEntitlementSerialIds(consumer)) {
        allCerts.add(new CertificateSerialDto(id));
    }
    // add content access cert if needed
    try {
        ContentAccessCertificate cac = contentAccessCertService.getCertificate(consumer);
        if (cac != null) {
            allCerts.add(new CertificateSerialDto(cac.getSerial().getId()));
        }
    } catch (IOException ioe) {
        throw new BadRequestException(i18n.tr("Cannot retrieve content access certificate"), ioe);
    } catch (GeneralSecurityException gse) {
        throw new BadRequestException(i18n.tr("Cannot retrieve content access certificate", gse));
    }
    return allCerts;
}
Also used : DeletedConsumer(org.candlepin.model.DeletedConsumer) Consumer(org.candlepin.model.Consumer) CertificateSerialDto(org.candlepin.model.CertificateSerialDto) GeneralSecurityException(java.security.GeneralSecurityException) ArrayList(java.util.ArrayList) BadRequestException(org.candlepin.common.exceptions.BadRequestException) ContentAccessCertificate(org.candlepin.model.ContentAccessCertificate) IOException(java.io.IOException) ConsumerType(org.candlepin.model.ConsumerType) LinkedList(java.util.LinkedList) Path(javax.ws.rs.Path) UpdateConsumerCheckIn(org.candlepin.auth.UpdateConsumerCheckIn) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Wrapped(org.jboss.resteasy.annotations.providers.jaxb.Wrapped) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with Wrapped

use of org.jboss.resteasy.annotations.providers.jaxb.Wrapped in project candlepin by candlepin.

the class OwnerResource method listEnvironments.

/**
 * Retrieves a list of Environments for an Owner
 *
 * @param envName Optional environment name filter to search for.
 * @return a list of Environment objects
 * @httpcode 200
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{owner_key}/environments")
@Wrapped(element = "environments")
@ApiOperation(notes = "Retrieves a list of Environments for an Owner", value = "List environments")
@ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") })
public CandlepinQuery<EnvironmentDTO> listEnvironments(@PathParam("owner_key") @Verify(Owner.class) String ownerKey, @ApiParam("Environment name filter to search for.") @QueryParam("name") String envName) {
    Owner owner = findOwnerByKey(ownerKey);
    CandlepinQuery<Environment> query = envName == null ? envCurator.listForOwner(owner) : envCurator.listForOwnerByName(owner, envName);
    return translator.translateQuery(query, EnvironmentDTO.class);
}
Also used : Owner(org.candlepin.model.Owner) Environment(org.candlepin.model.Environment) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Wrapped(org.jboss.resteasy.annotations.providers.jaxb.Wrapped) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with Wrapped

use of org.jboss.resteasy.annotations.providers.jaxb.Wrapped in project candlepin by candlepin.

the class PoolResource method list.

/**
 * @deprecated Use the method on /owners
 * @return List of pools
 */
@ApiOperation(notes = "Retrieves a list of Pools @deprecated Use the method on /owners", value = "")
@ApiResponses({ @ApiResponse(code = 400, message = "if both consumer(unit) and owner are given, or if a" + " product id is specified without a consumer(unit) or owner"), @ApiResponse(code = 404, message = "if a specified consumer(unit) or owner is not found"), @ApiResponse(code = 403, message = "") })
@GET
@Produces(MediaType.APPLICATION_JSON)
@Wrapped(element = "pools")
@Deprecated
@SecurityHole
public List<PoolDTO> list(@QueryParam("owner") String ownerId, @QueryParam("consumer") String consumerUuid, @QueryParam("product") String productId, @ApiParam("Use with consumerUuid to list all pools available to the consumer. " + "This will include pools which would otherwise be omitted due to a rules" + " warning. (i.e. not recommended) Pools that trigger an error however will" + " still be omitted. (no entitlements available, consumer type mismatch, etc)") @QueryParam("listall") @DefaultValue("false") boolean listAll, @ApiParam("Uses ISO 8601 format") @QueryParam("activeon") String activeOn, @Context Principal principal, @Context PageRequest pageRequest) {
    // Make sure we were given sane query parameters:
    if (consumerUuid != null && ownerId != null) {
        throw new BadRequestException(i18n.tr("Cannot filter on both owner and unit"));
    }
    if (consumerUuid == null && ownerId == null && productId != null) {
        throw new BadRequestException(i18n.tr("A unit or owner is needed to filter on product"));
    }
    Date activeOnDate = activeOn != null ? ResourceDateParser.parseDateString(activeOn) : new Date();
    Consumer c = null;
    String oId = null;
    if (consumerUuid != null) {
        c = consumerCurator.findByUuid(consumerUuid);
        if (c == null) {
            throw new NotFoundException(i18n.tr("Unit: {0} not found", consumerUuid));
        }
        // Now that we have a consumer, check that this principal can access it:
        if (!principal.canAccess(c, SubResource.NONE, Access.READ_ONLY)) {
            throw new ForbiddenException(i18n.tr("User {0} cannot access unit {1}", principal.getPrincipalName(), consumerUuid));
        }
        if (listAll) {
            oId = c.getOwnerId();
        }
    }
    if (ownerId != null) {
        Owner o = ownerCurator.secureFind(ownerId);
        if (o == null) {
            throw new NotFoundException(i18n.tr("owner: {0}", ownerId));
        }
        oId = o.getId();
        // Now that we have an owner, check that this principal can access it:
        if (!principal.canAccess(o, SubResource.POOLS, Access.READ_ONLY)) {
            throw new ForbiddenException(i18n.tr("User {0} cannot access owner {1}", principal.getPrincipalName(), o.getKey()));
        }
    }
    // the system).
    if (consumerUuid == null && ownerId == null && !principal.hasFullAccess()) {
        throw new ForbiddenException(i18n.tr("User {0} cannot access all pools.", principal.getPrincipalName()));
    }
    Page<List<Pool>> page = poolManager.listAvailableEntitlementPools(c, null, oId, productId, null, activeOnDate, listAll, new PoolFilterBuilder(), pageRequest, false, false, null);
    List<Pool> poolList = page.getPageData();
    calculatedAttributesUtil.setCalculatedAttributes(poolList, activeOnDate);
    calculatedAttributesUtil.setQuantityAttributes(poolList, c, activeOnDate);
    // 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 : ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) Owner(org.candlepin.model.Owner) ArrayList(java.util.ArrayList) NotFoundException(org.candlepin.common.exceptions.NotFoundException) PoolDTO(org.candlepin.dto.api.v1.PoolDTO) Date(java.util.Date) Consumer(org.candlepin.model.Consumer) BadRequestException(org.candlepin.common.exceptions.BadRequestException) PoolFilterBuilder(org.candlepin.model.PoolFilterBuilder) List(java.util.List) ArrayList(java.util.ArrayList) Pool(org.candlepin.model.Pool) SecurityHole(org.candlepin.common.auth.SecurityHole) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Wrapped(org.jboss.resteasy.annotations.providers.jaxb.Wrapped) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)4 ApiResponses (io.swagger.annotations.ApiResponses)4 GET (javax.ws.rs.GET)4 Produces (javax.ws.rs.Produces)4 Wrapped (org.jboss.resteasy.annotations.providers.jaxb.Wrapped)4 BadRequestException (org.candlepin.common.exceptions.BadRequestException)3 Consumer (org.candlepin.model.Consumer)3 Owner (org.candlepin.model.Owner)3 ArrayList (java.util.ArrayList)2 Path (javax.ws.rs.Path)2 NotFoundException (org.candlepin.common.exceptions.NotFoundException)2 ConsumerType (org.candlepin.model.ConsumerType)2 DeletedConsumer (org.candlepin.model.DeletedConsumer)2 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 UpdateConsumerCheckIn (org.candlepin.auth.UpdateConsumerCheckIn)1 SecurityHole (org.candlepin.common.auth.SecurityHole)1