PublisherServiceSpring.java 1.75 KB
package org.legrog.web.publisher;


import org.legrog.entities.Publisher;
import org.legrog.entities.PublisherRepository;
import org.legrog.entities.PublisherRevision;
import org.legrog.entities.PublisherRevisionRepository;

import javax.ejb.Stateless;
import javax.inject.Inject;
import java.util.List;
import java.util.Set;

@Stateless
public class PublisherServiceSpring implements PublisherService {
    @Inject
    PublisherRepository publisherRepository;

    @Inject
    PublisherRevisionRepository publisherRevisionRepository;

    public void addPublisherRevision(PublisherRevision publisherRevision) {
        publisherRevisionRepository.save(publisherRevision);
    }

    public List<PublisherRevision> getAllPublisherRevisions() {
        return publisherRevisionRepository.findAll();
    }

    public PublisherRevision getPublisherRevision(Integer publisherRevisionId) {
        return publisherRevisionRepository.findOne(publisherRevisionId);
    }

    public void addPublisher(Publisher publisher) {
        publisherRepository.save(publisher);
    }

    public void updatePublisher(Publisher publisher) {
        publisherRepository.save(publisher);
    }

    public void addRevisionToPublisher(Publisher publisher, PublisherRevision publisherRevision) {
        Set<PublisherRevision> publisherRevisionSet = publisher.getRevisions();
        publisherRevisionSet.add(publisherRevision);
        publisher.setRevisions(publisherRevisionSet);
        publisherRevision.setPublisher(publisher);
        publisherRepository.save(publisher);
    }

    public Publisher getPublisher(Integer publisherId) {
        return publisherRepository.findOne(publisherId);
    }

    public List<Publisher> getAllPublishers() {
        return publisherRepository.findAll();
    }
}