use of org.candlepin.model.ExporterMetadata in project candlepin by candlepin.
the class OwnerManager method cleanupAndDelete.
@Transactional
public void cleanupAndDelete(Owner owner, boolean revokeCerts) {
log.info("Cleaning up owner: {}", owner);
Collection<String> consumerIds = this.ownerCurator.getConsumerIds(owner).list();
Collection<Consumer> consumers = this.consumerCurator.lockAndLoadByIds(consumerIds);
consumers.addAll(consumerCurator.listByRecipientOwner(owner).list());
for (Consumer consumer : consumers) {
log.info("Removing all entitlements for consumer: {}", consumer);
// We're about to delete these consumers; no need to regen/dirty their dependent
// entitlements or recalculate status.
poolManager.revokeAllEntitlements(consumer, false);
}
// FIXME Perhaps this can be handled a little better.
for (Consumer consumer : consumers) {
// need to check if this has been removed due to a
// parent being deleted
// TODO: There has to be a more efficient way to do this...
log.info("Deleting consumer: {}", consumer);
Consumer next = consumerCurator.find(consumer.getId());
if (next != null) {
consumerCurator.delete(next);
}
}
for (ActivationKey key : activationKeyCurator.listByOwner(owner)) {
log.info("Deleting activation key: {}", key);
activationKeyCurator.delete(key);
}
log.debug("Deleting environments for owner: {}", owner);
envCurator.deleteEnvironmentsForOwner(owner);
// Delete the ueber certificate for this owner, if one exists.
log.debug("Deleting uber certificate for owner: {}", owner);
this.uberCertificateCurator.deleteForOwner(owner);
for (Pool p : poolManager.listPoolsByOwner(owner)) {
log.info("Deleting pool: {}", p);
poolManager.deletePool(p);
}
ExporterMetadata m = exportCurator.lookupByTypeAndOwner(ExporterMetadata.TYPE_PER_USER, owner);
if (m != null) {
log.info("Deleting export metadata: {}", m);
exportCurator.delete(m);
}
for (ImportRecord record : importRecordCurator.findRecords(owner)) {
log.info("Deleting import record: {}", record);
importRecordCurator.delete(record);
}
for (PermissionBlueprint perm : permissionCurator.findByOwner(owner)) {
log.info("Deleting permission: {}", perm.getAccess());
perm.getRole().getPermissions().remove(perm);
permissionCurator.delete(perm);
}
log.info("Deleting all products...");
this.productManager.removeAllProducts(owner);
log.info("Deleting all content...");
this.contentManager.removeAllContent(owner, false);
log.info("Deleting owner: {}", owner);
ownerCurator.delete(owner);
ownerCurator.flush();
}
use of org.candlepin.model.ExporterMetadata in project candlepin by candlepin.
the class ImporterTest method validateMetaJson.
@Test
public void validateMetaJson() throws Exception {
/* read file
* read in version
* read in created date
* make sure created date is XYZ
* make sure version is > ABC
*/
Date now = new Date();
File file = createFile("meta", "0.0.3", now, "test_user", "prefix");
File actual = createFile("meta.json", "0.0.3", now, "test_user", "prefix");
ExporterMetadataCurator emc = mock(ExporterMetadataCurator.class);
ExporterMetadata em = new ExporterMetadata();
Date daybefore = getDateBeforeDays(1);
em.setExported(daybefore);
em.setId("42");
em.setType(ExporterMetadata.TYPE_SYSTEM);
when(emc.lookupByType(ExporterMetadata.TYPE_SYSTEM)).thenReturn(em);
Importer i = new Importer(null, null, null, null, null, null, null, null, null, emc, null, null, i18n, null, null, su, null, this.mockSubReconciler, this.ec, this.translator);
i.validateMetadata(ExporterMetadata.TYPE_SYSTEM, null, actual, new ConflictOverrides());
Meta fileMeta = mapper.readValue(file, Meta.class);
Meta actualMeta = mapper.readValue(actual, Meta.class);
assertEquals(fileMeta.getPrincipalName(), actualMeta.getPrincipalName());
assertEquals(fileMeta.getCreated().getTime(), actualMeta.getCreated().getTime());
assertEquals(fileMeta.getWebAppPrefix(), actualMeta.getWebAppPrefix());
assertTrue(file.delete());
assertTrue(actual.delete());
assertTrue(daybefore.compareTo(em.getExported()) < 0);
}
use of org.candlepin.model.ExporterMetadata in project candlepin by candlepin.
the class ImporterTest method sameImport.
@Test
public void sameImport() throws Exception {
// actualmeta is the mock for the import itself
Date date = getDateBeforeDays(10);
File actualmeta = createFile("meta.json", "0.0.3", date, "test_user", "prefix");
ExporterMetadataCurator emc = mock(ExporterMetadataCurator.class);
// emc is the mock for lastrun (i.e., the most recent import in CP)
ExporterMetadata em = new ExporterMetadata();
// exact same date = assumed same manifest
em.setExported(date);
em.setId("42");
em.setType(ExporterMetadata.TYPE_SYSTEM);
when(emc.lookupByType(ExporterMetadata.TYPE_SYSTEM)).thenReturn(em);
Importer i = new Importer(null, null, null, null, null, null, null, null, null, emc, null, null, i18n, null, null, su, null, this.mockSubReconciler, this.ec, this.translator);
try {
i.validateMetadata(ExporterMetadata.TYPE_SYSTEM, null, actualmeta, new ConflictOverrides());
fail();
} catch (ImportConflictException e) {
assertFalse(e.message().getConflicts().isEmpty());
assertEquals(1, e.message().getConflicts().size());
assertTrue(e.message().getConflicts().contains(Importer.Conflict.MANIFEST_SAME));
}
}
Aggregations