All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.flowcentraltech.flowcentral.studio.web.writers.StudioMenuWriter Maven / Gradle / Ivy

There is a newer version: 3.0.2
Show newest version
/*
 * Copyright 2021-2024 FlowCentral Technologies Limited.
 * 
 * Licensed 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 com.flowcentraltech.flowcentral.studio.web.writers;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import com.flowcentraltech.flowcentral.application.business.AppletUtilities;
import com.flowcentraltech.flowcentral.application.data.AppletDef;
import com.flowcentraltech.flowcentral.application.util.ApplicationNameUtils;
import com.flowcentraltech.flowcentral.application.web.widgets.AbstractMenuWidget;
import com.flowcentraltech.flowcentral.common.business.CodeGenerationProvider;
import com.flowcentraltech.flowcentral.studio.business.StudioModuleService;
import com.flowcentraltech.flowcentral.studio.constants.StudioAppComponentType;
import com.flowcentraltech.flowcentral.studio.constants.StudioSessionAttributeConstants;
import com.flowcentraltech.flowcentral.studio.web.widgets.StudioMenuWidget;
import com.tcdng.unify.core.UnifyException;
import com.tcdng.unify.core.annotation.Component;
import com.tcdng.unify.core.annotation.Configurable;
import com.tcdng.unify.core.annotation.Writes;
import com.tcdng.unify.core.util.StringUtils;
import com.tcdng.unify.core.util.json.JsonWriter;
import com.tcdng.unify.web.ui.widget.EventHandler;
import com.tcdng.unify.web.ui.widget.ResponseWriter;
import com.tcdng.unify.web.ui.widget.Widget;
import com.tcdng.unify.web.ui.widget.WriteWork;
import com.tcdng.unify.web.ui.widget.writer.AbstractPanelWriter;

/**
 * Studio menu writer.
 * 
 * @author FlowCentral Technologies Limited
 * @since 1.0
 */
@Writes(StudioMenuWidget.class)
@Component("fc-studiomenu-writer")
public class StudioMenuWriter extends AbstractPanelWriter {

    private static final String ORIGINAL_MENU_PATHID = "originalStudio.menu.pathID";

    @Configurable
    private StudioModuleService studioModuleService;

    @Configurable
    private AppletUtilities appletUtilities;

    @Configurable
    private CodeGenerationProvider codeGenerationProvider;

    private static final List applicationAppletList = Collections.unmodifiableList(
            Arrays.asList("studio.stuManageModule", "studio.manageApplication", "studio.applicationReplication"));

    private static final List synchronizationAppletList = Collections
            .unmodifiableList(Arrays.asList("studio.delegateCreateSynchronization", "studio.delegateSynchronization"));

    private static final List snapshotAppletList = Collections
            .unmodifiableList(Arrays.asList("codegeneration.manageSnapshotSettings", "studio.takeSnapshot",
                    "studio.uploadSnapshot", "studio.snapshots"));

    private static final List utilMenuCategoryList = Collections.unmodifiableList(Arrays.asList(
            StudioAppComponentType.CODEGENERATION, StudioAppComponentType.SYNCHRONIZATION,
            StudioAppComponentType.SNAPSHOT, StudioAppComponentType.APPLICATION));

    private static final List collabUtilMenuCategoryList = Collections
            .unmodifiableList(Arrays.asList(StudioAppComponentType.COLLABORATION, StudioAppComponentType.CODEGENERATION,
                    StudioAppComponentType.SYNCHRONIZATION, StudioAppComponentType.SNAPSHOT,
                    StudioAppComponentType.APPLICATION));

    private static final List menuCategoryList = Collections.unmodifiableList(Arrays.asList(
            StudioAppComponentType.ENTITY, StudioAppComponentType.REFERENCE, StudioAppComponentType.ENUMERATION,
            StudioAppComponentType.WIDGET, StudioAppComponentType.APPLET, StudioAppComponentType.TABLE,
            StudioAppComponentType.FORM, StudioAppComponentType.REPORT_CONFIGURATION,
            StudioAppComponentType.NOTIFICATION_TEMPLATE, StudioAppComponentType.NOTIFICATION_LARGETEXT,
            StudioAppComponentType.WORKFLOW, StudioAppComponentType.CHART_DATASOURCE, StudioAppComponentType.CHART,
            StudioAppComponentType.DASHBOARD, StudioAppComponentType.HELP_SHEET));

