Search in sources :

Example 1 with LoopHelper

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);
}
Also used : LoopHelper(teammates.client.scripts.util.LoopHelper)

Example 2 with LoopHelper

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);
}
Also used : FeedbackResponseCommentSearchDocument(teammates.storage.search.FeedbackResponseCommentSearchDocument) FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) LoopHelper(teammates.client.scripts.util.LoopHelper) ArrayList(java.util.ArrayList) Document(com.google.appengine.api.search.Document) FeedbackResponseCommentSearchDocument(teammates.storage.search.FeedbackResponseCommentSearchDocument)

Example 3 with LoopHelper

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);
}
Also used : LoopHelper(teammates.client.scripts.util.LoopHelper) ArrayList(java.util.ArrayList) Document(com.google.appengine.api.search.Document) ScoredDocument(com.google.appengine.api.search.ScoredDocument)

Aggregations

LoopHelper (teammates.client.scripts.util.LoopHelper)3 Document (com.google.appengine.api.search.Document)2 ArrayList (java.util.ArrayList)2 ScoredDocument (com.google.appengine.api.search.ScoredDocument)1 FeedbackResponseCommentAttributes (teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes)1 FeedbackResponseCommentSearchDocument (teammates.storage.search.FeedbackResponseCommentSearchDocument)1