Java Code Examples for org.alfresco.repo.tenant.TenantUtil#getCurrentDomain()

The following examples show how to use org.alfresco.repo.tenant.TenantUtil#getCurrentDomain() . 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: TenantRoutingContentStore.java    From alfresco-simple-content-stores with Apache License 2.0 6 votes vote down vote up
/**
 *
 * {@inheritDoc}
 */
@Override
protected List<ContentStore> getAllStores()
{
    final List<ContentStore> stores = new ArrayList<>();
    if (!TenantUtil.isCurrentDomainDefault())
    {
        final String currentDomain = TenantUtil.getCurrentDomain();
        final ContentStore tenantStore = this.storeByTenant.get(currentDomain);
        if (tenantStore != null)
        {
            stores.add(tenantStore);
        }
    }
    stores.add(this.fallbackStore);

    return stores;
}
 
Example 2
Source File: ExceptionEventsServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void exceptionGenerated(String txnId, Throwable t)
{
    if(enabled)
    {
        try
        {
            long timestamp = System.currentTimeMillis();
            String networkId = TenantUtil.getCurrentDomain();
            String username = AuthenticationUtil.getFullyAuthenticatedUser();
            ExceptionGeneratedEvent event = new ExceptionGeneratedEvent(nextSequenceNumber(), txnId, timestamp,
                    networkId, t, username);
            messageProducer.send(event);
        }
        catch(MessagingException e)
        {
            logger.error(e);
        }
    }
}
 
Example 3
Source File: EventsServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void authorityAddedToGroup(String parentGroup, String childAuthority)
{
    if (includeEventType(AuthorityAddedToGroupEvent.EVENT_TYPE))
    {
        String username = AuthenticationUtil.getFullyAuthenticatedUser();
        String networkId = TenantUtil.getCurrentDomain();
        String txnId = AlfrescoTransactionSupport.getTransactionId();
        long timestamp = System.currentTimeMillis();
        Client client = getAlfrescoClient(ClientUtil.from(FileFilterMode.getClient()));
        
        Event event = AuthorityAddedToGroupEvent.builder().parentGroup(parentGroup).authorityName(childAuthority).seqNumber(nextSequenceNumber())
                .txnId(txnId).networkId(networkId).timestamp(timestamp).username(username).client(client).build();
                
        sendEvent(event);
    }
}
 
Example 4
Source File: EventsServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void contentGet(NodeRef nodeRef)
{
    NodeInfo nodeInfo = getNodeInfo(nodeRef, NodeContentGetEvent.EVENT_TYPE);
    if(nodeInfo.checkNodeInfo())
    {
        String username = AuthenticationUtil.getFullyAuthenticatedUser();
        String networkId = TenantUtil.getCurrentDomain();

        String name = nodeInfo.getName();
        String objectId = nodeInfo.getNodeId();
        String siteId = nodeInfo.getSiteId();
        String txnId = AlfrescoTransactionSupport.getTransactionId();
        List<String> nodePaths = nodeInfo.getPaths();
        List<List<String>> pathNodeIds = nodeInfo.getParentNodeIds();
        long timestamp = System.currentTimeMillis();
        Long modificationTime = nodeInfo.getModificationTimestamp();
        String nodeType = nodeInfo.getType().toPrefixString(namespaceService);
        Client alfrescoClient = getAlfrescoClient(nodeInfo.getClient());

        Set<String> aspects = nodeInfo.getAspectsAsStrings();
        Map<String, Serializable> properties = nodeInfo.getProperties();

        Event event = new NodeContentGetEvent(nextSequenceNumber(), name, txnId, timestamp, networkId, siteId,
                objectId, nodeType, nodePaths, pathNodeIds, username, modificationTime, alfrescoClient,
                aspects, properties);
        sendEvent(event);
    }
}
 