    @Override
    protected void doWriteStructureAndContent(ResponseWriter writer, Widget widget) throws UnifyException {
        final StudioMenuWidget studioMenuWidget = (StudioMenuWidget) widget;
        final boolean searchable = studioMenuWidget.isSearchable();

        final String applicationName = (String) getSessionAttribute(
                StudioSessionAttributeConstants.CURRENT_APPLICATION_NAME);
        final boolean application = !StringUtils.isBlank(applicationName);

        writer.write("
"); writer.write(""); writer.writeWithHtmlEscape(application ? getSessionMessage("studio.menu.application.components") : getSessionMessage("studio.menu.application.utilities")); writer.write("
"); if (searchable) { // Search writer.write("
"); writer.write(resolveSymbolHtmlHexCode("filter")); writer.write(""); writer.writeStructureAndContent(studioMenuWidget.getSearchCtrl()); writer.write(""); writer.write(resolveSymbolHtmlHexCode("ban")); writer.write(""); writer.write("
"); } final boolean isCollaborationEnabled = appletUtilities.collaborationProvider() != null; final List selMenuCategoryList = application ? menuCategoryList : (isCollaborationEnabled ? collabUtilMenuCategoryList : utilMenuCategoryList); StudioAppComponentType currCategory = studioMenuWidget.getCurrentSel(); if (currCategory == null) { currCategory = getSessionAttribute(StudioAppComponentType.class, StudioSessionAttributeConstants.CURRENT_MENU_CATEGORY); } if (currCategory == null || (application && !currCategory.isComponentType()) || (!application && currCategory.isComponentType())) { currCategory = application ? StudioAppComponentType.ENTITY : (isCollaborationEnabled ? StudioAppComponentType.COLLABORATION : (codeGenerationProvider != null ? StudioAppComponentType.CODEGENERATION : StudioAppComponentType.APPLICATION)); } studioMenuWidget.setCurrentSel(currCategory); writer.write("
"); // Category writer.write("
"); JsonWriter cjw = new JsonWriter(); cjw.beginArray(); final String categoryId = studioMenuWidget.getCategoryId(); final int catLen = selMenuCategoryList.size(); for (int i = 0; i < catLen; i++) { final StudioAppComponentType category = selMenuCategoryList.get(i); writer.write("
"); writer.write("").write(resolveSymbolHtmlHexCode(category.icon())).write(""); writer.write("").writeWithHtmlEscape(resolveSessionMessage(category.caption2())) .write(""); writer.write("
"); } cjw.endArray(); writer.write("
"); // Menu items writer.write("
"); writer.write("
"); if (application) { writer.write("
"); writer.writeWithHtmlEscape(resolveSessionMessage(currCategory.caption2())); writer.write("
"); } // Body writer.write("
"); writer.write(""); doWriteSectionStructureAndContent(writer, studioMenuWidget, menuSectionId); writer.write("
"); writer.write("
"); // End body writer.write("
"); writer.write("
"); writer.write("
"); WriteWork work = studioMenuWidget.getWriteWork(); work.set(StudioMenuWidget.WORK_MENU_CATEGORIES, cjw); writer.writeStructureAndContent(studioMenuWidget.getCurrentSelCtrl()); writer.write(""); } @Override protected void doWriteSectionStructureAndContent(ResponseWriter writer, Widget widget, String sectionId) throws UnifyException { final StudioMenuWidget studioMenuWidget = (StudioMenuWidget) widget; if (studioMenuWidget.getMenuSectionId().equals(sectionId)) { final String applicationName = (String) getSessionAttribute( StudioSessionAttributeConstants.CURRENT_APPLICATION_NAME); writer.write(""); WriteWork work = studioMenuWidget.getWriteWork(); work.set(StudioMenuWidget.WORK_MENUITEMS, mjw); } } @Override protected void doWriteBehavior(ResponseWriter writer, Widget widget, EventHandler[] handlers) throws UnifyException { StudioMenuWidget studioMenuWidget = (StudioMenuWidget) widget; WriteWork work = studioMenuWidget.getWriteWork(); writer.beginFunction("fuxstudio.rigStudioMenu"); writer.writeParam("pId", studioMenuWidget.getId()); writer.writeParam("pContId", studioMenuWidget.getContainerId()); writer.writeParam("pCategoryId", studioMenuWidget.getCategoryId()); final boolean searchable = studioMenuWidget.isSearchable(); if (searchable) { writer.writeParam("pSearch", true); writer.writeParam("pInpId", studioMenuWidget.getSearchCtrl().getId()); writer.writeParam("pClrId", studioMenuWidget.getClearId()); } // Resolves out of bean context error which usually happens on menu reload String originalPathId = (String) getSessionAttribute(ORIGINAL_MENU_PATHID); if (!StringUtils.isBlank(originalPathId)) { writer.writeCommandURLParam("pCmdURL", originalPathId); } else { originalPathId = getRequestContextUtil().getResponsePathParts().getControllerPathId(); setSessionAttribute(ORIGINAL_MENU_PATHID, originalPathId); writer.writeCommandURLParam("pCmdURL"); } writer.writeParam("pCurrSelCtrlId", studioMenuWidget.getCurrentSelCtrl().getId()); writer.writeParam("pMenuCat", (JsonWriter) work.get(StudioMenuWidget.WORK_MENU_CATEGORIES)); writer.writeParam("pMenuItems", (JsonWriter) work.get(StudioMenuWidget.WORK_MENUITEMS)); writer.endFunction(); getRequestContextUtil().setDefaultFocusOnWidgetId(studioMenuWidget.getSearchCtrl().getId()); } @Override protected void doWriteSectionBehavior(ResponseWriter writer, Widget widget, String sectionId) throws UnifyException { StudioMenuWidget studioMenuWidget = (StudioMenuWidget) widget; if (studioMenuWidget.getMenuSectionId().equals(sectionId)) { WriteWork work = studioMenuWidget.getWriteWork(); writer.beginFunction("fux.rigMenuSectionResult"); writer.writeParam("pId", studioMenuWidget.getId()); writer.writeParam("pContId", studioMenuWidget.getContainerId()); writer.writeCommandURLParam("pCmdURL"); writer.writeParam("pCollInit", studioMenuWidget.isCollapsedInitial()); writer.writeResolvedParam("pMenuItems", ((JsonWriter) work.get(AbstractMenuWidget.WORK_MENUITEMS)).toString()); writer.endFunction(); } } private List getApplicationAppletDefs(String applicationName, String filter) throws UnifyException { return getRoleAppletDefs(applicationName, applicationAppletList, filter); } private List getCollaborationAppletDefs(String applicationName, String filter) throws UnifyException { return getRoleAppletDefs(applicationName, appletUtilities.collaborationProvider().getCollaborationApplets(), filter); } private List getCodeGenerationAppletDefs(String applicationName, String filter) throws UnifyException { return getRoleAppletDefs(applicationName, codeGenerationProvider.getCodeGenerationApplets(), filter); } private List getSychronizationAppletDefs(String applicationName, String filter) throws UnifyException { return getRoleAppletDefs(applicationName, synchronizationAppletList, filter); } private List getSnapshotAppletDefs(String applicationName, String filter) throws UnifyException { return getRoleAppletDefs(applicationName, snapshotAppletList, filter); } private List getRoleAppletDefs(String applicationName, List applets, String filter) throws UnifyException { final String roleCode = getUserToken().getRoleCode(); if (filter != null) { filter = filter.toLowerCase(); } List appletDefList = new ArrayList(); for (String appletName : applets) { AppletDef _appletDef = appletUtilities.application() .getAppletDef(ApplicationNameUtils.addVestigialNamePart(appletName, applicationName)); if (appletUtilities.applicationPrivilegeManager().isRoleWithPrivilege(roleCode, _appletDef.getPrivilege())) { if (filter == null || _appletDef.getLowerCaseLabel().contains(filter)) { appletDefList.add(_appletDef); } } } return appletDefList; } }



© 2015 - 2024 Weber Informatics LLC | Privacy Policy