Skip to content

Commit 47c0b3b

Browse files
committed
Fix review chages
1 parent 586f0a9 commit 47c0b3b

File tree

2 files changed

+20
-26
lines changed

2 files changed

+20
-26
lines changed

core/src/main/java/org/wso2/testgrid/core/command/FinalizeRunTestplan.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ public void execute() throws CommandExecutionException {
141141
}
142142
updateProductStatus();
143143
} catch (IOException e) {
144-
logger.error("Error occurred while trying to read " + testPlanYamlFilePath);
144+
logger.error("Error occurred while trying to read " + testPlanYamlFilePath, e);
145145
} catch (TestGridDAOException e) {
146-
logger.error("Error while fetching test plan from database.");
146+
logger.error("Error while fetching test plan from database.", e);
147147
} catch (TestGridException e) {
148-
logger.error("Error occured while updating the product status.");
148+
logger.error("Error occured while updating the product status.", e);
149149
}
150150
}
151151

@@ -168,7 +168,7 @@ private void persistTestPlan(TestPlan testPlan) {
168168
*
169169
*/
170170
private void updateProductStatus() throws TestGridException {
171-
Path source = Paths.get(workspace + "/test-plans");
171+
Path source = Paths.get(workspace, "test-plans");
172172
String productId;
173173
Boolean isCompleteBuild = true;
174174
try (Stream<Path> stream = Files.list(source).filter(Files::isRegularFile)) {
@@ -200,9 +200,9 @@ private void updateProductStatus() throws TestGridException {
200200
}
201201
}
202202
} catch (TestGridDAOException e) {
203-
logger.error("Error occured when updating the product table of TG");
203+
logger.error("Error occured when updating the product table of TG", e);
204204
} catch (IOException e) {
205-
logger.error("Error occured when reading a test plan yaml file");
205+
logger.error("Error occured when reading a test plan yaml file", e);
206206
}
207207
}
208208
}

dao/src/main/java/org/wso2/testgrid/dao/repository/ProductRepository.java

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -153,31 +153,25 @@ private List<ProductTestStatus> getProductTestStatuses(List<Object[]> results) {
153153
/**
154154
* This method updates the last_success_timestamp column or last_failure_timestamp column with given timestamp.
155155
* The column is selected by considering product status.
156+
* ex:- UPDATE product SET last_failure_timestamp = <timestamp> where id = <product_id>;
156157
*
157158
* @param status Status of the product
158159
* @param timestamp Current timestamp
159160
* @param productId Id of the product
160161
*/
161-
public void updateProductStatusTimestamp(Status status, Date timestamp, String productId)
162-
throws TestGridDAOException {
163-
try {
164-
String queryStr = "UPDATE product SET ";
165-
if (status.equals(Status.SUCCESS)) {
166-
queryStr += "last_success_timestamp = ";
167-
} else if (status.equals(Status.FAIL)) {
168-
queryStr += "last_failure_timestamp = ";
169-
}
170-
queryStr += "'" + timestamp + "' where id = '" + productId + "';";
171-
172-
// Begin entity manager transaction
173-
entityManager.getTransaction().begin();
174-
175-
entityManager.createNativeQuery(queryStr).executeUpdate();
176-
177-
// Commit transaction
178-
entityManager.getTransaction().commit();
179-
} catch (Exception e) {
180-
throw new TestGridDAOException("Error on executing the native SQL query to update product table.", e);
162+
public void updateProductStatusTimestamp(Status status, Date timestamp, String productId) {
163+
String queryStr = "UPDATE product SET ";
164+
if (status.equals(Status.SUCCESS)) {
165+
queryStr += "last_success_timestamp = ";
166+
} else if (status.equals(Status.FAIL)) {
167+
queryStr += "last_failure_timestamp = ";
181168
}
169+
170+
// Begin entity manager transaction
171+
entityManager.getTransaction().begin();
172+
entityManager.createNativeQuery(
173+
StringUtil.concatStrings(queryStr, "'", timestamp, "' where id = '", productId, "';")).executeUpdate();
174+
// Commit transaction
175+
entityManager.getTransaction().commit();
182176
}
183177
}

0 commit comments

Comments
 (0)