org.alfresco.repo.tenant.TenantUtil Java Examples

The following examples show how to use org.alfresco.repo.tenant.TenantUtil. 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: QuickShareServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void removeSharedId(final String sharedId)
{
    TenantUtil.runAsDefaultTenant(new TenantRunAsWork<Void>()
    {
        public Void doWork() throws Exception
        {
            attributeService.removeAttribute(ATTR_KEY_SHAREDIDS_ROOT, sharedId);
            return null;
        }
    });

    try
    {
        // Remove scheduled expiry action if any
        NodeRef expiryActionNodeRef = getQuickShareLinkExpiryActionNode(sharedId);
        if (expiryActionNodeRef != null)
        {
            deleteQuickShareLinkExpiryAction(expiryActionNodeRef);
        }
    }
    catch (Exception ex)
    {
        throw new QuickShareLinkExpiryActionException("Couldn't delete the quick share link expiry action for the sharedId:" + sharedId);
    }
}
 
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: RepoService.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
public List<PersonNetwork> getNetworkMemberships()
{
	String personId = getId();
	String runAsNetworkId = Person.getNetworkId(personId);
	return TenantUtil.runAsUserTenant(new TenantRunAsWork<List<PersonNetwork>>()
	{
		@Override
		public List<PersonNetwork> doWork() throws Exception
		{
			List<PersonNetwork> members = new ArrayList<PersonNetwork>();
			PagingResults<Network> networks = networksService.getNetworks(new PagingRequest(0, Integer.MAX_VALUE));
			for(Network network : networks.getPage())
			{
	            NetworkImpl restNetwork = new NetworkImpl(network);
	            PersonNetwork personNetwork = new PersonNetwork(network.getIsHomeNetwork(), restNetwork);
				members.add(personNetwork);
			}
			return members;
		}
	}, personId, runAsNetworkId);
}
 
Example #4
Source File: ActivitiWorkflowEngine.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
* {@inheritDoc}
*/
public List<WorkflowDefinition> getDefinitions()
{
    try 
    {
        ProcessDefinitionQuery query = repoService.createProcessDefinitionQuery().latestVersion();
        if(activitiUtil.isMultiTenantWorkflowDeploymentEnabled() && !TenantUtil.isCurrentDomainDefault()) 
        {
            query.processDefinitionKeyLike("@" + TenantUtil.getCurrentDomain() + "%");
        }
        return getValidWorkflowDefinitions(query.list());
    }
    catch (ActivitiException ae)
    {
        String msg = messageService.getMessage(ERR_GET_WORKFLOW_DEF);
        if(logger.isDebugEnabled())
        {
        	logger.debug(msg, ae);
        }
        throw new WorkflowException(msg, ae);
    }
}
 
Example #5
Source File: RepoService.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
public List<TestSite> getSites(String personId)
{
	List<TestSite> sites = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<TestSite>>()
	{
		@Override
		public List<TestSite> doWork() throws Exception
		{
			List<SiteInfo> results = siteService.listSites(null, null);
			TreeMap<String, TestSite> ret = new TreeMap<String, TestSite>();
			for(SiteInfo siteInfo : results)
			{
				TestSite site = new TestSite(TestNetwork.this, siteInfo/*, null*/);
				ret.put(site.getSiteId(), site);
			}

			return new ArrayList<TestSite>(ret.values());
		}
	}, personId, getId());
	return sites;
}
 
Example #6
Source File: RepoService.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
public List<TestSite> getAllSites()
{
	List<TestSite> sites = TenantUtil.runAsSystemTenant(new TenantRunAsWork<List<TestSite>>()
	{
		@Override
		public List<TestSite> doWork() throws Exception
		{
			List<SiteInfo> results = siteService.listSites(null, null);
			TreeMap<String, TestSite> ret = new TreeMap<String, TestSite>();
			for(SiteInfo siteInfo : results)
			{
				TestSite site = new TestSite(TestNetwork.this, siteInfo/*, null*/);
				ret.put(site.getSiteId(), site);
			}

			return new ArrayList<TestSite>(ret.values());
		}
	}, getId());
	return sites;
}
 
Example #7
Source File: AbstractBaseApiTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * TODO implement as remote api call
 */
