Search in sources :

Example 1 with Sheets

use of com.google.api.services.sheets.v4.Sheets in project repairnator by Spirals-Team.

the class ScannerSerializer method main.

public static void main(String[] args) throws IOException, GeneralSecurityException {
    GoogleSpreadSheetFactory.initWithFileSecret("client_secret.json");
    GoogleSpreadSheetFactory.setSpreadsheetId(args[1]);
    Sheets sheets = GoogleSpreadSheetFactory.getSheets();
    List<List<Object>> results = sheets.spreadsheets().values().get(GoogleSpreadSheetFactory.getSpreadsheetID(), "Scanner Data!A:M").execute().getValues();
    MongoConnection mongoConnection = new MongoConnection(args[0], "repairnator");
    if (!mongoConnection.isConnected()) {
        throw new RuntimeException("Error when connection to mongodb");
    }
    MongoDBSerializerEngine serializerEngine = new MongoDBSerializerEngine(mongoConnection);
    List<SerializedData> data = new ArrayList<>();
    for (int i = 1; i < results.size(); i++) {
        List<Object> value = results.get(i);
        JsonObject result = new JsonObject();
        result.addProperty("hostname", Utils.getValue(value, 0));
        result.addProperty("dateBegin", Utils.getValue(value, 1));
        result.addProperty("dateLimit", Utils.getValue(value, 2));
        result.addProperty("totalRepoNumber", Utils.getValue(value, 3));
        result.addProperty("totalRepoUsingTravis", Utils.getValue(value, 4));
        result.addProperty("totalScannedBuilds", Utils.getValue(value, 5));
        result.addProperty("totalJavaBuilds", Utils.getValue(value, 6));
        result.addProperty("totalJavaPassingBuilds", Utils.getValue(value, 7));
        result.addProperty("totalJavaFailingBuilds", Utils.getValue(value, 8));
        result.addProperty("totalJavaFailingBuildsWithFailingTests", Utils.getValue(value, 9));
        result.addProperty("totalPRBuilds", Utils.getValue(value, 10));
        result.addProperty("dayLimit", Utils.getValue(value, 11));
        result.addProperty("duration", Utils.getValue(value, 12));
        result.addProperty("runId", Utils.getValue(value, 13));
        data.add(new SerializedData(Collections.EMPTY_LIST, result));
    }
    serializerEngine.serialize(data, SerializerType.SCANNER);
}
Also used : ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) SerializedData(fr.inria.spirals.repairnator.serializer.engines.SerializedData) MongoDBSerializerEngine(fr.inria.spirals.repairnator.serializer.engines.json.MongoDBSerializerEngine) ArrayList(java.util.ArrayList) List(java.util.List) JsonObject(com.google.gson.JsonObject) MongoConnection(fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection) Sheets(com.google.api.services.sheets.v4.Sheets)

Example 2 with Sheets

use of com.google.api.services.sheets.v4.Sheets in project repairnator by Spirals-Team.

the class ScannerSerializer4Bears method main.