Example 5
Source File: EventsServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void inheritPermissionsEnabled(NodeRef nodeRef)
{
    NodeInfo nodeInfo = getNodeInfo(nodeRef, InheritPermissionsEnabledEvent.EVENT_TYPE);
    if (nodeInfo.checkNodeInfo())
    {
        String username = AuthenticationUtil.getFullyAuthenticatedUser();
        String networkId = TenantUtil.getCurrentDomain();
        String name = nodeInfo.getName();
        String nodeId = nodeInfo.getNodeId();
        String siteId = nodeInfo.getSiteId();
        String txnId = AlfrescoTransactionSupport.getTransactionId();
        List<String> nodePaths = nodeInfo.getPaths();
        List<List<String>> pathNodeIds = nodeInfo.getParentNodeIds();
        long timestamp = System.currentTimeMillis();
        Long modificationTime = nodeInfo.getModificationTimestamp();
        String nodeType = nodeInfo.getType().toPrefixString(namespaceService);
        Client alfrescoClient = getAlfrescoClient(nodeInfo.getClient());

        Set<String> aspects = nodeInfo.getAspectsAsStrings();
        Map<String, Serializable> properties = nodeInfo.getProperties();

        Event event = InheritPermissionsEnabledEvent.builder().seqNumber(nextSequenceNumber()).name(name).txnId(txnId).timestamp(timestamp)
                .networkId(networkId).siteId(siteId).nodeId(nodeId).nodeType(nodeType).paths(nodePaths).parentNodeIds(pathNodeIds)
                .username(username).nodeModificationTime(modificationTime).client(alfrescoClient).aspects(aspects).nodeProperties(properties)
                .build();         
               
        sendEvent(event);
    }
}
 
Example 6
Source File: EventsServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void nodeUpdated(final NodeRef nodeRef, final Map<String, Property> propertiesAdded,
        final Set<String> propertiesRemoved, final Map<String, Property> propertiesChanged,
        final Set<String> aspectsAdded, final Set<String> aspectsRemoved)
{
    NodeInfo nodeInfo = getNodeInfo(nodeRef, NodeUpdatedEvent.EVENT_TYPE);
    if(nodeInfo.checkNodeInfo())
    {
        String username = AuthenticationUtil.getFullyAuthenticatedUser();
        String networkId = TenantUtil.getCurrentDomain();

        String name = nodeInfo.getName();
        String objectId = nodeInfo.getNodeId();
        String siteId = nodeInfo.getSiteId();
        String txnId = AlfrescoTransactionSupport.getTransactionId();
        List<String> nodePaths = nodeInfo.getPaths();
        List<List<String>> pathNodeIds = nodeInfo.getParentNodeIds();
        long timestamp = System.currentTimeMillis();
        Long modificationTime = nodeInfo.getModificationTimestamp();
        String nodeType = nodeInfo.getType().toPrefixString(namespaceService);
        Client alfrescoClient = getAlfrescoClient(nodeInfo.getClient());

        Set<String> aspects = nodeInfo.getAspectsAsStrings();
        Map<String, Serializable> properties = nodeInfo.getProperties();

        Event event = new NodeUpdatedEvent(nextSequenceNumber(), name, txnId, timestamp, networkId, siteId, objectId, nodeType, nodePaths,
                pathNodeIds, username, modificationTime, propertiesAdded, propertiesRemoved, propertiesChanged,
                aspectsAdded, aspectsRemoved, alfrescoClient, aspects, properties);
        sendEvent(event);
    }
}
 