protected String createUser(final PersonInfo personInfo, final TestNetwork network)
{
    final String tenantDomain = (network != null ? network.getId() : TenantService.DEFAULT_DOMAIN);
    
    return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<String>()
    {
        @Override
        public String doWork() throws Exception
        {
            return TenantUtil.runAsTenant(new TenantUtil.TenantRunAsWork<String>()
            {
                public String doWork() throws Exception
                {
                    String username = repoService.getPublicApiContext().createUserName(personInfo.getUsername(), tenantDomain);
                    personInfo.setUsername(username);
                    RepoService.TestPerson person = repoService.createUser(personInfo, username, network);
                    return person.getId();

                }
            }, tenantDomain);
        }
    }, networkAdmin);
}
 
Example #8
Source File: TestSites.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void initializeNetwork1() throws Exception
{
    if (network1 == null)
    {
        network1 = getRepoService().createNetwork(this.getClass().getName().toLowerCase()+"-1-"+RUNID, true);
        network1.create();

        TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>()
        {
            @Override
            public Void doWork() throws Exception
            {
                person1Id = network1.createUser().getId();
                person2Id = network1.createUser().getId();
                return null;
            }
        }, network1.getId());
    }
}
 
Example #9
Source File: NodesImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Posts activities based on the activity_type.
 * If the method is called with aSync=true then a TransactionListener is used post the activity
 * afterCommit.  Otherwise the activity posting is done synchronously.
 * @param activity_type
 * @param activityInfo
 * @param aSync
 */
protected void postActivity(Activity_Type activity_type, ActivityInfo activityInfo, boolean aSync)
{
    if (activityInfo == null) return; //Nothing to do.

    String activityType = determineActivityType(activity_type, activityInfo.getFileInfo().isFolder());
    if (activityType != null)
    {
        if (aSync)
        {
            ActivitiesTransactionListener txListener = new ActivitiesTransactionListener(activityType, activityInfo,
                    TenantUtil.getCurrentDomain(), Activities.APP_TOOL, Activities.RESTAPI_CLIENT,
                    poster, retryingTransactionHelper);
            AlfrescoTransactionSupport.bindListener(txListener);
        }
        else
        {
                poster.postFileFolderActivity(activityType, null, TenantUtil.getCurrentDomain(),
                    activityInfo.getSiteId(), activityInfo.getParentNodeRef(), activityInfo.getNodeRef(),
                    activityInfo.getFileName(), Activities.APP_TOOL, Activities.RESTAPI_CLIENT,
                    activityInfo.getFileInfo());
        }
    }
}
 
Example #10
Source File: MailActionExecuter.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public NodeRef getPerson(final String user)
{
    NodeRef person = null;
    String domain = tenantService.getPrimaryDomain(user); // get primary tenant 
    if (domain != null) 
    { 
        person = TenantUtil.runAsTenant(new TenantRunAsWork<NodeRef>()
        {
            public NodeRef doWork() throws Exception
            {
                return personService.getPerson(user);
            }
        }, domain);
    }
    else
    {
        person = personService.getPerson(user);
    }
    return person;
}
 
Example #11
Source File: RepoService.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Map<String, TestSite> getSitesForUser(String username)
{
	if(username == null)
	{
		username = AuthenticationUtil.getAdminUserName();
	}
	List<SiteInfo> sites = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<SiteInfo>>()
	{
		@Override
		public List<SiteInfo> doWork() throws Exception
		{
			List<SiteInfo> results = siteService.listSites(null, null);
			return results;
		}
	}, username, getId());
	TreeMap<String, TestSite> ret = new TreeMap<String, TestSite>();
	for(SiteInfo siteInfo : sites)
	{
		TestSite site = new TestSite(TestNetwork.this, siteInfo/*, null*/);
		ret.put(site.getSiteId(), site);
	}
	return ret;
}
 
