问题描述和代码已更新
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>