10-05-2010 10:19 AM
<?xml version="1.0" encoding="UTF-8"?>
<!– Custom Model –>
<!– Note: This model is pre-configured to load at startup of the Repository.
So, all custom –>
<!– types and aspects added here will automatically be registered –>
<model name="ivm:invoiceModel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
<!– Optional meta-data about the model –>
<description>Invoice Custom Model FH Mainz</description>
<author>M. Noubough</author>
<version>1.0</version>
<imports>
<!– Import Alfresco Dictionary Definitions –>
<import uri="http://www.alfresco.org/model/dictionary/1.0"
prefix="d" />
<!– Import Alfresco Content Domain Model Definitions –>
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" />
</imports>
<!– Introduction of new namespaces defined by this model –>
<!– NOTE: The following namespace custom.model should be changed to reflect
your own namespace –>
<namespaces>
<namespace uri="http://www.dialog-semiconductor.com/model/content/1.0"
prefix="ivm" />
</namespaces>
<types>
<type name="ivm:inVoice">
<title>Invoice FH Mainz</title>
<parent>cm:content</parent>
<properties>
<property name="ivm:Number">
<title>Rechnungsnummer</title>
<type>d:text</type>
<mandatory>true</mandatory>
</property>
<property name="ivm:Amount">
<title>Betrag</title>
<type>d:text</type>
<mandatory>true</mandatory>
</property>
<property name="ivmate">
<title>Datum</title>
<type>d:date</type>
<mandatory>true</mandatory>
</property>
<property name="ivm:customerNumber">
<title>Kundennummer</title>
<type>d:text</type>
<mandatory>true</mandatory>
</property>
<property name="ivmayment">
<title>Zahlungsfrist</title>
<type>d:date</type>
<mandatory>true</mandatory>
</property>
<property name="ivm:distributor">
<title>Lieferant</title>
<type>d:text</type>
<mandatory>true</mandatory>
</property>
<property name="ivm:distributorNumber">
<title>Lieferanten-Nr.</title>
<type>d:text</type>
<mandatory>true</mandatory>
</property>
</properties>
</type>
</types>
</model>
10-06-2010 04:21 AM
10-07-2010 05:40 AM
public class InvoiceDataActionExecuter extends ActionExecuterAbstractBase {
/**
* The node service
*/
private NodeService nodeService;
private ContentService contentService;
private ServiceRegistry serviceRegistry;
private FileFolderService fileFolderservice;
private SearchService searchService;
/*
* this method reads the jpl file and extracts the
*/
private List<String> readJPLFile(NodeRef ref) {
contentService = serviceRegistry.getContentService();
List<String> list = new ArrayList<String>();
if (contentService != null) {
ContentReader reader = contentService.getReader(ref,
ContentModel.PROP_CONTENT);
if (reader != null) {
InputStream is = reader.getContentInputStream();
BufferedReader bf = new BufferedReader(
new InputStreamReader(is));
String line = null;
int count = 0;
try {
if(bf!=null){
while ((line = bf.readLine()) != null) {
count++;
System.out.println(line);
if (count > 7) {
System.out.println(line);
line = line.substring(line.indexOf('=') + 2);
System.out.println("dies ist line: " + line);
//line = line.replaceAll("\"", "");
line=line.substring(1, line.lastIndexOf('"'));
list.add(line);
System.out.println(line);
}
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
bf.close();
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
return list;
}
@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
if (this.nodeService.exists(actionedUponNodeRef) == true) {
fileFolderservice = serviceRegistry.getFileFolderService();
FileInfo infos = fileFolderservice.getFileInfo(actionedUponNodeRef);
String pdfFileName = infos.getName();
System.out.println("Actioned File:" +pdfFileName);
pdfFileName = pdfFileName.substring(0, pdfFileName.indexOf('.'))
+ ".jpl";
System.out.println("JPL File:"+pdfFileName);
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE,
"SpacesStore");
searchService = serviceRegistry.getSearchService();
resultSet = searchService.query(storeRef,
SearchService.LANGUAGE_LUCENE,
"PATH:\"/app:company_home/cm:Dialog_Company\"");
System.out.println("Node Reference: "+resultSet.getNodeRef(0));
NodeRef nodeRef=resultSet.getNodeRef(0);
resultSet.close();
NodeRef fileRef=this.nodeService.getChildByName(nodeRef, ContentModel.ASSOC_CONTAINS, pdfFileName);
System.out.println("File Ref: "+fileRef);
if (resultSet != null) {
ArrayList<String> properties=(ArrayList<String>) readJPLFile(fileRef);
if(properties!=null && !properties.isEmpty()){
Map<QName,Serializable> properties1 =new HashMap<QName,Serializable>();
QName[] contentProperties = new QName[InvoiceModelProperties.PROPERTIES_SIZE];
contentProperties[0]=InvoiceModelProperties.PROP_DISTRIBUTOR;
contentProperties[1]=InvoiceModelProperties.PROP_DISTRIBUTOR_NUMBER;
contentProperties[2]=InvoiceModelProperties.PROP_NUMBER;
contentProperties[3]=InvoiceModelProperties.PROP_DATE;
contentProperties[4]=InvoiceModelProperties.PROP_CUSTOMER_NUMBER;
contentProperties[5]=InvoiceModelProperties.PROP_AMOUNT;
contentProperties[6]=InvoiceModelProperties.PROP_PAYMENT;
for(int i=0; i<contentProperties.length; i++){
properties1.put(contentProperties[i], properties.get(i));
}
if(!properties1.isEmpty()){
this.nodeService.setProperties(actionedUponNodeRef, properties1);
}
}
}
}
}
@Override
protected void addParameterDefinitions(List<ParameterDefinition> paramList) {
// do Nothing
}
public void setServiceRegistry(ServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry;
}
private ResultSet resultSet;
public FileFolderService getService() {
return fileFolderservice;
}
public void setService(FileFolderService service) {
this.fileFolderservice = service;
}
public ContentService getContentService() {
return contentService;
}
public void setContentService(ContentService myService) {
this.contentService = myService;
}
public NodeService getNodeService() {
return nodeService;
}
public ServiceRegistry getServiceRegistry() {
return serviceRegistry;
}
public void setNodeService(NodeService nodeService) {
this.nodeService = nodeService;
}
}
The node's content is missing:should i check out the PDF file before run action and the check in?
node: workspace://SpacesStore/b8a344d7-a00a-453f-a068-77dc18edd789
reader: null
Please contact your system administrator.
10-07-2010 06:35 AM
Map<QName, Serializeable> props = nodeService.getProperties(nodeRef);
props.put(…); // as often as needed
nodeService.putProperties(nodeRef, props);
10-07-2010 10:53 AM
10-11-2010 09:08 AM
As a side note, it is a bad habit sending debug messages with System.out.println()thank you for your advice on logging. I usually use log4j, so i have my own log4j.properties file along with the Action class in a jar, that i have deployed under tomcat/weapp/alfresco/WEB-INF/lib directory, but Alfresco ignores it. i am newbie in alfresco and don't know how to deploy custom log4j.properties, so that it extends Alfresco logging. therefore System.out.print() was the only alternative for my to get log messages.
call doAction()…
actioned Node exists
call makeJPLFileName()…
Actioned PDF Document :DFD213236A8953F196B1000C2952CC11.PDF
related JPL Document :DFD213236A8953F196B1000C2952CC11.jpl
get primary Parent of actioned Node…
ID of Parent of actioned Node: dc89752e-8e1e-4301-8fe6-e5e20116dae6
get Reference of JPL File…
Reference of JPL File: 59924d72-6ff8-46ff-a0fb-895df7bbe0cf
addProperty method entered…
call redJPLFile()…
SAP_IP: DFD213236A8953F196B1000C2952CC11 with length of: 32 character
call setProperty() of node service…
delete JPL file after proccessing…
14:49:25,964 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:25,964 DEBUG [smb.protocol.auth] Using Write transaction
14:49:25,964 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:25,979 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:25,979 DEBUG [smb.protocol.auth] Using Write transaction
14:49:25,979 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:25,995 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:25,995 DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,120 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,120 DEBUG [smb.protocol.auth] Using Write transaction
call doAction()…
actioned Node exists
call makeJPLFileName()…
Actioned PDF Document :DFD213236A8953F196B1000C2952CC11.PDF
related JPL Document :DFD213236A8953F196B1000C2952CC11.jpl
get primary Parent of actioned Node…
ID of Parent of actioned Node: dc89752e-8e1e-4301-8fe6-e5e20116dae6
get Reference of JPL File…
14:49:26,229 DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,229 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,245 User:admin DEBUG [smb.protocol.auth] Using Write transaction
JPL file doesn't exists …
14:49:26,261 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,261 DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,276 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,276 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,276 DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,276 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,292 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,292 DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,292 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,292 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,307 DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,307 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,307 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,307 DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,323 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,339 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,339 DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,339 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,354 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,386 DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,386 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,401 DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,401 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,511 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,526 DEBUG [smb.protocol.auth] Using Write transaction
call move method to move PDF file to fault Folder…
move method entered…
get Store Ref of actioned Node…
get Reference of Faut Folder…
14:49:27,339 DEBUG [smb.protocol.auth] Using Write transaction
14:49:27,354 DEBUG [smb.protocol.auth] Using Write transaction
14:49:27,370 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:27,370 DEBUG [smb.protocol.auth] Using Write transaction
14:49:27,386 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:28,604 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:28,604 DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,526 User:admin DEBUG [smb.protocol.auth] Using Write transaction
Fault Folder Reference is: 1069cc4d-8a17-469c-b0c9-ee4a8e1ba08a
call move method of node Service to move actioned Node…
14:49:30,526 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,573 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,589 DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,589 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,604 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,604 DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,620 ERROR [repo.action.AsynchronousActionExecutionQueueImpl] Failed to execute asynchronous action: Action[ id=b4183d74-7eca-4c16-ad9e-9632c
ee2b810, node=workspace://SpacesStore/b4183d74-7eca-4c16-ad9e-9632cee2b810 ]
java.lang.NullPointerException
at org.alfresco.repo.domain.hibernate.ChildAssocImpl.setQName(ChildAssocImpl.java:227)
at org.alfresco.repo.node.db.hibernate.HibernateNodeDaoServiceImpl$14.doInHibernate(HibernateNodeDaoServiceImpl.java:2254)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:339)
at org.alfresco.repo.node.db.hibernate.HibernateNodeDaoServiceImpl.writeChildAssocChanges(HibernateNodeDaoServiceImpl.java:2018)
at org.alfresco.repo.node.db.hibernate.HibernateNodeDaoServiceImpl.updateChildAssoc(HibernateNodeDaoServiceImpl.java:2262)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.alfresco.repo.transaction.TransactionalDaoInterceptor.invoke(TransactionalDaoInterceptor.java:62)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.alfresco.repo.domain.hibernate.DirtySessionMethodInterceptor.invoke(DirtySessionMethodInterceptor.java:413)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.alfresco.repo.transaction.SingleEntryTransactionResourceInterceptor.invokeInternal(SingleEntryTransactionResourceInterceptor.java:157)
at org.alfresco.repo.transaction.SingleEntryTransactionResourceInterceptor.invoke(SingleEntryTransactionResourceInterceptor.java:132)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy8.updateChildAssoc(Unknown Source)
at org.alfresco.repo.node.db.DbNodeServiceImpl.moveNode(DbNodeServiceImpl.java:2232)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.alfresco.repo.tenant.MultiTNodeServiceInterceptor.invoke(MultiTNodeServiceInterceptor.java:104)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy10.moveNode(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.alfresco.repo.service.StoreRedirectorProxyFactory$RedirectorInvocationHandler.invoke(StoreRedirectorProxyFactory.java:215)
at $Proxy11.moveNode(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.alfresco.repo.node.MLPropertyInterceptor.invoke(MLPropertyInterceptor.java:303)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.alfresco.repo.node.MLPropertyInterceptor.invoke(MLPropertyInterceptor.java:303)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.alfresco.repo.node.NodeRefPropertyMethodInterceptor.invoke(NodeRefPropertyMethodInterceptor.java:269)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.alfresco.repo.node.NodeRefPropertyMethodInterceptor.invoke(NodeRefPropertyMethodInterceptor.java:269)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy10.moveNode(Unknown Source)
at lab.ApplySapActionExecutor.moveIncompleteSAPdocument(Unknown Source)
at lab.ApplySapActionExecutor.doAction(Unknown Source)
at lab.ApplySapActionExecutor.executeImpl(Unknown Source)
at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:133)
at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:726)
at org.alfresco.repo.action.executer.CompositeActionExecuter.executeImpl(CompositeActionExecuter.java:66)
at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:133)
at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:726)
at org.alfresco.repo.action.ActionServiceImpl.executeActionImpl(ActionServiceImpl.java:658)
at org.alfresco.repo.action.AsynchronousActionExecutionQueueImpl$ActionExecutionWrapper$1$1.execute(AsynchronousActionExecutionQueueImpl.java:
494)
at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:325)
at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:232)
at org.alfresco.repo.action.AsynchronousActionExecutionQueueImpl$ActionExecutionWrapper$1.doWork(AsynchronousActionExecutionQueueImpl.java:503
)
at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:508)
at org.alfresco.repo.action.AsynchronousActionExecutionQueueImpl$ActionExecutionWrapper.run(AsynchronousActionExecutionQueueImpl.java:506)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
14:49:30,620 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,636 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,651 DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,651 DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,651 DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,651 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,667 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,667 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,667 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,667 DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,683 DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,683 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,698 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,714 DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,714 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,729 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,745 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,745 DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,745 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,745 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,745 DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,761 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,761 DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,761 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,761 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,776 DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,776 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,776 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,776 DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,808 DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,808 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,823 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,839 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,839 DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,854 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,854 DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,854 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,854 DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,854 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,870 User:admin DEBUG [smb.protocol.auth] Using Write transaction
package lab;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.model.FileExistsException;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.SearchService;
import org.apache.log4j.Logger;
public class ApplySapActionExecutor extends ActionExecuterAbstractBase {
private NodeService nodeService;
private ContentService contentService;
private ServiceRegistry serviceRegistry;
private static final Logger sLogger = Logger
.getLogger(ApplySapActionExecutor.class);
private void doAction(NodeRef actionedUponNodeRef) {
if (this.nodeService.exists(actionedUponNodeRef) == true) {
System.out.println("call makeJPLFileName()…");
String jplFileName = this.makeJPLFileName(actionedUponNodeRef);
System.out.println("get primary Parent of actioned Node…");
ChildAssociationRef childAss = this.nodeService
.getPrimaryParent(actionedUponNodeRef);
NodeRef parent = childAss.getParentRef();
sLogger.info("ID of Parent of actioned Node: " + parent.getId());
System.out.println("ID of Parent of actioned Node: "
+ parent.getId());
try {
//wait 2 s for JPL file
Thread.sleep(2000);
System.out.println("get Reference of JPL File…");
NodeRef jpl = this.nodeService.getChildByName(parent,
ContentModel.ASSOC_CONTAINS, jplFileName);
if (jpl != null) {
System.out.println("Reference of JPL File: " + jpl.getId());
this.setProperty(jpl, actionedUponNodeRef);
} else {
System.out.println("JPL file doesn't exists …");
System.out
.println("call move method to move PDF file to fault Folder…");
//JPL file does not exists—> move PDF file to fault folder
this.moveIncompleteSAPdocument(actionedUponNodeRef);
}
} catch (InterruptedException e) {
System.out
.println("call move method in catch block to move PDF file to fault Folder…");
this.moveIncompleteSAPdocument(actionedUponNodeRef);
e.printStackTrace();
}
}
}
private void moveIncompleteSAPdocument(final NodeRef actionedUponNodeRef) {
System.out.println("move method entered…");
System.out.println("get Store Ref of actioned Node…");
StoreRef storeRef = actionedUponNodeRef.getStoreRef();
System.out.println("get Reference of Faut Folder…");
ResultSet resultSet = this.serviceRegistry.getSearchService().query(
storeRef, SearchService.LANGUAGE_LUCENE,
"PATH:\"/app:company_home/cm:Fault_Folder\"");
NodeRef faultFolder = resultSet.getNodeRef(0);
if (faultFolder != null)
System.out.println("Fault Folder Reference is: "
+ faultFolder.getId());
try {
System.out
.println("call move method of node Service to move actioned Node…");
ChildAssociationRef assoc = this.nodeService.moveNode(
actionedUponNodeRef, faultFolder,
ContentModel.ASSOC_CONTAINS, null);
if (assoc != null) {
System.out.println("ChildAssociation Ref is: "
+ assoc.toString());
} else {
System.out.println("Node can't be moved …");
}
} catch (FileExistsException e) {
e.printStackTrace();
} finally {
resultSet.close();
}
}
//make construct JPL file name
private String makeJPLFileName(NodeRef actionedUponNodeRef) {
String jplFileName = null;
String pdfFileName = null;
pdfFileName = (String) this.nodeService.getProperty(
actionedUponNodeRef, ContentModel.PROP_NAME);
sLogger.info("Actioned PDF Document :" + pdfFileName);
System.out.println("Actioned PDF Document :" + pdfFileName);
jplFileName = pdfFileName.substring(0, pdfFileName.lastIndexOf('.'))
+ ".jpl";
sLogger.info("related JPL Document :" + jplFileName);
System.out.println("related JPL Document :" + jplFileName);
return jplFileName;
}
//set value of custom property SAP ID
private void setProperty(final NodeRef ref,
final NodeRef actionedUponNodeRef) {
System.out.println("addProperty method entered…");
ArrayList<String> properties;
try {
System.out.println("call redJPLFile()…");
properties = (ArrayList<String>) this.readJPLFile(ref);
if (properties != null && !properties.isEmpty()) {
final String sapId = properties.get(0);
if (sapId.length() < 32 || sapId.length() > 32) {
System.out
.println("Length of SAP_ID was less than 32 char… ");
this.moveIncompleteSAPdocument(actionedUponNodeRef);
return;
}
System.out.println("call setProperty() of node service…");
this.nodeService.setProperty(actionedUponNodeRef,
SAPMetaDataModelProperties.PROP_SAP_ID,
properties.get(0));
}
// this.moveIncompleteSAPdocument(actionedUponNodeRef);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (ref != null) {
//finally delete the JPL file
System.out.println("delete JPL file after proccessing…");
nodeService.addAspect(ref, ContentModel.ASPECT_TEMPORARY, null);
nodeService.deleteNode(ref);
}
}
}
private List<String> readJPLFile(NodeRef ref) throws IOException {
serviceRegistry.getCheckOutCheckInService();
contentService = serviceRegistry.getContentService();
List<String> list = new ArrayList<String>();
if (contentService != null) {
ContentReader reader = contentService.getReader(ref,
ContentModel.PROP_CONTENT);
if (reader != null) {
InputStream is = reader.getContentInputStream();
BufferedReader bf = new BufferedReader(
new InputStreamReader(is));
String line = null;
int count = 0;
try {
if (bf != null) {
while ((line = bf.readLine()) != null) {
count++;
if (count == 3) {
line = line.substring(line.indexOf('=') + 1);
sLogger.info("SAP_IP: " + line
+ " with length of: " + line.length()
+ " character");
System.out.println("SAP_IP: " + line
+ " with length of: " + line.length()
+ " character");
list.add(line);
}
}
}
} catch (IOException e) {
sLogger.error(e.getMessage());
e.printStackTrace();
} finally {
bf.close();
is.close();
}
}
}
return list;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action,
* org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
System.out.println("call doAction()…");
doAction(actionedUponNodeRef);
}
/**
* @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefinitions(java.util.List)
*/
@Override
protected void addParameterDefinitions(List<ParameterDefinition> paramList) {
// No parameters so do nothing
}
public void setNodeService(NodeService nodeService) {
this.nodeService = nodeService;
}
public void setServiceRegistry(ServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry;
}
}
10-11-2010 11:47 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.