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 2013/03/28 11:35:39 UTC
[15/20] ISIS-381: mothballing HTML viewer, SQL security, LDAP security
http://git-wip-us.apache.org/repos/asf/isis/blob/91a8000b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/request/ForwardRequest.java
----------------------------------------------------------------------
diff --git a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/request/ForwardRequest.java b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/request/ForwardRequest.java
deleted file mode 100644
index bfb1808..0000000
--- a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/request/ForwardRequest.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * 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.viewer.html.request;
-
-import org.apache.isis.viewer.html.task.Task;
-
-public class ForwardRequest implements Request {
-
- public static Request editObject(final String objectId) {
- return new ForwardRequest(EDIT_COMMAND, objectId);
- }
-
- public static Request listCollection(final String collectionId) {
- return new ForwardRequest(COLLECTION_COMMAND, collectionId);
- }
-
- public static ForwardRequest viewObject(final String objectId) {
- return new ForwardRequest(OBJECT_COMMAND, objectId);
- }
-
- public static Request viewObject(final String objectId, final String collectionField) {
- return new ForwardRequest(OBJECT_COMMAND, objectId, collectionField);
- }
-
- public static Request viewService(final String objectId) {
- return new ForwardRequest(SERVICE_COMMAND, objectId);
- }
-
- public static Request task(final Task task) {
- final ForwardRequest forwardRequest = new ForwardRequest(TASK_COMMAND, null);
- forwardRequest.taskId = task.getId();
- return forwardRequest;
- }
-
- public static Request taskComplete() {
- final ForwardRequest forwardRequest = new ForwardRequest(TASK_COMMAND, null);
- forwardRequest.submitName = "Ok";
- return forwardRequest;
- }
-
- private final String actionName;
- private Request forwardedRequest;
- private final String objectId;
- private final String fieldName;
- private String submitName;
- private String taskId;
-
- private ForwardRequest(final String actionName, final String id) {
- this(actionName, id, null);
- }
-
- private ForwardRequest(final String actionName, final String objectId, final String fieldName) {
- this.actionName = actionName;
- this.objectId = objectId;
- this.fieldName = fieldName;
- }
-
- @Override
- public void forward(final Request forwardedRequest) {
- this.forwardedRequest = forwardedRequest;
- }
-
- @Override
- public String getActionId() {
- return null;
- }
-
- @Override
- public String getElementId() {
- return null;
- }
-
- @Override
- public String getName() {
- return null;
- }
-
- @Override
- public String getRequestType() {
- return actionName;
- }
-
- @Override
- public String getButtonName() {
- return submitName;
- }
-
- @Override
- public String getProperty() {
- return fieldName;
- }
-
- @Override
- public String getFieldEntry(final int i) {
- return null;
- }
-
- @Override
- public String getTaskId() {
- return taskId;
- }
-
- @Override
- public Request getForward() {
- return forwardedRequest;
- }
-
- @Override
- public String getObjectId() {
- return objectId;
- }
-
- @Override
- public String toString() {
- return "ForwardRequest " + actionName + " " + forwardedRequest;
- }
-
- public static Request logon() {
- return new ForwardRequest("logon", null);
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/91a8000b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/request/Request.java
----------------------------------------------------------------------
diff --git a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/request/Request.java b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/request/Request.java
deleted file mode 100644
index 8681660..0000000
--- a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/request/Request.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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.viewer.html.request;
-
-/**
- * The Request object represents all the information collected from the user
- * when requesting the server do something.
- */
-public interface Request {
- public static final String EDIT_COMMAND = "edit";
- public static final String COLLECTION_COMMAND = "collection";
- public static final String FIELD_COLLECTION_COMMAND = "fieldCollection";
- public static final String OBJECT_COMMAND = "object";
- public static final String SERVICE_COMMAND = "serviceOption";
- public static final String TASK_COMMAND = "task";
- public static final String LOGON_COMMAND = "task";
-
- void forward(Request object);
-
- String getActionId();
-
- /**
- * Name of a property within an object.
- */
- String getProperty();
-
- /**
- * The element within a collection.
- */
- String getElementId();
-
- /**
- * The users entry into a field on the form.
- */
- String getFieldEntry(int i);
-
- Request getForward();
-
- String getObjectId();
-
- /**
- * Name of the request. See the constants defined in this class.
- */
- String getRequestType();
-
- String getTaskId();
-
- /**
- * Name of the button pressed on the form.
- */
- String getButtonName();
-
- String getName();
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/91a8000b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/request/ServletRequest.java
----------------------------------------------------------------------
diff --git a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/request/ServletRequest.java b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/request/ServletRequest.java
deleted file mode 100644
index 0ca1bda..0000000
--- a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/request/ServletRequest.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.viewer.html.request;
-
-import javax.servlet.http.HttpServletRequest;
-
-public class ServletRequest implements Request {
- private Request forwardRequest;
- private final HttpServletRequest request;
- private final String requestType;
-
- public ServletRequest(final HttpServletRequest request) {
- this.request = request;
-
- final String path = request.getServletPath();
- final int from = path.lastIndexOf('/');
- final int to = path.lastIndexOf('.');
- requestType = path.substring(from + 1, to);
- }
-
- @Override
- public void forward(final Request forwardRequest) {
- this.forwardRequest = forwardRequest;
- }
-
- @Override
- public String getActionId() {
- return request.getParameter("action");
- }
-
- @Override
- public String getProperty() {
- return request.getParameter("field");
- }
-
- @Override
- public String getElementId() {
- return request.getParameter("element");
- }
-
- @Override
- public String getFieldEntry(final int i) {
- return request.getParameter("fld" + i);
- }
-
- @Override
- public String getTaskId() {
- return request.getParameter("id");
- }
-
- @Override
- public Request getForward() {
- return forwardRequest;
- }
-
- @Override
- public String getName() {
- return request.getParameter("name");
- }
-
- @Override
- public String getObjectId() {
- return request.getParameter("id");
- }
-
- @Override
- public String getRequestType() {
- return requestType;
- }
-
- @Override
- public String getButtonName() {
- return request.getParameter("button");
- }
-
- @Override
- public String toString() {
- return "ServletRequest " + request.getRequestURI() + "?" + request.getQueryString();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/91a8000b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/AbstractHtmlViewerServlet.java
----------------------------------------------------------------------
diff --git a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/AbstractHtmlViewerServlet.java b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/AbstractHtmlViewerServlet.java
deleted file mode 100644
index a4cda01..0000000
--- a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/AbstractHtmlViewerServlet.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * 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.viewer.html.servlet;
-
-import javax.servlet.http.HttpServlet;
-
-import org.apache.isis.core.commons.authentication.AuthenticationSession;
-import org.apache.isis.core.commons.config.IsisConfiguration;
-import org.apache.isis.core.runtime.authentication.AuthenticationManager;
-import org.apache.isis.core.runtime.system.DeploymentType;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.viewer.html.PathBuilder;
-import org.apache.isis.viewer.html.PathBuilderDefault;
-import org.apache.isis.viewer.html.component.html.HtmlComponentFactory;
-
-public abstract class AbstractHtmlViewerServlet extends HttpServlet {
-
- private static final long serialVersionUID = 1L;
-
- private PathBuilder pathBuilder;
- private HtmlComponentFactory componentFactory;
-
- protected HtmlComponentFactory getHtmlComponentFactory() {
- if(componentFactory == null) {
- componentFactory = new HtmlComponentFactory(getPathBuilder());
- }
- return componentFactory;
- }
-
- protected PathBuilder getPathBuilder() {
- if (pathBuilder != null) {
- return pathBuilder;
- }
- return pathBuilder = new PathBuilderDefault(getServletContext());
- }
-
-
- /**
- * Convenience.
- */
- protected String pathTo(final String prefix) {
- return getPathBuilder().pathTo(prefix);
- }
-
- // //////////////////////////////////////////////////////////////
- // Dependencies (from context)
- // //////////////////////////////////////////////////////////////
-
- protected AuthenticationSession getAuthenticationSession() {
- return IsisContext.getAuthenticationSession();
- }
-
- protected IsisConfiguration getConfiguration() {
- return IsisContext.getConfiguration();
- }
-
- protected AuthenticationManager getAuthenticationManager() {
- return IsisContext.getAuthenticationManager();
- }
-
- protected DeploymentType getDeploymentType() {
- return IsisContext.getDeploymentType();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/91a8000b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/ControllerServlet.java
----------------------------------------------------------------------
diff --git a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/ControllerServlet.java b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/ControllerServlet.java
deleted file mode 100644
index 3c84343..0000000
--- a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/ControllerServlet.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * 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.viewer.html.servlet;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.log4j.Logger;
-
-import org.apache.isis.core.commons.authentication.AuthenticationSession;
-import org.apache.isis.viewer.html.PathBuilder;
-import org.apache.isis.viewer.html.component.Page;
-import org.apache.isis.viewer.html.context.Context;
-import org.apache.isis.viewer.html.request.Request;
-import org.apache.isis.viewer.html.request.ServletRequest;
-import org.apache.isis.viewer.html.servlet.internal.WebController;
-
-public class ControllerServlet extends AbstractHtmlViewerServlet {
-
- private static final long serialVersionUID = 1L;
- private static final Logger LOG = Logger.getLogger(ControllerServlet.class);
-
- private String encoding;
- private WebController controller;
-
- // //////////////////////////////////////////////////////////////////
- // init
- // //////////////////////////////////////////////////////////////////
-
- @Override
- public void init(final ServletConfig servletConfig) throws ServletException {
- super.init(servletConfig);
- encoding =
- getConfiguration().getString(HtmlServletConstants.ENCODING_KEY, HtmlServletConstants.ENCODING_DEFAULT);
-
- controller = getWebController(getPathBuilder());
-
- final boolean debugEnabled = getConfiguration().getBoolean(HtmlServletConstants.DEBUG_KEY);
- controller.setDebug(debugEnabled);
-
- controller.init();
- }
-
- // Don't remove this - It allows other implementations of HtmlViewer to replace the WebController
- protected WebController getWebController(PathBuilder pathBuilder) {
- if (controller == null) {
- controller = new WebController(getPathBuilder());
- }
- return controller;
- }
-
- // //////////////////////////////////////////////////////////////////
- // doGet, doPost
- // //////////////////////////////////////////////////////////////////
-
- @Override
- protected void doPost(final HttpServletRequest request, final HttpServletResponse response)
- throws ServletException, IOException {
- request.setCharacterEncoding(encoding);
- processRequest(request, response);
- }
-
- @Override
- protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException,
- IOException {
- processRequest(request, response);
- }
-
- private void processRequest(final HttpServletRequest request, final HttpServletResponse response)
- throws ServletException, IOException {
- LOG.info("request: " + request.getServletPath() + "?" + request.getQueryString());
-
- final Request req = new ServletRequest(request);
-
- if (req.getRequestType() == null) {
- throw new ServletException("No action specified");
- } else if (!controller.actionExists(req)) {
- throw new ServletException("No such action " + req.getRequestType());
- } else {
- try {
- final Context context = getContextForRequest(request);
- processRequest(request, response, req, context);
- } catch (final Exception e) {
- LOG.error("exception during request handling", e);
- throw new ServletException("Internal exception", e);
- }
- }
- }
-
- private Context getContextForRequest(final HttpServletRequest request) {
- final AuthenticationSession authSession = getAuthenticationSession();
- Context context = (Context) authSession.getAttribute(HtmlServletConstants.AUTHENTICATION_SESSION_CONTEXT_KEY);
- if (context == null || !context.isValid()) {
- context = new Context(getHtmlComponentFactory());
- authSession.setAttribute(HtmlServletConstants.AUTHENTICATION_SESSION_CONTEXT_KEY, context);
- }
- return context;
- }
-
- private void processRequest(final HttpServletRequest request, final HttpServletResponse response,
- final Request req, final Context context) throws IOException, ServletException {
- response.setContentType("text/html");
- response.setCharacterEncoding(encoding);
- // no need to check if logged in; the IsisSessionFilter would
- // have prevented us from getting here.
-
- final Page page = controller.generatePage(context, req);
- if (context.isValid()) {
- if (controller.isDebug()) {
- controller.addDebug(page, req);
- addDebug(request, page);
- }
- PrintWriter writer;
- writer = response.getWriter();
- page.write(writer);
- } else {
- response.sendRedirect(getLogonPage());
- }
- }
-
- protected String getLogonPage() {
- return pathTo(HtmlServletConstants.LOGON_PAGE);
- }
-
- private void addDebug(final HttpServletRequest request, final Page page) {
- page.addDebug("Servlet path", request.getServletPath());
- page.addDebug("Query string", request.getQueryString());
- page.addDebug("Context path", request.getContextPath());
- page.addDebug("Path info", request.getPathInfo());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/91a8000b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/HtmlServletConstants.java
----------------------------------------------------------------------
diff --git a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/HtmlServletConstants.java b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/HtmlServletConstants.java
deleted file mode 100644
index 4f40f75..0000000
--- a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/HtmlServletConstants.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.viewer.html.servlet;
-
-import org.apache.isis.core.commons.authentication.AuthenticationSession;
-import org.apache.isis.core.commons.config.ConfigurationConstants;
-
-public final class HtmlServletConstants {
-
- static final String PROPERTY_BASE = ConfigurationConstants.ROOT + "viewer.html.";
-
- static final String DEBUG_KEY = PROPERTY_BASE + "debug";
-
- static final String ENCODING_KEY = PROPERTY_BASE + "encoding";
- static final String ENCODING_DEFAULT = "ISO-8859-1";
-
- public static final String SUFFIX_INIT_PARAM = "viewer-html.suffix";
- public static final String SUFFIX_INIT_PARAM_VALUE_DEFAULT = "app";
-
- /**
- * Binding to the {@link AuthenticationSession}.
- */
- static final String AUTHENTICATION_SESSION_CONTEXT_KEY = "isis-context";
-
- public static final String LOGON_PAGE = "logon";
- static final String START_PAGE = "start";
-
- private HtmlServletConstants() {
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/91a8000b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/LogonServlet.java
----------------------------------------------------------------------
diff --git a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/LogonServlet.java b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/LogonServlet.java
deleted file mode 100644
index 79d5859..0000000
--- a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/LogonServlet.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * 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.viewer.html.servlet;
-
-import java.io.IOException;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.log4j.Logger;
-
-import org.apache.isis.core.commons.authentication.AuthenticationSession;
-import org.apache.isis.core.runtime.authentication.AuthenticationRequest;
-import org.apache.isis.core.runtime.authentication.AuthenticationRequestPassword;
-import org.apache.isis.core.runtime.authentication.exploration.AuthenticationRequestExploration;
-import org.apache.isis.core.runtime.authentication.standard.RegistrationDetailsPassword;
-import org.apache.isis.core.runtime.system.DeploymentType;
-import org.apache.isis.core.webapp.IsisSessionFilter;
-import org.apache.isis.core.webapp.auth.AuthenticationSessionStrategy;
-import org.apache.isis.viewer.html.component.html.HtmlComponentFactory;
-import org.apache.isis.viewer.html.component.html.LogonFormPage;
-import org.apache.isis.viewer.html.context.Context;
-import org.apache.isis.viewer.html.monitoring.servermonitor.Monitor;
-
-public class LogonServlet extends AbstractHtmlViewerServlet {
-
- private static final long serialVersionUID = 1L;
-
- private static final Logger LOG = Logger.getLogger(LogonServlet.class);
-
- private AuthenticationSessionStrategy authenticationSessionStrategy;
-
- @Override
- public void init() throws ServletException {
- authenticationSessionStrategy = IsisSessionFilter.lookup(getServletConfig().getInitParameter(IsisSessionFilter.AUTHENTICATION_SESSION_STRATEGY_KEY));
- }
-
- @Override
- protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
- doPost(request, response);
- }
-
- @Override
- protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
-
- // look for existing valid session
- final AuthenticationSession existingAuthSession = authenticationSessionStrategy.lookupValid(request, response);
- if (existingAuthSession != null) {
- redirectToStartPage(response, existingAuthSession.getUserName());
- return;
- }
-
- // prompt
- final String user = request.getParameter("username");
- final String password = request.getParameter("password");
- if (user == null && !getDeploymentType().isExploring()) {
- renderPrompt(response, "", "", null);
- return;
- }
-
- // authenticate; re-prompt if required
- final AuthenticationSession authSession = authenticate(user, password);
- if (authSession == null) {
- renderPrompt(response, user, password, "user/password invalid");
- return;
- }
-
- // authenticated
- authenticationSessionStrategy.bind(request, response, authSession);
-
- final Context context = new Context(getHtmlComponentFactory());
- context.setSession(authSession);
- authSession.setAttribute(HtmlServletConstants.AUTHENTICATION_SESSION_CONTEXT_KEY, context);
-
- LOG.info("created session");
- redirectToStartPage(response, user);
- }
-
- protected HtmlComponentFactory getHtmlComponentFactory() {
- return new HtmlComponentFactory(getPathBuilder());
- }
-
- private void redirectToStartPage(final HttpServletResponse response, final String user) throws IOException {
- Monitor.addEvent("Web", "Logon - " + user);
- response.sendRedirect(pathTo(HtmlServletConstants.START_PAGE));
- }
-
- private void renderPrompt(final HttpServletResponse response, final String user, final String password, final String error) throws IOException {
- response.setContentType("text/html");
- final HtmlComponentFactory factory = getHtmlComponentFactory();
- final boolean registerLink = getAuthenticationManager().supportsRegistration(RegistrationDetailsPassword.class);
- final LogonFormPage page = factory.createLogonPage(user, password, registerLink, error);
- page.write(response.getWriter());
- }
-
- protected AuthenticationSession authenticate(final String user, final String password) {
- AuthenticationRequest request;
- if (getDeploymentType() == DeploymentType.EXPLORATION) {
- request = new AuthenticationRequestExploration();
- } else {
- request = new AuthenticationRequestPassword(user, password);
- }
- return getAuthenticationManager().authenticate(request);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/91a8000b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/RegisterServlet.java
----------------------------------------------------------------------
diff --git a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/RegisterServlet.java b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/RegisterServlet.java
deleted file mode 100644
index d103d9a..0000000
--- a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/RegisterServlet.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.viewer.html.servlet;
-
-import java.io.IOException;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import com.google.common.base.Objects;
-
-import org.apache.log4j.Logger;
-
-import org.apache.isis.core.runtime.authentication.standard.RegistrationDetailsPassword;
-import org.apache.isis.viewer.html.component.html.HtmlComponentFactory;
-import org.apache.isis.viewer.html.component.html.RegisterFormPage;
-import org.apache.isis.viewer.html.monitoring.servermonitor.Monitor;
-
-public class RegisterServlet extends AbstractHtmlViewerServlet {
-
- private static final long serialVersionUID = 1L;
-
- @SuppressWarnings("unused")
- private static final Logger LOG = Logger.getLogger(RegisterServlet.class);
-
- @Override
- public void init() throws ServletException {
- }
-
- @Override
- protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
- doPost(request, response);
- }
-
- @Override
- protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
-
- // prompt
- final String user = request.getParameter("username");
- final String password = request.getParameter("password");
- final String password2 = request.getParameter("password2");
- if (user == null) {
- renderPrompt(response, "", "", "", "");
- return;
- }
-
- // register; re-prompt if required
- if (!Objects.equal(password, password2)) {
- renderPrompt(response, user, "", "", "passwords don't match");
- return;
- }
-
- // register; re-prompt if required
- final boolean registered = register(user, password, password2);
- if (!registered) {
- renderPrompt(response, user, "", "", "user name already taken");
- return;
- }
-
- // registered
- redirectToLogonPage(response, user);
- }
-
- private void redirectToLogonPage(final HttpServletResponse response, final String user) throws IOException {
- Monitor.addEvent("Web", "Logon - " + user);
- response.sendRedirect(pathTo(HtmlServletConstants.LOGON_PAGE));
- }
-
- private void renderPrompt(final HttpServletResponse response, final String user, final String password, final String password2, final String message) throws IOException {
- response.setContentType("text/html");
- final HtmlComponentFactory factory = new HtmlComponentFactory(getPathBuilder());
- final RegisterFormPage page = factory.createRegisterPage(user, password, message);
- page.write(response.getWriter());
- }
-
- private boolean register(final String user, final String password, final String password2) {
- return getAuthenticationManager().register(new RegistrationDetailsPassword(user, password));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/91a8000b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/internal/WebController.java
----------------------------------------------------------------------
diff --git a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/internal/WebController.java b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/internal/WebController.java
deleted file mode 100644
index 0d72805..0000000
--- a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/servlet/internal/WebController.java
+++ /dev/null
@@ -1,460 +0,0 @@
-/*
- * 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.viewer.html.servlet.internal;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-
-import org.apache.isis.core.commons.authentication.AuthenticationSession;
-import org.apache.isis.core.commons.debug.DebugString;
-import org.apache.isis.core.commons.exceptions.IsisApplicationException;
-import org.apache.isis.core.commons.exceptions.IsisException;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.util.Dump;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.runtime.userprofile.UserProfile;
-import org.apache.isis.core.runtime.userprofile.UserProfilesDebugUtil;
-import org.apache.isis.viewer.html.PathBuilder;
-import org.apache.isis.viewer.html.action.Action;
-import org.apache.isis.viewer.html.action.ActionException;
-import org.apache.isis.viewer.html.action.ChangeContext;
-import org.apache.isis.viewer.html.action.LogOut;
-import org.apache.isis.viewer.html.action.Welcome;
-import org.apache.isis.viewer.html.action.edit.AddItemToCollection;
-import org.apache.isis.viewer.html.action.edit.EditObject;
-import org.apache.isis.viewer.html.action.edit.RemoveItemFromCollection;
-import org.apache.isis.viewer.html.action.edit.Save;
-import org.apache.isis.viewer.html.action.misc.About;
-import org.apache.isis.viewer.html.action.misc.SetUser;
-import org.apache.isis.viewer.html.action.misc.SwapUser;
-import org.apache.isis.viewer.html.action.view.CollectionView;
-import org.apache.isis.viewer.html.action.view.FieldCollectionView;
-import org.apache.isis.viewer.html.action.view.ObjectView;
-import org.apache.isis.viewer.html.action.view.ServiceView;
-import org.apache.isis.viewer.html.component.Block;
-import org.apache.isis.viewer.html.component.Component;
-import org.apache.isis.viewer.html.component.ComponentFactory;
-import org.apache.isis.viewer.html.component.DebugPane;
-import org.apache.isis.viewer.html.component.Page;
-import org.apache.isis.viewer.html.context.Context;
-import org.apache.isis.viewer.html.context.ObjectLookupException;
-import org.apache.isis.viewer.html.crumb.Crumb;
-import org.apache.isis.viewer.html.image.ImageLookup;
-import org.apache.isis.viewer.html.monitoring.servermonitor.Monitor;
-import org.apache.isis.viewer.html.request.Request;
-import org.apache.isis.viewer.html.task.InvokeMethod;
-import org.apache.isis.viewer.html.task.TaskLookupException;
-import org.apache.isis.viewer.html.task.TaskStep;
-
-public class WebController {
-
- private static final Logger LOG = Logger.getLogger(WebController.class);
- private static final Logger ACCESS_LOG = Logger.getLogger("access_log");
-
- private static final String ERROR_REASON = "This error occurs when you go back to a page " + "using the browsers back button. To avoid this error in the future please avoid using the back button";
-
- protected class DebugView implements Action {
- public DebugView() {
- }
-
- @Override
- public void execute(final Request request, final Context context, final Page page) {
- page.setTitle("Debug");
-
- final DebugPane debugPane = context.getComponentFactory().createDebugPane();
- page.setDebug(debugPane);
-
- final DebugString debug = new DebugString();
-
- final AuthenticationSession authenticationSession = IsisContext.getAuthenticationSession();
- debug.appendTitle("Session");
- if (authenticationSession != null) {
- debug.appendln("user", authenticationSession.getUserName());
- debug.appendln("roles", authenticationSession.getRoles());
- } else {
- debug.appendln("none");
- }
-
- final UserProfile userProfile = IsisContext.getUserProfile();
- debug.appendTitle("User profile");
- if (userProfile != null) {
- UserProfilesDebugUtil.asDebuggableWithTitle(userProfile).debugData(debug);
- } else {
- debug.appendln("none");
- }
-
- debug.appendTitle("Actions");
- final Iterator e = actions.entrySet().iterator();
- debug.indent();
- while (e.hasNext()) {
- final Map.Entry element = (Map.Entry) e.next();
- debug.appendln(element.getKey() + " -> " + element.getValue());
- }
- debug.unindent();
-
- context.debug(debug);
-
- ImageLookup.debug(debug);
-
- debugPane.appendln("<pre>" + debug.toString() + "</pre>");
- }
-
- @Override
- public String name() {
- return "debug";
- }
- }
-
- protected class DebugSpecification implements Action {
- public DebugSpecification() {
- }
-
- @Override
- public void execute(final Request request, final Context context, final Page page) {
- final DebugPane debugPane = context.getComponentFactory().createDebugPane();
- page.setDebug(debugPane);
-
- debugPane.addSection("Specification");
- final ObjectAdapter object = context.getMappedObject(request.getObjectId());
- debugPane.appendln(Dump.specification(object));
- }
-
- @Override
- public String name() {
- return "spec";
- }
- }
-
- protected class DebugObject implements Action {
- public DebugObject() {
- }
-
- @Override
- public void execute(final Request request, final Context context, final Page page) {
- final DebugPane debugPane = context.getComponentFactory().createDebugPane();
- page.setDebug(debugPane);
-
- debugPane.addSection("Adapter");
- final ObjectAdapter object = context.getMappedObject(request.getObjectId());
- debugPane.appendln(Dump.adapter(object));
- debugPane.addSection("Graph");
- debugPane.appendln(Dump.graph(object, IsisContext.getAuthenticationSession()));
- }
-
- @Override
- public String name() {
- return "dump";
- }
- }
-
- protected class DebugOn implements Action {
- private final WebController controller;
-
- public DebugOn(final WebController controller) {
- this.controller = controller;
- }
-
- @Override
- public void execute(final Request request, final Context context, final Page page) {
- controller.setDebug(true);
- }
-
- @Override
- public String name() {
- return "debugon";
- }
- }
-
- protected class DebugOff implements Action {
- private final WebController controller;
-
- public DebugOff(final WebController controller) {
- this.controller = controller;
- }
-
- @Override
- public void execute(final Request request, final Context context, final Page page) {
- controller.setDebug(false);
- }
-
- @Override
- public String name() {
- return "debugoff";
- }
- }
-
- private final Map actions = new HashMap();
-
- private boolean isDebug;
- private final PathBuilder pathBuilder;
-
- public WebController(final PathBuilder pathBuilder) {
- this.pathBuilder = pathBuilder;
- }
-
- public boolean actionExists(final Request req) {
- return actions.containsKey(req.getRequestType());
- }
-
- protected void addAction(final Action action) {
- actions.put(action.name(), action);
- }
-
- private void addCrumbs(final Context context, final Page page) {
- final Crumb[] crumbs = context.getCrumbs();
- final String[] names = new String[crumbs.length];
- final boolean[] isLinked = context.isLinked();
-
- for (int i = 0; i < crumbs.length; i++) {
- names[i] = crumbs[i].title();
- }
-
- final ComponentFactory factory = context.getComponentFactory();
- final Component breadCrumbs = factory.createBreadCrumbs(names, isLinked);
-
- page.setCrumbs(breadCrumbs);
- }
-
- public void addDebug(final Page page, final Request req) {
- page.addDebug("<a href=\"" + pathTo("debug") + "\">Debug</a>");
- final String id = req.getObjectId();
- if (id != null) {
- page.addDebug("<a href=\"" + pathTo("dump") + "?id=" + id + "\">Object</a>");
- page.addDebug("<a href=\"" + pathTo("spec") + "?id=" + id + "\">Spec</a>");
- }
- page.addDebug("<a href=\"" + pathTo("about") + "\">About</a>");
- page.addDebug("<a href=\"" + pathTo("debugoff") + "\">Debug off</a>");
- }
-
- public Page generatePage(final Context context, final Request request) {
- context.restoreAllObjectsToLoader();
- final Page page = context.getComponentFactory().createPage();
- pageHeader(context, page);
- final Block navigation = page.getNavigation();
-
- final Block optionBar = context.getComponentFactory().createBlock("options", null);
- optionBar.add(context.getComponentFactory().createHeading("Options"));
-
- Block block = context.getComponentFactory().createBlock("item", null);
- Component option = context.getComponentFactory().createLink("logout", "Log Out", "End the current session");
- block.add(option);
- optionBar.add(block);
-
- block = context.getComponentFactory().createBlock("item", null);
- option = context.getComponentFactory().createLink("about", "About", "Details about this application");
- block.add(option);
- optionBar.add(block);
-
- // boolean isExploring = SessionAccess.inExplorationMode();
- final boolean isExploring = IsisContext.getDeploymentType().isExploring();
- if (isExploring) {
- block = context.getComponentFactory().createBlock("item", null);
- option = context.getComponentFactory().createLink("swapuser", "Swap User", "Swap the exploration user");
- block.add(option);
- optionBar.add(block);
- }
-
- navigation.add(optionBar);
-
- listServices(context, navigation);
- listHistory(context, navigation);
- Monitor.addEvent("Web", "Request " + request);
- runAction(context, request, page);
- addCrumbs(context, page);
-
- // The web viewer has no views of other objects, so changes can be
- // ignored
- if (IsisContext.inSession() && IsisContext.inTransaction()) {
- IsisContext.getUpdateNotifier().clear();
- }
- // TODO deal with disposed objects
-
- return page;
- }
-
- public void init() {
- addAction(new About());
- addAction(new SwapUser());
- addAction(new SetUser());
- addAction(new DebugView());
- addAction(new DebugSpecification());
- addAction(new DebugObject());
- addAction(new Welcome());
- addAction(new ObjectView());
- addAction(new CollectionView());
- addAction(new FieldCollectionView());
- addAction(new InvokeMethod());
- addAction(new TaskStep());
- addAction(new EditObject());
- addAction(new Save());
- addAction(new ServiceView());
- addAction(new LogOut());
- addAction(new RemoveItemFromCollection());
- addAction(new AddItemToCollection());
- addAction(new ChangeContext());
-
- // TODO allow these to be exclude by configuration so they cannot be run
- // in a real system
- addAction(new DebugOn(this));
- addAction(new DebugOff(this));
-
- Logger.getLogger(this.getClass()).info("init");
- }
-
- public boolean isDebug() {
- return isDebug;
- }
-
- private void listHistory(final Context context, final Block navigation) {
- context.listHistory(context, navigation);
- }
-
- private void listServices(final Context context, final Block navigationBar) {
- final Block taskBar = context.getComponentFactory().createBlock("services", null);
- taskBar.add(context.getComponentFactory().createHeading("Services"));
- final AdapterManager adapterManager = IsisContext.getPersistenceSession().getAdapterManager();
- final List<Object> services = getUserProfile().getPerspective().getServices();
- for (final Object service : services) {
- final ObjectAdapter serviceAdapter = adapterManager.adapterFor(service);
- if (serviceAdapter == null) {
- LOG.warn("unable to find service Id: " + service + "; skipping");
- continue;
- }
- if (isHidden(serviceAdapter)) {
- continue;
- }
- final String serviceMapId = context.mapObject(serviceAdapter);
- taskBar.add(createServiceComponent(context, serviceMapId, serviceAdapter));
- }
- navigationBar.add(taskBar);
- }
-
- private Component createServiceComponent(final Context context, final String serviceMapId, final ObjectAdapter serviceNO) {
- final String serviceName = serviceNO.titleString();
- final String serviceIcon = serviceNO.getIconName();
- return context.getComponentFactory().createService(serviceMapId, serviceName, serviceIcon);
- }
-
- private boolean isHidden(final ObjectAdapter serviceNO) {
- final ObjectSpecification serviceNoSpec = serviceNO.getSpecification();
- final boolean isHidden = serviceNoSpec.isHidden();
- return isHidden;
- }
-
- private void pageHeader(final Context context, final Page page) {
- page.getPageHeader().add(context.getComponentFactory().createInlineBlock("none", "", null));
- }
-
- private void runAction(final Context context, final Request request, final Page page) {
- try {
- ACCESS_LOG.info("request " + request.toString());
- Request r = request;
- final DebugString debug = new DebugString();
- debug.startSection("Request");
- debug.appendln("http", request.toString());
- debug.endSection();
- do {
- final Action action = (Action) actions.get(r.getRequestType());
- try {
- action.execute(r, context, page);
- } catch (final ObjectLookupException e) {
- final String error = "The object/service you selected has timed out. Please navigate to the object via the history bar.";
- displayError(context, page, error);
- } catch (final TaskLookupException e) {
- final String error = "The task you went back to has already been completed or cancelled. Please start the task again.";
- displayError(context, page, error);
- }
- r = r.getForward();
- if (r != null) {
- LOG.debug("forward to " + r);
- }
- } while (r != null);
- if (LOG.isDebugEnabled()) {
- context.debug(debug);
- debug.appendln();
- if (IsisContext.inSession()) {
- IsisContext.getSession(getExecutionContextId()).debugAll(debug);
- } else {
- debug.appendln("No session");
- }
- LOG.debug(debug.toString());
- }
- } catch (final ActionException e) {
- page.setTitle("Error");
- page.getViewPane().setTitle("Error", "Action Exception");
- LOG.error("ActionException, executing action " + request.getRequestType(), e);
- page.getViewPane().add(context.getComponentFactory().createErrorMessage(e, isDebug));
- } catch (final IsisApplicationException e) {
- page.setTitle("Error");
- page.getViewPane().setTitle("Error", "Application Exception");
- LOG.error("ApplicationException, executing action " + request.getRequestType(), e);
- page.getViewPane().add(context.getComponentFactory().createErrorMessage(e, isDebug));
- } catch (final IsisException e) {
- page.setTitle("Error");
- page.getViewPane().setTitle("Error", "System Exception");
- LOG.error("ObjectAdapterRuntimeException, executing action " + request.getRequestType(), e);
- page.getViewPane().add(context.getComponentFactory().createErrorMessage(e, true));
- } catch (final RuntimeException e) {
- page.setTitle("Error");
- page.getViewPane().setTitle("Error", "System Exception");
- LOG.error("RuntimeException, executing action " + request.getRequestType(), e);
- page.getViewPane().add(context.getComponentFactory().createErrorMessage(e, true));
- }
- }
-
- private void displayError(final Context context, final Page page, final String errorMessage) {
- page.setTitle("Error");
- page.getViewPane().setTitle("Error", "");
-
- final Block block1 = context.getComponentFactory().createBlock("error", "");
- block1.add(context.getComponentFactory().createInlineBlock("", errorMessage, ""));
- page.getViewPane().add(block1);
-
- final Block block2 = context.getComponentFactory().createBlock("text", "");
- block2.add(context.getComponentFactory().createInlineBlock("", ERROR_REASON, ""));
- page.getViewPane().add(block2);
- }
-
- public void setDebug(final boolean on) {
- this.isDebug = on;
- }
-
- protected String pathTo(final String prefix) {
- return pathBuilder.pathTo(prefix);
- }
-
- // ///////////////////////////////////////////////////////
- // Dependencies (from singleton)
- // ///////////////////////////////////////////////////////
-
- private UserProfile getUserProfile() {
- return IsisContext.getUserProfile();
- }
-
- private String getExecutionContextId() {
- return IsisContext.getSessionId();
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/91a8000b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/task/AddItemToCollectionTask.java
----------------------------------------------------------------------
diff --git a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/task/AddItemToCollectionTask.java b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/task/AddItemToCollectionTask.java
deleted file mode 100644
index babb1f9..0000000
--- a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/task/AddItemToCollectionTask.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * 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.viewer.html.task;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.consent.Consent;
-import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
-import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacetUtils;
-import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.runtime.system.persistence.Persistor;
-import org.apache.isis.viewer.html.component.Page;
-import org.apache.isis.viewer.html.context.Context;
-
-public class AddItemToCollectionTask extends Task {
- private final OneToManyAssociation field;
-
- public AddItemToCollectionTask(final Context context, final ObjectAdapter target, final OneToManyAssociation fld) {
- super(context, "Add to collection", "", target, 1);
- names[0] = fld.getName();
- descriptions[0] = fld.getDescription();
- fieldSpecifications[0] = fld.getSpecification();
- initialState[0] = null;
- optional[0] = true;
- // TODO add defaults and options
- this.field = fld;
- }
-
- @Override
- public void checkForValidity(final Context context) {
- final ObjectAdapter target = getTarget(context);
- final ObjectAdapter[] parameters = getEntries(context);
-
- final Consent valueValid = field.isValidToAdd(target, parameters[0]);
- errors[0] = valueValid.getReason();
- }
-
- @Override
- public void checkInstances(final Context context, final ObjectAdapter[] objects) {
- final ObjectAdapter collection = field.get(getTarget(context));
- final CollectionFacet facet = CollectionFacetUtils.getCollectionFacetFromSpec(collection);
- final ObjectAdapter target = getTarget(context);
- for (int i = 0; i < objects.length; i++) {
- final Consent valueValid = field.isValidToAdd(target, objects[i]);
- if (valueValid.isVetoed()) {
- objects[i] = null;
- } else if (facet.contains(collection, objects[i])) {
- objects[i] = null;
- }
- }
- }
-
- @Override
- public ObjectAdapter completeTask(final Context context, final Page page) {
- final ObjectAdapter targetAdapter = getTarget(context);
- final ObjectAdapter[] parameterAdapters = getEntries(context);
- field.addElement(targetAdapter, parameterAdapters[0]);
-
- if (targetAdapter.isTransient()) {
- getPersistenceSession().makePersistent(targetAdapter);
- }
- return targetAdapter;
- }
-
- @Override
- public boolean isEditing() {
- return true;
- }
-
- // /////////////////////////////////////////////////////
- // Dependencies (from context)
- // /////////////////////////////////////////////////////
-
- private static Persistor getPersistenceSession() {
- return IsisContext.getPersistenceSession();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/91a8000b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/task/EditTask.java
----------------------------------------------------------------------
diff --git a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/task/EditTask.java b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/task/EditTask.java
deleted file mode 100644
index 3a2649d..0000000
--- a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/task/EditTask.java
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * 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.viewer.html.task;
-
-import java.util.List;
-
-import org.apache.isis.applib.annotation.Where;
-import org.apache.isis.core.commons.authentication.AuthenticationSession;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.util.AdapterUtils;
-import org.apache.isis.core.metamodel.consent.Consent;
-import org.apache.isis.core.metamodel.facets.maxlen.MaxLengthFacet;
-import org.apache.isis.core.metamodel.facets.multiline.MultiLineFacet;
-import org.apache.isis.core.metamodel.facets.typicallen.TypicalLengthFacet;
-import org.apache.isis.core.metamodel.spec.ActionType;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociationFilters;
-import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
-import org.apache.isis.viewer.html.component.Page;
-import org.apache.isis.viewer.html.context.Context;
-
-public class EditTask extends Task {
-
- // REVIEW: should provide this rendering context, rather than hardcoding.
- // the net effect currently is that class members annotated with
- // @Hidden(where=Where.ANYWHERE) or @Disabled(where=Where.ANYWHERE) will indeed
- // be hidden/disabled, but will be visible/enabled (perhaps incorrectly)
- // for any other value for Where
- private final static Where where = Where.ANYWHERE;
-
- private static int size(final ObjectAdapter object) {
- final List<ObjectAssociation> fields = object.getSpecification().getAssociations(ObjectAssociationFilters.dynamicallyVisible(getAuthenticationSession(), object, where));
- return fields.size();
- }
-
- private static boolean skipField(final ObjectAdapter object, final ObjectAssociation fld) {
- return fld.isOneToManyAssociation() || fld.isUsable(getAuthenticationSession(), object, where).isVetoed();
- }
-
- private final ObjectAssociation[] fields;
- private final String newType;
-
- public EditTask(final Context context, final ObjectAdapter adapter) {
- super(context, "Edit", "", adapter, size(adapter));
-
- final List<ObjectAssociation> allFields = adapter.getSpecification().getAssociations(ObjectAssociationFilters.dynamicallyVisible(getAuthenticationSession(), adapter, where));
-
- fields = new ObjectAssociation[names.length];
- for (int i = 0, j = 0; j < allFields.size(); j++) {
- final ObjectAssociation fld = allFields.get(j);
- fields[i] = fld;
- names[i] = fld.getName();
- descriptions[i] = fld.getDescription();
-
- final Consent usableByUser = fld.isUsable(getAuthenticationSession(), adapter, where);
- if (usableByUser.isVetoed()) {
- descriptions[i] = usableByUser.getReason();
- }
-
- fieldSpecifications[i] = fld.getSpecification();
- initialState[i] = fld.get(adapter);
- if (skipField(adapter, fld)) {
- readOnly[i] = true;
- } else {
- readOnly[i] = false;
- optional[i] = !fld.isMandatory();
- if (fieldSpecifications[i].isParseable()) {
- final MultiLineFacet multilineFacet = fld.getFacet(MultiLineFacet.class);
- noLines[i] = multilineFacet.numberOfLines();
- wraps[i] = !multilineFacet.preventWrapping();
-
- final MaxLengthFacet maxLengthFacet = fld.getFacet(MaxLengthFacet.class);
- maxLength[i] = maxLengthFacet.value();
-
- final TypicalLengthFacet typicalLengthFacet = fld.getFacet(TypicalLengthFacet.class);
- typicalLength[i] = typicalLengthFacet.value();
- }
- }
- i++;
- }
-
- final boolean isTransient = adapter.isTransient();
- newType = isTransient ? getTarget(context).getSpecification().getSingularName() : null;
- }
-
- @Override
- protected ObjectAdapter[][] getOptions(final Context context, final int from, final int len) {
- final ObjectAdapter target = getTarget(context);
- final ObjectAdapter[][] options = new ObjectAdapter[len][];
- for (int i = from, j = 0; j < len; i++, j++) {
- if (skipField(target, fields[i])) {
- } else {
- options[j] = fields[i].getChoices(target);
- }
- }
- return options;
- }
-
- @Override
- public void checkForValidity(final Context context) {
- final ObjectAdapter target = getTarget(context);
- final ObjectAdapter[] entries = getEntries(context);
-
- final int len = fields.length;
- for (int i = 0; i < len; i++) {
- if (readOnly[i] || errors[i] != null) {
- continue;
- }
- final ObjectAssociation fld = fields[i];
- if (fld.isOneToOneAssociation()) {
- final OneToOneAssociation oneToOneAssociation = (OneToOneAssociation) fld;
- final ObjectAdapter entryReference = entries[i];
- final ObjectAdapter currentReference = oneToOneAssociation.get(target);
- if (currentReference != entryReference) {
- final Consent valueValid = ((OneToOneAssociation) fld).isAssociationValid(target, entryReference);
- errors[i] = valueValid.getReason();
- }
- }
- }
-
- if (target.isTransient()) {
- saveState(target, entries);
- final Consent isValid = target.getSpecification().isValid(target);
- error = isValid.isVetoed() ? isValid.getReason() : null;
- }
- }
-
- @Override
- public ObjectAdapter completeTask(final Context context, final Page page) {
- final ObjectAdapter targetAdapter = getTarget(context);
- final ObjectAdapter[] entryAdapters = getEntries(context);
-
- if (targetAdapter.isTransient()) {
- final ObjectAction action = targetAdapter.getSpecification().getObjectAction(ActionType.USER, "save", ObjectSpecification.EMPTY_LIST);
- if (action == null) {
- getPersistenceSession().makePersistent(targetAdapter);
- } else {
- action.execute(targetAdapter, new ObjectAdapter[0]);
- }
- } else {
- saveState(targetAdapter, entryAdapters);
- }
-
- return targetAdapter;
- }
-
- private void saveState(final ObjectAdapter targetAdapter, final ObjectAdapter[] entryAdapters) {
- getPersistenceSession().getTransactionManager().startTransaction();
- for (int i = 0; i < fields.length; i++) {
- final ObjectAssociation fld = fields[i];
- final ObjectAdapter entryAdapter = entryAdapters[i];
- final boolean isReadOnly = readOnly[i];
-
- if (isReadOnly) {
- continue;
- }
-
- if (fld.isOneToOneAssociation()) {
- final OneToOneAssociation oneToOneAssociation = ((OneToOneAssociation) fld);
- final Object entryPojo = AdapterUtils.unwrap(entryAdapter);
- if (entryPojo == null) {
- if (oneToOneAssociation.get(targetAdapter) != null) {
- oneToOneAssociation.clearAssociation(targetAdapter);
- }
- } else {
- final ObjectAdapter currentAdapter = oneToOneAssociation.get(targetAdapter);
- final Object currentPojo = AdapterUtils.unwrap(currentAdapter);
- if (currentAdapter == null || currentPojo == null || !currentPojo.equals(entryPojo)) {
- if (entryAdapter.isTransient()){
- getPersistenceSession().makePersistent(entryAdapter);
- }
- oneToOneAssociation.setAssociation(targetAdapter, entryAdapter);
- }
- }
- }
- }
- getPersistenceSession().getTransactionManager().endTransaction();
- }
-
- @Override
- protected boolean simpleField(final ObjectSpecification type, final int i) {
- return !fields[i].hasChoices() || super.simpleField(type, i);
- }
-
- @Override
- public boolean isEditing() {
- return true;
- }
-
- @Override
- public String getName() {
- if (newType == null) {
- return super.getName();
- }
- return "New " + newType;
- }
-
- // /////////////////////////////////////////////////////
- // Dependencies (from context)
- // /////////////////////////////////////////////////////
-
- private static PersistenceSession getPersistenceSession() {
- return IsisContext.getPersistenceSession();
- }
-
- private static AuthenticationSession getAuthenticationSession() {
- return IsisContext.getAuthenticationSession();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/91a8000b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/task/InvokeMethod.java
----------------------------------------------------------------------
diff --git a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/task/InvokeMethod.java b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/task/InvokeMethod.java
deleted file mode 100644
index 684b2ef..0000000
--- a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/task/InvokeMethod.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * 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.viewer.html.task;
-
-import java.util.List;
-
-import org.apache.isis.core.commons.exceptions.UnknownTypeException;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
-import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacetUtils;
-import org.apache.isis.core.metamodel.spec.Persistability;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.runtime.system.transaction.MessageBroker;
-import org.apache.isis.viewer.html.action.Action;
-import org.apache.isis.viewer.html.action.ActionException;
-import org.apache.isis.viewer.html.component.Page;
-import org.apache.isis.viewer.html.context.Context;
-import org.apache.isis.viewer.html.request.ForwardRequest;
-import org.apache.isis.viewer.html.request.Request;
-
-public final class InvokeMethod implements Action {
-
- @Override
- public void execute(final Request request, final Context context, final Page page) {
- final String idString = request.getObjectId();
- if (idString == null) {
- throw new ActionException("Task no longer in progress");
- }
- final ObjectAdapter target = context.getMappedObject(idString);
- final String id = request.getActionId();
- final ObjectAction action = context.getMappedAction(id);
- if (action == null) {
- throw new ActionException("No such action: " + id);
- }
-
- boolean executeImmediately = false;
- // TODO use new promptForParameters method instead of all this
- final boolean isContributedMethod = action.isContributed();
- if (action.getParameterCount() == 0) {
- executeImmediately = true;
- } else if (action.getParameterCount() == 1 && isContributedMethod && target.getSpecification().isOfType(action.getParameters().get(0).getSpecification())) {
- executeImmediately = true;
- }
-
- if (executeImmediately) {
- final ObjectAdapter[] parameters = isContributedMethod ? new ObjectAdapter[] { target } : null;
- final ObjectAdapter result = action.execute(target, parameters);
- final MessageBroker broker = IsisContext.getMessageBroker();
- final List<String> messages = broker.getMessages();
- final List<String> warnings = broker.getWarnings();
- context.setMessagesAndWarnings(messages, warnings);
- context.processChanges();
- final String targetId = context.mapObject(target);
- displayMethodResult(request, context, page, result, targetId);
- } else {
- final MethodTask methodTask = new MethodTask(context, target, action);
- context.addTaskCrumb(methodTask);
- request.forward(ForwardRequest.task(methodTask));
- }
- }
-
- static void displayMethodResult(final Request request, final Context context, final Page page, final ObjectAdapter result, final String targetId) {
- if (result == null) {
- // TODO ask context for page to display - this will be the most
- // recent object prior to the task
- // null object - so just view service
- request.forward(ForwardRequest.viewService(targetId));
- } else {
- if (result.getSpecification().isParentedOrFreeCollection()) {
- final CollectionFacet facet = CollectionFacetUtils.getCollectionFacetFromSpec(result);
- if (facet.size(result) == 1) {
- forwardObjectResult(request, context, facet.firstElement(result));
- } else {
- forwardCollectionResult(request, context, result);
- }
- } else if (result.getSpecification().isValueOrIsParented()) {
- // TODO deal with this object properly, it might not be just a
- // simple string
- final List<String> messages = context.getMessages();
- messages.add(0, "Action returned: " + result.titleString());
- request.forward(ForwardRequest.viewObject(targetId));
- } else if (result.getSpecification().isNotCollection()) {
- forwardObjectResult(request, context, result);
- } else {
- throw new UnknownTypeException(result.getSpecification().getFullIdentifier());
- }
- }
- }
-
- static void forwardCollectionResult(final Request request, final Context context, final ObjectAdapter coll) {
- final String collectionId = context.mapCollection(coll);
- request.forward(ForwardRequest.listCollection(collectionId));
- }
-
- static void forwardObjectResult(final Request request, final Context context, final ObjectAdapter resultAdapter) {
- final String objectId = context.mapObject(resultAdapter);
- if (resultAdapter.isTransient() && resultAdapter.getSpecification().persistability() == Persistability.USER_PERSISTABLE) {
- request.forward(ForwardRequest.editObject(objectId));
- } else if (resultAdapter.getSpecification().isService()) {
- request.forward(ForwardRequest.viewService(objectId));
- } else {
- request.forward(ForwardRequest.viewObject(objectId));
- }
- }
-
- @Override
- public String name() {
- return "method";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/91a8000b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/task/MethodTask.java
----------------------------------------------------------------------
diff --git a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/task/MethodTask.java b/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/task/MethodTask.java
deleted file mode 100644
index d0e1343..0000000
--- a/component/viewer/html/impl/src/main/java/org/apache/isis/viewer/html/task/MethodTask.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * 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.viewer.html.task;
-
-import java.util.List;
-
-import org.apache.isis.core.commons.debug.DebugBuilder;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.consent.Consent;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
-import org.apache.isis.core.metamodel.spec.feature.ObjectActionParameter;
-import org.apache.isis.core.metamodel.spec.feature.ParseableEntryActionParameter;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.runtime.system.transaction.MessageBroker;
-import org.apache.isis.viewer.html.component.Page;
-import org.apache.isis.viewer.html.context.Context;
-
-public final class MethodTask extends Task {
- private final ObjectAction action;
-
- protected MethodTask(final Context context, final ObjectAdapter target, final ObjectAction action) {
- super(context, action.getName(), action.getDescription(), target, action.getParameterCount());
- this.action = action;
-
- final List<ObjectActionParameter> parameters = action.getParameters();
- final int len = parameters.size();
-
- for (int i = 0; i < len; i++) {
- names[i] = parameters.get(i).getName();
- descriptions[i] = parameters.get(i).getDescription();
- fieldSpecifications[i] = parameters.get(i).getSpecification();
- optional[i] = parameters.get(i).isOptional();
-
- if (parameters.get(i).getSpecification().isParseable()) {
- final ParseableEntryActionParameter valueParameter = (ParseableEntryActionParameter) parameters.get(i);
- noLines[i] = valueParameter.getNoLines();
- wraps[i] = valueParameter.canWrap();
- maxLength[i] = valueParameter.getMaximumLength();
- typicalLength[i] = valueParameter.getTypicalLineLength();
- }
-
- }
-
- // String[] names = action.getParameterNames();
- // String[] descriptions = action.getParameterDescriptions();
- // ObjectSpecification[] types = action.getParameterTypes();
- final ObjectAdapter[] defaultParameterValues = action.getDefaults(target);
- // boolean[] optional = action.getOptionalParameters();
- for (int i = 0; i < names.length; i++) {
- // this.names[i] = names[i];
- // this.descriptions[i] = descriptions[i];
- // this.fieldSpecifications[i] = types[i];
- // this.optional[i] = optional[i];
-
- if (defaultParameterValues[i] == null) {
-
- // TODO: review; this isn't sufficient, because could provide an invalid value for a reference type, I think?
- if (action.isContributed() && parameters.get(i).isObject()) {
- initialState[i] = target;
- } else {
- initialState[i] = null;
- }
- } else {
- initialState[i] = defaultParameterValues[i];
- }
- /*
- * noLines[i] = action.getParameterNoLines()[i]; wraps[i] =
- * action.canParametersWrap()[i]; maxLength[i] =
- * action.getParameterMaxLengths()[i]; typicalLength[i] =
- * action.getParameterTypicalLengths()[i];
- */
- }
-
- }
-
- @Override
- public void checkForValidity(final Context context) {
- final ObjectAdapter[] parameters = getEntries(context);
- final ObjectAdapter target = getTarget(context);
- final Consent consent = action.isProposedArgumentSetValid(target, parameters);
- error = consent.getReason();
- }
-
- @Override
- public ObjectAdapter completeTask(final Context context, final Page page) {
- final ObjectAdapter[] parameters = getEntries(context);
- final ObjectAdapter target = getTarget(context);
- final ObjectAdapter result = action.execute(target, parameters);
- final MessageBroker broker = IsisContext.getMessageBroker();
- final List<String> messages = broker.getMessages();
- final List<String> warnings = broker.getWarnings();
- context.setMessagesAndWarnings(messages, warnings);
- return result;
- }
-
- @Override
- public void debug(final DebugBuilder debug) {
- debug.appendln("action: " + action);
- super.debug(debug);
- }
-
- @Override
- protected ObjectAdapter[][] getOptions(final Context context, final int from, final int len) {
- final ObjectAdapter[][] allOptions = action.getChoices(getTarget(context));
- final ObjectAdapter[][] options = new ObjectAdapter[len][];
- for (int i = from, j = 0; j < len; i++, j++) {
- options[j] = allOptions[i];
- }
- return options;
- }
-
- public boolean collectParameters() {
- // TODO use new promptForParameters method instead of all this
-
- final int expectedNoParameters = action.isContributed() ? 1 : 0;
- return action.getParameterCount() == expectedNoParameters;
- }
-}