You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2015/01/09 06:58:27 UTC
[09/50] [abbrv] isis git commit: ISIS-990: UserProfileService along
with example usage in todoapp.
ISIS-990: UserProfileService along with example usage in todoapp.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/b78c07f5
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/b78c07f5
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/b78c07f5
Branch: refs/heads/ISIS-970
Commit: b78c07f571efbcb398b4785a96c5fff835e43fc9
Parents: f8573ff
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Wed Jan 7 17:35:36 2015 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Wed Jan 7 17:35:36 2015 +0000
----------------------------------------------------------------------
.../viewer/wicket/ui/pages/PageAbstract.java | 109 ++++++++++++-------
.../services/userprof/UserProfileService.java | 56 ++++++++++
.../userprof/CustomUserProfileService.java | 43 ++++++++
.../src/main/webapp/WEB-INF/isis.properties | 2 +-
4 files changed, 169 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/b78c07f5/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/PageAbstract.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/PageAbstract.java b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/PageAbstract.java
index eee315f..94b3378 100644
--- a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/PageAbstract.java
+++ b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/PageAbstract.java
@@ -63,6 +63,7 @@ import org.slf4j.LoggerFactory;
import org.apache.isis.applib.annotation.DomainServiceLayout;
import org.apache.isis.applib.services.exceprecog.ExceptionRecognizer;
import org.apache.isis.applib.services.exceprecog.ExceptionRecognizerComposite;
+import org.apache.isis.applib.services.userprof.UserProfileService;
import org.apache.isis.core.commons.authentication.AuthenticationSession;
import org.apache.isis.core.commons.authentication.MessageBroker;
import org.apache.isis.core.commons.config.IsisConfiguration;
@@ -96,6 +97,10 @@ import org.apache.isis.viewer.wicket.ui.util.CssClassAppender;
*/
public abstract class PageAbstract extends WebPage implements ActionPromptProvider {
+ public static final String TERTIARY_MENU_BAR = "tertiaryMenuBar";
+ public static final String SECONDARY_MENU_BAR = "secondaryMenuBar";
+ public static final String PRIMARY_MENU_BAR = "primaryMenuBar";
+ public static final String USER_NAME = "userName";
private static Logger LOG = LoggerFactory.getLogger(PageAbstract.class);
private static final long serialVersionUID = 1L;
@@ -197,7 +202,7 @@ public abstract class PageAbstract extends WebPage implements ActionPromptProvid
// ensure that all collected JavaScript contributions are loaded at the page footer
add(new HeaderResponseContainer("footerJS", "footerJS"));
- } catch(RuntimeException ex) {
+ } catch(final RuntimeException ex) {
LOG.error("Failed to construct page, going back to sign in page", ex);
@@ -216,14 +221,14 @@ public abstract class PageAbstract extends WebPage implements ActionPromptProvid
}
}
- private void addApplicationName(MarkupContainer themeDiv) {
- BookmarkablePageLink<Void> applicationNameLink = homePageLink("applicationName");
+ private void addApplicationName(final MarkupContainer themeDiv) {
+ final BookmarkablePageLink<Void> applicationNameLink = homePageLink("applicationName");
applicationNameLink.setBody(Model.of(applicationName));
themeDiv.add(applicationNameLink);
}
private void addThemePicker() {
- ThemeChooser themeChooser = new ThemeChooser(ID_THEME_PICKER);
+ final ThemeChooser themeChooser = new ThemeChooser(ID_THEME_PICKER);
themeDiv.addOrReplace(themeChooser);
}
@@ -238,7 +243,7 @@ public abstract class PageAbstract extends WebPage implements ActionPromptProvid
}
@Override
- public void renderHead(IHeaderResponse response) {
+ public void renderHead(final IHeaderResponse response) {
super.renderHead(response);
@@ -250,7 +255,7 @@ public abstract class PageAbstract extends WebPage implements ActionPromptProvid
response.render(JavaScriptReferenceHeaderItem.forReference(JQUERY_LIVEQUERY_JS));
response.render(JavaScriptReferenceHeaderItem.forReference(JQUERY_ISIS_WICKET_VIEWER_JS));
- JGrowlBehaviour jGrowlBehaviour = new JGrowlBehaviour();
+ final JGrowlBehaviour jGrowlBehaviour = new JGrowlBehaviour();
jGrowlBehaviour.renderFeedbackMessages(response);
if(applicationCss != null) {
@@ -260,42 +265,62 @@ public abstract class PageAbstract extends WebPage implements ActionPromptProvid
response.render(JavaScriptReferenceHeaderItem.forUrl(applicationJs));
}
- // TODO mgrigorov Remove before merge to master
- WebClientInfo clientInfo = WebSession.get().getClientInfo();
- ClientProperties properties = clientInfo.getProperties();
- if (!(properties.isBrowserInternetExplorer() && properties.getBrowserVersionMajor() < 9)) {
- // use BootLint for any browser but IE 6-8
- response.render(JavaScriptHeaderItem.forReference(BootlintJavaScriptReference.INSTANCE));
+ if(isModernBrowser()) {
+ addBootLint(response);
}
}
+ private void addBootLint(final IHeaderResponse response) {
+ response.render(JavaScriptHeaderItem.forReference(BootlintJavaScriptReference.INSTANCE));
+ }
+
+ private boolean isModernBrowser() {
+ return !isIePre9();
+ }
+
+ private boolean isIePre9() {
+ final WebClientInfo clientInfo = WebSession.get().getClientInfo();
+ final ClientProperties properties = clientInfo.getProperties();
+ if (properties.isBrowserInternetExplorer())
+ if (properties.getBrowserVersionMajor() < 9)
+ return true;
+ return false;
+ }
+
/**
* Contributes theme specific Bootstrap CSS overrides if there is such resource
*
* @param response The header response to contribute to
*/
- private void contributeThemeSpecificOverrides(IHeaderResponse response) {
- IBootstrapSettings bootstrapSettings = Bootstrap.getSettings(getApplication());
- ITheme activeTheme = bootstrapSettings.getActiveThemeProvider().getActiveTheme();
- String name = activeTheme.name().toLowerCase(Locale.ENGLISH);
- String themeSpecificOverride = "bootstrap-overrides-" + name + ".css";
- ResourceReference.Key themeSpecificOverrideKey = new ResourceReference.Key(PageAbstract.class.getName(), themeSpecificOverride, null, null, null);
+ private void contributeThemeSpecificOverrides(final IHeaderResponse response) {
+ final IBootstrapSettings bootstrapSettings = Bootstrap.getSettings(getApplication());
+ final ITheme activeTheme = bootstrapSettings.getActiveThemeProvider().getActiveTheme();
+ final String name = activeTheme.name().toLowerCase(Locale.ENGLISH);
+ final String themeSpecificOverride = "bootstrap-overrides-" + name + ".css";
+ final ResourceReference.Key themeSpecificOverrideKey = new ResourceReference.Key(PageAbstract.class.getName(), themeSpecificOverride, null, null, null);
if (PackageResource.exists(themeSpecificOverrideKey)) {
response.render(CssHeaderItem.forReference(new CssResourceReference(themeSpecificOverrideKey)));
}
}
- private void addUserName(MarkupContainer themeDiv) {
- Label userName = new Label("userName", getAuthenticationSession().getUserName());
+ private void addUserName(final MarkupContainer themeDiv) {
+ final UserProfileService userProfileService = getUserProfileService();
+ final Label userName = new Label(USER_NAME, userProfileService.userProfileName());
themeDiv.add(userName);
}
+ private UserProfileService getUserProfileService() {
+ final UserProfileService userProfileService = lookupService(UserProfileService.class);
+ final String userProfileName = getAuthenticationSession().getUserName();
+ return userProfileService != null ? userProfileService: new UserProfileService.Default(userProfileName);
+ }
+
- private void addAboutLink(MarkupContainer themeDiv) {
- BookmarkablePageLink<Void> aboutLink = new BookmarkablePageLink<>("aboutLink", AboutPage.class);
+ private void addAboutLink(final MarkupContainer themeDiv) {
+ final BookmarkablePageLink<Void> aboutLink = new BookmarkablePageLink<>("aboutLink", AboutPage.class);
themeDiv.add(aboutLink);
- Label aboutLabel = new Label("aboutMessage", new ResourceModel("aboutLabel"));
+ final Label aboutLabel = new Label("aboutMessage", new ResourceModel("aboutLabel"));
aboutLink.add(aboutLabel);
addDevModeWarning(aboutLink);
}
@@ -304,14 +329,14 @@ public abstract class PageAbstract extends WebPage implements ActionPromptProvid
* Adds a component that shows a warning sign next to "About" link in development mode
* @param container The parent component
*/
- private void addDevModeWarning(MarkupContainer container) {
- WebComponent devModeWarning = new WebComponent("devModeWarning");
+ private void addDevModeWarning(final MarkupContainer container) {
+ final WebComponent devModeWarning = new WebComponent("devModeWarning");
devModeWarning.setVisible(getApplication().usesDevelopmentConfig());
container.add(devModeWarning);
}
private void addBreadcrumbs() {
- BreadcrumbPanel breadcrumbPanel = new BreadcrumbPanel(ID_BREADCRUMBS);
+ final BreadcrumbPanel breadcrumbPanel = new BreadcrumbPanel(ID_BREADCRUMBS);
themeDiv.addOrReplace(breadcrumbPanel);
}
@@ -332,13 +357,13 @@ public abstract class PageAbstract extends WebPage implements ActionPromptProvid
return pageParameters;
}
- private void addServiceActionMenuBars(MarkupContainer container) {
- addMenuBar(container, "primaryMenuBar", DomainServiceLayout.MenuBar.PRIMARY);
- addMenuBar(container, "secondaryMenuBar", DomainServiceLayout.MenuBar.SECONDARY);
- addMenuBar(container, "tertiaryMenuBar", DomainServiceLayout.MenuBar.TERTIARY);
+ private void addServiceActionMenuBars(final MarkupContainer container) {
+ addMenuBar(container, PRIMARY_MENU_BAR, DomainServiceLayout.MenuBar.PRIMARY);
+ addMenuBar(container, SECONDARY_MENU_BAR, DomainServiceLayout.MenuBar.SECONDARY);
+ addMenuBar(container, TERTIARY_MENU_BAR, DomainServiceLayout.MenuBar.TERTIARY);
}
- private void addMenuBar(MarkupContainer container, String id, DomainServiceLayout.MenuBar menuBar) {
+ private void addMenuBar(final MarkupContainer container, final String id, final DomainServiceLayout.MenuBar menuBar) {
final ServiceActionsModel model = new ServiceActionsModel(menuBar);
getComponentFactoryRegistry().addOrReplaceComponent(container, id, ComponentType.SERVICE_ACTIONS, model);
}
@@ -353,13 +378,13 @@ public abstract class PageAbstract extends WebPage implements ActionPromptProvid
* - used to find the best matching {@link ComponentFactory} to
* render the model.
*/
- protected void addChildComponents(MarkupContainer container, final IModel<?> model) {
+ protected void addChildComponents(final MarkupContainer container, final IModel<?> model) {
for (final ComponentType componentType : getChildModelTypes()) {
addComponent(container, componentType, model);
}
}
- private void addComponent(MarkupContainer container, final ComponentType componentType, final IModel<?> model) {
+ private void addComponent(final MarkupContainer container, final ComponentType componentType, final IModel<?> model) {
getComponentFactoryRegistry().addOrReplaceComponent(container, componentType, model);
}
@@ -375,16 +400,16 @@ public abstract class PageAbstract extends WebPage implements ActionPromptProvid
getComponentFactoryRegistry().addOrReplaceComponent(themeDiv, ID_BOOKMARKED_PAGES, ComponentType.BOOKMARKED_PAGES, getBookmarkedPagesModel());
}
- protected void bookmarkPage(BookmarkableModel<?> model) {
+ protected void bookmarkPage(final BookmarkableModel<?> model) {
getBookmarkedPagesModel().bookmarkPage(model);
}
- protected void removeAnyBookmark(EntityModel model) {
+ protected void removeAnyBookmark(final EntityModel model) {
getBookmarkedPagesModel().remove(model);
}
private BookmarkedPagesModel getBookmarkedPagesModel() {
- BookmarkedPagesModelProvider session = (BookmarkedPagesModelProvider) getSession();
+ final BookmarkedPagesModelProvider session = (BookmarkedPagesModelProvider) getSession();
return session.getBookmarkedPagesModel();
}
@@ -414,11 +439,11 @@ public abstract class PageAbstract extends WebPage implements ActionPromptProvid
* Propagates all {@link org.apache.isis.viewer.wicket.model.hints.IsisEventLetterAbstract letter} events down to
* all child components, wrapped in an {@link org.apache.isis.viewer.wicket.model.hints.IsisEnvelopeEvent envelope} event.
*/
- public void onEvent(org.apache.wicket.event.IEvent<?> event) {
- Object payload = event.getPayload();
+ public void onEvent(final org.apache.wicket.event.IEvent<?> event) {
+ final Object payload = event.getPayload();
if(payload instanceof IsisEventLetterAbstract) {
- IsisEventLetterAbstract letter = (IsisEventLetterAbstract)payload;
- IsisEnvelopeEvent broadcastEv = new IsisEnvelopeEvent(letter);
+ final IsisEventLetterAbstract letter = (IsisEventLetterAbstract)payload;
+ final IsisEnvelopeEvent broadcastEv = new IsisEnvelopeEvent(letter);
send(this, Broadcast.BREADTH, broadcastEv);
}
}
@@ -433,6 +458,10 @@ public abstract class PageAbstract extends WebPage implements ActionPromptProvid
return cfra.getComponentFactoryRegistry();
}
+ protected <T> T lookupService(final Class<T> serviceClass) {
+ return getServicesInjector().lookupService(serviceClass);
+ }
+
// ///////////////////////////////////////////////////
// System components
// ///////////////////////////////////////////////////
http://git-wip-us.apache.org/repos/asf/isis/blob/b78c07f5/core/applib/src/main/java/org/apache/isis/applib/services/userprof/UserProfileService.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/userprof/UserProfileService.java b/core/applib/src/main/java/org/apache/isis/applib/services/userprof/UserProfileService.java
new file mode 100644
index 0000000..216c5ad
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/userprof/UserProfileService.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.applib.services.userprof;
+
+import org.apache.isis.applib.annotation.Programmatic;
+
+/**
+ * Optional API providing details about the user .
+ *
+ * <p>
+ * Used by the Wicket viewer in its {@link org.apache.isis.applib.annotation.DomainServiceLayout.MenuBar#TERTIARY tertiary}
+ * "Me" menu bar.
+ * </p>
+ */
+public interface UserProfileService {
+
+ /**
+ * Used as the menu name of the {@link org.apache.isis.applib.annotation.DomainServiceLayout.MenuBar#TERTIARY tertiary}
+ * "Me" menu bar.
+ */
+ @Programmatic
+ String userProfileName();
+
+ /**
+ * Default implementation (instantiated internally by the framework if no
+ * other implementation has been registered).
+ */
+ public static class Default implements UserProfileService {
+ private final String userProfileName;
+
+ public Default(final String userProfileName) {
+ this.userProfileName = userProfileName;
+ }
+
+ @Override
+ public String userProfileName() {
+ return userProfileName;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/b78c07f5/example/application/todoapp/webapp/src/main/java/webapp/userprof/CustomUserProfileService.java
----------------------------------------------------------------------
diff --git a/example/application/todoapp/webapp/src/main/java/webapp/userprof/CustomUserProfileService.java b/example/application/todoapp/webapp/src/main/java/webapp/userprof/CustomUserProfileService.java
new file mode 100644
index 0000000..62ac918
--- /dev/null
+++ b/example/application/todoapp/webapp/src/main/java/webapp/userprof/CustomUserProfileService.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package webapp.userprof;
+
+import org.apache.isis.applib.annotation.DomainService;
+import org.apache.isis.applib.annotation.Programmatic;
+import org.apache.isis.applib.services.userprof.UserProfileService;
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+
+/**
+ * Demonstrates how to provide a custom implementation of the {@link org.apache.isis.applib.services.userprof.UserProfileService}.
+ */
+@DomainService
+public class CustomUserProfileService implements UserProfileService {
+
+ @Override
+ @Programmatic
+ public String userProfileName() {
+ return "Hi " + getAuthenticationSession().getUserName() + "!";
+ }
+
+ protected AuthenticationSession getAuthenticationSession() {
+ return IsisContext.getAuthenticationSession();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/b78c07f5/example/application/todoapp/webapp/src/main/webapp/WEB-INF/isis.properties
----------------------------------------------------------------------
diff --git a/example/application/todoapp/webapp/src/main/webapp/WEB-INF/isis.properties b/example/application/todoapp/webapp/src/main/webapp/WEB-INF/isis.properties
index 0ccea16..db7abf5 100644
--- a/example/application/todoapp/webapp/src/main/webapp/WEB-INF/isis.properties
+++ b/example/application/todoapp/webapp/src/main/webapp/WEB-INF/isis.properties
@@ -176,7 +176,7 @@ isis.services-installer=configuration-and-annotation
isis.services.ServicesInstallerFromAnnotation.packagePrefix=app,\
dom.todo,\
fixture.todo,\
- webapp.admin,\
+ webapp.userprof,\
webapp.prototyping
isis.services = \