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

org.finos.legend.depot.domain.notifications.MetadataNotification 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.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.EqualsExclude;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.finos.legend.depot.store.model.HasIdentifier;
import org.finos.legend.depot.domain.VersionedData;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@JsonIgnoreProperties(ignoreUnknown = true)
public class MetadataNotification extends VersionedData implements HasIdentifier
{
    private static final int DEFAULT_MAX_ATTEMPTS = 2;
    @EqualsExclude
    @JsonProperty
    private String id;
    @JsonProperty
    private String projectId;
    @JsonProperty
    private String eventId;
    @JsonProperty
    private String parentEventId;
    @JsonProperty
    private boolean fullUpdate;
    @JsonProperty
    private boolean transitive;
    @JsonProperty
    private int attempt;
    @JsonProperty
    private int maxAttempts;
    @JsonProperty
    private Date created;
    @JsonProperty
    private Date updated;
    @JsonProperty
    private Date completed;
    @EqualsExclude
    @JsonProperty
    private Map responses;
    @JsonProperty
    private Priority priority;


    @JsonCreator
    public MetadataNotification(@JsonProperty(value = "projectId") String projectId,
                                @JsonProperty(value = "groupId") String groupId,
                                @JsonProperty(value = "artifactId") String artifactId,
                                @JsonProperty(value = "version") String version,
                                @JsonProperty(value = "eventId") String eventId,
                                @JsonProperty(value = "parentEvent") String parentEventId,
                                @JsonProperty(value = "fullUpdate") Boolean fullUpdate,
                                @JsonProperty(value = "transitive") Boolean transitive,
                                @JsonProperty(value = "attempt") Integer attempt,
                                @JsonProperty(value = "maxAttempts") Integer maxAttempts,
                                @JsonProperty(value = "responses") Map responses,
                                @JsonProperty(value = "created") Date created,
                                @JsonProperty(value = "updated") Date updated,
                                @JsonProperty(value = "completed") Date completed,
                                @JsonProperty(value = "eventPriority") Priority priority)
    {
        super(groupId,artifactId,version);
        this.projectId = projectId;
        this.eventId = eventId;
        this.parentEventId = parentEventId;
        this.updated = updated;
        this.created = created;
        this.maxAttempts = maxAttempts != null ? maxAttempts : DEFAULT_MAX_ATTEMPTS;
        this.responses = responses != null ? responses : new HashMap<>();
        this.attempt = attempt != null ? attempt : 0;
        this.fullUpdate = fullUpdate != null ? fullUpdate : false;
        this.transitive = transitive != null ? transitive : false;
        this.priority = priority;
        this.completed = completed;
    }

    public MetadataNotification(String projectId, String groupId, String artifactId, String versionId)
    {
        this(projectId, groupId, artifactId, versionId, null, null, null, null, null, null, null, null,null,null, Priority.LOW);
    }

    public MetadataNotification(String projectId,String groupId, String artifactId, String versionId, Boolean fullUpdate,Boolean transitive, String parentEvent)
    {
        this(projectId, groupId, artifactId, versionId, null, parentEvent, fullUpdate, transitive, null, null, null,null,null,null, Priority.LOW);
    }

    public MetadataNotification(String projectId,String groupId, String artifactId, String versionId, Boolean fullUpdate,Boolean transitive, String parentEvent, Priority priority)
    {
        this(projectId, groupId, artifactId, versionId, null, parentEvent, fullUpdate, transitive, null, null, null, null,null, null, priority);
    }

    public MetadataNotification()
    {
    }

    public String getId()
    {
        return id;
    }

    public void setId(String id)
    {
        this.id = id;
    }

    public String getEventId()
    {
        return eventId;
    }

    public MetadataNotification setEventId(String eventID)
    {
        this.eventId = eventID;
        return this;
    }

    public Date getCompleted()
    {
        return completed;
    }

    public void setCompleted(Date completed)
    {
        this.completed = completed;
    }

    public void setEventPriority(Priority priority)
    {
        this.priority = priority;
    }

    public boolean isFullUpdate()
    {
        return fullUpdate;
    }

    public String getProjectId()
    {
        return projectId;
    }

    public MetadataNotification setProjectId(String projectId)
    {
        this.projectId = projectId;
        return this;
    }

    @JsonProperty("status")
    public MetadataNotificationStatus getStatus()
    {
        return this.responses.getOrDefault(this.attempt,new MetadataNotificationResponse()).getStatus();
    }

    public String getParentEventId()
    {
        return parentEventId;
    }

    public void setParentEventId(String parentEventId)
    {
        this.parentEventId = parentEventId;
    }

    public MetadataNotification setFullUpdate(boolean fullUpdate)
    {
        this.fullUpdate = fullUpdate;
        return this;
    }

    public void setTransitive(boolean transitive)
    {
        this.transitive = transitive;
    }

    public Date getCreated()
    {
        return created;
    }

    public void setCreated(Date created)
    {
        this.created = created;
    }

    public void setMaxAttempts(int maxAttempts)
    {
        this.maxAttempts = maxAttempts;
    }

    public boolean isTransitive()
    {
        return transitive;
    }

    public MetadataNotification complete()
    {
        this.completed = new Date();
        return this;
    }

    public MetadataNotification increaseAttempts()
    {
        this.attempt++;
        return this;
    }

    public boolean retriesExceeded()
    {
        return attempt >= maxAttempts;
    }


    public Map getResponses()
    {
        if (responses == null)
        {
            responses = new HashMap<>();
        }
        return responses;
    }

    public void setResponses(Map responses)
    {
        this.responses = responses;
    }

    public MetadataNotification addError(String errorMessage)
    {
        getResponse(this.attempt).addError(errorMessage);
        return this;
    }

    public void setResponse(MetadataNotificationResponse response)
    {
       getResponses().put(this.attempt,response);
    }

    public MetadataNotification combineResponse(MetadataNotificationResponse response)
    {
        if (response != null)
        {
            getResponse(this.attempt).combine(response);
        }
        return this;
    }

    private MetadataNotificationResponse getResponse(int attempt)
    {
        getResponses().putIfAbsent(attempt,new MetadataNotificationResponse());
        return getResponses().get(attempt);
    }

    @JsonIgnore
    public MetadataNotificationResponse getCurrentResponse()
    {
        return getResponses().get(attempt);
    }

    public Date getUpdated()
    {
        return updated;
    }

    public MetadataNotification setUpdated(Date updated)
    {
        this.updated = updated;
        return this;
    }

    public int getAttempt()
    {
        return attempt;
    }

    public MetadataNotification setAttempt(int integer)
    {
        this.attempt = integer;
        return this;
    }

    public int getMaxAttempts()
    {
        return maxAttempts;
    }

    public Priority getEventPriority()
    {
        return priority;
    }

    @Override
    public boolean equals(Object obj)
    {
        return EqualsBuilder.reflectionEquals(this, obj);
    }

    @Override
    public int hashCode()
    {
        return HashCodeBuilder.reflectionHashCode(this);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy