All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.finos.legend.depot.domain.notifications.MetadataNotificationResponse Maven / Gradle / Ivy

There is a newer version: 2.48.1
Show newest version
//  Copyright 2021 Goldman Sachs
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//

package org.finos.legend.depot.domain.notifications;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.ArrayList;
import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true)
public class MetadataNotificationResponse
{

    @JsonProperty
    private List messages = new ArrayList<>();
    @JsonProperty
    private List errors = new ArrayList<>();

    @JsonProperty(value = "status")
    public MetadataNotificationStatus getStatus()
    {
        return !errors.isEmpty() ? MetadataNotificationStatus.FAILED : MetadataNotificationStatus.SUCCESS;
    }

    @Override
    public String toString()
    {
        return "MetadataEventResponse{" +
                "messages=" + messages +
                ", errors=" + errors +
                '}';
    }

    public List getErrors()
    {
        return errors;
    }

    public List getMessages()
    {
        return messages;
    }

    public MetadataNotificationResponse addError(String message)
    {
        this.errors.add(message);
        return this;
    }

    public MetadataNotificationResponse addMessage(String message)
    {
        this.messages.add(message);
        return this;
    }

    public MetadataNotificationResponse addMessages(List messages)
    {
        this.messages.addAll(messages);
        return this;
    }

    public void logError(String error)
    {
        this.errors.add(error);
    }

    public boolean hasErrors()
    {
        return getErrors() != null && !getErrors().isEmpty();
    }

    public MetadataNotificationResponse combine(MetadataNotificationResponse eventResponse)
    {
        if (eventResponse != null)
        {
            this.errors.addAll(eventResponse.getErrors());
            this.addMessages(eventResponse.getMessages());
        }
        return this;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy