ALF-9155 Links service listing and finding in Java, plus tests

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29527 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Nick Burch
2011-08-03 14:45:14 +00:00
parent 7f54672204
commit 2e6df326bf
13 changed files with 2052 additions and 127 deletions

View File

@@ -10,6 +10,7 @@
<import resource="classpath*:alfresco/portlets-context.xml"/>
<import resource="classpath:alfresco/blog-context.xml"/>
<import resource="classpath:alfresco/calendar-services-context.xml"/>
<import resource="classpath:alfresco/links-services-context.xml"/>
<import resource="classpath:alfresco/comment-services-context.xml"/>
<import resource="classpath:alfresco/rating-services-context.xml"/>
<import resource="classpath:alfresco/rendition-services-context.xml"/>

View File

@@ -69,6 +69,9 @@ Inbound settings from iBatis
<!--GetChildren CQ (currently used by FileFolderService.list / PersonService.getPeople) -->
<typeAlias alias="FilterSortNode" type="org.alfresco.repo.node.getchildren.FilterSortNodeEntity"/>
<!--GetChildren by Auditable CQ -->
<typeAlias alias="NodeBackedEntity" type="org.alfresco.repo.query.NodeBackedEntity"/>
<!-- Authority CQ -->
<typeAlias alias="AuthorityInfo" type="org.alfresco.repo.security.authority.AuthorityInfoEntity"/>
@@ -191,6 +194,7 @@ Inbound settings from iBatis
<!-- Canned queries -->
<mapper resource="alfresco/ibatis/#resource.dialect#/query-test-common-SqlMap.xml"/>
<mapper resource="alfresco/ibatis/#resource.dialect#/query-usages-common-SqlMap.xml"/>
<mapper resource="alfresco/ibatis/#resource.dialect#/query-auditable-common-SqlMap.xml"/>
<mapper resource="alfresco/ibatis/#resource.dialect#/query-authorities-common-SqlMap.xml"/>
<mapper resource="alfresco/ibatis/#resource.dialect#/query-blogs-common-SqlMap.xml"/>
<mapper resource="alfresco/ibatis/#resource.dialect#/query-calendar-common-SqlMap.xml"/>

View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="alfresco.query.auditable">
<!-- -->
<!-- Result Maps -->
<!-- -->
<resultMap id="result_NodeBackedEntity" type="NodeBackedEntity">
<id property="id" column="id" jdbcType="BIGINT" javaType="java.lang.Long"/>
<result property="name" column="name" jdbcType="VARCHAR" javaType="java.lang.String"/>
<association property="node" resultMap="alfresco.node.result_Node"/>
</resultMap>
<!-- GetChildrenAuditable Canned Query (model-specific) - note: date properties are stored as ISO 8061 string -->
<select id="select_GetChildrenAuditableCannedQuery" parameterType="NodeBackedEntity" resultMap="result_NodeBackedEntity">
select
childNode.id as id,
childStore.protocol as protocol,
childStore.identifier as identifier,
childNode.uuid as uuid,
childNode.audit_created as audit_created,
childNode.audit_creator as audit_creator,
childNode.audit_modified as audit_modified,
childNode.audit_modifier as audit_modifier,
prop_name.string_value as name
from
alf_child_assoc assoc
join alf_node childNode on (childNode.id = assoc.child_node_id)
join alf_store childStore on (childStore.id = childNode.store_id)
left join alf_node_properties prop_name on (prop_name.node_id = childNode.id and prop_name.qname_id = #{nameQNameId})
where
assoc.parent_node_id = #{parentNodeId}
and childNode.type_qname_id = #{contentTypeQNameId}
</select>
</mapper>

View File

@@ -0,0 +1,64 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<!-- Links Service -->
<bean id="LinksService" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>org.alfresco.service.cmr.links.LinksService</value>
</property>
<property name="target">
<ref bean="linksService" />
</property>
<property name="interceptorNames">
<list>
<idref local="LinksService_transaction" />
<idref bean="AuditMethodInterceptor" />
<idref bean="exceptionTranslator" />
<idref bean="LinksService_security" />
</list>
</property>
</bean>
<!-- Links service transaction bean -->
<bean id="LinksService_transaction"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="*">${server.transaction.mode.default}</prop>
</props>
</property>
</bean>
<!-- List of Links Canned queries -->
<bean id="linksCannedQueryRegistry" class="org.alfresco.util.registry.NamedObjectRegistry">
<property name="storageType" value="org.alfresco.query.CannedQueryFactory"/>
</bean>
<!-- The regular GetChildren Auditable Canned Query Factory -->
<bean name="linksGetChildrenCannedQueryFactory" class="org.alfresco.repo.node.getchildren.GetChildrenAuditableCannedQueryFactory">
<property name="registry" ref="linksCannedQueryRegistry"/>
<property name="tenantService" ref="tenantService"/>
<property name="nodeDAO" ref="nodeDAO"/>
<property name="qnameDAO" ref="qnameDAO"/>
<property name="cannedQueryDAO" ref="cannedQueryDAO"/>
<property name="methodSecurity" ref="LinksService_security_listLinks"/>
</bean>
<!-- Links Service base bean -->
<bean id="linksService" class="org.alfresco.repo.links.LinksServiceImpl">
<property name="nodeService" ref="NodeService"/>
<property name="siteService" ref="SiteService"/>
<property name="searchService" ref="SearchService"/>
<property name="taggingService" ref="TaggingService"/>
<property name="transactionService" ref="transactionService" />
<property name="cannedQueryRegistry" ref="linksCannedQueryRegistry" />
<property name="namespaceService" ref="NamespaceService"/>
<property name="dictionaryService" ref="dictionaryService"/>
</bean>
</beans>

View File

@@ -1003,6 +1003,33 @@
</bean>
<!-- ==================== -->
<!-- The Links Service -->
<!-- ==================== -->
<!-- The links service itself does not require any security restrictions, -->
<!-- they are imposed by the node and site services it uses to do its work. -->
<bean id="LinksService_security" class="org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor" />
<!-- The canned queries that the links service uses do however need to check -->
<bean id="LinksService_CannedQuery_security" class="org.alfresco.repo.security.permissions.impl.acegi.MethodSecurityInterceptor">
<property name="authenticationManager"><ref bean="authenticationManager"/></property>
<property name="accessDecisionManager"><ref local="accessDecisionManager"/></property>
<property name="afterInvocationManager"><ref local="afterInvocationManager"/></property>
<property name="objectDefinitionSource">
<value>
org.alfresco.service.cmr.links.LinksService.listLinks=ACL_ALLOW,AFTER_ACL_NODE.sys:base.ReadProperties
</value>
</property>
</bean>
<bean id="LinksService_security_listLinks" class="org.alfresco.repo.security.permissions.impl.acegi.MethodSecurityBean">
<property name="methodSecurityInterceptor" ref="LinksService_CannedQuery_security" />
<property name="service" value="org.alfresco.service.cmr.links.LinksService" />
<property name="methodName" value="listLinks" />
</bean>
<!-- ======================== -->
<!-- Repository Admin Service -->
<!-- ======================== -->

View File

@@ -20,14 +20,12 @@ package org.alfresco.repo.calendar;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.query.CannedQueryFactory;
import org.alfresco.query.CannedQueryResults;
@@ -38,8 +36,7 @@ import org.alfresco.repo.calendar.cannedqueries.GetCalendarEntriesCannedQuery;
import org.alfresco.repo.calendar.cannedqueries.GetCalendarEntriesCannedQueryFactory;
import org.alfresco.repo.node.getchildren.GetChildrenCannedQuery;
import org.alfresco.repo.node.getchildren.GetChildrenCannedQueryFactory;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.repo.site.SiteServiceImpl;
import org.alfresco.service.cmr.calendar.CalendarEntry;
import org.alfresco.service.cmr.calendar.CalendarService;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -75,6 +72,7 @@ public class CalendarServiceImpl implements CalendarService
/**
* The logger
*/
@SuppressWarnings("unused")
private static Log logger = LogFactory.getLog(CalendarServiceImpl.class);
private NodeService nodeService;
@@ -122,107 +120,9 @@ public class CalendarServiceImpl implements CalendarService
*/
protected NodeRef getSiteCalendarContainer(final String siteShortName, boolean create)
{
// Does the site exist?
if(siteService.getSite(siteShortName) == null) {
// Either the site doesn't exist, or you're not allowed to see it
if(! create)
{
// Just say there's no container
return null;
}
else
{
// We can't create on a non-existant site
throw new AlfrescoRuntimeException(
"Unable to create the calendar container from a hidden or non-existant site"
);
}
}
// Check about the container
if(! siteService.hasContainer(siteShortName, CALENDAR_COMPONENT))
{
if(create)
{
if(transactionService.isReadOnly())
{
throw new AlfrescoRuntimeException(
"Unable to create the calendar container from a read only transaction"
);
}
// Have the site container created
if(logger.isDebugEnabled())
{
logger.debug("Creating " + CALENDAR_COMPONENT + " container in site " + siteShortName);
}
NodeRef container = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<NodeRef>()
{
public NodeRef doWork() throws Exception
{
// Create the site container
NodeRef container = siteService.createContainer(
siteShortName, CALENDAR_COMPONENT, null, null
);
// Done
return container;
}
}, AuthenticationUtil.getSystemUserName()
);
if(logger.isDebugEnabled())
{
logger.debug("Created " + CALENDAR_COMPONENT + " as " + container + " for " + siteShortName);
}
// Container is setup and ready to use
return container;
}
else
{
// No container for this site, and not allowed to create
// Have the site container created
if(logger.isDebugEnabled())
{
logger.debug("No " + CALENDAR_COMPONENT + " component in " + siteShortName + " and not creating");
}
return null;
}
}
else
{
// Container is already there
final NodeRef container = siteService.getContainer(siteShortName, CALENDAR_COMPONENT);
// Ensure the calendar container has the tag scope aspect applied to it
if(! taggingService.isTagScope(container))
{
if(logger.isDebugEnabled())
{
logger.debug("Attaching tag scope to " + CALENDAR_COMPONENT + " " + container.toString() + " for " + siteShortName);
}
AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Void>() {
public Void doWork() throws Exception
{
transactionService.getRetryingTransactionHelper().doInTransaction(
new RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
// Add the tag scope aspect
taggingService.addTagScope(container);
return null;
}
}, false, true
);
return null;
}
}, AuthenticationUtil.getSystemUserName());
}
// Container is appropriately setup and configured
return container;
}
return SiteServiceImpl.getSiteContainer(
siteShortName, CALENDAR_COMPONENT, create,
siteService, transactionService, taggingService);
}
private void handleTags(CalendarEntry entry)

