mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merged WEBAPP-API (5.2.1) to 5.2.N (5.2.1)
133081 jkaabimofrad: APPSREPO-61: First cut of automatic time expiry enhancement to the quick-sharing functionality. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@133216 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<view:view xmlns:view="http://www.alfresco.org/view/repository/1.0"
|
||||||
|
xmlns:d="http://www.alfresco.org/model/dictionary/1.0" xmlns:cm="http://www.alfresco.org/model/content/1.0"
|
||||||
|
xmlns:sys="http://www.alfresco.org/model/system/1.0" xmlns="">
|
||||||
|
|
||||||
|
<cm:folder view:childName="${spaces.quickshare.link_expiry_actions.childname}">
|
||||||
|
<view:properties>
|
||||||
|
<sys:store-protocol>workspace</sys:store-protocol>
|
||||||
|
<sys:store-identifier>SpacesStore</sys:store-identifier>
|
||||||
|
<sys:node-uuid>shared_link_expiry_actions_space</sys:node-uuid>
|
||||||
|
<cm:name>${spaces.quickshare.link_expiry_actions.name}</cm:name>
|
||||||
|
<cm:title>${spaces.quickshare.link_expiry_actions.name}</cm:title>
|
||||||
|
<cm:description>${spaces.quickshare.link_expiry_actions.description}</cm:description>
|
||||||
|
</view:properties>
|
||||||
|
</cm:folder>
|
||||||
|
|
||||||
|
</view:view>
|
@@ -376,6 +376,7 @@
|
|||||||
<prop key="spaces.solr_facets.root.childname">${spaces.solr_facets.root.childname}</prop>
|
<prop key="spaces.solr_facets.root.childname">${spaces.solr_facets.root.childname}</prop>
|
||||||
<prop key="spaces.smartfolders.childname">${spaces.smartfolders.childname}</prop>
|
<prop key="spaces.smartfolders.childname">${spaces.smartfolders.childname}</prop>
|
||||||
<prop key="spaces.smartdownloads.childname">${spaces.smartdownloads.childname}</prop>
|
<prop key="spaces.smartdownloads.childname">${spaces.smartdownloads.childname}</prop>
|
||||||
|
<prop key="spaces.quickshare.link_expiry_actions.childname">${spaces.quickshare.link_expiry_actions.childname}</prop>
|
||||||
</props>
|
</props>
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
@@ -194,3 +194,7 @@ spaces.smartfoldertemplates.description=Smart Folder Templates
|
|||||||
|
|
||||||
spaces.smartdownloads.name=Smart Folder Downloads
|
spaces.smartdownloads.name=Smart Folder Downloads
|
||||||
spaces.smartdownloads.description=Smart Folder downloads temporary association data
|
spaces.smartdownloads.description=Smart Folder downloads temporary association data
|
||||||
|
|
||||||
|
|
||||||
|
spaces.quickshare.link_expiry_actions.name=Quick Share Link Expiry Actions Space
|
||||||
|
spaces.quickshare.link_expiry_actions.description=A space used by the system to persist quick share link expiry actions.
|
@@ -35,6 +35,16 @@
|
|||||||
<tokenised>false</tokenised>
|
<tokenised>false</tokenised>
|
||||||
</index>
|
</index>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="qshare:expiryDate">
|
||||||
|
<title>Shared Link Expiry Date</title>
|
||||||
|
<type>d:datetime</type>
|
||||||
|
<protected>true</protected>
|
||||||
|
<mandatory>false</mandatory>
|
||||||
|
<multiple>false</multiple>
|
||||||
|
<index enabled="true">
|
||||||
|
<tokenised>false</tokenised>
|
||||||
|
</index>
|
||||||
|
</property>
|
||||||
</properties>
|
</properties>
|
||||||
</aspect>
|
</aspect>
|
||||||
</aspects>
|
</aspects>
|
||||||
|
@@ -84,6 +84,9 @@
|
|||||||
<property name="searchService" ref="SearchService" />
|
<property name="searchService" ref="SearchService" />
|
||||||
<property name="siteService" ref="SiteService" />
|
<property name="siteService" ref="SiteService" />
|
||||||
<property name="authorityService" ref="AuthorityService" />
|
<property name="authorityService" ref="AuthorityService" />
|
||||||
|
<property name="scheduledPersistedActionService" ref="scheduledPersistedActionService" />
|
||||||
|
<property name="quickShareLinkExpiryActionPersister" ref="quickShareLinkExpiryActionPersister" />
|
||||||
|
<property name="expiryDatePeriod" value="${system.quickshare.expiry_date.enforce.period}" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="quickShareResourceBundles" class="org.alfresco.i18n.ResourceBundleBootstrapComponent">
|
<bean id="quickShareResourceBundles" class="org.alfresco.i18n.ResourceBundleBootstrapComponent">
|
||||||
@@ -94,4 +97,24 @@
|
|||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<bean id="quickShareLinkExpiryActionExecutor" parent="action-executer"
|
||||||
|
class="org.alfresco.repo.quickshare.QuickShareLinkExpiryActionExecutor">
|
||||||
|
<property name="quickShareService" ref="quickShareService"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean id="quickShareLinkExpiryActionPersister" class="org.alfresco.repo.quickshare.QuickShareLinkExpiryActionPersisterImpl" >
|
||||||
|
<property name="nodeService" ref="nodeService" />
|
||||||
|
<property name="behaviourFilter" ref="policyBehaviourFilter" />
|
||||||
|
<property name="runtimeActionService" ref="actionService" />
|
||||||
|
<!-- Properties for bootstrapping the Link Expiry Actions root folder -->
|
||||||
|
<property name="importerBootstrap" ref="spacesBootstrap" />
|
||||||
|
<property name="bootstrapView">
|
||||||
|
<props>
|
||||||
|
<prop key="path">/${spaces.company_home.childname}/${spaces.dictionary.childname}</prop>
|
||||||
|
<prop key="location">alfresco/bootstrap/quickShareLinkExpiryActionSpace.xml</prop>
|
||||||
|
<prop key="messages">alfresco/messages/bootstrap-spaces</prop>
|
||||||
|
</props>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
@@ -485,6 +485,8 @@ spaces.solr_facets.root.childname=srft:facets
|
|||||||
spaces.smartfolders.childname=app:smart_folders
|
spaces.smartfolders.childname=app:smart_folders
|
||||||
spaces.smartdownloads.childname=app:smart_downloads
|
spaces.smartdownloads.childname=app:smart_downloads
|
||||||
spaces.transfer_summary_report.location=/${spaces.company_home.childname}/${spaces.dictionary.childname}/${spaces.transfers.childname}/${spaces.inbound_transfer_records.childname}
|
spaces.transfer_summary_report.location=/${spaces.company_home.childname}/${spaces.dictionary.childname}/${spaces.transfers.childname}/${spaces.inbound_transfer_records.childname}
|
||||||
|
spaces.quickshare.link_expiry_actions.childname=app:quick_share_link_expiry_actions
|
||||||
|
|
||||||
|
|
||||||
# ADM VersionStore Configuration
|
# ADM VersionStore Configuration
|
||||||
version.store.initialVersion=true
|
version.store.initialVersion=true
|
||||||
@@ -982,6 +984,12 @@ authority.useBridgeTable=true
|
|||||||
# enable QuickShare - if false then the QuickShare-specific REST APIs will return 403 Forbidden
|
# enable QuickShare - if false then the QuickShare-specific REST APIs will return 403 Forbidden
|
||||||
system.quickshare.enabled=true
|
system.quickshare.enabled=true
|
||||||
system.quickshare.email.from.default=noreply@alfresco.com
|
system.quickshare.email.from.default=noreply@alfresco.com
|
||||||
|
# By default the difference between the quick share expiry date and the current time must be at least 1 day (24 hours).
|
||||||
|
# However, this can be changed to at least 1 hour or 1 minute for testing purposes. For example,
|
||||||
|
# setting the value to MINUTES, means the service will calculate the difference between NOW and the given expiry date
|
||||||
|
# in terms of minutes and checks for the difference to be greater than 1 minute.
|
||||||
|
# DAYS | HOURS | MINUTES
|
||||||
|
system.quickshare.expiry_date.enforce.period=DAYS
|
||||||
|
|
||||||
# Oubound Mail
|
# Oubound Mail
|
||||||
mail.service.corePoolSize=8
|
mail.service.corePoolSize=8
|
||||||
|
@@ -23,25 +23,27 @@
|
|||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.model;
|
package org.alfresco.model;
|
||||||
|
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* QuickShare Model Constants
|
* QuickShare Model Constants
|
||||||
*
|
*
|
||||||
* @author janv
|
* @author janv
|
||||||
*/
|
*/
|
||||||
public interface QuickShareModel
|
public interface QuickShareModel
|
||||||
{
|
{
|
||||||
// Namespaces
|
// Namespaces
|
||||||
static final String QSHARE_MODEL_1_0_URI = "http://www.alfresco.org/model/qshare/1.0";
|
static final String QSHARE_MODEL_1_0_URI = "http://www.alfresco.org/model/qshare/1.0";
|
||||||
|
|
||||||
// Aspects
|
// Aspects
|
||||||
static final QName ASPECT_QSHARE = QName.createQName(QSHARE_MODEL_1_0_URI, "shared");
|
static final QName ASPECT_QSHARE = QName.createQName(QSHARE_MODEL_1_0_URI, "shared");
|
||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
static final QName PROP_QSHARE_SHAREDID = QName.createQName(QSHARE_MODEL_1_0_URI, "sharedId");
|
static final QName PROP_QSHARE_SHAREDID = QName.createQName(QSHARE_MODEL_1_0_URI, "sharedId");
|
||||||
static final QName PROP_QSHARE_SHAREDBY = QName.createQName(QSHARE_MODEL_1_0_URI, "sharedBy");
|
static final QName PROP_QSHARE_SHAREDBY = QName.createQName(QSHARE_MODEL_1_0_URI, "sharedBy");
|
||||||
}
|
static final QName PROP_QSHARE_EXPIRY_DATE = QName.createQName(QSHARE_MODEL_1_0_URI, "expiryDate");
|
||||||
|
|
||||||
|
}
|
||||||
|
@@ -1,28 +1,28 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Repository
|
* Alfresco Repository
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
*
|
*
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.repo.action.scheduled;
|
package org.alfresco.repo.action.scheduled;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -132,7 +132,7 @@ public class ScheduledPersistedActionServiceImpl implements ScheduledPersistedAc
|
|||||||
{
|
{
|
||||||
this.runtimeActionService = runtimeActionService;
|
this.runtimeActionService = runtimeActionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void locatePersistanceFolder()
|
protected void locatePersistanceFolder()
|
||||||
{
|
{
|
||||||
@@ -193,7 +193,7 @@ public class ScheduledPersistedActionServiceImpl implements ScheduledPersistedAc
|
|||||||
public void saveSchedule(ScheduledPersistedAction schedule)
|
public void saveSchedule(ScheduledPersistedAction schedule)
|
||||||
{
|
{
|
||||||
ScheduledPersistedActionImpl scheduleImpl = (ScheduledPersistedActionImpl)schedule;
|
ScheduledPersistedActionImpl scheduleImpl = (ScheduledPersistedActionImpl)schedule;
|
||||||
|
|
||||||
// Remove if already there
|
// Remove if already there
|
||||||
removeFromScheduler(scheduleImpl);
|
removeFromScheduler(scheduleImpl);
|
||||||
|
|
||||||
@@ -202,7 +202,7 @@ public class ScheduledPersistedActionServiceImpl implements ScheduledPersistedAc
|
|||||||
// if not already persisted, create the persistent schedule
|
// if not already persisted, create the persistent schedule
|
||||||
createPersistentSchedule(scheduleImpl);
|
createPersistentSchedule(scheduleImpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the persistent schedule with schedule properties
|
// update the persistent schedule with schedule properties
|
||||||
updatePersistentSchedule(scheduleImpl);
|
updatePersistentSchedule(scheduleImpl);
|
||||||
|
|
||||||
@@ -297,33 +297,36 @@ public class ScheduledPersistedActionServiceImpl implements ScheduledPersistedAc
|
|||||||
schedule.setPersistedAtNodeRef(null);
|
schedule.setPersistedAtNodeRef(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Returns the schedule for the specified action, or null if it isn't
|
|
||||||
* currently scheduled.
|
|
||||||
*/
|
|
||||||
public ScheduledPersistedAction getSchedule(Action persistedAction)
|
public ScheduledPersistedAction getSchedule(Action persistedAction)
|
||||||
{
|
{
|
||||||
NodeRef nodeRef = persistedAction.getNodeRef();
|
NodeRef nodeRef = persistedAction.getNodeRef();
|
||||||
if (nodeRef == null)
|
return getSchedule(nodeRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ScheduledPersistedAction getSchedule(NodeRef persistedActionNodeRef)
|
||||||
|
{
|
||||||
|
if (persistedActionNodeRef == null)
|
||||||
{
|
{
|
||||||
// action is not persistent
|
// action is not persistent
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// locate associated schedule for action
|
// locate associated schedule for action
|
||||||
List<AssociationRef> assocs = nodeService.getSourceAssocs(nodeRef, ActionModel.ASSOC_SCHEDULED_ACTION);
|
List<AssociationRef> assocs = nodeService.getSourceAssocs(persistedActionNodeRef, ActionModel.ASSOC_SCHEDULED_ACTION);
|
||||||
AssociationRef scheduledAssoc = null;
|
AssociationRef scheduledAssoc = null;
|
||||||
for (AssociationRef assoc : assocs)
|
for (AssociationRef assoc : assocs)
|
||||||
{
|
{
|
||||||
scheduledAssoc = assoc;
|
scheduledAssoc = assoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scheduledAssoc == null)
|
if (scheduledAssoc == null)
|
||||||
{
|
{
|
||||||
// there is no associated schedule
|
// there is no associated schedule
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// load the scheduled action
|
// load the scheduled action
|
||||||
return loadPersistentSchedule(scheduledAssoc.getSourceRef());
|
return loadPersistentSchedule(scheduledAssoc.getSourceRef());
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Repository
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.repo.quickshare;
|
||||||
|
|
||||||
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Jamal Kaabi-Mofrad
|
||||||
|
*/
|
||||||
|
public class QuickShareLinkExpiryActionException extends AlfrescoRuntimeException
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 6298296507061784874L;
|
||||||
|
|
||||||
|
public QuickShareLinkExpiryActionException(String msgId)
|
||||||
|
{
|
||||||
|
super(msgId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public QuickShareLinkExpiryActionException(String msgId, Object[] msgParams)
|
||||||
|
{
|
||||||
|
super(msgId, msgParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
public QuickShareLinkExpiryActionException(String msgId, Throwable cause)
|
||||||
|
{
|
||||||
|
super(msgId, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class InvalidExpiryDateException extends QuickShareLinkExpiryActionException
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 7529497485776706174L;
|
||||||
|
|
||||||
|
public InvalidExpiryDateException(String msgId)
|
||||||
|
{
|
||||||
|
super(msgId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InvalidExpiryDateException(String msgId, Object[] msgParams)
|
||||||
|
{
|
||||||
|
super(msgId, msgParams);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Repository
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.repo.quickshare;
|
||||||
|
|
||||||
|
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
|
||||||
|
import org.alfresco.service.cmr.action.Action;
|
||||||
|
import org.alfresco.service.cmr.action.ParameterDefinition;
|
||||||
|
import org.alfresco.service.cmr.quickshare.QuickShareLinkExpiryAction;
|
||||||
|
import org.alfresco.service.cmr.quickshare.QuickShareService;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This action executor unshares the shared link when the quick share link expiry action is triggered.
|
||||||
|
*
|
||||||
|
* @author Jamal Kaabi-Mofrad
|
||||||
|
*/
|
||||||
|
public class QuickShareLinkExpiryActionExecutor extends ActionExecuterAbstractBase
|
||||||
|
{
|
||||||
|
private static final Log LOGGER = LogFactory.getLog(QuickShareLinkExpiryActionExecutor.class);
|
||||||
|
|
||||||
|
private QuickShareService quickShareService;
|
||||||
|
|
||||||
|
public void setQuickShareService(QuickShareService quickShareService)
|
||||||
|
{
|
||||||
|
this.quickShareService = quickShareService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
|
||||||
|
{
|
||||||
|
if (!(action instanceof QuickShareLinkExpiryAction))
|
||||||
|
{
|
||||||
|
if (action.getActionDefinitionName().equals(QuickShareLinkExpiryActionImpl.EXECUTOR_NAME))
|
||||||
|
{
|
||||||
|
action = new QuickShareLinkExpiryActionImpl(action);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QuickShareLinkExpiryAction quickShareLinkExpiryAction = (QuickShareLinkExpiryAction) action;
|
||||||
|
String sharedId = quickShareLinkExpiryAction.getSharedId();
|
||||||
|
if (LOGGER.isDebugEnabled())
|
||||||
|
{
|
||||||
|
LOGGER.debug("Unsharing the shared id [" + sharedId + "] for the node:" + quickShareService.getMetaData(sharedId).get("name"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(sharedId))
|
||||||
|
{
|
||||||
|
throw new QuickShareLinkExpiryActionException("Shared id is not specified.");
|
||||||
|
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
quickShareService.unshareContent(sharedId);
|
||||||
|
if (LOGGER.isDebugEnabled())
|
||||||
|
{
|
||||||
|
LOGGER.debug("Unshared the shared id [" + sharedId + "] for the node:" + quickShareService.getMetaData(sharedId).get("name"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
if (ex instanceof QuickShareLinkExpiryActionException)
|
||||||
|
{
|
||||||
|
LOGGER.error("Couldn't delete the quick share expiry action [" + quickShareLinkExpiryAction.getNodeRef() + "] for the sharedId:"
|
||||||
|
+ sharedId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOGGER.error("Couldn't unshare the shared Id:" + sharedId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void addParameterDefinitions(List<ParameterDefinition> paramList)
|
||||||
|
{
|
||||||
|
// Not used - our definitions hold everything
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,166 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Repository
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.repo.quickshare;
|
||||||
|
|
||||||
|
import org.alfresco.repo.action.ActionImpl;
|
||||||
|
import org.alfresco.service.cmr.action.Action;
|
||||||
|
import org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction;
|
||||||
|
import org.alfresco.service.cmr.quickshare.QuickShareLinkExpiryAction;
|
||||||
|
import org.alfresco.service.namespace.QName;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quick share link expiry action implementation class.
|
||||||
|
*
|
||||||
|
* @author Jamal Kaabi-Mofrad
|
||||||
|
*/
|
||||||
|
public class QuickShareLinkExpiryActionImpl extends ActionImpl implements QuickShareLinkExpiryAction
|
||||||
|
{
|
||||||
|
|
||||||
|
public static final String EXECUTOR_NAME = "quickShareLinkExpiryActionExecutor";
|
||||||
|
public static final String QUICK_SHARE_LINK_EXPIRY_ACTION_NAME = "quickShareLinkExpiryActionName";
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 2497810872555230797L;
|
||||||
|
|
||||||
|
private ScheduledPersistedAction schedule;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param id the action id
|
||||||
|
* @param sharedId a unique name for the quick share link expiry action.
|
||||||
|
* @param description the action description
|
||||||
|
*/
|
||||||
|
public QuickShareLinkExpiryActionImpl(String id, String sharedId, String description)
|
||||||
|
{
|
||||||
|
super(null, id, EXECUTOR_NAME);
|
||||||
|
setActionQName(createQName(sharedId));
|
||||||
|
setDescription(description);
|
||||||
|
}
|
||||||
|
|
||||||
|
public QuickShareLinkExpiryActionImpl(Action action)
|
||||||
|
{
|
||||||
|
super(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setActionQName(QName actionQName)
|
||||||
|
{
|
||||||
|
setParameterValue(QUICK_SHARE_LINK_EXPIRY_ACTION_NAME, actionQName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public QName getActionQName()
|
||||||
|
{
|
||||||
|
Serializable parameterValue = getParameterValue(QUICK_SHARE_LINK_EXPIRY_ACTION_NAME);
|
||||||
|
return (QName) parameterValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ScheduledPersistedAction getSchedule()
|
||||||
|
{
|
||||||
|
return this.schedule;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSchedule(ScheduledPersistedAction schedule)
|
||||||
|
{
|
||||||
|
this.schedule = schedule;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSharedId()
|
||||||
|
{
|
||||||
|
// As we use the sharedId to generate the action's QName.
|
||||||
|
QName qName = getActionQName();
|
||||||
|
if (qName != null)
|
||||||
|
{
|
||||||
|
return qName.getLocalName();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Date getScheduleStart()
|
||||||
|
{
|
||||||
|
if (schedule == null)
|
||||||
|
return null;
|
||||||
|
return schedule.getScheduleStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setScheduleStart(Date startDate)
|
||||||
|
{
|
||||||
|
if (schedule == null)
|
||||||
|
{
|
||||||
|
throw new IllegalStateException("Scheduling is not enabled.");
|
||||||
|
}
|
||||||
|
schedule.setScheduleStart(startDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getScheduleIntervalCount()
|
||||||
|
{
|
||||||
|
if (schedule == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return schedule.getScheduleIntervalCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setScheduleIntervalCount(Integer count)
|
||||||
|
{
|
||||||
|
if (schedule == null)
|
||||||
|
{
|
||||||
|
throw new IllegalStateException("Scheduling is not enabled.");
|
||||||
|
}
|
||||||
|
schedule.setScheduleIntervalCount(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IntervalPeriod getScheduleIntervalPeriod()
|
||||||
|
{
|
||||||
|
if (schedule == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return schedule.getScheduleIntervalPeriod();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setScheduleIntervalPeriod(IntervalPeriod period)
|
||||||
|
{
|
||||||
|
if (schedule == null)
|
||||||
|
throw new IllegalStateException("Scheduling is not enabled.");
|
||||||
|
schedule.setScheduleIntervalPeriod(period);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static QName createQName(String sharedId)
|
||||||
|
{
|
||||||
|
return QName.createQName(null, sharedId);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,195 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Repository
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.repo.quickshare;
|
||||||
|
|
||||||
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.repo.action.RuntimeActionService;
|
||||||
|
import org.alfresco.repo.importer.ImporterBootstrap;
|
||||||
|
import org.alfresco.repo.policy.BehaviourFilter;
|
||||||
|
import org.alfresco.service.cmr.action.Action;
|
||||||
|
import org.alfresco.service.cmr.quickshare.QuickShareLinkExpiryAction;
|
||||||
|
import org.alfresco.service.cmr.quickshare.QuickShareLinkExpiryActionPersister;
|
||||||
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
|
import org.alfresco.service.cmr.repository.StoreRef;
|
||||||
|
import org.alfresco.service.namespace.QName;
|
||||||
|
import org.alfresco.util.ParameterCheck;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default implementation of the {@link QuickShareLinkExpiryActionPersister}.
|
||||||
|
* It is responsible for persisting and retrieving the quick share link expiry actions.
|
||||||
|
*
|
||||||
|
* @author Jamal Kaabi-Mofrad
|
||||||
|
*/
|
||||||
|
public class QuickShareLinkExpiryActionPersisterImpl implements QuickShareLinkExpiryActionPersister
|
||||||
|
{
|
||||||
|
protected static final NodeRef QUICK_SHARE_LINK_EXPIRY_ACTIONS_ROOT = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,
|
||||||
|
"shared_link_expiry_actions_space");
|
||||||
|
|
||||||
|
/* Injected services */
|
||||||
|
private NodeService nodeService;
|
||||||
|
private RuntimeActionService runtimeActionService;
|
||||||
|
private BehaviourFilter behaviourFilter;
|
||||||
|
private ImporterBootstrap importerBootstrap;
|
||||||
|
private Properties bootstrapView;
|
||||||
|
|
||||||
|
public void setNodeService(NodeService nodeService)
|
||||||
|
{
|
||||||
|
this.nodeService = nodeService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRuntimeActionService(RuntimeActionService runtimeActionService)
|
||||||
|
{
|
||||||
|
this.runtimeActionService = runtimeActionService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBehaviourFilter(BehaviourFilter behaviourFilter)
|
||||||
|
{
|
||||||
|
this.behaviourFilter = behaviourFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImporterBootstrap(ImporterBootstrap importerBootstrap)
|
||||||
|
{
|
||||||
|
this.importerBootstrap = importerBootstrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBootstrapView(Properties bootstrapView)
|
||||||
|
{
|
||||||
|
this.bootstrapView = bootstrapView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveQuickShareLinkExpiryAction(QuickShareLinkExpiryAction linkExpiryAction)
|
||||||
|
{
|
||||||
|
ParameterCheck.mandatory("linkExpiryAction", linkExpiryAction);
|
||||||
|
|
||||||
|
NodeRef actionNodeRef = findOrCreateActionNode(linkExpiryAction);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
behaviourFilter.disableBehaviour(actionNodeRef);
|
||||||
|
runtimeActionService.saveActionImpl(actionNodeRef, linkExpiryAction);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
behaviourFilter.enableBehaviour(actionNodeRef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NodeRef getQuickShareLinkExpiryActionNode(QName linkExpiryActionName)
|
||||||
|
{
|
||||||
|
ParameterCheck.mandatory("linkExpiryActionName", linkExpiryActionName);
|
||||||
|
|
||||||
|
NodeRef rootNodeRef = getOrCreateActionsRootNodeRef();
|
||||||
|
List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(rootNodeRef, ContentModel.ASSOC_CONTAINS, linkExpiryActionName);
|
||||||
|
if (!childAssocs.isEmpty())
|
||||||
|
{
|
||||||
|
if (childAssocs.size() > 1)
|
||||||
|
{
|
||||||
|
throw new QuickShareLinkExpiryActionException(
|
||||||
|
"Multiple quick share link expiry actions with the name: " + linkExpiryActionName + " exist!");
|
||||||
|
}
|
||||||
|
return childAssocs.get(0).getChildRef();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public QuickShareLinkExpiryAction loadQuickShareLinkExpiryAction(QName linkExpiryActionName)
|
||||||
|
{
|
||||||
|
NodeRef actionNode = getQuickShareLinkExpiryActionNode(linkExpiryActionName);
|
||||||
|
return loadQuickShareLinkExpiryAction(actionNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public QuickShareLinkExpiryAction loadQuickShareLinkExpiryAction(NodeRef linkExpiryActionNodeRef)
|
||||||
|
{
|
||||||
|
if (linkExpiryActionNodeRef != null)
|
||||||
|
{
|
||||||
|
Action action = runtimeActionService.createAction(linkExpiryActionNodeRef);
|
||||||
|
return new QuickShareLinkExpiryActionImpl(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteQuickShareLinkExpiryAction(QuickShareLinkExpiryAction linkExpiryAction)
|
||||||
|
{
|
||||||
|
ParameterCheck.mandatory("linkExpiryAction", linkExpiryAction);
|
||||||
|
|
||||||
|
NodeRef actionNodeRef = findOrCreateActionNode(linkExpiryAction);
|
||||||
|
if (actionNodeRef != null)
|
||||||
|
{
|
||||||
|
nodeService.deleteNode(actionNodeRef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private NodeRef findOrCreateActionNode(QuickShareLinkExpiryAction linkExpiryAction)
|
||||||
|
{
|
||||||
|
QName actionQName = linkExpiryAction.getActionQName();
|
||||||
|
NodeRef actionNode = getQuickShareLinkExpiryActionNode(actionQName);
|
||||||
|
if (actionNode == null)
|
||||||
|
{
|
||||||
|
NodeRef rootNodeRef = getOrCreateActionsRootNodeRef();
|
||||||
|
actionNode = runtimeActionService.createActionNodeRef(linkExpiryAction, rootNodeRef, ContentModel.ASSOC_CONTAINS, actionQName);
|
||||||
|
}
|
||||||
|
return actionNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the folder containing quick share link expiry action nodes.
|
||||||
|
* If it doesn't exist then it tries to create it.
|
||||||
|
*
|
||||||
|
* @throws QuickShareLinkExpiryActionException if the folder node can't be created.
|
||||||
|
*/
|
||||||
|
private NodeRef getOrCreateActionsRootNodeRef()
|
||||||
|
{
|
||||||
|
if (!nodeService.exists(QUICK_SHARE_LINK_EXPIRY_ACTIONS_ROOT))
|
||||||
|
{
|
||||||
|
//import
|
||||||
|
// This lazy create approach, avoids the need to create a patch for existing repo.
|
||||||
|
List<Properties> singletonList = new ArrayList<>();
|
||||||
|
singletonList.add(bootstrapView);
|
||||||
|
importerBootstrap.setBootstrapViews(singletonList);
|
||||||
|
importerBootstrap.setUseExistingStore(true);
|
||||||
|
importerBootstrap.bootstrap();
|
||||||
|
|
||||||
|
// if still doesn't exist, throw an exception.
|
||||||
|
if (!nodeService.exists(QUICK_SHARE_LINK_EXPIRY_ACTIONS_ROOT))
|
||||||
|
{
|
||||||
|
throw new QuickShareLinkExpiryActionException("Couldn't import the quick share link expiry actions root node.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QUICK_SHARE_LINK_EXPIRY_ACTIONS_ROOT;
|
||||||
|
}
|
||||||
|
}
|
@@ -29,6 +29,7 @@ import java.io.Serializable;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -64,12 +65,17 @@ import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
|
|||||||
import org.alfresco.repo.thumbnail.ThumbnailDefinition;
|
import org.alfresco.repo.thumbnail.ThumbnailDefinition;
|
||||||
import org.alfresco.service.cmr.action.Action;
|
import org.alfresco.service.cmr.action.Action;
|
||||||
import org.alfresco.service.cmr.action.ActionService;
|
import org.alfresco.service.cmr.action.ActionService;
|
||||||
|
import org.alfresco.service.cmr.action.scheduled.SchedulableAction.IntervalPeriod;
|
||||||
|
import org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction;
|
||||||
|
import org.alfresco.service.cmr.action.scheduled.ScheduledPersistedActionService;
|
||||||
import org.alfresco.service.cmr.attributes.AttributeService;
|
import org.alfresco.service.cmr.attributes.AttributeService;
|
||||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||||
import org.alfresco.service.cmr.preference.PreferenceService;
|
import org.alfresco.service.cmr.preference.PreferenceService;
|
||||||
import org.alfresco.service.cmr.quickshare.InvalidSharedIdException;
|
import org.alfresco.service.cmr.quickshare.InvalidSharedIdException;
|
||||||
import org.alfresco.service.cmr.quickshare.QuickShareDTO;
|
import org.alfresco.service.cmr.quickshare.QuickShareDTO;
|
||||||
import org.alfresco.service.cmr.quickshare.QuickShareDisabledException;
|
import org.alfresco.service.cmr.quickshare.QuickShareDisabledException;
|
||||||
|
import org.alfresco.service.cmr.quickshare.QuickShareLinkExpiryAction;
|
||||||
|
import org.alfresco.service.cmr.quickshare.QuickShareLinkExpiryActionPersister;
|
||||||
import org.alfresco.service.cmr.quickshare.QuickShareService;
|
import org.alfresco.service.cmr.quickshare.QuickShareService;
|
||||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
import org.alfresco.service.cmr.repository.ContentData;
|
import org.alfresco.service.cmr.repository.ContentData;
|
||||||
@@ -96,11 +102,13 @@ import org.alfresco.util.PropertyCheck;
|
|||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.joda.time.DateTime;
|
||||||
|
import org.joda.time.Interval;
|
||||||
|
import org.joda.time.PeriodType;
|
||||||
import org.safehaus.uuid.UUID;
|
import org.safehaus.uuid.UUID;
|
||||||
import org.safehaus.uuid.UUIDGenerator;
|
import org.safehaus.uuid.UUIDGenerator;
|
||||||
import org.springframework.extensions.surf.util.I18NUtil;
|
import org.springframework.extensions.surf.util.I18NUtil;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* QuickShare Service implementation.
|
* QuickShare Service implementation.
|
||||||
*
|
*
|
||||||
@@ -147,7 +155,10 @@ public class QuickShareServiceImpl implements QuickShareService,
|
|||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
private String defaultEmailSender;
|
private String defaultEmailSender;
|
||||||
private ClientAppConfig clientAppConfig;
|
private ClientAppConfig clientAppConfig;
|
||||||
|
private ScheduledPersistedActionService scheduledPersistedActionService;
|
||||||
|
private QuickShareLinkExpiryActionPersister quickShareLinkExpiryActionPersister;
|
||||||
|
// The default period is in DAYS, but we allow HOURS|MINUTES as well for testing purposes.
|
||||||
|
private ExpiryDatePeriod expiryDatePeriod = ExpiryDatePeriod.DAYS;
|
||||||
/**
|
/**
|
||||||
* Set the attribute service
|
* Set the attribute service
|
||||||
*/
|
*/
|
||||||
@@ -300,6 +311,39 @@ public class QuickShareServiceImpl implements QuickShareService,
|
|||||||
this.clientAppConfig = clientAppConfig;
|
this.clientAppConfig = clientAppConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spring configuration
|
||||||
|
*
|
||||||
|
* @param scheduledPersistedActionService the scheduledPersistedActionService to set
|
||||||
|
*/
|
||||||
|
public void setScheduledPersistedActionService(ScheduledPersistedActionService scheduledPersistedActionService)
|
||||||
|
{
|
||||||
|
this.scheduledPersistedActionService = scheduledPersistedActionService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spring configuration
|
||||||
|
*
|
||||||
|
* @param quickShareLinkExpiryActionPersister the quickShareLinkExpiryActionPersister to set
|
||||||
|
*/
|
||||||
|
public void setQuickShareLinkExpiryActionPersister(QuickShareLinkExpiryActionPersister quickShareLinkExpiryActionPersister)
|
||||||
|
{
|
||||||
|
this.quickShareLinkExpiryActionPersister = quickShareLinkExpiryActionPersister;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spring configuration
|
||||||
|
*
|
||||||
|
* @param expiryDatePeriod the expiryDatePeriod to set
|
||||||
|
*/
|
||||||
|
public void setExpiryDatePeriod(String expiryDatePeriod)
|
||||||
|
{
|
||||||
|
if (expiryDatePeriod != null)
|
||||||
|
{
|
||||||
|
this.expiryDatePeriod = ExpiryDatePeriod.valueOf(expiryDatePeriod.toUpperCase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void checkMandatoryProperties()
|
private void checkMandatoryProperties()
|
||||||
{
|
{
|
||||||
PropertyCheck.mandatory(this, "attributeService", attributeService);
|
PropertyCheck.mandatory(this, "attributeService", attributeService);
|
||||||
@@ -319,6 +363,8 @@ public class QuickShareServiceImpl implements QuickShareService,
|
|||||||
PropertyCheck.mandatory(this, "searchService", searchService);
|
PropertyCheck.mandatory(this, "searchService", searchService);
|
||||||
PropertyCheck.mandatory(this, "siteService", siteService);
|
PropertyCheck.mandatory(this, "siteService", siteService);
|
||||||
PropertyCheck.mandatory(this, "authorityService", authorityService);
|
PropertyCheck.mandatory(this, "authorityService", authorityService);
|
||||||
|
PropertyCheck.mandatory(this, "scheduledPersistedActionService", scheduledPersistedActionService);
|
||||||
|
PropertyCheck.mandatory(this, "quickShareLinkExpiryActionPersister", quickShareLinkExpiryActionPersister);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -349,29 +395,35 @@ public class QuickShareServiceImpl implements QuickShareService,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QuickShareDTO shareContent(final NodeRef nodeRef)
|
public QuickShareDTO shareContent(final NodeRef nodeRef)
|
||||||
|
{
|
||||||
|
return shareContent(nodeRef, DateTime.now().plusMinutes(1).toDate());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public QuickShareDTO shareContent(NodeRef nodeRef, Date expiryDate) throws QuickShareDisabledException, InvalidNodeRefException
|
||||||
{
|
{
|
||||||
checkEnabled();
|
checkEnabled();
|
||||||
|
|
||||||
//Check the node is the correct type
|
//Check the node is the correct type
|
||||||
final QName typeQName = nodeService.getType(nodeRef);
|
final QName typeQName = nodeService.getType(nodeRef);
|
||||||
if (isSharable(typeQName) == false)
|
if (isSharable(typeQName) == false)
|
||||||
{
|
{
|
||||||
throw new InvalidNodeRefException(nodeRef);
|
throw new InvalidNodeRefException(nodeRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String sharedId;
|
final String sharedId;
|
||||||
|
|
||||||
// Only add the quick share aspect if it isn't already present.
|
// Only add the quick share aspect if it isn't already present.
|
||||||
// If it is retura dto built from the existing properties.
|
// If it is retura dto built from the existing properties.
|
||||||
if (! nodeService.getAspects(nodeRef).contains(QuickShareModel.ASPECT_QSHARE))
|
if (! nodeService.getAspects(nodeRef).contains(QuickShareModel.ASPECT_QSHARE))
|
||||||
{
|
{
|
||||||
UUID uuid = UUIDGenerator.getInstance().generateRandomBasedUUID();
|
UUID uuid = UUIDGenerator.getInstance().generateRandomBasedUUID();
|
||||||
sharedId = Base64.encodeBase64URLSafeString(uuid.toByteArray()); // => 22 chars (eg. q3bEKPeDQvmJYgt4hJxOjw)
|
sharedId = Base64.encodeBase64URLSafeString(uuid.toByteArray()); // => 22 chars (eg. q3bEKPeDQvmJYgt4hJxOjw)
|
||||||
|
|
||||||
final Map<QName, Serializable> props = new HashMap<QName, Serializable>(2);
|
final Map<QName, Serializable> props = new HashMap<QName, Serializable>(2);
|
||||||
props.put(QuickShareModel.PROP_QSHARE_SHAREDID, sharedId);
|
props.put(QuickShareModel.PROP_QSHARE_SHAREDID, sharedId);
|
||||||
props.put(QuickShareModel.PROP_QSHARE_SHAREDBY, AuthenticationUtil.getRunAsUser());
|
props.put(QuickShareModel.PROP_QSHARE_SHAREDBY, AuthenticationUtil.getRunAsUser());
|
||||||
|
|
||||||
// Disable audit to preserve modifier and modified date
|
// Disable audit to preserve modifier and modified date
|
||||||
// see MNT-11960
|
// see MNT-11960
|
||||||
behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
|
behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
|
||||||
@@ -393,7 +445,7 @@ public class QuickShareServiceImpl implements QuickShareService,
|
|||||||
}
|
}
|
||||||
|
|
||||||
final NodeRef tenantNodeRef = tenantService.getName(nodeRef);
|
final NodeRef tenantNodeRef = tenantService.getName(nodeRef);
|
||||||
|
|
||||||
TenantUtil.runAsDefaultTenant(new TenantRunAsWork<Void>()
|
TenantUtil.runAsDefaultTenant(new TenantRunAsWork<Void>()
|
||||||
{
|
{
|
||||||
public Void doWork() throws Exception
|
public Void doWork() throws Exception
|
||||||
@@ -402,20 +454,20 @@ public class QuickShareServiceImpl implements QuickShareService,
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
final StringBuffer sb = new StringBuffer();
|
final StringBuffer sb = new StringBuffer();
|
||||||
sb.append("{").append("\"sharedId\":\"").append(sharedId).append("\"").append("}");
|
sb.append("{").append("\"sharedId\":\"").append(sharedId).append("\"").append("}");
|
||||||
|
|
||||||
eventPublisher.publishEvent(new EventPreparator(){
|
eventPublisher.publishEvent(new EventPreparator(){
|
||||||
@Override
|
@Override
|
||||||
public Event prepareEvent(String user, String networkId, String transactionId)
|
public Event prepareEvent(String user, String networkId, String transactionId)
|
||||||
{
|
{
|
||||||
return new ActivityEvent("quickshare", transactionId, networkId, user, nodeRef.getId(),
|
return new ActivityEvent("quickshare", transactionId, networkId, user, nodeRef.getId(),
|
||||||
null, typeQName.toString(), Client.asType(ClientType.webclient), sb.toString(),
|
null, typeQName.toString(), Client.asType(ClientType.webclient), sb.toString(),
|
||||||
null, null, 0l, null);
|
null, null, 0l, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (logger.isInfoEnabled())
|
if (logger.isInfoEnabled())
|
||||||
{
|
{
|
||||||
logger.info("QuickShare - shared content: "+sharedId+" ["+nodeRef+"]");
|
logger.info("QuickShare - shared content: "+sharedId+" ["+nodeRef+"]");
|
||||||
@@ -429,10 +481,28 @@ public class QuickShareServiceImpl implements QuickShareService,
|
|||||||
logger.debug("QuickShare - content already shared: "+sharedId+" ["+nodeRef+"]");
|
logger.debug("QuickShare - content already shared: "+sharedId+" ["+nodeRef+"]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (expiryDate != null)
|
||||||
return new QuickShareDTO(sharedId);
|
{
|
||||||
}
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is this service enable?
|
* Is this service enable?
|
||||||
@@ -530,6 +600,8 @@ public class QuickShareServiceImpl implements QuickShareService,
|
|||||||
if (nodeProps.containsKey(QuickShareModel.PROP_QSHARE_SHAREDID))
|
if (nodeProps.containsKey(QuickShareModel.PROP_QSHARE_SHAREDID))
|
||||||
{
|
{
|
||||||
metadata.put("sharedId", nodeProps.get(QuickShareModel.PROP_QSHARE_SHAREDID));
|
metadata.put("sharedId", nodeProps.get(QuickShareModel.PROP_QSHARE_SHAREDID));
|
||||||
|
metadata.put("expiryDate", nodeProps.get(QuickShareModel.PROP_QSHARE_EXPIRY_DATE));
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -719,6 +791,20 @@ public class QuickShareServiceImpl implements QuickShareService,
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Remove scheduled expiry action if any
|
||||||
|
NodeRef expiryActionNodeRef = getQuickShareLinkExpiryActionNode(sharedId);
|
||||||
|
if (expiryActionNodeRef != null)
|
||||||
|
{
|
||||||
|
deleteQuickShareLinkExpiryAction(expiryActionNodeRef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new QuickShareLinkExpiryActionException("Couldn't delete the quick share link expiry action for the sharedId:" + sharedId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -762,7 +848,7 @@ public class QuickShareServiceImpl implements QuickShareService,
|
|||||||
}, tenantDomain);
|
}, tenantDomain);
|
||||||
|
|
||||||
removeSharedId(sharedId);
|
removeSharedId(sharedId);
|
||||||
|
|
||||||
if (logger.isInfoEnabled())
|
if (logger.isInfoEnabled())
|
||||||
{
|
{
|
||||||
logger.info("QuickShare - unshared content: "+sharedId+" ["+nodeRef+"]");
|
logger.info("QuickShare - unshared content: "+sharedId+" ["+nodeRef+"]");
|
||||||
@@ -1100,5 +1186,215 @@ public class QuickShareServiceImpl implements QuickShareService,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates and persists the quick share link expiry action and its related schedule.
|
||||||
|
*/
|
||||||
|
protected void saveSharedLinkExpiryAction(String sharedId, Date expiryDate)
|
||||||
|
{
|
||||||
|
ParameterCheck.mandatory("expiryDate", expiryDate);
|
||||||
|
// Validate the given expiry date
|
||||||
|
checkExpiryDate(expiryDate);
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("Creating shared link expiry action for the sharedId:" + sharedId);
|
||||||
|
}
|
||||||
|
|
||||||
|
final NodeRef expiryActionNodeRef = getQuickShareLinkExpiryActionNode(sharedId);
|
||||||
|
// If an expiry action already exists for the specified shared Id, first remove it, before creating a new one.
|
||||||
|
if (expiryActionNodeRef != null)
|
||||||
|
{
|
||||||
|
deleteQuickShareLinkExpiryAction(expiryActionNodeRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the expiry action
|
||||||
|
final QuickShareLinkExpiryAction expiryAction = new QuickShareLinkExpiryActionImpl(java.util.UUID.randomUUID().toString(), sharedId,
|
||||||
|
"QuickShare link expiry action");
|
||||||
|
// Create the persisted schedule
|
||||||
|
final ScheduledPersistedAction schedule = scheduledPersistedActionService.createSchedule(expiryAction);
|
||||||
|
|
||||||
|
// first set the scheduledAction so we can set the other information
|
||||||
|
expiryAction.setSchedule(schedule);
|
||||||
|
expiryAction.setScheduleStart(expiryDate);
|
||||||
|
expiryAction.setScheduleIntervalCount(2);
|
||||||
|
expiryAction.setScheduleIntervalPeriod(IntervalPeriod.Minute);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TenantUtil.runAsDefaultTenant((TenantRunAsWork<Void>) () -> {
|
||||||
|
quickShareLinkExpiryActionPersister.saveQuickShareLinkExpiryAction(expiryAction);
|
||||||
|
scheduledPersistedActionService.saveSchedule(schedule);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new QuickShareLinkExpiryActionException("Couldn't create quick share link expiry action.", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("Quick share link expiry action is created for sharedId[" + sharedId + "] and it's scheduled to be executed on: "
|
||||||
|
+ expiryDate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteQuickShareLinkExpiryAction(QuickShareLinkExpiryAction linkExpiryAction)
|
||||||
|
{
|
||||||
|
ParameterCheck.mandatory("linkExpiryAction", linkExpiryAction);
|
||||||
|
|
||||||
|
NodeRef nodeRef = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Pair<String, NodeRef> pair = getTenantNodeRefFromSharedId(linkExpiryAction.getSharedId());
|
||||||
|
nodeRef =pair.getSecond();
|
||||||
|
}
|
||||||
|
catch (InvalidSharedIdException ex)
|
||||||
|
{
|
||||||
|
// do nothing, as the node might be already unshared
|
||||||
|
}
|
||||||
|
final NodeRef sharedNodeRef = nodeRef;
|
||||||
|
|
||||||
|
AuthenticationUtil.runAsSystem(() -> {
|
||||||
|
// Delete the expiry action and its related persisted schedule
|
||||||
|
deleteQuickShareLinkExpiryActionImpl(linkExpiryAction);
|
||||||
|
|
||||||
|
// As the method is called directly (ie. not via unshareContent method which removes the aspect properties),
|
||||||
|
// then we have to remove the 'expiryDate' property as well.
|
||||||
|
if (sharedNodeRef != null && nodeService.getProperty(sharedNodeRef, QuickShareModel.PROP_QSHARE_EXPIRY_DATE) != null)
|
||||||
|
{
|
||||||
|
behaviourFilter.disableBehaviour(sharedNodeRef, ContentModel.ASPECT_AUDITABLE);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
nodeService.removeProperty(sharedNodeRef, QuickShareModel.PROP_QSHARE_EXPIRY_DATE);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
behaviourFilter.enableBehaviour(sharedNodeRef, ContentModel.ASPECT_AUDITABLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes (hard deletes) the previously persisted {@link QuickShareLinkExpiryAction} and its related
|
||||||
|
* schedule {@link ScheduledPersistedAction} from the repository.
|
||||||
|
*/
|
||||||
|
protected void deleteQuickShareLinkExpiryAction(NodeRef linkExpiryActionNodeRef)
|
||||||
|
{
|
||||||
|
AuthenticationUtil.runAsSystem(() -> {
|
||||||
|
QuickShareLinkExpiryAction linkExpiryAction = quickShareLinkExpiryActionPersister.loadQuickShareLinkExpiryAction(linkExpiryActionNodeRef);
|
||||||
|
// Delete the expiry action and its related persisted schedule
|
||||||
|
deleteQuickShareLinkExpiryActionImpl(linkExpiryAction);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteQuickShareLinkExpiryActionImpl(QuickShareLinkExpiryAction linkExpiryAction)
|
||||||
|
{
|
||||||
|
// Attach the schedule if null. This could be the case when the Action is
|
||||||
|
// loaded from the quickShareLinkExpiryActionPersister
|
||||||
|
attachSchedule(linkExpiryAction);
|
||||||
|
if (linkExpiryAction.getSchedule() != null)
|
||||||
|
{
|
||||||
|
scheduledPersistedActionService.deleteSchedule(linkExpiryAction.getSchedule());
|
||||||
|
}
|
||||||
|
quickShareLinkExpiryActionPersister.deleteQuickShareLinkExpiryAction(linkExpiryAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
private QuickShareLinkExpiryAction attachSchedule(QuickShareLinkExpiryAction quickShareLinkExpiryAction)
|
||||||
|
{
|
||||||
|
if (quickShareLinkExpiryAction.getSchedule() == null)
|
||||||
|
{
|
||||||
|
ScheduledPersistedAction schedule = scheduledPersistedActionService.getSchedule(quickShareLinkExpiryAction);
|
||||||
|
quickShareLinkExpiryAction.setSchedule(schedule);
|
||||||
|
|
||||||
|
}
|
||||||
|
return quickShareLinkExpiryAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
private NodeRef getQuickShareLinkExpiryActionNode(String sharedId)
|
||||||
|
{
|
||||||
|
final QName expiryActionQName = QuickShareLinkExpiryActionImpl.createQName(sharedId);
|
||||||
|
return TenantUtil.runAsDefaultTenant(() -> quickShareLinkExpiryActionPersister.getQuickShareLinkExpiryActionNode(expiryActionQName));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkExpiryDate(Date expiryDate)
|
||||||
|
{
|
||||||
|
DateTime now = DateTime.now();
|
||||||
|
if (now.isAfter(expiryDate.getTime()))
|
||||||
|
{
|
||||||
|
throw new QuickShareLinkExpiryActionException.InvalidExpiryDateException("Invalid expiry date. Expiry date can't be in the past.");
|
||||||
|
}
|
||||||
|
if (expiryDatePeriod.getDuration(now, new DateTime(expiryDate)) < 1)
|
||||||
|
{
|
||||||
|
throw new QuickShareLinkExpiryActionException.InvalidExpiryDateException(
|
||||||
|
"Invalid expiry date. Expiry date can't be less then 1 " + expiryDatePeriod.getMessage() + '.');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A helper enum to get the number of days/hours/minutes between two dates.
|
||||||
|
*
|
||||||
|
* @author Jamal Kaabi-Mofrad
|
||||||
|
*/
|
||||||
|
private enum ExpiryDatePeriod
|
||||||
|
{
|
||||||
|
DAYS
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
int getDuration(DateTime now, DateTime expiryDate)
|
||||||
|
{
|
||||||
|
Interval interval = new Interval(now.withSecondOfMinute(0).withMillisOfSecond(0), expiryDate);
|
||||||
|
return interval.toPeriod(PeriodType.days()).getDays();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
String getMessage()
|
||||||
|
{
|
||||||
|
return "day (24 hours)";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
HOURS
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
int getDuration(DateTime now, DateTime expiryDate)
|
||||||
|
{
|
||||||
|
Interval interval = new Interval(now.withSecondOfMinute(0).withMillisOfSecond(0), expiryDate);
|
||||||
|
return interval.toPeriod(PeriodType.hours()).getHours();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
String getMessage()
|
||||||
|
{
|
||||||
|
return "hour";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
MINUTES
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public int getDuration(DateTime now, DateTime expiryDate)
|
||||||
|
{
|
||||||
|
Interval interval = new Interval(now.withMillisOfSecond(0), expiryDate);
|
||||||
|
return interval.toPeriod(PeriodType.minutes()).getMinutes();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
String getMessage()
|
||||||
|
{
|
||||||
|
return "minute";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
abstract int getDuration(DateTime now, DateTime expiryDate);
|
||||||
|
|
||||||
|
abstract String getMessage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,6 +28,7 @@ package org.alfresco.service.cmr.action.scheduled;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.alfresco.service.cmr.action.Action;
|
import org.alfresco.service.cmr.action.Action;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A service which handles the scheduling of the
|
* A service which handles the scheduling of the
|
||||||
@@ -64,6 +65,12 @@ public interface ScheduledPersistedActionService
|
|||||||
* null if it isn't currently scheduled.
|
* null if it isn't currently scheduled.
|
||||||
*/
|
*/
|
||||||
public ScheduledPersistedAction getSchedule(Action persistedAction);
|
public ScheduledPersistedAction getSchedule(Action persistedAction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the schedule for the specified action nodeRef, or
|
||||||
|
* null if it isn't currently scheduled.
|
||||||
|
*/
|
||||||
|
public ScheduledPersistedAction getSchedule(NodeRef persistedActionNodeRef);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all currently scheduled actions.
|
* Returns all currently scheduled actions.
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
package org.alfresco.service.cmr.quickshare;
|
package org.alfresco.service.cmr.quickshare;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data transfer object for holding quick share information.
|
* Data transfer object for holding quick share information.
|
||||||
@@ -38,6 +39,7 @@ public class QuickShareDTO implements Serializable
|
|||||||
private static final long serialVersionUID = -2163618127531335360L;
|
private static final long serialVersionUID = -2163618127531335360L;
|
||||||
|
|
||||||
private String sharedId;
|
private String sharedId;
|
||||||
|
private Date expiresAt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor
|
* Default constructor
|
||||||
@@ -45,8 +47,14 @@ public class QuickShareDTO implements Serializable
|
|||||||
* @param sharedId The quick share id
|
* @param sharedId The quick share id
|
||||||
*/
|
*/
|
||||||
public QuickShareDTO(String sharedId)
|
public QuickShareDTO(String sharedId)
|
||||||
|
{
|
||||||
|
this(sharedId, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public QuickShareDTO(String sharedId, Date expiresAt)
|
||||||
{
|
{
|
||||||
this.sharedId = sharedId;
|
this.sharedId = sharedId;
|
||||||
|
this.expiresAt = expiresAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,7 +62,7 @@ public class QuickShareDTO implements Serializable
|
|||||||
*/
|
*/
|
||||||
public QuickShareDTO(QuickShareDTO from)
|
public QuickShareDTO(QuickShareDTO from)
|
||||||
{
|
{
|
||||||
this(from.getId());
|
this(from.getId(), from.getExpiresAt());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,4 +72,9 @@ public class QuickShareDTO implements Serializable
|
|||||||
{
|
{
|
||||||
return this.sharedId;
|
return this.sharedId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Date getExpiresAt()
|
||||||
|
{
|
||||||
|
return expiresAt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Repository
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.service.cmr.quickshare;
|
||||||
|
|
||||||
|
import org.alfresco.service.cmr.action.Action;
|
||||||
|
import org.alfresco.service.cmr.action.scheduled.SchedulableAction;
|
||||||
|
import org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction;
|
||||||
|
import org.alfresco.service.namespace.QName;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This interface defines the details for a quick share link expiry action.
|
||||||
|
*
|
||||||
|
* @author Jamal Kaabi-Mofrad
|
||||||
|
*/
|
||||||
|
public interface QuickShareLinkExpiryAction extends Action, SchedulableAction, Serializable
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Gets the quick share sharedId.
|
||||||
|
*/
|
||||||
|
String getSharedId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the qualified name which uniquely identifies this quick share link expiry action.
|
||||||
|
*/
|
||||||
|
QName getActionQName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the schedule ({@link ScheduledPersistedAction} used to get the trigger details.
|
||||||
|
*/
|
||||||
|
ScheduledPersistedAction getSchedule();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the schedule ({@link ScheduledPersistedAction} used to set the trigger details.
|
||||||
|
*/
|
||||||
|
void setSchedule(ScheduledPersistedAction schedule);
|
||||||
|
}
|
@@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Repository
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.service.cmr.quickshare;
|
||||||
|
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.namespace.QName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This interface defines the persistence and the retrieval of {@link QuickShareLinkExpiryAction} actions.
|
||||||
|
*
|
||||||
|
* @author Jamal Kaabi-Mofrad
|
||||||
|
*/
|
||||||
|
public interface QuickShareLinkExpiryActionPersister
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Serializes the {@link QuickShareLinkExpiryAction} and stores it in
|
||||||
|
* the repository. The {@link QuickShareLinkExpiryAction}s saved in this way maybe
|
||||||
|
* retrieved using the <code>load()</code> method.
|
||||||
|
*
|
||||||
|
* @param linkExpiryAction The {@link QuickShareLinkExpiryAction} to be persisted.
|
||||||
|
*/
|
||||||
|
void saveQuickShareLinkExpiryAction(QuickShareLinkExpiryAction linkExpiryAction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a {@link QuickShareLinkExpiryAction} that has been stored
|
||||||
|
* in the repository using the <code>save()</code> method. If no
|
||||||
|
* {@link QuickShareLinkExpiryAction} exists in the repository with the specified
|
||||||
|
* QName then this method returns null.
|
||||||
|
*
|
||||||
|
* @param linkExpiryActionName The unique identifier used to specify the
|
||||||
|
* {@link QuickShareLinkExpiryAction} to retrieve.
|
||||||
|
* @return The NodeRef of the specified {@link QuickShareLinkExpiryAction} or null.
|
||||||
|
*/
|
||||||
|
NodeRef getQuickShareLinkExpiryActionNode(QName linkExpiryActionName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a {@link QuickShareLinkExpiryAction} that has been stored
|
||||||
|
* in the repository using the <code>save()</code> method. If no
|
||||||
|
* {@link QuickShareLinkExpiryAction} exists in the repository with the specified
|
||||||
|
* QName then this method returns null.
|
||||||
|
*
|
||||||
|
* @param linkExpiryActionName The unique identifier used to specify the
|
||||||
|
* {@link QuickShareLinkExpiryAction} to retrieve.
|
||||||
|
* @return The specified {@link QuickShareLinkExpiryAction} or null.
|
||||||
|
*/
|
||||||
|
QuickShareLinkExpiryAction loadQuickShareLinkExpiryAction(QName linkExpiryActionName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a {@link QuickShareLinkExpiryAction} that has been stored
|
||||||
|
* in the repository using the <code>save()</code> method. If no
|
||||||
|
* {@link QuickShareLinkExpiryAction} exists in the repository with the specified
|
||||||
|
* QName then this method returns null.
|
||||||
|
*
|
||||||
|
* @param linkExpiryActionNodeRef The nodeRef of the
|
||||||
|
* {@link QuickShareLinkExpiryAction} to retrieve.
|
||||||
|
* @return The specified {@link QuickShareLinkExpiryAction} or null.
|
||||||
|
*/
|
||||||
|
QuickShareLinkExpiryAction loadQuickShareLinkExpiryAction(NodeRef linkExpiryActionNodeRef);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the previously serialized {@link QuickShareLinkExpiryAction}
|
||||||
|
* from the repository. The {@link QuickShareLinkExpiryAction} will then no longer
|
||||||
|
* be available using the load methods.
|
||||||
|
*
|
||||||
|
* @param linkExpiryAction The {@link QuickShareLinkExpiryAction} to be deleted.
|
||||||
|
*/
|
||||||
|
void deleteQuickShareLinkExpiryAction(QuickShareLinkExpiryAction linkExpiryAction);
|
||||||
|
}
|
@@ -25,6 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.service.cmr.quickshare;
|
package org.alfresco.service.cmr.quickshare;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.alfresco.repo.quickshare.QuickShareServiceImpl.QuickShareEmailRequest;
|
import org.alfresco.repo.quickshare.QuickShareServiceImpl.QuickShareEmailRequest;
|
||||||
@@ -50,6 +51,15 @@ public interface QuickShareService
|
|||||||
*/
|
*/
|
||||||
public QuickShareDTO shareContent(NodeRef nodeRef) throws QuickShareDisabledException, InvalidNodeRefException;
|
public QuickShareDTO shareContent(NodeRef nodeRef) throws QuickShareDisabledException, InvalidNodeRefException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Share content identified by nodeRef and optionally set an expiry date for the shared link.
|
||||||
|
*
|
||||||
|
* @param nodeRef The NodeRef of the content to share
|
||||||
|
* @param expiryDate The expiry date of the shared link
|
||||||
|
* @return QuickDTO with details of the share
|
||||||
|
*/
|
||||||
|
QuickShareDTO shareContent(NodeRef nodeRef, Date expiryDate) throws QuickShareDisabledException, InvalidNodeRefException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get QuickShare related metadata for the given node.
|
* Get QuickShare related metadata for the given node.
|
||||||
*
|
*
|
||||||
@@ -105,4 +115,12 @@ public interface QuickShareService
|
|||||||
* @since 5.2
|
* @since 5.2
|
||||||
*/
|
*/
|
||||||
boolean isQuickShareEnabled();
|
boolean isQuickShareEnabled();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes (hard deletes) the previously persisted {@link QuickShareLinkExpiryAction} and its related
|
||||||
|
* schedule {@link org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction} from the repository.
|
||||||
|
*
|
||||||
|
* @param quickShareLinkExpiryAction The {@link QuickShareLinkExpiryAction} to be deleted.
|
||||||
|
*/
|
||||||
|
void deleteQuickShareLinkExpiryAction(QuickShareLinkExpiryAction quickShareLinkExpiryAction);
|
||||||
}
|
}
|
||||||
|
@@ -34,7 +34,9 @@ import static org.junit.Assert.fail;
|
|||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.model.QuickShareModel;
|
import org.alfresco.model.QuickShareModel;
|
||||||
@@ -47,10 +49,14 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
|||||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||||
import org.alfresco.repo.tenant.TenantUtil;
|
import org.alfresco.repo.tenant.TenantUtil;
|
||||||
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
|
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
|
||||||
|
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||||
|
import org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction;
|
||||||
|
import org.alfresco.service.cmr.action.scheduled.ScheduledPersistedActionService;
|
||||||
import org.alfresco.service.cmr.attributes.AttributeService;
|
import org.alfresco.service.cmr.attributes.AttributeService;
|
||||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
|
||||||
import org.alfresco.service.cmr.quickshare.InvalidSharedIdException;
|
import org.alfresco.service.cmr.quickshare.InvalidSharedIdException;
|
||||||
import org.alfresco.service.cmr.quickshare.QuickShareDTO;
|
import org.alfresco.service.cmr.quickshare.QuickShareDTO;
|
||||||
|
import org.alfresco.service.cmr.quickshare.QuickShareLinkExpiryAction;
|
||||||
|
import org.alfresco.service.cmr.quickshare.QuickShareLinkExpiryActionPersister;
|
||||||
import org.alfresco.service.cmr.quickshare.QuickShareService;
|
import org.alfresco.service.cmr.quickshare.QuickShareService;
|
||||||
import org.alfresco.service.cmr.repository.CopyService;
|
import org.alfresco.service.cmr.repository.CopyService;
|
||||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||||
@@ -64,6 +70,7 @@ import org.alfresco.util.test.junitrules.ApplicationContextInit;
|
|||||||
import org.alfresco.util.test.junitrules.TemporaryModels;
|
import org.alfresco.util.test.junitrules.TemporaryModels;
|
||||||
import org.alfresco.util.test.junitrules.TemporaryNodes;
|
import org.alfresco.util.test.junitrules.TemporaryNodes;
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
@@ -118,11 +125,15 @@ public class QuickShareServiceIntegrationTest
|
|||||||
private static CopyService copyService;
|
private static CopyService copyService;
|
||||||
private static NodeService nodeService;
|
private static NodeService nodeService;
|
||||||
private static QuickShareService quickShareService;
|
private static QuickShareService quickShareService;
|
||||||
private static DictionaryService dictionaryService;
|
private static QuickShareService directDuickShareService;
|
||||||
private static Repository repository;
|
private static Repository repository;
|
||||||
private static AttributeService attributeService;
|
private static AttributeService attributeService;
|
||||||
private static PermissionService permissionService;
|
private static PermissionService permissionService;
|
||||||
private static NodeArchiveService nodeArchiveService;
|
private static NodeArchiveService nodeArchiveService;
|
||||||
|
private static ScheduledPersistedActionService scheduledPersistedActionService;
|
||||||
|
private static QuickShareLinkExpiryActionPersister quickShareLinkExpiryActionPersister;
|
||||||
|
private static RetryingTransactionHelper transactionHelper;
|
||||||
|
private static Properties globalProperties;
|
||||||
|
|
||||||
private static AlfrescoPerson user1 = new AlfrescoPerson(testContext, "UserOne");
|
private static AlfrescoPerson user1 = new AlfrescoPerson(testContext, "UserOne");
|
||||||
private static AlfrescoPerson user2 = new AlfrescoPerson(testContext, "UserTwo");
|
private static AlfrescoPerson user2 = new AlfrescoPerson(testContext, "UserTwo");
|
||||||
@@ -151,13 +162,17 @@ public class QuickShareServiceIntegrationTest
|
|||||||
ApplicationContext ctx = testContext.getApplicationContext();
|
ApplicationContext ctx = testContext.getApplicationContext();
|
||||||
|
|
||||||
copyService = ctx.getBean("CopyService", CopyService.class);
|
copyService = ctx.getBean("CopyService", CopyService.class);
|
||||||
dictionaryService = ctx.getBean("dictionaryService", DictionaryService.class);
|
|
||||||
nodeService = ctx.getBean("NodeService", NodeService.class);
|
nodeService = ctx.getBean("NodeService", NodeService.class);
|
||||||
|
directDuickShareService = ctx.getBean("quickShareService", QuickShareService.class);
|
||||||
quickShareService = ctx.getBean("QuickShareService", QuickShareService.class);
|
quickShareService = ctx.getBean("QuickShareService", QuickShareService.class);
|
||||||
repository = ctx.getBean("repositoryHelper", Repository.class);
|
repository = ctx.getBean("repositoryHelper", Repository.class);
|
||||||
attributeService = ctx.getBean("AttributeService", AttributeService.class);
|
attributeService = ctx.getBean("AttributeService", AttributeService.class);
|
||||||
permissionService = ctx.getBean("PermissionService", PermissionService.class);
|
permissionService = ctx.getBean("PermissionService", PermissionService.class);
|
||||||
nodeArchiveService = ctx.getBean("nodeArchiveService", NodeArchiveService.class);
|
nodeArchiveService = ctx.getBean("nodeArchiveService", NodeArchiveService.class);
|
||||||
|
scheduledPersistedActionService = ctx.getBean("scheduledPersistedActionService", ScheduledPersistedActionService.class);
|
||||||
|
quickShareLinkExpiryActionPersister = ctx.getBean("quickShareLinkExpiryActionPersister", QuickShareLinkExpiryActionPersister.class);
|
||||||
|
transactionHelper = ctx.getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
|
||||||
|
globalProperties = ctx.getBean("global-properties", Properties.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before public void createTestData()
|
@Before public void createTestData()
|
||||||
@@ -219,7 +234,7 @@ public class QuickShareServiceIntegrationTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test public void unshare() {
|
@Test public void unshare() {
|
||||||
final QuickShareDTO dto = share(testNode, user1.getUsername());
|
final QuickShareDTO dto = share(testNode, user1.getUsername());
|
||||||
unshare(dto.getId(), user1.getUsername());
|
unshare(dto.getId(), user1.getUsername());
|
||||||
AuthenticationUtil.runAsSystem(new RunAsWork<Void>(){
|
AuthenticationUtil.runAsSystem(new RunAsWork<Void>(){
|
||||||
|
|
||||||
@@ -359,18 +374,16 @@ public class QuickShareServiceIntegrationTest
|
|||||||
}, userName);
|
}, userName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private QuickShareDTO share(final NodeRef nodeRef, String username)
|
private QuickShareDTO share(final NodeRef nodeRef, final String username)
|
||||||
{
|
{
|
||||||
return AuthenticationUtil.runAs(new RunAsWork<QuickShareDTO>()
|
return share(nodeRef, username, null);
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public QuickShareDTO doWork() throws Exception
|
|
||||||
{
|
|
||||||
return quickShareService.shareContent(nodeRef);
|
|
||||||
}
|
|
||||||
}, username);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private QuickShareDTO share(final NodeRef nodeRef, final String username, final Date expiryDate)
|
||||||
|
{
|
||||||
|
return AuthenticationUtil.runAs(() -> quickShareService.shareContent(nodeRef, expiryDate), username);
|
||||||
|
}
|
||||||
|
|
||||||
@Test public void getMetadataFromShareId()
|
@Test public void getMetadataFromShareId()
|
||||||
{
|
{
|
||||||
QuickShareDTO dto = share(testNode, user1.getUsername());
|
QuickShareDTO dto = share(testNode, user1.getUsername());
|
||||||
@@ -587,4 +600,317 @@ public class QuickShareServiceIntegrationTest
|
|||||||
assertEquals("The modifier has changed after sharing.", user1.getUsername(), modifier);
|
assertEquals("The modifier has changed after sharing.", user1.getUsername(), modifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the quick share link expiry date action.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testSharedLinkExpiryScheduling() throws Exception
|
||||||
|
{
|
||||||
|
// First record the number of available schedules
|
||||||
|
final int numOfSchedules = listSchedules();
|
||||||
|
|
||||||
|
// 1 day from now
|
||||||
|
Date expiryDate = DateTime.now().plusDays(1).toDate();
|
||||||
|
QuickShareDTO quickShareDTO = share(testNode, user1.getUsername(), expiryDate);
|
||||||
|
assertTrue(hasQuickShareAspect(testNode));
|
||||||
|
assertEquals(quickShareDTO.getId(), getProperty(testNode, QuickShareModel.PROP_QSHARE_SHAREDID));
|
||||||
|
assertNotNull(quickShareDTO.getExpiresAt());
|
||||||
|
assertEquals(expiryDate, quickShareDTO.getExpiresAt());
|
||||||
|
// Check that the expiry action is persisted
|
||||||
|
QuickShareLinkExpiryAction expiryAction = getExpiryActionAndAttachSchedule(quickShareDTO.getId());
|
||||||
|
assertEquals(quickShareDTO.getId(), expiryAction.getSharedId());
|
||||||
|
assertEquals(quickShareDTO.getExpiresAt(), expiryAction.getScheduleStart());
|
||||||
|
// assertNull("We haven't set interval count.", expiryAction.getScheduleIntervalCount());
|
||||||
|
//assertNull("We haven't set interval period.", expiryAction.getScheduleIntervalPeriod());
|
||||||
|
|
||||||
|
// Try to share the already shared node with a different expiry date.
|
||||||
|
// This basically will update the expiry action start time
|
||||||
|
expiryDate = DateTime.now().plusDays(7).toDate();
|
||||||
|
quickShareDTO = share(testNode, user1.getUsername(), expiryDate);
|
||||||
|
assertEquals(expiryDate, quickShareDTO.getExpiresAt());
|
||||||
|
assertEquals(expiryDate, getProperty(testNode, QuickShareModel.PROP_QSHARE_EXPIRY_DATE));
|
||||||
|
assertTrue(hasQuickShareAspect(testNode));
|
||||||
|
assertEquals(quickShareDTO.getId(), getProperty(testNode, QuickShareModel.PROP_QSHARE_SHAREDID));
|
||||||
|
// Check that the expiry action is persisted
|
||||||
|
expiryAction = getExpiryActionAndAttachSchedule(quickShareDTO.getId());
|
||||||
|
assertEquals(quickShareDTO.getId(), expiryAction.getSharedId());
|
||||||
|
assertEquals(quickShareDTO.getExpiresAt(), expiryAction.getScheduleStart());
|
||||||
|
//assertNull("We haven't set interval count.", expiryAction.getScheduleIntervalCount());
|
||||||
|
// assertNull("We haven't set interval period.", expiryAction.getScheduleIntervalPeriod());
|
||||||
|
|
||||||
|
// Delete the expiry action
|
||||||
|
deleteExpiryAction(expiryAction);
|
||||||
|
|
||||||
|
// Check that the expiry action has been deleted
|
||||||
|
QuickShareLinkExpiryAction deletedExpiryAction = getExpiryAction(quickShareDTO.getId());
|
||||||
|
assertNull(deletedExpiryAction);
|
||||||
|
assertNull(getProperty(testNode, QuickShareModel.PROP_QSHARE_EXPIRY_DATE));
|
||||||
|
// Unshare
|
||||||
|
unshare(quickShareDTO.getId(), user1.getUsername());
|
||||||
|
|
||||||
|
// Share the testNode, with expiry date of 1 day from now
|
||||||
|
expiryDate = DateTime.now().plusDays(1).toDate();
|
||||||
|
quickShareDTO = share(testNode, user1.getUsername(), expiryDate);
|
||||||
|
assertTrue(hasQuickShareAspect(testNode));
|
||||||
|
expiryAction = getExpiryActionAndAttachSchedule(quickShareDTO.getId());
|
||||||
|
assertEquals(expiryDate, expiryAction.getScheduleStart());
|
||||||
|
assertEquals(numOfSchedules + 1, listSchedules());
|
||||||
|
// Now update the schedule to be executed in 5 seconds.
|
||||||
|
expiryAction.setScheduleStart(DateTime.now().plusSeconds(5).toDate());
|
||||||
|
// Here we'll bypass the QuickShareService in order to force the new time.
|
||||||
|
// As the QuickShareService by default will enforce the expiry date to not be less than 24 hours.
|
||||||
|
forceSaveNewExpiryTime(expiryAction);
|
||||||
|
|
||||||
|
// wait 10 seconds
|
||||||
|
Thread.sleep(10000L);
|
||||||
|
// Check that the expiry action was successful and it removed the shared link
|
||||||
|
assertFalse(hasQuickShareAspect(testNode));
|
||||||
|
// Also check the expiry date property is removed
|
||||||
|
assertNull(getProperty(testNode, QuickShareModel.PROP_QSHARE_EXPIRY_DATE));
|
||||||
|
// Check that the persisted expiry action is removed
|
||||||
|
assertNull(getExpiryAction(quickShareDTO.getId()));
|
||||||
|
// Check that the persisted schedule is removed as well
|
||||||
|
assertEquals(numOfSchedules, listSchedules());
|
||||||
|
|
||||||
|
// Share the testNode, with expiry date of 1 day from now
|
||||||
|
expiryDate = DateTime.now().plusDays(1).toDate();
|
||||||
|
quickShareDTO = share(testNode, user1.getUsername(), expiryDate);
|
||||||
|
assertTrue(hasQuickShareAspect(testNode));
|
||||||
|
expiryAction = getExpiryActionAndAttachSchedule(quickShareDTO.getId());
|
||||||
|
assertEquals(expiryDate, expiryAction.getScheduleStart());
|
||||||
|
|
||||||
|
// Delete the shared testNode as user1
|
||||||
|
AuthenticationUtil.runAs(() -> {
|
||||||
|
nodeService.deleteNode(testNode);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}, user1.getUsername());
|
||||||
|
|
||||||
|
// Check that the persisted expiry action is removed, as we have deleted the source node
|
||||||
|
assertNull(getExpiryAction(quickShareDTO.getId()));
|
||||||
|
// Check that the persisted schedule is removed as well
|
||||||
|
assertEquals(numOfSchedules, listSchedules());
|
||||||
|
|
||||||
|
// Restore the testNode as user1
|
||||||
|
AuthenticationUtil.runAs(() -> {
|
||||||
|
final NodeRef archivedNode = nodeArchiveService.getArchivedNode(testNode);
|
||||||
|
RestoreNodeReport restoreNodeReport = nodeArchiveService.restoreArchivedNode(archivedNode);
|
||||||
|
assertNotNull(restoreNodeReport);
|
||||||
|
assertTrue(restoreNodeReport.getStatus() == RestoreStatus.SUCCESS);
|
||||||
|
testNode = restoreNodeReport.getRestoredNodeRef();
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}, user1.getUsername());
|
||||||
|
|
||||||
|
// Check that restoring the node hasn't brought back the shared aspect or the persisted expiry action
|
||||||
|
assertFalse(hasQuickShareAspect(testNode));
|
||||||
|
assertNull(getExpiryAction(quickShareDTO.getId()));
|
||||||
|
assertEquals(numOfSchedules, listSchedules());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test date validator for the quick share link expiry date action.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testSharedLinkExpiryDateValidator() throws Exception
|
||||||
|
{
|
||||||
|
// Try to share with invalid time - passed time
|
||||||
|
try
|
||||||
|
{
|
||||||
|
share(testNode, user1.getUsername(), DateTime.now().minusDays(1).toDate());
|
||||||
|
fail("Should have failed as the expiry date is invalid (passed time).");
|
||||||
|
}
|
||||||
|
catch (QuickShareLinkExpiryActionException.InvalidExpiryDateException ex)
|
||||||
|
{
|
||||||
|
// Expected
|
||||||
|
}
|
||||||
|
|
||||||
|
final String defaultExpiryDatePeriod = globalProperties.getProperty("system.quickshare.expiry_date.enforce.period");
|
||||||
|
|
||||||
|
// Test expiry date period enforcement
|
||||||
|
try
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Set the expiry date period enforcement to Days
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
((QuickShareServiceImpl) directDuickShareService).setExpiryDatePeriod("DAYS");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Try to share with invalid time - less than 1 day
|
||||||
|
share(testNode, user1.getUsername(), DateTime.now().plusHours(1).toDate());
|
||||||
|
fail("Should have failed as the expiry date is invalid (less than 1 day).");
|
||||||
|
}
|
||||||
|
catch (QuickShareLinkExpiryActionException.InvalidExpiryDateException ex)
|
||||||
|
{
|
||||||
|
// Expected
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Try to share with invalid time - less than 1 day
|
||||||
|
share(testNode, user1.getUsername(), DateTime.now().plusMinutes(30).toDate());
|
||||||
|
fail("Should have failed as the expiry date is invalid (less than 1 day).");
|
||||||
|
}
|
||||||
|
catch (QuickShareLinkExpiryActionException.InvalidExpiryDateException ex)
|
||||||
|
{
|
||||||
|
// Expected
|
||||||
|
}
|
||||||
|
// Set the expiry date to be in 24 hours
|
||||||
|
Date expiryDate = DateTime.now().plusHours(24).toDate();
|
||||||
|
QuickShareDTO quickShareDTO = share(testNode, user1.getUsername(), expiryDate);
|
||||||
|
assertTrue(hasQuickShareAspect(testNode));
|
||||||
|
QuickShareLinkExpiryAction expiryAction = getExpiryActionAndAttachSchedule(quickShareDTO.getId());
|
||||||
|
assertEquals(expiryDate, expiryAction.getScheduleStart());
|
||||||
|
// Unshare
|
||||||
|
quickShareService.unshareContent(quickShareDTO.getId());
|
||||||
|
|
||||||
|
// Set the expiry date to be next year
|
||||||
|
expiryDate = DateTime.now().plusYears(1).toDate();
|
||||||
|
quickShareDTO = share(testNode, user1.getUsername(), expiryDate);
|
||||||
|
assertTrue(hasQuickShareAspect(testNode));
|
||||||
|
expiryAction = getExpiryActionAndAttachSchedule(quickShareDTO.getId());
|
||||||
|
assertEquals(expiryDate, expiryAction.getScheduleStart());
|
||||||
|
// Unshare
|
||||||
|
quickShareService.unshareContent(quickShareDTO.getId());
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Set the expiry date period enforcement to Hours
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
((QuickShareServiceImpl) directDuickShareService).setExpiryDatePeriod("HOURS");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Try to share with invalid time - less than 1 hour
|
||||||
|
share(testNode, user1.getUsername(), DateTime.now().plusMinutes(30).toDate());
|
||||||
|
fail("Should have failed as the expiry date is invalid (less than 1 hour).");
|
||||||
|
}
|
||||||
|
catch (QuickShareLinkExpiryActionException.InvalidExpiryDateException ex)
|
||||||
|
{
|
||||||
|
// Expected
|
||||||
|
}
|
||||||
|
// Set the expiry date to be in the next hour
|
||||||
|
Date expiryDate = DateTime.now().plusHours(1).toDate();
|
||||||
|
QuickShareDTO quickShareDTO = share(testNode, user1.getUsername(), expiryDate);
|
||||||
|
assertTrue(hasQuickShareAspect(testNode));
|
||||||
|
QuickShareLinkExpiryAction expiryAction = getExpiryActionAndAttachSchedule(quickShareDTO.getId());
|
||||||
|
assertEquals(expiryDate, expiryAction.getScheduleStart());
|
||||||
|
// Unshare
|
||||||
|
quickShareService.unshareContent(quickShareDTO.getId());
|
||||||
|
|
||||||
|
// Set the expiry date to be in the next 2 days, even though we did set the date period to HOURS.
|
||||||
|
expiryDate = DateTime.now().plusDays(2).toDate();
|
||||||
|
quickShareDTO = share(testNode, user1.getUsername(), expiryDate);
|
||||||
|
assertTrue(hasQuickShareAspect(testNode));
|
||||||
|
expiryAction = getExpiryActionAndAttachSchedule(quickShareDTO.getId());
|
||||||
|
assertEquals(expiryDate, expiryAction.getScheduleStart());
|
||||||
|
// Unshare
|
||||||
|
quickShareService.unshareContent(quickShareDTO.getId());
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Set the expiry date period enforcement to Minutes
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
((QuickShareServiceImpl) directDuickShareService).setExpiryDatePeriod("MINUTES");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Try to share with invalid time - less than 1 minute
|
||||||
|
share(testNode, user1.getUsername(), DateTime.now().plusSeconds(10).toDate());
|
||||||
|
fail("Should have failed as the expiry date is invalid (less than 1 minute).");
|
||||||
|
}
|
||||||
|
catch (QuickShareLinkExpiryActionException.InvalidExpiryDateException ex)
|
||||||
|
{
|
||||||
|
// Expected
|
||||||
|
}
|
||||||
|
// Set the expiry date to be in 5 minutes time
|
||||||
|
Date expiryDate = DateTime.now().plusMinutes(5).toDate();
|
||||||
|
QuickShareDTO quickShareDTO = share(testNode, user1.getUsername(), expiryDate);
|
||||||
|
assertTrue(hasQuickShareAspect(testNode));
|
||||||
|
QuickShareLinkExpiryAction expiryAction = getExpiryActionAndAttachSchedule(quickShareDTO.getId());
|
||||||
|
assertEquals(expiryDate, expiryAction.getScheduleStart());
|
||||||
|
// Unshare
|
||||||
|
quickShareService.unshareContent(quickShareDTO.getId());
|
||||||
|
|
||||||
|
// Set the expiry date to be in 60 days
|
||||||
|
expiryDate = DateTime.now().plusDays(60).toDate();
|
||||||
|
quickShareDTO = share(testNode, user1.getUsername(), expiryDate);
|
||||||
|
assertTrue(hasQuickShareAspect(testNode));
|
||||||
|
expiryAction = getExpiryActionAndAttachSchedule(quickShareDTO.getId());
|
||||||
|
assertEquals(expiryDate, expiryAction.getScheduleStart());
|
||||||
|
// Unshare
|
||||||
|
quickShareService.unshareContent(quickShareDTO.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
((QuickShareServiceImpl) directDuickShareService).setExpiryDatePeriod(defaultExpiryDatePeriod);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private QuickShareLinkExpiryAction getExpiryActionAndAttachSchedule(String sharedId)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Check that the expiry action is persisted
|
||||||
|
QuickShareLinkExpiryAction expiryAction = getExpiryAction(sharedId);
|
||||||
|
assertNotNull(expiryAction);
|
||||||
|
assertNotNull("Expiry action should have been persisted.", expiryAction.getNodeRef());
|
||||||
|
assertNull("The schedule hasn't been attached yet.", expiryAction.getSchedule());
|
||||||
|
ScheduledPersistedAction scheduledPersistedAction = getSchedule(expiryAction);
|
||||||
|
assertNotNull("Scheduled action should have been persisted.", scheduledPersistedAction);
|
||||||
|
//Attach the schedule
|
||||||
|
expiryAction.setSchedule(scheduledPersistedAction);
|
||||||
|
|
||||||
|
return expiryAction;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private QuickShareLinkExpiryAction getExpiryAction(final String sharedId)
|
||||||
|
{
|
||||||
|
return AuthenticationUtil.runAsSystem(
|
||||||
|
() -> quickShareLinkExpiryActionPersister.loadQuickShareLinkExpiryAction(QuickShareLinkExpiryActionImpl.createQName(sharedId)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private ScheduledPersistedAction getSchedule(final QuickShareLinkExpiryAction linkExpiryAction)
|
||||||
|
{
|
||||||
|
return AuthenticationUtil.runAsSystem(
|
||||||
|
() -> scheduledPersistedActionService.getSchedule(linkExpiryAction));
|
||||||
|
}
|
||||||
|
|
||||||
|
private int listSchedules()
|
||||||
|
{
|
||||||
|
return AuthenticationUtil.runAsSystem(() -> scheduledPersistedActionService.listSchedules().size());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteExpiryAction(final QuickShareLinkExpiryAction linkExpiryAction)
|
||||||
|
{
|
||||||
|
transactionHelper.doInTransaction(() -> {
|
||||||
|
quickShareService.deleteQuickShareLinkExpiryAction(linkExpiryAction);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasQuickShareAspect(NodeRef nodeRef)
|
||||||
|
{
|
||||||
|
return AuthenticationUtil.runAsSystem(() -> nodeService.hasAspect(nodeRef, QuickShareModel.ASPECT_QSHARE));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Serializable getProperty(NodeRef nodeRef, QName property)
|
||||||
|
{
|
||||||
|
return AuthenticationUtil.runAsSystem(() -> nodeService.getProperty(nodeRef, property));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void forceSaveNewExpiryTime(final QuickShareLinkExpiryAction linkExpiryAction)
|
||||||
|
{
|
||||||
|
transactionHelper.doInTransaction(() -> {
|
||||||
|
AuthenticationUtil.runAsSystem(() -> {
|
||||||
|
quickShareLinkExpiryActionPersister.saveQuickShareLinkExpiryAction(linkExpiryAction);
|
||||||
|
scheduledPersistedActionService.saveSchedule(linkExpiryAction.getSchedule());
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user