bump product version to 4.1.6.2
[LibreOffice.git] / qadevOOo / runner / stats / ComplexDataBaseOutProducer.java
blob386ec11ca844200f0aceac3723e77204883697db
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package stats;
20 import share.LogWriter;
21 import java.text.DecimalFormat;
22 import java.util.HashMap;
23 import java.util.Calendar;
24 import java.util.GregorianCalendar;
26 /**
30 public class ComplexDataBaseOutProducer extends DataBaseOutProducer {
32 /** Creates a new instance of ComplexDataBaseOutProducer */
33 public ComplexDataBaseOutProducer(HashMap<String,String> param) {
34 super(param);
35 // do we have to write debug output?
36 Object o = param.get("DebugIsActive");
37 if (o != null) {
38 if (o instanceof String) {
39 String debug = (String)o;
40 m_bDebug = (debug.equalsIgnoreCase("yes") || debug.equalsIgnoreCase("true"));
45 String testBase = (String)mSqlInput.get("TestBase");
46 String apiVersion = (String)mSqlInput.get("Version");
47 String os = (String)mSqlInput.get("OperatingSystem");
48 if (testBase == null || apiVersion == null || os == null) {
49 System.err.println("The ComplexDataBaseOutProducer constructor needs this parameters to work correctly:");
50 System.err.println("TestBase - " + testBase);
51 System.err.println("Version - " + apiVersion);
52 System.err.println("OperatingSystem - " + os);
53 System.err.println("Add the missing parameter.");
55 int sep = testBase.indexOf('_');
56 String testLanguage = testBase.substring(0,sep);
57 testBase = testBase.substring(sep+1);
59 // 2do fallback?
60 // if (os == null || os.equals(""))
61 // os = System.getProperty("os.name");
62 String descriptionString = testLanguage+":"+ os +":"+testBase+":"+apiVersion;
63 if (apiVersion != null)
64 apiVersion = apiVersion.substring(0, 6);
66 if (mSqlInput.get("date") == null) {
67 // build date if it's not there
68 Calendar cal = new GregorianCalendar();
69 DecimalFormat dfmt = new DecimalFormat("00");
70 String year = Integer.toString(cal.get(GregorianCalendar.YEAR));
71 // month is starting with "0"
72 String month = dfmt.format(cal.get(GregorianCalendar.MONTH) + 1);
73 String day = dfmt.format(cal.get(GregorianCalendar.DATE));
74 String dateString = year + "-" + month + "-" + day;
76 mSqlInput.put("date", dateString);
78 mSqlInput.put("test_run_description", descriptionString);
79 mSqlInput.put("api_version_name", apiVersion);
80 setWriteableEntryTypes(new String[]{"unit", "method"});
83 /**
84 * Prepare the database.
85 * @parameter log A log writer
86 * @return True, if everything worked.
88 protected boolean prepareDataBase(LogWriter log) {
89 executeSQLCommand("SELECT id AS \"test_run.id\", api_version_id, description, date FROM test_run" +
90 " WHERE date = \"$date\" AND description = \"$test_run_description\";", true);
91 String id = (String)mSqlInput.get("test_run.id");
92 // create an entry for this test run
93 if (id == null) {
94 executeSQLCommand("SELECT id as api_version_id FROM api_version" +
95 " WHERE version = \"$api_version_name\";", true);
96 String api_version_id = (String)mSqlInput.get("api_version_id");
97 // create an entry for this API
98 if (api_version_id == null) {
99 executeSQLCommand("INSERT api_version (api_name, version)" +
100 " VALUES (\"soapi\", \"$api_version_name\")");
101 executeSQLCommand("SELECT id as api_version_id FROM api_version" +
102 " WHERE version = \"$api_version_name\";", true);
104 executeSQLCommand("INSERT test_run (api_version_id, description, date)" +
105 " VALUES ($api_version_id, \"$test_run_description\", \"$date\");");
106 executeSQLCommand("SELECT id AS \"test_run.id\", api_version_id, description, date FROM test_run" +
107 " WHERE date = \"$date\" AND description = \"$test_run_description\";", true);
109 return true;
113 * Insert the result of the test of an entry into the database.
114 * @parameter log A log writer
115 * @return True, if everything worked.
117 protected boolean insertEntry(LogWriter log) {
119 if ( m_bDebug ) {
120 System.out.println("DEBUG - ComplexDataBaseOutProducer: entry.id has to be null: " + (mSqlInput.get("entry.id")==null));
121 System.out.println("DEBUG - ComplexDataBaseOutProducer: EntryLongName: " + mSqlInput.get("EntryLongName"));
123 executeSQLCommand("SELECT id as \"entry.id\", name as \"entry.name\" FROM entry WHERE name = \"$EntryLongName\";", true);
125 if (mSqlInput.get("entry.id") == null) {
126 if ( m_bDebug ) {
127 System.out.println("DEBUG - ComplexDataBaseOutProducer: No entry.id found, this is a new entry in the database.");
129 executeSQLCommand("INSERT entry (name, type)" +
130 " VALUES (\"$EntryLongName\", \"$EntryType\");");
131 executeSQLCommand("SELECT id as \"entry.id\", name as \"entry.name\" FROM entry WHERE name = \"$EntryLongName\";", true);
135 executeSQLCommand("SELECT id as \"api_entry.id\", api_version_id as \"api_entry.api_version_id\", entry_id as \"api_entry.entry_id\" FROM api_entry" +
136 " WHERE entry_id = $entry.id;", true);
137 if (mSqlInput.get("api_entry.id") == null) {
138 System.out.println("No api_entry.id found");
139 executeSQLCommand("INSERT api_entry (entry_id, api_version_id)"+
140 " VALUES ($entry.id, $api_version_id);");
141 executeSQLCommand("SELECT id as \"api_entry.id\", api_version_id as \"api_entry.api_version_id\", entry_id as \"api_entry.entry_id\" FROM api_entry" +
142 " WHERE entry_id = $entry.id;", true);
146 executeSQLCommand("SELECT status as \"test_state.status\" FROM test_state"+
147 " WHERE test_run_id = $test_run.id AND entry_id = $entry.id;", true);
149 String entryState = (String)mSqlInput.get("EntryState");
150 String status = (String)mSqlInput.get("test_state.status");
152 if (!entryState.equals("SKIPPED.FAILED")) { // occurs in case of misspellings: do not make an database entry.
153 if (status == null) {
154 executeSQLCommand("INSERT test_state (test_run_id, entry_id, status)"+
155 " VALUES ($test_run.id, $entry.id, \"$EntryState\");");
157 else {
158 executeSQLCommand("UPDATE test_state SET status = \"$EntryState\""+
159 " where test_run_id =$test_run.id AND entry_id = $entry.id;");
162 return true;
165 public Object getWatcher() {
166 return null;
169 public void setWatcher(Object watcher) {