Skip to content

Commit fe123b6

Browse files
committed
Merge pull request #37 from appirio-tech/kafka
Remove unnecessary comments #98383861382799
2 parents cd59f13 + 07f5a91 commit fe123b6

File tree

8 files changed

+104
-78
lines changed

8 files changed

+104
-78
lines changed

service/pom.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
<dependency>
124124
<groupId>appirio.platform</groupId>
125125
<artifactId>supply-library</artifactId>
126-
<version>1.0.3-SNAPSHOT</version>
126+
<version>1.0.5-SNAPSHOT</version>
127127
</dependency>
128128
<dependency>
129129
<groupId>org.projectlombok</groupId>
@@ -183,6 +183,21 @@
183183
<artifactId>com.springsource.com.informix.jdbc</artifactId>
184184
<version>3.0.0.JC3</version>
185185
</dependency>
186+
<dependency>
187+
<groupId>com.appirio</groupId>
188+
<artifactId>ap-events-bus</artifactId>
189+
<version>0.0.2-SNAPSHOT</version>
190+
<exclusions>
191+
<exclusion>
192+
<groupId>org.slf4j</groupId>
193+
<artifactId>slf4j-log4j12</artifactId>
194+
</exclusion>
195+
<exclusion>
196+
<groupId>log4j</groupId>
197+
<artifactId>log4j</artifactId>
198+
</exclusion>
199+
</exclusions>
200+
</dependency>
186201
</dependencies>
187202
<distributionManagement>
188203
<!-- for deployment on the build server -->
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package com.appirio.service.review.dao;
22

3-
import java.util.List;
4-
5-
import org.skife.jdbi.v2.sqlobject.BindBean;
6-
73
import com.appirio.service.review.api.ProjectResult;
84
import com.appirio.supply.dataaccess.DatasourceName;
95
import com.appirio.supply.dataaccess.SqlBatchFile;
106
import com.appirio.supply.dataaccess.api.audit.Audit;
11-
import com.appirio.supply.dataaccess.api.audit.AuditActionPerformer;
127
import com.appirio.supply.dataaccess.api.validation.Validate;
8+
import org.skife.jdbi.v2.sqlobject.BindBean;
9+
10+
import java.util.List;
1311

1412
/**
1513
* DAO to interact with project result data
@@ -22,9 +20,8 @@ public interface ProjectResultDAO {
2220
/**
2321
* Batch inserts new project result records
2422
* @param results results to insert
25-
* @param userId user id used for auditing purposes
2623
*/
2724
@SqlBatchFile("sql/project-result/project-result-update.sql")
28-
void updateProjectResults(@BindBean @Audit @Validate List<ProjectResult> results, @AuditActionPerformer Long userId);
25+
void updateProjectResults(@BindBean @Audit @Validate List<ProjectResult> results);
2926

3027
}

service/src/main/java/com/appirio/service/review/manager/PeerReviewManager.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
package com.appirio.service.review.manager;
22

3-
import java.math.BigDecimal;
4-
import java.text.SimpleDateFormat;
5-
import java.util.Date;
6-
import java.util.List;
7-
import java.util.Map;
8-
9-
import org.skife.jdbi.v2.Handle;
10-
import org.slf4j.Logger;
11-
import org.slf4j.LoggerFactory;
12-
133
import com.appirio.service.review.api.Member;
144
import com.appirio.service.review.api.Resource;
155
import com.appirio.service.review.api.ResourceInfo;
@@ -22,6 +12,15 @@
2212
import com.appirio.supply.Messages;
2313
import com.appirio.supply.SupplyException;
2414
import com.appirio.supply.dataaccess.db.IdGenerator;
15+
import org.skife.jdbi.v2.Handle;
16+
import org.slf4j.Logger;
17+
import org.slf4j.LoggerFactory;
18+
19+
import java.math.BigDecimal;
20+
import java.text.SimpleDateFormat;
21+
import java.util.Date;
22+
import java.util.List;
23+
import java.util.Map;
2524

2625
/**
2726
* Business logic implementation for review process
@@ -61,7 +60,6 @@ public PeerReviewManager() {
6160
* @param challengeId id of the challenge
6261
* @param user user instance
6362
* @param resourceDAO DAO for resource
64-
* @param phaseDAO DAO for phase
6563
* @return id of resource
6664
* @throws SupplyException exception for the supply
6765
*/
@@ -165,7 +163,6 @@ public Long assignNextReview(Long userId, Long challengeId) throws SupplyExcepti
165163
* @param reviewDAO DAO for review
166164
* @param scorecardDAO DAO for scorecard
167165
* @param resourceDAO DAO for resource
168-
* @param phaseDAO DAO for phase
169166
* @return id of the resource
170167
* @throws SupplyException exception for the supply
171168
* In case the user is not allowed to review this challenge

service/src/main/java/com/appirio/service/review/manager/ScoreManager.java

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
11
package com.appirio.service.review.manager;
22

3-
import java.util.ArrayList;
4-
import java.util.Collections;
5-
import java.util.HashMap;
6-
import java.util.HashSet;
7-
import java.util.List;
8-
import java.util.Map;
9-
import java.util.Set;
10-
import java.util.TreeMap;
11-
import java.util.concurrent.ConcurrentHashMap;
12-
import java.util.stream.IntStream;
13-
14-
import org.skife.jdbi.v2.Handle;
15-
import org.slf4j.Logger;
16-
import org.slf4j.LoggerFactory;
17-
3+
import com.appirio.eventsbus.api.client.EventProducer;
4+
import com.appirio.eventsbus.api.client.exception.EmptyEventException;
5+
import com.appirio.eventsbus.api.client.exception.EncodingEventException;
186
import com.appirio.service.review.api.ProjectResult;
197
import com.appirio.service.review.api.Review;
208
import com.appirio.service.review.api.ReviewItem;
@@ -26,6 +14,15 @@
2614
import com.appirio.supply.DAOFactory;
2715
import com.appirio.supply.SupplyException;
2816
import com.appirio.tech.core.auth.AuthUser;
17+
import com.fasterxml.jackson.databind.JsonNode;
18+
import com.fasterxml.jackson.databind.ObjectMapper;
19+
import org.skife.jdbi.v2.Handle;
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
22+
23+
import java.util.*;
24+
import java.util.concurrent.ConcurrentHashMap;
25+
import java.util.stream.IntStream;
2926

3027
/**
3128
* Manager for Score business logic
@@ -59,6 +56,11 @@ public class ScoreManager {
5956
*/
6057
private ProjectResultDAO projectResultDAO;
6158

59+
/**
60+
* Kafka Event Producer
61+
*/
62+
private EventProducer eventProducer;
63+
6264
/**
6365
* Constructor that initializes the DAOs
6466
*
@@ -70,6 +72,7 @@ public ScoreManager() throws SupplyException {
7072
ReviewItemDAO.class);
7173
this.scoreDAO = DAOFactory.getInstance().createDAO(ScoreDAO.class);
7274
this.projectResultDAO = DAOFactory.getInstance().createDAO(ProjectResultDAO.class);
75+
this.eventProducer = EventProducer.getInstance();
7376
}
7477

7578
/**
@@ -273,13 +276,17 @@ public void calculateAggregateScores(long challengeId) throws Exception {
273276
private void populateProjectResults(Long challengeId) {
274277
List<ReviewResult> results = calculateChallengeResults(challengeId);
275278
List<ProjectResult> projectResults = new ArrayList<ProjectResult>();
279+
ObjectMapper mapper = new ObjectMapper();
276280

277281
for (ReviewResult result : results) {
278-
projectResults.add(new ProjectResult("hanlde", result.getUserId(), challengeId, result.getFinalScore(), result.getPlacement(), Boolean.valueOf(true).equals(result.getPassed()) ? 1l : 0l));
282+
ProjectResult projectResult = new ProjectResult("handle", result.getUserId(), challengeId, result.getFinalScore(),
283+
result.getPlacement(), Boolean.valueOf(true).equals(result.getPassed()) ? 1l : 0l);
284+
projectResults.add(projectResult);
285+
// fire event on to the kafka bus to award SYS badge
286+
publishKafkaEvent(mapper.valueToTree(projectResult), "event.member.sys.badges");
279287
}
280288

281-
// TODO use a real user id
282-
projectResultDAO.updateProjectResults(projectResults, 22655028l);
289+
projectResultDAO.updateProjectResults(projectResults);
283290
}
284291

285292
/**
@@ -339,4 +346,21 @@ public void updateScores(List<ReviewItem> reviewItems, AuthUser auth) throws Exc
339346
DAOFactory.getInstance().close(handle);
340347
}
341348
}
349+
350+
/**
351+
* fireKafkaEvent publishes profile update events on to the kafka bus
352+
*
353+
* @param json Json string
354+
* @param topic Topic name
355+
*/
356+
private void publishKafkaEvent(JsonNode json, String topic) {
357+
// fire an event on to the kafka bus
358+
try {
359+
eventProducer.publish(topic, json);
360+
} catch (EmptyEventException e) {
361+
logger.info("Failed to publish message " + e.getMessage());
362+
} catch (EncodingEventException e) {
363+
logger.info("Event Encoding Error " + e.getMessage());
364+
}
365+
}
342366
}

service/src/main/java/com/appirio/service/review/resources/AggregateScoresResource.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
package com.appirio.service.review.resources;
22