View File

@@ -36,9 +36,6 @@ public class CalendarEntity extends NodeBackedEntity
private String recurrenceLastMeeting;
// Supplemental query-related parameters
private Long parentNodeId;
private Long nameQNameId;
private Long contentTypeQNameId;
private Long fromDateQNameId;
private Long toDateQNameId;
private Long recurrenceRuleQNameId;
@@ -56,10 +53,7 @@ public class CalendarEntity extends NodeBackedEntity
Long fromDateQNameId, Long toDateQNameId,
Long recurrenceRuleQNameId, Long recurrenceLastMeetingQNameId)
{
super();
this.parentNodeId = parentNodeId;
this.nameQNameId = nameQNameId;
this.contentTypeQNameId = contentTypeQNameId;
super(parentNodeId, nameQNameId, contentTypeQNameId);
this.fromDateQNameId = fromDateQNameId;
this.toDateQNameId = toDateQNameId;
this.recurrenceRuleQNameId = recurrenceRuleQNameId;
@@ -118,21 +112,6 @@ public class CalendarEntity extends NodeBackedEntity
// Supplemental query-related parameters
public Long getParentNodeId()
{
return parentNodeId;
}
public Long getNameQNameId()
{
return nameQNameId;
}
public Long getContentTypeQNameId()
{
return contentTypeQNameId;
}
public Long getFromDateQNameId()
{
return fromDateQNameId;

View File

@@ -0,0 +1,174 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* 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/>.
*/
package org.alfresco.repo.links;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.alfresco.service.cmr.links.LinkInfo;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* An implementation of {@link LinkInfo}
*
* @author Nick Burch (based on existing webscript controllers in the REST API)
* @since 4.0
*/
public class LinkInfoImpl implements LinkInfo
{
private NodeRef nodeRef;
private NodeRef containerNodeRef;
private String systemName;
private String title;
private String description;
private String url;
private String creator;
private Date createdAt;
private Date modifiedAt;
private boolean internal;
private List<String> tags = new ArrayList<String>();
/**
* Creates a new, empty LinkInfo
*/
public LinkInfoImpl()
{
}
/**
* Createa a LinkInfo object from an existing node
*/
public LinkInfoImpl(NodeRef nodeRef, NodeRef containerNodeRef, String systemName)
{
this.nodeRef = nodeRef;
this.containerNodeRef = containerNodeRef;
this.systemName = systemName;
}
@Override
public NodeRef getContainerNodeRef()
{
return containerNodeRef;
}
@Override
public NodeRef getNodeRef()
{
return nodeRef;
}
@Override
public String getSystemName()
{
return systemName;
}
@Override
public String getTitle()
{
return title;
}
@Override
public String getDescription()
{
return description;
}
@Override
public String getURL()
{
return url;
}
@Override
public String getCreator()
{
return creator;
}
@Override
public Date getCreatedAt()
{
return createdAt;
}
@Override
public Date getModifiedAt()
{
return modifiedAt;
}
@Override
public boolean isInternal()
{
return internal;
}
@Override
public List<String> getTags()
{
return tags;
}
@Override
public void setTitle(String title)
{
this.title = title;
}
@Override
public void setDescription(String description)
{
this.description = description;
}
@Override
public void setURL(String url)
{
this.url = url;
}
@Override
public void setInternal(boolean internal)
{
this.internal = internal;
}
public void setCreator(String creator)
{
this.creator = creator;
}
public void setCreatedAt(Date createdAt)
{
this.createdAt = createdAt;
}
public void setModifiedAt(Date modifiedAt)
{
this.modifiedAt = modifiedAt;
}
public void setTags(List<String> tags)
{
this.tags = tags;
}
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* 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/>.
*/
package org.alfresco.repo.links;
import org.alfresco.service.namespace.QName;
/**
* Links models constants
*
* @author Nick Burch
*/
public interface LinksModel
{
/** Links Model */
public static final String LINKS_MODEL_URL = "http://www.alfresco.org/model/linksmodel/1.0";
public static final String LINKS_MODEL_PREFIX = "lnk";
/** Link */
public static final QName TYPE_LINK = QName.createQName(LINKS_MODEL_URL, "link");
public static final QName PROP_TITLE = QName.createQName(LINKS_MODEL_URL, "title");
public static final QName PROP_DESCRIPTION = QName.createQName(LINKS_MODEL_URL, "description");
public static final QName PROP_URL = QName.createQName(LINKS_MODEL_URL, "url");
/** Internal Link */
public static final QName ASPECT_INTERNAL_LINK = QName.createQName(LINKS_MODEL_URL, "internal");
public static final QName PROP_IS_INTERNAL = QName.createQName(LINKS_MODEL_URL, "isInternal");
}

View File

@@ -0,0 +1,529 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* 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/>.
*/
package org.alfresco.repo.links;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.model.ContentModel;
import org.alfresco.query.CannedQueryFactory;
import org.alfresco.query.CannedQueryResults;
import org.alfresco.query.EmptyPagingResults;
import org.alfresco.query.PagingRequest;
import org.alfresco.query.PagingResults;
import org.alfresco.repo.node.getchildren.GetChildrenAuditableCannedQuery;
import org.alfresco.repo.node.getchildren.GetChildrenAuditableCannedQueryFactory;
import org.alfresco.repo.query.NodeBackedEntity;
import org.alfresco.repo.search.impl.lucene.LuceneUtils;
import org.alfresco.repo.site.SiteServiceImpl;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.links.LinkInfo;
import org.alfresco.service.cmr.links.LinksService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.cmr.search.LimitBy;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.ResultSetRow;
import org.alfresco.service.cmr.search.SearchParameters;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.cmr.tagging.TaggingService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ISO9075;
import org.alfresco.util.Pair;
import org.alfresco.util.registry.NamedObjectRegistry;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @author Nick Burch (based on existing webscript controllers in the REST API)
* @since 4.0
*/
public class LinksServiceImpl implements LinksService
{
public static final String LINKS_COMPONENT = "links";
protected static final String CANNED_QUERY_GET_CHILDREN = "linksGetChildrenCannedQueryFactory";
/**
* The logger
*/
@SuppressWarnings("unused")
private static Log logger = LogFactory.getLog(LinksServiceImpl.class);
private NodeService nodeService;
private SiteService siteService;
private SearchService searchService;
private TaggingService taggingService;
private NamespaceService namespaceService;
private DictionaryService dictionaryService;
private TransactionService transactionService;
private NamedObjectRegistry<CannedQueryFactory<? extends Object>> cannedQueryRegistry;
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setSiteService(SiteService siteService)
{
this.siteService = siteService;
}
public void setSearchService(SearchService searchService)
{
this.searchService = searchService;
}
public void setTaggingService(TaggingService taggingService)
{
this.taggingService = taggingService;
}
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
public void setTransactionService(TransactionService transactionService)
{
this.transactionService = transactionService;
}
/**
* Set the registry of {@link CannedQueryFactory canned queries}
*/
public void setCannedQueryRegistry(NamedObjectRegistry<CannedQueryFactory<? extends Object>> cannedQueryRegistry)
{
this.cannedQueryRegistry = cannedQueryRegistry;
}
/**
* Fetches the Links Container on a site, creating as required if requested.
*/
protected NodeRef getSiteLinksContainer(final String siteShortName, boolean create)
{
return SiteServiceImpl.getSiteContainer(
siteShortName, LINKS_COMPONENT, create,
siteService, transactionService, taggingService);
}
private void handleTags(LinkInfo link)
{
NodeRef nodeRef = link.getNodeRef();
List<String> currentTags = taggingService.getTags(nodeRef);
List<String> newTags = link.getTags();
if(currentTags.size() == 0 && newTags.size() == 0)
{
// No tags, easy
return;
}
// Figure out what (if anything) changed
Set<String> toAdd = new HashSet<String>(newTags);
Set<String> toDel = new HashSet<String>(currentTags);
for(String tag : currentTags)
{
if(toAdd.contains(tag))
{
toAdd.remove(tag);
}
}
for(String tag : newTags)
{
if(toDel.contains(tag))
{
toDel.remove(tag);
}
}
if(toDel.size() == 0 && toAdd.size() == 0)
{
// No changes
}
// Make the changes
for(String tag : toDel)
{
taggingService.removeTag(nodeRef, tag);
}
for(String tag : toAdd)
{
taggingService.addTag(nodeRef, tag);
}
}
private LinkInfo buildLink(NodeRef nodeRef, NodeRef container, String name)
{
LinkInfoImpl link = new LinkInfoImpl(nodeRef, container, name);
// Grab all the properties, we need the bulk of them anyway
Map<QName,Serializable> props = nodeService.getProperties(nodeRef);
// Start with the auditable properties
link.setCreator((String)props.get(ContentModel.PROP_CREATOR));
link.setCreatedAt((Date)props.get(ContentModel.PROP_CREATED));
link.setModifiedAt((Date)props.get(ContentModel.PROP_MODIFIED));
// Now the link ones
link.setTitle((String)props.get(LinksModel.PROP_TITLE));
link.setDescription((String)props.get(LinksModel.PROP_DESCRIPTION));
link.setURL((String)props.get(LinksModel.PROP_URL));
// Now the internal aspect
if(nodeService.hasAspect(nodeRef, LinksModel.ASPECT_INTERNAL_LINK))
{
Boolean isInternal = DefaultTypeConverter.INSTANCE.convert(
Boolean.class, props.get(LinksModel.PROP_IS_INTERNAL));
link.setInternal(isInternal);
}
else
{
// Not internal
link.setInternal(false);
}
// Finally tags
link.setTags(taggingService.getTags(nodeRef));
// All done
return link;
}
@Override
public LinkInfo getLink(String siteShortName, String linkName)
{
NodeRef container = getSiteLinksContainer(siteShortName, false);
if(container == null)
{
// No links
return null;
}
NodeRef link = nodeService.getChildByName(container, ContentModel.ASSOC_CONTAINS, linkName);
if(link != null)
{
return buildLink(link, container, linkName);
}
return null;
}
@Override
public LinkInfo createLink(String siteShortName, String title,
String description, String url, boolean internal)
{
// Grab the location to store in
NodeRef container = getSiteLinksContainer(siteShortName, true);
// Get the properties for the node
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
props.put(LinksModel.PROP_TITLE, title);
props.put(LinksModel.PROP_DESCRIPTION, description);
props.put(LinksModel.PROP_URL, url);
if(internal)
{
props.put(LinksModel.PROP_IS_INTERNAL, "true");
}
// Generate a unique name
// (Should be unique, but will retry for a new one if not)
String name = "link-" + (new Date()).getTime() + "-" +
Math.round(Math.random()*10000);
props.put(ContentModel.PROP_NAME, name);
// Build the node
NodeRef nodeRef = nodeService.createNode(
container,
ContentModel.ASSOC_CONTAINS,
QName.createQName(name),
LinksModel.TYPE_LINK,
props
).getChildRef();
// Generate the wrapping object for it
// Build it that way, so creator and created date come through
return buildLink(nodeRef, container, name);
}
@Override
public LinkInfo updateLink(LinkInfo link)
{
// Sanity check what we were given
if(link.getNodeRef() == null)
{
throw new IllegalArgumentException("Can't update a link that was never persisted, call create instead");
}
// Change the properties
NodeRef nodeRef = link.getNodeRef();
nodeService.setProperty(nodeRef, LinksModel.PROP_TITLE, link.getTitle());
nodeService.setProperty(nodeRef, LinksModel.PROP_DESCRIPTION, link.getDescription());
nodeService.setProperty(nodeRef, LinksModel.PROP_URL, link.getURL());
// Internal/External is "special"
if(link.isInternal())
{
if(! nodeService.hasAspect(nodeRef, LinksModel.ASPECT_INTERNAL_LINK))
{
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
props.put(LinksModel.PROP_IS_INTERNAL, "true");
nodeService.addAspect(nodeRef, LinksModel.ASPECT_INTERNAL_LINK, props);
}
}
else
{
if(nodeService.hasAspect(nodeRef, LinksModel.ASPECT_INTERNAL_LINK))
{
nodeService.removeAspect(nodeRef, LinksModel.ASPECT_INTERNAL_LINK);
}
}
// Now do the tags
handleTags(link);
// All done
return link;
}
@Override
public void deleteLink(LinkInfo link)
{
if(link.getNodeRef() == null)
{
throw new IllegalArgumentException("Can't delete a link entry that was never persisted");
}
nodeService.deleteNode(link.getNodeRef());
}
@Override
public PagingResults<LinkInfo> listLinks(String siteShortName, PagingRequest paging)
{
return listLinks(siteShortName, null, null, null, paging);
}
@Override
public PagingResults<LinkInfo> listLinks(String siteShortName, String user,
PagingRequest paging)
{
return listLinks(siteShortName, user, null, null, paging);
}
@Override
public PagingResults<LinkInfo> listLinks(String siteShortName, Date from,
Date to, PagingRequest paging)
{
return listLinks(siteShortName, null, from, to, paging);
}
private PagingResults<LinkInfo> listLinks(String siteShortName, String user,
Date from, Date to, PagingRequest paging)
{
NodeRef container = getSiteLinksContainer(siteShortName, false);
if(container == null)
{
// No events
return new EmptyPagingResults<LinkInfo>();
}
// Run the canned query
GetChildrenAuditableCannedQueryFactory getChildrenCannedQueryFactory = (GetChildrenAuditableCannedQueryFactory)cannedQueryRegistry.getNamedObject(CANNED_QUERY_GET_CHILDREN);
GetChildrenAuditableCannedQuery cq = (GetChildrenAuditableCannedQuery)getChildrenCannedQueryFactory.getCannedQuery(
container, LinksModel.TYPE_LINK, user, from, to, null, null, null,
getChildrenCannedQueryFactory.createDateDescendingCQSortDetails(), paging);
// Execute the canned query
CannedQueryResults<NodeBackedEntity> results = cq.execute();
// Convert to Link objects
return wrap(results, container);
}
@Override
public PagingResults<LinkInfo> findLinks(String siteShortName, String user,
Date from, Date to, String tag, PagingRequest paging)
{
NodeRef container = getSiteLinksContainer(siteShortName, false);
if(container == null)
{
// No links
return new EmptyPagingResults<LinkInfo>();
}
// Build the query
StringBuilder luceneQuery = new StringBuilder();
luceneQuery.append(
" +TYPE:\"" + LinksModel.TYPE_LINK + "\""
);
luceneQuery.append(
" +PATH:\"" + nodeService.getPath(container).toPrefixString(namespaceService) + "/*\""
);
if(user != null)
{
luceneQuery.append(
" +@cm\\:creator:\"" + user + "\""
);
}
if(from != null && to != null)
{
luceneQuery.append(LuceneUtils.createDateRangeQuery(
from, to, ContentModel.PROP_CREATED, dictionaryService, namespaceService
));
}
if(tag != null)
{
luceneQuery.append(
" +PATH:\"/cm:taggable/cm:" + ISO9075.encode(tag) + "/member\""
);
}
String sortOn = "@{http://www.alfresco.org/model/content/1.0}created";
// Query
SearchParameters sp = new SearchParameters();
sp.addStore(container.getStoreRef());
sp.setLanguage(SearchService.LANGUAGE_LUCENE);
sp.setQuery(luceneQuery.toString());
sp.addSort(sortOn, false);
if (paging.getMaxItems() > 0)
{
sp.setLimit(paging.getMaxItems());
sp.setLimitBy(LimitBy.FINAL_SIZE);
}
if (paging.getSkipCount() > 0)
{
sp.setSkipCount(paging.getSkipCount());
}
// Build the results
PagingResults<LinkInfo> pagedResults = new EmptyPagingResults<LinkInfo>();
ResultSet results = null;
try
{
results = searchService.query(sp);
pagedResults = wrap(results, container);
}
finally
{
if(results != null)
{
results.close();
}
}
return pagedResults;
}
private PagingResults<LinkInfo> wrap(final ResultSet finalLuceneResults, final NodeRef container)
{
final List<LinkInfo> links = new ArrayList<LinkInfo>();
for(ResultSetRow row : finalLuceneResults)
{
LinkInfo link = buildLink(
row.getNodeRef(), container, row.getQName().getLocalName()
);
links.add(link);
}
// Wrap
return new PagingResults<LinkInfo>() {
@Override
public boolean hasMoreItems() {
return finalLuceneResults.hasMore();
}
@Override
public Pair<Integer, Integer> getTotalResultCount() {
int skipCount = finalLuceneResults.getStart();
int itemsRemainingAfterThisPage = finalLuceneResults.length();
final int totalItemsInUnpagedResultSet = skipCount + itemsRemainingAfterThisPage;
return new Pair<Integer, Integer>(totalItemsInUnpagedResultSet, totalItemsInUnpagedResultSet);
}
@Override
public List<LinkInfo> getPage() {
return links;
}
@Override
public String getQueryExecutionId() {
return null;
}
};
}
/**
* Our class to wrap up paged results of NodeBackedEntities as
* LinkInfo instances
*/
private PagingResults<LinkInfo> wrap(final PagingResults<NodeBackedEntity> results, final NodeRef container)
{
return new PagingResults<LinkInfo>()
{
@Override
public String getQueryExecutionId()
{
return results.getQueryExecutionId();
}
@Override
public List<LinkInfo> getPage()
{
List<LinkInfo> links = new ArrayList<LinkInfo>();
for(NodeBackedEntity node : results.getPage())
{
NodeRef nodeRef = node.getNodeRef();
String name = node.getName();
links.add(buildLink(nodeRef, container, name));
}
return links;
}
@Override
public boolean hasMoreItems()
{
return results.hasMoreItems();
}
@Override
public Pair<Integer, Integer> getTotalResultCount()
{
return results.getTotalResultCount();
}
};
}
}

View File

@@ -0,0 +1,963 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* 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/>.
*/
package org.alfresco.repo.links;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.query.PagingRequest;
import org.alfresco.query.PagingResults;
import org.alfresco.repo.policy.BehaviourFilter;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.site.SiteModel;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.links.LinkInfo;
import org.alfresco.service.cmr.links.LinksService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.service.cmr.tagging.TaggingService;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.PropertyMap;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
/**
* Test cases for {@link LinksServiceImpl}.
*
* @author Nick Burch
* @since 4.0
*/
public class LinksServiceImplTest
{
private static final String TEST_SITE_PREFIX = "LinksSiteTest";
private static final long ONE_DAY_MS = 24*60*60*1000;
private static final ApplicationContext testContext = ApplicationContextHelper.getApplicationContext();
// injected services
private static MutableAuthenticationService AUTHENTICATION_SERVICE;
private static BehaviourFilter BEHAVIOUR_FILTER;
private static LinksService LINKS_SERVICE;
private static DictionaryService DICTIONARY_SERVICE;
private static NodeService NODE_SERVICE;
private static NodeService PUBLIC_NODE_SERVICE;
private static PersonService PERSON_SERVICE;
private static RetryingTransactionHelper TRANSACTION_HELPER;
private static TransactionService TRANSACTION_SERVICE;
private static PermissionService PERMISSION_SERVICE;
private static SiteService SITE_SERVICE;
private static TaggingService TAGGING_SERVICE;
private static final String TEST_USER = LinksServiceImplTest.class.getSimpleName() + "_testuser";
private static final String ADMIN_USER = AuthenticationUtil.getAdminUserName();
private static SiteInfo LINKS_SITE;
private static SiteInfo ALTERNATE_LINKS_SITE;
/**
* Temporary test nodes (created during a test method) that need deletion after the test method.
*/
private List<NodeRef> testNodesToTidy = new ArrayList<NodeRef>();
/**
* Temporary test nodes (created BeforeClass) that need deletion after this test class.
*/
private static List<NodeRef> CLASS_TEST_NODES_TO_TIDY = new ArrayList<NodeRef>();
@BeforeClass public static void initTestsContext() throws Exception
{
AUTHENTICATION_SERVICE = (MutableAuthenticationService)testContext.getBean("authenticationService");
BEHAVIOUR_FILTER = (BehaviourFilter)testContext.getBean("policyBehaviourFilter");
LINKS_SERVICE = (LinksService)testContext.getBean("LinksService");
DICTIONARY_SERVICE = (DictionaryService)testContext.getBean("dictionaryService");
NODE_SERVICE = (NodeService)testContext.getBean("nodeService");
PUBLIC_NODE_SERVICE = (NodeService)testContext.getBean("NodeService");
PERSON_SERVICE = (PersonService)testContext.getBean("personService");
TRANSACTION_HELPER = (RetryingTransactionHelper)testContext.getBean("retryingTransactionHelper");
TRANSACTION_SERVICE = (TransactionService)testContext.getBean("TransactionService");
PERMISSION_SERVICE = (PermissionService)testContext.getBean("permissionService");
SITE_SERVICE = (SiteService)testContext.getBean("siteService");
TAGGING_SERVICE = (TaggingService)testContext.getBean("TaggingService");
// Do the setup as admin
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
createUser(TEST_USER);
// We need to create the test site as the test user so that they can contribute content to it in tests below.
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
createTestSites();
}
@Test public void createNewEntry() throws Exception
{
LinkInfo link;
// Nothing to start with
PagingResults<LinkInfo> results =
LINKS_SERVICE.listLinks(LINKS_SITE.getShortName(), new PagingRequest(10));
assertEquals(0, results.getPage().size());
// Get with an arbitrary name gives nothing
link = LINKS_SERVICE.getLink(LINKS_SITE.getShortName(), "madeUp");
assertEquals(null, link);
link = LINKS_SERVICE.getLink(LINKS_SITE.getShortName(), "madeUp2");
assertEquals(null, link);
// Create one
link = LINKS_SERVICE.createLink(
LINKS_SITE.getShortName(), "Title", "Description",
"http://www.alfresco.com/", false
);
// Ensure it got a noderef, and the correct site
assertNotNull(link.getNodeRef());
assertNotNull(link.getSystemName());
NodeRef container = NODE_SERVICE.getPrimaryParent(link.getNodeRef()).getParentRef();
NodeRef site = NODE_SERVICE.getPrimaryParent(container).getParentRef();
assertEquals(LINKS_SITE.getNodeRef(), site);
// Check the details on the object
assertEquals("Title", link.getTitle());
assertEquals("Description", link.getDescription());
assertEquals("http://www.alfresco.com/", link.getURL());
assertEquals(false, link.isInternal());
assertEquals(ADMIN_USER, link.getCreator());
assertEquals(0, link.getTags().size());
// Fetch it, and check the details
link = LINKS_SERVICE.getLink(LINKS_SITE.getShortName(), link.getSystemName());
assertEquals("Title", link.getTitle());
assertEquals("Description", link.getDescription());
assertEquals("http://www.alfresco.com/", link.getURL());
assertEquals(false, link.isInternal());
assertEquals(ADMIN_USER, link.getCreator());
assertEquals(0, link.getTags().size());
// Mark it as done with
testNodesToTidy.add(link.getNodeRef());
}
@Test public void createUpdateDeleteEntry() throws Exception
{
LinkInfo link;
// Run as the test user instead
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
// Create a link
link = LINKS_SERVICE.createLink(
LINKS_SITE.getShortName(), "Title", "Description",
"http://www.alfresco.com/", false
);
// Check it
assertEquals("Title", link.getTitle());
assertEquals("Description", link.getDescription());
assertEquals("http://www.alfresco.com/", link.getURL());
assertEquals(false, link.isInternal());
assertEquals(TEST_USER, link.getCreator());
assertEquals(0, link.getTags().size());
// Change it
link.setTitle("New Title");
link.setURL("http://share.alfresco.com/");
link.setInternal(true);
LINKS_SERVICE.updateLink(link);
// Fetch, and check
link = LINKS_SERVICE.getLink(LINKS_SITE.getShortName(), link.getSystemName());
assertEquals("New Title", link.getTitle());
assertEquals("Description", link.getDescription());
assertEquals("http://share.alfresco.com/", link.getURL());
assertEquals(true, link.isInternal());
assertEquals(TEST_USER, link.getCreator());
assertEquals(0, link.getTags().size());
// Delete it
LINKS_SERVICE.deleteLink(link);
// Check it went
assertEquals(null, LINKS_SERVICE.getLink(LINKS_SITE.getShortName(), link.getSystemName()));
}
/**
* Ensures that when we try to write an entry to the
* container of a new site, it is correctly setup for us.
* This test does it's own transactions
*/
@Test public void newContainerSetup() throws Exception
{
final String TEST_SITE_NAME = "LinksTestNewTestSite";
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
if(SITE_SERVICE.getSite(TEST_SITE_NAME) != null)
{
SITE_SERVICE.deleteSite(TEST_SITE_NAME);
}
SITE_SERVICE.createSite(
TEST_SITE_PREFIX, TEST_SITE_NAME, "Test", "Test", SiteVisibility.PUBLIC
);
// Won't have the container to start with
assertFalse(SITE_SERVICE.hasContainer(TEST_SITE_NAME, LinksServiceImpl.LINKS_COMPONENT));
// Create a link
LINKS_SERVICE.createLink(
TEST_SITE_NAME, "Title", "Description",
"http://www.alfresco.com/", false
);
// It will now exist
assertTrue(SITE_SERVICE.hasContainer(TEST_SITE_NAME, LinksServiceImpl.LINKS_COMPONENT));
// It'll be a tag scope too
NodeRef container = SITE_SERVICE.getContainer(TEST_SITE_NAME, LinksServiceImpl.LINKS_COMPONENT);
assertTrue(TAGGING_SERVICE.isTagScope(container));
// Tidy up
SITE_SERVICE.deleteSite(TEST_SITE_NAME);
return null;
}
});
}
@Test public void tagging() throws Exception
{
LinkInfo link;
final String TAG_1 = "link_tag_1";
final String TAG_2 = "link_tag_2";
final String TAG_3 = "link_tag_3";
// Create one without tagging
link = LINKS_SERVICE.createLink(
LINKS_SITE.getShortName(), "Title", "Description",
"http://www.alfresco.com/", false
);
testNodesToTidy.add(link.getNodeRef());
// Check
assertEquals(0, link.getTags().size());
link = LINKS_SERVICE.getLink(LINKS_SITE.getShortName(), link.getSystemName());
assertEquals(0, link.getTags().size());
// Update it to have tags
link.getTags().add(TAG_1);
link.getTags().add(TAG_2);
link.getTags().add(TAG_1);
assertEquals(3, link.getTags().size());
LINKS_SERVICE.updateLink(link);
// Check
link = LINKS_SERVICE.getLink(LINKS_SITE.getShortName(), link.getSystemName());
assertEquals(2, link.getTags().size());
assertEquals(true, link.getTags().contains(TAG_1));
assertEquals(true, link.getTags().contains(TAG_2));
assertEquals(false, link.getTags().contains(TAG_3));
// Update it to have different tags
link.getTags().remove(TAG_2);
link.getTags().add(TAG_3);
link.getTags().add(TAG_1);
LINKS_SERVICE.updateLink(link);
// Check it as-is
assertEquals(3, link.getTags().size()); // Includes duplicate tag until re-loaded
assertEquals(true, link.getTags().contains(TAG_1));
assertEquals(false, link.getTags().contains(TAG_2));
assertEquals(true, link.getTags().contains(TAG_3));
// Now load and re-check
link = LINKS_SERVICE.getLink(LINKS_SITE.getShortName(), link.getSystemName());
assertEquals(2, link.getTags().size()); // Duplicate now gone
assertEquals(true, link.getTags().contains(TAG_1));
assertEquals(false, link.getTags().contains(TAG_2));
assertEquals(true, link.getTags().contains(TAG_3));
// Update it to have no tags
link.getTags().clear();
LINKS_SERVICE.updateLink(link);
// Check
link = LINKS_SERVICE.getLink(LINKS_SITE.getShortName(), link.getSystemName());
assertEquals(0, link.getTags().size());
// Update it to have tags again
link.getTags().add(TAG_1);
link.getTags().add(TAG_2);
link.getTags().add(TAG_3);
LINKS_SERVICE.updateLink(link);
// Check
link = LINKS_SERVICE.getLink(LINKS_SITE.getShortName(), link.getSystemName());
assertEquals(3, link.getTags().size());
assertEquals(true, link.getTags().contains(TAG_1));
assertEquals(true, link.getTags().contains(TAG_2));
assertEquals(true, link.getTags().contains(TAG_3));
// Tidy
LINKS_SERVICE.deleteLink(link);
}
/**
* Tests for listing the links of a site, possibly by user or date range
*/
@Test public void linksListing() throws Exception
{
PagingRequest paging = new PagingRequest(10);
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
// Nothing to start with
PagingResults<LinkInfo> results =
LINKS_SERVICE.listLinks(LINKS_SITE.getShortName(), paging);
assertEquals(0, results.getPage().size());
// Add a few
LinkInfo linkA = LINKS_SERVICE.createLink(
LINKS_SITE.getShortName(), "TitleA", "Description",
"http://www.alfresco.com/", false
);
LinkInfo linkB = LINKS_SERVICE.createLink(
LINKS_SITE.getShortName(), "TitleB", "Description",
"http://www.alfresco.com/", false
);
LinkInfo linkC = LINKS_SERVICE.createLink(
LINKS_SITE.getShortName(), "TitleC", "Description",
"http://www.alfresco.com/", false
);
testNodesToTidy.add(linkA.getNodeRef());
testNodesToTidy.add(linkB.getNodeRef());
testNodesToTidy.add(linkC.getNodeRef());
// Check now, should be newest first
results = LINKS_SERVICE.listLinks(LINKS_SITE.getShortName(), paging);
assertEquals(3, results.getPage().size());
assertEquals("TitleC", results.getPage().get(0).getTitle());
assertEquals("TitleB", results.getPage().get(1).getTitle());
assertEquals("TitleA", results.getPage().get(2).getTitle());
// Add one more, as a different user, and drop the page size
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
LinkInfo linkD = LINKS_SERVICE.createLink(
LINKS_SITE.getShortName(), "TitleD", "Description",
"http://www.alfresco.com/", false
);
testNodesToTidy.add(linkD.getNodeRef());
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
paging = new PagingRequest(3);
results = LINKS_SERVICE.listLinks(LINKS_SITE.getShortName(), paging);
assertEquals(3, results.getPage().size());
assertEquals("TitleD", results.getPage().get(0).getTitle());
assertEquals("TitleC", results.getPage().get(1).getTitle());
assertEquals("TitleB", results.getPage().get(2).getTitle());
paging = new PagingRequest(3, 3);
results = LINKS_SERVICE.listLinks(LINKS_SITE.getShortName(), paging);
assertEquals(1, results.getPage().size());
assertEquals("TitleA", results.getPage().get(0).getTitle());
// Now check filtering by user
paging = new PagingRequest(10);
results = LINKS_SERVICE.listLinks(LINKS_SITE.getShortName(), TEST_USER, paging);
assertEquals(3, results.getPage().size());
assertEquals("TitleC", results.getPage().get(0).getTitle());
assertEquals("TitleB", results.getPage().get(1).getTitle());
assertEquals("TitleA", results.getPage().get(2).getTitle());
results = LINKS_SERVICE.listLinks(LINKS_SITE.getShortName(), ADMIN_USER, paging);
assertEquals(1, results.getPage().size());
assertEquals("TitleD", results.getPage().get(0).getTitle());
// Now check filtering by date range
pushCreatedDateBack(linkB, 10);
pushCreatedDateBack(linkC, 100);
Date today = new Date();
Date tomorrow = new Date(today.getTime()+ONE_DAY_MS);
Date yesterday = new Date(today.getTime()-ONE_DAY_MS);
Date twoWeeksAgo = new Date(today.getTime()-14*ONE_DAY_MS);
// Very recent ones
results = LINKS_SERVICE.listLinks(LINKS_SITE.getShortName(), yesterday, tomorrow, paging);
assertEquals(2, results.getPage().size());
assertEquals("TitleD", results.getPage().get(0).getTitle());
assertEquals("TitleA", results.getPage().get(1).getTitle());
// Fairly old ones
results = LINKS_SERVICE.listLinks(LINKS_SITE.getShortName(), twoWeeksAgo, yesterday, paging);
assertEquals(1, results.getPage().size());
assertEquals("TitleB", results.getPage().get(0).getTitle());
// Fairly old to current
results = LINKS_SERVICE.listLinks(LINKS_SITE.getShortName(), twoWeeksAgo, tomorrow, paging);
assertEquals(3, results.getPage().size());
assertEquals("TitleD", results.getPage().get(0).getTitle());
assertEquals("TitleA", results.getPage().get(1).getTitle());
assertEquals("TitleB", results.getPage().get(2).getTitle());
// Tidy
paging = new PagingRequest(10);
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
results = LINKS_SERVICE.listLinks(LINKS_SITE.getShortName(), paging);
for(LinkInfo link : results.getPage())
{
PUBLIC_NODE_SERVICE.deleteNode(link.getNodeRef());
}
results = LINKS_SERVICE.listLinks(ALTERNATE_LINKS_SITE.getShortName(), paging);
for(LinkInfo link : results.getPage())
{
PUBLIC_NODE_SERVICE.deleteNode(link.getNodeRef());
}
}
/**
* Checks that the correct permission checking occurs on fetching
* links listings (which go through canned queries)
*/
@Test public void linksListingPermissionsChecking() throws Exception
{
PagingRequest paging = new PagingRequest(10);
PagingResults<LinkInfo> results;
// Nothing to start with in either site
results = LINKS_SERVICE.listLinks(LINKS_SITE.getShortName(), paging);
assertEquals(0, results.getPage().size());
results = LINKS_SERVICE.listLinks(ALTERNATE_LINKS_SITE.getShortName(), paging);
assertEquals(0, results.getPage().size());
// Double check that we're only allowed to see the 1st site
assertEquals(true, SITE_SERVICE.isMember(LINKS_SITE.getShortName(), TEST_USER));
assertEquals(false, SITE_SERVICE.isMember(ALTERNATE_LINKS_SITE.getShortName(), TEST_USER));
// Now become the test user
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
// Add two events to one site and three to the other
// Note - add the events as a different user for the site that the
// test user isn't a member of!
LinkInfo linkA = LINKS_SERVICE.createLink(
LINKS_SITE.getShortName(), "TitleA", "Description",
"http://www.alfresco.com/", false
);
LinkInfo linkB = LINKS_SERVICE.createLink(
LINKS_SITE.getShortName(), "TitleB", "Description",
"http://www.alfresco.com/", false
);
testNodesToTidy.add(linkA.getNodeRef());
testNodesToTidy.add(linkB.getNodeRef());
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
LinkInfo linkPrivA = LINKS_SERVICE.createLink(
ALTERNATE_LINKS_SITE.getShortName(), "PrivTitleA", "Description",
"http://team.alfresco.com/", false
);
LinkInfo linkPrivB = LINKS_SERVICE.createLink(
ALTERNATE_LINKS_SITE.getShortName(), "PrivTitleB", "Description",
"http://team.alfresco.com/", false
);
LinkInfo linkPrivC = LINKS_SERVICE.createLink(
ALTERNATE_LINKS_SITE.getShortName(), "PrivTitleC", "Description",
"http://team.alfresco.com/", false
);
testNodesToTidy.add(linkPrivA.getNodeRef());
testNodesToTidy.add(linkPrivB.getNodeRef());
testNodesToTidy.add(linkPrivC.getNodeRef());
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
// Check again, as we're not in the 2nd site won't see any there
results = LINKS_SERVICE.listLinks(LINKS_SITE.getShortName(), paging);
assertEquals(2, results.getPage().size());
results = LINKS_SERVICE.listLinks(ALTERNATE_LINKS_SITE.getShortName(), paging);
assertEquals(0, results.getPage().size());
// Join the site, now we can see both
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
SITE_SERVICE.setMembership(ALTERNATE_LINKS_SITE.getShortName(), TEST_USER, SiteModel.SITE_COLLABORATOR);
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
return null;
}
});
results = LINKS_SERVICE.listLinks(LINKS_SITE.getShortName(), paging);
assertEquals(2, results.getPage().size());
results = LINKS_SERVICE.listLinks(ALTERNATE_LINKS_SITE.getShortName(), paging);
assertEquals(3, results.getPage().size());
// Explicitly remove their permissions from one node, check it vanishes from the list
PERMISSION_SERVICE.setInheritParentPermissions(linkPrivC.getNodeRef(), false);
PERMISSION_SERVICE.clearPermission(linkPrivC.getNodeRef(), TEST_USER);
results = LINKS_SERVICE.listLinks(LINKS_SITE.getShortName(), paging);
assertEquals(2, results.getPage().size());
results = LINKS_SERVICE.listLinks(ALTERNATE_LINKS_SITE.getShortName(), paging);
assertEquals(2, results.getPage().size());
// Leave, they go away again
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
SITE_SERVICE.removeMembership(ALTERNATE_LINKS_SITE.getShortName(), TEST_USER);
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
return null;
}
});
results = LINKS_SERVICE.listLinks(LINKS_SITE.getShortName(), paging);
assertEquals(2, results.getPage().size());
results = LINKS_SERVICE.listLinks(ALTERNATE_LINKS_SITE.getShortName(), paging);
assertEquals(0, results.getPage().size());
// Tidy
paging = new PagingRequest(10);
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
results = LINKS_SERVICE.listLinks(LINKS_SITE.getShortName(), paging);
for(LinkInfo link : results.getPage())
{
PUBLIC_NODE_SERVICE.deleteNode(link.getNodeRef());
}
results = LINKS_SERVICE.listLinks(ALTERNATE_LINKS_SITE.getShortName(), paging);
for(LinkInfo link : results.getPage())
{
PUBLIC_NODE_SERVICE.deleteNode(link.getNodeRef());
}
}
/**
* The lucene based searching
*/
@Test public void linksSearching() throws Exception
{
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
PagingRequest paging = new PagingRequest(10);
PagingResults<LinkInfo> results;
final String TAG_1 = "link_tag_1";
final String TAG_2 = "link_tag_2";
final String TAG_3 = "link_tag_3";
final String TAG_4 = "link_tag_4";
// Nothing to start with in either site
results = LINKS_SERVICE.findLinks(LINKS_SITE.getShortName(), null, null, null, null, paging);
assertEquals(0, results.getPage().size());
results = LINKS_SERVICE.findLinks(ALTERNATE_LINKS_SITE.getShortName(), null, null, null, null, paging);
assertEquals(0, results.getPage().size());
// Add some entries to the two sites
LinkInfo linkA = LINKS_SERVICE.createLink(
LINKS_SITE.getShortName(), "TitleA", "Description",
"http://www.alfresco.com/", false
);
LinkInfo linkB = LINKS_SERVICE.createLink(
LINKS_SITE.getShortName(), "TitleB", "Description",
"http://www.alfresco.com/", false
);
testNodesToTidy.add(linkA.getNodeRef());
testNodesToTidy.add(linkB.getNodeRef());
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
LinkInfo linkPrivA = LINKS_SERVICE.createLink(
ALTERNATE_LINKS_SITE.getShortName(), "PrivTitleA", "Description",
"http://team.alfresco.com/", false
);
LinkInfo linkPrivB = LINKS_SERVICE.createLink(
ALTERNATE_LINKS_SITE.getShortName(), "PrivTitleB", "Description",
"http://team.alfresco.com/", false
);
LinkInfo linkPrivC = LINKS_SERVICE.createLink(
ALTERNATE_LINKS_SITE.getShortName(), "PrivTitleC", "Description",
"http://team.alfresco.com/", false
);
testNodesToTidy.add(linkPrivA.getNodeRef());
testNodesToTidy.add(linkPrivB.getNodeRef());
testNodesToTidy.add(linkPrivC.getNodeRef());
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
// Check again, won't be able to see the alternate site ones yet
results = LINKS_SERVICE.findLinks(LINKS_SITE.getShortName(), null, null, null, null, paging);
assertEquals(2, results.getPage().size());
results = LINKS_SERVICE.findLinks(ALTERNATE_LINKS_SITE.getShortName(), null, null, null, null, paging);
assertEquals(0, results.getPage().size());
// Now join the site, will be allowed to see things
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
SITE_SERVICE.setMembership(ALTERNATE_LINKS_SITE.getShortName(), TEST_USER, SiteModel.SITE_COLLABORATOR);
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
return null;
}
});
results = LINKS_SERVICE.findLinks(LINKS_SITE.getShortName(), null, null, null, null, paging);
assertEquals(2, results.getPage().size());
results = LINKS_SERVICE.findLinks(ALTERNATE_LINKS_SITE.getShortName(), null, null, null, null, paging);
assertEquals(3, results.getPage().size());
// Alter some of the links' created dates
pushCreatedDateBack(linkB, 10);
pushCreatedDateBack(linkPrivB, 10);
pushCreatedDateBack(linkPrivC, 100);
// Force a new transaction
// Add tags and another entry
linkA.getTags().add(TAG_1);
linkA.getTags().add(TAG_2);
LINKS_SERVICE.updateLink(linkA);
linkPrivA.getTags().add(TAG_1);
linkPrivA.getTags().add(TAG_3);
LINKS_SERVICE.updateLink(linkPrivA);
linkPrivB.getTags().add(TAG_1);
LINKS_SERVICE.updateLink(linkPrivB);
LinkInfo linkPrivD = LINKS_SERVICE.createLink(
ALTERNATE_LINKS_SITE.getShortName(), "PrivTitleD", "Description",
"http://team.alfresco.com/", false
);
testNodesToTidy.add(linkPrivD.getNodeRef());
// Filter by username
results = LINKS_SERVICE.findLinks(LINKS_SITE.getShortName(), TEST_USER, null, null, null, paging);
assertEquals(2, results.getPage().size());
results = LINKS_SERVICE.findLinks(ALTERNATE_LINKS_SITE.getShortName(), TEST_USER, null, null, null, paging);
assertEquals(1, results.getPage().size());
results = LINKS_SERVICE.findLinks(LINKS_SITE.getShortName(), ADMIN_USER, null, null, null, paging);
assertEquals(0, results.getPage().size());
results = LINKS_SERVICE.findLinks(ALTERNATE_LINKS_SITE.getShortName(), ADMIN_USER, null, null, null, paging);
assertEquals(3, results.getPage().size());
// Filter by date
Date today = new Date();
Date tomorrow = new Date(today.getTime()+ONE_DAY_MS);
Date yesterday = new Date(today.getTime()-ONE_DAY_MS);
Date twoWeeksAgo = new Date(today.getTime()-14*ONE_DAY_MS);
// The A's are on today, as is PrivD
results = LINKS_SERVICE.findLinks(LINKS_SITE.getShortName(), null, yesterday, tomorrow, null, paging);
assertEquals(1, results.getPage().size());
results = LINKS_SERVICE.findLinks(ALTERNATE_LINKS_SITE.getShortName(), null, yesterday, tomorrow, null, paging);
assertEquals(2, results.getPage().size());
// The B's are 10 days ago
results = LINKS_SERVICE.findLinks(LINKS_SITE.getShortName(), null, twoWeeksAgo, yesterday, null, paging);
assertEquals(1, results.getPage().size());
results = LINKS_SERVICE.findLinks(ALTERNATE_LINKS_SITE.getShortName(), null, twoWeeksAgo, yesterday, null, paging);
assertEquals(1, results.getPage().size());
// Get both A's, B's and D, but not C as it's 100 days ago
results = LINKS_SERVICE.findLinks(LINKS_SITE.getShortName(), null, twoWeeksAgo, tomorrow, null, paging);
assertEquals(2, results.getPage().size());
results = LINKS_SERVICE.findLinks(ALTERNATE_LINKS_SITE.getShortName(), null, twoWeeksAgo, tomorrow, null, paging);
assertEquals(3, results.getPage().size());
// Filter by tag
// Tag1 is on A, PrivA and PrivB
results = LINKS_SERVICE.findLinks(LINKS_SITE.getShortName(), null, null, null, TAG_1, paging);
assertEquals(1, results.getPage().size());
results = LINKS_SERVICE.findLinks(ALTERNATE_LINKS_SITE.getShortName(), null, null, null, TAG_1, paging);
assertEquals(2, results.getPage().size());
// Tag2 is on A
results = LINKS_SERVICE.findLinks(LINKS_SITE.getShortName(), null, null, null, TAG_2, paging);
assertEquals(1, results.getPage().size());
results = LINKS_SERVICE.findLinks(ALTERNATE_LINKS_SITE.getShortName(), null, null, null, TAG_2, paging);
assertEquals(0, results.getPage().size());
// Tag3 is on PrivA
results = LINKS_SERVICE.findLinks(LINKS_SITE.getShortName(), null, null, null, TAG_3, paging);
assertEquals(0, results.getPage().size());
results = LINKS_SERVICE.findLinks(ALTERNATE_LINKS_SITE.getShortName(), null, null, null, TAG_3, paging);
assertEquals(1, results.getPage().size());
// Tag4 isn't on anything
results = LINKS_SERVICE.findLinks(LINKS_SITE.getShortName(), null, null, null, TAG_4, paging);
assertEquals(0, results.getPage().size());
results = LINKS_SERVICE.findLinks(ALTERNATE_LINKS_SITE.getShortName(), null, null, null, TAG_4, paging);
assertEquals(0, results.getPage().size());
// Filter by username and date and tag
results = LINKS_SERVICE.findLinks(LINKS_SITE.getShortName(), ADMIN_USER, yesterday, tomorrow, TAG_1, paging);
assertEquals(0, results.getPage().size()); // Wrong user
results = LINKS_SERVICE.findLinks(ALTERNATE_LINKS_SITE.getShortName(), ADMIN_USER, yesterday, tomorrow, TAG_1, paging);
assertEquals(1, results.getPage().size()); // Only PrivA
}
// --------------------------------------------------------------------------------
/**
* Alters the created date on a link entry for testing
*/
private void pushCreatedDateBack(LinkInfo link, int daysAgo) throws Exception
{
final NodeRef node = link.getNodeRef();
final Date created = link.getCreatedAt();
final Date newCreated = new Date(created.getTime() - daysAgo*ONE_DAY_MS);
// Update the created date
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
BEHAVIOUR_FILTER.disableBehaviour(ContentModel.ASPECT_AUDITABLE);
NODE_SERVICE.setProperty(node, ContentModel.PROP_CREATED, newCreated);
return null;
}
}, false, true);
// Change something else too in the public nodeservice, to force a re-index
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
BEHAVIOUR_FILTER.disableBehaviour(ContentModel.ASPECT_AUDITABLE);
PUBLIC_NODE_SERVICE.setProperty(node, ContentModel.PROP_CREATED, newCreated);
PUBLIC_NODE_SERVICE.setProperty(node, ContentModel.PROP_DESCRIPTION, "Forced Change");
return null;
}
}, false, true);
// Check it was taken
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
assertEquals(newCreated, NODE_SERVICE.getProperty(node, ContentModel.PROP_CREATED));
assertEquals(newCreated, PUBLIC_NODE_SERVICE.getProperty(node, ContentModel.PROP_CREATED));
return null;
}
}, false, true);
// Update the object itself
((LinkInfoImpl)link).setCreatedAt(newCreated);
}
private static void createTestSites() throws Exception
{
final LinksServiceImpl privateCalendarService = (LinksServiceImpl)testContext.getBean("linksService");
LINKS_SITE = TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<SiteInfo>()
{
@Override
public SiteInfo execute() throws Throwable
{
SiteInfo site = SITE_SERVICE.createSite(
TEST_SITE_PREFIX,
LinksServiceImplTest.class.getSimpleName() + "_testSite" + System.currentTimeMillis(),
"test site title", "test site description",
SiteVisibility.PUBLIC
);
privateCalendarService.getSiteLinksContainer(site.getShortName(), true);
CLASS_TEST_NODES_TO_TIDY.add(site.getNodeRef());
return site;
}
});
// Create the alternate site as admin
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
ALTERNATE_LINKS_SITE = TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<SiteInfo>()
{
@Override
public SiteInfo execute() throws Throwable
{
SiteInfo site = SITE_SERVICE.createSite(
TEST_SITE_PREFIX,
LinksServiceImplTest.class.getSimpleName() + "_testAltSite" + System.currentTimeMillis(),
"alternate site title", "alternate site description",
SiteVisibility.PRIVATE
);
privateCalendarService.getSiteLinksContainer(site.getShortName(), true);
CLASS_TEST_NODES_TO_TIDY.add(site.getNodeRef());
return site;
}
});
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
}
/**
* By default, all tests are run as the admin user.
*/
@Before public void setAdminUser()
{
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
}
@After public void deleteTestNodes() throws Exception
{
performDeletionOfNodes(testNodesToTidy);
}
@AfterClass public static void deleteClassTestNodesAndUsers() throws Exception
{
performDeletionOfNodes(CLASS_TEST_NODES_TO_TIDY);
deleteUser(TEST_USER);
}
/**
* Deletes the specified NodeRefs, if they exist.
* @param nodesToDelete
*/
private static void performDeletionOfNodes(final List<NodeRef> nodesToDelete)
{
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
for (NodeRef node : nodesToDelete)
{
if (NODE_SERVICE.exists(node))
{
// st:site nodes can only be deleted via the SiteService
if (NODE_SERVICE.getType(node).equals(SiteModel.TYPE_SITE))
{
SiteInfo siteInfo = SITE_SERVICE.getSite(node);
SITE_SERVICE.deleteSite(siteInfo.getShortName());
}
else
{
NODE_SERVICE.deleteNode(node);
}
}
}
return null;
}
});
}
private static void createUser(final String userName)
{
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
if (!AUTHENTICATION_SERVICE.authenticationExists(userName))
{
AUTHENTICATION_SERVICE.createAuthentication(userName, "PWD".toCharArray());
}
if (!PERSON_SERVICE.personExists(userName))
{
PropertyMap ppOne = new PropertyMap();
ppOne.put(ContentModel.PROP_USERNAME, userName);
ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName");
ppOne.put(ContentModel.PROP_LASTNAME, "lastName");
ppOne.put(ContentModel.PROP_EMAIL, "email@email.com");
ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle");
PERSON_SERVICE.createPerson(ppOne);
}
return null;
}
});
}
private static void deleteUser(final String userName)
{
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
if (PERSON_SERVICE.personExists(userName))
{
PERSON_SERVICE.deletePerson(userName);
}
return null;
}
});
}
}