Example 7
Source File: EventsServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void inheritPermissionsDisabled(NodeRef nodeRef, boolean async)
{
    NodeInfo nodeInfo = getNodeInfo(nodeRef, InheritPermissionsDisabledEvent.EVENT_TYPE);
    if (nodeInfo.checkNodeInfo())
    {
        String username = AuthenticationUtil.getFullyAuthenticatedUser();
        String networkId = TenantUtil.getCurrentDomain();
        String name = nodeInfo.getName();
        String nodeId = nodeInfo.getNodeId();
        String siteId = nodeInfo.getSiteId();
        String txnId = AlfrescoTransactionSupport.getTransactionId();
        List<String> nodePaths = nodeInfo.getPaths();
        List<List<String>> pathNodeIds = nodeInfo.getParentNodeIds();
        long timestamp = System.currentTimeMillis();
        Long modificationTime = nodeInfo.getModificationTimestamp();
        String nodeType = nodeInfo.getType().toPrefixString(namespaceService);
        Client alfrescoClient = getAlfrescoClient(nodeInfo.getClient());

        Set<String> aspects = nodeInfo.getAspectsAsStrings();
        Map<String, Serializable> properties = nodeInfo.getProperties();

        Event event = InheritPermissionsDisabledEvent.builder().async(async).seqNumber(nextSequenceNumber()).name(name).txnId(txnId)
                .timestamp(timestamp).networkId(networkId).siteId(siteId).nodeId(nodeId).nodeType(nodeType).paths(nodePaths)
                .parentNodeIds(pathNodeIds).username(username).nodeModificationTime(modificationTime).client(alfrescoClient).aspects(aspects)
                .nodeProperties(properties).build();      
        sendEvent(event);
    }
}
 
Example 8
Source File: NodesImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Check for special case: additional node validation (pending common lower-level service support)
 * for blacklist of system nodes that should not be deleted or locked, eg. Company Home, Sites, Data Dictionary
 *
 * @param nodeRef
 * @param type
 * @return
 */
protected boolean isSpecialNode(NodeRef nodeRef, QName type)
{
    // Check for Company Home, Sites and Data Dictionary (note: must be tenant-aware)

    if (nodeRef.equals(repositoryHelper.getCompanyHome()))
    {
        return true;
    }
    else if (type.equals(SiteModel.TYPE_SITES) || type.equals(SiteModel.TYPE_SITE))
    {
        // note: alternatively, we could inject SiteServiceInternal and use getSitesRoot (or indirectly via node locator)
        return true;
    }
    else
    {
        String tenantDomain = TenantUtil.getCurrentDomain();
        NodeRef ddNodeRef = ddCache.get(tenantDomain);
        if (ddNodeRef == null)
        {
            List<ChildAssociationRef> ddAssocs = nodeService.getChildAssocs(
                    repositoryHelper.getCompanyHome(),
                    ContentModel.ASSOC_CONTAINS,
                    QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "dictionary"));
            if (ddAssocs.size() == 1)
            {
                ddNodeRef = ddAssocs.get(0).getChildRef();
                ddCache.put(tenantDomain, ddNodeRef);
            }
        }

        if (nodeRef.equals(ddNodeRef))
        {
            return true;
        }
    }

    return false;
}
 
Example 9
Source File: EventsServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void nodeCreated(final NodeRef nodeRef)
{
    NodeInfo nodeInfo = getNodeInfo(nodeRef, NodeAddedEvent.EVENT_TYPE);
    if(nodeInfo.checkNodeInfo())
    {
        String username = AuthenticationUtil.getFullyAuthenticatedUser();
        String networkId = TenantUtil.getCurrentDomain();

        String name = nodeInfo.getName();
        String objectId = nodeInfo.getNodeId();
        String siteId = nodeInfo.getSiteId();
        String txnId = AlfrescoTransactionSupport.getTransactionId();
        List<String> nodePaths = nodeInfo.getPaths();
        List<List<String>> pathNodeIds = nodeInfo.getParentNodeIds();
        long timestamp = System.currentTimeMillis();
        Long modificationTime = nodeInfo.getModificationTimestamp();
        String nodeType = nodeInfo.getType().toPrefixString(namespaceService);
        Client alfrescoClient = getAlfrescoClient(nodeInfo.getClient());

        Set<String> aspects = nodeInfo.getAspectsAsStrings();
        Map<String, Serializable> properties = nodeInfo.getProperties();

        Event event = new NodeAddedEvent(nextSequenceNumber(), name, txnId, timestamp, networkId, siteId, objectId, nodeType, nodePaths, pathNodeIds,
                username, modificationTime, alfrescoClient, aspects, properties);
        sendEvent(event);
    }
}
 
Example 10
Source File: TenantRoutingContentStore.java    From alfresco-simple-content-stores with Apache License 2.0 5 votes vote down vote up
/**
 *
 * {@inheritDoc}
 */
@Override
protected ContentStore getStore(final String contentUrl, final boolean mustExist)
{
    ContentStore readStore = null;

    if (!TenantUtil.isCurrentDomainDefault())
    {
        final String currentDomain = TenantUtil.getCurrentDomain();
        if (this.storeByTenant.containsKey(currentDomain))
        {
            readStore = this.storeByTenant.get(currentDomain);

            if (!readStore.isContentUrlSupported(contentUrl) || (mustExist && !readStore.exists(contentUrl)))
            {
                readStore = null;
            }
        }
    }

    if (readStore == null)
    {
        readStore = super.getStore(contentUrl, mustExist);
    }

    return readStore;
}
 
Example 11
Source File: EventsServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void nodeLiked(final NodeRef nodeRef)
{
    NodeInfo nodeInfo = getNodeInfo(nodeRef, NodeLikedEvent.EVENT_TYPE);
    if(nodeInfo.checkNodeInfo())
    {
        String username = AuthenticationUtil.getFullyAuthenticatedUser();
        String networkId = TenantUtil.getCurrentDomain();

        String name = nodeInfo.getName();
        String objectId = nodeInfo.getNodeId();
        String siteId = nodeInfo.getSiteId();
        String txnId = AlfrescoTransactionSupport.getTransactionId();
        List<String> nodePaths = nodeInfo.getPaths();
        List<List<String>> pathNodeIds = nodeInfo.getParentNodeIds();
        long timestamp = System.currentTimeMillis();
        Long modificationTime = nodeInfo.getModificationTimestamp();
        String nodeType = nodeInfo.getType().toPrefixString(namespaceService);

        Set<String> aspects = nodeInfo.getAspectsAsStrings();
        Map<String, Serializable> properties = nodeInfo.getProperties();

        Client alfrescoClient = getAlfrescoClient(nodeInfo.getClient());

        Event event = new NodeLikedEvent(nextSequenceNumber(), name, txnId, timestamp, networkId, siteId, objectId, nodeType, nodePaths,
                pathNodeIds, username, modificationTime, alfrescoClient, aspects, properties);
        sendEvent(event);
    }
}
 
Example 12
Source File: EventsServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void revokeLocalPermissions(NodeRef nodeRef, String authority, String permission)
{
    NodeInfo nodeInfo = getNodeInfo(nodeRef, LocalPermissionRevokedEvent.EVENT_TYPE);
    if (nodeInfo.checkNodeInfo())
    {
        String username = AuthenticationUtil.getFullyAuthenticatedUser();
        String networkId = TenantUtil.getCurrentDomain();
        String name = nodeInfo.getName();
        String nodeId = nodeInfo.getNodeId();
        String siteId = nodeInfo.getSiteId();
        String txnId = AlfrescoTransactionSupport.getTransactionId();
        List<String> nodePaths = nodeInfo.getPaths();
        List<List<String>> pathNodeIds = nodeInfo.getParentNodeIds();
        long timestamp = System.currentTimeMillis();
        Long modificationTime = nodeInfo.getModificationTimestamp();
        String nodeType = nodeInfo.getType().toPrefixString(namespaceService);
        Client alfrescoClient = getAlfrescoClient(nodeInfo.getClient());

        Set<String> aspects = nodeInfo.getAspectsAsStrings();
        Map<String, Serializable> properties = nodeInfo.getProperties();

        Event event = LocalPermissionRevokedEvent.builder().authority(authority).permission(permission).seqNumber(nextSequenceNumber()).name(name)
                .txnId(txnId).timestamp(timestamp).networkId(networkId).siteId(siteId).nodeId(nodeId).nodeType(nodeType).paths(nodePaths).parentNodeIds(pathNodeIds)
                .username(username).nodeModificationTime(modificationTime).client(alfrescoClient).aspects(aspects).nodeProperties(properties).build();                  
        sendEvent(event);
    }
    
}
 
