Skip to content

Commit

Permalink
Merge pull request #2 from Open-MBEE/feature/commits
Browse files Browse the repository at this point in the history
MMS-986, MMS-987, MMS-988 calls and related branch dao changes
  • Loading branch information
HuiJun authored Dec 6, 2018
2 parents efc522b + 410f752 commit 8f900a0
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ public ResponseEntity<? extends BaseResponse> handleRequest(
logger.info("Saving branch: {}", branch.getId());

if (branch.getParentRefId() != null) {
Branch parentRef = branchRepository.findByBranchId(branch.getParentRefId());
b.setParentRef(parentRef);
//Branch parentRef = branchRepository.findByBranchId(branch.getParentRefId());
b.setParentRefId(branch.getParentRefId());
} else {
b.setParentRef(branchRepository.findByBranchId("master"));
b.setParentRefId("master");
}

if (branch.getParentCommitId() != null) {
Commit parentCommit = commitRepository
.findByCommitId(branch.getParentCommitId());
b.setParentCommit(parentCommit);
b.setParentCommit(parentCommit.getId());
} else {
b.setParentCommit(commitRepository.findLatest());
b.setParentCommit(commitRepository.findLatestByRef(b.getParentRefId()).getId());
}

b.setTimestamp(now);
Expand All @@ -76,7 +76,7 @@ public ResponseEntity<? extends BaseResponse> handleRequest(
DbContextHolder.setContext(projectId, saved.getBranchId());
if (branchesOperations.createBranch()) {
branchesOperations.copyTablesFromParent(saved.getBranchId(),
b.getParentRef().getBranchId(), branch.getParentCommitId());
b.getParentRefId(), branch.getParentCommitId());
}
response.getBranches().add(branch);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -22,30 +24,42 @@ public CommitsController(CommitService commitService) {
this.commitService = commitService;
}

@GetMapping(value = "commits")
@GetMapping(value = "/refs/{refId}/commits")
public ResponseEntity<?> handleGet(
@PathVariable String projectId,
@PathVariable String refId,
@RequestParam Map<String, String> params) {

return ResponseEntity.ok(null);
CommitsResponse res = commitService.getRefCommits(projectId, refId, params);
return ResponseEntity.ok(res);
}

@GetMapping(value = "/commits/{commitId}")
public ResponseEntity<?> handleCommitGet(
@PathVariable String projectId,
@PathVariable String commitId) {

return ResponseEntity.ok(null);
CommitsResponse res = commitService.getCommit(projectId, commitId);
return ResponseEntity.ok(res);
}

@GetMapping(value = "/refs/{refId}/elements/{elementId}/commits")
public ResponseEntity<?> handleElementCommitsGet(
@PathVariable String projectId,
@PathVariable String refId,
@PathVariable String elementId,
@RequestParam Map<String, String> params) {
@RequestParam Map<String, Object> params) {

return ResponseEntity.ok(null);
CommitsResponse res = commitService.getElementCommits(projectId, refId, elementId, params);
return ResponseEntity.ok(res);
}

@PutMapping(value = "/commits")
public ResponseEntity<?> handleBulkGet(
@PathVariable String projectId,
@RequestBody CommitsRequest req) {

CommitsResponse res = commitService.getCommits(projectId, req);
return ResponseEntity.ok(res);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.openmbee.sdvc.crud.controllers.commits;

import java.util.List;
import org.openmbee.sdvc.crud.controllers.BaseRequest;

public class CommitsRequest extends BaseRequest {

private List<CommitJson> commits;

public List<CommitJson> getCommits() {
return commits;
}

public void setCommits(List<CommitJson> commits) {
this.commits = commits;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public List<CommitJson> getCommits() {
return (List<CommitJson>) this.get(Constants.COMMIT_KEY);
}

public void setElements(List<CommitJson> commits) {
public void setCommits(List<CommitJson> commits) {
this.put(Constants.COMMIT_KEY, commits);
}

Expand Down
46 changes: 8 additions & 38 deletions crud/src/main/java/org/openmbee/sdvc/crud/domains/Branch.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "branches")
Expand All @@ -24,19 +21,8 @@ public class Branch {
private String branchId;
private String branchName;

@ManyToOne
@JoinColumn(name = "parent")
private Branch parentRef;

@Transient
private String parentRefId;

@ManyToOne
@JoinColumn(name = "parentCommit")
private Commit parentCommit;

@Transient
private String parentCommitId;
private Long parentCommit;

private Instant timestamp;

Expand All @@ -47,12 +33,12 @@ public Branch() {

}

public Branch(String elasticId, String branchId, String branchName, Branch parentRef,
Commit parentCommit, Instant timestamp, boolean tag, boolean deleted) {
public Branch(String elasticId, String branchId, String branchName, String parentRef,
Long parentCommit, Instant timestamp, boolean tag, boolean deleted) {
setElasticId(elasticId);
setBranchId(branchId);
setBranchName(branchName);
setParentRef(parentRef);
setParentRefId(parentRef);
setParentCommit(parentCommit);
setTimestamp(timestamp);
setTag(tag);
Expand Down Expand Up @@ -91,22 +77,6 @@ public void setBranchName(String branchName) {
this.branchName = branchName;
}

public Branch getParentRef() {
return parentRef;
}

public void setParentRef(Branch parentRef) {
this.parentRef = parentRef;
}

public Commit getParentCommit() {
return parentCommit;
}

public void setParentCommit(Commit parentCommit) {
this.parentCommit = parentCommit;
}

public Instant getTimestamp() {
return timestamp;
}
Expand Down Expand Up @@ -139,11 +109,11 @@ public void setParentRefId(String parentRefId) {
this.parentRefId = parentRefId;
}

public String getParentCommitId() {
return parentCommitId;
public Long getParentCommit() {
return parentCommit;
}

public void setParentCommitId(String parentCommitId) {
this.parentCommitId = parentCommitId;
public void setParentCommit(Long parentCommit) {
this.parentCommit = parentCommit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@

@Component
public class BranchDAOImpl extends BaseDAOImpl implements BranchDAO {

/*
private CommitDAO commitRepository;
@Autowired
public void setCommitRepository(CommitDAO commitRepository) {
this.commitRepository = commitRepository;
}

*/
public Branch save(Branch branch) {
String sql = "INSERT INTO branches (elasticId, branchId, branchName, parent, parentCommit, timestamp, tag, deleted) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";

String sql = "INSERT INTO branches (elasticId, branchId, branchName, parentRefId, parentCommit, timestamp, tag, deleted) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
/*
if (branch.getParentRefId() != null && branch.getParentRef() == null) {
Branch parentRef = findByBranchId(branch.getParentRefId());
branch.setParentRef(parentRef);
Expand All @@ -43,7 +43,7 @@ public Branch save(Branch branch) {
Commit latest = commitRepository.findLatest();
branch.setParentCommit(latest);
}

*/
KeyHolder keyHolder = new GeneratedKeyHolder();

getConnection().update(new PreparedStatementCreator() {
Expand All @@ -53,8 +53,8 @@ public PreparedStatement createPreparedStatement(Connection connection)
ps.setString(1, branch.getElasticId());
ps.setString(2, branch.getBranchId());
ps.setString(3, branch.getBranchName());
ps.setLong(4, branch.getParentRef().getId());
ps.setLong(5, branch.getParentCommit().getId());
ps.setString(4, branch.getParentRefId());
ps.setLong(5, branch.getParentCommit());
ps.setTimestamp(6, Timestamp.from(branch.getTimestamp()));
ps.setBoolean(7, branch.isTag());
ps.setBoolean(8, branch.isDeleted());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ public interface CommitDAO {

public Commit findByCommitId(String commitId);

public Commit findByTimestamp(Instant timestamp);
public Commit findByRefAndTimestamp(String refId, Instant timestamp);

public Commit findLatest();
public Commit findLatestByRef(String refId);

public List<Commit> findAll();

public List<Commit> findByRefAndTimestampAndLimit(String refId, Instant timestamp, int limit);

}
Loading

0 comments on commit 8f900a0

Please sign in to comment.