use of teammates.client.scripts.util.LoopHelper in project teammates by TEAMMATES.
the class DataMigrationBaseScript method doOperation.
@Override
protected void doOperation() {
List<T> entities = getEntities();
if (entities.isEmpty()) {
println("There is nothing to migrate.");
return;
}
int numberOfAffectedEntities = 0;
int numberOfUpdatedEntities = 0;
String entityType = getEntityType(entities.get(0));
LoopHelper loopHelper = new LoopHelper(100, entityType + "s processed.");
println("Running " + getClass().getName() + "...");
println("Preview: " + isPreview());
for (T entity : entities) {
loopHelper.recordLoop();
boolean isMigrationNeeded = isMigrationNeeded(entity);
if (!isMigrationNeeded) {
continue;
}
numberOfAffectedEntities++;
if (isPreview()) {
printPreviewInformation(entity);
continue;
}
try {
migrate(entity);
numberOfUpdatedEntities++;
} catch (Exception e) {
println("Problem migrating " + getEntityInfo(entity));
println(e.getMessage());
}
}
postAction();
println("Total number of " + entityType + "s: " + loopHelper.getCount());
println("Number of affected " + entityType + "s: " + numberOfAffectedEntities);
println("Number of updated " + entityType + "s: " + numberOfUpdatedEntities);
}
use of teammates.client.scripts.util.LoopHelper in project teammates by TEAMMATES.
the class DataMigrationForFeedbackResponseCommentSearchDocument method postAction.
/**
* {@inheritDoc}
*/
@Override
protected void postAction() {
if (isPreview()) {
return;
}
LoopHelper loopHelper = new LoopHelper(BATCH_SIZE, "documents processed.");
List<Document> documentsToUpdate = new ArrayList<>();
for (FeedbackResponseCommentAttributes comment : commentsToMigrate) {
loopHelper.recordLoop();
documentsToUpdate.add(new FeedbackResponseCommentSearchDocument(comment).build());
if (documentsToUpdate.size() == BATCH_SIZE) {
updateAndClearDocuments(documentsToUpdate);
}
}
updateAndClearDocuments(documentsToUpdate);
}
use of teammates.client.scripts.util.LoopHelper in project teammates by TEAMMATES.
the class DataMigrationForOrphanedCommentSearchDocuments method postAction.
@Override
protected void postAction() {
println("Number of documents in the old format that have existing parent comments: " + numOfDocumentsNotDeleted);
if (numOfDocumentsNotDeleted > 0) {
println("Warning: these documents will not be deleted. Please run the other migration script again.");
}
if (isPreview()) {
return;
}
LoopHelper loopHelper = new LoopHelper(BATCH_SIZE, "documents processed.");
List<Document> batch = new ArrayList<>(BATCH_SIZE);
for (Document document : documentsToDelete) {
loopHelper.recordLoop();
batch.add(document);
if (batch.size() == BATCH_SIZE) {
batchDeleteAndClear(batch);
}
}
batchDeleteAndClear(batch);
}
Aggregations