Search in sources :

Example 46 with Content

use of org.candlepin.model.Content in project candlepin by candlepin.

the class OwnerContentResource method getContent.

@ApiOperation(notes = "Retrieves a single Content", value = "getContent")
@ApiResponses({ @ApiResponse(code = 400, message = "") })
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{content_id}")
public ContentDTO getContent(@Verify(Owner.class) @PathParam("owner_key") String ownerKey, @PathParam("content_id") String contentId) {
    Owner owner = this.getOwnerByKey(ownerKey);
    Content content = this.fetchContent(owner, contentId);
    return this.translator.translate(content, ContentDTO.class);
}
Also used : Owner(org.candlepin.model.Owner) Content(org.candlepin.model.Content) 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 47 with Content

use of org.candlepin.model.Content in project candlepin by candlepin.

the class OwnerContentResource method remove.

@ApiOperation(notes = "Deletes a Content", value = "remove")
@DELETE
@Produces(MediaType.APPLICATION_JSON)
@Path("/{content_id}")
public void remove(@PathParam("owner_key") String ownerKey, @PathParam("content_id") String contentId) {
    Owner owner = this.getOwnerByKey(ownerKey);
    Content content = this.fetchContent(owner, contentId);
    if (content.isLocked()) {
        throw new ForbiddenException(i18n.tr("content \"{0}\" is locked", content.getId()));
    }
    this.contentManager.removeContent(owner, content, true);
    ownerManager.refreshOwnerForContentAccess(owner);
}
Also used : Owner(org.candlepin.model.Owner) ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) Content(org.candlepin.model.Content) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation)

Example 48 with Content

use of org.candlepin.model.Content in project candlepin by candlepin.

the class OwnerContentResource method listContent.

@ApiOperation(notes = "Retrieves list of Content", value = "list", response = Content.class, responseContainer = "list")
@GET
@Produces(MediaType.APPLICATION_JSON)
public CandlepinQuery<ContentDTO> listContent(@Verify(Owner.class) @PathParam("owner_key") String ownerKey) {
    final Owner owner = this.getOwnerByKey(ownerKey);
    CandlepinQuery<Content> query = this.ownerContentCurator.getContentByOwner(owner);
    return this.translator.translateQuery(query, ContentDTO.class);
}
Also used : Owner(org.candlepin.model.Owner) Content(org.candlepin.model.Content) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 49 with Content

use of org.candlepin.model.Content in project candlepin by candlepin.

the class OwnerContentResource method createContent.

@ApiOperation(notes = "Creates a Content", value = "createContent")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public ContentDTO createContent(@PathParam("owner_key") String ownerKey, @ApiParam(name = "content", required = true) ContentDTO content) {
    Owner owner = this.getOwnerByKey(ownerKey);
    Content entity = this.createContentImpl(owner, content);
    ownerManager.refreshOwnerForContentAccess(owner);
    return this.translator.translate(entity, ContentDTO.class);
}
Also used : Owner(org.candlepin.model.Owner) Content(org.candlepin.model.Content) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation)

Example 50 with Content

use of org.candlepin.model.Content in project candlepin by candlepin.

the class OrphanCleanupJob method toExecute.

@Override
@Transactional
public void toExecute(JobExecutionContext ctx) throws JobExecutionException {
    log.debug("Deleting orphaned entities...");
    int count;
    // Content
    count = 0;
    CandlepinQuery<Content> contentQuery = this.ownerContentCurator.getOrphanedContent().setLockMode(LockModeType.PESSIMISTIC_WRITE);
    for (Content content : contentQuery) {
        this.contentCurator.delete(content);
        ++count;
    }
    this.contentCurator.flush();
    log.debug("{} orphaned content entities deleted", count);
    // Products
    count = 0;
    CandlepinQuery<Product> productQuery = this.ownerProductCurator.getOrphanedProducts().setLockMode(LockModeType.PESSIMISTIC_WRITE);
    for (Product product : productQuery) {
        this.productCurator.delete(product);
        ++count;
    }
    this.productCurator.flush();
    log.debug("{} orphaned product entities deleted", count);
}
Also used : Content(org.candlepin.model.Content) Product(org.candlepin.model.Product) Transactional(com.google.inject.persist.Transactional)

Aggregations

Content (org.candlepin.model.Content)97 Test (org.junit.Test)45 ProductContent (org.candlepin.model.ProductContent)41 Product (org.candlepin.model.Product)40 Owner (org.candlepin.model.Owner)39 ContentDTO (org.candlepin.dto.api.v1.ContentDTO)25 HashMap (java.util.HashMap)18 EnvironmentContent (org.candlepin.model.EnvironmentContent)17 HashSet (java.util.HashSet)14 LinkedList (java.util.LinkedList)11 ProductDTO (org.candlepin.dto.api.v1.ProductDTO)10 ArrayList (java.util.ArrayList)9 Matchers.anyString (org.mockito.Matchers.anyString)9 Transactional (com.google.inject.persist.Transactional)8 Produces (javax.ws.rs.Produces)8 Parameters (junitparams.Parameters)8 ApiOperation (io.swagger.annotations.ApiOperation)7 ForbiddenException (org.candlepin.common.exceptions.ForbiddenException)7 Path (javax.ws.rs.Path)6 ProductContentDTO (org.candlepin.dto.api.v1.ProductDTO.ProductContentDTO)6