08-26-2013 05:11 PM
<?xml version="1.0" encoding="UTF-8"?>
<model name="contracts:contractsModel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
<description>Contract Metadata</description>
<author>yangy</author>
<version>1.0</version>
<imports>
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
</imports>
<namespaces>
<namespace uri="contracts.model" prefix="contracts"/>
</namespaces>
<aspects>
<aspect name="contracts:metadata">
<title>Contracts Metadata</title>
<properties>
<property name="contracts:masterID">
<title>Master ID</title>
<type>d:text</type>
</property>
<property name="contracts:companyName">
<title>Company Name</title>
<type>d:text</type>
</property>
</properties>
</aspect>
</aspects>
</model>
Caused by: org.alfresco.service.cmr.dictionary.InvalidAspectException: 07260056 The aspect is invalid: {contracts.model.}metadata
package com._10x13.alfresco.email;
import org.alfresco.email.server.handler.FolderEmailMessageHandler;
import org.apache.log4j.Logger;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.email.EmailMessage;
import org.alfresco.service.cmr.email.EmailMessagePart;
import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.namespace.NamespacePrefixResolver;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.ListableBeanFactory;
import javax.xml.parsers.*;
import org.xml.sax.InputSource;
import org.w3c.dom.*;
import java.io.*;
import java.util.*;
public class CustomFolderEmailMessageHandler
extends FolderEmailMessageHandler {
private Logger log = Logger.getLogger("com._10x13");
private ListableBeanFactory beanFactory;
private NodeService nodeService;
public void setNodeService(NodeService nodeService)
{
// System.out.println(" dist ");
this.nodeService = nodeService;
}
public void processMessage(NodeRef folderNodeRef, EmailMessage message){
//ServiceRegistry serviceRegistry = (ServiceRegistry) beanFactory.getBean(ServiceRegistry.SERVICE_REGISTRY);
//NodeService nodeService = serviceRegistry.getNodeService();
String toAddress = message.getTo();
String fromAddress = message.getFrom();
String subject = message.getSubject();
MimetypeService mimetypeService = getMimetypeService();
InputStream contentIs;
InputStream bodyContent;
NodeRef contentNodeRef;
String mimeType;
log.info("An Email was sent to: " + toAddress);
log.info("An Email was sent from: " + fromAddress);
log.info("An Email was sent with the subject line of: " + subject);
//here we extract the body of the email and the meta data
EmailMessagePart mailBody = message.getBody();
bodyContent = mailBody.getContent();
String metaData = fromStream(bodyContent);
//get the metadata
String masterID = parseXMLString(metaData, "MasterID");
String companyName = parseXMLString(metaData, "CompanyName");
for(EmailMessagePart attachment: message.getAttachments()) {
//Skip saving the email as an html file
if(!attachment.getFileName().startsWith(subject)){
log.info("attached file is named: " + attachment.getFileName()
+ "And Has a size of: " + attachment.getSize() + " Bytes");
contentIs = attachment.getContent();
mimeType = mimetypeService.guessMimetype(attachment.getFileName());
//here the document is added as a node, returned nodeRef
contentNodeRef = addContentNode(nodeService,
folderNodeRef, attachment.getFileName(), true);
writeContent(contentNodeRef, contentIs, mimeType, attachment.getEncoding());
log.info("the file has been written to node: " + contentNodeRef.toString());
//add the metadata
Map<QName,Serializable> aspectValues = new HashMap<QName,Serializable>();
QName CUSTOM_ASPECT_QNAME = QName.createQName("contracts.model", "metadata");
QName PROP_QNAME_MY_PROPERTY = QName.createQName("contracts.model", "masterID");
aspectValues.put(PROP_QNAME_MY_PROPERTY, masterID);
nodeService.addAspect(contentNodeRef, CUSTOM_ASPECT_QNAME, aspectValues);
//clear aspectValues
aspectValues.clear();
PROP_QNAME_MY_PROPERTY = QName.createQName("contracts.model", "companyName");
aspectValues.put(PROP_QNAME_MY_PROPERTY, companyName);
nodeService.addAspect(contentNodeRef, CUSTOM_ASPECT_QNAME, aspectValues);
}
}
}
public static String parseXMLString(String s, String tag) {
String result = "";
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(s));
Document doc = db.parse(is);
NodeList node = doc.getElementsByTagName(tag);
Element line = (Element) node.item(0);
result = getCharacterDataFromElement(line);
}
catch (Exception e) {
e.printStackTrace();
}
return result;
}
public static String getCharacterDataFromElement(Element e) {
Node child = e.getFirstChild();
if (child instanceof CharacterData) {
CharacterData cd = (CharacterData) child;
return cd.getData();
}
return "?";
}
public static String fromStream(InputStream is) {
BufferedReader br = null;
StringBuilder sb = new StringBuilder();
String line;
try {
br = new BufferedReader(new InputStreamReader(is));
while ((line = br.readLine()) != null) {
sb.append(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return sb.toString();
}
}
08-27-2013 09:36 AM
QName.createQName("contracts.model", "metadata");
createQName(java.lang.String prefix, java.lang.String localName, NamespacePrefixResolver prefixResolver)
QName CUSTOM_ASPECT_QNAME = QName.createQName("contracts", "metadata", namespacePrefixResolver);
Caused by: java.lang.IllegalArgumentException: A Prefix Resolver must be specified
08-27-2013 10:41 AM
<?xml version="1.0" encoding="UTF-8"?>
<model name="contracts:contractsModel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
<description>Contract Metadata</description>
<author>yangy</author>
<version>1.0</version>
<imports>
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
</imports>
<namespaces>
<namespace uri="http://www.yourorganization.org/model/content/1.0" prefix="contracts"/>
</namespaces>
<aspects>
<aspect name="contracts:metadata">
<title>Contracts Metadata</title>
<properties>
<property name="contracts:masterID">
<title>Master ID</title>
<type>d:text</type>
</property>
<property name="contracts:companyName">
<title>Company Name</title>
<type>d:text</type>
</property>
</properties>
</aspect>
</aspects>
</model>
08-27-2013 10:58 AM
08-27-2013 03:40 PM
<namespace uri="http://www.yourorganization.org/model/content/1.0">
and this is now the error:
Caused by: org.alfresco.service.namespace.NamespaceException: A namespace prefix is not registered for uri contracts.model
at org.alfresco.service.namespace.QName.toPrefixString(QName.java:414)
at org.alfresco.repo.template.BaseContentNode.hasAspect(BaseContentNode.java:345)
at sun.reflect.GeneratedMethodAccessor626.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:870)
at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:106)
08-27-2013 05:15 PM
<namespace uri="http://www.yourorganization.org/model/yourmodelname/1.0" prefix="contracts"/>
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.