Search in sources :

Example 6 with Component

use of org.jaffa.presentation.portlet.component.Component in project jaffa-framework by jaffa-projects.

the class HistoryNav method addFormKeyToHistoryNav.

/**
 * This will add the input FormKey to the historyNav.
 * If the historyNav didn't exist, then one will be initialized.
 * If the input FormKey already existed on the historyNav, then all subsequent FormKeys will be removed from the list.
 * Also, all the subsequent components will be closed.
 * @param request The request stream.
 * @param fk The FormKey to add.
 */
public static void addFormKeyToHistoryNav(HttpServletRequest request, FormKey fk) {
    List historyNavList = obtainHistoryNav(request);
    if (historyNavList == null) {
        historyNavList = initializeHistoryNav(request);
        historyNavList.add(fk);
    } else if (!historyNavList.contains(fk)) {
        historyNavList.add(fk);
    } else {
        // close all the subsequent components, provided they are different from the current component
        int indexOfFk = historyNavList.indexOf(fk);
        for (int i = indexOfFk + 1; i < historyNavList.size(); i++) {
            FormKey subsequentFk = (FormKey) historyNavList.get(i);
            String subsequentComponentId = subsequentFk.getComponentId();
            if (subsequentComponentId != null && !subsequentComponentId.equals(fk.getComponentId())) {
                Component subsequentComponent = UserSession.getUserSession(request).getComponent(subsequentComponentId);
                if (subsequentComponent != null && subsequentComponent.isActive())
                    subsequentComponent.quit();
            }
        }
        // remove all subsequent FormKeys
        if (indexOfFk + 1 < historyNavList.size())
            historyNavList.subList(indexOfFk + 1, historyNavList.size()).clear();
    }
    // In such a scenario we need to check the list for dead components
    for (Iterator i = historyNavList.iterator(); i.hasNext(); ) {
        FormKey aFormKey = (FormKey) i.next();
        String compId = aFormKey.getComponentId();
        if (compId != null) {
            Component comp = UserSession.getUserSession(request).getComponent(compId);
            if (comp == null || !comp.isActive())
                i.remove();
        }
    }
    // Add the historyNav to the request stream
    request.setAttribute(HistoryNav.HISTORY_NAV_PARAMETER, historyNavList);
}
Also used : Component(org.jaffa.presentation.portlet.component.Component)

Example 7 with Component

use of org.jaffa.presentation.portlet.component.Component in project jaffa-framework by jaffa-projects.

the class StartComponentAction method defaultAction.

/**
 * Invokes the component passed in the request stream.
 *
 * @return A FormKey instance which describes the current Component & Form
 * @throws Exception if the application business logic throws an exception
 */
public FormKey defaultAction() throws Exception {
    // Get the component & finalUrl parameter-values from the request-stream
    String initialComponent = request.getParameter(COMPONENT_PARAMETER);
    String finalUrl = request.getParameter(FINALURL_PARAMETER);
    if (log.isDebugEnabled())
        log.debug("Received the Initial Parameters - component=" + initialComponent + ", finalUrl=" + finalUrl);
    // set the default value for initialComponent
    if (initialComponent == null) {
        if (finalUrl != null) {
            // the form key escapes the input for XSS prevention
            return new FormKey(finalUrl, null);
        } else {
            String str = "The parameter " + COMPONENT_PARAMETER + " should be passed";
            log.error(str);
            throw new IllegalArgumentException(str);
        }
    }
    /**
     ********************************************************
     * Create Component To Run
     * *********************************************************
     */
    if (log.isDebugEnabled())
        log.debug("Calling the ComponentManager to run " + initialComponent);
    Component comp = null;
    try {
        comp = ComponentManager.run(initialComponent, UserSession.getUserSession(request));
    } catch (AccessControlException e) {
        // No access to component, direct to an error page
        request.setAttribute("componentName", initialComponent);
        return new FormKey(NO_ACCESS_FORWARD, null);
    }
    // Initialize the HistoryNav by setting an appropriate attribute in the request stream
    // Need to do this before setting "returnToFormKey" otherwise it will assume "close_browser"
    HistoryNav.initializeHistoryNav(request, finalUrl);
    // Set the ReturnToFromKey property of the component
    if (finalUrl != null) {
        comp.setReturnToFormKey(new FormKey(finalUrl, null));
    }
    // Set the parameters on the component using reflection
    comp.reflectAndSetParms(request);
    FormKey fk;
    try {
        // get the formKey for the component
        fk = comp.display();
    } catch (ApplicationExceptions e) {
        String str = "Error in invoking the display method of the Component " + comp.getClass().getName();
        if (log.isDebugEnabled())
            log.debug(str);
        throw e;
    } catch (Exception e) {
        String str = "Error in invoking the display method of the Component " + comp.getClass().getName();
        log.error(str, e);
        throw e;
    }
    return fk;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) AccessControlException(java.security.AccessControlException) Component(org.jaffa.presentation.portlet.component.Component) AccessControlException(java.security.AccessControlException)

