001/*
002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *      Andre Justo
016 */
017
018package org.nuxeo.ecm.media.publishing.wistia;
019
020import org.apache.commons.logging.Log;
021import org.apache.commons.logging.LogFactory;
022import org.jboss.seam.ScopeType;
023import org.jboss.seam.annotations.Name;
024import org.jboss.seam.annotations.Scope;
025import org.nuxeo.ecm.media.publishing.MediaPublishingProvider;
026import org.nuxeo.ecm.media.publishing.MediaPublishingService;
027import org.nuxeo.ecm.media.publishing.wistia.model.Project;
028import org.nuxeo.runtime.api.Framework;
029
030import java.io.Serializable;
031import java.util.List;
032
033/**
034 * @since 7.3
035 */
036@Name("wistiaPublishingActions")
037@Scope(ScopeType.EVENT)
038public class WistiaPublishingActions implements Serializable{
039
040    private static final long serialVersionUID = 1L;
041
042    private static final Log log = LogFactory.getLog(WistiaPublishingActions.class);
043
044    List<Project> projects;
045
046    /**
047     * Helper to retrieve a list of projects for a given Wistia account
048     */
049    public List<Project> getProjects(String account) {
050
051        if (account == null || account.length() == 0) {
052            return null;
053        }
054
055        if (projects == null) {
056            MediaPublishingProvider service = getMediaPublishingService().getProvider("Wistia");
057            projects = ((WistiaService) service).getProjects(account);
058        }
059
060        return projects;
061    }
062
063    private MediaPublishingService getMediaPublishingService() {
064        return Framework.getService(MediaPublishingService.class);
065    }
066}