|
|
@@ -4,9 +4,12 @@ import nju.seec.SEECdemo.data.dao.assignment.CodeDAO;
|
|
|
import nju.seec.SEECdemo.data.dao.assignment.CodeResultDAO;
|
|
|
import nju.seec.SEECdemo.data.entity.assignment.Code;
|
|
|
import nju.seec.SEECdemo.data.entity.assignment.CodeResult;
|
|
|
-import nju.seec.SEECdemo.data.entity.Group;
|
|
|
+import nju.seec.SEECdemo.logic.service.impl.assignment.mock.MockGroup;
|
|
|
import nju.seec.SEECdemo.logic.api.GitlabApi;
|
|
|
import nju.seec.SEECdemo.logic.api.JenkinsApi;
|
|
|
+import nju.seec.SEECdemo.logic.service.impl.assignment.mock.MockQuestion;
|
|
|
+import nju.seec.SEECdemo.logic.service.impl.assignment.stub.GroupServiceStub;
|
|
|
+import nju.seec.SEECdemo.logic.service.impl.assignment.stub.QuestionServiceStub;
|
|
|
import nju.seec.SEECdemo.logic.storage.StorageProvider;
|
|
|
import nju.seec.SEECdemo.util.enums.AssignmentStatus;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
@@ -21,9 +24,6 @@ import java.io.ByteArrayInputStream;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.nio.file.Files;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
|
|
|
@Component
|
|
|
public class AssignmentPaperBuilder {
|
|
|
@@ -37,10 +37,11 @@ public class AssignmentPaperBuilder {
|
|
|
private final StorageProvider storageProvider;
|
|
|
|
|
|
private final QuestionServiceStub questionServiceStub;
|
|
|
+ private final GroupServiceStub groupServiceStub;
|
|
|
|
|
|
@Autowired
|
|
|
public AssignmentPaperBuilder(GitlabApi gitlabApi, GitHelper helper, JenkinsApi jenkinsApi, CodeDAO codeDAO, CodeResultDAO codeResultDAO, StorageProvider storageProvider,
|
|
|
- QuestionServiceStub questionServiceStub){
|
|
|
+ QuestionServiceStub questionServiceStub, GroupServiceStub groupServiceStub){
|
|
|
this.gitlabApi = gitlabApi;
|
|
|
this.helper = helper;
|
|
|
this.jenkinsApi = jenkinsApi;
|
|
|
@@ -48,6 +49,7 @@ public class AssignmentPaperBuilder {
|
|
|
this.codeResultDAO = codeResultDAO;
|
|
|
this.storageProvider = storageProvider;
|
|
|
this.questionServiceStub = questionServiceStub;
|
|
|
+ this.groupServiceStub = groupServiceStub;
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
|
@@ -59,21 +61,21 @@ public class AssignmentPaperBuilder {
|
|
|
releaseQuestion(code.getQuestionId(), tempDir);
|
|
|
code.setInitHash(helper.push(tempDir, code.getUuid()));
|
|
|
// 为群组创建项目,并将组员加入到项目中
|
|
|
- for(Group group:code.getCourse().getGroupSet()){
|
|
|
- int projectId = gitlabApi.forkProject(group.getMemberSet().iterator().next().getId(), code.getId(), group.getNamespace());
|
|
|
+ for(MockGroup group: groupServiceStub.getGroupListByCourse(code.getCourseId())){
|
|
|
+ int projectId = gitlabApi.forkProject(group.getMemberSet().iterator().next(), code.getId(), group.getNamespace());
|
|
|
CodeResult codeResult = new CodeResult();
|
|
|
codeResult.setId(projectId);
|
|
|
- codeResult.setGroup(group);
|
|
|
+ codeResult.setGroupId(group.getId());
|
|
|
codeResult.setCode(code);
|
|
|
// TODO
|
|
|
// 创建jenkins上的构建job
|
|
|
- String buildJob = group.getName() + "-" + projectId + "-build";
|
|
|
+ String buildJob = projectId + "-build";
|
|
|
jenkinsApi.createBuildJob(buildJob);
|
|
|
codeResult.setBuildJob(buildJob);
|
|
|
// 调用kube Api创建该项目的应用空间,并记录其id
|
|
|
|
|
|
// 创建jenkins上的测试job
|
|
|
- String testJob = group.getName() + "-" + projectId + "-test";
|
|
|
+ String testJob = projectId + "-test";
|
|
|
jenkinsApi.createTestJob(testJob);
|
|
|
codeResult.setTestJob(testJob);
|
|
|
codeResultDAO.save(codeResult);
|
|
|
@@ -88,10 +90,10 @@ public class AssignmentPaperBuilder {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void releaseQuestion(int questionId, File codeDir) throws IOException {
|
|
|
+ private void releaseQuestion(Long questionId, File codeDir) throws IOException {
|
|
|
FileUtils.cleanDirectory(codeDir);
|
|
|
- String problemName = questionServiceStub.getQuestionUniqueName(questionId);
|
|
|
- byte[] content = storageProvider.fetch(problemName + ".zip");
|
|
|
+ MockQuestion question = questionServiceStub.getQuestion(questionId);
|
|
|
+ byte[] content = storageProvider.fetch(question.getUniqueName() + ".zip");
|
|
|
ByteArrayInputStream inputStream = new ByteArrayInputStream(content);
|
|
|
ZipUtil.unpack(inputStream, codeDir);
|
|
|
}
|