Skip to content

The Unified and Autonomous Development Platform

Sub page should override onPageInitialize() instead of onInitialize()

robin shine1edc128e6990
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/GitFilter.java b/gitop.core/src/main/java/com/pmease/gitop/core/GitFilter.java
index 24990c0312..ea31781472 100644
--- a/gitop.core/src/main/java/com/pmease/gitop/core/GitFilter.java
+++ b/gitop.core/src/main/java/com/pmease/gitop/core/GitFilter.java
@@ -151,21 +151,23 @@ public class GitFilter implements Filter {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
- if (gitop.isReady()) {
- try {
- if (GitSmartHttpTools.isInfoRefs(httpRequest)) {
+ try {
+ if (GitSmartHttpTools.isInfoRefs(httpRequest)) {
+ if (gitop.isReady())
processRefs(httpRequest, httpResponse);
- } else if (GitSmartHttpTools.isReceivePack(httpRequest) || GitSmartHttpTools.isUploadPack(httpRequest)) {
+ else
+ throw new GeneralException("Server is not ready");
+ } else if (GitSmartHttpTools.isReceivePack(httpRequest) || GitSmartHttpTools.isUploadPack(httpRequest)) {
+ if (gitop.isReady())
processPacks(httpRequest, httpResponse);
- } else {
- chain.doFilter(request, response);
- }
- } catch (GeneralException e) {
- logger.error("Error serving git request", e);
- GitSmartHttpTools.sendError(httpRequest, httpResponse, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
+ else
+ throw new GeneralException("Server is not ready");
+ } else {
+ chain.doFilter(request, response);
}
- } else {
- GitSmartHttpTools.sendError(httpRequest, httpResponse, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Server is not ready.");
+ } catch (GeneralException e) {
+ logger.error("Error serving git request", e);
+ GitSmartHttpTools.sendError(httpRequest, httpResponse, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
}
}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/AbstractLayoutPage.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/AbstractLayoutPage.java
index 686ee789b0..b34f17f44d 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/AbstractLayoutPage.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/AbstractLayoutPage.java
@@ -1,8 +1,6 @@
package com.pmease.gitop.web.page;
import org.apache.shiro.SecurityUtils;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.request.mapper.parameter.PageParameters;
import com.google.common.base.Optional;
import com.pmease.gitop.core.model.User;
@@ -10,21 +8,9 @@ import com.pmease.gitop.core.model.User;
@SuppressWarnings("serial")
public abstract class AbstractLayoutPage extends BasePage {
- public AbstractLayoutPage() {
- commonInit();
- }
-
- public AbstractLayoutPage(PageParameters params) {
- super(params);
- commonInit();
- }
-
- public AbstractLayoutPage(IModel<?> model) {
- super(model);
- commonInit();
- }
-
- private void commonInit() {
+ @Override
+ protected void onPageInitialize() {
+ super.onPageInitialize();
add(new GlobalHeaderPanel("header"));
}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/BasePage.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/BasePage.java
index a7b031eb27..97690bdf49 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/BasePage.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/BasePage.java
@@ -31,6 +31,8 @@ import com.pmease.gitop.web.page.init.ServerInitPage;
public abstract class BasePage extends WebPage {
private WebMarkupContainer body;
+
+ private boolean shouldInitialize = true;
public BasePage() {
commonInit();
@@ -47,23 +49,11 @@ public abstract class BasePage extends WebPage {
}
private void commonInit() {
- body = new TransparentWebMarkupContainer("body");
- add(body);
- body.add(AttributeAppender.append("class",
- new AbstractReadOnlyModel<String>() {
-
- @Override
- public String getObject() {
- String css = getPageCssClass();
- return Strings.isNullOrEmpty(css) ? "" : css;
- }
- }));
-
- if (!Gitop.getInstance().isReady()
- && getClass() != ServerInitPage.class) {
- throw new RestartResponseAtInterceptPageException(
- ServerInitPage.class);
+ if (!Gitop.getInstance().isReady() && getClass() != ServerInitPage.class) {
+ redirect(ServerInitPage.class);
}
+
+ shouldInitialize = true;
}
@Override
@@ -119,23 +109,47 @@ public abstract class BasePage extends WebPage {
}
}
+ public final void redirectWithIntercept(final Class<? extends Page> clazz) {
+ shouldInitialize = true;
+ throw new RestartResponseAtInterceptPageException(clazz);
+ }
+
+ public final void redirectWithIntercept(final Class<? extends Page> clazz, final PageParameters pageParams) {
+ shouldInitialize = true;
+ throw new RestartResponseAtInterceptPageException(clazz, pageParams);
+ }
+
+ public final void redirectWithIntercept(final Page page) {
+ shouldInitialize = true;
+ throw new RestartResponseAtInterceptPageException(page);
+ }
+
public final void redirect(final Class<? extends Page> clazz) {
+ shouldInitialize = false;
throw new RestartResponseException(clazz);
}
public final void redirect(final Class<? extends Page> clazz,
PageParameters parameters) {
+ shouldInitialize = false;
throw new RestartResponseException(clazz, parameters);
}
public final void redirect(final Page page) {
+ shouldInitialize = false;
throw new RestartResponseException(page);
}
public final void redirect(String url) {
+ shouldInitialize = false;
throw new RedirectToUrlException(url);
}
-
+
+ public final void redirectToOriginal() {
+ shouldInitialize = false;
+ continueToOriginalDestination();
+ }
+
protected String getPageCssClass() {
String name = getClass().getSimpleName();
return StringUtils.camelCaseToLowerCaseWithHyphen(name);
@@ -144,10 +158,19 @@ public abstract class BasePage extends WebPage {
protected boolean isPermitted() {
return true;
}
+
+ protected void onPageInitialize() {
+ body = new TransparentWebMarkupContainer("body");
+ add(body);
+ body.add(AttributeAppender.append("class",
+ new AbstractReadOnlyModel<String>() {
- @Override
- protected void onInitialize() {
- super.onInitialize();
+ @Override
+ public String getObject() {
+ String css = getPageCssClass();
+ return Strings.isNullOrEmpty(css) ? "" : css;
+ }
+ }));
if (!isPermitted()) {
throw new AccessDeniedException();
@@ -179,8 +202,16 @@ public abstract class BasePage extends WebPage {
* cause components with resources using global resources not working
* properly.
*/
- add(new WebMarkupContainer("globalResourceBinder")
- .add(new BaseResourceBehavior()));
+ add(new WebMarkupContainer("globalResourceBinder").add(new BaseResourceBehavior()));
+ }
+
+ @Override
+ protected final void onInitialize() {
+ super.onInitialize();
+
+ if (shouldInitialize) {
+ onPageInitialize();
+ }
}
protected abstract String getPageTitle();
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/account/AccountHomePage.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/account/AccountHomePage.java
index dbf91dd93c..2ba5bcdd6f 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/account/AccountHomePage.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/account/AccountHomePage.java
@@ -36,6 +36,11 @@ public class AccountHomePage extends AbstractLayoutPage {
}
};
+ }
+
+ @Override
+ protected void onPageInitialize() {
+ super.onPageInitialize();
add(new Label("accountName", getAccount().getName()));
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/account/RegisterPage.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/account/RegisterPage.java
index a6672a1e61..9df2b560df 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/account/RegisterPage.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/account/RegisterPage.java
@@ -41,9 +41,20 @@ public class RegisterPage extends AbstractLayoutPage {
return "Gitop - Sign Up";
}
- public RegisterPage() {
+ @Override
+ protected void onPageInitialize() {
+ super.onPageInitialize();
+
final IModel<User> model = Model.<User>of(new User());
- Form<User> form = new Form<User>("form", model);
+ Form<User> form = new Form<User>("form", model) {
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ }
+
+ };
add(form);
form.add(new FeedbackPanel("feedback", form));
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/account/setting/AccountSettingPage.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/account/setting/AccountSettingPage.java
index ae944b6277..a65c646772 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/account/setting/AccountSettingPage.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/account/setting/AccountSettingPage.java
@@ -10,8 +10,6 @@ import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.AbstractReadOnlyModel;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.request.mapper.parameter.PageParameters;
import com.google.common.collect.ImmutableList;
import com.pmease.gitop.core.model.User;
@@ -50,21 +48,10 @@ public abstract class AccountSettingPage extends AbstractLayoutPage {
}
}
- public AccountSettingPage() {
- commonInit();
- }
-
- public AccountSettingPage(PageParameters params) {
- super(params);
- commonInit();
- }
-
- public AccountSettingPage(IModel<?> model) {
- super(model);
- commonInit();
- }
+ @Override
+ protected void onPageInitialize() {
+ super.onPageInitialize();
- private void commonInit() {
add(new UserAvatarLink("userlink", new UserModel(getAccount())));
add(new ListView<Category>("setting", ImmutableList.<Category>copyOf(Category.values())) {
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/account/setting/password/AccountPasswordPage.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/account/setting/password/AccountPasswordPage.java
index 99d16b7a99..ee003bf2fd 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/account/setting/password/AccountPasswordPage.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/account/setting/password/AccountPasswordPage.java
@@ -34,7 +34,10 @@ public class AccountPasswordPage extends AccountSettingPage {
return Category.PASSWORD;
}
- public AccountPasswordPage() {
+ @Override
+ protected void onPageInitialize() {
+ super.onPageInitialize();
+
Form<User> form = new Form<User>("form", new UserModel(getAccount()));
add(form);
form.add(new PasswordFieldElement("oldPass", "Current Password",
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/init/ServerInitPage.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/init/ServerInitPage.java
index 17ff590de2..14de17d58b 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/init/ServerInitPage.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/init/ServerInitPage.java
@@ -3,7 +3,6 @@ package com.pmease.gitop.web.page.init;
import java.util.ArrayList;
import java.util.List;
-import org.apache.wicket.RestartResponseException;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
@@ -22,9 +21,15 @@ public class ServerInitPage extends BasePage {
public ServerInitPage() {
initStage = Gitop.getInstance().getInitStage();
if (initStage == null) {
- continueToOriginalDestination();
- throw new RestartResponseException(getApplication().getHomePage());
+ redirectToOriginal();
+
+ redirect(getApplication().getHomePage());
}
+ }
+
+ @Override
+ protected void onPageInitialize() {
+ super.onPageInitialize();
add(new Label("message", initStage.getMessage()));
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/ProjectHomePage.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/ProjectHomePage.java
index 69023e71fd..262455d866 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/ProjectHomePage.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/ProjectHomePage.java
@@ -1,5 +1,6 @@
package com.pmease.gitop.web.page.project;
+import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
@@ -12,6 +13,7 @@ import com.pmease.gitop.core.model.Project;
import com.pmease.gitop.web.page.AbstractLayoutPage;
@SuppressWarnings("serial")
+@RequiresAuthentication
public class ProjectHomePage extends AbstractLayoutPage {
private final IModel<Project> projectModel;
@@ -43,6 +45,11 @@ public class ProjectHomePage extends AbstractLayoutPage {
}
};
+ }
+
+ @Override
+ protected void onPageInitialize() {
+ super.onPageInitialize();
add(new Label("accountName", getProject().getOwner().getName()));
add(new Label("projectName", getProject().getName()));
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/test/TestPage.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/test/TestPage.java
index 08d7adc63d..5328279117 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/test/TestPage.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/test/TestPage.java
@@ -14,7 +14,10 @@ import com.pmease.gitop.web.page.BasePage;
@SuppressWarnings("serial")
public class TestPage extends BasePage {
- public TestPage() {
+ @Override
+ protected void onPageInitialize() {
+ super.onPageInitialize();
+
final EditContext editContext = EditableUtils.getContext(new Project());
Form<?> form = new Form<Void>("form") {