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.model.control.core.server.logic;
018
019import com.echothree.model.control.core.common.exception.UnknownTextDecorationNameException;
020import com.echothree.model.control.core.common.exception.UnknownTextTransformationNameException;
021import com.echothree.model.control.core.server.control.TextControl;
022import com.echothree.model.data.core.server.entity.TextDecoration;
023import com.echothree.model.data.core.server.entity.TextTransformation;
024import com.echothree.util.common.message.ExecutionErrors;
025import com.echothree.util.server.control.BaseLogic;
026import com.echothree.util.server.message.ExecutionErrorAccumulator;
027import javax.enterprise.context.ApplicationScoped;
028import javax.enterprise.inject.spi.CDI;
029import javax.inject.Inject;
030
031@ApplicationScoped
032public class TextLogic
033        extends BaseLogic {
034
035    @Inject
036    protected TextControl textControl;
037
038    protected TextLogic() {
039        super();
040    }
041
042    public static TextLogic getInstance() {
043        return CDI.current().select(TextLogic.class).get();
044    }
045
046    public TextDecoration getTextDecorationByName(final ExecutionErrorAccumulator eea, final String textDecorationName) {
047        var textDecoration = textControl.getTextDecorationByName(textDecorationName);
048
049        if(textDecoration == null) {
050            handleExecutionError(UnknownTextDecorationNameException.class, eea, ExecutionErrors.UnknownTextDecorationName.name(), textDecorationName);
051        }
052
053        return textDecoration;
054    }
055    
056    public TextTransformation getTextTransformationByName(final ExecutionErrorAccumulator eea, final String textTransformationName) {
057        var textTransformation = textControl.getTextTransformationByName(textTransformationName);
058
059        if(textTransformation == null) {
060            handleExecutionError(UnknownTextTransformationNameException.class, eea, ExecutionErrors.UnknownTextTransformationName.name(), textTransformationName);
061        }
062
063        return textTransformation;
064    }
065    
066}