incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmatth...@apache.org
Subject svn commit: r1049143 - in /incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher: ./ debug/ view/action/ view/display/ view/logon/ view/simple/
Date Tue, 14 Dec 2010 16:15:36 GMT
Author: rmatthews
Date: Tue Dec 14 16:15:35 2010
New Revision: 1049143

URL: http://svn.apache.org/viewvc?rev=1049143&view=rev
Log:
Improved debugging and error handling.

Fixed log-on on process.

Modified:
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/Dispatcher.java
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/UserManager.java
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/debug/DebugAction.java
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/debug/DebugView.java
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/action/ActionButton.java
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/action/Methods.java
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/display/Title.java
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Logon.java
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/User.java
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/simple/AbstractConditionalBlock.java

Modified: incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/Dispatcher.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/Dispatcher.java?rev=1049143&r1=1049142&r2=1049143&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/Dispatcher.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/Dispatcher.java
Tue Dec 14 16:15:35 2010
@@ -32,6 +32,7 @@ import java.util.Map;
 import java.util.Stack;
 import java.util.TreeSet;
 
+import org.apache.isis.core.commons.debug.DebugString;
 import org.apache.isis.core.commons.exceptions.IsisException;
 import org.apache.isis.core.commons.factory.InstanceFactory;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
@@ -41,6 +42,8 @@ import org.apache.isis.core.metamodel.fa
 import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
 import org.apache.isis.core.runtime.context.IsisContext;
+import org.apache.isis.core.runtime.persistence.PersistenceSession;
+import org.apache.isis.core.runtime.transaction.IsisTransactionManager;
 import org.apache.isis.viewer.scimpi.dispatcher.action.ActionAction;
 import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext;
 import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext.Debug;
