Search in sources :

Example 31 with SiteInfo

use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-remote-api by Alfresco.

the class SitesImpl method getSites.

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);
}
Also used : SiteMembershipComparator(org.alfresco.repo.site.SiteMembershipComparator) ArrayList(java.util.ArrayList) SortColumn(org.alfresco.rest.framework.resource.parameters.SortColumn) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) SiteMembership(org.alfresco.repo.site.SiteMembership) SiteService(org.alfresco.service.cmr.site.SiteService) Pair(org.alfresco.util.Pair) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) FilterProp(org.alfresco.repo.node.getchildren.FilterProp) Paging(org.alfresco.rest.framework.resource.parameters.Paging) SortOrder(org.alfresco.query.CannedQuerySortDetails.SortOrder) PagingRequest(org.alfresco.query.PagingRequest) PageDetails(org.alfresco.query.PageDetails)

Example 32 with SiteInfo

use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-remote-api by Alfresco.

the class SitesImpl method updateSite.

@Override
public Site updateSite(String siteId, SiteUpdate update, Parameters parameters) {
    if (logger.isDebugEnabled()) {
        logger.debug("Updating site, ID: " + siteId + ", site data: " + update + ", parameters: " + parameters);
    }
    // Get the site by ID (aka short name)
    SiteInfo siteInfo = validateSite(siteId);
    if (siteInfo == null) {
        // site does not exist
        throw new EntityNotFoundException(siteId);
    }
    // Bind any provided values to the site info, allowing for "partial" updates.
    if (update.wasSet(Site.TITLE)) {
        siteInfo.setTitle(update.getTitle());
    }
    if (update.wasSet(Site.DESCRIPTION)) {
        siteInfo.setDescription(update.getDescription());
    }
    if (update.wasSet(Site.VISIBILITY)) {
        siteInfo.setVisibility(update.getVisibility());
    }
    // Validate the new details
    validateSite(new Site(siteInfo, null));
    // Perform the actual update.
    siteService.updateSite(siteInfo);
    return getSite(siteId);
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Example 33 with SiteInfo

use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-remote-api by Alfresco.

the class Invites method executeImpl.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco
     * .web.scripts.WebScriptRequest,
     * org.alfresco.web.scripts.WebScriptResponse)
     */
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) {
    // initialise model to pass on for template to render
    Map<String, Object> model = new HashMap<String, Object>();
    // Get parameter names
    String[] paramNames = req.getParameterNames();
    // handle no parameters given on URL
    if ((paramNames == null) || (paramNames.length == 0)) {
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, "No parameters have been provided on URL");
    }
    // get URL request parameters, checking if at least one has been provided
    // check if 'inviterUserName' parameter provided
    String inviterUserName = req.getParameter(PARAM_INVITER_USER_NAME);
    boolean inviterUserNameProvided = (inviterUserName != null) && (inviterUserName.length() != 0);
    // check if 'inviteeUserName' parameter provided
    String inviteeUserName = req.getParameter(PARAM_INVITEE_USER_NAME);
    boolean inviteeUserNameProvided = (inviteeUserName != null) && (inviteeUserName.length() != 0);
    // check if 'siteShortName' parameter provided
    String siteShortName = req.getParameter(PARAM_SITE_SHORT_NAME);
    boolean siteShortNameProvided = (siteShortName != null) && (siteShortName.length() != 0);
    // check if 'inviteId' parameter provided
    String inviteId = req.getParameter(PARAM_INVITE_ID);
    boolean inviteIdProvided = (inviteId != null) && (inviteId.length() != 0);
    // 'inviteId' URL request parameters has not been provided
    if (!(inviterUserNameProvided || inviteeUserNameProvided || siteShortNameProvided || inviteIdProvided)) {
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, "At least one of the following URL request parameters must be provided in URL " + "'inviterUserName', 'inviteeUserName', 'siteShortName' or 'inviteId'");
    }
    // InviteInfo List to place onto model
    List<InviteInfo> inviteInfoList = new ArrayList<InviteInfo>();
    // query properties
    if (inviteIdProvided) {
        NominatedInvitation invitation = (NominatedInvitation) invitationService.getInvitation(inviteId);
        Map<String, SiteInfo> siteInfoCache = new HashMap<String, SiteInfo>(2);
        inviteInfoList.add(toInviteInfo(siteInfoCache, invitation));
    } else // 'inviteId' has not been provided, so create the query properties from
    // the invite URL request
    // parameters
    // - because this web script class will terminate with a web script
    // exception if none of the required
    // request parameters are provided, at least one of these query
    // properties will be set
    // at this point
    {
        InvitationSearchCriteriaImpl criteria = new InvitationSearchCriteriaImpl();
        criteria.setInvitationType(InvitationSearchCriteria.InvitationType.NOMINATED);
        criteria.setResourceType(Invitation.ResourceType.WEB_SITE);
        if (inviterUserNameProvided) {
            criteria.setInviter(inviterUserName);
        }
        if (inviteeUserNameProvided) {
            criteria.setInvitee(inviteeUserName);
        }
        if (siteShortNameProvided) {
            criteria.setResourceName(siteShortName);
        }
        // MNT-9905 Pending Invites created by one site manager aren't visible to other site managers
        String currentUser = AuthenticationUtil.getRunAsUser();
        List<Invitation> invitations;
        if (siteShortNameProvided == true && (SiteModel.SITE_MANAGER).equals(siteService.getMembersRole(siteShortName, currentUser)) && inviterUserNameProvided == false && inviteeUserNameProvided == false) {
            final InvitationSearchCriteriaImpl crit = criteria;
            RunAsWork<List<Invitation>> runAsSystem = new RunAsWork<List<Invitation>>() {

                @Override
                public List<Invitation> doWork() throws Exception {
                    return invitationService.searchInvitation(crit);
                }
            };
            invitations = AuthenticationUtil.runAs(runAsSystem, AuthenticationUtil.getSystemUserName());
        } else {
            invitations = invitationService.searchInvitation(criteria);
        }
        // Put InviteInfo objects (containing workflow path properties
        // wf:inviterUserName, wf:inviteeUserName, wf:siteShortName,
        // and invite id property (from workflow instance id))
        // onto model for each invite workflow task returned by the query
        Map<String, SiteInfo> siteInfoCache = new HashMap<String, SiteInfo>(invitations.size() * 2);
        for (Invitation invitation : invitations) {
            inviteInfoList.add(toInviteInfo(siteInfoCache, (NominatedInvitation) invitation));
        }
    }
    // put the list of invite infos onto model to be passed onto template
    // for rendering
    model.put(MODEL_KEY_NAME_INVITES, inviteInfoList);
    return model;
}
Also used : InviteInfo(org.alfresco.repo.invitation.site.InviteInfo) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NominatedInvitation(org.alfresco.service.cmr.invitation.NominatedInvitation) HashMap(java.util.HashMap) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) ArrayList(java.util.ArrayList) NominatedInvitation(org.alfresco.service.cmr.invitation.NominatedInvitation) Invitation(org.alfresco.service.cmr.invitation.Invitation) InvitationSearchCriteriaImpl(org.alfresco.repo.invitation.InvitationSearchCriteriaImpl) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 34 with SiteInfo

