use of org.candlepin.model.Content in project candlepin by candlepin.
the class ProductImporterTest method addNoVendorContentTo.
// Returns the Content object added without vendor
private Content addNoVendorContentTo(Product product) {
Content content = TestUtil.createContent("100130", "name");
content.setVendor("");
content.setMetadataExpire(1000L);
product.addContent(content, true);
return content;
}
use of org.candlepin.model.Content in project candlepin by candlepin.
the class TestUtil method createContent.
public static Content createContent(ContentData cdata) {
Content content = null;
if (cdata != null) {
content = createContent(cdata.getId(), cdata.getName());
content.setUuid(cdata.getUuid());
content.setType(cdata.getType());
content.setLabel(cdata.getLabel());
content.setVendor(cdata.getVendor());
content.setContentUrl(cdata.getContentUrl());
content.setRequiredTags(cdata.getRequiredTags());
content.setReleaseVersion(cdata.getReleaseVersion());
content.setGpgUrl(cdata.getGpgUrl());
content.setMetadataExpire(cdata.getMetadataExpire());
content.setModifiedProductIds(cdata.getModifiedProductIds());
content.setArches(cdata.getArches());
content.setLocked(cdata.isLocked());
}
return content;
}
use of org.candlepin.model.Content in project candlepin by candlepin.
the class DatabaseTestFixture method createEnvironment.
protected Environment createEnvironment(Owner owner, String id, String name, String description, Collection<Consumer> consumers, Collection<Content> content) {
Environment environment = new Environment(id, name, owner);
environment.setDescription(description);
if (content != null) {
for (Content elem : content) {
EnvironmentContent envContent = new EnvironmentContent(environment, elem, true);
// Impl note:
// At the time of writing, this line is redundant. But if we ever fix environment,
// this will be good to have as a backup.
environment.getEnvironmentContent().add(envContent);
}
}
environment = this.environmentCurator.create(environment);
// Update consumers to point to the new environment
if (consumers != null) {
for (Consumer consumer : consumers) {
consumer.setEnvironmentId(environment.getId());
this.consumerCurator.merge(consumer);
}
}
return environment;
}
use of org.candlepin.model.Content in project candlepin by candlepin.
the class EnvironmentTranslator method populate.
/**
* {@inheritDoc}
*/
@Override
public EnvironmentDTO populate(ModelTranslator translator, Environment source, EnvironmentDTO dest) {
dest = super.populate(translator, source, dest);
dest.setId(source.getId());
dest.setName(source.getName());
dest.setDescription(source.getDescription());
if (translator != null) {
dest.setOwner(translator.translate(source.getOwner(), OwnerDTO.class));
Set<EnvironmentContent> envContents = source.getEnvironmentContent();
if (envContents != null) {
Collection<EnvironmentContent> envContent = source.getEnvironmentContent();
dest.setEnvironmentContent(Collections.<EnvironmentContentDTO>emptyList());
if (envContent != null) {
ObjectTranslator<Content, ContentDTO> contentTranslator = translator.findTranslatorByClass(Content.class, ContentDTO.class);
for (EnvironmentContent ec : envContent) {
if (ec != null) {
ContentDTO dto = contentTranslator.translate(translator, ec.getContent());
if (dto != null) {
dest.addContent(dto, ec.getEnabled());
}
}
}
}
}
} else {
dest.setOwner(null);
dest.setEnvironmentContent(null);
}
return dest;
}
use of org.candlepin.model.Content in project candlepin by candlepin.
the class HostedTestSubscriptionResource method addBatchContent.
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/owners/{owner_key}/products/{product_id}/batch_content")
@Transactional
public ProductDTO addBatchContent(@PathParam("owner_key") String ownerKey, @PathParam("product_id") String productId, Map<String, Boolean> contentMap) {
Owner owner = this.getOwnerByKey(ownerKey);
Product product = this.fetchProduct(owner, productId);
Collection<ProductContent> productContent = new LinkedList<>();
ProductDTO pdto = this.translator.translate(product, ProductDTO.class);
// Impl note:
// This is a wholely inefficient way of doing this. When we return to using ID-based linking
// and we're not linking the universe with our model, we can just attach the IDs directly
// without needing all this DTO conversion back and forth.
// Alternatively, we can shut off Hibernate's auto-commit junk and get in the habit of
// calling commit methods as necessary so we don't have to work with DTOs internally.
boolean changed = false;
for (Entry<String, Boolean> entry : contentMap.entrySet()) {
Content content = this.fetchContent(owner, entry.getKey());
boolean enabled = entry.getValue() != null ? entry.getValue() : ProductContent.DEFAULT_ENABLED_STATE;
ContentDTO cdto = this.translator.translate(content, ContentDTO.class);
changed |= pdto.addContent(cdto, enabled);
addContentToUpstreamSubscriptions(product, content, enabled);
}
if (changed) {
product = this.productManager.updateProduct(pdto, owner, true);
}
return this.translator.translate(product, ProductDTO.class);
}
Aggregations