001// -------------------------------------------------------------------------------- 002// Copyright 2002-2025 Echo Three, LLC 003// 004// Licensed under the Apache License, Version 2.0 (the "License"); 005// you may not use this file except in compliance with the License. 006// You may obtain a copy of the License at 007// 008// http://www.apache.org/licenses/LICENSE-2.0 009// 010// Unless required by applicable law or agreed to in writing, software 011// distributed under the License is distributed on an "AS IS" BASIS, 012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013// See the License for the specific language governing permissions and 014// limitations under the License. 015// -------------------------------------------------------------------------------- 016 017package com.echothree.control.user.authentication.server.command; 018 019import com.echothree.control.user.authentication.common.form.AuthenticationFormFactory; 020import com.echothree.control.user.authentication.common.form.GetVendorLoginDefaultsForm; 021import com.echothree.control.user.authentication.common.result.AuthenticationResultFactory; 022import com.echothree.model.control.party.common.PartyTypes; 023import com.echothree.util.common.command.BaseResult; 024import com.echothree.util.common.validation.FieldDefinition; 025import com.echothree.util.server.control.BaseSimpleCommand; 026import java.util.List; 027import javax.enterprise.context.RequestScoped; 028 029@RequestScoped 030public class GetVendorLoginDefaultsCommand 031 extends BaseSimpleCommand<GetVendorLoginDefaultsForm> { 032 033 private final static List<FieldDefinition> FORM_FIELD_DEFINITIONS; 034 035 static { 036 FORM_FIELD_DEFINITIONS = List.of(); 037 } 038 039 /** Creates a new instance of GetVendorLoginDefaultsCommand */ 040 public GetVendorLoginDefaultsCommand() { 041 super(null, FORM_FIELD_DEFINITIONS, true); 042 } 043 044 @Override 045 protected BaseResult execute() { 046 var result = AuthenticationResultFactory.getGetVendorLoginDefaultsResult(); 047 var userControl = getUserControl(); 048 var userSession = userControl.getUserSessionByUserVisit(getUserVisit()); 049 String username = null; 050 051 if(userSession != null) { 052 var party = userSession.getParty(); 053 054 if(party != null) { 055 if(party.getLastDetail().getPartyType().getPartyTypeName().equals(PartyTypes.VENDOR.name())) { 056 var userLogin = userControl.getUserLogin(party); 057 058 username = userLogin.getUsername(); 059 } 060 } 061 } 062 063 var vendorLoginForm = AuthenticationFormFactory.getVendorLoginForm(); 064 vendorLoginForm.setUsername(username); 065 result.setVendorLoginForm(vendorLoginForm); 066 067 return result; 068 } 069 070}