public static void main(String[] args) throws IOException, GeneralSecurityException {
    GoogleSpreadSheetFactory.initWithFileSecret("client_secret.json");
    GoogleSpreadSheetFactory.setSpreadsheetId(args[1]);
    Sheets sheets = GoogleSpreadSheetFactory.getSheets();
    List<List<Object>> results = sheets.spreadsheets().values().get(GoogleSpreadSheetFactory.getSpreadsheetID(), "Scanner Data!A:M").execute().getValues();
    MongoConnection mongoConnection = new MongoConnection(args[0], "bears");
    if (!mongoConnection.isConnected()) {
        throw new RuntimeException("Error when connection to mongodb");
    }
    MongoDBSerializerEngine serializerEngine = new MongoDBSerializerEngine(mongoConnection);
    List<SerializedData> data = new ArrayList<>();
    for (int i = 1; i < results.size(); i++) {
        List<Object> value = results.get(i);
        JsonObject result = new JsonObject();
        result.addProperty("hostname", Utils.getValue(value, 0));
        result.addProperty("dateBegin", Utils.getValue(value, 1));
        result.addProperty("dateEnd", Utils.getValue(value, 2));
        result.addProperty("duration", Utils.getValue(value, 3));
        result.addProperty("dateLookedFrom", Utils.getValue(value, 4));
        result.addProperty("dateLookedTo", Utils.getValue(value, 5));
        result.addProperty("totalRepoNumber", Utils.getValue(value, 6));
        result.addProperty("totalRepoUsingTravis", Utils.getValue(value, 7));
        result.addProperty("totalScannedBuilds", Utils.getValue(value, 8));
        result.addProperty("totalJavaBuilds", Utils.getValue(value, 9));
        result.addProperty("totalJavaPassingBuilds", Utils.getValue(value, 10));
        result.addProperty("totalJavaFailingBuilds", Utils.getValue(value, 11));
        result.addProperty("totalJavaFailingBuildsWithFailingTests", Utils.getValue(value, 12));
        result.addProperty("totalPRBuilds", Utils.getValue(value, 13));
        result.addProperty("totalFailingAndPassingBuildPairs", Utils.getValue(value, 14));
        result.addProperty("totalPassingAndPassingBuildPairs", Utils.getValue(value, 15));
        result.addProperty("totalPairOfBuilds", Utils.getValue(value, 16));
        result.addProperty("runId", Utils.getValue(value, 17));
        data.add(new SerializedData(Collections.EMPTY_LIST, result));
    }
    serializerEngine.serialize(data, SerializerType.SCANNER4BEARS);
}
Also used : ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) SerializedData(fr.inria.spirals.repairnator.serializer.engines.SerializedData) MongoDBSerializerEngine(fr.inria.spirals.repairnator.serializer.engines.json.MongoDBSerializerEngine) ArrayList(java.util.ArrayList) List(java.util.List) JsonObject(com.google.gson.JsonObject) MongoConnection(fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection) Sheets(com.google.api.services.sheets.v4.Sheets)

Example 3 with Sheets

use of com.google.api.services.sheets.v4.Sheets in project repairnator by Spirals-Team.

the class InspectorTimeSerializer method main.

public static void main(String[] args) throws IOException, GeneralSecurityException {
    GoogleSpreadSheetFactory.initWithFileSecret("client_secret.json");
    GoogleSpreadSheetFactory.setSpreadsheetId(args[1]);
    Sheets sheets = GoogleSpreadSheetFactory.getSheets();
    List<List<Object>> results = sheets.spreadsheets().values().get(GoogleSpreadSheetFactory.getSpreadsheetID(), "Duration Data!A:P").execute().getValues();
    MongoConnection mongoConnection = new MongoConnection(args[0], "repairnator");
    if (!mongoConnection.isConnected()) {
        throw new RuntimeException("Error when connection to mongodb");
    }
    MongoDBSerializerEngine serializerEngine = new MongoDBSerializerEngine(mongoConnection);
    List<SerializedData> data = new ArrayList<>();
    for (int i = 1; i < results.size(); i++) {
        List<Object> value = results.get(i);
        JsonObject result = new JsonObject();
        result.addProperty("buildId", Utils.getValue(value, 0));
        result.addProperty("repositoryName", Utils.getValue(value, 1));
        result.addProperty("buildReproductionDate", Utils.getValue(value, 2));
        result.addProperty("hostname", Utils.getValue(value, 3));
        result.addProperty("totalDuration", Utils.getValue(value, 4));
        result.addProperty("clonage", Utils.getValue(value, 5));
        result.addProperty("checkoutBuild", Utils.getValue(value, 6));
        result.addProperty("build", Utils.getValue(value, 7));
        result.addProperty("test", Utils.getValue(value, 8));
        result.addProperty("gatherTestInfo", Utils.getValue(value, 9));
        result.addProperty("squashRepository", Utils.getValue(value, 10));
        result.addProperty("push", Utils.getValue(value, 11));
        result.addProperty("computeClasspath", Utils.getValue(value, 12));
        result.addProperty("computeSourceDir", Utils.getValue(value, 13));
        result.addProperty("repair", Utils.getValue(value, 14));
        result.addProperty("runId", Utils.getValue(value, 15));
        data.add(new SerializedData(Collections.EMPTY_LIST, result));
    }
    serializerEngine.serialize(data, SerializerType.TIMES);
}
Also used : ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) SerializedData(fr.inria.spirals.repairnator.serializer.engines.SerializedData) MongoDBSerializerEngine(fr.inria.spirals.repairnator.serializer.engines.json.MongoDBSerializerEngine) ArrayList(java.util.ArrayList) List(java.util.List) JsonObject(com.google.gson.JsonObject) MongoConnection(fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection) Sheets(com.google.api.services.sheets.v4.Sheets)

