0

问题描述和代码已更新

int attachmentid = 123;问题 1:为了读取自定义属性 sc:OpenERPattachmentID1 以获取存储在其中的 id 值,我应该用什么替换下面代码中的虚拟对象? (问题1由alfrescian回答!)

package com.openerp.behavior;



import java.util.List;
import java.net.*;
import java.io.*;


import org.alfresco.repo.node.NodeServicePolicies;

import org.alfresco.repo.policy.Behaviour;

import org.alfresco.repo.policy.JavaBehaviour;

import org.alfresco.repo.policy.PolicyComponent;

import org.alfresco.repo.policy.Behaviour.NotificationFrequency;

import org.alfresco.repo.security.authentication.AuthenticationUtil;

import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;

import org.alfresco.service.cmr.repository.ChildAssociationRef;

import org.alfresco.service.cmr.repository.NodeRef;

import org.alfresco.service.cmr.repository.NodeService;

import org.alfresco.service.namespace.NamespaceService;

import org.alfresco.service.namespace.QName;

import org.alfresco.service.transaction.TransactionService;

import org.apache.log4j.Logger;



//import com.openerp.model.scOpenERPModel;

public class DeleteAsset implements NodeServicePolicies.BeforeDeleteNodePolicy  {



    private PolicyComponent policyComponent;

    private Behaviour beforeDeleteNode;
    private NodeService nodeService;



    public void init() {

        this.beforeDeleteNode = new JavaBehaviour(this,"beforeDeleteNode",NotificationFrequency.EVERY_EVENT);

        this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI,"beforeDeleteNode"), 

                QName.createQName(scOpenERPModel.NAMESPACE,scOpenERPModel.ASSET_CONTENT_TYPE), this.beforeDeleteNode);

    }
    public setNodeService(NodeService nodeService){
           this.nodeService = nodeService;  
        }




    @Override

    public void beforeDeleteNode(NodeRef node) {

        System.out.println("beforeDeleteNode!");

        try {
            QName attachmentID1= QName.createQName("http://www.someco.com/model/content/1.0", "OpenERPattachmentID1"); // this could/shoul be defined in your OpenERPModel-class
            int attachmentid = (Integer)nodeService.getProperty(node, attachmentID1);
            //int attachmentid = 123;
            URL oracle = new URL("http://0.0.0.0:1885/delete/%20?attachmentid=" + attachmentid);
            URLConnection yc = oracle.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(
                        yc.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) 
            //System.out.println(inputLine);
                in.close(); 

        } catch(Exception e) {

            e.printStackTrace();

        }



    }

}

问题 2:我将 DeleteAsset.class 放在哪里?

我是 Java 和 Alfresco 新手,如果有人能告诉我 alfresco-4.2.c/tomcat/webapps/alfresco/WEB-INF/classes/com/openerp/behavior/ 是否是正确的文件夹,我会很棒编译后的 DeleteAsset.class

问题3:我应该在NAMESPACE 和ASSET_CONTENT_TYPE 中放什么? 我想在没有模型类的情况下工作,因为我还没有关于它的教程,我应该用什么代替scOpenERPModel.NAMESPACE,scOpenERPModel.ASSET_CONTENT_TYPE

这是我完整的自定义网络上下文文件:

<?xml version='1.0' encoding='UTF-8'?>
 <!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN'
 'http://www.springframework.org/dtd/spring-beans.dtd'>

 <beans>
<!-- Registration of new models -->
<bean id="smartsolution.dictionaryBootstrap" parent="dictionaryModelBootstrap"
 depends-on="dictionaryBootstrap">
    <property name="models">
        <list>
                <value>alfresco/extension/scOpenERPModel.xml</value>
        </list>
    </property>
</bean>

<!-- deletion of attachments within openERP when delete is initiated in Alfresco-->
<bean id="deletionBehavior" class="com.openerp.behavior.DeleteAsset" init-method="init">
    <property name="nodeService">
        <ref bean="nodeService" />
    </property>
    <property name="policyComponent">
        <ref bean="policyComponent" />
    </property>
</bean>

4

1 回答 1

3

好吧,你还有很长的路要走......你想用你的“oracle”连接来实现什么?

要回答您的主要问题:如何读取属性:

  1. 不要将 XML 模型放入 com/openerp/model/scOpenERPModel - 它应该是定义常量以访问您的自定义类型、方面和道具的 java 类(例如:https ://svn.alfresco.com/repos/alfresco -open-mirror/alfresco/HEAD/root/projects/data-model/source/java/org/alfresco/model/ContentModel.java)但这不是强制性的——它只是帮助你。

  2. 读取属性

    1. 注入节点服务:

      private NodeService nodeService;
      public setNodeService(NodeService nodeService){
         this.nodeService = nodeService;  
      }
      
    2. 在你的 beforeDeleteNode

      QName attachmentID1= QName.createQName("your sc NS uri", "OpenERPattachmentID1"); // this could/shoul be defined in your OpenERPModel-class
      int attachmentid = (Integer) nodeService.getProperty(node, attachmentID1);
      
于 2013-10-04T09:54:56.383 回答