use of org.alfresco.repo.content.transform.LocalTransform in project alfresco-repository by Alfresco.
the class LocalSynchronousTransformClient method isSupported.
@Override
public boolean isSupported(String sourceMimetype, long sourceSizeInBytes, String contentUrl, String targetMimetype, Map<String, String> actualOptions, String transformName, NodeRef sourceNodeRef) {
String renditionName = TransformDefinition.convertToRenditionName(transformName);
LocalTransform transform = localTransformServiceRegistry.getLocalTransform(sourceMimetype, sourceSizeInBytes, targetMimetype, actualOptions, renditionName);
if (logger.isDebugEnabled()) {
logger.debug(TRANSFORM + renditionName + " from " + sourceMimetype + (transform == null ? " is unsupported" : " is supported"));
}
return transform != null;
}
use of org.alfresco.repo.content.transform.LocalTransform in project alfresco-repository by Alfresco.
the class LocalSynchronousTransformClient method transform.
@Override
public void transform(ContentReader reader, ContentWriter writer, Map<String, String> actualOptions, String transformName, NodeRef sourceNodeRef) {
String renditionName = TransformDefinition.convertToRenditionName(transformName);
try {
if (reader == null) {
throw new IllegalArgumentException("The content reader must be set");
}
if (!reader.exists()) {
throw new IllegalArgumentException("sourceNodeRef " + sourceNodeRef + " has no content.");
}
String sourceMimetype = reader.getMimetype();
long sourceSizeInBytes = reader.getSize();
if (sourceMimetype == null) {
throw new IllegalArgumentException("The content reader mimetype must be set");
}
String targetMimetype = writer.getMimetype();
if (targetMimetype == null) {
throw new IllegalArgumentException("The content writer mimetype must be set");
}
LocalTransform transform = localTransformServiceRegistry.getLocalTransform(sourceMimetype, sourceSizeInBytes, targetMimetype, actualOptions, renditionName);
if (transform == null) {
throw new UnsupportedTransformationException("Transformation of " + sourceMimetype + (sourceSizeInBytes > 0 ? " size " + sourceSizeInBytes : "") + " to " + targetMimetype + " unsupported");
}
if (logger.isDebugEnabled()) {
logger.debug(TRANSFORM + " requested " + renditionName);
}
transform.transform(reader, writer, actualOptions, renditionName, sourceNodeRef);
if (logger.isDebugEnabled()) {
logger.debug(TRANSFORM + " created " + renditionName);
}
} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug(TRANSFORM + " failed " + renditionName, e);
}
throw e;
}
}
use of org.alfresco.repo.content.transform.LocalTransform in project alfresco-repository by Alfresco.
the class LocalTransformClient method checkSupported.
@Override
public void checkSupported(NodeRef sourceNodeRef, RenditionDefinition2 renditionDefinition, String sourceMimetype, long sourceSizeInBytes, String contentUrl) {
String targetMimetype = renditionDefinition.getTargetMimetype();
String renditionName = renditionDefinition.getRenditionName();
Map<String, String> actualOptions = renditionDefinition.getTransformOptions();
LocalTransform localTransform = localTransformServiceRegistry.getLocalTransform(sourceMimetype, sourceSizeInBytes, targetMimetype, actualOptions, renditionName);
transform.set(localTransform);
String message = TRANSFORM + renditionName + " from " + sourceMimetype + (localTransform == null ? " is unsupported" : " is supported");
logger.debug(message);
if (localTransform == null) {
throw new UnsupportedOperationException(message);
}
}
use of org.alfresco.repo.content.transform.LocalTransform in project alfresco-repository by Alfresco.
the class ContentTransformServiceAdaptor method wrapLocalTransformer.
private ContentTransformer wrapLocalTransformer(String sourceUrl, String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions transformationOptions) {
AbstractContentTransformer2 transformer = null;
Map<String, String> options = converter.getOptions(transformationOptions, null, null);
LocalTransform localTransform = localTransformServiceRegistryImpl.getLocalTransform(sourceMimetype, sourceSize, targetMimetype, options, null);
if (localTransform != null) {
transformer = new AbstractContentTransformer2() {
@Override
public void transform(ContentReader reader, ContentWriter writer, TransformationOptions options) throws ContentIOException {
try {
transformInternal(reader, writer, transformationOptions);
} catch (Exception e) {
throw new ContentIOException(e.getMessage(), e);
}
}
@Override
protected void transformInternal(ContentReader reader, ContentWriter writer, TransformationOptions transformationOptions) throws Exception {
localTransform.transform(reader, writer, options, null, null);
}
@Override
public void register() {
}
@Override
public boolean isSupportedTransformation(String sourceMimetype, String targetMimetype, TransformationOptions options) {
return true;
}
@Override
public boolean isTransformable(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options) {
return true;
}
@Override
public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options) {
return true;
}
@Override
public boolean isTransformableSize(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options) {
return true;
}
@Override
public String getName() {
return "Wrapped<" + localTransformServiceRegistryImpl.findTransformerName(sourceMimetype, sourceSize, targetMimetype, options, null) + ">";
}
};
}
return transformer;
}
use of org.alfresco.repo.content.transform.LocalTransform in project alfresco-repository by Alfresco.
the class LocalTransformClient method transform.
@Override
public void transform(NodeRef sourceNodeRef, RenditionDefinition2 renditionDefinition, String user, int sourceContentHashCode) {
String renditionName = renditionDefinition.getRenditionName();
String targetMimetype = renditionDefinition.getTargetMimetype();
Map<String, String> actualOptions = renditionDefinition.getTransformOptions();
LocalTransform localTransform = transform.get();
executorService.submit(() -> {
AuthenticationUtil.runAs((AuthenticationUtil.RunAsWork<Void>) () -> transactionService.getRetryingTransactionHelper().doInTransaction(() -> {
try {
if (localTransform == null) {
throw new IllegalStateException("isSupported was not called prior to an asynchronous transform.");
}
ContentReader reader = contentService.getReader(sourceNodeRef, ContentModel.PROP_CONTENT);
if (null == reader || !reader.exists()) {
throw new IllegalArgumentException("sourceNodeRef " + sourceNodeRef + " has no content.");
}
if (logger.isDebugEnabled()) {
logger.debug(TRANSFORM + "requested " + renditionName);
}
ContentWriter writer = contentService.getTempWriter();
writer.setMimetype(targetMimetype);
localTransform.transform(reader, writer, actualOptions, renditionName, sourceNodeRef);
InputStream inputStream = writer.getReader().getContentInputStream();
if (logger.isDebugEnabled()) {
logger.debug(TRANSFORM + "to be consumed " + renditionName);
}
renditionService2.consume(sourceNodeRef, inputStream, renditionDefinition, sourceContentHashCode);
if (logger.isDebugEnabled()) {
logger.debug(TRANSFORM + "consumed " + renditionName);
}
} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug(TRANSFORM + "failed " + renditionName, e);
}
if (renditionDefinition instanceof TransformDefinition) {
((TransformDefinition) renditionDefinition).setErrorMessage(e.getMessage());
}
renditionService2.failure(sourceNodeRef, renditionDefinition, sourceContentHashCode);
throw e;
}
return null;
}), user);
});
}
Aggregations