ListPublisherRevisionsView.java 2.13 KB
package org.legrog.presentation;

import org.legrog.application.PublisherRevisionService;
import org.legrog.application.PublisherService;
import org.legrog.entities.Publisher;
import org.legrog.entities.PublisherRevision;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@Named
@RequestScoped
public class ListPublisherRevisionsView {
    Logger logger = LoggerFactory.getLogger(getClass());

    @Inject
    PublisherRevisionService publisherRevisionService;

    private Integer publisherId;

    private boolean viewAll;

    private List<PublisherRevision> publisherRevisions;

    public List<PublisherRevision> getPublisherRevisions() {
        return publisherRevisions;
    }
/*
    if (!viewAll) {
        logger.info("!viewAll");
        ArrayList<PublisherRevision> filteredPublisherRevisions= new ArrayList<PublisherRevision>();
        Iterator<PublisherRevision> publisherRevisionIterator = filteredPublisherRevisions.iterator();
        while (publisherRevisionIterator.hasNext()) {
            PublisherRevision publisherRevision = publisherRevisionIterator.next();
            if (publisherRevision.getPublisher().getPublisherId() == publisherId.intValue()) {
                filteredPublisherRevisions.add(publisherRevision);
            }
        }
        publisherRevisions = filteredPublisherRevisions;
    }
*/
    @PostConstruct
    public void init() {
        publisherRevisions = publisherRevisionService.getAllPublisherRevisions();
        logger.info("init");
    }

    public void setView() {
        logger.info("setView");
        logger.info("publisherId = " + publisherId);
        viewAll = false;
        if (publisherId == null) {
            viewAll = true;
        }
    }

    public Integer getPublisherId() {
        return publisherId;
    }

    public void setPublisherId(Integer publisherId) {
        this.publisherId = publisherId;
    }

    public boolean isViewAll() {
        return viewAll;
    }
}