Example 8 with Component

use of org.jaffa.presentation.portlet.component.Component in project jaffa-framework by jaffa-projects.

the class UserSession method garbageCollectIdleComponents.

/**
 * This will perform garbage collection of idle components. Idle components are those components which have had no activity performed in the last 'timeOutMinutes' minutes.
 * @param timeOutMinutes The minutes used to determine idle components.
 */
public void garbageCollectIdleComponents(int timeOutMinutes) {
    List excludeComponents = null;
    String[] ec = StringHelper.parseString((String) ContextManagerFactory.instance().getProperty(RULE_GC_EXCLUDES), ",");
    if (ec == null || ec.length == 0)
        excludeComponents = new ArrayList();
    else
        excludeComponents = Arrays.asList(ec);
    // create an array of Component objects
    Component[] components = new Component[m_components.size()];
    Iterator itr = m_components.values().iterator();
    for (int i = 0; itr.hasNext(); i++) components[i] = (Component) itr.next();
    for (int i = 0; i < components.length; i++) {
        Component component = components[i];
        if (component.isActive() && !excludeComponents.contains(component.getComponentDefinition().getComponentName())) {
            // Collection of componentIds. This will avoid circular references
            Collection checkedComponentIdsList = new ArrayList();
            if (hasComponentTimedOut(component, DateTime.addMinute(new DateTime(), -timeOutMinutes), checkedComponentIdsList)) {
                if (log.isInfoEnabled())
                    log.info("Garbage collecting component " + component.getComponentDefinition().getComponentName() + " having id " + component.getComponentId());
                component.quit();
            }
        }
    }
}
Also used : Component(org.jaffa.presentation.portlet.component.Component) DateTime(org.jaffa.datatypes.DateTime)

Example 9 with Component

use of org.jaffa.presentation.portlet.component.Component in project jaffa-framework by jaffa-projects.

the class UserSession method hasComponentTimedOut.

private boolean hasComponentTimedOut(Component component, DateTime time, Collection checkedComponentIdsList) {
    boolean timedOut;
    if (!component.isActive()) {
        // assume Inactive component = TimedOut component
        timedOut = true;
    } else {
        timedOut = component.returnLastActivityDate().isBefore(time);
        if (timedOut && !checkedComponentIdsList.contains(component.getComponentId())) {
            checkedComponentIdsList.add(component.getComponentId());
            Collection childComponents = component.returnChildComponents();
            if (childComponents != null) {
                for (Iterator i = childComponents.iterator(); i.hasNext(); ) {
                    Component childComponent = (Component) i.next();
                    timedOut = hasComponentTimedOut(childComponent, time, checkedComponentIdsList);
                    if (!timedOut)
                        break;
                }
            }
        }
    }
    return timedOut;
}
Also used : Component(org.jaffa.presentation.portlet.component.Component)

Example 10 with Component

use of org.jaffa.presentation.portlet.component.Component in project jaffa-framework by jaffa-projects.

the class FormSelectionMaintenanceComponent method validateFields.