Example 13
Source File: EventsServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void nodeTagged(final NodeRef nodeRef, final String tag)
{
    NodeInfo nodeInfo = getNodeInfo(nodeRef, NodeTaggedEvent.EVENT_TYPE);
    if(nodeInfo.checkNodeInfo())
    {
        String username = AuthenticationUtil.getFullyAuthenticatedUser();
        String networkId = TenantUtil.getCurrentDomain();

        String name = nodeInfo.getName();
        String objectId = nodeInfo.getNodeId();
        String siteId = nodeInfo.getSiteId();
        String txnId = AlfrescoTransactionSupport.getTransactionId();
        List<String> nodePaths = nodeInfo.getPaths();
        List<List<String>> pathNodeIds = nodeInfo.getParentNodeIds();
        long timestamp = System.currentTimeMillis();
        Long modificationTime = nodeInfo.getModificationTimestamp();
        String nodeType = nodeInfo.getType().toPrefixString(namespaceService);

        Set<String> aspects = nodeInfo.getAspectsAsStrings();
        Map<String, Serializable> properties = nodeInfo.getProperties();

        Client alfrescoClient = getAlfrescoClient(nodeInfo.getClient());

        Event event = new NodeTaggedEvent(nextSequenceNumber(), name, txnId, timestamp, networkId, siteId, objectId, nodeType, nodePaths,
                pathNodeIds, username, modificationTime, tag, alfrescoClient, aspects, properties);
        sendEvent(event);
    }
}
 
Example 14
Source File: EventsServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private NodeRenamedEvent nodeRenamedEvent(NodeInfo nodeInfo, String oldName, String newName)
{
    String username = AuthenticationUtil.getFullyAuthenticatedUser();
    String networkId = TenantUtil.getCurrentDomain();

    String objectId = nodeInfo.getNodeId();
    String siteId = nodeInfo.getSiteId();
    String txnId = AlfrescoTransactionSupport.getTransactionId();
    long timestamp = System.currentTimeMillis();
    Long modificationTime = nodeInfo.getModificationTimestamp();
    QName nodeTypeQName = nodeInfo.getType();
    String nodeType = nodeTypeQName.toPrefixString(namespaceService);
    List<List<String>> parentNodeIds = nodeInfo.getParentNodeIds();

    List<String> newPaths = nodeInfo.getPaths();
    List<String> paths = null;

    // For site display name (title) rename events we don't want the path to be changed to the display name (title); leave it to name (id)
    if (nodeTypeQName.equals(SiteModel.TYPE_SITE))
    {
        paths = newPaths;
    }
    else
    {
        nodeInfo.updateName(oldName);
        paths = nodeInfo.getPaths();
    }

    Set<String> aspects = nodeInfo.getAspectsAsStrings();
    Map<String, Serializable> properties = nodeInfo.getProperties();

    Client alfrescoClient = getAlfrescoClient(nodeInfo.getClient());

    NodeRenamedEvent event = new NodeRenamedEvent(nextSequenceNumber(), oldName, newName, txnId, timestamp, networkId, siteId, objectId, nodeType,
            paths, parentNodeIds, username, modificationTime, newPaths, alfrescoClient,aspects, properties);
    return event;
}
 
Example 15
Source File: EventPublisherForTestingOnly.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Gets userful information from the current thread for use when creating an event
 * @return ThreadInfo
 */
protected ThreadInfo getThreadInfo()
{
    return new ThreadInfo(
                AuthenticationUtil.getFullyAuthenticatedUser(),
                AlfrescoTransactionSupport.getTransactionId(),
                TenantUtil.getCurrentDomain());
}
 
