use of org.alfresco.service.cmr.repository.InvalidNodeRefException in project alfresco-remote-api by Alfresco.
the class MetaDataGet method executeImpl.
@Override
protected Map<String, Object> executeImpl(final WebScriptRequest req, Status status, Cache cache) {
// create map of params (template vars)
Map<String, String> params = req.getServiceMatch().getTemplateVars();
final NodeRef nodeRef = WebScriptUtil.getNodeRef(params);
if (nodeRef == null) {
String msg = "A valid NodeRef must be specified!";
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg);
}
try {
Map<String, Object> model = quickShareService.getMetaData(nodeRef);
if (logger.isDebugEnabled()) {
logger.debug("Retrieved limited metadata: " + nodeRef + " [" + model + "]");
}
return model;
} catch (InvalidNodeRefException inre) {
logger.error("Unable to find node: " + inre.getNodeRef());
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find nodeRef: " + inre.getNodeRef());
}
}
use of org.alfresco.service.cmr.repository.InvalidNodeRefException in project alfresco-remote-api by Alfresco.
the class QuickShareContentGet method execute.
@Override
public void execute(final WebScriptRequest req, final WebScriptResponse res) throws IOException {
if (!isEnabled()) {
throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "QuickShare is disabled system-wide");
}
// create map of template vars (params)
final Map<String, String> params = req.getServiceMatch().getTemplateVars();
final String sharedId = params.get("shared_id");
if (sharedId == null) {
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "A valid sharedId must be specified !");
}
try {
Pair<String, NodeRef> pair = quickShareSerivce.getTenantNodeRefFromSharedId(sharedId);
final String tenantDomain = pair.getFirst();
final NodeRef nodeRef = pair.getSecond();
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
public Void doWork() throws Exception {
if (!nodeService.getAspects(nodeRef).contains(QuickShareModel.ASPECT_QSHARE)) {
throw new InvalidNodeRefException(nodeRef);
}
executeImpl(nodeRef, params, req, res, null);
return null;
}
}, tenantDomain);
if (logger.isDebugEnabled()) {
logger.debug("QuickShare - retrieved content: " + sharedId + " [" + nodeRef + "]");
}
} catch (InvalidSharedIdException ex) {
logger.error("Unable to find: " + sharedId);
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: " + sharedId);
} catch (InvalidNodeRefException inre) {
logger.error("Unable to find: " + sharedId + " [" + inre.getNodeRef() + "]");
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: " + sharedId);
}
}
use of org.alfresco.service.cmr.repository.InvalidNodeRefException in project alfresco-remote-api by Alfresco.
the class ShareContentPost method executeImpl.
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
if (!isEnabled()) {
throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "QuickShare is disabled system-wide");
}
// create map of params (template vars)
Map<String, String> params = req.getServiceMatch().getTemplateVars();
final NodeRef nodeRef = WebScriptUtil.getNodeRef(params);
if (nodeRef == null) {
String msg = "A valid NodeRef must be specified!";
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg);
}
try {
QuickShareDTO dto = quickShareService.shareContent(nodeRef);
Map<String, Object> model = new HashMap<String, Object>(1);
model.put("sharedDTO", dto);
return model;
} catch (InvalidNodeRefException inre) {
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find node: " + nodeRef);
}
}
use of org.alfresco.service.cmr.repository.InvalidNodeRefException in project alfresco-remote-api by Alfresco.
the class UnshareContentDelete method executeImpl.
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
if (!isEnabled()) {
throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "QuickShare is disabled system-wide");
}
// create map of params (template vars)
Map<String, String> params = req.getServiceMatch().getTemplateVars();
final String sharedId = params.get("shared_id");
if (sharedId == null) {
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "A valid sharedId must be specified !");
}
try {
NodeRef nodeRef = quickShareService.getTenantNodeRefFromSharedId(sharedId).getSecond();
String sharedBy = (String) nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDBY);
if (!quickShareService.canDeleteSharedLink(nodeRef, sharedBy)) {
throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "Can't perform unshare action: " + sharedId);
}
quickShareService.unshareContent(sharedId);
Map<String, Object> model = new HashMap<>(1);
model.put("success", Boolean.TRUE);
return model;
} catch (InvalidSharedIdException ex) {
logger.error("Unable to find: " + sharedId);
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: " + sharedId);
} catch (InvalidNodeRefException inre) {
logger.error("Unable to find: " + sharedId + " [" + inre.getNodeRef() + "]");
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: " + sharedId);
}
}
use of org.alfresco.service.cmr.repository.InvalidNodeRefException in project alfresco-remote-api by Alfresco.
the class LockMethod method attemptLock.
/**
* The main lock implementation method.
*
* @throws WebDAVServerException
* @throws Exception
*/
protected void attemptLock() throws WebDAVServerException, Exception {
FileFolderService fileFolderService = getFileFolderService();
final String path = getPath();
NodeRef rootNodeRef = getRootNodeRef();
// Get the active user
final String userName = getDAVHelper().getAuthenticationService().getCurrentUserName();
if (logger.isDebugEnabled()) {
logger.debug("Locking node: \n" + " user: " + userName + "\n" + " path: " + path);
}
FileInfo lockNodeInfo = null;
try {
// Check if the path exists
lockNodeInfo = getNodeForPath(getRootNodeRef(), getPath());
} catch (FileNotFoundException e) {
if (m_conditions != null) {
// MNT-12303 fix, check whether this is a refresh lock request
for (Condition condition : m_conditions) {
List<String> lockTolensMatch = condition.getLockTokensMatch();
List<String> etagsMatch = condition.getETagsMatch();
if (m_request.getContentLength() == -1 && (lockTolensMatch != null && !lockTolensMatch.isEmpty()) || (etagsMatch != null && !etagsMatch.isEmpty())) {
// so there is nothing to refresh. Return 403 Forbidden as original SharePoint Server.
throw new WebDAVServerException(HttpServletResponse.SC_FORBIDDEN);
}
}
}
// need to create it
String[] splitPath = getDAVHelper().splitPath(path);
// check
if (splitPath[1].length() == 0) {
throw new WebDAVServerException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
FileInfo dirInfo = null;
List<String> dirPathElements = getDAVHelper().splitAllPaths(splitPath[0]);
if (dirPathElements.size() == 0) {
// if there are no path elements we are at the root so get the root node
dirInfo = fileFolderService.getFileInfo(getRootNodeRef());
} else {
// make sure folder structure is present
dirInfo = FileFolderUtil.makeFolders(fileFolderService, rootNodeRef, dirPathElements, ContentModel.TYPE_FOLDER);
}
if (dirInfo == null) {
throw new WebDAVServerException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
// create the file
lockNodeInfo = createNode(dirInfo.getNodeRef(), splitPath[1], ContentModel.TYPE_CONTENT);
// ALF-10309 fix, mark created node with webdavNoContent aspect, we assume that save operation
// is performed by client, webdavNoContent aspect normally removed in put method unless there
// is a cancel before the PUT request takes place
int lockTimeout = getLockTimeout();
if (lockTimeout > 0 && !getNodeService().hasAspect(lockNodeInfo.getNodeRef(), ContentModel.ASPECT_WEBDAV_NO_CONTENT)) {
final NodeRef nodeRef = lockNodeInfo.getNodeRef();
getNodeService().addAspect(nodeRef, ContentModel.ASPECT_WEBDAV_NO_CONTENT, null);
// Remove node after the timeout (MS Office 2003 requests 3 minutes) if the PUT or UNLOCK has not taken place
timer.schedule(new TimerTask() {
@Override
public void run() {
// run as current user
AuthenticationUtil.runAs(new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
try {
if (getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_WEBDAV_NO_CONTENT)) {
getTransactionService().getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<String>() {
public String execute() throws Throwable {
getNodeService().deleteNode(nodeRef);
if (logger.isDebugEnabled()) {
logger.debug("Timer DELETE " + path);
}
return null;
}
}, false, true);
} else if (logger.isDebugEnabled()) {
logger.debug("Timer IGNORE " + path);
}
} catch (InvalidNodeRefException e) {
// Might get this if the node is deleted. If so just ignore.
if (logger.isDebugEnabled()) {
logger.debug("Timer DOES NOT EXIST " + path);
}
}
return null;
}
}, userName);
}
}, lockTimeout * 1000);
if (logger.isDebugEnabled()) {
logger.debug("Timer START in " + lockTimeout + " seconds " + path);
}
}
if (logger.isDebugEnabled()) {
logger.debug("Created new node for lock: \n" + " path: " + path + "\n" + " node: " + lockNodeInfo);
}
m_response.setStatus(HttpServletResponse.SC_CREATED);
}
// Check if this is a new lock or a lock refresh
if (hasLockToken()) {
lockInfo = checkNode(lockNodeInfo);
if (!lockInfo.isLocked() && m_request.getContentLength() == -1) {
// see http://www.ics.uci.edu/~ejw/authoring/protocol/rfc2518.html#rfc.section.7.8
throw new WebDAVServerException(HttpServletResponse.SC_BAD_REQUEST);
}
// If a request body is not defined and "If" header is sent we have createExclusive as false,
// but we need to check a previous LOCK was an exclusive. I.e. get the property for node. It
// is already has got in a checkNode method, so we need just get a scope from lockInfo.
// This particular case was raised as ALF-4008.
this.createExclusive = WebDAV.XML_EXCLUSIVE.equals(this.lockInfo.getScope());
// Refresh an existing lock
refreshLock(lockNodeInfo, userName);
} else {
lockInfo = checkNode(lockNodeInfo, true, createExclusive);
// Create a new lock
createLock(lockNodeInfo, userName);
}
m_response.setHeader(WebDAV.HEADER_LOCK_TOKEN, "<" + WebDAV.makeLockToken(lockNodeInfo.getNodeRef(), userName) + ">");
m_response.setHeader(WebDAV.HEADER_CONTENT_TYPE, WebDAV.XML_CONTENT_TYPE);
// We either created a new lock or refreshed an existing lock, send back the lock details
generateResponse(lockNodeInfo, userName);
}
Aggregations