Search in sources :

Example 1 with ConflictOverrides

use of org.candlepin.sync.ConflictOverrides in project candlepin by candlepin.

the class ManifestManagerTest method testImportStoredManifest.

@Test
public void testImportStoredManifest() throws Exception {
    Owner owner = TestUtil.createOwner();
    String fileId = "1234";
    String filename = "manifest.zip";
    ConflictOverrides overrides = new ConflictOverrides(Conflict.DISTRIBUTOR_CONFLICT);
    ManifestFile manifest = mock(ManifestFile.class);
    when(manifest.getId()).thenReturn(fileId);
    when(fileService.get(eq(fileId))).thenReturn(manifest);
    manager.importStoredManifest(owner, fileId, overrides, filename);
    verify(importer).loadStoredExport(eq(manifest), eq(owner), eq(overrides), eq(filename));
    verify(fileService).delete(fileId);
}
Also used : ConflictOverrides(org.candlepin.sync.ConflictOverrides) Owner(org.candlepin.model.Owner) ManifestFile(org.candlepin.sync.file.ManifestFile) Test(org.junit.Test)

Example 2 with ConflictOverrides

use of org.candlepin.sync.ConflictOverrides in project candlepin by candlepin.

the class ImportJobTest method checkJobDetail.

@Test
public void checkJobDetail() throws IOException {
    String archiveFilePath = "/path/to/some/file.zip";
    String expectedOriginalUploadFileName = "test.zip";
    ConflictOverrides expectedConflictOverrides = new ConflictOverrides(Conflict.values());
    JobDetail detail = job.scheduleImport(owner, archiveFilePath, expectedOriginalUploadFileName, expectedConflictOverrides);
    JobDataMap dataMap = detail.getJobDataMap();
    assertEquals(dataMap.get(JobStatus.OWNER_ID), owner.getKey());
    assertEquals(dataMap.get(JobStatus.TARGET_ID), owner.getKey());
    assertEquals(dataMap.get(JobStatus.TARGET_TYPE), JobStatus.TargetType.OWNER);
    assertEquals(dataMap.get(ImportJob.STORED_FILE_ID), archiveFilePath);
    assertEquals(dataMap.get(ImportJob.UPLOADED_FILE_NAME), expectedOriginalUploadFileName);
    String[] overrides = (String[]) dataMap.get(ImportJob.CONFLICT_OVERRIDES);
    assertArrayEquals(expectedConflictOverrides.asStringArray(), overrides);
}
Also used : ConflictOverrides(org.candlepin.sync.ConflictOverrides) JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) Test(org.junit.Test)

Example 3 with ConflictOverrides

use of org.candlepin.sync.ConflictOverrides in project candlepin by candlepin.

the class OwnerResource method importManifestAsync.

/**
 * Initiates an asynchronous manifest import for the given organization. The details of
 * the started job can be obtained via the {@link JobResource}.
 *
 * This will bring in any products, content, and subscriptions that were assigned to
 * the distributor who generated the manifest.
 *
 * @return a JobDetail object representing the newly started {@link ImportJob}.
 * @httpcode 400
 * @httpcode 404
 * @httpcode 500
 * @httpcode 200
 * @httpcode 409
 */
@POST
@Path("{owner_key}/imports/async")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(notes = "Initiates an asynchronous manifest import for the given organization. " + "This will bring in any products, content, and subscriptions that were " + "assigned to the distributor who generated the manifest.", value = "Import Manifest Asynchronously")
@ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 404, message = "Owner not found"), @ApiResponse(code = 500, message = ""), @ApiResponse(code = 409, message = "") })
public JobDetail importManifestAsync(@PathParam("owner_key") @Verify(Owner.class) String ownerKey, @QueryParam("force") String[] overrideConflicts, MultipartInput input) {
    ConflictOverrides overrides = processConflictOverrideParams(overrideConflicts);
    UploadMetadata fileData = new UploadMetadata();
    Owner owner = findOwnerByKey(ownerKey);
    try {
        fileData = getArchiveFromResponse(input);
        String archivePath = fileData.getData().getAbsolutePath();
        log.info("Running async import of archive {} for owner {}", archivePath, owner.getDisplayName());
        return manifestManager.importManifestAsync(owner, fileData.getData(), fileData.getUploadedFilename(), overrides);
    } catch (IOException e) {
        manifestManager.recordImportFailure(owner, e, fileData.getUploadedFilename());
        throw new IseException(i18n.tr("Error reading export archive"), e);
    } catch (ManifestFileServiceException e) {
        manifestManager.recordImportFailure(owner, e, fileData.getUploadedFilename());
        throw new IseException(i18n.tr("Error storing uploaded archive for asynchronous processing."), e);
    } catch (CandlepinException e) {
        manifestManager.recordImportFailure(owner, e, fileData.getUploadedFilename());
        throw e;
    }
}
Also used : ConflictOverrides(org.candlepin.sync.ConflictOverrides) CandlepinException(org.candlepin.common.exceptions.CandlepinException) Owner(org.candlepin.model.Owner) IseException(org.candlepin.common.exceptions.IseException) IOException(java.io.IOException) ManifestFileServiceException(org.candlepin.sync.file.ManifestFileServiceException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with ConflictOverrides

use of org.candlepin.sync.ConflictOverrides in project candlepin by candlepin.

the class OwnerResource method importManifest.

/**
 * Imports a manifest zip file for the given organization.
 *
 * This will bring in any products, content, and subscriptions that were assigned to
 * the distributor who generated the manifest.
 *
 * @deprecated use GET /owners/:owner_key/imports/async
 *
 * @return a ImportRecord object if the import is successful.
 * @httpcode 400
 * @httpcode 404
 * @httpcode 500
 * @httpcode 200
 * @httpcode 409
 */
@POST
@Path("{owner_key}/imports")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(notes = "Imports a manifest zip file for the given organization. " + "This will bring in any products, content, and subscriptions that were " + "assigned to the distributor who generated the manifest.", value = "Import Manifest")
@ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 404, message = "Owner not found"), @ApiResponse(code = 500, message = ""), @ApiResponse(code = 409, message = "") })
@Deprecated
public ImportRecord importManifest(@PathParam("owner_key") @Verify(Owner.class) String ownerKey, @QueryParam("force") String[] overrideConflicts, MultipartInput input) {
    ConflictOverrides overrides = processConflictOverrideParams(overrideConflicts);
    UploadMetadata fileData = new UploadMetadata();
    Owner owner = findOwnerByKey(ownerKey);
    try {
        fileData = getArchiveFromResponse(input);
        return manifestManager.importManifest(owner, fileData.getData(), fileData.getUploadedFilename(), overrides);
    } catch (IOException e) {
        log.error("Reading error during importing", e);
        manifestManager.recordImportFailure(owner, e, fileData.getUploadedFilename());
        throw new IseException(i18n.tr("Error reading export archive"), e);
    }// These come back with internationalized messages, so we can transfer:
     catch (SyncDataFormatException e) {
        log.error("Format error of the data in a manifest", e);
        manifestManager.recordImportFailure(owner, e, fileData.getUploadedFilename());
        throw new BadRequestException(e.getMessage(), e);
    } catch (ImporterException e) {
        log.error("Problem with archive", e);
        manifestManager.recordImportFailure(owner, e, fileData.getUploadedFilename());
        throw new IseException(e.getMessage(), e);
    }// to pass on the http return code
     catch (CandlepinException e) {
        log.error("Recording import failure", e);
        manifestManager.recordImportFailure(owner, e, fileData.getUploadedFilename());
        throw e;
    } finally {
        log.info("Import attempt completed for owner {}", owner.getDisplayName());
    }
}
Also used : ImporterException(org.candlepin.sync.ImporterException) ConflictOverrides(org.candlepin.sync.ConflictOverrides) CandlepinException(org.candlepin.common.exceptions.CandlepinException) Owner(org.candlepin.model.Owner) IseException(org.candlepin.common.exceptions.IseException) SyncDataFormatException(org.candlepin.sync.SyncDataFormatException) BadRequestException(org.candlepin.common.exceptions.BadRequestException) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 5 with ConflictOverrides

use of org.candlepin.sync.ConflictOverrides in project candlepin by candlepin.

the class ManifestManagerTest method testManifestImportAsync.

@Test
public void testManifestImportAsync() throws Exception {
    Owner owner = TestUtil.createOwner();
    File file = mock(File.class);
    String filename = "manifest.zip";
    ConflictOverrides overrides = new ConflictOverrides(Conflict.DISTRIBUTOR_CONFLICT);
    UserPrincipal principal = TestUtil.createOwnerPrincipal();
    when(principalProvider.get()).thenReturn(principal);
    ManifestFile manifest = mock(ManifestFile.class);
    when(fileService.store(ManifestFileType.IMPORT, file, principal.getName(), owner.getKey())).thenReturn(manifest);
    JobDetail job = manager.importManifestAsync(owner, file, filename, overrides);
    JobDataMap jobData = job.getJobDataMap();
    assertEquals(owner.getKey(), jobData.get("owner_id"));
    assertEquals(JobStatus.TargetType.OWNER, jobData.get("target_type"));
    assertEquals(owner.getKey(), jobData.get("target_id"));
    assertEquals(manifest.getId(), jobData.get("stored_manifest_file_id"));
    assertEquals(filename, jobData.get("uploaded_file_name"));
    ConflictOverrides retrievedOverrides = new ConflictOverrides((String[]) jobData.get("conflict_overrides"));
    assertTrue(retrievedOverrides.isForced(Conflict.DISTRIBUTOR_CONFLICT));
    verify(fileService).store(eq(ManifestFileType.IMPORT), eq(file), eq(principal.getName()), eq(owner.getKey()));
}
Also used : ConflictOverrides(org.candlepin.sync.ConflictOverrides) Owner(org.candlepin.model.Owner) JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) ManifestFile(org.candlepin.sync.file.ManifestFile) File(java.io.File) UserPrincipal(org.candlepin.auth.UserPrincipal) ManifestFile(org.candlepin.sync.file.ManifestFile) Test(org.junit.Test)

Aggregations

ConflictOverrides (org.candlepin.sync.ConflictOverrides)11 Test (org.junit.Test)8 Owner (org.candlepin.model.Owner)7 JobDetail (org.quartz.JobDetail)5 IseException (org.candlepin.common.exceptions.IseException)3 ImporterException (org.candlepin.sync.ImporterException)3 ManifestFile (org.candlepin.sync.file.ManifestFile)3 JobDataMap (org.quartz.JobDataMap)3 JobExecutionException (org.quartz.JobExecutionException)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 File (java.io.File)2 IOException (java.io.IOException)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 BadRequestException (org.candlepin.common.exceptions.BadRequestException)2 CandlepinException (org.candlepin.common.exceptions.CandlepinException)2 NotFoundException (org.candlepin.common.exceptions.NotFoundException)2