001/*
002 * (C) Copyright 2006-2016 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Tiago Cardoso <tcardoso@nuxeo.com>
018 */
019package org.nuxeo.ecm.platform.threed.renderView;
020
021import org.jboss.seam.ScopeType;
022import org.jboss.seam.annotations.Name;
023import org.jboss.seam.annotations.Scope;
024import org.nuxeo.ecm.core.api.DocumentModel;
025import org.nuxeo.ecm.core.api.PropertyException;
026import org.nuxeo.ecm.platform.threed.service.ThreeDService;
027import org.nuxeo.runtime.api.Framework;
028
029import java.util.ArrayList;
030import java.util.Collections;
031import java.util.List;
032
033import static org.nuxeo.ecm.platform.threed.ThreeDConstants.THREED_FACET;
034import static org.nuxeo.ecm.platform.threed.ThreeDDocumentConstants.RENDER_VIEWS_PROPERTY;
035
036/**
037 * Backing bean for the Render Views of an document.
038 *
039 * @since 8.4
040 */
041@Name("renderViewActions")
042@Scope(ScopeType.EVENT)
043public class RenderViewActions {
044
045    public List<RenderViewItem> getItems(DocumentModel doc) throws PropertyException {
046        if (!doc.hasFacet(THREED_FACET)) {
047            return Collections.emptyList();
048        }
049        int size = doc.getProperty(RENDER_VIEWS_PROPERTY).getValue(List.class).size();
050        List<RenderViewItem> items = new ArrayList<>(size);
051        for (int i = 0; i < size; i++) {
052            items.add(new RenderViewItem(doc, RENDER_VIEWS_PROPERTY, i));
053        }
054        return items;
055    }
056
057    public boolean isConvertingRenders(DocumentModel doc) {
058        ThreeDService service = Framework.getService(ThreeDService.class);
059        return !service.getBatchProgress(doc.getRepositoryName(), doc.getId()).isUnknown();
060    }
061
062}