use of org.alfresco.rest.api.model.Rendition in project alfresco-remote-api by Alfresco.
the class TestPeople method createAvatarDirect.
private NodeRef createAvatarDirect(NodeRef personRef, File avatarFile) {
// create new avatar node
nodeService.addAspect(personRef, ContentModel.ASPECT_PREFERENCES, null);
ChildAssociationRef assoc = nodeService.createNode(personRef, ContentModel.ASSOC_PREFERENCE_IMAGE, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "origAvatar"), ContentModel.TYPE_CONTENT);
final NodeRef avatarRef = assoc.getChildRef();
// JSF client compatibility?
nodeService.createAssociation(personRef, avatarRef, ContentModel.ASSOC_AVATAR);
// upload the avatar content
ContentService contentService = applicationContext.getBean("ContentService", ContentService.class);
ContentWriter writer = contentService.getWriter(avatarRef, ContentModel.PROP_CONTENT, true);
writer.guessMimetype(avatarFile.getName());
writer.putContent(avatarFile);
Rendition avatarR = new Rendition();
avatarR.setId("avatar");
Renditions renditions = applicationContext.getBean("Renditions", Renditions.class);
renditions.createRendition(avatarRef, avatarR, false, null);
return avatarRef;
}
use of org.alfresco.rest.api.model.Rendition in project alfresco-remote-api by Alfresco.
the class RenditionsImpl method toApiRendition.
protected Rendition toApiRendition(NodeRef renditionNodeRef) {
Rendition apiRendition = new Rendition();
String renditionName = (String) nodeService.getProperty(renditionNodeRef, ContentModel.PROP_NAME);
apiRendition.setId(renditionName);
ContentData contentData = getContentData(renditionNodeRef, false);
ContentInfo contentInfo = null;
if (contentData != null) {
contentInfo = new ContentInfo(contentData.getMimetype(), getMimeTypeDisplayName(contentData.getMimetype()), contentData.getSize(), contentData.getEncoding());
}
apiRendition.setContent(contentInfo);
apiRendition.setStatus(RenditionStatus.CREATED);
return apiRendition;
}
use of org.alfresco.rest.api.model.Rendition in project alfresco-remote-api by Alfresco.
the class RenditionsImpl method getRenditions.
@Override
public CollectionWithPagingInfo<Rendition> getRenditions(NodeRef nodeRef, Parameters parameters) {
final NodeRef validatedNodeRef = validateNode(nodeRef.getStoreRef(), nodeRef.getId());
String contentMimeType = getMimeType(validatedNodeRef);
Query query = parameters.getQuery();
boolean includeCreated = true;
boolean includeNotCreated = true;
String status = getStatus(parameters);
if (status != null) {
includeCreated = RenditionStatus.CREATED.equals(RenditionStatus.valueOf(status));
includeNotCreated = !includeCreated;
}
Map<String, Rendition> apiRenditions = new TreeMap<>();
if (includeNotCreated) {
// List all available thumbnail definitions
List<ThumbnailDefinition> thumbnailDefinitions = thumbnailService.getThumbnailRegistry().getThumbnailDefinitions(contentMimeType, -1);
for (ThumbnailDefinition thumbnailDefinition : thumbnailDefinitions) {
apiRenditions.put(thumbnailDefinition.getName(), toApiRendition(thumbnailDefinition));
}
}
List<ChildAssociationRef> nodeRefRenditions = renditionService.getRenditions(validatedNodeRef);
if (!nodeRefRenditions.isEmpty()) {
for (ChildAssociationRef childAssociationRef : nodeRefRenditions) {
NodeRef renditionNodeRef = childAssociationRef.getChildRef();
Rendition apiRendition = toApiRendition(renditionNodeRef);
if (includeCreated) {
// Replace/append any thumbnail definitions with created rendition info
apiRenditions.put(apiRendition.getId(), apiRendition);
} else {
// Remove any thumbnail definitions that has been created from the list,
// as the filter requires only the Not_Created renditions
apiRenditions.remove(apiRendition.getId());
}
}
}
// 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.rest.api.model.Rendition in project alfresco-remote-api by Alfresco.
the class DeletedNodesImpl method getRendition.
@Override
public Rendition getRendition(String archivedId, String renditionId, Parameters parameters) {
NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, archivedId);
Rendition rendition = renditions.getRendition(nodeRef, renditionId, parameters);
return rendition;
}
use of org.alfresco.rest.api.model.Rendition in project alfresco-remote-api by Alfresco.
the class PeopleImpl method uploadAvatarContent.
@Override
public Person uploadAvatarContent(String personId, BasicContentInfo contentInfo, InputStream stream, Parameters parameters) {
if (!thumbnailService.getThumbnailsEnabled()) {
throw new DisabledServiceException("Thumbnail generation has been disabled.");
}
personId = validatePerson(personId);
checkCurrentUserOrAdmin(personId);
NodeRef personNode = personService.getPerson(personId);
NodeRef avatarOrigNodeRef = getAvatarOriginal(personNode);
if (avatarOrigNodeRef != null) {
deleteAvatar(avatarOrigNodeRef);
}
QName origAvatarQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "origAvatar");
nodeService.addAspect(personNode, ContentModel.ASPECT_PREFERENCES, null);
ChildAssociationRef assoc = nodeService.createNode(personNode, ContentModel.ASSOC_PREFERENCE_IMAGE, origAvatarQName, ContentModel.TYPE_CONTENT);
NodeRef avatar = assoc.getChildRef();
String avatarOriginalNodeId = avatar.getId();
// TODO do we still need this ? - backward compatible with JSF web-client avatar
nodeService.createAssociation(personNode, avatar, ContentModel.ASSOC_AVATAR);
Node n = nodes.updateContent(avatarOriginalNodeId, contentInfo, stream, parameters);
String mimeType = n.getContent().getMimeType();
if (mimeType.indexOf("image/") != 0) {
throw new InvalidArgumentException("Uploaded content must be an image (content type determined to be '" + mimeType + "')");
}
// create thumbnail synchronously
Rendition avatarR = new Rendition();
avatarR.setId("avatar");
renditions.createRendition(avatar, avatarR, false, parameters);
List<String> include = Arrays.asList(PARAM_INCLUDE_ASPECTNAMES, PARAM_INCLUDE_PROPERTIES);
return getPersonWithProperties(personId, include);
}
Aggregations