Search in sources :

Example 86 with SiteInfo

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

the class SiteServiceImpl method getSiteImpl.

/**
 * Get the site implementation given a short name
 *
 * @param shortName String
 * @return SiteInfo
 */
private SiteInfo getSiteImpl(String shortName) {
    SiteInfo result = null;
    // Get the site node
    NodeRef siteNodeRef = getSiteNodeRef(shortName);
    if (siteNodeRef != null) {
        // Create the site info
        result = createSiteInfo(siteNodeRef);
    }
    // Return the site information
    return result;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef)

Example 87 with SiteInfo

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

the class AbstractEventsService method getNodeInfo.

protected NodeInfo getNodeInfo(final NodeRef nodeRef, final String eventType) {
    NodeInfo nodeInfo = AuthenticationUtil.runAsSystem(new RunAsWork<NodeInfo>() {

        public NodeInfo doWork() throws Exception {
            NodeInfo nodeInfo = null;
            String txnId = AlfrescoTransactionSupport.getTransactionId();
            if (!includeEventType(eventType)) {
                nodeInfo = new NodeInfo(eventType, null, null, nodeRef, null, null, null, null, null, null, null, null, false, null, null);
            } else if (nodeRef == null || !nodeService.exists(nodeRef)) {
                nodeInfo = new NodeInfo(eventType, txnId, null, nodeRef, null, null, null, null, null, null, null, false, true, false, null);
            } else {
                FileFilterMode.Client filterclient = FileFilterMode.getClient();
                Visibility visibility = hiddenAspect.getVisibility(filterclient, nodeRef);
                QName type = nodeService.getType(nodeRef);
                if (!typeMatches(type)) {
                    nodeInfo = new NodeInfo(eventType, txnId, null, nodeRef, null, null, null, null, null, null, null, true, true, false, false);
                } else if (!visibility.equals(Visibility.Visible)) {
                    nodeInfo = new NodeInfo(eventType, txnId, null, nodeRef, null, null, null, null, null, null, null, true, true, true, true);
                } else {
                    SiteInfo siteInfo = siteService.getSite(nodeRef);
                    String siteId = (siteInfo != null ? siteInfo.getShortName() : null);
                    Set<QName> aspects = nodeService.getAspects(nodeRef);
                    final String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
                    List<Path> nodePaths = Collections.singletonList(nodeService.getPath(nodeRef));
                    Date modifiedTime = (Date) nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIED);
                    Long modificationTimestamp = (modifiedTime != null ? modifiedTime.getTime() : null);
                    Status status = nodeService.getNodeStatus(nodeRef);
                    Client client = ClientUtil.from(filterclient);
                    nodeInfo = new NodeInfo(eventType, txnId, name, nodeRef, status, nodePaths, modificationTimestamp, type, aspects, siteId, client, true, true, true, true);
                }
            }
            return nodeInfo;
        }
    });
    return nodeInfo;
}
Also used : Status(org.alfresco.service.cmr.repository.NodeRef.Status) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) Set(java.util.Set) HashSet(java.util.HashSet) QName(org.alfresco.service.namespace.QName) MessagingException(org.gytheio.messaging.MessagingException) Date(java.util.Date) Visibility(org.alfresco.repo.model.filefolder.HiddenAspect.Visibility) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) FileFilterMode(org.alfresco.util.FileFilterMode) Client(org.alfresco.sync.repo.Client)

Example 88 with SiteInfo

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

the class TemporarySites method createSite.

/**
 * This method creates a Share Site (<b>or subtype</b>) and adds it to the internal list of NodeRefs to be tidied up by the rule.
 * This method will be run in its own transaction and will be run with the specified user as the fully authenticated user,
 * thus ensuring the named user is the creator of the new site.
 *
 * @param sitePreset      the site preset
 * @param siteShortName   the short name of the new site
 * @param siteTitle       the title of the new site
 * @param siteDescription the description of the new site
 * @param visibility      the visibility
 * @param siteType        the site type (must be st:site or subtype)
 * @param siteCreator     the username of the person who will create the site
 * @return the newly created SiteInfo.
 */
