use of org.candlepin.model.ImportRecord in project candlepin by candlepin.
the class ImporterTest method testRecordImportNoActiveSubsFound.
@Test
public void testRecordImportNoActiveSubsFound() {
String expectedOwnerKey = "TEST_OWNER";
Owner owner = new Owner(expectedOwnerKey);
EventSink eventSinkMock = mock(EventSink.class);
ImportRecordCurator importRecordCurator = mock(ImportRecordCurator.class);
Importer importer = new Importer(null, null, null, null, null, null, null, null, config, null, null, eventSinkMock, i18n, null, null, su, importRecordCurator, this.mockSubReconciler, this.ec, this.translator);
Map<String, Object> data = new HashMap<>();
data.put("subscriptions", new ArrayList<Subscription>());
ImportRecord record = importer.recordImportSuccess(owner, data, new ConflictOverrides(), "test.zip");
assertEquals(ImportRecord.Status.SUCCESS_WITH_WARNING, record.getStatus());
assertEquals(owner.getKey() + " file imported successfully." + "No active subscriptions found in the file.", record.getStatusMessage());
verify(eventSinkMock, never()).emitSubscriptionExpired(any(Subscription.class));
verify(importRecordCurator).create(eq(record));
}
use of org.candlepin.model.ImportRecord in project candlepin by candlepin.
the class ImporterTest method testRecordImportExpiredSubsFound.
@Test
public void testRecordImportExpiredSubsFound() {
String expectedOwnerKey = "TEST_OWNER";
Owner owner = new Owner(expectedOwnerKey);
EventSink eventSinkMock = mock(EventSink.class);
ImportRecordCurator importRecordCurator = mock(ImportRecordCurator.class);
Importer importer = new Importer(null, null, null, null, null, null, null, null, config, null, null, eventSinkMock, i18n, null, null, su, importRecordCurator, this.mockSubReconciler, this.ec, this.translator);
Map<String, Object> data = new HashMap<>();
List<Subscription> subscriptions = new ArrayList<>();
Subscription subscription1 = new Subscription();
// expires tomorrow
subscription1.setEndDate(new Date((new Date()).getTime() + (1000 * 60 * 60 * 24)));
subscriptions.add(subscription1);
Subscription subscription2 = new Subscription();
// expires yesterday
subscription2.setEndDate(new Date((new Date()).getTime() - (1000 * 60 * 60 * 24)));
subscriptions.add(subscription2);
data.put("subscriptions", subscriptions);
ImportRecord record = importer.recordImportSuccess(owner, data, new ConflictOverrides(), "test.zip");
assertEquals(ImportRecord.Status.SUCCESS_WITH_WARNING, record.getStatus());
assertEquals(owner.getKey() + " file imported successfully." + "One or more inactive subscriptions found in the file.", record.getStatusMessage());
verify(eventSinkMock, never()).emitSubscriptionExpired(subscription1);
verify(eventSinkMock).emitSubscriptionExpired(subscription2);
verify(importRecordCurator).create(eq(record));
}
use of org.candlepin.model.ImportRecord in project candlepin by candlepin.
the class ImporterTest method testRecordImportSetsUpstreamConsumerFromOwner.
@Test
public void testRecordImportSetsUpstreamConsumerFromOwner() {
String expectedOwnerKey = "TEST_OWNER";
Owner owner = new Owner(expectedOwnerKey);
UpstreamConsumer uc = new UpstreamConsumer("uc", owner, new ConsumerType(ConsumerType.ConsumerTypeEnum.CANDLEPIN), "uuid");
uc.setContentAccessMode("mode");
owner.setUpstreamConsumer(uc);
EventSink eventSinkMock = mock(EventSink.class);
ImportRecordCurator importRecordCurator = mock(ImportRecordCurator.class);
Importer importer = new Importer(null, null, null, null, null, null, null, null, config, null, null, eventSinkMock, i18n, null, null, su, importRecordCurator, this.mockSubReconciler, this.ec, this.translator);
Meta meta = new Meta("1.0", new Date(), "test-user", "candlepin", "testcdn");
Map<String, Object> data = new HashMap<>();
data.put("meta", meta);
data.put("subscriptions", new ArrayList<Subscription>());
ImportRecord record = importer.recordImportSuccess(owner, data, new ConflictOverrides(), "test.zip");
ImportUpstreamConsumer iuc = record.getUpstreamConsumer();
assertNotNull(iuc);
assertEquals(uc.getOwnerId(), iuc.getOwnerId());
assertEquals(uc.getName(), iuc.getName());
assertEquals(uc.getUuid(), iuc.getUuid());
assertEquals(uc.getType(), iuc.getType());
assertEquals(uc.getWebUrl(), iuc.getWebUrl());
assertEquals(uc.getApiUrl(), iuc.getApiUrl());
assertEquals(uc.getContentAccessMode(), iuc.getContentAccessMode());
verify(importRecordCurator).create(eq(record));
}
use of org.candlepin.model.ImportRecord in project candlepin by candlepin.
the class Importer method recordImportFailure.
public void recordImportFailure(Owner owner, Throwable error, String filename) {
ImportRecord record = new ImportRecord(owner);
log.error("Recording import failure", error);
if (error instanceof ImporterException) {
Meta meta = (Meta) ((ImporterException) error).getCollectedData().get("meta");
if (meta != null) {
record.setGeneratedBy(meta.getPrincipalName());
record.setGeneratedDate(meta.getCreated());
}
}
record.setUpstreamConsumer(createImportUpstreamConsumer(owner, null));
record.setFileName(filename);
record.recordStatus(ImportRecord.Status.FAILURE, error.getMessage());
this.importRecordCurator.create(record);
}
use of org.candlepin.model.ImportRecord in project candlepin by candlepin.
the class Importer method recordImportSuccess.
/**
* Records a successful import of a manifest.
*
* @param owner the owner that the manifest was imported into.
* @param data the data to store in this record.
* @param forcedConflicts the conflicts that were forced.
* @param filename the name of the originally uploaded file.
* @return the newly created {@link ImportRecord}.
*/
public ImportRecord recordImportSuccess(Owner owner, Map<String, Object> data, ConflictOverrides forcedConflicts, String filename) {
ImportRecord record = new ImportRecord(owner);
Meta meta = (Meta) data.get("meta");
if (meta != null) {
record.setGeneratedBy(meta.getPrincipalName());
record.setGeneratedDate(meta.getCreated());
}
record.setUpstreamConsumer(createImportUpstreamConsumer(owner, null));
record.setFileName(filename);
List<Subscription> subscriptions = (List<Subscription>) data.get("subscriptions");
boolean activeSubscriptionFound = false, expiredSubscriptionFound = false;
Date currentDate = new Date();
for (Subscription subscription : subscriptions) {
if (subscription.getEndDate() == null || subscription.getEndDate().after(currentDate)) {
activeSubscriptionFound = true;
} else {
expiredSubscriptionFound = true;
sink.emitSubscriptionExpired(subscription);
}
}
String msg = i18n.tr("{0} file imported successfully.", owner.getKey());
if (!forcedConflicts.isEmpty()) {
msg = i18n.tr("{0} file imported forcibly.", owner.getKey());
}
if (!activeSubscriptionFound) {
msg += i18n.tr("No active subscriptions found in the file.");
record.recordStatus(ImportRecord.Status.SUCCESS_WITH_WARNING, msg);
} else if (expiredSubscriptionFound) {
msg += i18n.tr("One or more inactive subscriptions found in the file.");
record.recordStatus(ImportRecord.Status.SUCCESS_WITH_WARNING, msg);
} else {
record.recordStatus(ImportRecord.Status.SUCCESS, msg);
}
this.importRecordCurator.create(record);
return record;
}
Aggregations