Example 16
Source File: TransactionalCache.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Convert the key to a tenant-specific key if the cache is tenant-aware and
 * the current thread is running in the context of a tenant.
 * 
 * @param key           the key to convert
 * @return              a key that separates tenant-specific values
 */
private Serializable getTenantAwareCacheKey(final K key)
{
    if (isTenantAware)
    {
        final String tenantDomain = TenantUtil.getCurrentDomain();
        if (! tenantDomain.equals(TenantService.DEFAULT_DOMAIN))
        {
            return new CacheRegionKey(tenantDomain, key);
        }
        // drop through
    }
    return key;
}
 
Example 17
Source File: EventsServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void nodeMoved(ChildAssociationRef oldChildAssocRef, ChildAssociationRef newChildAssocRef)
{
    NodeRef nodeRef = newChildAssocRef.getChildRef();
    NodeInfo nodeInfo = getNodeInfo(nodeRef, NodeMovedEvent.EVENT_TYPE);
    if(nodeInfo.checkNodeInfo())
    {
        String username = AuthenticationUtil.getFullyAuthenticatedUser();
        String networkId = TenantUtil.getCurrentDomain();

        String objectId = nodeInfo.getNodeId();
        String siteId = nodeInfo.getSiteId();
        String txnId = AlfrescoTransactionSupport.getTransactionId();
        long timestamp = System.currentTimeMillis();
        Long modificationTime = nodeInfo.getModificationTimestamp();
        String nodeType = nodeInfo.getType().toPrefixString(namespaceService);

        NodeRef oldParentNodeRef = oldChildAssocRef.getParentRef();
        NodeRef newParentNodeRef = newChildAssocRef.getParentRef();
        NodeRef oldNodeRef = oldChildAssocRef.getChildRef();
        NodeRef newNodeRef = newChildAssocRef.getChildRef();

        String oldParentNodeName = (String)nodeService.getProperty(oldParentNodeRef, ContentModel.PROP_NAME);
        String newParentNodeName = (String)nodeService.getProperty(newParentNodeRef, ContentModel.PROP_NAME);
        String oldNodeName = (String)nodeService.getProperty(oldNodeRef, ContentModel.PROP_NAME);
        String newNodeName = (String)nodeService.getProperty(newNodeRef, ContentModel.PROP_NAME);
        List<Path> newParentPaths = nodeService.getPaths(newParentNodeRef, false);
        List<String> newPaths = getPaths(newParentPaths, Arrays.asList(newParentNodeName, newNodeName));

        // renames are handled by an onUpdateProperties callback, we just deal with real moves here.
        if(!oldParentNodeRef.equals(newParentNodeRef))
        {
            List<List<String>> toParentNodeIds = getNodeIds(newParentPaths);
            List<Path> oldParentPaths = nodeService.getPaths(oldParentNodeRef, false);
            List<String> previousPaths = getPaths(oldParentPaths, Arrays.asList(oldParentNodeName, oldNodeName));
            List<List<String>> previousParentNodeIds = getNodeIds(oldParentPaths);

            Set<String> aspects = nodeInfo.getAspectsAsStrings();
            Map<String, Serializable> properties = nodeInfo.getProperties();
           
            Client alfrescoClient = getAlfrescoClient(nodeInfo.getClient());

            Event event = new NodeMovedEvent(nextSequenceNumber(), oldNodeName, newNodeName, txnId, timestamp, networkId, siteId, objectId, nodeType, 
                    previousPaths, previousParentNodeIds, username, modificationTime, newPaths, toParentNodeIds, alfrescoClient,
                    aspects, properties);
            sendEvent(event);
        }
    }
}
 
Example 18
Source File: CMISAbstractDictionaryService.java    From alfresco-data-model with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected CMISDictionaryRegistry getRegistry()
{
    String tenant = TenantUtil.getCurrentDomain();
    return getRegistry(tenant);
}
 
