VotingCompoAddEntryView.java 2.04 KB
package fi.codecrew.moya.web.cdiview.voting;

import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import javax.validation.constraints.NotNull;

import org.primefaces.model.UploadedFile;

import fi.codecrew.moya.beans.VotingBeanLocal;
import fi.codecrew.moya.model.CompoEntry;
import fi.codecrew.moya.model.CompoEntryFile;

@Named
@RequestScoped
public class VotingCompoAddEntryView {

	@EJB
	VotingBeanLocal votingBean;

	@NotNull
	private String name;
	private String notes;
	private String screenMessage;

	@NotNull
	private UploadedFile uploadedFile;

	private Integer compoId;
	private String compoName;

	public Integer getCompoId() {
		return compoId;
	}

	public void setCompoId(Integer compoId) {
		this.compoId = compoId;
	}

	public UploadedFile getUploadedFile() {
		return uploadedFile;
	}

	public void setUploadedFile(UploadedFile uploadedFile) {
		this.uploadedFile = uploadedFile;
	}

	public String getScreenMessage() {
		return screenMessage;
	}

	public void setScreenMessage(String screenMessage) {
		this.screenMessage = screenMessage;
	}

	public String getNotes() {
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCompoName() {
		return compoName;
	}

	public void setCompoName(String compoName) {
		this.compoName = compoName;
	}

	public String send() {
		CompoEntry compoEntry = new CompoEntry();
		compoEntry.setTitle(name);
		compoEntry.setNotes(notes);
		compoEntry.setScreenMessage(screenMessage);
		compoEntry.setCompo(votingBean.getCompoById(compoId));
		CompoEntryFile cef = new CompoEntryFile(compoEntry);
		cef.setFileData(this.uploadedFile.getContents());
		cef.setFileName(uploadedFile.getFileName());
		votingBean.addEntry(compoEntry, cef);
		return null;
	}

	public void initView() {
		compoName = votingBean.getCompoById(compoId).getName();
	}
}