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);
}
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);
}
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;
}
}
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());
}
}
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()));
}
Aggregations