Java Code Examples for org.alfresco.service.cmr.site.SiteInfo#getShortName()

The following examples show how to use org.alfresco.service.cmr.site.SiteInfo#getShortName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SiteMembership.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public SiteMembership(SiteInfo siteInfo, String personId, String firstName, String lastName,
        String role)
{
    super();
    if (siteInfo == null)
    {
        throw new java.lang.IllegalArgumentException();
    }
    if (personId == null)
    {
        throw new java.lang.IllegalArgumentException(
                "Person required building site membership of " + siteInfo.getShortName());
    }
    if (firstName == null)
    {
        throw new java.lang.IllegalArgumentException(
                "FirstName required building site membership of " + siteInfo.getShortName());
    }
    if (lastName == null)
    {
        throw new java.lang.IllegalArgumentException(
                "LastName required building site membership of " + siteInfo.getShortName());
    }
    if (role == null)
    {
        throw new java.lang.IllegalArgumentException(
                "Role required building site membership of " + siteInfo.getShortName());
    }
    this.siteInfo = siteInfo;
    this.personId = personId;
    this.firstName = firstName;
    this.lastName = lastName;
    this.role = role;
}
 
Example 2
Source File: SitesImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
public FavouriteSite getFavouriteSite(String personId, String siteId)
{
    personId = people.validatePerson(personId);
    SiteInfo siteInfo = validateSite(siteId);
    if(siteInfo == null)
    {
        // site does not exist
        throw new RelationshipResourceNotFoundException(personId, siteId);
    }
    // set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
    siteId = siteInfo.getShortName();
    NodeRef nodeRef = siteInfo.getNodeRef();

    if(favouritesService.isFavourite(personId, nodeRef))
    {
        String role = getSiteRole(siteId, personId);
        return new FavouriteSite(siteInfo, role);
    }
    else
    {
        throw new RelationshipResourceNotFoundException(personId, siteId);
    }
}
 
Example 3
Source File: SiteMembershipRequestsImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void cancelSiteMembershipRequest(String inviteeId, String siteId)
{
	inviteeId = people.validatePerson(inviteeId);
	SiteInfo siteInfo = sites.validateSite(siteId);
   	if(siteInfo == null)
   	{
   		// site does not exist
   		throw new RelationshipResourceNotFoundException(inviteeId, siteId);
   	}
	// set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
	siteId = siteInfo.getShortName();

	Invitation invitation = getSiteInvitation(inviteeId, siteId);
	if(invitation == null)
	{
		// no such invitation
   		throw new RelationshipResourceNotFoundException(inviteeId, siteId);
	}
	invitationService.cancel(invitation.getInviteId());
}
 
Example 4
Source File: SitesImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void removeFavouriteSite(String personId, String siteId)
{
    personId = people.validatePerson(personId);
    SiteInfo siteInfo = validateSite(siteId);
    if(siteInfo == null)
    {
        // site does not exist
        throw new RelationshipResourceNotFoundException(personId, siteId);
    }
    siteId = siteInfo.getShortName();

    StringBuilder prefKey = new StringBuilder(FAVOURITE_SITES_PREFIX);
    prefKey.append(siteId);
    String value = (String)preferenceService.getPreference(personId, prefKey.toString());
    boolean isFavouriteSite = (value == null ? false : value.equalsIgnoreCase("true"));

    if(!isFavouriteSite)
    {
        throw new NotFoundException("Site " + siteId + " is not a favourite site");
    }

    preferenceService.clearPreferences(personId, prefKey.toString());
}
 
Example 5
Source File: SiteExportGet.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void doUserACPExport(List<NodeRef> userNodes, SiteInfo site,
        CloseIgnoringOutputStream writeTo) throws IOException
{
    // Build the parameters
    ExporterCrawlerParameters parameters = new ExporterCrawlerParameters();
    parameters.setExportFrom(new Location(userNodes.toArray(new NodeRef[userNodes.size()])));
    parameters.setCrawlChildNodes(true);
    parameters.setCrawlSelf(true);
    parameters.setCrawlContent(true);
    
    // And the export handler
    ACPExportPackageHandler handler = new ACPExportPackageHandler(
            writeTo,
            new File(site.getShortName() + "-users.xml"),
            new File(site.getShortName() + "-users"),
            mimetypeService);
    
    // Do the export
    exporterService.exportView(handler, parameters, null);
}
 
