use of org.alfresco.service.cmr.repository.TransformationOptions in project alfresco-repository by Alfresco.
the class TransformActionExecuter method doTransform.
/**
* Executed in a new transaction so that failures don't cause the entire transaction to rollback.
*/
protected void doTransform(Action ruleAction, NodeRef sourceNodeRef, ContentReader contentReader, NodeRef destinationNodeRef, ContentWriter contentWriter) {
// transform - will throw NoTransformerException if there are no transformers
TransformationOptions transformationOptions = newTransformationOptions(ruleAction, sourceNodeRef);
transformationOptions.setTargetNodeRef(destinationNodeRef);
String sourceMimetype = contentReader.getMimetype();
Map<String, String> options = converter.getOptions(transformationOptions, sourceMimetype, contentWriter.getMimetype());
synchronousTransformClient.transform(contentReader, contentWriter, options, null, sourceNodeRef);
}
use of org.alfresco.service.cmr.repository.TransformationOptions in project alfresco-repository by Alfresco.
the class LegacyTransformClient method transform.
@Override
public void transform(NodeRef sourceNodeRef, RenditionDefinition2 renditionDefinition, String user, int sourceContentHashCode) {
String targetMimetype = renditionDefinition.getTargetMimetype();
String renditionName = renditionDefinition.getRenditionName();
Map<String, String> actualOptions = renditionDefinition.getTransformOptions();
TransformationOptions options = converter.getTransformationOptions(renditionName, actualOptions);
options.setSourceNodeRef(sourceNodeRef);
ContentTransformer legacyTransform = transform.get();
executorService.submit(() -> {
AuthenticationUtil.runAs((AuthenticationUtil.RunAsWork<Void>) () -> transactionService.getRetryingTransactionHelper().doInTransaction(() -> {
try {
if (legacyTransform == 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);
}
// Note: we don't call legacyTransform.transform(reader, writer, options) as the Legacy
// transforms (unlike Local and Transform Service) automatically fail over to the next
// highest priority. This was not done for the newer transforms, as a fail over can always be
// defined and that makes it simpler to understand what is going on.
ContentWriter writer = contentService.getTempWriter();
writer.setMimetype(targetMimetype);
legacySynchronousTransformClient.transform(reader, writer, options);
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);
});
}
use of org.alfresco.service.cmr.repository.TransformationOptions in project alfresco-repository by Alfresco.
the class LegacyTransformClient 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> options = renditionDefinition.getTransformOptions();
TransformationOptions transformationOptions = converter.getTransformationOptions(renditionName, options);
transformationOptions.setSourceNodeRef(sourceNodeRef);
ContentTransformer legacyTransform = legacySynchronousTransformClient.getTransformer(contentUrl, sourceMimetype, sourceSizeInBytes, targetMimetype, transformationOptions);
transform.set(legacyTransform);
String message = TRANSFORM + renditionName + " from " + sourceMimetype + (legacyTransform == null ? " is unsupported" : " is supported");
logger.debug(message);
if (legacyTransform == null) {
throw new UnsupportedOperationException(message);
}
}
use of org.alfresco.service.cmr.repository.TransformationOptions in project alfresco-repository by Alfresco.
the class LegacyTransformerDebug method availableTransformers.
/**
* Called once all available transformers have been identified.
*/
@Deprecated
public void availableTransformers(List<ContentTransformer> transformers, long sourceSize, String renditionName, NodeRef sourceNodeRef, String calledFrom) {
if (isEnabled()) {
Deque<Frame> ourStack = ThreadInfo.getStack();
Frame frame = ourStack.peek();
boolean firstLevel = ourStack.size() == 1;
// Note once turned on we don't turn it off again.
if (transformers.size() == 0) {
frame.setFailureReason(NO_TRANSFORMERS);
if (frame.unavailableTransformers != null && frame.unavailableTransformers.size() != 0) {
ThreadInfo.setDebugOutput(true);
}
}
frame.setSourceSize(sourceSize);
// Log the basic info about this transformation
logBasicDetails(frame, sourceSize, null, renditionName, calledFrom + ((transformers.size() == 0) ? " NO transformers" : ""), firstLevel);
// Report available and unavailable transformers
char c = 'a';
int longestNameLength = getLongestTransformerNameLength(transformers, frame);
for (ContentTransformer trans : transformers) {
String name = getName(trans);
int padName = longestNameLength - name.length() + 1;
TransformationOptions options = new TransformationOptions();
options.setUse(frame.renditionName);
options.setSourceNodeRef(frame.sourceNodeRef);
long maxSourceSizeKBytes = trans.getMaxSourceSizeKBytes(frame.sourceMimetype, frame.targetMimetype, options);
String size = maxSourceSizeKBytes > 0 ? "< " + fileSize(maxSourceSizeKBytes * 1024) : "";
int padSize = 10 - size.length();
String priority = gePriority(trans, frame.sourceMimetype, frame.targetMimetype);
log((c == 'a' ? "**" : " ") + (c++) + ") " + priority + ' ' + name + spaces(padName) + size + spaces(padSize) + ms(trans.getTransformationTime(frame.sourceMimetype, frame.targetMimetype)));
}
if (frame.unavailableTransformers != null) {
for (UnavailableTransformer unavailable : frame.unavailableTransformers) {
int pad = longestNameLength - unavailable.name.length();
String reason = "> " + fileSize(unavailable.maxSourceSizeKBytes * 1024);
if (unavailable.debug || logger.isTraceEnabled()) {
log("--" + (c++) + ") " + unavailable.priority + ' ' + unavailable.name + spaces(pad + 1) + reason, unavailable.debug);
}
}
}
}
}
use of org.alfresco.service.cmr.repository.TransformationOptions in project alfresco-repository by Alfresco.
the class LegacyTransformerDebug method transformationsByExtension.
/**
* Returns a String and /or debug that provides a list of supported transformations
* sorted by source and target mimetype extension.
* @param sourceExtension restricts the list to one source extension. Unrestricted if null.
* @param targetExtension restricts the list to one target extension. Unrestricted if null.
* @param toString indicates that a String value should be returned in addition to any debug.
* @param format42 indicates the new 4.2 rather than older 4.1.4 format should be used.
* The 4.1.4 format did not order the transformers or mimetypes and only included top
* level transformers.
* @param onlyNonDeterministic if true only report transformations where there is more than
* one transformer available with the same priority.
* @param renditionName to which the transformation will be put (such as "Index", "Preview", null).
* @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
*/
@Deprecated
@Override
public String transformationsByExtension(String sourceExtension, String targetExtension, boolean toString, boolean format42, boolean onlyNonDeterministic, String renditionName) {
// (for example a test transform).
if (getStringBuilder() != null) {
return null;
}
Collection<ContentTransformer> transformers = format42 && !onlyNonDeterministic ? sortTransformersByName(null) : transformerRegistry.getTransformers();
Collection<String> sourceMimetypes = format42 || sourceExtension != null ? getSourceMimetypes(sourceExtension) : mimetypeService.getMimetypes();
Collection<String> targetMimetypes = format42 || targetExtension != null ? getTargetMimetypes(sourceExtension, targetExtension, sourceMimetypes) : mimetypeService.getMimetypes();
TransformationOptions options = new TransformationOptions();
options.setUse(renditionName);
StringBuilder sb = null;
try {
if (toString) {
sb = new StringBuilder();
setStringBuilder(sb);
}
pushMisc();
for (String sourceMimetype : sourceMimetypes) {
for (String targetMimetype : targetMimetypes) {
// Find available transformers
List<ContentTransformer> availableTransformer = new ArrayList<ContentTransformer>();
for (ContentTransformer transformer : transformers) {
if (transformer.isTransformable(sourceMimetype, -1, targetMimetype, options)) {
availableTransformer.add(transformer);
}
}
// Sort by priority
final String currSourceMimetype = sourceExtension;
final String currTargetMimetype = targetExtension;
Collections.sort(availableTransformer, new Comparator<ContentTransformer>() {
@Override
public int compare(ContentTransformer transformer1, ContentTransformer transformer2) {
return transformerConfig.getPriority(transformer1, currSourceMimetype, currTargetMimetype) - transformerConfig.getPriority(transformer2, currSourceMimetype, currTargetMimetype);
}
});
// Do we need to produce any output?
int size = availableTransformer.size();
int priority = size >= 2 ? transformerConfig.getPriority(availableTransformer.get(0), sourceMimetype, targetMimetype) : -1;
if (!onlyNonDeterministic || (size >= 2 && priority == transformerConfig.getPriority(availableTransformer.get(1), sourceMimetype, targetMimetype))) {
// Log the transformers
boolean supportedByTransformService = remoteTransformServiceRegistry == null || remoteTransformServiceRegistry instanceof DummyTransformServiceRegistry ? false : remoteTransformServiceRegistry.isSupported(sourceMimetype, -1, targetMimetype, Collections.emptyMap(), null);
List<SupportedTransform> localTransformers = localTransformServiceRegistryImpl == null ? Collections.emptyList() : localTransformServiceRegistryImpl.findTransformers(sourceMimetype, targetMimetype, Collections.emptyMap(), null);
if (!localTransformers.isEmpty() || supportedByTransformService || size >= 1) {
try {
pushMisc();
int transformerCount = 0;
if (supportedByTransformService) {
long maxSourceSizeKBytes = remoteTransformServiceRegistry.findMaxSize(sourceMimetype, targetMimetype, Collections.emptyMap(), null);
activeTransformer(sourceMimetype, targetMimetype, transformerCount, " ", TRANSFORM_SERVICE_NAME, maxSourceSizeKBytes, transformerCount++ == 0);
}
for (SupportedTransform localTransformer : localTransformers) {
long maxSourceSizeKBytes = localTransformer.getMaxSourceSizeBytes();
String transformName = "Local:" + localTransformer.getName();
String transformerPriority = "[" + localTransformer.getPriority() + ']';
transformerPriority = spaces(5 - transformerPriority.length()) + transformerPriority;
activeTransformer(sourceMimetype, targetMimetype, transformerCount, transformerPriority, transformName, maxSourceSizeKBytes, transformerCount++ == 0);
}
for (ContentTransformer transformer : availableTransformer) {
if (!onlyNonDeterministic || transformerCount < 2 || priority == transformerConfig.getPriority(transformer, sourceMimetype, targetMimetype)) {
long maxSourceSizeKBytes = transformer.getMaxSourceSizeKBytes(sourceMimetype, targetMimetype, options);
activeTransformer(sourceMimetype, targetMimetype, transformerCount, transformer, maxSourceSizeKBytes, transformerCount++ == 0);
}
}
} finally {
popMisc();
}
}
}
}
}
} finally {
popMisc();
setStringBuilder(null);
}
stripFinishedLine(sb);
return stripLeadingNumber(sb);
}
Aggregations