Example 4 with Sheets

use of com.google.api.services.sheets.v4.Sheets in project jbpm-work-items by kiegroup.

the class ReadSheetValuesWorkitemHandler method executeWorkItem.

public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
    Map<String, Object> results = new HashMap<String, Object>();
    String paramSheetId = (String) workItem.getParameter("SheetId");
    // to learn google spreadsheet ranges go to
    // https://developers.google.com/sheets/api/guides/concepts
    String paramRange = (String) workItem.getParameter("Range");
    try {
        Sheets service = auth.getSheetsService(appName, clientSecret);
        ValueRange sheetResponse = service.spreadsheets().values().get(paramSheetId, paramRange).execute();
        List<List<Object>> values = sheetResponse.getValues();
        results.put(RESULTS_VALUES, values);
    } catch (Exception e) {
        handleException(e);
    }
    workItemManager.completeWorkItem(workItem.getId(), results);
}
Also used : ValueRange(com.google.api.services.sheets.v4.model.ValueRange) HashMap(java.util.HashMap) List(java.util.List) Sheets(com.google.api.services.sheets.v4.Sheets)

Example 5 with Sheets

use of com.google.api.services.sheets.v4.Sheets in project repairnator by Spirals-Team.

the class GoogleSpreadSheetFactory method insertData.

public static void insertData(List<List<Object>> dataRows, Sheets sheets, String range, Logger logger) {
    ValueRange valueRange = new ValueRange();
    valueRange.setValues(dataRows);
    try {
        AppendValuesResponse response = sheets.spreadsheets().values().append(GoogleSpreadSheetFactory.getSpreadsheetID(), range, valueRange).setInsertDataOption("INSERT_ROWS").setValueInputOption("USER_ENTERED").execute();
        if (response != null && response.getUpdates().getUpdatedCells() > 0) {
            logger.debug("Data have been inserted in Google Spreadsheet.");
        }
    } catch (IOException e) {
        logger.error("An error occurred while inserting data in Google Spreadsheet.", e);
    }
}
Also used : ValueRange(com.google.api.services.sheets.v4.model.ValueRange) AppendValuesResponse(com.google.api.services.sheets.v4.model.AppendValuesResponse) IOException(java.io.IOException)

Aggregations

Sheets (com.google.api.services.sheets.v4.Sheets)8 List (java.util.List)8 JsonObject (com.google.gson.JsonObject)6 SerializedData (fr.inria.spirals.repairnator.serializer.engines.SerializedData)6 MongoDBSerializerEngine (fr.inria.spirals.repairnator.serializer.engines.json.MongoDBSerializerEngine)6 MongoConnection (fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection)6 ArrayList (java.util.ArrayList)6 ValueRange (com.google.api.services.sheets.v4.model.ValueRange)2 AppendValuesResponse (com.google.api.services.sheets.v4.model.AppendValuesResponse)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1