use of org.alfresco.service.cmr.repository.InvalidNodeRefException in project alfresco-remote-api by Alfresco.
the class QuickShareLinksImpl method readProperty.
/**
* Download content via shared link.
* <p>
* Note: does *not* require authenticated access for (public) shared link.
*
* @param sharedId
* @param renditionId - optional
* @param parameters {@link Parameters}
* @return
* @throws EntityNotFoundException
*/
public BinaryResource readProperty(String sharedId, final String renditionId, final Parameters parameters) throws EntityNotFoundException {
checkEnabled();
checkValidShareId(sharedId);
try {
Pair<String, NodeRef> pair = quickShareService.getTenantNodeRefFromSharedId(sharedId);
String networkTenantDomain = pair.getFirst();
final NodeRef nodeRef = pair.getSecond();
return TenantUtil.runAsSystemTenant(() -> {
// belt-and-braces (similar to QuickShareContentGet)
if (!nodeService.hasAspect(nodeRef, QuickShareModel.ASPECT_QSHARE)) {
throw new InvalidNodeRefException(nodeRef);
}
if (renditionId != null) {
return renditions.getContent(nodeRef, renditionId, parameters);
} else {
return nodes.getContent(nodeRef, parameters, false);
}
}, networkTenantDomain);
} 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.InvalidNodeRefException in project alfresco-remote-api by Alfresco.
the class QuickShareLinksImpl method create.
/**
* Create quick share.
* <p>
* Requires authenticated access.
*
* @param nodeIds
* @param parameters
* @return
*/
public List<QuickShareLink> create(List<QuickShareLink> nodeIds, Parameters parameters) {
checkEnabled();
List<QuickShareLink> result = new ArrayList<>(nodeIds.size());
List<String> includeParam = parameters != null ? parameters.getInclude() : Collections.<String>emptyList();
for (QuickShareLink qs : nodeIds) {
String nodeId = qs.getNodeId();
if (nodeId == null) {
throw new InvalidArgumentException("A valid nodeId must be specified !");
}
NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId);
try {
// Note: will throw InvalidNodeRefException (=> 404) if node does not exist
String sharedId = (String) nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDID);
if (sharedId != null) {
throw new ConstraintViolatedException("sharedId already exists: " + nodeId + " [" + sharedId + "]");
}
// Note: since we already check node exists above, we can assume that InvalidNodeRefException (=> 404) here means not content (see type check)
try {
QuickShareDTO qsDto = quickShareService.shareContent(nodeRef, qs.getExpiresAt());
result.add(getQuickShareInfo(qsDto.getId(), false, includeParam));
} catch (InvalidNodeRefException inre) {
throw new InvalidArgumentException("Unable to create shared link to non-file content: " + nodeId);
} catch (QuickShareLinkExpiryActionException ex) {
throw new InvalidArgumentException(ex.getMessage());
}
} catch (AccessDeniedException ade) {
throw new PermissionDeniedException("Unable to create shared link to node that does not exist: " + nodeId);
} catch (InvalidNodeRefException inre) {
logger.warn("Unable to create shared link: [" + nodeRef + "]");
throw new EntityNotFoundException(nodeId);
}
}
return result;
}
use of org.alfresco.service.cmr.repository.InvalidNodeRefException in project alfresco-remote-api by Alfresco.
the class QuickShareLinksImpl method emailSharedLink.
@Override
public void emailSharedLink(String sharedId, QuickShareLinkEmailRequest emailRequest, Parameters parameters) {
checkEnabled();
checkValidShareId(sharedId);
validateEmailRequest(emailRequest);
try {
NodeRef nodeRef = quickShareService.getTenantNodeRefFromSharedId(sharedId).getSecond();
String sharedNodeName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
QuickShareEmailRequest request = new QuickShareEmailRequest();
request.setSharedNodeName(sharedNodeName);
request.setClient(emailRequest.getClient());
request.setSharedId(sharedId);
request.setSenderMessage(emailRequest.getMessage());
request.setLocale(I18NUtil.parseLocale(emailRequest.getLocale()));
request.setToEmails(emailRequest.getRecipientEmails());
quickShareService.sendEmailNotification(request);
} catch (InvalidSharedIdException ex) {
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.InvalidNodeRefException in project alfresco-remote-api by Alfresco.
the class QuickShareLinksImpl method getRenditions.
@Override
public CollectionWithPagingInfo<Rendition> getRenditions(String sharedId) {
checkEnabled();
checkValidShareId(sharedId);
try {
Pair<String, NodeRef> pair = quickShareService.getTenantNodeRefFromSharedId(sharedId);
String networkTenantDomain = pair.getFirst();
final NodeRef nodeRef = pair.getSecond();
return TenantUtil.runAsSystemTenant(() -> {
Parameters params = getParamsWithCreatedStatus();
return renditions.getRenditions(nodeRef, params);
}, networkTenantDomain);
} 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.InvalidNodeRefException in project alfresco-remote-api by Alfresco.
the class ResultMapper method getNode.
/**
* Builds a node representation based on a ResultSetRow;
* @param searchRequestContext
* @param aRow
* @param params
* @param mapUserInfo
* @param isHistory
* @return Node
*/
public Node getNode(ResultSetRow aRow, Params params, Map<String, UserInfo> mapUserInfo, boolean isHistory) {
String nodeStore = storeMapper.getStore(aRow.getNodeRef());
if (isHistory)
nodeStore = HISTORY;
Node aNode = null;
switch(nodeStore) {
case LIVE_NODES:
aNode = nodes.getFolderOrDocument(aRow.getNodeRef(), null, null, params.getInclude(), mapUserInfo);
break;
case HISTORY:
aNode = nodes.getFolderOrDocument(aRow.getNodeRef(), null, null, params.getInclude(), mapUserInfo);
break;
case VERSIONS:
Map<QName, Serializable> properties = serviceRegistry.getNodeService().getProperties(aRow.getNodeRef());
NodeRef frozenNodeRef = ((NodeRef) properties.get(Version2Model.PROP_QNAME_FROZEN_NODE_REF));
String versionLabelId = (String) properties.get(Version2Model.PROP_QNAME_VERSION_LABEL);
Version v = null;
try {
if (frozenNodeRef != null && versionLabelId != null) {
v = nodeVersions.findVersion(frozenNodeRef.getId(), versionLabelId);
aNode = nodes.getFolderOrDocument(v.getFrozenStateNodeRef(), null, null, params.getInclude(), mapUserInfo);
}
} catch (EntityNotFoundException | InvalidNodeRefException e) {
// Solr says there is a node but we can't find it
logger.debug("Failed to find a versioned node with id of " + frozenNodeRef + " this is probably because the original node has been deleted.");
}
if (v != null && aNode != null) {
nodeVersions.mapVersionInfo(v, aNode, aRow.getNodeRef());
aNode.setNodeId(frozenNodeRef.getId());
aNode.setVersionLabel(versionLabelId);
}
break;
case DELETED:
try {
aNode = deletedNodes.getDeletedNode(aRow.getNodeRef().getId(), params, false, mapUserInfo);
} catch (EntityNotFoundException enfe) {
// Solr says there is a deleted node but we can't find it, we want the rest of the search to return so lets ignore it.
logger.debug("Failed to find a deleted node with id of " + aRow.getNodeRef().getId());
}
break;
}
if (aNode != null) {
aNode.setLocation(nodeStore);
}
return aNode;
}
Aggregations