12-16-2005 09:46 AM
public void init() {
// Create behaviours
onCreateObsoDate = new JavaBehaviour(this, "onCreateObsoDate");
onAddObsoDate = new JavaBehaviour(this, "onAddObsoDate");
onUpdateObsoDate = new JavaBehaviour(this, "onUpdateObsoDate");
QName ASPECT_OBSO = QName.createQName("http://www.toto.com/ged/obso", "obsolescence");
policyComponent.bindClassBehaviour(QName.createQName("http://www.toto.com/ged/obso", "onCreateNode"),ASPECT_OBSO, onCreateObsoDate);
policyComponent.bindClassBehaviour(QName.createQName("http://www.toto.com/ged/obso", "onAddAspect"), ASPECT_OBSO, onAddObsoDate);
policyComponent.bindClassBehaviour(QName.createQName("http://www.toto.com/ged/obso", "onUpdateNode"), ASPECT_OBSO, onUpdateObsoDate);
<model name="gc:obso_model" xmlns="http://www.alfresco.org/model/dictionary/1.0">
<description>custom Model for obsolescence date (GED-2)</description>
<author></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>
<namespaces>
<!– Define a Namespace for my new definitions –>
<namespace uri="http://www.toto.com/ged/obso" prefix="gc"/>
</namespaces>
<!– Type and Aspect definitions go here –>
<types/>
<aspects>
<aspect name="gc:obsolescence">
<title>Date d'obsolescence</title>
<properties>
<property name="gc:obso_date">
<type>d:date</type>
</property>
</properties>
</aspect>
</aspects>
</model>
01-12-2006 11:17 AM
policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateNode"),ASPECT_OBSO, onCreateObsoDate);
onCreateObsoDate = new JavaBehaviour(this, "onCreateObsoDate");
12-16-2005 01:24 PM
12-16-2005 01:44 PM
public void init() {
// Create behaviours
onCreateObsoDate = new JavaBehaviour(this, "onCreateObsoDate");
onAddObsoDate = new JavaBehaviour(this, "onAddObsoDate");
onUpdateObsoDate = new JavaBehaviour(this, "onUpdateObsoDate");
QName ASPECT_OBSO = QName.createQName("http://www.toto.com/ged/obso", "obsolescence");
policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateNode"),ASPECT_OBSO, onCreateObsoDate);
policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"), ASPECT_OBSO, onAddObsoDate);
policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onUpdateNode"), ASPECT_OBSO, onUpdateObsoDate);
12-19-2005 05:32 AM
<model name="gc:obso_model" xmlns="http://www.alfresco.org/model/dictionary/1.0">
<description>theypayme custom Model for obsolescence date (GED-2)</description>
<author></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>
<namespaces>
<!– Define a Namespace for my new definitions –>
<namespace uri="http://www.theypayme.com/ged/obso" prefix="gc"/>
</namespaces>
<!– Type and Aspect definitions go here –>
<types/>
<aspects>
<aspect name="gc:obsolescence">
<title>Date d'obsolescence</title>
<properties>
<property name="gc:obso_date">
<type>d:date</type>
</property>
</properties>
</aspect>
</aspects>
</model>
package com.theypayme.ged.aspects;
import java.util.Calendar;
import java.util.Date;
import org.alfresco.repo.policy.Behaviour;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.policy.PolicyScope;
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.cmr.repository.StoreRef;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class ObsolescenceDateAspect {
private static final Log logger = LogFactory.getLog(ObsolescenceDateAspect.class);
// Dependencies
private PolicyComponent policyComponent;
private NodeService nodeService;
private AuthenticationService authenticationService;
private Behaviour onCreateObsoDate;
private Behaviour onAddObsoDate;
private Behaviour onUpdateObsoDate;
public ObsolescenceDateAspect(){
logger.error("In ObsolescenceDateAspect constructor !") ;
// put a breakpoint here to check your aspect is registered at server start
}
public void init()
{
// Create behaviours
onCreateObsoDate = new JavaBehaviour(this, "onCreateObsoDate");
onAddObsoDate = new JavaBehaviour(this, "onAddObsoDate");
onUpdateObsoDate = new JavaBehaviour(this, "onUpdateObsoDate");
QName ASPECT_OBSO = QName.createQName("http://www.theypayme.com/ged/obso", "obsolescence");
policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateNode"),ASPECT_OBSO, onCreateObsoDate);
policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"), ASPECT_OBSO, onAddObsoDate);
policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onUpdateNode"), ASPECT_OBSO, onUpdateObsoDate);
}
/**
* Maintain audit properties on creation of Node
*
* @param childAssocRef the association to the child created
*/
public void onCreateObsoDate(ChildAssociationRef childAssocRef)
{
NodeRef nodeRef = childAssocRef.getChildRef();
onAddObsoDate(nodeRef, null);
}
/**
* Maintain audit properties on addition of audit aspect to a node
*
* @param nodeRef the node to which auditing has been added
* @param aspect the aspect added
*/
public void onAddObsoDate(NodeRef nodeRef, QName aspect)
{
try
{
onUpdateObsoDate.disable();
// Set created / updated date
Date now = createDate();
nodeService.setProperty(
nodeRef,
QName.createQName("http://www.theypayme.com/ged/obso", "obso_date"),
now
);
}
finally
{
onUpdateObsoDate.enable();
}
}
private Date createDate(){
Calendar cal = Calendar.getInstance() ;
cal.add( Calendar.YEAR, 2 );
return cal.getTime() ;
}
/**
* Maintain audit properties on update of node
*
* @param nodeRef the updated node
*/
public void onUpdateObsoDate(NodeRef nodeRef)
{
// Set updated date
Date now = createDate();
nodeService.setProperty(
nodeRef,
QName.createQName("http://www.theypayme.com/ged/obso", "obso_date"),
now
);
}
public AuthenticationService getAuthenticationService() {
return authenticationService;
}
public void setAuthenticationService(AuthenticationService authenticationService) {
this.authenticationService = authenticationService;
}
public NodeService getNodeService() {
return nodeService;
}
public void setNodeService(NodeService nodeService) {
this.nodeService = nodeService;
}
public PolicyComponent getPolicyComponent() {
return policyComponent;
}
public void setPolicyComponent(PolicyComponent policyComponent) {
this.policyComponent = policyComponent;
}
}
<bean
id="obsolescenceAspect"
class="com.globecast.ged.aspects.ObsolescenceDateAspect"
init-method="init"
>
<property name="nodeService">
<ref bean="nodeService" />
</property>
<property name="policyComponent">
<ref bean="policyComponent" />
</property>
<property name="authenticationService">
<ref bean="authenticationService" />
</property>
</bean>
01-12-2006 10:11 AM
01-12-2006 11:17 AM
policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateNode"),ASPECT_OBSO, onCreateObsoDate);
onCreateObsoDate = new JavaBehaviour(this, "onCreateObsoDate");
01-12-2006 11:25 AM
01-12-2006 04:14 PM
package com.tsgrp.alfresco.aspects;
import java.util.StringTokenizer;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.policy.Behaviour;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
/**
* Aspect that enables a content item to be subscribed to.
* Upon update of the content item, all subscribers will be notified.
*
* @author Ryan Berg (rberg@tsgrp.com)
* @version 1.0
*/
public class SubscribeableAspect
{
// Logger
private static final Log logger = LogFactory.getLog(SubscribeableAspect.class);
// Unknown user, for when authentication has not occured
private static final String USERNAME_UNKNOWN = "unknown";
// Custom QNames
private static final QName ASPECT_SUBSCRIBEABLE = QName.createQName("http://www.tsgrp.com/alfresco/model/1.0", "subscribeable");
private static final QName PROP_SUBSCRIBERS = QName.createQName("http://www.tsgrp.com/alfresco/model/1.0", "subscribers");
// Dependencies
private NodeService nodeService;
private AuthenticationService authenticationService;
private PolicyComponent policyComponent;
private JavaMailSender mailSender;
// Behaviours
private Behaviour onUpdateSubscribeable;
/**
* @param nodeService the node service to use for audit property maintenance
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @param policyComponent the policy component
*/
public void setPolicyComponent(PolicyComponent policyComponent)
{
this.policyComponent = policyComponent;
}
/**
* @param authenticationService the authentication service
*/
public void setAuthenticationService(AuthenticationService authenticationService)
{
this.authenticationService = authenticationService;
}
/**
* @param mailSender The JavaMailSender to set.
*/
public void setMailSender(JavaMailSender mailSender)
{
this.mailSender = mailSender;
}
/**
* Initialise the Auditable Aspect
*/
public void init()
{
// Create behaviours
onUpdateSubscribeable = new JavaBehaviour(this, "onUpdateSubscribeable");
// Bind behaviours to node policies
policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onUpdateNode"), ASPECT_SUBSCRIBEABLE, onUpdateSubscribeable);
}
/**
* Maintain audit properties on update of node
*
* @param nodeRef the updated node
*/
public void onUpdateSubscribeable(NodeRef nodeRef)
{
String subscribers = (String)nodeService.getProperty(nodeRef, PROP_SUBSCRIBERS);
String modifier = getUsername();
NotificationInfo info = new NotificationInfo(modifier, nodeRef);
StringTokenizer st = new StringTokenizer(subscribers, ",");
while(st.hasMoreTokens())
{
notifySubscriber(st.nextToken(), info);
}
if (logger.isDebugEnabled())
logger.debug("Subscribeable node " + nodeRef + " updated [notified=" + subscribers + "]");
}
/**
* @return the current username (or unknown, if unknown)
*/
private String getUsername()
{
String currentUserName = authenticationService.getCurrentUserName();
if (currentUserName != null)
{
return currentUserName;
}
return USERNAME_UNKNOWN;
}
/**
* Send an e-mail to a subscriber
* @param subscriber - email address of subscriber
* @param info - notification information
*/
private void notifySubscriber(String subscriber, NotificationInfo info)
{
SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
simpleMailMessage.setTo(subscriber);
simpleMailMessage.setSubject("*** Alfresco Subscription Alert: " + info.getName());
StringBuilder buf = new StringBuilder(256);
buf.append("An item you are subscribed to has been modified.\r\n\r\n");
buf.append("PATH: " + info.getPath() + "/" + info.getName() + "\r\n");
buf.append("MODIFIED BY: " + info.getModifier() + "\r\n");
simpleMailMessage.setText(buf.toString());
simpleMailMessage.setFrom("rberg@tsgrp.com");
try
{
// Send the message
this.mailSender.send(simpleMailMessage);
}
catch (Throwable e)
{
// don't stop the action but let admins know email is not getting sent
logger.error("Failed to send subscription alert email to " + subscriber, e);
}
}
/**
* Simple class which contains the notification information.
* Data member values are initialized by passing the node reference
* into the constructor.
*/
private class NotificationInfo
{
private String modifier;
private String name;
private String path;
public NotificationInfo(String modifier, NodeRef nodeRef)
{
setModifier(modifier);
setName((String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME));
setPath((String)nodeService.getPath(nodeRef).toDisplayPath(nodeService));
}
private void setModifier(String modifier)
{
this.modifier = modifier;
}
public String getModifier()
{
return modifier;
}
private void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
private void setPath(String path)
{
this.path = path;
}
public String getPath()
{
return path;
}
}
}
01-16-2006 07:01 AM
List notifications = AlfrescoTransactionSupport.getResource("SubscribeableAspect.notifications");
if (notifications == null)
{
notifications = new List();
AlfrescoTransactionSupport.bindResource("SubscribeableAspect.notification", notifications);
}
AlfrescoTransactionSupport.bindListener(this);03-17-2006 03:53 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.