Skip to content

The Unified and Autonomous Development Platform

Branch multi choice editor.

robin shine53b8d04a1310
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.css b/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.css
index d0abc7503e..c3b8ebd8b2 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.css
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.css
@@ -137,4 +137,4 @@ table.reflection .right-spacing {margin-right: 8px;}
.viewer .table {margin-bottom: 0;}
/* Select2 */
-.select2-container {min-width: 160px;}
\ No newline at end of file
+.editor .select2-container {width: 100%;}
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/BranchProtection.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/BranchProtection.java
index 43c577dd5f..4330956164 100644
--- a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/BranchProtection.java
+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/BranchProtection.java
@@ -10,12 +10,19 @@ import javax.validation.constraints.Size;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.commons.editable.annotation.OmitNames;
+import com.pmease.commons.util.trimmable.TrimUtils;
+import com.pmease.commons.util.trimmable.Trimmable;
+import com.pmease.gitop.core.Gitop;
import com.pmease.gitop.core.editable.BranchChoice;
import com.pmease.gitop.core.editable.TeamChoice;
+import com.pmease.gitop.core.manager.BranchManager;
+import com.pmease.gitop.core.manager.TeamManager;
+import com.pmease.gitop.model.Project;
import com.pmease.gitop.model.PullRequest;
import com.pmease.gitop.model.Team;
import com.pmease.gitop.model.gatekeeper.AndGateKeeper;
import com.pmease.gitop.model.gatekeeper.CommonGateKeeper;
+import com.pmease.gitop.model.gatekeeper.GateKeeper;
import com.pmease.gitop.model.gatekeeper.IfThenGateKeeper;
import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;
@@ -46,7 +53,7 @@ public class BranchProtection extends CommonGateKeeper {
}
@Editable
- public static class Entry implements Serializable {
+ public static class Entry implements Trimmable, Serializable {
private Long branchId;
@@ -74,6 +81,15 @@ public class BranchProtection extends CommonGateKeeper {
this.teamId = teamId;
}
+ @Override
+ public Object trim(Object context) {
+ if (Gitop.getInstance(BranchManager.class).get(branchId) == null)
+ return null;
+ if (Gitop.getInstance(TeamManager.class).get(teamId) == null)
+ return null;
+ return this;
+ }
+
}
@Override
@@ -82,7 +98,7 @@ public class BranchProtection extends CommonGateKeeper {
for (Entry entry: entries) {
IfThenGateKeeper ifThenGateKeeper = new IfThenGateKeeper();
IfSubmittedToSpecifiedBranches ifGate = new IfSubmittedToSpecifiedBranches();
- ifGate.setBranchIds(entry.getBranchId().toString());
+ ifGate.getBranchIds().add(entry.getBranchId());
ifThenGateKeeper.setIfGate(ifGate);
IfApprovedBySpecifiedTeam thenGate = new IfApprovedBySpecifiedTeam();
@@ -94,4 +110,14 @@ public class BranchProtection extends CommonGateKeeper {
return andGateKeeper.doCheck(request);
}
+ @Override
+ protected GateKeeper trim(Project project) {
+ TrimUtils.trim(entries, project);
+
+ if (entries.isEmpty())
+ return null;
+ else
+ return this;
+ }
+
}
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/DirectoryProtection.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/DirectoryProtection.java
index 91203b9cbd..08077bb682 100644
--- a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/DirectoryProtection.java
+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/DirectoryProtection.java
@@ -12,12 +12,18 @@ import org.hibernate.validator.constraints.NotEmpty;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.commons.editable.annotation.OmitNames;
+import com.pmease.commons.util.trimmable.TrimUtils;
+import com.pmease.commons.util.trimmable.Trimmable;
+import com.pmease.gitop.core.Gitop;
import com.pmease.gitop.core.editable.DirectoryChoice;
import com.pmease.gitop.core.editable.TeamChoice;
+import com.pmease.gitop.core.manager.TeamManager;
+import com.pmease.gitop.model.Project;
import com.pmease.gitop.model.PullRequest;
import com.pmease.gitop.model.Team;
import com.pmease.gitop.model.gatekeeper.AndGateKeeper;
import com.pmease.gitop.model.gatekeeper.CommonGateKeeper;
+import com.pmease.gitop.model.gatekeeper.GateKeeper;
import com.pmease.gitop.model.gatekeeper.IfThenGateKeeper;
import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;
@@ -48,7 +54,8 @@ public class DirectoryProtection extends CommonGateKeeper {
}
@Editable
- public static class Entry implements Serializable {
+ public static class Entry implements Trimmable, Serializable {
+
private String directory;
private Long teamId;
@@ -75,6 +82,14 @@ public class DirectoryProtection extends CommonGateKeeper {
this.teamId = teamId;
}
+ @Override
+ public Object trim(Object context) {
+ if (Gitop.getInstance(TeamManager.class).get(teamId) == null)
+ return null;
+ else
+ return this;
+ }
+
}
@Override
@@ -95,4 +110,14 @@ public class DirectoryProtection extends CommonGateKeeper {
return andGateKeeper.doCheck(request);
}
+ @Override
+ protected GateKeeper trim(Project project) {
+ TrimUtils.trim(entries, project);
+
+ if (entries.isEmpty())
+ return null;
+ else
+ return this;
+ }
+
}
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedBySpecifiedUser.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedBySpecifiedUser.java
index c4e6ba70e7..e10b925c8a 100644
--- a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedBySpecifiedUser.java
+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedBySpecifiedUser.java
@@ -8,10 +8,12 @@ import com.pmease.commons.loader.AppLoader;
import com.pmease.gitop.core.Gitop;
import com.pmease.gitop.core.manager.UserManager;
import com.pmease.gitop.core.manager.VoteInvitationManager;
+import com.pmease.gitop.model.Project;
import com.pmease.gitop.model.PullRequest;
import com.pmease.gitop.model.User;
import com.pmease.gitop.model.Vote;
import com.pmease.gitop.model.gatekeeper.ApprovalGateKeeper;
+import com.pmease.gitop.model.gatekeeper.GateKeeper;
import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;
import com.pmease.gitop.model.gatekeeper.voteeligibility.CanVoteBySpecifiedUser;
@@ -57,7 +59,7 @@ public class IfApprovedBySpecifiedUser extends ApprovalGateKeeper {
}
@Override
- public Object trim(Object context) {
+ protected GateKeeper trim(Project project) {
UserManager userManager = AppLoader.getInstance(UserManager.class);
if (userManager.get(getUserId()) == null)
return null;
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmittedToSpecifiedBranchPatterns.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmittedToSpecifiedBranchPatterns.java
index 44c7ac625d..6576df5f6a 100644
--- a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmittedToSpecifiedBranchPatterns.java
+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmittedToSpecifiedBranchPatterns.java
@@ -2,7 +2,6 @@ package com.pmease.gitop.core.gatekeeper;
import javax.validation.constraints.NotNull;
-import com.google.common.base.Preconditions;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.commons.loader.AppLoader;
import com.pmease.commons.util.namedentity.EntityLoader;
@@ -14,6 +13,7 @@ import com.pmease.gitop.core.manager.BranchManager;
import com.pmease.gitop.model.Project;
import com.pmease.gitop.model.PullRequest;
import com.pmease.gitop.model.gatekeeper.BranchGateKeeper;
+import com.pmease.gitop.model.gatekeeper.GateKeeper;
import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;
@SuppressWarnings("serial")
@@ -50,10 +50,7 @@ public class IfSubmittedToSpecifiedBranchPatterns extends BranchGateKeeper {
}
@Override
- public Object trim(Object context) {
- Preconditions.checkArgument(context instanceof Project);
-
- Project project = (Project) context;
+ protected GateKeeper trim(Project project) {
BranchManager branchManager = AppLoader.getInstance(BranchManager.class);
EntityLoader entityLoader = branchManager.asEntityLoader(project);
EntityPatternSet patternSet = EntityPatternSet.fromStored(getBranchPatterns(), entityLoader);
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmittedToSpecifiedBranches.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmittedToSpecifiedBranches.java
index 9db158d0f2..27ef6aa66d 100644
--- a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmittedToSpecifiedBranches.java
+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmittedToSpecifiedBranches.java
@@ -1,19 +1,20 @@
package com.pmease.gitop.core.gatekeeper;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
-import com.google.common.base.Preconditions;
import com.pmease.commons.editable.annotation.Editable;
-import com.pmease.commons.loader.AppLoader;
-import com.pmease.commons.util.namedentity.EntityLoader;
-import com.pmease.commons.util.namedentity.EntityMatcher;
-import com.pmease.commons.util.namedentity.EntityPatternSet;
-import com.pmease.commons.util.pattern.PatternSetMatcher;
-import com.pmease.commons.util.pattern.WildcardPathMatcher;
+import com.pmease.gitop.core.Gitop;
+import com.pmease.gitop.core.editable.BranchChoice;
import com.pmease.gitop.core.manager.BranchManager;
import com.pmease.gitop.model.Project;
import com.pmease.gitop.model.PullRequest;
import com.pmease.gitop.model.gatekeeper.BranchGateKeeper;
+import com.pmease.gitop.model.gatekeeper.GateKeeper;
import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;
@SuppressWarnings("serial")
@@ -21,50 +22,40 @@ import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;
"This gate keeper will be passed if the commit is submitted to specified branches.")
public class IfSubmittedToSpecifiedBranches extends BranchGateKeeper {
- private String branchIds;
+ private List<Long> branchIds = new ArrayList<>();
- @Editable
+ @Editable(name="Branches", description="Select branches to check.")
+ @BranchChoice
@NotNull
- public String getBranchIds() {
+ @Size(min=1)
+ public List<Long> getBranchIds() {
return branchIds;
}
- public void setBranchIds(String branchIds) {
+ public void setBranchIds(List<Long> branchIds) {
this.branchIds = branchIds;
}
@Override
public CheckResult doCheck(PullRequest request) {
- Project project = request.getTarget().getProject();
- BranchManager branchManager = AppLoader.getInstance(BranchManager.class);
- EntityLoader entityLoader = branchManager.asEntityLoader(project);
- EntityMatcher entityMatcher = new EntityMatcher(entityLoader, new WildcardPathMatcher());
- PatternSetMatcher patternSetMatcher = new PatternSetMatcher(entityMatcher);
-
- EntityPatternSet patternSet = EntityPatternSet.fromStored(getBranchIds(), entityLoader);
-
- if (patternSetMatcher.matches(getBranchIds(), request.getTarget().getName()))
- return accepted("Target branch matches pattern '" + patternSet + "'.");
+ String reason = "Submitted to branch '" + request.getTarget().getName() + "'.";
+ if (branchIds.contains(request.getTarget().getId()))
+ return accepted(reason);
else
- return rejected("Target branch does not match pattern '" + patternSet + "'.");
+ return rejected(reason);
}
@Override
- public Object trim(Object context) {
- Preconditions.checkArgument(context instanceof Project);
-
- Project project = (Project) context;
- BranchManager branchManager = AppLoader.getInstance(BranchManager.class);
- EntityLoader entityLoader = branchManager.asEntityLoader(project);
- EntityPatternSet patternSet = EntityPatternSet.fromStored(getBranchIds(), entityLoader);
- patternSet.trim(project);
-
- if (patternSet.getStored().isEmpty()) {
+ protected GateKeeper trim(Project project) {
+ BranchManager branchManager = Gitop.getInstance(BranchManager.class);
+ for (Iterator<Long> it = branchIds.iterator(); it.hasNext();) {
+ if (branchManager.get(it.next()) == null)
+ it.remove();
+ }
+ if (branchIds.isEmpty())
return null;
- } else {
- setBranchIds(patternSet.toString());
+ else
return this;
- }
}
}
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/TeamAwareGateKeeper.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/TeamAwareGateKeeper.java
index b506bbfeb0..cde5c13e38 100644
--- a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/TeamAwareGateKeeper.java
+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/TeamAwareGateKeeper.java
@@ -5,8 +5,10 @@ import javax.validation.constraints.NotNull;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.gitop.core.Gitop;
import com.pmease.gitop.core.manager.TeamManager;
+import com.pmease.gitop.model.Project;
import com.pmease.gitop.model.Team;
import com.pmease.gitop.model.gatekeeper.ApprovalGateKeeper;
+import com.pmease.gitop.model.gatekeeper.GateKeeper;
@SuppressWarnings("serial")
public abstract class TeamAwareGateKeeper extends ApprovalGateKeeper {
@@ -28,7 +30,7 @@ public abstract class TeamAwareGateKeeper extends ApprovalGateKeeper {
}
@Override
- public Object trim(Object context) {
+ protected GateKeeper trim(Project project) {
TeamManager teamManager = Gitop.getInstance(TeamManager.class);
if (teamManager.get(getTeamId()) == null)
return null;
diff --git a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/AbstractGateKeeper.java b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/AbstractGateKeeper.java
index 885204a729..453e7af5ef 100644
--- a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/AbstractGateKeeper.java
+++ b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/AbstractGateKeeper.java
@@ -5,7 +5,9 @@ import java.util.List;
import javax.annotation.Nullable;
+import com.google.common.base.Preconditions;
import com.pmease.commons.editable.annotation.Editable;
+import com.pmease.gitop.model.Project;
import com.pmease.gitop.model.PullRequest;
import com.pmease.gitop.model.gatekeeper.checkresult.Accepted;
import com.pmease.gitop.model.gatekeeper.checkresult.Blocked;
@@ -47,7 +49,12 @@ public abstract class AbstractGateKeeper implements GateKeeper {
protected abstract CheckResult doCheck(PullRequest request);
@Override
- public Object trim(@Nullable Object context) {
+ public final Object trim(@Nullable Object context) {
+ Preconditions.checkArgument(context instanceof Project);
+ return trim((Project)context);
+ }
+
+ protected GateKeeper trim(Project project) {
return this;
}
diff --git a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/AndOrGateKeeper.java b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/AndOrGateKeeper.java
index fae40724f2..a842efa3da 100644
--- a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/AndOrGateKeeper.java
+++ b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/AndOrGateKeeper.java
@@ -8,6 +8,7 @@ import javax.validation.constraints.NotNull;
import com.pmease.commons.util.trimmable.AndOrConstruct;
import com.pmease.commons.util.trimmable.TrimUtils;
+import com.pmease.gitop.model.Project;
@SuppressWarnings("serial")
public abstract class AndOrGateKeeper extends CompositeGateKeeper {
@@ -25,8 +26,8 @@ public abstract class AndOrGateKeeper extends CompositeGateKeeper {
}
@Override
- public Object trim(Object context) {
- return TrimUtils.trim(new AndOrConstruct() {
+ protected GateKeeper trim(Project project) {
+ return (GateKeeper) TrimUtils.trim(new AndOrConstruct() {
@Override
public Object getSelf() {
@@ -38,7 +39,7 @@ public abstract class AndOrGateKeeper extends CompositeGateKeeper {
return getGateKeepers();
}
- }, context);
+ }, project);
}
}
diff --git a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/DefaultGateKeeper.java b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/DefaultGateKeeper.java
index 960a9cdacb..84d43960e5 100644
--- a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/DefaultGateKeeper.java
+++ b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/DefaultGateKeeper.java
@@ -1,6 +1,7 @@
package com.pmease.gitop.model.gatekeeper;
import com.pmease.commons.editable.annotation.Editable;
+import com.pmease.gitop.model.Project;
import com.pmease.gitop.model.PullRequest;
import com.pmease.gitop.model.gatekeeper.checkresult.Accepted;
import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;
@@ -10,8 +11,8 @@ import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;
public class DefaultGateKeeper extends AbstractGateKeeper {
@Override
- public Object trim(Object context) {
- return null;
+ protected GateKeeper trim(Project project) {
+ return this;
}
@Override
diff --git a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/NotGateKeeper.java b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/NotGateKeeper.java
index 3a3baa02a5..d319ea58dc 100644
--- a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/NotGateKeeper.java
+++ b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/NotGateKeeper.java
@@ -5,6 +5,7 @@ import javax.validation.constraints.NotNull;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.commons.editable.annotation.TableLayout;
+import com.pmease.gitop.model.Project;
import com.pmease.gitop.model.PullRequest;
import com.pmease.gitop.model.gatekeeper.checkresult.Accepted;
import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;
@@ -41,8 +42,8 @@ public class NotGateKeeper extends CompositeGateKeeper {
}
@Override
- public Object trim(Object context) {
- return getGateKeeper().trim(context);
+ protected GateKeeper trim(Project project) {
+ return (GateKeeper) getGateKeeper().trim(project);
}
}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/editable/branch/BranchEditSupport.java b/gitop.web/src/main/java/com/pmease/gitop/web/editable/branch/BranchEditSupport.java
index bc37f8327e..39c13c675d 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/editable/branch/BranchEditSupport.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/editable/branch/BranchEditSupport.java
@@ -2,6 +2,7 @@ package com.pmease.gitop.web.editable.branch;
import java.io.Serializable;
import java.lang.reflect.Method;
+import java.util.List;
import com.pmease.commons.editable.BeanEditContext;
import com.pmease.commons.editable.EditSupport;
@@ -21,7 +22,10 @@ public class BranchEditSupport implements EditSupport {
public PropertyEditContext getPropertyEditContext(Serializable bean, String propertyName) {
Method propertyGetter = BeanUtils.getGetter(JavassistUtils.unproxy(bean.getClass()), propertyName);
if (propertyGetter.getAnnotation(BranchChoice.class) != null) {
- return new BranchSingleChoiceEditContext(bean, propertyName);
+ if (List.class.isAssignableFrom(propertyGetter.getReturnType()))
+ return new BranchMultiChoiceEditContext(bean, propertyName);
+ else
+ return new BranchSingleChoiceEditContext(bean, propertyName);
} else {
return null;
}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/editable/branch/BranchMultiChoiceEditContext.java b/gitop.web/src/main/java/com/pmease/gitop/web/editable/branch/BranchMultiChoiceEditContext.java
new file mode 100644
index 0000000000..2f254fae2f
--- /dev/null
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/editable/branch/BranchMultiChoiceEditContext.java
@@ -0,0 +1,44 @@
+package com.pmease.gitop.web.editable.branch;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.wicket.markup.html.basic.Label;
+import org.eclipse.jgit.util.StringUtils;
+
+import com.pmease.commons.editable.PropertyEditContext;
+import com.pmease.gitop.core.Gitop;
+import com.pmease.gitop.core.manager.BranchManager;
+
+@SuppressWarnings("serial")
+public class BranchMultiChoiceEditContext extends PropertyEditContext {
+
+ public BranchMultiChoiceEditContext(Serializable bean, String propertyName) {
+ super(bean, propertyName);
+ }
+
+ @Override
+ public Object renderForEdit(Object renderParam) {
+ return new BranchMultiChoiceEditor((String) renderParam, this);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Object renderForView(Object renderParam) {
+ Collection<Long> branchIds = (Collection<Long>) getPropertyValue();
+ if (branchIds != null && !branchIds.isEmpty()) {
+ BranchManager branchManager = Gitop.getInstance(BranchManager.class);
+ List<String> branchNames = new ArrayList<>();
+ for (Long branchId: branchIds) {
+ branchNames.add(branchManager.load(branchId).getName());
+ }
+ return new Label((String) renderParam, StringUtils.join(branchNames, ", " ));
+ } else {
+ return new Label((String) renderParam, "<i>Not Defined</i>")
+ .setEscapeModelStrings(false);
+ }
+ }
+
+}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/editable/branch/BranchMultiChoiceEditor.html b/gitop.web/src/main/java/com/pmease/gitop/web/editable/branch/BranchMultiChoiceEditor.html
new file mode 100644
index 0000000000..5596a9ca8b
--- /dev/null
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/editable/branch/BranchMultiChoiceEditor.html
@@ -0,0 +1,3 @@
+<wicket:panel>
+ <input wicket:id="chooser" type="hidden"></input>
+</wicket:panel>
\ No newline at end of file
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/editable/branch/BranchMultiChoiceEditor.java b/gitop.web/src/main/java/com/pmease/gitop/web/editable/branch/BranchMultiChoiceEditor.java
new file mode 100644
index 0000000000..484fd77222
--- /dev/null
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/editable/branch/BranchMultiChoiceEditor.java
@@ -0,0 +1,88 @@
+package com.pmease.gitop.web.editable.branch;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.LoadableDetachableModel;
+import org.hibernate.criterion.DetachedCriteria;
+import org.hibernate.criterion.Restrictions;
+
+import com.pmease.gitop.core.Gitop;
+import com.pmease.gitop.core.manager.BranchManager;
+import com.pmease.gitop.model.Branch;
+import com.pmease.gitop.web.component.choice.BranchChoiceProvider;
+import com.pmease.gitop.web.component.choice.BranchMultiChoice;
+import com.pmease.gitop.web.page.project.AbstractProjectPage;
+
+@SuppressWarnings("serial")
+public class BranchMultiChoiceEditor extends Panel {
+
+ private final BranchMultiChoiceEditContext editContext;
+
+ public BranchMultiChoiceEditor(String id, BranchMultiChoiceEditContext editContext) {
+ super(id);
+ this.editContext = editContext;
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ IModel<Collection<Branch>> model = new IModel<Collection<Branch>>() {
+
+ @Override
+ public void detach() {
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Collection<Branch> getObject() {
+ List<Long> branchIds = (List<Long>) editContext.getPropertyValue();
+ if (branchIds != null) {
+ BranchManager branchManager = Gitop.getInstance(BranchManager.class);
+ Collection<Branch> branches = new ArrayList<>();
+ for (Long branchId: branchIds)
+ branches.add(branchManager.load(branchId));
+ return branches;
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public void setObject(Collection<Branch> branches) {
+ if (branches != null) {
+ List<Long> branchIds = new ArrayList<>();
+ for (Branch branch: branches)
+ branchIds.add(branch.getId());
+ editContext.setPropertyValue((Serializable) branchIds);
+ } else {
+ editContext.setPropertyValue(null);
+ }
+ }
+
+ };
+
+ BranchChoiceProvider branchProvider = new BranchChoiceProvider(new LoadableDetachableModel<DetachedCriteria>() {
+
+ @Override
+ protected DetachedCriteria load() {
+ DetachedCriteria criteria = DetachedCriteria.forClass(Branch.class);
+ AbstractProjectPage page = (AbstractProjectPage) getPage();
+ criteria.add(Restrictions.eq("project", page.getProject()));
+ return criteria;
+ }
+
+ });
+
+ BranchMultiChoice chooser = new BranchMultiChoice("chooser", model, branchProvider);
+ chooser.setConvertEmptyInputStringToNull(true);
+
+ add(chooser);
+ }
+
+}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/editable/branch/BranchSingleChoiceEditor.html b/gitop.web/src/main/java/com/pmease/gitop/web/editable/branch/BranchSingleChoiceEditor.html
index 5596a9ca8b..55d8f7968d 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/editable/branch/BranchSingleChoiceEditor.html
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/editable/branch/BranchSingleChoiceEditor.html
@@ -1,3 +1,3 @@
<wicket:panel>
- <input wicket:id="chooser" type="hidden"></input>
+ <input wicket:id="chooser" type="hidden" class="select2"></input>
</wicket:panel>
\ No newline at end of file
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/settings/GateKeeperSettingPage.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/settings/GateKeeperSettingPage.java
index bf3b680129..aa905efd65 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/settings/GateKeeperSettingPage.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/settings/GateKeeperSettingPage.java
@@ -72,7 +72,7 @@ public class GateKeeperSettingPage extends AbstractProjectSettingPage {
}
@Override
- protected void onSave(AjaxRequestTarget target) {
+ protected void onSave(AjaxRequestTarget target, GateKeeper gatekeeper) {
close(target);
getProject().getGateKeepers().add(gateKeeper);
onGateKeeperChanged(target);
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/settings/gatekeeper/GateKeeperEditor.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/settings/gatekeeper/GateKeeperEditor.java
index d767b8e79a..59b05ada19 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/settings/gatekeeper/GateKeeperEditor.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/settings/gatekeeper/GateKeeperEditor.java
@@ -1,5 +1,6 @@
package com.pmease.gitop.web.page.project.settings.gatekeeper;
+import org.apache.commons.lang3.SerializationUtils;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
@@ -21,7 +22,7 @@ public abstract class GateKeeperEditor extends Panel {
public GateKeeperEditor(String id, GateKeeper gateKeeper) {
super(id);
- this.gateKeeper = gateKeeper;
+ this.gateKeeper = SerializationUtils.clone(gateKeeper);
}
@Override
@@ -57,15 +58,15 @@ public abstract class GateKeeperEditor extends Panel {
editContext.validate();
if (!editContext.hasValidationError())
- onSave(target);
+ onSave(target, gateKeeper);
else
target.add(GateKeeperEditor.this);
}
});
}
-
+
protected abstract void onCancel(AjaxRequestTarget target);
- protected abstract void onSave(AjaxRequestTarget target);
+ protected abstract void onSave(AjaxRequestTarget target, GateKeeper gateKeeper);
}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/settings/gatekeeper/GateKeeperPanel.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/settings/gatekeeper/GateKeeperPanel.java
index b1075c09b6..72bb5c097c 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/settings/gatekeeper/GateKeeperPanel.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/settings/gatekeeper/GateKeeperPanel.java
@@ -72,7 +72,7 @@ public abstract class GateKeeperPanel extends Panel {
}
@Override
- protected void onSave(AjaxRequestTarget target) {
+ protected void onSave(AjaxRequestTarget target, GateKeeper gateKeeper) {
close(target);
GateKeeperPanel.this.onChange(target, gateKeeper);
}
@@ -167,7 +167,7 @@ public abstract class GateKeeperPanel extends Panel {
}
@Override
- protected void onSave(AjaxRequestTarget target) {
+ protected void onSave(AjaxRequestTarget target, GateKeeper gatekeeper) {
close(target);
fragment.replace(new WebMarkupContainer("childEditor").setOutputMarkupPlaceholderTag(true).setVisible(true));
andOrGateKeeper.getGateKeepers().add(gateKeeper);
@@ -219,7 +219,7 @@ public abstract class GateKeeperPanel extends Panel {
}
@Override
- protected void onSave(AjaxRequestTarget target) {
+ protected void onSave(AjaxRequestTarget target, GateKeeper gatekeeper) {
close(target);
fragment.replace(new WebMarkupContainer("gateKeeperEditor").setOutputMarkupPlaceholderTag(true).setVisible(true));
notGateKeeper.setGateKeeper(gateKeeper);
@@ -293,7 +293,7 @@ public abstract class GateKeeperPanel extends Panel {
}
@Override
- protected void onSave(AjaxRequestTarget target) {
+ protected void onSave(AjaxRequestTarget target, GateKeeper gatekeeper) {
close(target);
fragment.replace(new WebMarkupContainer("ifEditor").setOutputMarkupPlaceholderTag(true).setVisible(true));
ifThenGateKeeper.setIfGate(gateKeeper);
@@ -363,7 +363,7 @@ public abstract class GateKeeperPanel extends Panel {
}
@Override
- protected void onSave(AjaxRequestTarget target) {
+ protected void onSave(AjaxRequestTarget target, GateKeeper gatekeeper) {
close(target);
fragment.replace(new WebMarkupContainer("thenEditor").setOutputMarkupPlaceholderTag(true).setVisible(true));
ifThenGateKeeper.setThenGate(gateKeeper);