Login

Username

Password





Register   Reset password

This is a read-only archive of the forum.

# D3grade 9/13/2007 5:56 PM
Hi Guys,

Like a few people, we have restructured Cuyahoga slightly to better suite our own needs, however we would like to integrate the ContentItem features currently being developed. I’ve been through the source in the trunk, and there seems to be fare few changes.

I was wondering if anyone could explain the changes, and how these are / are going to be used (ie the decorators and what not) as everything isn’t quite hooked up yet, so hard to get an overall understanding.

Any help is greatly appreciated.

Many thanks

Matt
# mgaerber 9/14/2007 8:29 AM
Hi,

it is supposed to server as base class for all business entities. Using the base class you will benefit from automatic/configurable functionality that is provided through the decorators.

1. Inherit from ContentItem
2. Let your business class implement some interfaces (ISearchable, IVersionable)
3. The ContentItemService class (or a custom version from you) offers methods (Save, Update, etc.) that then trigger the decorators to do their work.

So instead of doing:
myDaoClass.Save(myBusinessClass);
myVersioner.AddNewVersion(myBusinessClass);
myLogger.Log("Saved class xy");
...
you just do:
contentItemService.Save(myBusinessClass);

and the rest will happen behind the scenes.

Most other improvements (categories, search module, administration etc.) are somewhat independent from the ContentItem stuff.

Regards,

Max
# D3grade 9/14/2007 9:35 AM
Cheers Max,

That was very usefull. I'll have another run through it and see what i can make of it.

Many thanks

Matt
# D3grade 10/2/2007 5:19 PM
Ok, so as a quick learning example, i am trying to convert the static html module to use the content item class, and to use the ContentItemService to do the saving.

I've got StaticHtmlContent to inherit from ContentItem and have modified the hbm file after looking at how the FileResource one works, and also changed the cm_statichtml database table accordingly. Now if i don't use contentItemService this works fine, and content is entered into the database as expected.

However, if i change over to use the contentItemService by adding a reference in the modules constructor as follows:
ContentItemService< StaticHtmlContent> _contentItemService;

public StaticHtmlModule(ContentItemService< StaticHtmlContent> contentItemService)
{
      this._contentItemService = contentItemService;
}

And changing GetContent to the following:
public StaticHtmlContent GetContent()
		{
			if (base.Section != null)
			{
                IList< StaticHtmlContent> results = this._contentItemService.FindContentItemsBySection(this.Section);
				if (results.Count == 1)
				{
					return results[0];
				}
				else if (results.Count > 1)
				{
					throw new Exception("A request for StaticHtmlContent should only return one item");
				}
				else
				{
					return null;
				}
			}
			else
			{
				throw new Exception("Unable to get the StaticHtmlContent when no Section is available");
			}
		}

I get the following error:
Can't create component 'module.Cuyahoga.Modules.StaticHtml.StaticHtmlModule' as it has dependencies to be satisfied. 
module.Cuyahoga.Modules.StaticHtml.StaticHtmlModule is waiting for the following dependencies: 