use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-remote-api by Alfresco.

the class Invites method toInviteInfo.

private InviteInfo toInviteInfo(Map<String, SiteInfo> siteInfoCache, final NominatedInvitation invitation) {
    // get the site info
    String resourceName = invitation.getResourceName();
    SiteInfo siteInfo = siteInfoCache.get(resourceName);
    if (siteInfo == null) {
        siteInfo = siteService.getSite(resourceName);
        siteInfoCache.put(resourceName, siteInfo);
    }
    String invitationStatus = InviteInfo.INVITATION_STATUS_PENDING;
    TemplateNode inviterPerson = getPersonIfAllowed(invitation.getInviterUserName());
    // fetch the person node for the invitee
    TemplateNode inviteePerson = getPersonIfAllowed(invitation.getInviteeUserName());
    InviteInfo ret = new InviteInfo(invitationStatus, invitation.getInviterUserName(), inviterPerson, invitation.getInviteeUserName(), inviteePerson, invitation.getRoleName(), invitation.getResourceName(), siteInfo, invitation.getSentInviteDate(), invitation.getInviteId());
    return ret;
}
Also used : TemplateNode(org.alfresco.repo.template.TemplateNode) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) InviteInfo(org.alfresco.repo.invitation.site.InviteInfo)

Example 35 with SiteInfo

use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-remote-api by Alfresco.

the class AbstractSiteWebScript method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    // Grab the site
    String siteName = req.getServiceMatch().getTemplateVars().get("shortname");
    SiteInfo site = siteService.getSite(siteName);
    if (site == null) {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "No Site found with that short name");
    }
    // Process
    return executeImpl(site, req, status, cache);
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) WebScriptException(org.springframework.extensions.webscripts.WebScriptException)

Aggregations

SiteInfo (org.alfresco.service.cmr.site.SiteInfo)103 NodeRef (org.alfresco.service.cmr.repository.NodeRef)42 ArrayList (java.util.ArrayList)22 Test (org.junit.Test)18 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)15 FilterPropString (org.alfresco.repo.node.getchildren.FilterPropString)15 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)15 RelationshipResourceNotFoundException (org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException)15 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)13 QName (org.alfresco.service.namespace.QName)13 HashMap (java.util.HashMap)12 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)12 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)12 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)12 IOException (java.io.IOException)8 Serializable (java.io.Serializable)8 JSONObject (org.json.simple.JSONObject)8 RMSite (org.alfresco.rm.rest.api.model.RMSite)7 UnknownAuthorityException (org.alfresco.repo.security.authority.UnknownAuthorityException)5 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)5