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.adapter; 020 021import org.nuxeo.common.utils.FileUtils; 022import org.nuxeo.ecm.core.api.Blob; 023import org.nuxeo.ecm.core.api.Blobs; 024import org.nuxeo.ecm.core.api.CoreSession; 025import org.nuxeo.ecm.core.api.DocumentModel; 026import org.nuxeo.ecm.core.api.NuxeoException; 027import org.nuxeo.ecm.core.api.thumbnail.ThumbnailFactory; 028import org.nuxeo.ecm.platform.picture.api.adapters.PictureResourceAdapter; 029import org.nuxeo.ecm.platform.types.adapter.TypeInfo; 030 031import java.io.File; 032import java.io.IOException; 033 034import static org.nuxeo.ecm.platform.threed.ThreeDConstants.THREED_FACET; 035import static org.nuxeo.ecm.platform.threed.ThreeDConstants.THUMBNAIL_PICTURE_TITLE; 036import static org.nuxeo.ecm.platform.threed.ThreeDDocumentConstants.RENDER_VIEWS_PROPERTY; 037 038/** 039 * 3D content thumbnail factory 040 * 041 * @since 8.4 042 */ 043public class ThumbnailThreeDFactory implements ThumbnailFactory { 044 045 @Override 046 public Blob getThumbnail(DocumentModel documentModel, CoreSession coreSession) { 047 if (!documentModel.hasFacet(THREED_FACET)) { 048 throw new NuxeoException("Document is not 3D"); 049 } 050 Blob thumbnailBlob = (Blob) documentModel.getPropertyValue(RENDER_VIEWS_PROPERTY + "/0/thumbnail"); 051 052 if (thumbnailBlob == null) { 053 // do default 054 TypeInfo docType = documentModel.getAdapter(TypeInfo.class); 055 try { 056 return Blobs.createBlob( 057 FileUtils.getResourceFileFromContext("nuxeo.war" + File.separator + docType.getBigIcon())); 058 } catch (IOException e) { 059 throw new NuxeoException(e); 060 } 061 } 062 return thumbnailBlob; 063 } 064 065 @Override 066 public Blob computeThumbnail(DocumentModel documentModel, CoreSession coreSession) { 067 return null; 068 } 069 070}