如何更新现有的协作者

时间:2019-02-05 16:04:11

标签: java box-api

我有一个遍历文件夹树的程序,以便根据员工及其位置的列表来设置文件夹树的安全性。

首先,我将删除所有安全性,然后再添加用户和组。当用户被重新添加为合作者时,这产生了数千封电子邮件,并且有很多讨厌的邮件给我!

因此,现在我试图找到一种更新协作者的方法,而不是删除/添加。我正在做的事情是从文件夹中建立一个协作者列表。然后,我在列表中寻找特定用户。如果找不到它们,我添加它们。如果找到它们,我需要将其安全性从“编辑器”更新为“ Co_Owner”。

有人知道怎么做吗?参见下面的代码。...

//  Loop through the property's sub-folders
for (final BoxFolder propertySubfolder : boxService.getSubFolders( propertyFolder ))
{
    out.format( "  %s%n", propertySubfolder.getInfo().getName() );

// Capture a list of all existing collaborators for later...
List<BoxCollaboration.Info > listOfCollaborators = new ArrayList<BoxCollaboration.Info >();

for( final BoxCollaboration.Info collaboration : propertySubfolder.getCollaborations() )
{
    //  Loop through existing collaborators and remove any groups so we can add them later with the appropriate access
    if( collaboration.getAccessibleBy() != null )
    {
        String collabName = collaboration.getAccessibleBy().getName();
        if( StringUtils.containsIgnoreCase( listOfGroupEditors.toString(), collabName ) )
        {
            out.println( "  Removing: " + collabName );
            collaboration.getResource().delete();
        }
        else
        {
            // Add all collaborators in this subfolder to a list for checking if we need to add collaborators later
            listOfCollaborators.add( collaboration );
        }
    }
}

int index;
BoxCollaboration.Info aCollaboration;
// Add the regional directory as a co_owner
if( regionalDirector != null )
{
    index = findCollaborator( regionalDirector, listOfCollaborators );
    if( index == -1 )
    {
        out.println( "  Adding regional director: " + regionalDirector.getInfo().getName() );
        propertySubfolder.collaborate( regionalDirector, BoxCollaboration.Role.CO_OWNER );
    }
    else
    {
        aCollaboration = listOfCollaborators.get( index );
        aCollaboration.setRole( BoxCollaboration.Role.CO_OWNER );
        // now what?
    }
}

0 个答案:

没有答案