Skip to content

Commit

Permalink
Fixes bug when syncing others issues : project_id wasn't used and lead
Browse files Browse the repository at this point in the history
to failure if multiples projects are on the same DB
  • Loading branch information
jrrdev committed Aug 20, 2016
1 parent 3951038 commit ae3fe64
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public IssueData read() throws Exception, UnexpectedInputException,
}

if (issues == null) {
issues = getDao().getNotClosedIssuesId(jobStartTime);
issues = getDao().getNotClosedIssuesId(jobStartTime, getProjectId());
index = 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public interface IssuesDao {
* Time used for filtering
* @return the list of issues ids
*/
public List<BigInteger> getNotClosedIssuesId(Calendar jobStartTime);
public List<BigInteger> getNotClosedIssuesId(Calendar jobStartTime, BigInteger projectId);

/**
* Evict all caches.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public class JdbcIssuesService implements IssuesDao {
*/
private static final String SQL_GET_NOT_CLOSED_ISSUES_ID = "SELECT bug.id FROM mantis_bug_table bug\n"
+ " WHERE bug.status_id <> 90\n"
+ " AND bug.last_sync <= ?";
+ " AND bug.last_sync <= ?"
+ " AND bug.project_id = ?";

/**
* JDBC template.
Expand Down Expand Up @@ -295,12 +296,12 @@ public boolean insertIntoCustomFieldProjectIfNotExists(final ObjectRef item,

/**
* {@inheritDoc}
* @see com.github.jrrdev.mantisbtsync.core.services.IssuesDao#getNotClosedIssuesId(java.sql.Date)
* @see com.github.jrrdev.mantisbtsync.core.services.IssuesDao#getNotClosedIssuesId(java.sql.Date, BigInteger)
*/
@Override
public List<BigInteger> getNotClosedIssuesId(final Calendar jobStartTime) {
public List<BigInteger> getNotClosedIssuesId(final Calendar jobStartTime, final BigInteger projectId) {
final java.sql.Timestamp time = new java.sql.Timestamp(jobStartTime.getTimeInMillis());
return jdbcTemplate.queryForList(SQL_GET_NOT_CLOSED_ISSUES_ID, BigInteger.class, time);
return jdbcTemplate.queryForList(SQL_GET_NOT_CLOSED_ISSUES_ID, BigInteger.class, time, projectId);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import biz.futureware.mantis.rpc.soap.client.ObjectRef;

import com.github.jrrdev.mantisbtsync.core.junit.AbstractSqlWriterTest;
import com.github.jrrdev.mantisbtsync.core.services.IssuesDao;
import com.ninja_squad.dbsetup.operation.Operation;

/**
Expand Down Expand Up @@ -365,6 +364,7 @@ public void testGetNotClosedIssuesId() {
insertInto("mantis_project_table")
.columns("id", "name")
.values(1, "project_1")
.values(2, "project_2")
.build(),

insertInto("mantis_enum_status")
Expand All @@ -378,13 +378,14 @@ public void testGetNotClosedIssuesId() {
.values(1, 1, "sum", before, 1)
.values(2, 1, "sum", after, 1)
.values(3, 1, "sum", before, 90)
.values(4, 2, "sum", before, 1)
.build());

lauchOperation(op);

cal.add(Calendar.MINUTE, 5);

final List<BigInteger> list = dao.getNotClosedIssuesId(cal);
final List<BigInteger> list = dao.getNotClosedIssuesId(cal, BigInteger.ONE);
assertEquals(1, list.size());
assertEquals(BigInteger.ONE, list.get(0));
}
Expand Down

0 comments on commit ae3fe64

Please sign in to comment.