Example 19
Source File: EventsServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void contentWrite(NodeRef nodeRef, QName propertyQName, ContentData value)
{
    NodeInfo nodeInfo = getNodeInfo(nodeRef, NodeContentPutEvent.EVENT_TYPE);
    if(nodeInfo.checkNodeInfo())
    {
        String username = AuthenticationUtil.getFullyAuthenticatedUser();
        String networkId = TenantUtil.getCurrentDomain();

        String name = nodeInfo.getName();
        String objectId = nodeInfo.getNodeId();
        String siteId = nodeInfo.getSiteId();
        String txnId = AlfrescoTransactionSupport.getTransactionId();
        List<String> nodePaths = nodeInfo.getPaths();
        List<List<String>> pathNodeIds = nodeInfo.getParentNodeIds();
        long timestamp = System.currentTimeMillis();
        Long modificationTime = nodeInfo.getModificationTimestamp();
        long size;
        String mimeType;
        String encoding;
        if (value != null)
        {
            size = value.getSize();
            mimeType = value.getMimetype();
            encoding = value.getEncoding();
        }
        else
        {
            size = 0;
            mimeType = "";
            encoding = "";
        }

        String nodeType = nodeInfo.getType().toPrefixString(namespaceService);
        Client alfrescoClient = getAlfrescoClient(nodeInfo.getClient());

        Set<String> aspects = nodeInfo.getAspectsAsStrings();
        Map<String, Serializable> properties = nodeInfo.getProperties();

        Event event = new NodeContentPutEvent(nextSequenceNumber(), name, txnId, timestamp, networkId, siteId, objectId,
                nodeType, nodePaths, pathNodeIds, username, modificationTime, size, mimeType, encoding, alfrescoClient, aspects, properties);
        sendEvent(event);
    }
}
 
Example 20
Source File: TransactionalCache.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Transaction-long setting to force all the share cache to be bypassed for the current transaction.
 * <p/>
 * This setting is like having a {@link NullCache null} {@link #setSharedCache(SimpleCache) shared cache},
 * but only lasts for the transaction.
 * <p/>
 * Use this when a read transaction <b>must</b> see consistent and current data i.e. go to the database.
 * While this is active, write operations will also not be committed to the shared cache.
 * 
 * @param noSharedCacheRead         <tt>true</tt> to avoid reading from the shared cache for the transaction
 */
@SuppressWarnings("unchecked")
public void setDisableSharedCacheReadForTransaction(boolean noSharedCacheRead)
{
    TransactionData txnData = getTransactionData();

    // If we are switching on noSharedCacheRead mode, convert all existing reads and updates to avoid 'consistent
    // read' behaviour giving us a potentially out of date node already accessed
    if (noSharedCacheRead && !txnData.noSharedCacheRead)
    {
        txnData.noSharedCacheRead = noSharedCacheRead;
        String currentCacheRegion = TenantUtil.getCurrentDomain();
        for (Map.Entry<Serializable, CacheBucket<V>> entry : new ArrayList<Map.Entry<Serializable, CacheBucket<V>>>(
                txnData.updatedItemsCache.entrySet()))
        {
            Serializable cacheKey = entry.getKey();
            K key = null;
            if (cacheKey instanceof CacheRegionKey)
            {
                CacheRegionKey cacheRegionKey = (CacheRegionKey) cacheKey;
                if (currentCacheRegion.equals(cacheRegionKey.getCacheRegion()))
                {
                    key = (K) cacheRegionKey.getCacheKey();
                }
            }
            else
            {
                key = (K) cacheKey;
            }

            if (key != null)
            {
                CacheBucket<V> bucket = entry.getValue();
                // Simply 'forget' reads
                if (bucket instanceof ReadCacheBucket)
                {
                    txnData.updatedItemsCache.remove(cacheKey);
                }
                // Convert updates to removes
                else if (bucket instanceof UpdateCacheBucket)
                {
                    remove(key);
                }
                // Leave new entries alone - they can't have come from the shared cache
            }
        }
    }
}