Services: 
- Cuyahoga.Core.Service.Content.ContentItemService`1[[Cuyahoga.Modules.StaticHtml.StaticHtmlContent, Cuyahoga.Modules, Version=1.5.0.0, Culture=neutral, PublicKeyToken=null]] which was not registered. 

Can anyone tell me what i am doing wrong?
# D3grade 10/2/2007 6:20 PM (edited 10/2/2007 6:30 PM)
Ahh ha, found it.

I had programmed against the implementation of ContentItemService as apposed to the interface IContentItemService

It now seems to work fine, however the search decorator isn't firing.

Are the decorators meant to be applied automtatically? or do you apply them manually? If so, how?

Matt
# mgaerber 10/2/2007 8:40 PM (edited 10/2/2007 8:41 PM)
Whooa, you're really getting into the 2.0 code ;-)

As this is work in progress, there are no docs yet. But to answer your question:

To make use of the decorators your classes derived from ContentItem will have to implement interfaces (e.g. ISearchableContent in Core.Service.Search). So you would have
StaticHtmlContent : ContentItem, ISearchableContent

The decorators then check (e.g. for a save operation) if the ContentItem that is being handled has an interface the decorator can act upon.

Maybe you want to post your module code, so I can check if there are any other issues.

Regards,

Max

# mgaerber 10/2/2007 8:45 PM
Example class for use with the search decorator
using System;
using System.Text;
using System.Data;
using System.Collections;
using System.Collections.Generic;

using System.Xml.Serialization;

using Cuyahoga.Core.Domain;
using Cuyahoga.Core.Service.Search;

namespace Cuyahoga.Modules.Axxepta.Domain
{

	public class Company : ContentItem, ISearchableContent
	{
		private string companyFullName;
		private string companyShortName;
		private string companyKey;
		private string companyType;
		private string country;
        private Address address;
        private IList&lt;FileResource&gt; fileResources;

        public Company() : base(){ }


        #region Properties

        public virtual string CompanyFullName
		{
			get{ return companyFullName; }
			set{ companyFullName = value; }
		}

        public virtual string CompanyShortName
		{
			get{ return companyShortName; }
			set{ companyShortName = value; }
		}

        public virtual string CompanyKey
		{
			get{ return companyKey; }
			set
			{
				if(value != null && value.ToString() != string.Empty) 
				{
					companyKey = value;
				}
			}
		}

        public virtual string CompanyType
		{
			get{ return companyType; }
			set{ companyType = value; }
		}

        public virtual string Country
		{
			get{ return country; }
			set{ country = value; }
		}

        public virtual Address Address
        {
            get { return address; }
            set { address = value; }
        }

        public virtual IList&lt;FileResource&gt; FileResources
        {
            get { return this.fileResources; }
            set { this.fileResources = value; }
        }

        # endregion


        #region ISearchableContent Members

        public string ToSearchContent()
        {
            StringBuilder sb = new StringBuilder();
            //don't forget to add spaces after each term...
            sb.Append(this.companyFullName); sb.Append(" ");
            sb.Append(this.companyType); sb.Append(" ");
            sb.Append(this.address.Name1); sb.Append(" ");
            sb.Append(this.address.Name2); sb.Append(" ");
            sb.Append(this.address.Name3); sb.Append(" ");
            sb.Append(this.address.Street); sb.Append(" ");
            sb.Append(this.address.Zip); sb.Append(" ");
            sb.Append(this.address.Zipbox); sb.Append(" ");
            sb.Append(this.address.City); sb.Append(" ");
            sb.Append(this.address.Country); sb.Append(" ");

            return sb.ToString();
        }

        public IList&lt;CustomSearchField&gt; GetCustomSearchFields()
        {
            List&lt;CustomSearchField&gt; customFields = new List&lt;CustomSearchField&gt;();
            customFields.Add(new CustomSearchField("companyname", this.companyFullName, true, false));
            customFields.Add(new CustomSearchField("companycountry", this.country, true, false));

            return customFields;
        }

        #endregion
    }//end class
}//namespace
# D3grade 10/2/2007 9:50 PM
Hmmm, i'm positive i am implementing the ISearchableContent within the StaticHtmlContent class (i didn't post it orgionally as it was relivant to my first problem)

But you are saying that the decorators should automatically be applied then? (i thought this might be the case with the way the decorator chain was defined in the services.config)

If you can confirm this should be the case, then i will know the right things to debug.

Cheers

Matt
# D3grade 10/3/2007 1:09 PM
Ok, i have hit another problem which i beleive is to do with the joined-subclass.

If there is no content for my StaticHtmlModule in the database, when i hit save it is created fine, however if i am editing the content it does not update.

I've debugged the solution and everything says it is running fine, but the data just isn't updating.

Anyone got any ideas?

Matt
# mgaerber 10/3/2007 5:20 PM
Hmmm, i'm positive i am implementing the ISearchableContent within the StaticHtmlContent class (i didn't post it orgionally as it was relivant to my first problem)

But you are saying that the decorators should automatically be applied then? (i thought this might be the case with the way the decorator chain was defined in the services.config)

If you use the ContentitemService (or your own implementation of it) and your content implements ContentItem, ISearchableContent and the SearachDecorator is defined in services.config it *should* work.
If there is no content for my StaticHtmlModule in the database, when i hit save it is created fine, however if i am editing the content it does not update.

Could you post some code and error messages (if any).
# D3grade 10/3/2007 5:21 PM
Ok, i have solved the problem of why my search decorator wasn't firing. I'm not sure wether who wrote the search decorator was using .NET 1, but the search decorator class is not defined as public (which i belive is default in .NET 1 but not in 2).

Setting the decorator class to public does indeed fire the decorator, so that is one problem solved (after a few hours head scratching) however i still need to resolve my other problem with joined-subclasses.

I may have found a problem with the RebuildIndex page as it tries to get a list of ContentItems, however content items can't be instantiatied by themselves as they are abstract. If someone has any ideas on this aswell that would be great.

I do have one more request. As i am sure you can tell, i am spending a lot of time lateley trying to get contentitem and versioning and workflow working. If the main guys who are implementing this would like to get in touch, and offer more direct assistance i'll be happy to put some hours in to get this working how you invision it and put the code back into the community.

Many thanks

Matt
# D3grade 10/4/2007 10:11 AM (edited 10/4/2007 10:31 AM)
Ok, RE the SaveOrUpdate not updating. I posted on the NHibernate forum, and got a reply that led me down the following path.

If i change the SaveOrUpdate method of the ContentItemDao class from:
[Transaction(TransactionMode.Requires)]
public T SaveOrUpdate(T entity)
{
    this.GetNewSession().SaveOrUpdate(entity);
    return entity;
}

to:
[Transaction(TransactionMode.Requires)]
public T SaveOrUpdate(T entity)
{
    ISession session = this.GetNewSession();
    session.SaveOrUpdate(entity);
    session.Flush();
    return entity;
}

the update does occur, and the data is persisted.

Could someone let me know if this is a recomended way to go? or is something mis-configured?
# D3grade 10/4/2007 12:22 PM
I have also been trying to get assistance on this over at the NHibernate forums so if you want to see what has been said please take a look at

http://forum.hibernate.org/viewtopic.php?p=2366298

Based upon these comments, do we need to write a custom SessionManager that automatically flushes the session at the end of a request?
# mgaerber 10/5/2007 2:08 PM
Setting the decorator class to public does indeed fire the decorator, so that is one problem solved (after a few hours head scratching)
That's quite strange because for me it worked even without the public modifier. Could be some issue with the proxies. Anyway it was meant to be public.
I may have found a problem with the RebuildIndex page as it tries to get a list of ContentItems, however content items can't be instantiatied by themselves as they are abstract. If someone has any ideas on this aswell that would be great.
What would the problem be? ContentItems are meant to be subclassed and only those derived classes would occur.
I do have one more request. As i am sure you can tell, i am spending a lot of time lateley trying to get contentitem and versioning and workflow working. If the main guys who are implementing this would like to get in touch, and offer more direct assistance i'll be happy to put some hours in to get this working how you invision it and put the code back into the community.
Next week I am really busy but after that we could talk/mail about your issues more directly. It would be great to speed up development...
# D3grade 10/5/2007 8:20 PM
mgaerberWhat would the problem be? ContentItems are meant to be subclassed and only those derived classes would occur.

Hmmm, didn't seem to want to work for me. Will have to take another look at that one.
Next week I am really busy but after that we could talk/mail about your issues more directly. It would be great to speed up development...

That would be a great help.
# D3grade 11/28/2007 11:20 PM
D3gradeI have also been trying to get assistance on this over at the NHibernate forums so if you want to see what has been said please take a look at

http://forum.hibernate.org/viewtopic.php?p=2366298

Based upon these comments, do we need to write a custom SessionManager that automatically flushes the session at the end of a request?

Has anbody been able to look into this? (Max / Martjin)

You guys thought of using the OpenSessionInView pattern?
# D3grade 12/6/2007 11:17 PM
Anybody?
# martijnb 12/7/2007 1:20 PM
I'll ping Max about this, because he knows more about this subject than I do. He's probably very busy at the moment.
# mgaerber 12/7/2007 8:26 PM
Hi,

as the Hibernate forum posts point out - it's the responsibility of the Castle session manager to handle the session right. For me it never occured the way you described it but maybe we will have to check the SessionWebModule and see if there is something missing.

As well, there have been lots of updates of the referenced assemblies (nhibernate, castle etc.) and I am not up to date about possible (new) issues.

Regards,

Max
# scamp 2/20/2008 10:57 PM
I'm sure some one has figured this out by now. However, its still not fixed in the trunk, so i'd assume it's still an issue.

The ContentItemDao is missing a Castle.Services.Transaction.Transactional Attribute on the class itself. The Transaction Service will flush at the end of the transaction, but the attribute must be on the class for it to work.