001// -------------------------------------------------------------------------------- 002// Copyright 2002-2024 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.form.VendorLoginForm; 022import com.echothree.control.user.authentication.common.result.AuthenticationResultFactory; 023import com.echothree.control.user.authentication.common.result.GetVendorLoginDefaultsResult; 024import com.echothree.model.control.party.common.PartyTypes; 025import com.echothree.model.control.user.server.control.UserControl; 026import com.echothree.model.data.party.server.entity.Party; 027import com.echothree.model.data.user.common.pk.UserVisitPK; 028import com.echothree.model.data.user.server.entity.UserLogin; 029import com.echothree.model.data.user.server.entity.UserSession; 030import com.echothree.util.common.validation.FieldDefinition; 031import com.echothree.util.common.command.BaseResult; 032import com.echothree.util.server.control.BaseSimpleCommand; 033import java.util.Arrays; 034import java.util.Collections; 035import java.util.List; 036 037public class GetVendorLoginDefaultsCommand 038 extends BaseSimpleCommand<GetVendorLoginDefaultsForm> { 039 040 private final static List<FieldDefinition> FORM_FIELD_DEFINITIONS; 041 042 static { 043 FORM_FIELD_DEFINITIONS = Collections.unmodifiableList(Arrays.asList( 044 )); 045 } 046 047 /** Creates a new instance of GetVendorLoginDefaultsCommand */ 048 public GetVendorLoginDefaultsCommand(UserVisitPK userVisitPK, GetVendorLoginDefaultsForm form) { 049 super(userVisitPK, form, null, FORM_FIELD_DEFINITIONS, true); 050 } 051 052 @Override 053 protected BaseResult execute() { 054 GetVendorLoginDefaultsResult result = AuthenticationResultFactory.getGetVendorLoginDefaultsResult(); 055 UserControl userControl = getUserControl(); 056 UserSession userSession = userControl.getUserSessionByUserVisit(getUserVisit()); 057 String username = null; 058 059 if(userSession != null) { 060 Party party = userSession.getParty(); 061 062 if(party != null) { 063 if(party.getLastDetail().getPartyType().getPartyTypeName().equals(PartyTypes.VENDOR.name())) { 064 UserLogin userLogin = userControl.getUserLogin(party); 065 066 username = userLogin.getUsername(); 067 } 068 } 069 } 070 071 VendorLoginForm vendorLoginForm = AuthenticationFormFactory.getVendorLoginForm(); 072 vendorLoginForm.setUsername(username); 073 result.setVendorLoginForm(vendorLoginForm); 074 075 return result; 076 } 077 078}