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

The following examples show how to use org.alfresco.repo.tenant.TenantUtil#runAsDefaultTenant() . 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: QuickShareServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Removes (hard deletes) the previously persisted {@link QuickShareLinkExpiryAction} and its related
 * schedule {@link ScheduledPersistedAction} from the repository.
 */
protected void deleteQuickShareLinkExpiryAction(NodeRef linkExpiryActionNodeRef)
{
    TenantUtil.runAsDefaultTenant(() -> {
        QuickShareLinkExpiryAction linkExpiryAction = quickShareLinkExpiryActionPersister.loadQuickShareLinkExpiryAction(linkExpiryActionNodeRef);
        // Delete the expiry action and its related persisted schedule
        deleteQuickShareLinkExpiryActionImpl(linkExpiryAction);
        return null;
    });
}
 
Example 3
Source File: QuickShareServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Pair<String, NodeRef> getTenantNodeRefFromSharedId(final String sharedId)
{
    NodeRef nodeRef = TenantUtil.runAsDefaultTenant(new TenantRunAsWork<NodeRef>()
    {
        public NodeRef doWork() throws Exception
        {
            return (NodeRef) attributeService.getAttribute(ATTR_KEY_SHAREDIDS_ROOT, sharedId);
        }
    });

    if (nodeRef == null)
    {
        /* TODO
         * Temporary fix for RA-1093 and MNT-16224. The extra lookup should be
         * removed (the same as before, just throw the 'InvalidSharedIdException' exception) when we
         * have a system wide patch to remove the 'shared' aspect of the nodes that have been archived while shared.
         */
        // TMDQ
        final String query = "+TYPE:\"cm:content\" AND +ASPECT:\"qshare:shared\" AND =qshare:sharedId:\"" + sharedId + "\"";
        SearchParameters sp = new SearchParameters();
        sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
        sp.setQuery(query);
        sp.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);

        List<NodeRef> nodeRefs = null;
        ResultSet results = null;
        try
        {
            results = searchService.query(sp);
            nodeRefs = results.getNodeRefs();
        }
        catch (Exception ex)
        {
            throw new InvalidSharedIdException(sharedId);
        }
        finally
        {
            if (results != null)
            {
                results.close();
            }
        }
        if (nodeRefs.size() != 1)
        {
            throw new InvalidSharedIdException(sharedId);
        }
        nodeRef = tenantService.getName(nodeRefs.get(0));
    }

    // note: relies on tenant-specific (ie. mangled) nodeRef
    String tenantDomain = tenantService.getDomain(nodeRef.getStoreRef().getIdentifier());
    return new Pair<>(tenantDomain, tenantService.getBaseName(nodeRef));
}
 
Example 4
Source File: QuickShareServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Creates and persists the quick share link expiry action and its related schedule.
 */
protected void saveSharedLinkExpiryAction(String sharedId, Date expiryDate)
{
    ParameterCheck.mandatory("expiryDate", expiryDate);
    // Validate the given expiry date
    checkExpiryDate(expiryDate);

    if (logger.isDebugEnabled())
    {
        logger.debug("Creating shared link expiry action for the sharedId:" + sharedId);
    }

    final NodeRef expiryActionNodeRef = getQuickShareLinkExpiryActionNode(sharedId);
    // If an expiry action already exists for the specified shared Id, first remove it, before creating a new one.
    if (expiryActionNodeRef != null)
    {
        deleteQuickShareLinkExpiryAction(expiryActionNodeRef);
    }

    // Create the expiry action
    final QuickShareLinkExpiryAction expiryAction = new QuickShareLinkExpiryActionImpl(java.util.UUID.randomUUID().toString(), sharedId,
                "QuickShare link expiry action");
    // Create the persisted schedule
    final ScheduledPersistedAction schedule = scheduledPersistedActionService.createSchedule(expiryAction);

    // first set the scheduledAction so we can set the other information
    expiryAction.setSchedule(schedule);
    expiryAction.setScheduleStart(expiryDate);

    try
    {
        TenantUtil.runAsDefaultTenant((TenantRunAsWork<Void>) () -> {
            quickShareLinkExpiryActionPersister.saveQuickShareLinkExpiryAction(expiryAction);
            scheduledPersistedActionService.saveSchedule(schedule);

            return null;
        });

    }
    catch (Exception ex)
    {
        throw new QuickShareLinkExpiryActionException("Couldn't create quick share link expiry action.", ex);
    }

    if (logger.isDebugEnabled())
    {
        logger.debug("Quick share link expiry action is created for sharedId[" + sharedId + "] and it's scheduled to be executed on: "
                    + expiryDate);
    }
}
 
Example 5
Source File: QuickShareServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private NodeRef getQuickShareLinkExpiryActionNode(String sharedId)
{
    final QName expiryActionQName = QuickShareLinkExpiryActionImpl.createQName(sharedId);
    return TenantUtil.runAsDefaultTenant(() -> quickShareLinkExpiryActionPersister.getQuickShareLinkExpiryActionNode(expiryActionQName));
}