use of org.alfresco.repo.rendition2.RenditionDefinitionRegistry2 in project alfresco-remote-api by Alfresco.
the class RenditionsImpl method createRenditions.
@Override
public void createRenditions(NodeRef nodeRef, String versionLabelId, List<Rendition> renditions, Parameters parameters) throws NotFoundException, ConstraintViolatedException {
if (renditions.isEmpty()) {
return;
}
if (!renditionService2.isEnabled()) {
throw new DisabledServiceException("Rendition generation has been disabled.");
}
final NodeRef sourceNodeRef = validateNode(nodeRef.getStoreRef(), nodeRef.getId(), versionLabelId, parameters);
RenditionDefinitionRegistry2 renditionDefinitionRegistry2 = renditionService2.getRenditionDefinitionRegistry2();
// So that POST /nodes/{nodeId}/renditions can specify rendition names as a comma separated list just like
// POST /nodes/{nodId}/children can specify a comma separated list, the following code checks to see if the
// supplied Rendition names are actually comma separated lists. The following example shows it is possible to
// use both approaches.
// [
// { "id": "doclib" },
// { "id": "avatar,avatar32" }
// ]
Set<String> renditionNames = new HashSet<>();
for (Rendition rendition : renditions) {
String name = getName(rendition);
Set<String> requestedRenditions = NodesImpl.getRequestedRenditions(name);
if (requestedRenditions == null) {
renditionNames.add(null);
} else {
renditionNames.addAll(requestedRenditions);
}
}
StringJoiner renditionNamesAlreadyExist = new StringJoiner(",");
StringJoiner renditionNamesNotRegistered = new StringJoiner(",");
List<String> renditionNamesToCreate = new ArrayList<>();
for (String renditionName : renditionNames) {
if (renditionName == null) {
// 400
throw new IllegalArgumentException(("Null rendition name supplied"));
}
RenditionDefinition2 renditionDefinition = renditionDefinitionRegistry2.getRenditionDefinition(renditionName);
if (renditionDefinition == null) {
renditionNamesNotRegistered.add(renditionName);
}
final NodeRef renditionNodeRef = getRenditionByName(sourceNodeRef, renditionName, parameters);
if (renditionNodeRef == null) {
renditionNamesToCreate.add(renditionName);
} else {
renditionNamesAlreadyExist.add(renditionName);
}
}
if (renditionNamesNotRegistered.length() != 0) {
// 404
throw new NotFoundException("Renditions not registered: " + renditionNamesNotRegistered);
}
if (renditionNamesToCreate.size() == 0) {
// 409
throw new ConstraintViolatedException("All renditions requested already exist: " + renditionNamesAlreadyExist);
}
for (String renditionName : renditionNamesToCreate) {
try {
renditionService2.render(sourceNodeRef, renditionName);
} catch (UnsupportedOperationException e) {
// 400
throw new IllegalArgumentException((e.getMessage()));
} catch (IllegalStateException e) {
// 409
throw new StaleEntityException(e.getMessage());
}
}
}
use of org.alfresco.repo.rendition2.RenditionDefinitionRegistry2 in project alfresco-remote-api by Alfresco.
the class RenditionsImpl method toApiRendition.
protected Rendition toApiRendition(String renditionName) {
RenditionDefinitionRegistry2 renditionDefinitionRegistry2 = renditionService2.getRenditionDefinitionRegistry2();
RenditionDefinition2 renditionDefinition = renditionDefinitionRegistry2.getRenditionDefinition(renditionName);
ContentInfo contentInfo = new ContentInfo(renditionDefinition.getTargetMimetype(), getMimeTypeDisplayName(renditionDefinition.getTargetMimetype()), null, null);
Rendition apiRendition = new Rendition();
apiRendition.setId(renditionName);
apiRendition.setContent(contentInfo);
apiRendition.setStatus(RenditionStatus.NOT_CREATED);
return apiRendition;
}
use of org.alfresco.repo.rendition2.RenditionDefinitionRegistry2 in project alfresco-remote-api by Alfresco.
the class RenditionsImpl method getRendition.
@Override
public Rendition getRendition(NodeRef nodeRef, String versionLabelId, String renditionId, Parameters parameters) {
final NodeRef validatedNodeRef = validateNode(nodeRef.getStoreRef(), nodeRef.getId(), versionLabelId, parameters);
NodeRef renditionNodeRef = getRenditionByName(validatedNodeRef, renditionId, parameters);
boolean includeNotCreated = true;
String status = getStatus(parameters);
if (status != null) {
includeNotCreated = !RenditionStatus.CREATED.equals(RenditionStatus.valueOf(status));
}
// if there is no rendition, then try to find the available/registered rendition (yet to be created).
if (renditionNodeRef == null && includeNotCreated) {
ContentData contentData = getContentData(validatedNodeRef, true);
String sourceMimetype = contentData.getMimetype();
long size = contentData.getSize();
RenditionDefinitionRegistry2 renditionDefinitionRegistry2 = renditionService2.getRenditionDefinitionRegistry2();
RenditionDefinition2 renditionDefinition = renditionDefinitionRegistry2.getRenditionDefinition(renditionId);
if (renditionDefinition == null) {
throw new NotFoundException(renditionId + " is not registered.");
} else {
Set<String> renditionNames = renditionDefinitionRegistry2.getRenditionNamesFrom(sourceMimetype, size);
boolean found = false;
for (String renditionName : renditionNames) {
// Check the registered renditionId is applicable for the node's mimeType
if (renditionId.equals(renditionName)) {
found = true;
break;
}
}
if (!found) {
throw new NotFoundException(renditionId + " is not applicable for the node's mimeType " + sourceMimetype);
}
}
return toApiRendition(renditionId);
}
if (renditionNodeRef == null) {
throw new NotFoundException("The rendition with id: " + renditionId + " was not found.");
}
return toApiRendition(renditionNodeRef);
}
use of org.alfresco.repo.rendition2.RenditionDefinitionRegistry2 in project alfresco-remote-api by Alfresco.
the class RenditionsImpl method getRenditions.
@Override
public CollectionWithPagingInfo<Rendition> getRenditions(NodeRef nodeRef, String versionLabelId, Parameters parameters) {
final NodeRef validatedNodeRef = validateNode(nodeRef.getStoreRef(), nodeRef.getId(), versionLabelId, parameters);
ContentData contentData = getContentData(validatedNodeRef, true);
String sourceMimetype = contentData.getMimetype();
boolean includeCreated = true;
boolean includeNotCreated = true;
String status = getStatus(parameters);
if (status != null) {
includeCreated = RenditionStatus.CREATED.equals(RenditionStatus.valueOf(status));
includeNotCreated = !includeCreated;
}
// List all available rendition definitions
long size = contentData.getSize();
RenditionDefinitionRegistry2 renditionDefinitionRegistry2 = renditionService2.getRenditionDefinitionRegistry2();
Set<String> renditionNames = renditionDefinitionRegistry2.getRenditionNamesFrom(sourceMimetype, size);
Map<String, Rendition> apiRenditions = new TreeMap<>();
if (includeNotCreated) {
for (String renditionName : renditionNames) {
apiRenditions.put(renditionName, toApiRendition(renditionName));
}
}
List<ChildAssociationRef> nodeRefRenditions = renditionService2.getRenditions(validatedNodeRef);
if (!nodeRefRenditions.isEmpty()) {
for (ChildAssociationRef childAssociationRef : nodeRefRenditions) {
NodeRef renditionNodeRef = childAssociationRef.getChildRef();
Rendition apiRendition = toApiRendition(renditionNodeRef);
String renditionName = apiRendition.getId();
if (renditionNames.contains(renditionName)) {
if (includeCreated) {
// Replace/append any thumbnail definitions with created rendition info
apiRenditions.put(renditionName, apiRendition);
} else {
// Remove any thumbnail definitions that has been created from the list,
// as the filter requires only the Not_Created renditions
apiRenditions.remove(renditionName);
}
} else {
if (logger.isTraceEnabled()) {
logger.trace("Skip unknown rendition [" + renditionName + ", " + renditionNodeRef + "]");
}
}
}
}
// Wrap paging info, as the core service doesn't support paging
Paging paging = parameters.getPaging();
PagingResults<Rendition> results = Util.wrapPagingResults(paging, apiRenditions.values());
return CollectionWithPagingInfo.asPaged(paging, results.getPage(), results.hasMoreItems(), results.getTotalResultCount().getFirst());
}
use of org.alfresco.repo.rendition2.RenditionDefinitionRegistry2 in project alfresco-remote-api by Alfresco.
the class NodesImpl method requestRenditions.
private void requestRenditions(Set<String> renditionNames, Node fileNode) {
if (renditionNames != null) {
NodeRef sourceNodeRef = fileNode.getNodeRef();
String mimeType = fileNode.getContent().getMimeType();
long size = fileNode.getContent().getSizeInBytes();
RenditionDefinitionRegistry2 renditionDefinitionRegistry2 = renditionService2.getRenditionDefinitionRegistry2();
Set<String> availableRenditions = renditionDefinitionRegistry2.getRenditionNamesFrom(mimeType, size);
for (String renditionName : renditionNames) {
// RA-1052 (REPO-47)
try {
// File may be to big
if (!availableRenditions.contains(renditionName)) {
throw new InvalidArgumentException("Unable to create thumbnail '" + renditionName + "' for " + mimeType + " as no transformer is currently available.");
}
renditionService2.render(sourceNodeRef, renditionName);
} catch (Exception ex) {
// Note: The log level is not 'error' as it could easily fill out the log file.
if (logger.isDebugEnabled()) {
// Don't throw the exception as we don't want the the upload to fail, just log it.
logger.debug("Asynchronous request to create a rendition upon upload failed: " + ex.getMessage());
}
}
}
}
}
Aggregations