package ua.be.wee.model.pt;

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

import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import ua.be.wee.model.nodes.ports.ControlOutputPort;

@Entity
public class EndActivityEvent extends Event {

	@OneToOne
	private ControlOutputPort relatesTo;
	
	@OneToMany
	private List<TraceArtifact> producedArtifacts;
	
	public EndActivityEvent() {
		producedArtifacts = new ArrayList<TraceArtifact>();
	}

	public ControlOutputPort getRelatesTo() {
		return relatesTo;
	}

	public void setRelatesTo(ControlOutputPort relatesTo) {
		this.relatesTo = relatesTo;
	}
	
	public void addTraceArtifact(TraceArtifact art) {
		producedArtifacts.add(art);
	}
	
	public List<TraceArtifact> getProducedArtifacts() {
		return producedArtifacts;
	}
	
	public void setProducedArtifacts(List<TraceArtifact> arts) {
		producedArtifacts = arts;
	}
	
	public TraceArtifact getArtifact(String iri) {
		for (TraceArtifact traceArtifact : producedArtifacts) {
			if (iri.equals(traceArtifact.getIri())) {
				return traceArtifact;
			}
		}
		return null;
	}
	
}