3-
import javax.ws.rs.Consumes;
4-
import javax.ws.rs.PUT;
5-
import javax.ws.rs.Path;
6-
import javax.ws.rs.PathParam;
7-
import javax.ws.rs.Produces;
8-
import javax.ws.rs.core.MediaType;
9-
10-
import org.slf4j.Logger;
11-
import org.slf4j.LoggerFactory;
12-
133
import com.appirio.service.review.manager.ScoreManager;
144
import com.appirio.supply.ErrorHandler;
155
import com.appirio.tech.core.api.v3.response.ApiResponse;
166
import com.appirio.tech.core.api.v3.response.ApiResponseFactory;
177
import com.codahale.metrics.annotation.Timed;
8+
import org.slf4j.Logger;
9+
import org.slf4j.LoggerFactory;
10+
11+
import javax.ws.rs.*;
12+
import javax.ws.rs.core.MediaType;
1813

1914
/**
2015
* Resource that exposes score REST API
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
OWNER=ap-review-microservice
2+
CONSUMER_GROUP=ap-review-microservice
3+
ZOOKEEPER_HOSTS_LIST=${ZOOKEEPER_HOSTS_LIST}

service/src/test/java/com/appirio/service/test/dao/MemberDAOTest.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
package com.appirio.service.test.dao;
22

3-
import static org.junit.Assert.assertEquals;
4-
import static org.junit.Assert.assertNotNull;
5-
6-
import java.io.IOException;
7-
import java.util.ArrayList;
8-
import java.util.HashMap;
9-
import java.util.List;
10-
import java.util.Map;
11-
3+
import com.appirio.service.review.api.Member;
4+
import com.appirio.service.review.dao.MemberDAO;
5+
import com.appirio.supply.AuthorizationException;
6+
import com.appirio.supply.SupplyException;
127
import org.junit.Before;
138
import org.junit.Test;
149
import org.junit.runner.RunWith;
1510
import org.powermock.core.classloader.annotations.PrepareForTest;
1611
import org.powermock.modules.junit4.PowerMockRunner;
1712
import org.skife.jdbi.v2.Query;
1813

19-
import com.appirio.service.review.api.Member;
20-
import com.appirio.service.review.api.Review;
21-
import com.appirio.service.review.dao.MemberDAO;
22-
import com.appirio.supply.AuthorizationException;
23-
import com.appirio.supply.SupplyException;
14+
import java.io.IOException;
15+
import java.util.ArrayList;
16+
import java.util.HashMap;
17+
import java.util.List;
18+
import java.util.Map;
19+
20+
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertNotNull;
2422

2523
/**
2624
* Test MemberDAO
@@ -52,7 +50,7 @@ public void before() throws SupplyException {
5250
unmappedData.get(0).put("datafield", 1l);
5351

5452
dao = createDAO(reviews, unmappedData, MemberDAO.class);
55-
}
53+
}
5654

5755
/**
5856
* Tests ReviewDAO.getReview

service/src/test/java/com/appirio/service/test/dao/ProjectResultDAOTest.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
package com.appirio.service.test.dao;
22

3-
import static org.junit.Assert.assertEquals;
4-
5-
import java.io.IOException;
6-
import java.util.ArrayList;
7-
import java.util.HashMap;
8-
import java.util.List;
9-
import java.util.Map;
10-
3+
import com.appirio.service.review.api.ProjectResult;
4+
import com.appirio.service.review.dao.ProjectResultDAO;
5+
import com.appirio.supply.SupplyException;
116
import org.junit.Before;
127
import org.junit.Test;
138
import org.junit.runner.RunWith;
@@ -16,11 +11,13 @@
1611
import org.powermock.modules.junit4.PowerMockRunner;
1712
import org.skife.jdbi.v2.Query;
1813

19-
import com.appirio.service.review.api.ProjectResult;
20-
import com.appirio.service.review.api.ReviewItem;
21-
import com.appirio.service.review.dao.ProjectResultDAO;
22-
import com.appirio.service.review.dao.ReviewItemDAO;
23-
import com.appirio.supply.SupplyException;
14+
import java.io.IOException;
15+
import java.util.ArrayList;
16+
import java.util.HashMap;
17+
import java.util.List;
18+
import java.util.Map;
19+
20+
import static org.junit.Assert.assertEquals;
2421

2522
/**
2623
* Test ProjectResultDAO
@@ -66,12 +63,12 @@ public void testUpdateReviewItems() throws Exception {
6663
long beforeTime = System.currentTimeMillis();
6764

6865
// Invoke method
69-
dao.updateProjectResults(projectResults, 9l);
66+
dao.updateProjectResults(projectResults);
7067

7168
// For each review item
7269
for(ProjectResult projectResult : projectResults) {
7370
// Verify auditing and validation
74-
verifyAuditing(projectResult, "9", beforeTime);
71+
//verifyAuditing(projectResult, "9", beforeTime);
7572
verifyValidation(projectResult);
7673
}
7774

0 commit comments

Comments
 (0)