001/**
002 * Copyright (C) 2006-2025 Talend Inc. - www.talend.com
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 */
016package org.talend.sdk.component.api.exception;
017
018import javax.json.bind.annotation.JsonbCreator;
019import javax.json.bind.annotation.JsonbPropertyOrder;
020
021import lombok.Data;
022
023/**
024 * This class is dedicated to Studio's guess schema feature.
025 * It has the same goal as ComponentException except that you can specify an action to execute in some cases.
026 *
027 * If you don't need such feature, just use ComponentException.
028 *
029 * See me TCOMP-2342 for more details.
030 */
031@Data
032@JsonbPropertyOrder({ "localizedMessage", "message", "stackTrace", "suppressed", "possibleHandleErrorWith" })
033public class DiscoverSchemaException extends RuntimeException {
034
035    public enum HandleErrorWith {
036        /**
037         * default case
038         */
039        EXCEPTION,
040        /**
041         * unhandled.
042         */
043        SILENT,
044        /**
045         * unhandled.
046         */
047        RETRY,
048        /**
049         * Potentially execute a mock job in studio.
050         * Will ask user's validation before executing.
051         * When specifying this option, developer should be sure that no side effect can be generated by connector.
052         */
053        EXECUTE_MOCK_JOB,
054        /**
055         * Will execute a lifecycle through framework using only configuration.
056         * This won't query for any user input.
057         * When specifying this option, developer should be sure that no side effect can be generated by connector.
058         */
059        EXECUTE_LIFECYCLE;
060    }
061
062    private HandleErrorWith possibleHandleErrorWith = HandleErrorWith.EXCEPTION;
063
064    public DiscoverSchemaException(final ComponentException e) {
065        super(e.getOriginalMessage(), e.getCause());
066    }
067
068    public DiscoverSchemaException(final ComponentException e, final HandleErrorWith handling) {
069        super(e.getOriginalMessage(), e.getCause());
070        setPossibleHandleErrorWith(handling);
071    }
072
073    public DiscoverSchemaException(final String message, final HandleErrorWith handling) {
074        super(message);
075        setPossibleHandleErrorWith(handling);
076    }
077
078    @JsonbCreator
079    public DiscoverSchemaException(final String message, final StackTraceElement[] stackTrace,
080            final HandleErrorWith handling) {
081        super(message);
082        setStackTrace(stackTrace);
083        setPossibleHandleErrorWith(handling);
084    }
085
086}