Skip to content

The Unified and Autonomous Development Platform

Gate keeper basic classes.

robin shinea5adf4cc1683
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/model/InvolvedBranch.java b/gitop.core/src/main/java/com/pmease/gitop/core/model/InvolvedBranch.java
new file mode 100644
index 0000000000..899b70400a
--- /dev/null
+++ b/gitop.core/src/main/java/com/pmease/gitop/core/model/InvolvedBranch.java
@@ -0,0 +1,49 @@
+package com.pmease.gitop.core.model;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+import javax.persistence.UniqueConstraint;
+
+import org.hibernate.annotations.FetchMode;
+
+import com.pmease.commons.persistence.AbstractEntity;
+
+@Entity
+ usage=org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE)
+@Table(uniqueConstraints={
+ @UniqueConstraint(columnNames={"repository", "name"})
+})
+@SuppressWarnings("serial")
+public class InvolvedBranch extends AbstractEntity {
+
+ @Column(nullable=false)
+ private String name;
+
+ @ManyToOne(fetch=FetchType.EAGER)
+ @org.hibernate.annotations.Fetch(FetchMode.SELECT)
+ @JoinColumn(nullable=false)
+ @org.hibernate.annotations.ForeignKey(name="FK_BRCH_REPO")
+ private Repository repository;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Repository getRepository() {
+ return repository;
+ }
+
+ public void setRepository(Repository repository) {
+ this.repository = repository;
+ }
+
+}
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/model/InvolvedCommit.java b/gitop.core/src/main/java/com/pmease/gitop/core/model/InvolvedCommit.java
new file mode 100644
index 0000000000..ef5e71d1eb
--- /dev/null
+++ b/gitop.core/src/main/java/com/pmease/gitop/core/model/InvolvedCommit.java
@@ -0,0 +1,15 @@
+package com.pmease.gitop.core.model;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+
+import com.pmease.commons.persistence.AbstractEntity;
+
+@SuppressWarnings("serial")
+@Entity
+public class InvolvedCommit extends AbstractEntity {
+
+ @Column(nullable=false, unique=true)
+ private String revision;
+
+}
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/model/PullRequest.java b/gitop.core/src/main/java/com/pmease/gitop/core/model/PullRequest.java
new file mode 100644
index 0000000000..e5421a2dd2
--- /dev/null
+++ b/gitop.core/src/main/java/com/pmease/gitop/core/model/PullRequest.java
@@ -0,0 +1,56 @@
+package com.pmease.gitop.core.model;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+
+import org.hibernate.annotations.FetchMode;
+
+import com.pmease.commons.persistence.AbstractEntity;
+
+@SuppressWarnings("serial")
+@Entity
+public class PullRequest extends AbstractEntity {
+
+ @Column(nullable=false)
+ private String title;
+
+ @ManyToOne(fetch=FetchType.EAGER)
+ @org.hibernate.annotations.Fetch(FetchMode.SELECT)
+ @JoinColumn(nullable=false)
+ @org.hibernate.annotations.ForeignKey(name="FK_PR_TBRCH")
+ private InvolvedBranch targetBranch;
+
+ @ManyToOne(fetch=FetchType.EAGER)
+ @org.hibernate.annotations.Fetch(FetchMode.SELECT)
+ @JoinColumn(nullable=true)
+ @org.hibernate.annotations.ForeignKey(name="FK_PR_SBRCH")
+ private InvolvedBranch sourceBranch;
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public InvolvedBranch getTargetBranch() {
+ return targetBranch;
+ }
+
+ public void setTargetBranch(InvolvedBranch targetBranch) {
+ this.targetBranch = targetBranch;
+ }
+
+ public InvolvedBranch getSourceBranch() {
+ return sourceBranch;
+ }
+
+ public void setSourceBranch(InvolvedBranch sourceBranch) {
+ this.sourceBranch = sourceBranch;
+ }
+
+}
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/model/Repository.java b/gitop.core/src/main/java/com/pmease/gitop/core/model/Repository.java
index e432e9e232..251e6e44eb 100644
--- a/gitop.core/src/main/java/com/pmease/gitop/core/model/Repository.java
+++ b/gitop.core/src/main/java/com/pmease/gitop/core/model/Repository.java
@@ -11,6 +11,7 @@ import javax.persistence.UniqueConstraint;
import org.hibernate.annotations.FetchMode;
import com.pmease.commons.persistence.AbstractEntity;
+import com.pmease.gitop.core.model.gatekeeper.GateKeeper;
@Entity
@org.hibernate.annotations.Cache(
@@ -31,6 +32,9 @@ public class Repository extends AbstractEntity {
@JoinColumn(nullable=false)
@org.hibernate.annotations.ForeignKey(name="FK_REPO_ACC")
private Account account;
+
+ @Column(nullable=true)
+ private GateKeeper gateKeeper;
public String getName() {
return name;
@@ -55,5 +59,13 @@ public class Repository extends AbstractEntity {
public void setAccount(Account account) {
this.account = account;
}
-
+
+ public GateKeeper getGateKeeper() {
+ return gateKeeper;
+ }
+
+ public void setGateKeeper(GateKeeper gateKeeper) {
+ this.gateKeeper = gateKeeper;
+ }
+
}
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/model/Team.java b/gitop.core/src/main/java/com/pmease/gitop/core/model/Team.java
index b64259df17..17d30a3f35 100644
--- a/gitop.core/src/main/java/com/pmease/gitop/core/model/Team.java
+++ b/gitop.core/src/main/java/com/pmease/gitop/core/model/Team.java
@@ -46,6 +46,7 @@ public class Team extends AbstractEntity implements Permission {
private AccountWideOperation authorizedAccountWideOperation = new ReadFromAccount();
+ @Column(nullable=false)
private List<OperationOfRepositorySet> authorizedRepositoryOperations = new ArrayList<OperationOfRepositorySet>();
@ManyToOne(fetch=FetchType.EAGER)
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/model/gatekeeper/AndGateKeeper.java b/gitop.core/src/main/java/com/pmease/gitop/core/model/gatekeeper/AndGateKeeper.java
new file mode 100644
index 0000000000..3b7c73d755
--- /dev/null
+++ b/gitop.core/src/main/java/com/pmease/gitop/core/model/gatekeeper/AndGateKeeper.java
@@ -0,0 +1,38 @@
+package com.pmease.gitop.core.model.gatekeeper;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.pmease.gitop.core.model.InvolvedCommit;
+
+public class AndGateKeeper implements GateKeeper {
+
+ private List<GateKeeper> gateKeepers = new ArrayList<GateKeeper>();
+
+ public List<GateKeeper> getGateKeepers() {
+ return gateKeepers;
+ }
+
+ public void setGateKeepers(List<GateKeeper> gateKeepers) {
+ this.gateKeepers = gateKeepers;
+ }
+
+ @Override
+ public CHECK_RESULT check(InvolvedCommit commit) {
+ boolean undetermined = false;
+
+ for (GateKeeper each: getGateKeepers()) {
+ CHECK_RESULT result = each.check(commit);
+ if (result == CHECK_RESULT.REJECT)
+ return result;
+ else if (result == CHECK_RESULT.UNDETERMINED)
+ undetermined = true;
+ }
+
+ if (undetermined)
+ return CHECK_RESULT.UNDETERMINED;
+ else
+ return CHECK_RESULT.ACCEPT;
+ }
+
+}
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/model/gatekeeper/GateKeeper.java b/gitop.core/src/main/java/com/pmease/gitop/core/model/gatekeeper/GateKeeper.java
new file mode 100644
index 0000000000..a0cc35c742
--- /dev/null
+++ b/gitop.core/src/main/java/com/pmease/gitop/core/model/gatekeeper/GateKeeper.java
@@ -0,0 +1,10 @@
+package com.pmease.gitop.core.model.gatekeeper;
+
+import com.pmease.gitop.core.model.InvolvedCommit;
+
+public interface GateKeeper {
+
+ public enum CHECK_RESULT {ACCEPT, REJECT, UNDETERMINED}
+
+ CHECK_RESULT check(InvolvedCommit commit);
+}
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/model/gatekeeper/OrGateKeeper.java b/gitop.core/src/main/java/com/pmease/gitop/core/model/gatekeeper/OrGateKeeper.java
new file mode 100644
index 0000000000..6b73bf51a0
--- /dev/null
+++ b/gitop.core/src/main/java/com/pmease/gitop/core/model/gatekeeper/OrGateKeeper.java
@@ -0,0 +1,38 @@
+package com.pmease.gitop.core.model.gatekeeper;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.pmease.gitop.core.model.InvolvedCommit;
+
+public class OrGateKeeper implements GateKeeper {
+
+ private List<GateKeeper> gateKeepers = new ArrayList<GateKeeper>();
+
+ public List<GateKeeper> getGateKeepers() {
+ return gateKeepers;
+ }
+
+ public void setGateKeepers(List<GateKeeper> gateKeepers) {
+ this.gateKeepers = gateKeepers;
+ }
+
+ @Override
+ public CHECK_RESULT check(InvolvedCommit commit) {
+ boolean undetermined = false;
+
+ for (GateKeeper each: getGateKeepers()) {
+ CHECK_RESULT result = each.check(commit);
+ if (result == CHECK_RESULT.ACCEPT)
+ return result;
+ else if (result == CHECK_RESULT.UNDETERMINED)
+ undetermined = true;
+ }
+
+ if (undetermined)
+ return CHECK_RESULT.UNDETERMINED;
+ else
+ return CHECK_RESULT.REJECT;
+ }
+
+}