2

我在为现有节点(“站点”文件夹)设置权限时遇到问题。我有一个组,我需要授予她对“站点”文件夹的完全控制权限。我为此使用了下一个 xml

<cm:folder view:childName="cm:Sites">
    <view:acl>
        <view:ace view:access="ALLOWED">
            <view:authority>GROUP_NOTEBOOK_PROJECT_CREATOR_GROUP</view:authority>
            <view:permission>FullControl</view:permission>
        </view:ace>
    </view:acl>
    <view:properties>
        <cm:name>Sites</cm:name>
        <sys:node-uuid>1e6f0610-a018-4966-ab37-c71e809dc6ed</sys:node-uuid>
    </view:properties>
</cm:folder>

和下一个配置上下文

<bean id="com.agilent.datastore.notebook.server.systemBootstrap" class="org.alfresco.repo.module.ImporterModuleComponent"
parent="module.baseComponent">
<property name="moduleId" value="${artifactId}" />
<property name="name" value="${name}" />
<property name="description" value="${description}" />
<property name="sinceVersion" value="${noSnapshotVersion}.${buildNumber}" />
<property name="appliesFromVersion" value="${noSnapshotVersion}.${buildNumber}" />
<!-- Uncomment next line if you want to execute bootstrap again -->
<!-- property name="executeOnceOnly" value="false" / -->
<property name="importer" ref="spacesBootstrap" />
<property name="bootstrapViews">
  <list>
    <props>
      <prop key="uuidBinding">UPDATE_EXISTING</prop>
      <prop key="path">/${spaces.company_home.childname}</prop>
      <prop key="location">alfresco/extension/agilent/sites.acp</prop>

但是当我引导这个文件夹时,我遇到了异常Cannot insert duplicate key row in object 'dbo.alf_child_assoc' with unique index 'parent_node_id'.; nested exception is java.sql.SQLException: Cannot insert duplicate key row in object 'dbo.alf_child_assoc' with unique index 'parent_node_id'.

4

2 回答 2

0

实现你想要的最好的方法是编写一个补丁,这是一个扩展 alfresco AbstractPatch.java 类的 java 类。

在 applyInternal 方法中,您首先使用 xpath-search 获取站点文件夹,因为它在后台使用 nodeService。由于补丁是在引导期间运行的,因此在执行此代码期间 Solr 将不可用。

像这样声明你在 spring 上下文文件中打补丁:

<bean id="patch.setPermissionsOnSitesFolderPatch"     class="org.yourdomain.alfresco.patch.SetPermissionOnSitesFolderPatch" parent="basePatch">
<property name="id">
  <value>patch.patch.setPermissionsOnSitesFolderPatch</value>
</property>
<property name="description">
  <value>patch.setPermissionsOnSitesFolderPatch.description</value>
</property>
<property name="fixesFromSchema">
  <value>0</value>
</property>
<property name="fixesToSchema">
  <value>${version.schema}</value>
</property>
 <property name="targetSchema">
   <value>10000</value>
  </property>
  <property name="force" value="true" />

  <property name="repository" ref="repositoryHelper"/>
</bean>
于 2014-03-27T20:08:21.777 回答
0

要完成@billerby 的答案,您还需要一个 Java 类来配合该片段。Alfresco文档包含一个很好的例子。使用它是我为我的用例提出的:

注意我使用的是 Lombok,但这只是为了方便

public class UpdatePermissionsPatch extends AbstractPatch {

    /**
      * The Alfresco Service Registry that gives access to all public content services in Alfresco.
      */
    @Setter private ServiceRegistry serviceRegistry;

    /* Properties */
    @Setter private String path;
    @Setter private String authority;
    @Setter private String permission;
    @Setter private boolean allowed;

    /** This will clear permissions for the specified authority if set to true */
    @Setter private boolean clearPermissions;

    private String getSuccessId() {
        return getId() + ".result";
    }

    private String getErrorId() {
        return getId() + ".error";
    }

    @Override
    protected String applyInternal() throws Exception {
       log.info("Starting execution of patch: {}", I18NUtil.getMessage(getId()));

       // Get the store reference for the Repository store that contains live content
       StoreRef store = StoreRef.STORE_REF_WORKSPACE_SPACESSTORE;

       // Get root node for store
       NodeRef rootRef = serviceRegistry.getNodeService().getRootNode(store);

       // Do the patch work
       setPermissions(getWipNodeRef(rootRef));

       log.info("Finished execution of patch: {}", I18NUtil.getMessage(getId()));

       return I18NUtil.getMessage(getSuccessId());
    }

    private void setPermissions(NodeRef nodeRef) {
        PermissionService permsService = serviceRegistry.getPermissionService();

        if (clearPermissions) {
            permsService.clearPermission(nodeRef, authority);
        }

        permsService.setPermission(nodeRef, authority, permission, allowed);
    }

    private NodeRef getWipNodeRef(NodeRef rootNodeRef) {
        NamespaceService nsService = serviceRegistry.getNamespaceService();
        List<NodeRef> refs = searchService.selectNodes(rootNodeRef, path, null, nsService, false);
        if (refs.size() != 1) {
            throw new AlfrescoRuntimeException(I18NUtil.getMessage(getErrorId(),
                String.format("Node could not be found, XPATH query %s returned %i nodes.", path, refs.size())
            ));
        }

        return refs.get(0);
    }
}

您的引导上下文 xml 将需要包含以下内容:

<bean
    id="org.tutorial.folderUpdateWipPermissions"
    class="org.tutorial.patch.UpdatePermissionsPatch"
    parent="basePatch"
>
    <property name="id" value="org.tutorial.bootstrap.patch.folderUpdateWipPermissions" />
    <property name="description" value="org.tutorial.bootstrap.patch.folderUpdateWipPermissions.description" />
    <property name="fixesFromSchema" value="0" />
    <property name="fixesToSchema" value="${version.schema}" />
    <property name="targetSchema" value="100003" />
    <property name="serviceRegistry">
        <ref bean="ServiceRegistry"/>
    </property>
    <property name="path" value="/${spaces.company_home.childname}/cm:Work_x0020_In_x0020_Progress" />
    <property name="authority" value="GROUP_MyGroup" />
    <property name="permission" value="Consumer" />
    <property name="allowed" value="true" />
    <property name="clearPermissions" value="true" />
</bean>
于 2021-08-12T20:53:37.113 回答