use of org.alfresco.service.cmr.quickshare.QuickShareDisabledException in project alfresco-repository by Alfresco.
the class QuickShareServiceImpl method shareContent.
@Override
public QuickShareDTO shareContent(NodeRef nodeRef, Date expiryDate) throws QuickShareDisabledException, InvalidNodeRefException {
checkEnabled();
// Check the node is the correct type
final QName typeQName = nodeService.getType(nodeRef);
if (isSharable(typeQName) == false) {
throw new InvalidNodeRefException(nodeRef);
}
final String sharedId;
// If it is retura dto built from the existing properties.
if (!nodeService.getAspects(nodeRef).contains(QuickShareModel.ASPECT_QSHARE)) {
UUID uuid = UUIDGenerator.getInstance().generateRandomBasedUUID();
// => 22 chars (eg. q3bEKPeDQvmJYgt4hJxOjw)
sharedId = Base64.encodeBase64URLSafeString(uuid.toByteArray());
final Map<QName, Serializable> props = new HashMap<QName, Serializable>(2);
props.put(QuickShareModel.PROP_QSHARE_SHAREDID, sharedId);
props.put(QuickShareModel.PROP_QSHARE_SHAREDBY, AuthenticationUtil.getRunAsUser());
// Disable audit to preserve modifier and modified date
// see MNT-11960
behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
try {
// consumer/contributor should be able to add "shared" aspect (MNT-10366)
AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {
public Void doWork() {
nodeService.addAspect(nodeRef, QuickShareModel.ASPECT_QSHARE, props);
return null;
}
});
} finally {
behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
}
final NodeRef tenantNodeRef = tenantService.getName(nodeRef);
TenantUtil.runAsDefaultTenant(new TenantRunAsWork<Void>() {
public Void doWork() throws Exception {
attributeService.setAttribute(tenantNodeRef, ATTR_KEY_SHAREDIDS_ROOT, sharedId);
return null;
}
});
final StringBuffer sb = new StringBuffer();
sb.append("{").append("\"sharedId\":\"").append(sharedId).append("\"").append("}");
eventPublisher.publishEvent(new EventPreparator() {
@Override
public Event prepareEvent(String user, String networkId, String transactionId) {
return new ActivityEvent("quickshare", transactionId, networkId, user, nodeRef.getId(), null, typeQName.toString(), Client.asType(ClientType.webclient), sb.toString(), null, null, 0l, null);
}
});
if (logger.isInfoEnabled()) {
logger.info("QuickShare - shared content: " + sharedId + " [" + nodeRef + "]");
}
} else {
sharedId = (String) nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDID);
if (logger.isDebugEnabled()) {
logger.debug("QuickShare - content already shared: " + sharedId + " [" + nodeRef + "]");
}
}
if (expiryDate != null) {
AuthenticationUtil.runAsSystem((RunAsWork<Void>) () -> {
// Create and save the expiry action
saveSharedLinkExpiryAction(sharedId, expiryDate);
// if we get here, it means the expiry date is validated and the action
// is created and saved, so now set the expiryDate property.
behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
try {
nodeService.setProperty(nodeRef, QuickShareModel.PROP_QSHARE_EXPIRY_DATE, expiryDate);
} finally {
behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
}
return null;
});
}
return new QuickShareDTO(sharedId, expiryDate);
}
Aggregations