/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see .
*/
package org.alfresco.opencmis;
import java.io.Serializable;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.rendition.executer.ImageRenderingEngine;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.rendition.RenditionDefinition;
import org.alfresco.service.cmr.rendition.RenditionService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.apache.chemistry.opencmis.commons.data.RenditionData;
import org.apache.chemistry.opencmis.commons.exceptions.CmisFilterNotValidException;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.RenditionDataImpl;
public class CMISRenditionMapping
{
private NodeService nodeService;
private ContentService contentService;
private RenditionService renditionService;
private TransactionService transactionService;
private Map> kindToRenditionNames;
private Map renditionNamesToKind;
private Map renditionNameToSize;
public CMISRenditionMapping(NodeService nodeService, ContentService contentService,
RenditionService renditionService, TransactionService transactionService,
Map> renditionKinds)
{
this.nodeService = nodeService;
this.contentService = contentService;
this.renditionService = renditionService;
this.transactionService = transactionService;
if (renditionKinds == null)
{
this.kindToRenditionNames = new HashMap>();
} else
{
this.kindToRenditionNames = renditionKinds;
}
renditionNamesToKind = new HashMap();
for (Entry> entry : renditionKinds.entrySet())
{
for (String renditionName : entry.getValue())
{
renditionNamesToKind.put(renditionName, entry.getKey());
}
}
cacheRenditionSizes();
}
private void cacheRenditionSizes()
{
renditionNameToSize = AuthenticationUtil.runAs(new RunAsWork