View File

@@ -0,0 +1,109 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* 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/>.
*/
package org.alfresco.service.cmr.links;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import org.alfresco.repo.security.permissions.PermissionCheckValue;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* This class represents a Link in a site
*
* @author Nick Burch
* @since 4.0
*/
public interface LinkInfo extends Serializable, PermissionCheckValue {
/**
* @return the NodeRef of the underlying link
*/
NodeRef getNodeRef();
/**
* @return the NodeRef of the site container this belongs to
*/
NodeRef getContainerNodeRef();
/**
* @return the System generated name for the link
*/
String getSystemName();
/**
* @return the Title of the link
*/
String getTitle();
/**
* Sets the Title of the link
*/
void setTitle(String title);
/**
* @return the Description of the link
*/
String getDescription();
/**
* Sets the Description of the link
*/
void setDescription(String description);
/**
* @return the URL of the link
*/
String getURL();
/**
* Sets the URL of the link
*/
void setURL(String url);
/**
* @return the creator of the link
*/
String getCreator();
/**
* @return the creation date and time
*/
Date getCreatedAt();
/**
* @return the modification date and time
*/
Date getModifiedAt();
/**
* Is this a internal link?
*/
boolean isInternal();
/**
* Sets if this is an internal link or not
*/
void setInternal(boolean internal);
/**
* @return the Tags associated with the link
*/
List<String> getTags();
}

