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; 020 021import org.nuxeo.ecm.core.api.Blob; 022 023import java.io.Serializable; 024import java.util.HashMap; 025import java.util.List; 026import java.util.Map; 027 028import static java.lang.Math.abs; 029 030/** 031 * Object wrapping a transmission format with {@link ThreeD} and LoD details 032 * 033 * @since 8.4 034 */ 035public class TransmissionThreeD extends ThreeD { 036 037 public static final String NAME = "name"; 038 039 public static final String CONTENT = "content"; 040 041 public static final String PERC_POLY = "percPoly"; 042 043 public static final String MAX_POLY = "maxPoly"; 044 045 public static final String PERC_TEX = "percTex"; 046 047 public static final String MAX_TEX = "maxTex"; 048 049 public static final String INFO = "info"; 050 051 protected final Integer percPoly; 052 053 protected final Long maxPoly; 054 055 protected final Integer percTex; 056 057 protected final String maxTex; 058 059 protected final String name; 060 061 public TransmissionThreeD(Blob blob, List<Blob> resources, ThreeDInfo info, Integer percPoly, Long maxPoly, 062 Integer percTex, String maxTex, String name) { 063 super(blob, resources, info); 064 this.percPoly = percPoly; 065 this.maxPoly = maxPoly; 066 this.percTex = percTex; 067 this.maxTex = maxTex; 068 this.name = name; 069 } 070 071 public TransmissionThreeD(Map<String, Serializable> map) { 072 super((Blob) map.get(CONTENT), null, 073 (map.get(INFO) != null) ? new ThreeDInfo((Map<String, Serializable>) map.get(INFO)) : null); 074 name = (String) map.get(NAME); 075 Long percPolyLong = (Long) map.get(PERC_POLY); 076 percPoly = (percPolyLong != null) ? percPolyLong.intValue() : null; 077 Long maxPolyLong = (Long) map.get(MAX_POLY); 078 maxPoly = (maxPolyLong != null) ? maxPolyLong : null; 079 Long percTexLong = (Long) map.get(PERC_POLY); 080 percTex = (percTexLong != null) ? percTexLong.intValue() : null; 081 maxTex = (String) map.get(MAX_TEX); 082 } 083 084 public String getTitle() { 085 return name; 086 } 087 088 public Integer getPercPoly() { 089 return percPoly; 090 } 091 092 public Long getMaxPoly() { 093 return maxPoly; 094 } 095 096 public Integer getPercTex() { 097 return percTex; 098 } 099 100 public String getMaxTex() { 101 return maxTex; 102 } 103 104 public String getName() { 105 return name; 106 } 107 108 public String getId() { 109 return String.valueOf(abs(name.hashCode())); 110 } 111 112 public Map<String, Serializable> toMap() { 113 Map<String, Serializable> map = new HashMap<>(); 114 map.put(NAME, name); 115 map.put(CONTENT, (Serializable) blob); 116 map.put(PERC_POLY, percPoly); 117 map.put(MAX_POLY, maxPoly); 118 map.put(PERC_TEX, percTex); 119 map.put(MAX_TEX, maxTex); 120 map.put(INFO, (info != null) ? (Serializable) info.toMap() : null); 121 return map; 122 } 123}