use of org.candlepin.model.EnvironmentContent 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.EnvironmentContent 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.EnvironmentContent in project candlepin by candlepin.
the class EnvironmentTranslatorTest method verifyOutput.
@Override
protected void verifyOutput(Environment source, EnvironmentDTO dto, boolean childrenGenerated) {
if (source != null) {
assertEquals(source.getId(), dto.getId());
assertEquals(source.getName(), dto.getName());
assertEquals(source.getDescription(), dto.getDescription());
if (childrenGenerated) {
this.ownerTranslatorTest.verifyOutput(source.getOwner(), dto.getOwner(), childrenGenerated);
assertNotNull(dto.getEnvironmentContent());
for (EnvironmentContent ec : source.getEnvironmentContent()) {
for (EnvironmentContentDTO ecdto : dto.getEnvironmentContent()) {
Content content = ec.getContent();
ContentDTO cdto = ecdto.getContent();
assertNotNull(cdto);
assertNotNull(cdto.getUuid());
if (cdto.getUuid().equals(content.getUuid())) {
assertEquals(ec.getEnabled(), ecdto.isEnabled());
// Pass the content off to the ContentTranslatorTest to verify it
this.contentTranslatorTest.verifyOutput(content, cdto, childrenGenerated);
}
}
}
} else {
assertNull(dto.getEnvironmentContent());
assertNull(dto.getOwner());
}
} else {
assertNull(dto);
}
}
use of org.candlepin.model.EnvironmentContent in project candlepin by candlepin.
the class EnvironmentResource method demoteContent.
@ApiOperation(notes = "Demotes a Content from an Environment. Consumer's registered to " + "this environment will no see this content in their entitlement certificates. (after" + " they are regenerated and synced to clients) This call accepts multiple content IDs" + " to demote at once, allowing us to mass demote, then trigger a cert regeneration." + " NOTE: This call expects the actual content IDs, *not* the ID created for each " + "EnvironmentContent object created after a promotion. This is to help integrate " + "with other management apps which should not have to track/lookup a specific ID " + "for the content to demote.", value = "demoteContent")
@ApiResponses({ @ApiResponse(code = 404, message = "When the content has already been demoted.") })
@DELETE
@Produces(MediaType.APPLICATION_JSON)
@Path("/{env_id}/content")
public JobDetail demoteContent(@PathParam("env_id") @Verify(Environment.class) String envId, @QueryParam("content") String[] contentIds, @QueryParam("lazy_regen") @DefaultValue("true") Boolean lazyRegen) {
Environment e = lookupEnvironment(envId);
Map<String, EnvironmentContent> demotedContent = new HashMap<>();
// Step through and validate all given content IDs before deleting
for (String contentId : contentIds) {
EnvironmentContent envContent = envContentCurator.lookupByEnvironmentAndContent(e, contentId);
if (envContent == null) {
throw new NotFoundException(i18n.tr("Content does not exist in environment: {0}", contentId));
}
demotedContent.put(contentId, envContent);
}
try {
envContentCurator.bulkDeleteTransactional(new ArrayList<>(demotedContent.values()));
clearContentAccessCerts(e);
} catch (RollbackException hibernateException) {
if (rdbmsExceptionTranslator.isUpdateHadNoEffectException(hibernateException)) {
log.info("Concurrent content demotion will cause this request to fail.", hibernateException);
throw new NotFoundException(i18n.tr("One of the content does not exist in the environment anymore: {0}", demotedContent.values()));
} else {
throw hibernateException;
}
}
// Impl note: Unfortunately, we have to make an additional set here, as the keySet isn't
// serializable. Attempting to use it causes exceptions.
Set<String> demotedContentIds = new HashSet<>(demotedContent.keySet());
JobDataMap map = new JobDataMap();
map.put(RegenEnvEntitlementCertsJob.ENV, e);
map.put(RegenEnvEntitlementCertsJob.CONTENT, demotedContentIds);
map.put(RegenEnvEntitlementCertsJob.LAZY_REGEN, lazyRegen);
JobDetail detail = newJob(RegenEnvEntitlementCertsJob.class).withIdentity("regen_entitlement_cert_of_env" + Util.generateUUID()).usingJobData(map).build();
return detail;
}
use of org.candlepin.model.EnvironmentContent in project candlepin by candlepin.
the class EnvironmentResource method batchCreate.
/**
* To make promotion transactional
* @param contentToPromote
* @param env
* @return contentIds Ids of the promoted content
*/
@Transactional
public Set<String> batchCreate(List<org.candlepin.model.dto.EnvironmentContent> contentToPromote, Environment env) {
Set<String> contentIds = new HashSet<>();
for (org.candlepin.model.dto.EnvironmentContent promoteMe : contentToPromote) {
// Make sure the content exists:
EnvironmentContent envcontent = new EnvironmentContent();
envcontent.setEnvironment(env);
envcontent.setContent(this.resolveContent(env, promoteMe.getContentId()));
envcontent.setEnabled(promoteMe.getEnabled());
envContentCurator.create(envcontent);
env.getEnvironmentContent().add(envcontent);
contentIds.add(promoteMe.getContentId());
}
return contentIds;
}
Aggregations