use of org.datatransferproject.spi.cloud.types.PortabilityJob in project data-transfer-project by google.
the class GooglePhotosImporterTest method retrieveAlbumStringOnlyOnce.
@Test
public void retrieveAlbumStringOnlyOnce() throws PermissionDeniedException, InvalidTokenException, IOException {
String albumId = "Album Id";
String albumName = "Album Name";
String albumDescription = "Album Description";
PhotoAlbum albumModel = new PhotoAlbum(albumId, albumName, albumDescription);
PortabilityJob portabilityJob = Mockito.mock(PortabilityJob.class);
Mockito.when(portabilityJob.userLocale()).thenReturn("it");
JobStore jobStore = Mockito.mock(JobStore.class);
Mockito.when(jobStore.findJob(uuid)).thenReturn(portabilityJob);
GoogleAlbum responseAlbum = new GoogleAlbum();
responseAlbum.setId(NEW_ALBUM_ID);
Mockito.when(googlePhotosInterface.createAlbum(any(GoogleAlbum.class))).thenReturn(responseAlbum);
GooglePhotosImporter sut = new GooglePhotosImporter(null, jobStore, null, null, googlePhotosInterface, imageStreamProvider, monitor, 1.0);
sut.importSingleAlbum(uuid, null, albumModel);
sut.importSingleAlbum(uuid, null, albumModel);
Mockito.verify(jobStore, atMostOnce()).findJob(uuid);
}
use of org.datatransferproject.spi.cloud.types.PortabilityJob in project data-transfer-project by google.
the class GooglePhotosImporterTest method importAlbumWithITString.
@Test
public void importAlbumWithITString() throws PermissionDeniedException, InvalidTokenException, IOException {
String albumId = "Album Id";
String albumName = "Album Name";
String albumDescription = "Album Description";
PhotoAlbum albumModel = new PhotoAlbum(albumId, albumName, albumDescription);
PortabilityJob portabilityJob = Mockito.mock(PortabilityJob.class);
Mockito.when(portabilityJob.userLocale()).thenReturn("it");
JobStore jobStore = Mockito.mock(JobStore.class);
Mockito.when(jobStore.findJob(uuid)).thenReturn(portabilityJob);
GoogleAlbum responseAlbum = new GoogleAlbum();
responseAlbum.setId(NEW_ALBUM_ID);
Mockito.when(googlePhotosInterface.createAlbum(any(GoogleAlbum.class))).thenReturn(responseAlbum);
GooglePhotosImporter sut = new GooglePhotosImporter(null, jobStore, null, null, googlePhotosInterface, imageStreamProvider, monitor, 1.0);
sut.importSingleAlbum(uuid, null, albumModel);
ArgumentCaptor<GoogleAlbum> albumArgumentCaptor = ArgumentCaptor.forClass(GoogleAlbum.class);
Mockito.verify(googlePhotosInterface).createAlbum(albumArgumentCaptor.capture());
assertEquals(albumArgumentCaptor.getValue().getTitle(), albumName);
}
use of org.datatransferproject.spi.cloud.types.PortabilityJob in project data-transfer-project by google.
the class AzureTableStore method updateJob.
@Override
protected void updateJob(UUID jobId, PortabilityJob job, JobUpdateValidator validator) throws IOException {
Preconditions.checkNotNull(jobId, "Job is null");
Preconditions.checkNotNull(job, "Job is null");
try {
CloudTable table = tableClient.getTableReference(JOB_TABLE);
String serializedJob = configuration.getMapper().writeValueAsString(job);
DataWrapper wrapper = new DataWrapper(configuration.getPartitionKey(), jobId.toString(), job.jobAuthorization().state().name(), serializedJob);
if (validator != null) {
PortabilityJob previousJob = findJob(jobId);
if (previousJob == null) {
throw new IOException("Could not find record for jobId: " + jobId);
}
validator.validate(previousJob, job);
}
TableOperation insert = TableOperation.insertOrReplace(wrapper);
table.execute(insert);
} catch (JsonProcessingException | StorageException | URISyntaxException e) {
throw new IOException("Error updating job: " + jobId, e);
}
}
use of org.datatransferproject.spi.cloud.types.PortabilityJob in project data-transfer-project by google.
the class GoogleJobStore method updateJob.
/**
* Verifies a {@code PortabilityJob} already exists for {@code jobId}, and updates the entry to
* {@code job}, within a {@code Transaction}. If {@code validator} is non-null,
* validator.validate() is called first in the transaction.
*
* @throws IOException if a job didn't already exist for {@code jobId} or there was a problem
* updating it @throws IllegalStateException if validator.validate() failed
*/
@Override
protected void updateJob(UUID jobId, PortabilityJob job, JobUpdateValidator validator) throws IOException {
Preconditions.checkNotNull(jobId);
Transaction transaction = datastore.newTransaction();
Key key = getJobKey(jobId);
try {
Entity previousEntity = transaction.get(key);
if (previousEntity == null) {
throw new IOException("Could not find record for jobId: " + jobId);
}
if (validator != null) {
PortabilityJob previousJob = PortabilityJob.fromMap(getProperties(previousEntity));
validator.validate(previousJob, job);
}
Entity newEntity = createUpdatedEntity(key, job.toMap());
transaction.put(newEntity);
transaction.commit();
} catch (Throwable t) {
transaction.rollback();
throw new IOException("Failed atomic update of jobId: " + jobId, t);
}
}
use of org.datatransferproject.spi.cloud.types.PortabilityJob in project data-transfer-project by google.
the class LocalJobStore method updateJob.
/**
* Verifies a {@code PortabilityJob} already exists for {@code jobId}, and updates the entry to
* {@code job}. If {@code validator} is non-null, validator.validate() is called first, as part of
* the atomic update.
*
* @throws IOException if a job didn't already exist for {@code jobId} or there was a problem
* updating it
* @throws IllegalStateException if validator.validate() failed
*/
@Override
protected synchronized void updateJob(UUID jobId, PortabilityJob job, JobUpdateValidator validator) throws IOException {
Preconditions.checkNotNull(jobId);
try {
Map<String, Object> previousEntry = JOB_MAP.replace(jobId, job.toMap());
if (previousEntry == null) {
throw new IOException("jobId: " + jobId + " didn't exist in the map");
}
if (validator != null) {
PortabilityJob previousJob = PortabilityJob.fromMap(previousEntry);
validator.validate(previousJob, job);
}
} catch (NullPointerException | IllegalStateException e) {
throw new IOException("Couldn't update jobId: " + jobId, e);
}
}
Aggregations