View File

@@ -0,0 +1,92 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* 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/>.
*/
package org.alfresco.service.cmr.links;
import java.util.Date;
import org.alfresco.query.PagingRequest;
import org.alfresco.query.PagingResults;
import org.alfresco.service.NotAuditable;
/**
* The Links service.
*
* @author Nick Burch
* @since 4.0
*/
public interface LinksService {
/**
* Creates a new {@link LinkInfo} in the given site, with the
* specified settings
*
* @return The newly created {@link LinkInfo}
*/
@NotAuditable
LinkInfo createLink(String siteShortName, String title,
String description, String url, boolean internal);
/**
* Updates an existing {@link LinkInfo} in the repository.
*
* @return The updated {@link LinkInfo}
*/
@NotAuditable
LinkInfo updateLink(LinkInfo link);
/**
* Deletes an existing {@link LinkInfo} from the repository
*/
@NotAuditable
void deleteLink(LinkInfo entry);
/**
* Retrieves an existing {@link LinkInfo} from the repository
*/
@NotAuditable
LinkInfo getLink(String siteShortName, String linkName);
/**
* Retrieves all {@link LinkInfo} instances in the repository
* for the given site.
*/
@NotAuditable
PagingResults<LinkInfo> listLinks(String siteShortName, PagingRequest paging);
/**
* Retrieves all {@link LinkInfo} instances in the repository
* for the given site and the specified user.
*/
@NotAuditable
PagingResults<LinkInfo> listLinks(String siteShortName, String user, PagingRequest paging);
/**
* Retrieves all {@link LinkInfo} instances in the repository
* for the given site, created in the specified date range
*/
@NotAuditable
PagingResults<LinkInfo> listLinks(String siteShortName, Date from, Date to, PagingRequest paging);
/**
* Finds all {@link LinkInfo} instances indexed in the repository
* for the given site, created by the specified user in the specified
* date range, with the given tag
*/
@NotAuditable
PagingResults<LinkInfo> findLinks(String siteShortName, String user, Date from, Date to, String tag, PagingRequest paging);
}