@@ -64,7 +67,6 @@ import org.dom4j.io.SAXReader;
 
 
 public class Dispatcher {
-    private static final String LOGIN = "login";
     public static final String ACTION = "_action";
     public static final String EDIT = "_edit";
     public static final String REMOVE = "_remove";
@@ -81,62 +83,52 @@ public class Dispatcher {
     public void process(RequestContext context, String servletPath) {
 
         try {
-        /*
-         *  This is commented out untill the comment above is dealt with.  Once that is done
this can be deleted.           
-            if (session == null && IsisContext.getSession() == null && !servletPath.endsWith("logon.app"))
{
-                String username = getParameter("username");
-                if (username == null) {
-                    UserManager.startRequest(session);
-                    context.setRequestPath("/" + LOGIN + "." + EXTENSION);
-                    String contextPath = context.getContextPath();
-                    String queryString = context.getQueryString();
-                    context.addVariable("login-path", contextPath + servletPath + (queryString
== null ? "" : "?" + queryString),
-                            Scope.REQUEST);
-                } else {
-                    String password = getParameter("password");
-                    session = UserManager.authenticate(new AuthenticationRequestPassword(username,
password));
-                    context.setSession(session);
-                    context.setRequestPath(servletPath);
-                    UserManager.startRequest(session);
-                    context.startRequest();
-                }
-            } else {
-                UserManager.startRequest(session);
-                context.startRequest();
-                context.setRequestPath(servletPath);
-                processActions(context, servletPath);
-            }
-            */
-            UserManager.startRequest(context);
-            AuthenticationSession session = context.getSession(); 
+            AuthenticationSession session = UserManager.startRequest(context);
+            LOG.debug("exsiting session: " + session);
+            LOG.info("processing request " + servletPath);
+
             IsisContext.getPersistenceSession().getTransactionManager().startTransaction();
-            context.startRequest();
             context.setRequestPath(servletPath);
+            context.startRequest();
+            
             // TODO review how session should start 
-   //         if (!newSession || servletPath.endsWith(context.getContextPath() + "/logon.app"))
{
-                // sessions should not start of with an action
-                processActions(context, servletPath);
-                boolean stillSameSession = context.getSession() == session;
-                List<String> copyMessages = IsisContext.getMessageBroker().getMessages();
-                List<String> copyWarnings = IsisContext.getMessageBroker().getWarnings();
-                if (stillSameSession) {
-                    IsisContext.getPersistenceSession().getTransactionManager().endTransaction();
-                }
-                IsisContext.getPersistenceSession().getTransactionManager().startTransaction();
-                for (String message : copyMessages) {
-                    IsisContext.getMessageBroker().addMessage(message);
-                }
-                for (String warning : copyWarnings) {
-                    IsisContext.getMessageBroker().addWarning(warning);
-                }
-                
-  //          }
+            // if (!newSession || servletPath.endsWith(context.getContextPath() + "/logon.app"))
{
+            // sessions should not start of with an action
+            
+            processActions(context, servletPath);
+            IsisTransactionManager transactionManager = IsisContext.getPersistenceSession().getTransactionManager();
+            if (transactionManager.getTransaction().getState().canFlush()) {
+                transactionManager.flushTransaction();
+            }
             processView(context);
-            IsisContext.getPersistenceSession().getTransactionManager().endTransaction();
+            // Note - the session will have changed since the earlier call if a user has
logged in or out in the action processing above.
+            transactionManager = IsisContext.getPersistenceSession().getTransactionManager();
+            if (transactionManager.getTransaction().getState().canCommit()) {
+                IsisContext.getPersistenceSession().getTransactionManager().endTransaction();
+            }
         } catch (Throwable e) {
-            LOG.error("process failed", e);
-            generateErrorPage(e, context);
-            IsisContext.getPersistenceSession().getTransactionManager().abortTransaction();
+            DebugString error = new DebugString();
+            
+            List<String> messages =  IsisContext.getMessageBroker().getMessages();
+            for (String message : messages) {
+                context.getWriter().append("<div class=\"message\">message: " + message
+ "</div>");
+                error.appendln("message", message);
+            }
+            messages =  IsisContext.getMessageBroker().getWarnings();
+            for (String message : messages) {
+                context.getWriter().append("<div class=\"message\">warning: " + message
+ "</div>");
+                error.appendln("warning", message);
+            }
+
+            generateErrorPage(e, context, error);
+            PersistenceSession checkSession = IsisContext.getPersistenceSession();
+            IsisTransactionManager transactionManager = checkSession.getTransactionManager();
+            if (transactionManager.getTransaction().getState().canAbort()) {
+                transactionManager.abortTransaction();
+            }
+            
+            String message = "failed while processing " + servletPath;
+            LOG.error(message + "\n" + error + "\n" + message, e);
 
         } finally {
             try {
@@ -168,7 +160,7 @@ public class Dispatcher {
                 throw new ScimpiException("No logic for " + actionName);
             }
 
-            LOG.debug("processing " + action);
+            LOG.debug("processing action: " + action);
             action.process(context);
             String fowardTo = context.forwardTo();
             if (fowardTo != null) {
@@ -199,16 +191,7 @@ public class Dispatcher {
         request.appendDebug("processing " + fullPath); 
         try {
             request.processNextTag();
-            List<String> messages = IsisContext.getMessageBroker().getMessages();
-            if (messages.size() > 0) {
-                // TODO write out all messages
-                context.getWriter().println("Ignored messages");
-            }
-            List<String> warnings = IsisContext.getMessageBroker().getWarnings();
-            if (warnings.size() > 0) {
-                // TODO write out all warning
-                context.getWriter().println("Ignored warnings");
-            }
+            noteIfMessagesHaveNotBeenDisplay(context);
             IsisContext.getUpdateNotifier().clear();
         } catch (RuntimeException e) {
             IsisContext.getMessageBroker().getMessages();
@@ -219,13 +202,26 @@ public class Dispatcher {
         String page = request.popBuffer();
         context.getWriter().write(page);
         if (context.getDebug() == Debug.PAGE) {
-            DebugView view = new DebugView(context.getWriter());
+            DebugView view = new DebugView(context.getWriter(), new DebugString());
             view.startTable();
             context.append(view);
             view.endTable();
         }
     }
 
+    public void noteIfMessagesHaveNotBeenDisplay(RequestContext context) {
+        List<String> messages = IsisContext.getMessageBroker().getMessages();
+        if (messages.size() > 0) {
+            // TODO write out all messages
+            context.getWriter().println("Note - messages existed but where not displayed");
+        }
+        List<String> warnings = IsisContext.getMessageBroker().getWarnings();
+        if (warnings.size() > 0) {
+            // TODO write out all warning
+            context.getWriter().println("Note - warnings existed but where not displayed");
+        }
+    }
+
     private String determineFile(RequestContext context, String file) {
         String fileName = file.trim();
         if (fileName.startsWith(GENERIC)) {
@@ -314,12 +310,12 @@ public class Dispatcher {
      */
     }
 
-    private void generateErrorPage(Throwable exception, RequestContext requestContext) {
+    private void generateErrorPage(Throwable exception, RequestContext requestContext, DebugString
error) {
         requestContext.setStatus(500);
         requestContext.setContentType("text/html");
 
         PrintWriter writer = requestContext.getWriter();
-        DebugView errorView = new DebugView(writer);
+        DebugView errorView = new DebugView(writer, error);
         errorView.header();
         errorView.startTable();
         try {

Modified: incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/UserManager.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/UserManager.java?rev=1049143&r1=1049142&r2=1049143&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/UserManager.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/UserManager.java
Tue Dec 14 16:15:35 2010
@@ -40,14 +40,17 @@ public class UserManager {
         return instance.authenticationManager;
     }
 
-    public static void startRequest(RequestContext context) {
+    public static AuthenticationSession startRequest(RequestContext context) {
         AuthenticationSession session = context.getSession();
         if (session == null) {
             session = new UserlessSession();
+            LOG.info("start anonymous request: " + session);
+        } else {
+            LOG.info("start request for: " + session.getUserName());
         }
-        LOG.info("start request: " + session);
         IsisContext.closeSession();
         IsisContext.openSession(session);
+        return session;
     }
 
     public static AuthenticationSession authenticate(AuthenticationRequestPassword passwordAuthenticationRequest)
{
@@ -61,7 +64,11 @@ public class UserManager {
     }
 
     public static void endRequest(final AuthenticationSession session) {
-        LOG.info("end request: " + session);
+        if (session == null) {
+            LOG.info("end anonymous request");
+        } else {
+            LOG.info("end request for: " + session.getUserName());
+        }
         IsisContext.closeSession();
     }
 

Modified: incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/debug/DebugAction.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/debug/DebugAction.java?rev=1049143&r1=1049142&r2=1049143&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/debug/DebugAction.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/debug/DebugAction.java
Tue Dec 14 16:15:35 2010
@@ -56,7 +56,7 @@ public class DebugAction implements Acti
     public void debug(DebugView view) {}
 
     public void process(RequestContext context) throws IOException {
-        DebugView view = new DebugView(context.getWriter());
+        DebugView view = new DebugView(context.getWriter(), new DebugString());
         view.header();
         view.appendln("<div class=\"links\">");
         view.appendln("<a href=\"debug.app?action=system\">System</a>");

Modified: incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/debug/DebugView.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/debug/DebugView.java?rev=1049143&r1=1049142&r2=1049143&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/debug/DebugView.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/debug/DebugView.java
Tue Dec 14 16:15:35 2010
@@ -22,12 +22,16 @@ package org.apache.isis.viewer.scimpi.di
 
 import java.io.PrintWriter;
 
+import org.apache.isis.core.commons.debug.DebugString;
+
 
 public class DebugView {
     private final PrintWriter writer;
+    private final DebugString debug;
 
-    public DebugView(PrintWriter writer) {
+    public DebugView(PrintWriter writer, DebugString debug) {
         this.writer = writer;
+        this.debug = debug;
     }
     
     public void header() {
@@ -58,6 +62,7 @@ public class DebugView {
         String message = e.getMessage();
         if (message != null) {
             writer.println("<tr><td class=\"error\" colspan=\"2\" >" + message
+ "<td></tr>");
+            debug.appendln(message);
         }
         causingException(e);
         writer.println("<tr><td class=\"code\" colspan=\"2\" >");
@@ -69,12 +74,14 @@ public class DebugView {
         Throwable cause = throwable.getCause();
         if (cause != null && cause != throwable) {
             writer.println("<tr><td colspan=\"2\" >" + cause.getMessage() + "<td></tr>");
+            debug.append(cause.getMessage());
             causingException(cause);
         }
     }
 
     public void divider(String title) {
         writer.println("<tr><th class=\"title\" colspan=\"2\" >" + title + "</th></tr>");
+        debug.appendTitle(title);
     }
 
     public void endTable() {
@@ -82,12 +89,14 @@ public class DebugView {
     }
 
     public void appendRow(String name, Object object) {
-        writer.println("<tr><td class=\"label\">" + name + "</td><td>"
-                + (object == null ? "null" : object.toString()) + "<td></tr>");
+        String value = object == null ? "null" : object.toString();
+        writer.println("<tr><td class=\"label\">" + name + "</td><td>"
+ value + "<td></tr>");
+        debug.appendln(name, value);
     }
 
     public void appendRow(Object object) {
         writer.println("<tr><td colspan=\"2\">" + object.toString() + "<td></tr>");

+        debug.appendln(object.toString());
     } 
 
     public void appendDebugTrace(String text) { 

Modified: incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/action/ActionButton.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/action/ActionButton.java?rev=1049143&r1=1049142&r2=1049143&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/action/ActionButton.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/action/ActionButton.java
Tue Dec 14 16:15:35 2010
@@ -41,6 +41,7 @@ public class ActionButton extends Abstra
         String methodName = request.getRequiredProperty(METHOD);
         String forwardResultTo = request.getOptionalProperty(VIEW);
         String forwardVoidTo = request.getOptionalProperty(VOID);
+        String forwardErrorTo = request.getOptionalProperty(ERRORS);
         String variable = request.getOptionalProperty(RESULT_NAME);
         String scope = request.getOptionalProperty(SCOPE);
         String buttonTitle = request.getOptionalProperty(TITLE);
@@ -74,7 +75,7 @@ public class ActionButton extends Abstra
         
         if (MethodsUtils.isVisibleAndUsable(object, action) && MethodsUtils.canRunMethod(object,
action, objectParameters).isAllowed()) {
             // TODO use the form creation mechanism as used in ActionForm
-            write(request, object, action, parameters, objectId, version, forwardResultTo,
forwardVoidTo, variable, scope, buttonTitle, resultOverride, idName, className);
+            write(request, object, action, parameters, objectId, version, forwardResultTo,
forwardVoidTo, forwardErrorTo, variable, scope, buttonTitle, resultOverride, idName, className);
         }
         request.popBlockContent();
     }
@@ -88,6 +89,7 @@ public class ActionButton extends Abstra
             String version,
             String forwardResultTo,
             String forwardVoidTo,
+            String forwardErrorTo,
             String variable,
             String scope,
             String buttonTitle, 
@@ -135,8 +137,13 @@ public class ActionButton extends Abstra
             forwardResultTo = context.fullFilePath(forwardResultTo);
             request.appendHtml("  <input type=\"hidden\" name=\"" + VIEW + "\" value=\""
+ forwardResultTo + "\" />\n");
         }
+        if (forwardErrorTo == null) {
+            forwardErrorTo = request.getContext().getResourceFile();
+        }
+        forwardErrorTo = context.fullFilePath(forwardErrorTo);
+        request.appendHtml("  <input type=\"hidden\" name=\"" + ERRORS + "\" value=\""
+ forwardErrorTo + "\" />\n");
         if (forwardVoidTo == null) {
-           forwardVoidTo = request.getContext().getResourceFile();
+            forwardVoidTo = request.getContext().getResourceFile();
         }
         forwardVoidTo = context.fullFilePath(forwardVoidTo);
         request.appendHtml("  <input type=\"hidden\" name=\"" + VOID + "\" value=\"" +
forwardVoidTo + "\" />\n");

Modified: incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/action/Methods.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/action/Methods.java?rev=1049143&r1=1049142&r2=1049143&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/action/Methods.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/action/Methods.java
Tue Dec 14 16:15:35 2010
@@ -122,7 +122,7 @@ public class Methods extends AbstractEle
             } else {
                 String version = request.getContext().mapVersion(adapter);
                 if (action.getParameterCount() == 0) {
-                    ActionButton.write(request, adapter, action, parameters, objectId, version,
"_generic." + Dispatcher.EXTENSION, null,
+                    ActionButton.write(request, adapter, action, parameters, objectId, version,
"_generic." + Dispatcher.EXTENSION, null, null,
                             null, null, null, null, null, null);
                 } else if (showForms) {
                     CreateFormParameter params = new CreateFormParameter();

Modified: incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/display/Title.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/display/Title.java?rev=1049143&r1=1049142&r2=1049143&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/display/Title.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/display/Title.java
Tue Dec 14 16:15:35 2010
@@ -26,6 +26,7 @@ import org.apache.isis.core.runtime.cont
 import org.apache.isis.viewer.scimpi.dispatcher.AbstractElementProcessor;
 import org.apache.isis.viewer.scimpi.dispatcher.ForbiddenException;
 import org.apache.isis.viewer.scimpi.dispatcher.processor.Request;
+import org.apache.isis.viewer.scimpi.dispatcher.util.MethodsUtils;
 
 
 public class Title extends AbstractElementProcessor {
@@ -36,7 +37,7 @@ public class Title extends AbstractEleme
         boolean isIconShowing = request.isRequested(SHOW_ICON, true);
         String className = request.getOptionalProperty(CLASS);
         className = className == null ? "title-icon" : className;
-        ObjectAdapter object = request.getContext().getMappedObjectOrResult(id);
+        ObjectAdapter object = MethodsUtils.findObject(request.getContext(), id);
         if (fieldName != null) {
             ObjectAssociation field = object.getSpecification().getAssociation(fieldName);
             if (field.isVisible(IsisContext.getAuthenticationSession(), object).isVetoed())
{

Modified: incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Logon.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Logon.java?rev=1049143&r1=1049142&r2=1049143&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Logon.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Logon.java
Tue Dec 14 16:15:35 2010
@@ -23,7 +23,9 @@ package org.apache.isis.viewer.scimpi.di
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.isis.core.runtime.context.IsisContext;
 import org.apache.isis.viewer.scimpi.dispatcher.AbstractElementProcessor;
+import org.apache.isis.viewer.scimpi.dispatcher.UserlessSession;
 import org.apache.isis.viewer.scimpi.dispatcher.processor.Request;
 import org.apache.isis.viewer.scimpi.dispatcher.view.form.HiddenInputField;
 import org.apache.isis.viewer.scimpi.dispatcher.view.form.InputField;
@@ -38,23 +40,30 @@ public class Logon extends AbstractEleme
             view = (String) request.getContext().getVariable("login-path");
         }
 
+        boolean isNotLoggedIn = IsisContext.getSession().getAuthenticationSession() instanceof
UserlessSession;
+        if (isNotLoggedIn) {
+            loginForm(request, view);
+        }
+    }
+
+    public static void loginForm(Request request, String view) {
         String error = request.getOptionalProperty(ERRORS, request.getContext().getRequestedFile());
         List<HiddenInputField> hiddenFields = new ArrayList<HiddenInputField>();
         hiddenFields.add(new HiddenInputField(ERRORS, error));
         if (view != null) {
             hiddenFields.add(new HiddenInputField(VIEW, view));
         }
-
+   
         InputField nameField = new InputField("username");
         nameField.setType(InputField.TEXT);
         nameField.setLabel("User Name");
-
+   
         InputField passwordField = new InputField("password");
         passwordField.setType(InputField.PASSWORD);
         passwordField.setLabel("Password");
-
+   
         InputField[] fields = new InputField[] { nameField, passwordField, };
-
+   
         String legend = request.getOptionalProperty(LEGEND);
         String loginButtonTitle = request.getOptionalProperty(TITLE, "Log in");
         String className = request.getOptionalProperty(CLASS, "login");

Modified: incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/User.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/User.java?rev=1049143&r1=1049142&r2=1049143&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/User.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/User.java
Tue Dec 14 16:15:35 2010
@@ -23,6 +23,7 @@ package org.apache.isis.viewer.scimpi.di
 import org.apache.isis.core.runtime.context.IsisContext;
 import org.apache.isis.viewer.scimpi.dispatcher.AbstractElementProcessor;
 import org.apache.isis.viewer.scimpi.dispatcher.Dispatcher;
+import org.apache.isis.viewer.scimpi.dispatcher.UserlessSession;
 import org.apache.isis.viewer.scimpi.dispatcher.processor.Request;
 
 
@@ -33,23 +34,38 @@ public class User extends AbstractElemen
     private static final String DEFAULT_LOGOUT_VIEW = "logout." + Dispatcher.EXTENSION;
 
     public void process(Request request) {
-        boolean isLoggedIn = IsisContext.getSession() != null;
+        boolean isLoggedIn = !(IsisContext.getSession().getAuthenticationSession() instanceof
UserlessSession);
         request.appendHtml("<div class=\"user\">");
         if (isLoggedIn) {
-            String user = request.getOptionalProperty(NAME);
-            if (user == null) {
-                user = IsisContext.getAuthenticationSession().getUserName();
-            }
-            request.appendHtml("Welcome <span class=\"name\">" + user + "</span>,
");
-            String logoutView = request.getOptionalProperty(LOGOUT_VIEW, DEFAULT_LOGOUT_VIEW);
-            request.appendHtml("<a class=\"link\" href=\"logout.app?view=" + logoutView
+ "\">Log out</a>");
+            displayUserAndLogoutLink(request);
         } else {
-            String loginView = request.getOptionalProperty(LOGIN_VIEW, DEFAULT_LOGIN_VIEW);
-            request.appendHtml("<a div class=\"link\" href=\"" + loginView + "\">Log
in</a>");
+            displayLoginForm(request);
         }
         request.appendHtml("</div>");
     }
 
+    public void displayLoginForm(Request request) {
+        String loginView = request.getOptionalProperty(LOGIN_VIEW);
+        if (loginView == null) {
+            Logon.loginForm(request, ".");
+        } else {
+            if (loginView.trim().length() == 0) {
+                loginView = DEFAULT_LOGIN_VIEW;
+            }
+            request.appendHtml("<a div class=\"link\" href=\"" + loginView + "\">Log
in</a>");
+        }
+    }
+
+    public void displayUserAndLogoutLink(Request request) {
+        String user = request.getOptionalProperty(NAME);
+        if (user == null) {
+            user = IsisContext.getAuthenticationSession().getUserName();
+        }
+        request.appendHtml("Welcome <span class=\"name\">" + user + "</span>,
");
+        String logoutView = request.getOptionalProperty(LOGOUT_VIEW, DEFAULT_LOGOUT_VIEW);
+        request.appendHtml("<a class=\"link\" href=\"logout.app?view=" + logoutView +
"\">Log out</a>");
+    }
+
     public String getName() {
         return "user";
     }

Modified: incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/simple/AbstractConditionalBlock.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/simple/AbstractConditionalBlock.java?rev=1049143&r1=1049142&r2=1049143&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/simple/AbstractConditionalBlock.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/simple/AbstractConditionalBlock.java
Tue Dec 14 16:15:35 2010
@@ -33,6 +33,7 @@ import org.apache.isis.core.runtime.cont
 import org.apache.isis.viewer.scimpi.dispatcher.AbstractElementProcessor;
 import org.apache.isis.viewer.scimpi.dispatcher.ScimpiException;
 import org.apache.isis.viewer.scimpi.dispatcher.processor.Request;
+import org.apache.isis.viewer.scimpi.dispatcher.util.MethodsUtils;
 
 
 public abstract class AbstractConditionalBlock extends AbstractElementProcessor {
@@ -42,7 +43,7 @@ public abstract class AbstractConditiona
         
         String method = request.getOptionalProperty(METHOD + "-visible");
         if (method != null) {
-            ObjectAdapter object = (ObjectAdapter) request.getContext().getMappedObjectOrResult(id);
+            ObjectAdapter object = MethodsUtils.findObject(request.getContext(), id);
             // TODO needs to work irrespective of parameters 
             ObjectAction objectAction = object.getSpecification().getObjectAction(ObjectActionType.USER,
method, new ObjectSpecification[0]);
             Consent visible = objectAction.isVisible(IsisContext.getAuthenticationSession(),
object);
@@ -52,7 +53,7 @@ public abstract class AbstractConditiona
 
         method = request.getOptionalProperty(METHOD + "-usable");
         if (method != null) {
-            ObjectAdapter object = (ObjectAdapter) request.getContext().getMappedObjectOrResult(id);
+            ObjectAdapter object = MethodsUtils.findObject(request.getContext(), id);
             // TODO needs to work irrespective of parameters 
             ObjectAction objectAction = object.getSpecification().getObjectAction(ObjectActionType.USER,
method, new ObjectSpecification[0]);
             Consent usable = objectAction.isUsable(IsisContext.getAuthenticationSession(),
object);
@@ -62,7 +63,7 @@ public abstract class AbstractConditiona
 
         method = request.getOptionalProperty(METHOD + "-exists");
         if (method != null) {
-            ObjectAdapter object = (ObjectAdapter) request.getContext().getMappedObjectOrResult(id);
+            ObjectAdapter object = MethodsUtils.findObject(request.getContext(), id);
             List<? extends ObjectAction> objectActions = object.getSpecification().getObjectActionList(ObjectActionType.USER);
             boolean methodExists = false;
             for (ObjectAction objectAssociation : objectActions) {
@@ -77,7 +78,7 @@ public abstract class AbstractConditiona
 
         String field = request.getOptionalProperty(FIELD + "-visible");
         if (field != null) {
-            ObjectAdapter object = (ObjectAdapter) request.getContext().getMappedObjectOrResult(id);
+            ObjectAdapter object = MethodsUtils.findObject(request.getContext(), id);
             ObjectAssociation objectField = object.getSpecification().getAssociation(field);
             Consent visible = objectField.isVisible(IsisContext.getAuthenticationSession(),
object);
             processTags(visible.isAllowed(), request);
@@ -86,7 +87,7 @@ public abstract class AbstractConditiona
 
         field = request.getOptionalProperty(FIELD + "-exists");
         if (field != null) {
-            ObjectAdapter object = (ObjectAdapter) request.getContext().getMappedObjectOrResult(id);
+            ObjectAdapter object = MethodsUtils.findObject(request.getContext(), id);
             List<? extends ObjectAssociation> objectFields = object.getSpecification().getAssociationList();
             boolean fieldExists = false;
             for (ObjectAssociation objectAssociation : objectFields) {
@@ -101,7 +102,7 @@ public abstract class AbstractConditiona
 
         field = request.getOptionalProperty(FIELD + "-editable");
         if (field != null) {
-            ObjectAdapter object = (ObjectAdapter) request.getContext().getMappedObjectOrResult(id);
+            ObjectAdapter object = MethodsUtils.findObject(request.getContext(), id);
             ObjectAssociation objectField = object.getSpecification().getAssociation(field);
             Consent usable = objectField.isUsable(IsisContext.getAuthenticationSession(),
object);
             processTags(usable.isAllowed(), request);
@@ -110,7 +111,7 @@ public abstract class AbstractConditiona
         
         field = request.getOptionalProperty(FIELD + "-empty");
         if (field != null) {
-            ObjectAdapter object = (ObjectAdapter) request.getContext().getMappedObjectOrResult(id);
+            ObjectAdapter object = MethodsUtils.findObject(request.getContext(), id);
             ObjectAssociation objectField = object.getSpecification().getAssociation(field);
             IsisContext.getPersistenceSession().resolveField(object, objectField);
             ObjectAdapter fld = objectField.get(object);
@@ -127,7 +128,7 @@ public abstract class AbstractConditiona
         
         field = request.getOptionalProperty(FIELD + "-set");
         if (field != null) {
-            ObjectAdapter object = (ObjectAdapter) request.getContext().getMappedObjectOrResult(id);
+            ObjectAdapter object = MethodsUtils.findObject(request.getContext(), id);
             ObjectAssociation objectField = object.getSpecification().getAssociation(field);
             IsisContext.getPersistenceSession().resolveField(object, objectField);
             ObjectAdapter fld = objectField.get(object);
@@ -150,7 +151,7 @@ public abstract class AbstractConditiona
 
         String type = request.getOptionalProperty(TYPE);
         if (type != null) {
-            ObjectAdapter object = (ObjectAdapter) request.getContext().getMappedObjectOrResult(id);
+            ObjectAdapter object = MethodsUtils.findObject(request.getContext(), id);
             Class<?> cls = forClass(request);
             boolean hasType = cls == null || cls.isAssignableFrom(object.getObject().getClass());

             processTags(hasType, request);



Mime
View raw message