protected void validateFields(GridModelRow row, ApplicationExceptions appExps, boolean showForm) throws ApplicationExceptions, FrameworkException {
    String additionalComponent = null;
    CheckBoxModel checkBoxModel = (CheckBoxModel) row.get("select");
    if ((checkBoxModel != null && checkBoxModel.getState()) || showForm) {
        // Check copies are greater then zero
        EditBoxModel mCopies = (EditBoxModel) row.get("copies");
        if (mCopies != null && !showForm) {
            if (mCopies.getValue() != null && mCopies.getValue().length() > 0) {
                int iCopies = Integer.parseInt(mCopies.getValue());
                if (iCopies < 1) {
                    appExps.add(new FormSelectionException(FormSelectionException.INVALID_COPIES));
                }
            } else {
                appExps.add(new FormSelectionException(FormSelectionException.INVALID_COPIES));
            }
        }
        if (!showForm) {
            // check either printer, email or publish has value
            EditBoxModel mPrinter = (EditBoxModel) row.get("printer");
            EditBoxModel mEmail = (EditBoxModel) row.get("email");
            CheckBoxModel mPublish = (CheckBoxModel) row.get("publish");
            if ((mPrinter.getValue() == null) && (mEmail.getValue() == null) && (mPublish.getState() != true) && !showForm) {
                appExps.add(new FormSelectionException(FormSelectionException.INVALID_OUTPUT_DESTINATION));
            }
        }
        // Validate AdditionalData exist or not
        try {
            FormSelectionMaintenanceOutRowDto rowDto = (FormSelectionMaintenanceOutRowDto) row.get("object");
            additionalComponent = rowDto.getAdditionalDataComponent();
            if (additionalComponent != null) {
                Component comp = (Component) run(additionalComponent);
                BeanUtils.setProperty(comp, getKey1(), getValue1());
                if (getKey2() != null) {
                    BeanUtils.setProperty(comp, getKey2(), getValue2());
                }
                if (getKey3() != null) {
                    BeanUtils.setProperty(comp, getKey3(), getValue3());
                }
                if (getKey4() != null) {
                    BeanUtils.setProperty(comp, getKey4(), getValue4());
                }
                if (getKey5() != null) {
                    BeanUtils.setProperty(comp, getKey5(), getValue5());
                }
                if (getKey6() != null) {
                    BeanUtils.setProperty(comp, getKey6(), getValue6());
                }
                if (comp instanceof IAdditionalData) {
                    ((IAdditionalData) comp).validate();
                } else {
                    if (log.isDebugEnabled()) {
                        log.debug("Additional Data Interface not implemented ");
                    }
                }
            }
        } catch (SecurityException se) {
            log.error("SecurityException Occurred ", se);
            appExps.add(new FormSelectionException(FormSelectionException.SECURITY_EXCEPTION));
        } catch (IllegalAccessException e) {
            log.error("IllegalAccessException Occurred ", e);
        } catch (InvocationTargetException e) {
            log.error("InvocationTargetException Occurred ", e);
        } catch (IllegalArgumentException e) {
            log.error("IllegalArgumentException Occurred ", e);
        } catch (ApplicationExceptions applicationException) {
            log.debug("Catch : Application Exception from additional data component");
            if (applicationException != null && applicationException.size() > 0) {
                for (Iterator i = applicationException.iterator(); i.hasNext(); ) {
                    ApplicationException appEx = (ApplicationException) i.next();
                    appExps.add(appEx);
                }
            }
        } catch (FrameworkException frameworkException) {
            throw frameworkException;
        }
    }
}
Also used : FormSelectionException(org.jaffa.modules.printing.components.formselectionmaintenance.FormSelectionException) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) FrameworkException(org.jaffa.exceptions.FrameworkException) org.jaffa.components.maint(org.jaffa.components.maint) InvocationTargetException(java.lang.reflect.InvocationTargetException) CheckBoxModel(org.jaffa.presentation.portlet.widgets.model.CheckBoxModel) ApplicationException(org.jaffa.exceptions.ApplicationException) FormSelectionMaintenanceOutRowDto(org.jaffa.modules.printing.components.formselectionmaintenance.dto.FormSelectionMaintenanceOutRowDto) EditBoxModel(org.jaffa.presentation.portlet.widgets.model.EditBoxModel) Iterator(java.util.Iterator) IAdditionalData(org.jaffa.modules.printing.components.formselectionmaintenance.IAdditionalData) Component(org.jaffa.presentation.portlet.component.Component) RiaWrapperComponent(org.jaffa.presentation.portlet.component.RiaWrapperComponent)

Aggregations

Component (org.jaffa.presentation.portlet.component.Component)10 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ApplicationException (org.jaffa.exceptions.ApplicationException)2 FrameworkException (org.jaffa.exceptions.FrameworkException)2 FormSelectionException (org.jaffa.modules.printing.components.formselectionmaintenance.FormSelectionException)2 FormSelectionMaintenanceOutRowDto (org.jaffa.modules.printing.components.formselectionmaintenance.dto.FormSelectionMaintenanceOutRowDto)2 FormKey (org.jaffa.presentation.portlet.FormKey)2 RiaWrapperComponent (org.jaffa.presentation.portlet.component.RiaWrapperComponent)2 AccessControlException (java.security.AccessControlException)1 Iterator (java.util.Iterator)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 org.jaffa.components.maint (org.jaffa.components.maint)1 DateTime (org.jaffa.datatypes.DateTime)1 MandatoryFieldException (org.jaffa.datatypes.exceptions.MandatoryFieldException)1 IAdditionalData (org.jaffa.modules.printing.components.formselectionmaintenance.IAdditionalData)1 IAdditionalDataObject (org.jaffa.modules.printing.components.formselectionmaintenance.IAdditionalDataObject)1 UserSession (org.jaffa.presentation.portlet.session.UserSession)1 CheckBoxModel (org.jaffa.presentation.portlet.widgets.model.CheckBoxModel)1 EditBoxModel (org.jaffa.presentation.portlet.widgets.model.EditBoxModel)1