use of org.alfresco.service.cmr.repository.ContentData in project acs-community-packaging by Alfresco.
the class EditContentPropertiesDialog method formatErrorMessage.
/**
* Formats the error message to display if an error occurs during finish processing
*
* @param exception The exception
* @return The formatted message
*/
@Override
protected String formatErrorMessage(Throwable exception) {
if (editableNode != null) {
// special case for Mimetype - since this is a sub-property of the ContentData object
// we must extract it so it can be edited in the client, then we check for it later
// and create a new ContentData object to wrap it and it's associated URL
ContentData content = (ContentData) this.editableNode.getProperties().get(ContentModel.PROP_CONTENT);
if (content != null) {
this.editableNode.getProperties().put(TEMP_PROP_MIMETYPE, content.getMimetype());
this.editableNode.getProperties().put(TEMP_PROP_ENCODING, content.getEncoding());
}
}
if (exception instanceof FileExistsException) {
return MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_EXISTS), ((FileExistsException) exception).getName());
} else if (exception instanceof InvalidNodeRefException) {
return MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { this.browseBean.getDocument().getId() });
} else {
return super.formatErrorMessage(exception);
}
}
use of org.alfresco.service.cmr.repository.ContentData in project acs-community-packaging by Alfresco.
the class EditContentPropertiesDialog method init.
// ------------------------------------------------------------------------------
// Dialog implementation
@Override
public void init(Map<String, String> parameters) {
super.init(parameters);
// setup the editable node
this.editableNode = initEditableNode();
if (editableNode != null) {
// special case for Mimetype - since this is a sub-property of the ContentData object
// we must extract it so it can be edited in the client, then we check for it later
// and create a new ContentData object to wrap it and it's associated URL
ContentData content = (ContentData) this.editableNode.getProperties().get(ContentModel.PROP_CONTENT);
if (content != null) {
this.editableNode.getProperties().put(TEMP_PROP_MIMETYPE, content.getMimetype());
this.editableNode.getProperties().put(TEMP_PROP_ENCODING, content.getEncoding());
}
}
}
use of org.alfresco.service.cmr.repository.ContentData in project alfresco-remote-api by Alfresco.
the class PeopleImpl method processPersonProperties.
protected void processPersonProperties(String userName, final Map<QName, Serializable> nodeProps) {
if (!contentUsageService.getEnabled()) {
// quota used will always be 0 in this case so remove from the person properties
nodeProps.remove(ContentModel.PROP_SIZE_QUOTA);
nodeProps.remove(ContentModel.PROP_SIZE_CURRENT);
}
// The person description is located in a separate content file located at cm:persondescription
// "Inline" this data, by removing the cm:persondescription property and adding a temporary property
// (Person.PROP_PERSON_DESCRIPTION) containing the actual content as a string.
final ContentData personDescription = (ContentData) nodeProps.get(ContentModel.PROP_PERSONDESC);
if (personDescription != null) {
nodeProps.remove(ContentModel.PROP_PERSONDESC);
AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
ContentReader reader = contentService.getRawReader(personDescription.getContentUrl());
if (reader != null && reader.exists()) {
String description = reader.getContentString();
nodeProps.put(Person.PROP_PERSON_DESCRIPTION, description);
}
return null;
}
});
}
}
use of org.alfresco.service.cmr.repository.ContentData in project alfresco-remote-api by Alfresco.
the class QuickShareLinksImpl method getQuickShareInfo.
private QuickShareLink getQuickShareInfo(NodeRef nodeRef, Map<String, Object> map, boolean noAuth, List<String> includeParam) {
String sharedId = (String) map.get("sharedId");
try {
Map<QName, Serializable> nodeProps = nodeService.getProperties(nodeRef);
ContentData cd = (ContentData) nodeProps.get(ContentModel.PROP_CONTENT);
String mimeType = cd.getMimetype();
String mimeTypeName = mimeTypeService.getDisplaysByMimetype().get(mimeType);
ContentInfo contentInfo = new ContentInfo(mimeType, mimeTypeName, cd.getSize(), cd.getEncoding());
Map<String, UserInfo> mapUserInfo = new HashMap<>(2);
// note: if noAuth mode then don't return userids (to limit disclosure and be consistent with v0 internal)
boolean displayNameOnly = noAuth;
UserInfo modifiedByUser = Node.lookupUserInfo((String) nodeProps.get(ContentModel.PROP_MODIFIER), mapUserInfo, personService, displayNameOnly);
// TODO review - should we return sharedByUser for authenticated users only ?? (not exposed by V0 but needed for "find")
String sharedByUserId = (String) nodeProps.get(QuickShareModel.PROP_QSHARE_SHAREDBY);
UserInfo sharedByUser = Node.lookupUserInfo(sharedByUserId, mapUserInfo, personService, displayNameOnly);
QuickShareLink qs = new QuickShareLink(sharedId, nodeRef.getId());
qs.setName((String) map.get("name"));
qs.setTitle((String) map.get("title"));
qs.setDescription((String) map.get("description"));
qs.setContent(contentInfo);
qs.setModifiedAt((Date) map.get("modified"));
qs.setModifiedByUser(modifiedByUser);
qs.setSharedByUser(sharedByUser);
qs.setExpiresAt((Date) map.get("expiryDate"));
// note: if noAuth mode then do not return allowable operations (eg. but can be optionally returned when finding shared links)
if (!noAuth) {
if (includeParam.contains(PARAM_INCLUDE_ALLOWABLEOPERATIONS)) {
if (quickShareService.canDeleteSharedLink(nodeRef, sharedByUserId)) {
// the allowable operations for the shared link
qs.setAllowableOperations(Collections.singletonList(Nodes.OP_DELETE));
}
Node doc = nodes.getFolderOrDocument(nodeRef, null, null, includeParam, null);
List<String> allowableOps = doc.getAllowableOperations();
// the allowable operations for the actual file being shared
qs.setAllowableOperationsOnTarget(allowableOps);
}
// in noAuth mode we don't return the path info
if (includeParam.contains(PARAM_INCLUDE_PATH)) {
qs.setPath(nodes.lookupPathInfo(nodeRef, null));
}
}
return qs;
} catch (InvalidSharedIdException ex) {
logger.warn("Unable to find: " + sharedId);
throw new EntityNotFoundException(sharedId);
} catch (InvalidNodeRefException inre) {
logger.warn("Unable to find: " + sharedId + " [" + inre.getNodeRef() + "]");
throw new EntityNotFoundException(sharedId);
}
}
use of org.alfresco.service.cmr.repository.ContentData in project alfresco-remote-api by Alfresco.
the class RenditionsImpl method createRendition.
@Override
public void createRendition(NodeRef nodeRef, Rendition rendition, boolean executeAsync, Parameters parameters) {
// If thumbnail generation has been configured off, then don't bother.
if (!thumbnailService.getThumbnailsEnabled()) {
throw new DisabledServiceException("Thumbnail generation has been disabled.");
}
final NodeRef sourceNodeRef = validateNode(nodeRef.getStoreRef(), nodeRef.getId());
final NodeRef renditionNodeRef = getRenditionByName(sourceNodeRef, rendition.getId(), parameters);
if (renditionNodeRef != null) {
throw new ConstraintViolatedException(rendition.getId() + " rendition already exists.");
}
// Use the thumbnail registry to get the details of the thumbnail
ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
ThumbnailDefinition thumbnailDefinition = registry.getThumbnailDefinition(rendition.getId());
if (thumbnailDefinition == null) {
throw new NotFoundException(rendition.getId() + " is not registered.");
}
ContentData contentData = getContentData(sourceNodeRef, true);
// Check if anything is currently available to generate thumbnails for the specified mimeType
if (!registry.isThumbnailDefinitionAvailable(contentData.getContentUrl(), contentData.getMimetype(), contentData.getSize(), sourceNodeRef, thumbnailDefinition)) {
throw new InvalidArgumentException("Unable to create thumbnail '" + thumbnailDefinition.getName() + "' for " + contentData.getMimetype() + " as no transformer is currently available.");
}
Action action = ThumbnailHelper.createCreateThumbnailAction(thumbnailDefinition, serviceRegistry);
// Create thumbnail - or else queue for async creation
actionService.executeAction(action, sourceNodeRef, true, executeAsync);
}
Aggregations