Search in sources :

Example 81 with SiteInfo

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

the class SiteTitleDisplayHandler method getDisplayLabel.

@Override
public FacetLabel getDisplayLabel(String value) {
    // Solr returns the site short name encoded
    value = ISO9075.decode(value);
    String title = null;
    if (nonSiteLocationsLabels.containsKey(value)) {
        title = nonSiteLocationsLabels.get(value);
    } else {
        SiteService siteService = serviceRegistry.getSiteService();
        SiteInfo siteInfo = siteService.getSite(value);
        title = siteInfo != null ? siteInfo.getTitle() : value;
    }
    return new FacetLabel(value, title, -1);
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) SiteService(org.alfresco.service.cmr.site.SiteService)

Example 82 with SiteInfo

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

the class SiteServiceImpl method createSite.

public SiteInfo createSite(final String sitePreset, String passedShortName, final String title, final String description, final SiteVisibility visibility, final QName siteType) {
    // Check that the provided site type is a subtype of TYPE_SITE
    if (SiteModel.TYPE_SITE.equals(siteType) == false && dictionaryService.isSubClass(siteType, TYPE_SITE) == false) {
        throw new SiteServiceException(MSG_INVALID_SITE_TYPE, new Object[] { siteType });
    }
    // Remove spaces from shortName
    final String shortName = passedShortName.replaceAll(" ", "");
    // Check to see if we already have a site of this name
    NodeRef existingSite = getSiteNodeRef(shortName, false);
    if (existingSite != null || authorityService.authorityExists(getSiteGroup(shortName, true))) {
        // Throw an exception since we have a duplicate site name
        throw new SiteServiceException(MSG_UNABLE_TO_CREATE, new Object[] { shortName });
    }
    // Check that the site name isn't too long
    // Authorities are limited to 100 characters by the PermissionService
    int longestPermissionLength = 0;
    for (String permission : permissionService.getSettablePermissions(siteType)) {
        if (permission.length() > longestPermissionLength)
            longestPermissionLength = permission.length();
    }
    int maximumPermisionGroupLength = 99 - longestPermissionLength;
    if (getSiteGroup(shortName, true).length() > maximumPermisionGroupLength) {
        throw new SiteServiceException(MSG_SITE_SHORT_NAME_TOO_LONG, new Object[] { shortName, maximumPermisionGroupLength - getSiteGroup("", true).length() });
    }
    // Get the site parent node reference
    final NodeRef siteParent = getSiteParent(shortName);
    if (siteParent == null) {
        throw new SiteServiceException("No root sites folder exists");
    }
    // Create the site node
    final PropertyMap properties = new PropertyMap(4);
    properties.put(ContentModel.PROP_NAME, shortName);
    properties.put(SiteModel.PROP_SITE_PRESET, sitePreset);
    properties.put(SiteModel.PROP_SITE_VISIBILITY, visibility.toString());
    properties.put(ContentModel.PROP_TITLE, title);
    properties.put(ContentModel.PROP_DESCRIPTION, description);
    final NodeRef siteNodeRef = AuthenticationUtil.runAs(new RunAsWork<NodeRef>() {

        @Override
        public NodeRef doWork() throws Exception {
            behaviourFilter.disableBehaviour(siteParent, ContentModel.ASPECT_AUDITABLE);
            try {
                return nodeService.createNode(siteParent, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, shortName), siteType, properties).getChildRef();
            } finally {
                behaviourFilter.enableBehaviour(siteParent, ContentModel.ASPECT_AUDITABLE);
            }
        }
    }, AuthenticationUtil.getSystemUserName());
    // Make the new site a tag scope
    this.taggingService.addTagScope(siteNodeRef);
    // Clear the sites inherited permissions
    this.permissionService.setInheritParentPermissions(siteNodeRef, false);
    // Create the relevant groups and assign permissions
    setupSitePermissions(siteNodeRef, shortName, visibility, null);
    eventPublisher.publishEvent(new EventPreparator() {

        @Override
        public Event prepareEvent(String user, String networkId, String transactionId) {
            return new SiteManagementEvent("site.create", transactionId, networkId, new Date().getTime(), user, shortName, title, description, visibility.toString(), sitePreset);
        }
    });
    // Return created site information
    Map<QName, Serializable> customProperties = getSiteCustomProperties(siteNodeRef);
    SiteInfo siteInfo = new SiteInfoImpl(sitePreset, shortName, title, description, visibility, customProperties, siteNodeRef);
    return siteInfo;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) SiteManagementEvent(org.alfresco.sync.events.types.SiteManagementEvent) FilterTypeString(org.alfresco.repo.node.getchildren.FilterPropString.FilterTypeString) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) JSONException(org.json.JSONException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) LuceneQueryParserException(org.alfresco.repo.search.impl.lucene.LuceneQueryParserException) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) NoSuchPersonException(org.alfresco.service.cmr.security.NoSuchPersonException) Date(java.util.Date) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PropertyMap(org.alfresco.util.PropertyMap) EventPreparator(org.alfresco.sync.repo.events.EventPreparator) Event(org.alfresco.sync.events.types.Event) SiteManagementEvent(org.alfresco.sync.events.types.SiteManagementEvent) ApplicationEvent(org.springframework.context.ApplicationEvent)