Example 6
Source File: SiteExportGet.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void doPeopleACPExport(final List<NodeRef> peopleNodes, SiteInfo site, CloseIgnoringOutputStream writeTo) throws IOException
{
    if (!peopleNodes.isEmpty())
    {
        // Build the parameters
        ExporterCrawlerParameters parameters = new ExporterCrawlerParameters();
        parameters.setExportFrom(new Location(peopleNodes.toArray(new NodeRef[peopleNodes.size()])));
        parameters.setCrawlChildNodes(true);
        parameters.setCrawlSelf(true);
        parameters.setCrawlContent(true);
        
        // And the export handler
        ACPExportPackageHandler handler = new ACPExportPackageHandler(
                writeTo,
                new File(site.getShortName() + "-people.xml"),
                new File(site.getShortName() + "-people"),
                mimetypeService);
        
        // Do the export
        exporterService.exportView(handler, parameters, null);
    }
}
 
Example 7
Source File: SiteExportGet.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void doSiteACPExport(SiteInfo site, CloseIgnoringOutputStream writeTo) throws IOException
{
    // Build the parameters
    ExporterCrawlerParameters parameters = new ExporterCrawlerParameters();
    parameters.setExportFrom(new Location(site.getNodeRef()));
    parameters.setCrawlChildNodes(true);
    parameters.setCrawlSelf(true);
    parameters.setCrawlContent(true);
    
    // And the export handler
    ACPExportPackageHandler handler = new ACPExportPackageHandler(
            writeTo,
            new File(site.getShortName() + ".xml"),
            new File(site.getShortName()),
            mimetypeService);
    
    // Do the export
    exporterService.exportView(handler, parameters, null);
}
 
Example 8
Source File: SiteMembership.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public SiteMembership(SiteInfo siteInfo, String personId, String role)
{
    super();
    if (siteInfo == null)
    {
        throw new java.lang.IllegalArgumentException();
    }
    if (personId == null)
    {
        throw new java.lang.IllegalArgumentException(
                "Person required building site membership of " + siteInfo.getShortName());
    }
    if (role == null)
    {
        throw new java.lang.IllegalArgumentException(
                "Role required building site membership of " + siteInfo.getShortName());
    }

    this.siteInfo = siteInfo;
    this.personId = personId;
    this.role = role;
}
 
Example 9
Source File: SitesImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void deleteSite(String siteId, Parameters parameters)
{
    boolean isSiteAdmin = siteService.isSiteAdmin(AuthenticationUtil.getFullyAuthenticatedUser());
    SiteInfo siteInfo = validateSite(siteId);
    if (siteInfo == null)
    {
        // site does not exist
        throw new EntityNotFoundException(siteId);
    }
    siteId = siteInfo.getShortName();

    NodeRef siteNodeRef = siteInfo.getNodeRef();

    // belt-and-braces - double-check before purge/delete (rather than
    // rollback)
    if ((isSiteAdmin == false) && (permissionService.hasPermission(siteNodeRef, PermissionService.DELETE) != AccessStatus.ALLOWED))
    {
        throw new AccessDeniedException("Cannot delete site: " + siteId);
    }

    // default false (if not provided)
    boolean permanentDelete = Boolean.valueOf(parameters.getParameter(PARAM_PERMANENT));

    if (permanentDelete == true)
    {
        // Set as temporary to delete node instead of archiving.
        nodeService.addAspect(siteNodeRef, ContentModel.ASPECT_TEMPORARY, null);

        // bypassing trashcan means that purge behaviour will not fire, so
        // explicitly force cleanup here
        siteServiceImpl.beforePurgeNode(siteNodeRef);
    }

    siteService.deleteSite(siteId);
}
 
Example 10
Source File: InvitationServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Generates a description for the workflow
 * 
 * @param siteInfo The site to generate a description for
 * @param messageId The resource bundle key to use for the description 
 * @return The workflow description
 */
protected String generateWorkflowDescription(SiteInfo siteInfo, String messageId)
{
    String siteTitle = siteInfo.getTitle();
    if (siteTitle == null || siteTitle.length() == 0)
    {
        siteTitle = siteInfo.getShortName();
    }
    
    Locale locale = (Locale) this.nodeService.getProperty(siteInfo.getNodeRef(), ContentModel.PROP_LOCALE);
    
    return I18NUtil.getMessage(messageId, locale == null ? I18NUtil.getLocale() : locale, siteTitle);
}
 
Example 11
Source File: SitesImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public SiteMember updateSiteMember(String siteId, SiteMember siteMember)
{
    String siteMemberId = siteMember.getPersonId();
    if(siteMemberId == null)
    {
        throw new InvalidArgumentException("Member id is null");
    }
    siteMemberId = people.validatePerson(siteMemberId);
    SiteInfo siteInfo = validateSite(siteId);
    if(siteInfo == null)
    {
        // site does not exist
        throw new EntityNotFoundException(siteId);
    }
    siteId = siteInfo.getShortName();
    String siteRole = siteMember.getRole();
    if(siteRole == null)
    {
        throw new InvalidArgumentException("Must provide a role");
    }

    /* MNT-10551 : fix */
    if (!siteService.isMember(siteId, siteMember.getPersonId()))
    {
        throw new InvalidArgumentException("User is not a member of the site");
    }

    try
    {
        siteService.setMembership(siteId, siteMember.getPersonId(), siteRole);
    }
    catch (UnknownAuthorityException e)
    {
        throw new InvalidArgumentException("Unknown role '" + siteRole + "'");
    }
    return siteMember;
}
 
Example 12
Source File: SitesImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void removeSiteMember(String personId, String siteId)
{
    personId = people.validatePerson(personId);
    SiteInfo siteInfo = validateSite(siteId);
    if(siteInfo == null)
    {
        // site does not exist
        throw new RelationshipResourceNotFoundException(personId, siteId);
    }
    // set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
    siteId = siteInfo.getShortName();

    boolean isMember = siteService.isMember(siteId, personId);
    if(!isMember)
    {
        throw new InvalidArgumentException();
    }
    String role = siteService.getMembersRole(siteId, personId);
    if(role != null)
    {
        if(role.equals(SiteModel.SITE_MANAGER))
        {
            int numAuthorities = siteService.countAuthoritiesWithRole(siteId, SiteModel.SITE_MANAGER);
            if(numAuthorities <= 1)
            {
                throw new InvalidArgumentException("Can't remove last manager of site " + siteId);
            }
            siteService.removeMembership(siteId, personId);
        }
        else
        {
            siteService.removeMembership(siteId, personId);
        }
    }
    else
    {
        throw new AlfrescoRuntimeException("Unable to determine role of site member");
    }
}
 
Example 13
Source File: NodesImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected ActivityInfo getActivityInfo(NodeRef parentNodeRef, NodeRef nodeRef)
{
    // runAs system, eg. user may not have permission see one or more parents (irrespective of whether in a site context of not)
    SiteInfo siteInfo = AuthenticationUtil.runAs(new RunAsWork<SiteInfo>()
    {
        @Override
        public SiteInfo doWork() throws Exception
        {
            return siteService.getSite(nodeRef);
        }
    }, AuthenticationUtil.getSystemUserName());

    String siteId = (siteInfo != null ? siteInfo.getShortName() : null);
    if(siteId != null && !siteId.equals(""))
    {
        FileInfo fileInfo = fileFolderService.getFileInfo(nodeRef);
        if (fileInfo != null)
        {
            boolean isContent = isSubClass(fileInfo.getType(), ContentModel.TYPE_CONTENT);

            if (fileInfo.isFolder() || isContent)
            {
                return new ActivityInfo(null, parentNodeRef, siteId, fileInfo);
            }
        }
    }
    else
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("Non-site activity, so ignored " + nodeRef);
        }
    }
    return null;
}
 
Example 14
Source File: SiteMembershipRequestsImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
private SiteMembershipRequest inviteToPublicSite(final SiteInfo siteInfo, final String message, final String inviteeId,
		final String inviteeRole)
{
	SiteMembershipRequest siteMembershipRequest = null;

	final String siteId = siteInfo.getShortName();
	NodeRef siteNodeRef = siteInfo.getNodeRef();
	String siteCreator = (String)nodeService.getProperty(siteNodeRef, ContentModel.PROP_CREATOR);

	final String siteNetwork = networksService.getUserDefaultNetwork(siteCreator);
	if(StringUtils.isNotEmpty(siteNetwork))
	{
		// MT
		siteMembershipRequest = TenantUtil.runAsUserTenant(new TenantRunAsWork<SiteMembershipRequest>()
		{
			@Override
			public SiteMembershipRequest doWork() throws Exception
			{
				return inviteToSite(siteId, inviteeId, inviteeRole, message);
			}
		}, siteCreator, siteNetwork);
	}
	else
	{
		siteMembershipRequest = AuthenticationUtil.runAs(new RunAsWork<SiteMembershipRequest>()
		{
			@Override
			public SiteMembershipRequest doWork() throws Exception
			{
				return inviteToSite(siteId, inviteeId, inviteeRole, message);
			}
		}, siteCreator);
	}

	return siteMembershipRequest;
}
 
Example 15
Source File: SitesImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public SiteContainer getSiteContainer(String siteId, String containerId)
{
    // check site and container node validity
    SiteInfo siteInfo = validateSite(siteId);
    if(siteInfo == null)
    {
        // site does not exist
        throw new RelationshipResourceNotFoundException(siteId, containerId);
    }
    // set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
    siteId = siteInfo.getShortName();

    NodeRef containerNodeRef = siteService.getContainer(siteId, containerId);
    if(containerNodeRef == null)
    {
        throw new RelationshipResourceNotFoundException(siteId, containerId);
    }

    // check that the containerId is actually a container for the specified site
    SiteInfo testSiteInfo = siteService.getSite(containerNodeRef);
    if(testSiteInfo == null)
    {
        throw new RelationshipResourceNotFoundException(siteId, containerId);
    }
    else
    {
        if(!testSiteInfo.getShortName().equals(siteId))
        {
            throw new RelationshipResourceNotFoundException(siteId, containerId);
        }
    }

    String folderId = (String)nodeService.getProperty(containerNodeRef, SiteModel.PROP_COMPONENT_ID);

    SiteContainer siteContainer = new SiteContainer(folderId, containerNodeRef);
    return siteContainer;
}
 
Example 16
Source File: SitesImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Create default/fixed preset (Share) site - with DocLib container/component
 *
 * @param site
 * @return
 */
public Site createSite(Site site, Parameters parameters)
{
    // note: if site id is null then will be generated from the site title
    site = validateSite(site);

    SiteInfo siteInfo = null;
    try
    {
        siteInfo = createSite(site);
    }
    catch (SiteServiceException sse)
    {
        if (sse.getMsgId().equals("site_service.unable_to_create"))
        {
            throw new ConstraintViolatedException(sse.getMessage());
        }
        else
        {
            throw sse;
        }
    }

    String siteId = siteInfo.getShortName();
    NodeRef siteNodeRef = siteInfo.getNodeRef();

    // default false (if not provided)
    boolean skipShareSurfConfig = Boolean.valueOf(parameters.getParameter(PARAM_SKIP_SURF_CONFIGURATION));
    if (skipShareSurfConfig == false)
    {
        // import default/fixed preset Share surf config
        importSite(siteId, siteNodeRef);
    }

    // pre-create doclib
    siteService.createContainer(siteId, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null);

    // default false (if not provided)
    boolean skipAddToFavorites = Boolean.valueOf(parameters.getParameter(PARAM_SKIP_ADDTOFAVORITES));
    if (skipAddToFavorites == false)
    {
        String personId = AuthenticationUtil.getFullyAuthenticatedUser();
        favouritesService.addFavourite(personId, siteNodeRef); // ignore result
    }

    return getSite(siteInfo, true);
}
 
Example 17
Source File: ActivityPosterImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void postFileFolderAdded(NodeRef nodeRef)
{
    if(activitiesEnabled && !hiddenAspect.hasHiddenAspect(nodeRef))
    {
        SiteInfo siteInfo = siteService.getSite(nodeRef);
        String siteId = (siteInfo != null ? siteInfo.getShortName() : null);
        
        if(siteId != null && !siteId.equals(""))
        {
            // post only for nodes within sites
            NodeRef parentNodeRef = nodeService.getPrimaryParent(nodeRef).getParentRef();

            String path = null;
            boolean isFolder = isFolder(nodeRef);
            String name = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);

            if(isFolder)
            {
                NodeRef documentLibrary = siteService.getContainer(siteId, SiteService.DOCUMENT_LIBRARY);
                path = "/";
                try
                {
                    path = getPathFromNode(documentLibrary, nodeRef);
                }
                catch (FileNotFoundException error)
                {
                    if (logger.isDebugEnabled())
                    {
                        logger.debug("No " + SiteService.DOCUMENT_LIBRARY + " container found.");
                    }
                }
            }
            FileInfo fileInfo = fileFolderService.getFileInfo(nodeRef);
            poster.postFileFolderActivity((isFolder ? ActivityType.FOLDER_ADDED : ActivityType.FILE_ADDED), path, getCurrentTenantDomain(),
                                           siteId, parentNodeRef, nodeRef, name, APP_TOOL, Client.asType(ClientType.cmis), fileInfo);
            
        }
    }
}
 
Example 18
Source File: SiteMembershipRequestsImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public SiteMembershipRequest createSiteMembershipRequest(String inviteeId, final SiteMembershipRequest siteInvite)
{
   	SiteMembershipRequest request = null;

   	inviteeId = people.validatePerson(inviteeId, true);

   	// Note that the order of error checking is important. The server first needs to check for the status 404 
   	// conditions before checking for status 400 conditions. Otherwise the server is open to a probing attack. 
	String siteId = siteInvite.getId();
	final SiteInfo siteInfo = sites.validateSite(siteId);
   	if(siteInfo == null)
   	{
   		// site does not exist
   		throw new RelationshipResourceNotFoundException(inviteeId, siteId);
   	}
	// set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
	siteId = siteInfo.getShortName();

	final SiteVisibility siteVisibility = siteInfo.getVisibility();

	if(siteVisibility.equals(SiteVisibility.PRIVATE))
	{
		// note: security, no indication that this is a private site
		throw new RelationshipResourceNotFoundException(inviteeId, siteId);
	}

	// Is the invitee already a member of the site?
	boolean isMember = siteService.isMember(siteId, inviteeId);
	if(isMember)
	{
		// yes
		throw new InvalidArgumentException(inviteeId + " is already a member of site " + siteId);
	}

	// Is there an outstanding site invite request for the (invitee, site)?
	Invitation invitation = getSiteInvitation(inviteeId, siteId);
	if(invitation != null)
	{
		// yes
		throw new InvalidArgumentException(inviteeId + " is already invited to site " + siteId);
	}

	final String inviteeRole = DEFAULT_ROLE;
	String message = siteInvite.getMessage();
	if(message == null)
	{
		// the invitation service ignores null messages so convert to an empty message.
		message = "";
	}

	if(siteVisibility.equals(SiteVisibility.MODERATED))
	{
		request = inviteToModeratedSite(message, inviteeId, siteId, inviteeRole);
	}
	else if(siteVisibility.equals(SiteVisibility.PUBLIC))
	{
		request = inviteToPublicSite(siteInfo, message, inviteeId, inviteeRole);
	}
	else
	{
		// note: security, no indication that this is a private site
		throw new RelationshipResourceNotFoundException(inviteeId, siteId);
	}

	return request;
}
 
Example 19
Source File: SitesImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
public CollectionWithPagingInfo<MemberOfSite> getSites(String personId, Parameters parameters)
{
    Paging paging = parameters.getPaging();

    personId = people.validatePerson(personId);

    PagingRequest pagingRequest = Util.getPagingRequest(paging);

    // get the sorting options
    List<Pair<? extends Object, SortOrder>> sortPairs = new ArrayList<>(parameters.getSorting().size());

    List<SortColumn> sortCols = parameters.getSorting();
    if ((sortCols != null) && (sortCols.size() > 0))
    {
        for (SortColumn sortCol : sortCols)
        {
            SiteService.SortFields sortProp = SORT_SITE_MEMBERSHIP.get(sortCol.column);
            if (sortProp == null)
            {
                throw new InvalidArgumentException("Invalid sort field: "+sortCol.column);
            }
            sortPairs.add(new Pair<>(sortProp, (sortCol.asc ? SortOrder.ASCENDING : SortOrder.DESCENDING)));
        }
    }
    else
    {
        // default sort order
        sortPairs.add(new Pair<SiteService.SortFields, SortOrder>(
                SiteService.SortFields.SiteTitle,
                SortOrder.ASCENDING ));
    }

    // get the unsorted list of site memberships
    List<SiteMembership> siteMembers = siteService.listSiteMemberships(personId, 0);

    // sort the list of site memberships
    int totalSize = siteMembers.size();
    final List<SiteMembership> sortedSiteMembers = new ArrayList<>(siteMembers);
    Collections.sort(sortedSiteMembers, new SiteMembershipComparator(
                sortPairs,
                SiteMembershipComparator.Type.SITES));

    PageDetails pageDetails = PageDetails.getPageDetails(pagingRequest, totalSize);
    List<MemberOfSite> ret = new ArrayList<>(totalSize);

    List<FilterProp> filterProps = getFilterPropListOfSites(parameters);

    int counter;
    int totalItems = 0;
    Iterator<SiteMembership> it = sortedSiteMembers.iterator();
    for(counter = 0; it.hasNext();)
    {
        SiteMembership siteMember = it.next();

        if (filterProps != null && !includeFilter(siteMember, filterProps))
        {
            continue;
        }

        if(counter < pageDetails.getSkipCount())
        {
            totalItems++;
            counter++;
            continue;
        }
        
        if (counter <= pageDetails.getEnd() - 1)
        {
            SiteInfo siteInfo = siteMember.getSiteInfo();
            MemberOfSite memberOfSite = new MemberOfSite(siteInfo.getShortName(), siteInfo.getNodeRef(), siteMember.getRole());
            ret.add(memberOfSite);

            counter++;
        }

        totalItems++;
    }
    return CollectionWithPagingInfo.asPaged(paging, ret, counter < totalItems, totalItems);

}
 
Example 20
Source File: SitesImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
public SiteMember addSiteMember(String siteId, SiteMember siteMember)
{
	String personId = people.validatePerson(siteMember.getPersonId());
   	SiteInfo siteInfo = validateSite(siteId);
   	if(siteInfo == null)
   	{
   		// site does not exist
		logger.debug("addSiteMember:  site does not exist "+siteId+ " person "+personId);
   		throw new EntityNotFoundException(siteId);
   	}
   	// set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
   	siteId = siteInfo.getShortName();
   	
   	String role = siteMember.getRole();
   	if(role == null)
   	{
		logger.debug("addSiteMember:  Must provide a role "+siteMember);
   		throw new InvalidArgumentException("Must provide a role");
   	}
   	
   	if(siteService.isMember(siteId, personId))
   	{
		logger.debug("addSiteMember:  "+ personId + " is already a member of site " + siteId);
   		throw new ConstraintViolatedException(personId + " is already a member of site " + siteId);
   	}

   	if(!siteService.canAddMember(siteId, personId, role))
   	{
		logger.debug("addSiteMember:  PermissionDeniedException "+siteId+ " person "+personId+ " role "+role);
   		throw new PermissionDeniedException();
   	}

       try
       {
           siteService.setMembership(siteId, personId, role);
       }
       catch (UnknownAuthorityException e)
       {
		logger.debug("addSiteMember:  UnknownAuthorityException "+siteId+ " person "+personId+ " role "+role);
           throw new InvalidArgumentException("Unknown role '" + role + "'");
       }
       return siteMember;
   }