| 1 |
package com.audatex.axn.ui.clickcommon.components.csa.profile; import com.audatex.axn.bre.configuration.ProfileWizardConfiguration; import com.audatex.axn.bre.core.refactor.PageInformationUtil; import com.audatex.axn.business.profilewizard.IProfileRulesManager; import com.audatex.axn.business.profilewizard.IProfileWizardService; import com.audatex.axn.business.profilewizard.ProcessStep; import com.audatex.axn.business.profilewizard.exception.ProfileWizardException; import com.audatex.axn.saxifwrapper.common.HistorizableItemWrapper; import com.audatex.axn.saxifwrapper.member.BusinessProcessModificationWrapper; import com.audatex.axn.ui.clickcommon.components.BaseComponent; import com.audatex.axn.ui.clickcommon.components.foundation.ComponentDescriptor; import com.audatex.axn.ui.clickcommon.controls.NullableCheckBox; import com.audatex.axn.ui.clickcommon.controls.behavior.IConfigurableComponent; import com.audatex.axn.ui.clickcommon.controls.datetime.CalendarDateTimeField; import com.audatex.axn.ui.clickcommon.pages.BasePage; import com.audatex.axn.ui.clickcommon.services.BREConfiguration; import com.audatex.axn.ui.clickcommon.util.MemberHelper; import com.audatex.axn.ui.clickcommon.util.StringEscapeUtils; import com.audatex.axn.valueholders.member.BusinessProcessModificationType; import com.audatex.axn.valueholders.member.MemberType; import com.audatex.axn.valueholders.member.OrganizationType; import com.google.gson.Gson; import net.sf.click.control.*; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; /** * Component to display details of one profile. It also allows to create new and edit existing profiles. * * @author alexander.gock * @since 18.01 (06-Dec-2017) * @see AXNGA-4115 */ public class ProfileDetailsComponent extends BaseComponent implements IConfigurableComponent { private static final Logger LOGGER = LoggerFactory.getLogger(ProfileDetailsComponent.class); public static final String FLD_PROFILE_ID = "profileId"; public static final String FLD_NAME = "name"; public static final String FLD_OWNER_NAME = "ownerName"; public static final String FLD_SAVE_DETAILS = "saveDetails"; private static final String[] JS_IMPORTS = new String[] { "bre_profiledetails.js", "profilewizard/bre_profilewizard_stepselector.js"}; private static final String[] CSS_IMPORTS = new String[] {"components/profilewizard/bre_profilewizard_stepselector.css"}; private static final String MSG_ERROR_OCCURED = "root.csa.profile.message.error"; private static final String MSG_NAME_REQUIRED = "root.csa.profile.message.name.required"; private static final String MSG_NAME_NOT_UNIQUE = "root.csa.profile.message.name.unique"; private static final String MSG_SAVED_SUCCESSFULLY = "root.csa.profile.message.save.success"; private static final String MSG_PROFILE_NOT_FOUND = "root.csa.profile.message.notfound"; private static final String DELETE_TITLE = "root.csa.profile.deletestep"; private static final String POPUP_CHECKBOX = "root.csa.profile.popupcheckbox"; private static final String POPUP_CONFIRMATION = "root.csa.profile.popupconfirmation"; protected IProfileRulesManager profileRulesManager; protected BREConfiguration breConfiguration; private HiddenField profileId; private CalendarDateTimeField lastUpdate; public ProfileDetailsComponent(String name) { super(name, null); setOwnTemplate(true); } @Override public void setConfig(BREConfiguration config) { breConfiguration = config; } @Override public void loadWrapper() { BusinessProcessModificationWrapper profileWrapper; String profileId = getIContext().getRequestParameter(FLD_PROFILE_ID); BusinessProcessModificationType profile = null; if (StringUtils.isNotEmpty(profileId)) { // open existing profile IProfileWizardService service = componentContainer.getComponent(IProfileWizardService.class); MemberType selectedMember = MemberHelper.getCurrentMember(); try { profile = service.getProfile(profileId, selectedMember); if (profile == null) { PageInformationUtil.getMessagePanel().addErrorMessage(getMessage(MSG_PROFILE_NOT_FOUND)); } } catch (ProfileWizardException e) { LOGGER.error("Error loading existing profile: " + profileId, e); PageInformationUtil.getMessagePanel().addErrorMessage(e.getMessage()); } } if(profile == null) { profile = new BusinessProcessModificationType(); profile.setItemId(StringUtils.EMPTY); MemberType selectedMember = MemberHelper.getCurrentMember(); if (selectedMember instanceof OrganizationType) { profile.setOwnerCompanyName(((OrganizationType)selectedMember).getCompanyName()); profile.setOwnerOrganizationName(((OrganizationType)selectedMember).getOrganizationName()); profile.setMemberId(selectedMember.getMemberId()); } } profileWrapper = new BusinessProcessModificationWrapper(profile); setWrapper(profileWrapper); } @Override public void onCreate() { profileRulesManager = componentContainer.getComponent(IProfileRulesManager.class); profileId = new HiddenField(FLD_PROFILE_ID, getWrapper().getItemId()); add(profileId); TextField name = new TextField(FLD_NAME); add(name); TextField profileId = new TextField(HistorizableItemWrapper.FLD_HISTORIZABLEITEM_ITEMID); profileId.setDisabled(true); add(profileId); NullableCheckBox isDefault = new NullableCheckBox(BusinessProcessModificationWrapper.FLD_BUSINESSPROCESSMODIFICATION_ISDEFAULT); isDefault.setDisabled(true); add(isDefault); TextField ownerName = new TextField(FLD_OWNER_NAME); ownerName.setDisabled(true); add(ownerName); TextField ownerMemberId = new TextField(BusinessProcessModificationWrapper.FLD_BUSINESSPROCESSMODIFICATION_MEMBERID); ownerMemberId.setDisabled(true); add(ownerMemberId); lastUpdate = new CalendarDateTimeField(HistorizableItemWrapper.FLD_HISTORIZABLEITEM_LASTUPDATEDDATETIME); lastUpdate.setDisabled(true); add(lastUpdate); TextField processName = new TextField(BusinessProcessModificationWrapper.FLD_BUSINESSPROCESSMODIFICATION_PROCESSNAME); processName.setDisabled(true); add(processName); Button saveDetails = new Button(FLD_SAVE_DETAILS); add(saveDetails); } @Override public void onInit() { super.onInit(); String errorMsg = "BRE.ProfileDetails.messageServerError = '" + StringEscapeUtils.escapeJavaScript(getMessage(MSG_ERROR_OCCURED)) + "';"; String nameRequiredMsg = "BRE.ProfileDetails.messageNameRequired = '" + StringEscapeUtils.escapeJavaScript(getMessage(MSG_NAME_REQUIRED)) + "';"; String nameNotUnique = "BRE.ProfileDetails.messageNameNotUnique = '" + StringEscapeUtils.escapeJavaScript(getMessage(MSG_NAME_NOT_UNIQUE)) + "';"; String saveSuccessMsg = "BRE.ProfileDetails.messageSavedSuccessfully = '" + StringEscapeUtils.escapeJavaScript(getMessage(MSG_SAVED_SUCCESSFULLY)) + "';"; BasePage.addDomReadyEvent(errorMsg); BasePage.addDomReadyEvent(nameRequiredMsg); BasePage.addDomReadyEvent(nameNotUnique); BasePage.addDomReadyEvent(saveSuccessMsg); } @Override public void copyFieldsFromWrapper(Form form) { super.copyFieldsFromWrapper(form); BusinessProcessModificationWrapper wrapper = getWrapper(); Field name = getFieldByLocalName(FLD_NAME); if (name != null) { name.setValue(wrapper.getModificationName()); } Field ownerName = getFieldByLocalName(FLD_OWNER_NAME); if (ownerName != null) { List<String> combinedName = new ArrayList<String>(2); if (StringUtils.isNotEmpty(wrapper.getOwnerCompanyName())) { combinedName.add(wrapper.getOwnerCompanyName()); } if (StringUtils.isNotEmpty(wrapper.getOwnerOrganizationName())) { combinedName.add(wrapper.getOwnerOrganizationName()); } ownerName.setValue(StringUtils.join(combinedName, " ")); } initStepLists(wrapper.getProcessName()); } @Override public void copyFieldsToWrapper() { super.copyFieldsToWrapper(form); BusinessProcessModificationWrapper wrapper = getWrapper(); Field name = getFieldByLocalName(FLD_NAME); if (name != null) { wrapper.setModificationName(name.getValue()); } } public BusinessProcessModificationWrapper getWrapper() { return (BusinessProcessModificationWrapper)super.getWrapper(); } @Override public String getHtmlImports() { return addHtmlImports(JS_IMPORTS, CSS_IMPORTS); } public static ComponentDescriptor getComponentDescriptor() { ComponentDescriptor componentDescriptor = new ComponentDescriptor(); componentDescriptor.add(FLD_NAME, TextField.class); componentDescriptor.add(HistorizableItemWrapper.FLD_HISTORIZABLEITEM_ITEMID, TextField.class); componentDescriptor .add(BusinessProcessModificationWrapper.FLD_BUSINESSPROCESSMODIFICATION_ISDEFAULT, NullableCheckBox.class); componentDescriptor.add(FLD_OWNER_NAME, TextField.class); componentDescriptor .add(BusinessProcessModificationWrapper.FLD_BUSINESSPROCESSMODIFICATION_MEMBERID, TextField.class); componentDescriptor .add(BusinessProcessModificationWrapper.FLD_BUSINESSPROCESSMODIFICATION_PROCESSNAME, TextField.class); componentDescriptor .add(HistorizableItemWrapper.FLD_HISTORIZABLEITEM_LASTUPDATEDDATETIME, CalendarDateTimeField.class); componentDescriptor.add(FLD_SAVE_DETAILS, Button.class); return componentDescriptor; } private void initStepLists(String profileProcessName) { MemberType selectedMember = MemberHelper.getCurrentMember(); String baseProcessName = breConfiguration.get(ProfileWizardConfiguration.WIZARD_BASE_PROCESS); List<ProcessStep> defaultSteps = profileRulesManager.getProcessSteps(baseProcessName, selectedMember); List<String> defaultStepsFixed = new ArrayList<String>(); for (ProcessStep processStep : defaultSteps) { defaultStepsFixed.add(processStep.getName()); } List<ProcessStep> selectedSteps; if (StringUtils.isNotEmpty(profileProcessName)) { selectedSteps = profileRulesManager.getProcessSteps(profileProcessName, selectedMember); } else { selectedSteps = Collections.EMPTY_LIST; } defaultSteps.removeAll(selectedSteps); setupComponentModel(defaultSteps, defaultStepsFixed, selectedSteps); } protected void setupComponentModel( List<ProcessStep> defaultSteps, List<String> defaultStepsFixed, List<ProcessStep> selectedSteps) { Map<String, Object> componentModel = getIPage().getModel(); componentModel.put("defaultSteps", defaultSteps != null ? defaultSteps : "{}"); componentModel.put("defaultStepsFixed", defaultStepsFixed != null ? new Gson().toJson(defaultStepsFixed) : "{}"); componentModel.put("selectedSteps", selectedSteps != null ? selectedSteps : "{}"); componentModel.put("deleteTitle", getMessage(DELETE_TITLE)); componentModel.put("popupConfirmation", getMessage(POPUP_CONFIRMATION)); componentModel.put("popupCheckbox", getMessage(POPUP_CHECKBOX)); } } |
Комментарии