public String getHeadCSV() {
return "user;file;file2;user2;weigth";
}
private EntityMatrix generateMatrix() {
EntityMatrix matrix = new EntityMatrix();
matrix.setStarted(new Date());
matrix.getParams().put("matrixBeginDate", beginDate);
matrix.getParams().put("matrixEndDate", endDate);
List<AuxUserFileFileUserDirectional> result = new ArrayList<>();
List<String> filesName = getFilesName();
String prefix = getPrefixFile();
String suffix = getSuffixFile();
// select a issue/pullrequest comments
List<EntityIssue> issuesCommenteds;
if (!filesName.isEmpty()) {
String jpql = "SELECT DISTINCT i "
+ "FROM "
+ "EntityPullRequest p JOIN p.issue i JOIN p.repositoryCommits rc JOIN rc.files f "
+ "WHERE "
+ "p.repository = :repo AND "
+ "p.createdAt BETWEEN :beginDate AND :endDate AND "
+ "i.commentsCount > 1 AND "
+ "f.filename IN :filesName";
System.out.println(jpql);
issuesCommenteds = dao.selectWithParams(jpql,
new String[]{"repo", "beginDate", "endDate", "filesName"},
new Object[]{getRepository(), beginDate, endDate, filesName});
} else if (prefix.length() > 1 || suffix.length() > 1) {
String jpql = "SELECT DISTINCT i "
+ "FROM "
+ "EntityPullRequest p JOIN p.issue i JOIN p.repositoryCommits rc JOIN rc.files f "
+ "WHERE "
+ "p.repository = :repo AND "
+ "p.createdAt BETWEEN :beginDate AND :endDate AND "
+ "i.commentsCount > 1 "
+ (prefix.length() > 1 ? " AND f.filename LIKE :prefix " : "")
+ (suffix.length() > 1 ? " AND f.filename LIKE :suffix " : "");
System.out.println(jpql);
issuesCommenteds = dao.selectWithParams(jpql,
new String[]{"repo",
"beginDate",
"endDate",
(prefix.length() > 1 ? "prefix " : "#none#"),
(suffix.length() > 1 ? "suffix" : "#none#")},
new Object[]{getRepository(),
beginDate,
endDate,
prefix,
suffix});
} else {
String jpql = "SELECT DISTINCT i "
+ "FROM "
+ "EntityPullRequest p JOIN p.issue i "
+ "WHERE "
+ "p.repository = :repo AND "
+ "p.createdAt BETWEEN :beginDate AND :endDate AND "
+ "i.commentsCount > 1 ";
System.out.println(jpql);
issuesCommenteds = dao.selectWithParams(jpql,
new String[]{"repo", "beginDate", "endDate"},
new Object[]{getRepository(), beginDate, endDate});
}
out.printLog("Issues comentadas: " + issuesCommenteds.size());
int count = 1;
for (EntityIssue issue : issuesCommenteds) {
out.printLog("##################### NR: " + issue.getNumber() + " URL: " + issue.getUrl());
out.printLog(count + " of the " + issuesCommenteds.size());
String jpql = "SELECT p "
+ " FROM EntityPullRequest p "
+ " WHERE p.repository = :repo "
+ " AND p.issue = :issue ";
EntityPullRequest pr = dao.selectOneWithParams(jpql,
new String[]{"repo", "issue"},
new Object[]{getRepository(), issue});
if (pr.getRepositoryCommits().isEmpty()) {
continue;
}
out.printLog(pr.getRepositoryCommits().size() + " commits in pull request ");
List<EntityCommitFile> commitFiles = new ArrayList();
for (EntityRepositoryCommit comm : pr.getRepositoryCommits()) {
if (comm.getFiles().size() <= getMaxFilesPerCommit()) {
commitFiles.addAll(comm.getFiles());
}
}
out.printLog(commitFiles.size() + " files in pull request ");
Set<AuxFileFile> tempResultFiles = new HashSet<>();
for (int i = 0; i < commitFiles.size(); i++) {
EntityCommitFile file1 = commitFiles.get(i);
for (int j = i + 1; j < commitFiles.size(); j++) {
EntityCommitFile file2 = commitFiles.get(j);
if (!file1.equals(file2)
&& !Util.stringEquals(file1.getFilename(), file2.getFilename())) {
tempResultFiles.add(new AuxFileFile(file1.getFilename(), file2.getFilename()));
}
}
}
commitFiles.clear();
jpql = "SELECT c "
+ " FROM EntityComment c "
+ " WHERE c.issue = :issue "
+ " ORDER BY c.createdAt ";
System.out.println(jpql);
List<EntityComment> comments = dao.selectWithParams(jpql,
new String[]{"issue"},
new Object[]{issue});
out.printLog(comments.size() + " comments");
List<AuxUserUserDirectional> tempResultUsers = new ArrayList<>();
for (int k = 0; k < comments.size(); k++) {
EntityComment iCom = comments.get(k);
for (int l = k - 1; l >= 0; l--) {
EntityComment jCom = comments.get(l);
if (iCom.getUser().equals(jCom.getUser())) {
break;
}
boolean contem = false;
AuxUserUserDirectional aux = new AuxUserUserDirectional(
iCom.getUser().getLogin(),
iCom.getUser().getEmail(),
jCom.getUser().getLogin(),
jCom.getUser().getEmail());
for (AuxUserUserDirectional a : tempResultUsers) {
if (a.equals(aux)) {
a.inc();
contem = true;
break;
}
}
if (!contem) {
tempResultUsers.add(aux);
}
}
}
comments.clear();
for (AuxUserUserDirectional users : tempResultUsers) {
for (AuxFileFile files : tempResultFiles) {
AuxUserFileFileUserDirectional aux = new AuxUserFileFileUserDirectional(
users.getUser(),
files.getFileName(),
files.getFileName2(),
users.getUser2(),
users.getWeigth());
boolean contem = false;
for (AuxUserFileFileUserDirectional a : result) {
if (a.equals(aux)) {
a.inc();
contem = true;
break;
}
}
if (!contem) {
result.add(aux);
}
}
}
count++;
out.printLog("Temp user result: " + result.size());
}
matrix.setNodes(objectsToNodes(result));
result.clear();
return matrix;
}