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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations