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