use of org.candlepin.model.ImportRecord in project candlepin by candlepin.
the class ManifestManager method importStoredManifest.
/**
* Imports a stored manifest file into the target {@link Owner}. The stored file is deleted
* as soon as the import is complete.
*
* @param targetOwner the target owner.
* @param fileId the manifest file ID.
* @param overrides the {@link ConflictOverrides} to apply to the import process.
* @param uploadedFileName the originally uploaded file name.
* @return the result of the import.
* @throws BadRequestException if the file is not found in the {@link ManifestFileService}
* @throws ImporterException if there is an issue importing the file.
*/
@Transactional
public ImportRecord importStoredManifest(Owner targetOwner, String fileId, ConflictOverrides overrides, String uploadedFileName) throws BadRequestException, ImporterException {
ManifestFile manifest = manifestFileService.get(fileId);
if (manifest == null) {
throw new BadRequestException(i18n.tr("The requested manifest file was not found: {0}", fileId));
}
ImportRecord importResult = importer.loadStoredExport(manifest, targetOwner, overrides, uploadedFileName);
deleteStoredManifest(manifest.getId());
return importResult;
}
use of org.candlepin.model.ImportRecord in project candlepin by candlepin.
the class OwnerResourceTest method testImportManifestSynchronousSuccess.
@Test
public void testImportManifestSynchronousSuccess() throws IOException, ImporterException {
ManifestManager manifestManager = mock(ManifestManager.class);
EventSink es = mock(EventSink.class);
OwnerResource thisOwnerResource = new OwnerResource(ownerCurator, productCurator, null, null, i18n, es, eventFactory, null, null, manifestManager, null, null, null, null, importRecordCurator, null, null, null, null, null, null, null, contentOverrideValidator, serviceLevelValidator, null, null, null, null, null, this.modelTranslator);
MultipartInput input = mock(MultipartInput.class);
InputPart part = mock(InputPart.class);
File archive = mock(File.class);
List<InputPart> parts = new ArrayList<>();
parts.add(part);
MultivaluedMap<String, String> mm = new MultivaluedMapImpl<>();
List<String> contDis = new ArrayList<>();
contDis.add("form-data; name=\"upload\"; filename=\"test_file.zip\"");
mm.put("Content-Disposition", contDis);
when(input.getParts()).thenReturn(parts);
when(part.getHeaders()).thenReturn(mm);
when(part.getBody(any(GenericType.class))).thenReturn(archive);
ImportRecord ir = new ImportRecord(owner);
when(manifestManager.importManifest(eq(owner), any(File.class), eq("test_file.zip"), any(ConflictOverrides.class))).thenReturn(ir);
ImportRecord response = thisOwnerResource.importManifest(owner.getKey(), new String[] {}, input);
assertNotNull(response);
assertEquals(ir, response);
}
use of org.candlepin.model.ImportRecord in project candlepin by candlepin.
the class ImporterTest method testRecordImportIgnoresUpstreamConsumerIfNotSetOnOwner.
@Test
public void testRecordImportIgnoresUpstreamConsumerIfNotSetOnOwner() {
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);
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");
assertNull(record.getUpstreamConsumer());
verify(importRecordCurator).create(eq(record));
}
use of org.candlepin.model.ImportRecord in project candlepin by candlepin.
the class ImporterTest method testRecordImportSuccess.
@Test
public void testRecordImportSuccess() {
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);
Meta meta = new Meta("1.0", new Date(), "test-user", "candlepin", "testcdn");
List<Subscription> subscriptions = new ArrayList<>();
Subscription subscription = new Subscription();
subscriptions.add(subscription);
Map<String, Object> data = new HashMap<>();
data.put("meta", meta);
data.put("subscriptions", subscriptions);
ImportRecord record = importer.recordImportSuccess(owner, data, new ConflictOverrides(), "test.zip");
assertEquals(meta.getPrincipalName(), record.getGeneratedBy());
assertEquals(meta.getCreated(), record.getGeneratedDate());
assertEquals(ImportRecord.Status.SUCCESS, record.getStatus());
assertEquals(owner.getKey() + " file imported successfully.", record.getStatusMessage());
assertEquals("test.zip", record.getFileName());
verify(importRecordCurator).create(eq(record));
verify(eventSinkMock, never()).emitSubscriptionExpired(subscription);
}
use of org.candlepin.model.ImportRecord in project candlepin by candlepin.
the class ImportRecordJobTest method lessThanThreshold.
@Test
public void lessThanThreshold() throws Exception {
Owner owner = new Owner("owner");
ownerCurator.create(owner);
for (int i = 0; i < 7; i++) {
ImportRecord record = new ImportRecord(owner);
record.recordStatus(ImportRecord.Status.SUCCESS, "great!");
this.importRecordCurator.create(record);
}
this.job.execute(null);
List<ImportRecord> records = this.importRecordCurator.findRecords(owner).list();
Assert.assertEquals(7, records.size());
}
Aggregations