Example 83 with SiteInfo

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

the class ScriptSiteService method getSite.

/**
 * Get a site for a provided site short name.
 * <p>
 * Returns null if the site does not exist.
 *
 * @param shortName short name of the site
 * @return Site the site, null if does not exist
 */
public Site getSite(final String shortName) {
    SiteInfo siteInfo = null;
    Site site = null;
    if (siteService.isSiteAdmin(AuthenticationUtil.getFullyAuthenticatedUser())) {
        siteInfo = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<SiteInfo>() {

            public SiteInfo doWork() throws Exception {
                return siteService.getSite(shortName);
            }
        }, AuthenticationUtil.getAdminUserName());
    } else {
        siteInfo = this.siteService.getSite(shortName);
    }
    if (siteInfo != null) {
        site = new Site(siteInfo, this.serviceRegistry, this.siteService, getScope());
    }
    return site;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo)

Example 84 with SiteInfo

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

the class SiteMembershipComparator method compare.

@Override
public int compare(SiteMembership o1, SiteMembership o2) {
    String personId1 = o1.getPersonId();
    String personId2 = o2.getPersonId();
    SiteInfo siteInfo1 = o1.getSiteInfo();
    SiteInfo siteInfo2 = o2.getSiteInfo();
    String shortName1 = siteInfo1.getShortName();
    String shortName2 = siteInfo2.getShortName();
    String firstName1 = o1.getFirstName();
    String firstName2 = o2.getFirstName();
    String lastName1 = o1.getLastName();
    String lastName2 = o2.getLastName();
    String siteRole1 = o1.getRole();
    String siteRole2 = o2.getRole();
    String siteTitle1 = siteInfo1.getTitle();
    String siteTitle2 = siteInfo2.getTitle();
    int personId = safeCompare(personId1, personId2);
    int firstName = safeCompare(firstName1, firstName2);
    int siteShortName = safeCompare(shortName1, shortName2);
    int lastName = safeCompare(lastName1, lastName2);
    int siteRole = safeCompare(siteRole1, siteRole2);
    int siteTitle = safeCompare(siteTitle1, siteTitle2);
    if (siteRole == 0 && siteShortName == 0 && personId == 0) {
        // equals contract
        return 0;
    }
    int ret = 0;
    switch(comparatorType) {
        case SITES:
            {
                ret = compareSitesBody(shortName1, shortName2, siteRole1, siteRole2, siteTitle1, siteTitle2, siteShortName, siteRole, siteTitle, ret);
                break;
            }
        case MEMBERS:
            {
                ret = compareSiteMembersBody(sortPairs, personId1, personId2, lastName1, lastName2, siteRole1, siteRole2, personId, firstName, lastName, siteRole, ret);
                break;
            }
    }
    return ret;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo)

Example 85 with SiteInfo

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

the class SiteServiceImpl method listSites.

public List<SiteInfo> listSites(Set<String> siteNames) {
    List<ChildAssociationRef> assocs = this.nodeService.getChildrenByName(getSiteRoot(), ContentModel.ASSOC_CONTAINS, siteNames);
    List<SiteInfo> result = new ArrayList<SiteInfo>(assocs.size());
    for (ChildAssociationRef assoc : assocs) {
        // Ignore any node that is not a "site" type
        NodeRef site = assoc.getChildRef();
        QName siteClassName = this.nodeService.getType(site);
        if (dictionaryService.isSubClass(siteClassName, SiteModel.TYPE_SITE)) {
            result.add(createSiteInfo(site));
        }
    }
    return result;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Aggregations

SiteInfo (org.alfresco.service.cmr.site.SiteInfo)190 NodeRef (org.alfresco.service.cmr.repository.NodeRef)83 Test (org.junit.Test)48 FilterPropString (org.alfresco.repo.node.getchildren.FilterPropString)45 ArrayList (java.util.ArrayList)32 QName (org.alfresco.service.namespace.QName)29 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)27 BaseAlfrescoSpringTest (org.alfresco.util.BaseAlfrescoSpringTest)26 HashMap (java.util.HashMap)22 Serializable (java.io.Serializable)20 RelationshipResourceNotFoundException (org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException)18 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)17 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)17 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)15 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)15 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)14 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)14 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)12 Date (java.util.Date)9 PagingRequest (org.alfresco.query.PagingRequest)9