001// -------------------------------------------------------------------------------- 002// Copyright 2002-2026 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.geo.server.command; 018 019import com.echothree.control.user.geo.common.edit.GeoCodeTimeZoneEdit; 020import com.echothree.control.user.geo.common.edit.GeoEditFactory; 021import com.echothree.control.user.geo.common.result.EditGeoCodeTimeZoneResult; 022import com.echothree.control.user.geo.common.result.GeoResultFactory; 023import com.echothree.control.user.geo.common.spec.GeoCodeTimeZoneSpec; 024import com.echothree.model.control.geo.server.control.GeoControl; 025import com.echothree.model.control.geo.server.logic.GeoCodeTimeZoneLogic; 026import com.echothree.model.control.party.common.PartyTypes; 027import com.echothree.model.control.security.common.SecurityRoleGroups; 028import com.echothree.model.control.security.common.SecurityRoles; 029import com.echothree.model.data.geo.server.entity.GeoCode; 030import com.echothree.model.data.geo.server.entity.GeoCodeTimeZone; 031import com.echothree.util.common.validation.FieldDefinition; 032import com.echothree.util.common.validation.FieldType; 033import com.echothree.util.server.control.BaseAbstractEditCommand; 034import com.echothree.util.server.control.CommandSecurityDefinition; 035import com.echothree.util.server.control.PartyTypeDefinition; 036import com.echothree.util.server.control.SecurityRoleDefinition; 037import java.util.List; 038import javax.enterprise.context.Dependent; 039import javax.inject.Inject; 040 041@Dependent 042public class EditGeoCodeTimeZoneCommand 043 extends BaseAbstractEditCommand<GeoCodeTimeZoneSpec, GeoCodeTimeZoneEdit, EditGeoCodeTimeZoneResult, GeoCodeTimeZone, GeoCode> { 044 045 private final static CommandSecurityDefinition COMMAND_SECURITY_DEFINITION; 046 private final static List<FieldDefinition> SPEC_FIELD_DEFINITIONS; 047 private final static List<FieldDefinition> EDIT_FIELD_DEFINITIONS; 048 049 static { 050 COMMAND_SECURITY_DEFINITION = new CommandSecurityDefinition(List.of( 051 new PartyTypeDefinition(PartyTypes.UTILITY.name(), null), 052 new PartyTypeDefinition(PartyTypes.EMPLOYEE.name(), List.of( 053 new SecurityRoleDefinition(SecurityRoleGroups.GeoCodeTimeZone.name(), SecurityRoles.Edit.name()) 054 )) 055 )); 056 057 SPEC_FIELD_DEFINITIONS = List.of( 058 new FieldDefinition("GeoCodeName", FieldType.ENTITY_NAME, true, null, null), 059 new FieldDefinition("JavaTimeZoneName", FieldType.TIME_ZONE_NAME, true, null, null) 060 ); 061 062 EDIT_FIELD_DEFINITIONS = List.of( 063 new FieldDefinition("IsDefault", FieldType.BOOLEAN, true, null, null), 064 new FieldDefinition("SortOrder", FieldType.SIGNED_INTEGER, true, null, null) 065 ); 066 } 067 068 @Inject 069 GeoControl geoControl; 070 071 @Inject 072 GeoCodeTimeZoneLogic geoCodeTimeZoneLogic; 073 074 /** Creates a new instance of EditGeoCodeTimeZoneCommand */ 075 public EditGeoCodeTimeZoneCommand() { 076 super(COMMAND_SECURITY_DEFINITION, SPEC_FIELD_DEFINITIONS, EDIT_FIELD_DEFINITIONS); 077 } 078 079 @Override 080 public EditGeoCodeTimeZoneResult getResult() { 081 return GeoResultFactory.getEditGeoCodeTimeZoneResult(); 082 } 083 084 @Override 085 public GeoCodeTimeZoneEdit getEdit() { 086 return GeoEditFactory.getGeoCodeTimeZoneEdit(); 087 } 088 089 @Override 090 public GeoCodeTimeZone getEntity(EditGeoCodeTimeZoneResult result) { 091 return geoCodeTimeZoneLogic.getGeoCodeTimeZoneBySpec(this, spec, editModeToEntityPermission(editMode)); 092 } 093 094 @Override 095 public GeoCode getLockEntity(GeoCodeTimeZone geoCodeTimeZone) { 096 return geoCodeTimeZone.getGeoCode(); 097 } 098 099 @Override 100 public void fillInResult(EditGeoCodeTimeZoneResult result, GeoCodeTimeZone geoCodeTimeZone) { 101 result.setGeoCodeTimeZone(geoControl.getGeoCodeTimeZoneTransfer(getUserVisit(), geoCodeTimeZone)); 102 } 103 104 @Override 105 public void doLock(GeoCodeTimeZoneEdit edit, GeoCodeTimeZone geoCodeTimeZone) { 106 edit.setIsDefault(geoCodeTimeZone.getIsDefault().toString()); 107 edit.setSortOrder(geoCodeTimeZone.getSortOrder().toString()); 108 } 109 110 @Override 111 public void doUpdate(GeoCodeTimeZone geoCodeTimeZone) { 112 var geoCodeTimeZoneValue = geoControl.getGeoCodeTimeZoneValue(geoCodeTimeZone); 113 114 geoCodeTimeZoneValue.setIsDefault(Boolean.valueOf(edit.getIsDefault())); 115 geoCodeTimeZoneValue.setSortOrder(Integer.valueOf(edit.getSortOrder())); 116 117 geoControl.updateGeoCodeTimeZoneFromValue(geoCodeTimeZoneValue, getPartyPK()); 118 } 119 120}