Example #12
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 #13
Source File: EventsServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void groupDeleted(String groupName, boolean cascade)
{
    if (includeEventType(GroupDeletedEvent.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 = GroupDeletedEvent.builder().authorityName(groupName).cascade(cascade).seqNumber(nextSequenceNumber()).txnId(txnId)
                .networkId(networkId).timestamp(timestamp).username(username).client(client).build();
        
        sendEvent(event);
    }        
}
 
Example #14
Source File: QuickShareServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean canRead(String sharedId)
{
    Pair<String, NodeRef> pair = getTenantNodeRefFromSharedId(sharedId);
    final String tenantDomain = pair.getFirst();
    final NodeRef nodeRef = pair.getSecond();
    
    return TenantUtil.runAsTenant(new TenantRunAsWork<Boolean>()
    {
        public Boolean doWork() throws Exception
        {
            try
            {
                checkQuickShareNode(nodeRef);
                return permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.ALLOWED;
            }
            catch (AccessDeniedException ex)
            {
                return false;
            }
        }
    }, tenantDomain);
    
}
 
Example #15
Source File: EventsServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void fileClassified(NodeRef nodeRef)
{
    NodeInfo nodeInfo = getNodeInfo(nodeRef, FileClassifiedEvent.EVENT_TYPE);
    if(nodeInfo.checkNodeInfo())
    {
        Event event = FileClassifiedEvent.builder()
                          .seqNumber(nextSequenceNumber())
                          .name(nodeInfo.getName())
                          .txnId(AlfrescoTransactionSupport.getTransactionId())
                          .timestamp(System.currentTimeMillis())
                          .networkId(TenantUtil.getCurrentDomain())
                          .siteId(nodeInfo.getSiteId())
                          .nodeId(nodeInfo.getNodeId())
                          .nodeType(nodeInfo.getType().toPrefixString(namespaceService))
                          .paths(nodeInfo.getPaths())
                          .parentNodeIds(nodeInfo.getParentNodeIds())
                          .username(AuthenticationUtil.getFullyAuthenticatedUser())
                          .nodeModificationTime(nodeInfo.getModificationTimestamp())
                          .client(getAlfrescoClient(nodeInfo.getClient()))
                          .aspects(nodeInfo.getAspectsAsStrings())
                          .nodeProperties(nodeInfo.getProperties())
                          .build();
        sendEvent(event);
    }
}
 
Example #16
Source File: EventsServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void fileUnclassified(NodeRef nodeRef)
{
    NodeInfo nodeInfo = getNodeInfo(nodeRef, FileUnclassifiedEvent.EVENT_TYPE);
    if(nodeInfo.checkNodeInfo())
    {
        Event event = FileUnclassifiedEvent.builder()
                          .seqNumber(nextSequenceNumber())
                          .name(nodeInfo.getName())
                          .txnId(AlfrescoTransactionSupport.getTransactionId())
                          .timestamp(System.currentTimeMillis())
                          .networkId(TenantUtil.getCurrentDomain())
                          .siteId(nodeInfo.getSiteId())
                          .nodeId(nodeInfo.getNodeId())
                          .nodeType(nodeInfo.getType().toPrefixString(namespaceService))
                          .paths(nodeInfo.getPaths())
                          .parentNodeIds(nodeInfo.getParentNodeIds())
                          .username(AuthenticationUtil.getFullyAuthenticatedUser())
                          .nodeModificationTime(nodeInfo.getModificationTimestamp())
                          .client(getAlfrescoClient(nodeInfo.getClient()))
                          .aspects(nodeInfo.getAspectsAsStrings())
                          .nodeProperties(nodeInfo.getProperties())
                          .build();
        sendEvent(event);
    }
}
 
Example #17
Source File: AuthenticationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test for ALF-20680
 * Test of the {@link RepositoryAuthenticationDao#getUserFolderLocation(String)} in multitenancy
 */
public void testAuthenticateMultiTenant()
{
    // Create a tenant domain
    TenantUtil.runAsSystemTenant(new TenantUtil.TenantRunAsWork<Object>()
    {
        public Object doWork() throws Exception
        {
            if (!tenantAdminService.existsTenant(TEST_TENANT_DOMAIN))
            {
                tenantAdminService.createTenant(TEST_TENANT_DOMAIN, TENANT_ADMIN_PW.toCharArray(), null);
            }
            return null;
        }
    }, TenantService.DEFAULT_DOMAIN);

    // Use default admin
    authenticateMultiTenantWork(AuthenticationUtil.getAdminUserName(), DEFAULT_ADMIN_PW);

    // Use tenant admin
    authenticateMultiTenantWork(AuthenticationUtil.getAdminUserName() + TenantService.SEPARATOR + TEST_TENANT_DOMAIN, TENANT_ADMIN_PW);
}
 
Example #18
Source File: TenantRoutingContentStore.java    From alfresco-simple-content-stores with Apache License 2.0 6 votes vote down vote up
/**
 *
 * {@inheritDoc}
 */
@Override
protected ContentStore selectWriteStoreFromRoutes(final ContentContext ctx)
{
    final ContentStore writeStore;
    final String tenant = TenantUtil.getCurrentDomain();
    if (this.storeByTenant.containsKey(tenant))
    {
        LOGGER.debug("Selecting store for tenant {} to write {}", tenant, ctx);
        writeStore = this.storeByTenant.get(tenant);
    }
    else
    {
        LOGGER.debug("No store defined for tenant {} - delegating to super.selectWiteStoreFromRoute", tenant);
        writeStore = super.selectWriteStoreFromRoutes(ctx);
    }

    return writeStore;
}
 
Example #19
Source File: MailActionExecuter.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public String getPersonEmail(final String user)
{
    final NodeRef person = getPerson(user);
    String email = null;
    String domain = tenantService.getPrimaryDomain(user); // get primary tenant 
    if (domain != null) 
    { 
        email = TenantUtil.runAsTenant(new TenantRunAsWork<String>()
        {
            public String doWork() throws Exception
            {
                return (String) nodeService.getProperty(person, ContentModel.PROP_EMAIL);
            }
        }, domain);
    }
    else
    {
        email = (String) nodeService.getProperty(person, ContentModel.PROP_EMAIL);
    }
    return email;
}
 
Example #20
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 #21
Source File: QuickShareServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void deleteQuickShareLinkExpiryAction(QuickShareLinkExpiryAction linkExpiryAction)
{
    ParameterCheck.mandatory("linkExpiryAction", linkExpiryAction);

    NodeRef nodeRef = null;
    try
    {
        Pair<String, NodeRef> pair = getTenantNodeRefFromSharedId(linkExpiryAction.getSharedId());
        nodeRef = pair.getSecond();
    }
    catch (InvalidSharedIdException ex)
    {
        // do nothing, as the node might be already unshared
    }
    final NodeRef sharedNodeRef = nodeRef;

    TenantUtil.runAsSystemTenant(() -> {
        // Delete the expiry action and its related persisted schedule
        deleteQuickShareLinkExpiryActionImpl(linkExpiryAction);

        // As the method is called directly (ie. not via unshareContent method which removes the aspect properties),
        // then we have to remove the 'expiryDate' property as well.
        if (sharedNodeRef != null && nodeService.getProperty(sharedNodeRef, QuickShareModel.PROP_QSHARE_EXPIRY_DATE) != null)
        {
            behaviourFilter.disableBehaviour(sharedNodeRef, ContentModel.ASPECT_AUDITABLE);
            try
            {
                nodeService.removeProperty(sharedNodeRef, QuickShareModel.PROP_QSHARE_EXPIRY_DATE);
            }
            finally
            {
                behaviourFilter.enableBehaviour(sharedNodeRef, ContentModel.ASPECT_AUDITABLE);
            }
        }
        return null;
    }, TenantUtil.getCurrentDomain());
}
 
Example #22
Source File: RepoService.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public NodeRef addUserDescription(final String personId, final String personDescription)
{
	NodeRef personRef = TenantUtil.runAsTenant(new TenantRunAsWork<NodeRef>()
	{
		public NodeRef doWork() throws Exception
		{
			return RepoService.this.addUserDescription(personId, TestNetwork.this, personDescription);
		}
	}, getId());

	return personRef;
}
 
Example #23
Source File: AbstractEventsService.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
    public void afterRollback()
    {
        String txnId = AlfrescoTransactionSupport.getTransactionId();
        long timestamp = System.currentTimeMillis();
        String networkId = TenantUtil.getCurrentDomain();
        String username = AuthenticationUtil.getFullyAuthenticatedUser();
        Client alfrescoClient = getAlfrescoClient(null);

        Event event = new TransactionRolledBackEvent(nextSequenceNumber(), txnId, networkId, timestamp, username,
                alfrescoClient);

        if (logger.isDebugEnabled())
        {
            logger.debug("sendEvent "+event);
        }

        try
        {
            messageProducer.send(event);
        }
        catch (MessagingException e)
        {
//			throw new AlfrescoRuntimeException("Failed to send event", e);
            // TODO just log for now. How to deal with no running ActiveMQ?
            logger.error("Failed to send event " + event, e);
        }
        finally
        {
            TxnEvents events = (TxnEvents)AlfrescoTransactionSupport.getResource(EVENTS_KEY);
            if(events != null)
            {
                events.clear();
            }
        }
    }
 
Example #24
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 #25
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 #26
Source File: EventsServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void nodeCheckedIn(NodeRef nodeRef)
{
    NodeInfo nodeInfo = getNodeInfo(nodeRef, NodeCheckedInEvent.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 NodeCheckedInEvent(nextSequenceNumber(), name, txnId, timestamp, networkId, siteId, objectId, nodeType,
                nodePaths, pathNodeIds, username, modificationTime, alfrescoClient, aspects,
                properties);
        sendEvent(event);
    }
}
 
Example #27
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 #28
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 #29
Source File: EventsServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void recordRejected(NodeRef nodeRef)
{
    NodeInfo nodeInfo = getNodeInfo(nodeRef, RecordRejectedEvent.EVENT_TYPE);
    if(nodeInfo.checkNodeInfo())
    {
        //The event should contain the path that points to the original location of the file.
        //Since the record creation, the record might've been hidden on the collaboration site, thus removing the secondary parent-child association, 
        //we'll use a RM specific property that stores the original location of the file.
        if (PROP_RMA_RECORD_ORIGINATING_LOCATION == null)
        {
            logger.error(format("Could not generate %s event for node %s because %s property is not found.", RecordRejectedEvent.EVENT_TYPE, nodeRef, RM_MODEL_PROP_NAME_RECORD_ORIGINATING_LOCATION));
            return;
        }
        NodeRef recordOriginatingLocation = (NodeRef) nodeService.getProperty(nodeRef, PROP_RMA_RECORD_ORIGINATING_LOCATION);
        String recordOriginatingParentName = (String) nodeService.getProperty(recordOriginatingLocation, ContentModel.PROP_NAME);
        Path originatingParentPath = nodeService.getPath(recordOriginatingLocation);
        
        Event event = RecordRejectedEvent.builder()
                          .seqNumber(nextSequenceNumber())
                          .name(nodeInfo.getName())
                          .txnId(AlfrescoTransactionSupport.getTransactionId())
                          .timestamp(System.currentTimeMillis())
                          .networkId(TenantUtil.getCurrentDomain())
                          .siteId(nodeInfo.getSiteId())
                          .nodeId(nodeInfo.getNodeId())
                          .nodeType(nodeInfo.getType().toPrefixString(namespaceService))
                          .paths(getPaths(singletonList(originatingParentPath), asList(recordOriginatingParentName, nodeInfo.getName())))
                          .parentNodeIds(this.getNodeIds(singletonList(originatingParentPath)))
                          .username(AuthenticationUtil.getFullyAuthenticatedUser())
                          .nodeModificationTime(nodeInfo.getModificationTimestamp())
                          .client(getAlfrescoClient(nodeInfo.getClient()))
                          .aspects(nodeInfo.getAspectsAsStrings())
                          .nodeProperties(nodeInfo.getProperties())
                          .build();
        sendEvent(event);
    }
}
 
Example #30
Source File: EventsServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void recordCreated(NodeRef nodeRef)
{
    NodeInfo nodeInfo = getNodeInfo(nodeRef, RecordCreatedEvent.EVENT_TYPE);
    if(nodeInfo.checkNodeInfo())
    {
        //The event should contain the path that points to the original location of the file.
        //When a node is declared as a record, a secondary association is created for the original location, hence use just that.
        List<Path> allPaths = nodeService.getPaths(nodeRef, false);
        Path primaryPath = nodeService.getPath(nodeRef);
        
        if (allPaths.size() >= 2)
        {
            allPaths.remove(primaryPath);
        }

        List<Path> recordPath = Collections.singletonList(allPaths.get(0));
                    
        Event event = RecordCreatedEvent.builder()
                          .seqNumber(nextSequenceNumber())
                          .name(nodeInfo.getName())
                          .txnId(AlfrescoTransactionSupport.getTransactionId())
                          .timestamp(System.currentTimeMillis())
                          .networkId(TenantUtil.getCurrentDomain())
                          .siteId(nodeInfo.getSiteId())
                          .nodeId(nodeInfo.getNodeId())
                          .nodeType(nodeInfo.getType().toPrefixString(namespaceService))
                          .paths(getPaths(recordPath, Arrays.asList(nodeInfo.getName())))
                          .parentNodeIds(this.getNodeIdsFromParent(recordPath))
                          .username(AuthenticationUtil.getFullyAuthenticatedUser())
                          .nodeModificationTime(nodeInfo.getModificationTimestamp())
                          .client(getAlfrescoClient(nodeInfo.getClient()))
                          .aspects(nodeInfo.getAspectsAsStrings())
                          .nodeProperties(nodeInfo.getProperties())
                          .build();
        sendEvent(event);
    }
}