Search in sources :

Example 1 with ImportRecord

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;
}
Also used : BadRequestException(org.candlepin.common.exceptions.BadRequestException) ImportRecord(org.candlepin.model.ImportRecord) ManifestFile(org.candlepin.sync.file.ManifestFile) Transactional(com.google.inject.persist.Transactional)

Example 2 with ImportRecord

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);
}
Also used : ConflictOverrides(org.candlepin.sync.ConflictOverrides) GenericType(org.jboss.resteasy.util.GenericType) MultipartInput(org.jboss.resteasy.plugins.providers.multipart.MultipartInput) ArrayList(java.util.ArrayList) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) Matchers.anyString(org.mockito.Matchers.anyString) ManifestManager(org.candlepin.controller.ManifestManager) ImportRecord(org.candlepin.model.ImportRecord) InputPart(org.jboss.resteasy.plugins.providers.multipart.InputPart) EventSink(org.candlepin.audit.EventSink) File(java.io.File) Test(org.junit.Test)

Example 3 with ImportRecord

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));
}
Also used : Owner(org.candlepin.model.Owner) HashMap(java.util.HashMap) ImportRecord(org.candlepin.model.ImportRecord) Date(java.util.Date) ImportRecordCurator(org.candlepin.model.ImportRecordCurator) EventSink(org.candlepin.audit.EventSink) Subscription(org.candlepin.model.dto.Subscription) Test(org.junit.Test)

Example 4 with ImportRecord

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);
}
Also used : Owner(org.candlepin.model.Owner) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ImportRecord(org.candlepin.model.ImportRecord) Date(java.util.Date) ImportRecordCurator(org.candlepin.model.ImportRecordCurator) EventSink(org.candlepin.audit.EventSink) Subscription(org.candlepin.model.dto.Subscription) Test(org.junit.Test)

Example 5 with ImportRecord

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());
}
Also used : Owner(org.candlepin.model.Owner) ImportRecord(org.candlepin.model.ImportRecord) Test(org.junit.Test)

Aggregations

ImportRecord (org.candlepin.model.ImportRecord)17 Test (org.junit.Test)11 Owner (org.candlepin.model.Owner)10 Date (java.util.Date)7 EventSink (org.candlepin.audit.EventSink)6 Subscription (org.candlepin.model.dto.Subscription)6 HashMap (java.util.HashMap)5 ImportRecordCurator (org.candlepin.model.ImportRecordCurator)5 ArrayList (java.util.ArrayList)4 ConflictOverrides (org.candlepin.sync.ConflictOverrides)3 Transactional (com.google.inject.persist.Transactional)2 BadRequestException (org.candlepin.common.exceptions.BadRequestException)2 ConsumerType (org.candlepin.model.ConsumerType)2 ExporterMetadata (org.candlepin.model.ExporterMetadata)2 Pool (org.candlepin.model.Pool)2 UpstreamConsumer (org.candlepin.model.UpstreamConsumer)2 File (java.io.File)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Principal (org.candlepin.auth.Principal)1