public SiteInfo createSite(final String sitePreset, final String siteShortName, final String siteTitle, final String siteDescription, final SiteVisibility visibility, final QName siteType, final String siteCreator) {
    final RetryingTransactionHelper transactionHelper = appContextRule.getApplicationContext().getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
    AuthenticationUtil.pushAuthentication();
    AuthenticationUtil.setFullyAuthenticatedUser(siteCreator);
    SiteInfo newSite = transactionHelper.doInTransaction(new RetryingTransactionCallback<SiteInfo>() {

        public SiteInfo execute() throws Throwable {
            final SiteService siteService = appContextRule.getApplicationContext().getBean("siteService", SiteService.class);
            SiteInfo newSite = siteService.createSite(sitePreset, siteShortName, siteTitle, siteDescription, visibility, siteType);
            // ensure that the Document Library folder is pre-created so that test code can start creating content straight away.
            // At the time of writing HEAD does not create this folder automatically, but Thor does.
            // So to be safe, I'll pre-check if the node is there.
            NodeRef docLibFolder = siteService.getContainer(siteShortName, SiteService.DOCUMENT_LIBRARY);
            if (docLibFolder == null) {
                docLibFolder = siteService.createContainer(siteShortName, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null);
            }
            return newSite;
        }
    });
    AuthenticationUtil.popAuthentication();
    this.temporarySites.add(newSite);
    return newSite;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteService(org.alfresco.service.cmr.site.SiteService) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper)

Example 89 with SiteInfo

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

the class TemporaryNodes method after.

@Override
protected void after() {
    final ApplicationContext springContext = appContextRule.getApplicationContext();
    final RetryingTransactionHelper transactionHelper = springContext.getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
    final CheckOutCheckInService cociService = springContext.getBean("CheckOutCheckInService", CheckOutCheckInService.class);
    final DictionaryService dictionaryService = springContext.getBean("DictionaryService", DictionaryService.class);
    final NodeService nodeService = springContext.getBean("NodeService", NodeService.class);
    final SiteService siteService = springContext.getBean("SiteService", SiteService.class);
    final VersionService versionService = springContext.getBean("VersionService", VersionService.class);
    // Run as system to ensure all non-system nodes can be deleted irrespective of which user created them.
    AuthenticationUtil.runAs(new RunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>() {

                @Override
                public Void execute() throws Throwable {
                    // Although we loop through all nodes, this is a cascade-delete and so we may only need to delete the first node.
                    for (NodeRef node : temporaryNodeRefs) {
                        // If it's already been deleted, don't worry about it.
                        if (nodeService.exists(node)) {
                            // If it has been checked out, cancel the checkout before deletion.
                            if (cociService.isCheckedOut(node)) {
                                log.debug("Cancelling checkout of temporary node " + nodeService.getProperty(node, ContentModel.PROP_NAME));
                                NodeRef workingCopy = cociService.getWorkingCopy(node);
                                cociService.cancelCheckout(workingCopy);
                            }
                            // If it's been versioned, then we need to clean out the version history too.
                            if (versionService.isVersioned(node)) {
                                log.debug("Deleting version history of temporary node " + nodeService.getProperty(node, ContentModel.PROP_NAME));
                                versionService.deleteVersionHistory(node);
                            }
                            log.debug("Deleting temporary node " + nodeService.getProperty(node, ContentModel.PROP_NAME));
                            // Site nodes are a special case which must be deleted through the SiteService.
                            final QName nodeType = nodeService.getType(node);
                            if (nodeType.equals(SiteModel.TYPE_SITE) || dictionaryService.isSubClass(nodeType, SiteModel.TYPE_SITE)) {
                                SiteInfo siteInfo = siteService.getSite(node);
                                siteService.deleteSite(siteInfo.getShortName());
                            } else {
                                nodeService.deleteNode(node);
                            }
                        }
                    }
                    return null;
                }
            });
            return null;
        }
    }, AuthenticationUtil.getSystemUserName());
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) QName(org.alfresco.service.namespace.QName) NodeService(org.alfresco.service.cmr.repository.NodeService) VersionService(org.alfresco.service.cmr.version.VersionService) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ApplicationContext(org.springframework.context.ApplicationContext) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) CheckOutCheckInService(org.alfresco.service.cmr.coci.CheckOutCheckInService) SiteService(org.alfresco.service.cmr.site.SiteService) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)

Example 90 with SiteInfo

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

the class ActivityPosterImpl method postFileFolderAdded.

/**
 * {@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);
        }
    }
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException)

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