06-14-2012 06:01 PM
06-15-2012 05:06 AM
06-15-2012 10:09 AM
You probably want to register a post commit transaction listener in the onCreate event.This doesn't work, still apparently called *before* the content data is available as the contentData.getMimetype() line below throws an NPE. The Tika message (…detected by Tika as being…) also appears in the debug logs *after* the stack trace…
public void afterCommit() {
…
ContentData contentData = (ContentData) nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
String nodeMimeType = contentData.getMimetype();
…
}
Another way may be to trigger your code from addAspect. if your custom metadata has any custom properties then an aspect will be automatically created for your custom property. You could use that event to run your code.
06-15-2012 11:03 AM
06-15-2012 11:13 AM
Umm - so metadata is post commit as well. Which interface are you using?
Metadata extraction is an action which should be triggered by a rule. But currently it is (probably incorrectly) hard coded into half the public interfaces. To get ftp to extract meta-data define a rule.
09-24-2012 04:30 PM
09-24-2012 05:43 PM
package com.jgsullivan.myriad.alfresco.behaviors.template;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.executer.ContentMetadataExtracter;
import org.alfresco.repo.content.ContentServicePolicies;
import org.alfresco.repo.policy.Behaviour;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.transaction.TransactionListenerAdapter;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.service.cmr.repository.ContentData;
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.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Behavior that casts the node type to the appropriate Myriad model type
* based on the applied mime type.
* @author pjaromin
*
*/
public class ModelSetTypeBehavior extends TransactionListenerAdapter
implements ContentServicePolicies.OnContentUpdatePolicy {
private static final QName QNAME_ONCONTENTUPDATE = QName.createQName(NamespaceService.ALFRESCO_URI, "onContentUpdate");
private Behaviour onContentUpdate;
private PolicyComponent policyComponent;
private ServiceRegistry serviceRegistry;
private Map<String, String> mimeToModelTypeMap;
private Map<String, QName> qnameMap;
public void init() {
if (log().isDebugEnabled()) {
log().debug("Initializing Behavior");
}
this.onContentUpdate = new JavaBehaviour(this, "onContentUpdate", NotificationFrequency.FIRST_EVENT);
this.policyComponent.bindClassBehaviour(QNAME_ONCONTENTUPDATE, ContentModel.TYPE_CONTENT, onContentUpdate);
}
/*
* (non-Javadoc)
* @see org.alfresco.repo.content.ContentServicePolicies.OnContentUpdatePolicy#onContentUpdate(org.alfresco.service.cmr.repository.NodeRef, boolean)
*/
@Override
public void onContentUpdate(NodeRef nodeRef, boolean newContent) {
if (log().isDebugEnabled()) {
log().debug("onContentUpdate, new[" + newContent + "]");
}
NodeService nodeService = serviceRegistry.getNodeService();
ContentData contentData = (ContentData) nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
String nodeMimeType = contentData.getMimetype();
QName type = getQNameMap().get(nodeMimeType);
if (type != null) {
nodeService.setType(nodeRef, type);
// Extract meta-data here because it doen't happen automatically when imported through FTP (for example)
ActionService actionService = serviceRegistry.getActionService();
Action extractMeta = actionService.createAction(ContentMetadataExtracter.EXECUTOR_NAME);
actionService.executeAction(extractMeta, nodeRef);
}
else {
log().warn("No type configured for mimetype [" + nodeMimeType + "]");
}
}
/**
*
* @return
*/
private Map<String, QName> getQNameMap() {
if (qnameMap == null) {
qnameMap = new HashMap<String, QName>();
// Pre-resolve QNames…
for (Entry<String,String> e : mimeToModelTypeMap.entrySet()) {
QName qname = this.qnameFromMimetype(e.getKey());
if (qname != null) {
qnameMap.put(e.getKey(), qname);
}
}
}
return qnameMap;
}
/**
*
* @param mimeType
* @return
*/
private QName qnameFromMimetype(String mimeType) {
QName qname = null;
String qNameStr = mimeToModelTypeMap.get(mimeType);
qname = QName.createQName(qNameStr, serviceRegistry.getNamespaceService());
return qname;
}
public PolicyComponent getPolicyComponent() {
return policyComponent;
}
public void setPolicyComponent(PolicyComponent policyComponent) {
this.policyComponent = policyComponent;
}
public ServiceRegistry getServiceRegistry() {
return serviceRegistry;
}
public void setServiceRegistry(ServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry;
}
public void setMimeToModelTypeMap(Map<String, String> mimeToModelTypeMap) {
this.mimeToModelTypeMap = mimeToModelTypeMap;
}
public Map<String, String> getMimeToModelTypeMap() {
return mimeToModelTypeMap;
}
protected Log log() {
return LogFactory.getLog(this.getClass());
}
}
<!– –>
<!– ModelSetTypeBehavior –>
<!– –>
<bean id="model-behavior"
class="com.jgsullivan.myriad.alfresco.behaviors.template.ModelSetTypeBehavior"
init-method="init" depends-on="${artifactId}.dictionaryBootstrap">
<property name="policyComponent" ref="policyComponent" />
<property name="serviceRegistry" ref="ServiceRegistry" />
<property name="mimeToModelTypeMap">
<map>
<entry key="application/myriad-template-package"><value>myr:templatePackage</value</entry>
…multiple custom models here…
<entry key="application/x-font-ttf"><value>myr:font</value></entry>
</map>
</property>
</bean>
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.