Archive for December 2009
Normal Forms – Common Sense Intervenes?
There is an easy mnemonic that describes our usual goal of “third normal form”. Here it is:
What does this mean?
First Normal Form
If a relation contains no repeating groups, then it is in first normal form. Conversely, if we find that for a single primary key, we have two data items that we need to ‘squeeze’ into one column, then the data cannot be in first normal form. Let’s say that we’ve decided to slap together a database containing information about patients and the (medicinal) drugs they are taking. So we create a table with the following columns, including the primary key “Patient ID Number”:
| Patient ID Number | Patient Name | Drug | Trade Name | Formulation | Size | Dose | Frequency | Side Effect |
Let’s try filling in some information..
| Patient ID Number | Patient Name | Drug | Trade Name | Formulation | Size | Dose | Frequency | Side Effect |
| 6009315011076 | Soap,Joe | Carbimazole Carbamazepine |
Neomercazole Tegretol |
Tab Caps |
10mg 200mg |
30mg 200mg |
OD TDS |
Agranulocytosis nil |
| 6003325011074 | Green,Anne | Carbimazole | Neomercazole | Tab | 10mg | 10mg | OD | nil |
Woops. At the intersection of some rows and columns, we’ve had to fill in two different data items. It’s also obvious that there is considerable redundancy in the table – the drug Carbimazole (with all the associated information) is represented twice.
Fixing to First Normal Form
It should be clear that we can fix things by simply introducing a “composite primary key” – we can group the drug and the patient ID together as a composite primary key, so now each row has a unique primary key, and at no intersection of row and column do we have to put in two data items:
| Patient ID Number | Drug | Patient Name | Trade Name | Formulation | Size | Dose | Frequency | Side Effect |
| 6009315011076 | Carbimazole | Soap, Joe | Neomercazole | Tab | 10mg | 30mg | OD | Agranulocytosis |
| 6009315011076 | Carbamazepine | Soap, Joe | Tegretol | Caps | 200mg | 200mg | TDS | nil |
| 6003325011074 | Carbimazole | Green,Anne | Neomercazole | Tab | 10mg | 10mg | OD | nil |
Equally clearly, this is a clumsy fix, and really hasn’t changed much. We still have immense data redundancy. We need to go further to..
Second Normal Form
Note that, although the above table is now in ‘first normal form’, nothing much has changed. Look at the table carefully, and you’ll see that there are what we call partial dependencies. In other words, the columns Trade Name, Formulation, and Size depend only on the Drug component of the key, and not on the other part of the key, Patient ID Number. Likewise, the Patient Name depends only on the Patient ID Number, and is not dependent at all on the Drug column! To get rid of this problem, we create two new tables, a Patient Table:
| Patient | |
| Patient ID Number | Patient Name |
| 6009315011076 | Soap, Joe |
| 6003325011074 | Green,Anne |
and a Drug Table:
| Drug | |||
| Drug | Trade Name | Formulation | Size |
| Carbimazole | Neomercazole | Tab | 10mg |
| Carbamazepine | Tegretol | Caps | 200mg |
Finally, we relate the two in a diminished form of our original table, thus:
| PatientRx | ||||
| Patient ID Number | Drug | Dose | Frequency | Side Effect |
| 6009315011076 | Carbimazole | 30mg | OD | Agranulocytosis |
| 6009315011076 | Carbamazepine | 200mg | TDS | nil |
| 6003325011074 | Carbimazole | 10mg | OD | nil |
Third Normal Form
.. but still we’re not finished. Look at the last table carefully. There’s an intimate relationship between the the dose and the frequency of giving a drug. Here’s where knowledge of your subject comes in. Many people would be happy to stop at this point. There is no absolutely fixed rule that says you have to give your carbamazepine at a dose of 200mg TDS – in fact, if you’re religiously doing so, you’re probably mistreating a lot of your epileptics. But let’s say the whole point of our drug survey is to relate different drug regimens and associated side effect! In this context, we have a strong association between the dose and frequency of a drug. We call such a relationship between two non-key attributes a transitive dependency.
Third normal form is about removing transitive dependencies. How could we do this? Well, we could label each dose + frequency as a “regimen”, and proceed to break up the PatientRx table into two, thus:
| PatientRx | ||||
| Patient ID Number | Drug | Regimen | Side Effect | |
| 6009315011076 | Carbimazole | R1 | Agranulocytosis | |
| 6009315011076 | Carbamazepine | R3 | nil | |
| 6003325011074 | Carbimazole | R2 | nil | |
with a new DrugRegimen table:
| DrugRegimen | ||||
| Regimen | Dose | Frequency | ||
| R1 | 30mg | OD | ||
| R2 | 10mg | OD | ||
| R3 | 200mg | TDS | ||
Common Sense Intervenes?
A moment’s consideration will suggest that we could have done things several different ways!
- Firstly, what was to prevent us from lumping the drug, dose and frequency together in the DrugRegimen table? In many ways, this makes more sense. One’s never going to give carbamazepine in a dose of 10mg daily, or (heaven forbid!) carbimazole 200mg TDS, so it’s silly to have these sort of redundant options enshrined within our database! You can see the importance of knowing your subject, and not just blindly putting tables together. If we move drug name into the DrugRegimen table..
PatientRx Patient ID Number Regimen Side Effect 6009315011076 R1 Agranulocytosis 6009315011076 R3 nil 6003325011074 R2 nil with a new DrugRegimen table:
DrugRegimen Regimen Drug Dose Frequency R1 Carbimazole 30mg OD R2 Carbimazole 10mg OD R3 Carbamazepine 200mg TDS then we can immediately see that:
- The “Drug” column disappears from the PatientRx table;
- “Regimen” now becomes part of the composite primary key within the same table;
- In our first incarnation of PatientRx, where we had “Drug”, “Dose” and “Frequency” as columns, it’s probably more correct to regard “Dose” and “Frequency” as being dependent on “Drug” – a partial dependency that violates second normal form, rather than stressing their transitive dependency on one another (violating third normal form)! Nevertheless, one could still make a fairly strong case (based on their transitive dependency) for further dividing the DrugRegimen table into two tables, for example:
DrugRegimen Regimen Drug Dosing R1 Carbimazole D1 R2 Carbimazole D2 R3 Carbamazepine D3 DrugDosing Dosing Dose Frequency D1 30mg OD D2 10mg OD D3 200mg TDS Personally, I wouldn’t bother to do this last step, unless I was dealing with a whole lot of drugs that had similar dosing schedules. You can argue it both ways! This shows how, although there are a lot of hard rules in database design, a lot of what you do depends on an in-depth appreciation of the subjects you are dealing with, and what you want to get out of the database!
- Secondly, one could argue that in the PatientRx table, “Side Effect depends only on Regimen, so the table violates second normal form”. This is very much a personal opinion, but my contention would be that such an assertion is completely false, as there is an intimate relationship between the patient (and his/her unique metabolism), and the likelihood of a side effect occurring. Tricky, isn’t it?
- Thirdly, one should note that there is likely to be more than one side effect, in certain cases. So, just when we thought that we were home and dry, we find that our PatientRx table isn’t even in first normal form, all because we left an ‘s’ off the title of this column, and didn’t think hard enough!
A Summary of Normalisation
We can see the usefulness of our mnemonic Rule #3 – A datum should depend on a key, individual data items should depend on the whole key (not just part of the key, which would be a partial dependency), and nothing but the key (to avoid transitive dependencies).
What are the merits of such extensive normalisation (besides giving us a lot of little tables??). The merit of first normal form should be intuitively obvious, but what about second and third? Think about our example of first normal form. We could not insert a new drug into our database (say aspirin) until at least one of our patients was on aspirin. This insertion anomaly, and a host of other consequences besides the obvious redundancy, make second normal form a good idea. Likewise (after we’ve accepted that defining a drug regimen is a good idea, and decided that a regimen constitutes a particular dose and frequency), we cannot add a new drug regimen until we’ve normalised our tables to third normal form. Note that a lot depends on how we are actually using the data!
There are other ‘higher’ forms of normalisation, for even third normal form doesn’t guarantee that all ‘anomalies’ have been removed. Generally, we don’t often go beyond 3NF (third normal form), but here are a few ‘higher’ normal forms, just to whet your appetite!
- ‘Boyce-Codd Normal form’ – When there are alternate keys (there is more than one candidate key), a table may be in 3NF and anomalies may still result. This occurs when there is a composite primary key, and there are two equally valid candidates to make up part of this composite primary key. If there is an attribute (one or more columns) on which any other attribute is fully dependent, and this attribute is NOT itself a candidate key, then the table is not in Boyce-Codd Normal form (BCNF). We fix this by breaking the table up into two tables, both in BCNF.
(There is a special name for an attribute on which some other attribute is fully dependent – we call it a determinant.) - ‘Fourth Normal Form’ is even more tricky. Here the central concept is one of multivalued dependency – there are three attributes in a relation (let’s call them A, B and C), and although for each A there is a well-defined set of values for both B and C, nevertheless values in B and C are independent.
- We won’t even talk about “Fifth normal form” (join dependencies), and “Domain-Key normal form”.
Umbraco 4.0.3
For the first time on the Microsoft platform a free user and developer friendly cms that makes it quick and easy to create websites – or a breeze to build complex web applications. umbraco got award-winning integration capabilities and supports your ASP.NET User and Custom Controls out of the box. It’s a developers dream and your users will love it too. Used by more than 57.000 active websites including Heinz.com, Peugeot.com, NAIAS.com and Microsofts documentinteropinitiative.org website you can be sure that the technology is proven, stable and scales.
Key Features and Ratings
Core Technologies
Umbraco is a Microsoft.NET solution. It runs on Microsoft Windows Server 2003 and up against SQL Server 2005 or VistaDB.
Built on the .NET framework 2.0 and using ASP.NET 2.0 and C#, Umbraco supports .NET Custom Control and .NET User Controls without having to do anything special. Controls are added to Umbraco using Macros. It fully supports ASP.NET Ajax using jQuery, Prototype, MooTools or another Ajax toolkit.
It also fully supports ASP.NET Master Pages. XSLT is used for generating dynamic lists.
You have full access to the Umbraco API which includes over 15,000 lines of code. The API is well documented. The event model for the content engine is also exposed allowing you to automate tasks based on the actions of content editors.
Designing Templates/Look and Feel
Umbraco does not have a custom template engine, so you do not have learn a new templating language in order to create websites. This is a plus in our opinion. The Umbraco team believes there are better tools already out there, tools that designers know well and are comfortable using.
Umbraco Templates
For Umbraco, it’s as easy as designing your website in your favorite tool like Adobe Dreamweaver, then cut and paste the HTML code into the Umbraco template editor (in the Back Office) and then in the spots where you want your Umbraco data, insert an Umbraco field and save. When a page is rendered using the template, the content is dynamically displayed.
Umbraco Templates — Insert Page Field
Umbraco gives you 100% control over the design for your website. You don’t need to worry about themes or skinning, the design can be anything you want. Hartvig believes that themes and skinning is often a sign of bad separation of content, functionality and presentation.
Modify vs Customize
Like any open source content management solution, you are able to modify the source. But like the Umbraco folks say, that’s a big step to take and you run the risks of breaking future upgrades or breaking compatibility. Their motto instead is customize and extend, saying they have built every part of Umbraco to be extensible.
What About MVC?
Umbraco is heavily investigating the use of ASP.NET MVC — Microsoft’s newest framework for ASP.NET (see details here) — as an alternative for the front-end website. Hartvig says that the current engine is very close to the MVC model now.
Web Analytics
Umbraco does not have web analytics built-in. Hartvig believes analytics is not a trivial task and is best left to the experts. You can integrate any web analytics tool with Umbraco via web server plugins, access logs or JavaScript — think WebTrends and Google Analytics.
Content Entities
In Umbraco, the core or foundational concept is the Document Type.
Document Types describe the type of content that you can create in your website. Examples of Document Types include News Items, Articles, HomePage, SearchPage. Document Types are to Umbraco what content types are to another web cms and web pages are to another.
Document Types and IA
Understanding how Document Types work is the key to understanding Umbraco. Unfortunately, at first they are a bit confusing, because defining them is a mostly about modeling content but also a bit about the website’s information architecture.
This blend of concepts and the related implications threw us for a little turn. However, if you can get these concepts under your belt, then the rest of the system is much easier to understand.
When you create Document Types you are also outlining the rough structure for the website’s information architecture. Specifically, when you define a type, you must also specify where that type can live in the website’s structure. Down the road, content authors and manager will not be able to over-ride this.
To put this differently, when you define the type you aren’t exactly building the navigation, but you are placing limits on how the navigation can be defined.
In Umbraco, there’s no delineation between content (like individual articles) and webpages (like HomePage or Article List page). You create Document Types for each type of content whether it’s “real” content or a webpage with dynamic functionality and some metadata, etc. Hartvig says that this is a good thing and provides the flexibility needed when building a website.
In thinking about the blend of type definition and type usage it strikes us as a good model for small to mid-sized organizations with only one or a few authors and no “Editor” or “Administrator” to who controls the overall structure of the website. The initial system set up can be done by an expert and then the content managers can be left to their own devices and one need not fret that content instances will end up in the wrong place in the website.
For larger organizations it can also work, but if more powerful users want full control over the website’s information hierarchies, they might find the blend of type and location to be a source of frustration.
Creating Document Types
Document Types are like SQL database tables. You create the Type and then assign a number of properties to it, indicating what the format of each property can be (text, rich text, drop down, etc) and if that property is required. This is pretty standard stuff for content management systems.
For example, an Article Document Type means that you can create one or more articles for your website.
Umbraco — Creating a New Document Type
When you create a Document Type, you provide some basic information about it such as Name, Alias, Icon, thumbnail and description. The Icon is the image you see beside the content you create in the Content Section. The thumbnail gives you a quick view of what type of content you are creating when you create a new piece of content.
You can also indicate to have a template created automatically. All this does is create a template shell with the same name as the document type. You can actually have more than one template (view of the Document Type), but one is the default. The allowed templates section on the Info tab indicates which templates you can use for this Document Type.
Document Type Tabs
Sometimes you may have a lot of different properties for your content type. You can organize the way the content information is added by creating TABS for your document type. This is simply a way to organize the information you want to add without having everything listed on one single page. For example, you can have a tab for Core Content and one for MetaData.
Creating Properties
You define the properties for your Document Type in the Generic Properties tab and assign a TAB those properties will appear on.
Umbraco — Document Type Properties
Defining Structure
The Structure Tab for a Document Type lists the Document Types already created. Here you select the type of Document Types that can be created as child nodes under your Document Type.
The structure is really the navigation for your site. If you create a HomePage Document Type, then you would probably allow all other Document Types to be created under it. But if you were creating a News Summary Page Document Type, you would probably only want a News Item Document Type to be created under it.
Security
Umbraco’s security model is easy to understand. There are two parts to it. First, you can easily create users and roles in Umbraco.
Creating Users
When you create a user, you set up all the basics such as username, password, email, default language and role. In Umbraco, a user is assigned to one role only. You select what sections within the Back Office the user has access to and you can automatically redirect the user to Canvas Editing on log in, thus restricting them from the Back Office completely.
Umbraco — Creating a User
You can also restrict the area of content the user can work in by setting the Start Node in Content. If you set this node to something other than the top level, when the user logs in they only see the Content Navigation Tree from that Node down.
Umbraco — Restricting Content Access
Creating User Types
There are several User Types created by default in Umbraco: Writer, Editor, Translator, Reviewer. For each role, you specify the permissions for that role.
Umbraco — Creating a User Type
When a user is assigned to a specific User Type, their actions are limited to those set by the User Type:
Umbraco — Limiting Permissions by User Type
User Permissions
You can also set user permissions on individual pages.
Umbraco — Defining User Permissions
Membership
You also have the ability in Umbraco to create Members Only areas for your website. In the Members Section of the Back Office you can create Member Types like Basic, Silver and Gold, Member Groups and view the Members who are signed up.
You can full control here over how to format Membership.
To assign a section of your website as Members only, you right click on the particular section and select the Public Access Menu Item. You actually have two options here. The first is to assign a generic username and password to the selected content. The second to assign a Group or Groups.
Umbraco — Role Based Access Control
Content Versioning
Versioning of content entities is a core function of Umbraco. Every time you publish your content entity a new version is created and an audit trail is maintained. You can rollback to any version you want. There is no limit on the number of versions you have.
Umbraco — Content Versions with Visual Differences
When viewing a version of the content, you can view the difference between the current version and an older one. Content marked in red will not be shown if the version to rollback to is selected, content marked in green is new.
Also using Umbraco’s event model you can easily clean up old versions automatically, or you can use Umbraco’s free tools.
Workflow
Workflow is an interesting topic for Hartvig. He quotes James Robertson and Tony Byrne saying “workflow doesn’t work in practice”. That being said, you can implement workflow.
Out of the box, Umbraco includes the basics including the ability to restrict users and get notified on actions. Workflow is based on the permission model you set up in the Users section. For example, if you don’t allow Writers to have Publish permissions, then the Writer only has the ability to Save or Save and Send for Approval:
Umbraco — Simple Workflow Options
Note that the article has a little orange star, indicating it has not been published. As well, the right click menu does not offer the option to Publish, but to Send To Publish, which means sending for approval. There is also a button in the main window that you can click to send the article off for approval as well.
Notifications
The system does not automatically send out workflow notifications. One must subscribe to specific system events in order for this to happen. You can do this on a Site level, Section Level or Page level. You can also select which types of changes you want notification on (see list below).
Umbraco — Configuring Event Notifications
Notifications come by email:
Umbraco — Email Notification Example
This is a fairly straightforward and basic approach to providing workflow for your content. In addition, the event model is exposed which is meant to enable third-party integrations (e.g., workflow systems, translation automation, etc.). In speaking with Niels, he generally discourages the use of workflow unless it is absolutely needed. With that said, there are cases where it is absolutely needed.
Multi-Lingual Support
Umbraco ships with 15 languages for a localized back office user interface (UI). You can also add additional language if required.
The Umbraco UI text is stored in an XML file. This enables you to take a copy of the file and translate it for a new language. Once done, the language is automatically available.
Current languages include: English, French, Spanish (with variants), Dutch, Japanese, Chinese, Russian, Danish, Swedish, Norwegian and Greek.
There is a menu item on the Content Menu to Send to Translation. You must have a user assigned to the Translator role for this to work. This will send an email to the Translator.
Umbraco — Send Content for Translation
Editorial Capabilities
Umbraco refers to their Administration site as the Back Office. In the Back Office you can do a number of things, depending on your role and permissions: Manage Content, Media, Users and Members.
You can also manage Settings like style sheets, templates, scripts, dictionary, languages, media types and document types. Finally, there’s a developers section where you can do things like browse cache settings, manage data types, create and manage macros, packages, XSLT files and phyton files.
When you first log in, the opening dashboard is empty, but you are able to modify what is displayed in the dashboard through the use of dashboard controls.
These dashboard controls are basically .NET user controls that are added to the /config/dashboard.config file. There are a number of free community controls for things like New Content, Last Modified Content, Search, Viewing Log Files, etc.
You can even create tabs to organize your dashboard better.
Umbraco Back Office — Main Dashboard
Content Section
The content section is where your editors are going to live. Other than possibly the media section, it’s the only section they will likely have access to. It’s here that they can manage the website pages and content.
The tree structure in the left pane represents the structure of the website — the navigation. To create a new page you can simply right-click on the navigation item where you want the new page to live (i.e click on Home to have it live under Home) and then fill in the sections in the main window.
Note that depending on how you set up the Document Type the new webpage is based on, there may be multiple tabs to complete. You can save your new webpage, Save and Publish or Preview it.
Umbraco — Creating Content in the Back Office
When you create a new piece of content you can publish immediately or set a date sometime in the future. You can also set an archive date (Remove On).
In addition, you can change the default template that the content will be rendered in. Remember that you can only select a template that has been defined as allowed for that Document Type. These properties are automatic with every piece of content created.
Other options that can be added include hiding the page in navigation, setting up an Umbraco alias and set up redirects to another page. Again, these many of these are properties you have to set up.
The right-click menu in the Content Section gives you a number of options:
Umbraco Back Office — Content Right Click Menu
One option is to Edit in Canvas. This options enables you to view the website and edit in context:
Umbraco — Editing in Canvas Mode (In-context Editing)
External Blog Editor Integration
If you prefer to develop your content using an external editor, you can do that with Umbraco. Out of the box, Umbraco supports both Word 2007 and Windows Live Writer, but you can also use just about any blog editor that works with the MetaWeblog API.
There is a small catch to this capability and that is that you can only grant access to a specific section of your website using the Content Channels functionality.
URL Rewriting
If you don’t like having meaningless URL’s for your visitors (i.e index.aspx?id=3&pid=3932), consider URL Re-writing. With URL rewriting, you can store all your content in the database while having user-friendly URL’s. Here’s a code snippet to do just this:
void Application_BeginRequest(Object sender, EventArgs e)
{
String strCurrentPath;
String strCustomPath;
strCurrentPath = Request.Path;
strCurrentPath = strCurrentPath.ToLower();
// the URL contains this folder name
if (strCurrentPath.IndexOf( “/SomeSubFolder/” ) > -1)
{
strCustomPath = “getContent.aspx?id=” +
Path.GetFileNameWithoutExtension( strCurrentPath );
// rewrite the URL
Context.RewritePath( strCustomPath );
}
}
The getContent.aspx will take the page name as a parameter and do a lookup in the database and return the content for the page. I have left the details out because the point of the code snippet is to show how to rewrite the URL and get the data from the database.
Stack Over Flow Just Lovin’
I know I am probably about a year too late, but I have just stumbled on http://stackoverflow.com Man what a totally amazing site!! I asked a (Really dumb) question that I have wanted to know the answer to for a while and 58 seconds later I got two excellent answers – I’m just amazed I have only just found this. If like me you struggle to get your head round some of the more advanced ASP.NET stuff you see people like Haack and Mr Gu doing then just ask on http://stackoverflow.com!! Excellent resource and a really well written site, some very clever features and I think very clever algorithms for matching questions.
Hosting Umbraco Site > Development to Production
- UPLOAD UMBRACO
- Delete the default.aspx and web.config files in the WWWROOT folder at the host
- Upload the umbraco ZIP file to the wwwroot folder using the reliablesite.net FILE MANAGER found in the control panel
- Of course you can use FTP if you prefer, but the file manager has a full set of tools to make things easy without FTP
- UNPACK UMBRACO
- Use the FILE MANAGER in the hosting control panel to UNZIP the Umbraco archive
- SET PERMISSIONS
- Using the FILE MANAGER in the hosting control panel, change the folder permissions on the WWWROOT. Check the boxes for READ and WRITE for both listed accounts. One will be NETWORK SERVICE and the other will be the DOMAIN account. YOU MUST also check the box to propagate the changes to all subfolders
- NOTE: This is the only way I could get umbraco to work. I am sure that once umbraco is installed, there are certain folders that don’t need full permissions. I hope somebody can update this guide with best practices!
- CREATE THE DATABASE
- Use the DB manager to create a SQL server 2005 database.
- Name it something like mydomain_umbraco (where mydomain is somethign meaningful) because there is only 1 SQL server instance at the host and you will later need to be able to find your database in the list of databases presented in the Microsoft SQL Server Management Studio Express.
- Use the DB control panel to create a Database user and password.
- FIND THE DATABASE CONNECTION STRING
- click the “SPACE HOME” link in the control panel.
- At the “SPACE HOME” page, you will see a link on the right hand side of the page called “VIEW SPACE SUMMARY”.
- About 2/3 of the way down, the SPACE SUMMARY will show the database instance IP and port in the form x.x.x.x,x Make not of this, you will need it later.
- CONFIGURE THE DATABASE
- install SQL Server Management Studio Express on your local machine. This is part of MS SQL Server Express, a free download. See the this page for details
- open the Management Studio
- use the server address that you found above along with the db name and account credentials you created (use SQL SERVER AUTHENTICATION)
- navigate to Databases->your database->Security->Users->your database user
- right-click and select Properties
- below “Database role membership“, check the following boxes:
- db_datareader
- db_datawriter
- db_owner
- EDIT WEB.CONFIG
- Use the FILE MANAGER in the hosting control panel to edit the web.config file in the WWWROOT folder.
- modify the umbracoDbDSN entry in web.config to reflect the database server hostname, database name, login and password used above
- Note: You shouldn’t have to do this step as the web installer allows you to enter in your db settings and will modify the web.config for you depending on what option you choose.
- FINISH THE INSTALL
- Navigate to the website URL that your are installing to and click next
- on the setup screen, select SQL SERVER database type from the dropdown list
- Use the same SERVER address as used above, along with the database name and user credentials that you selected
101 High Quality CSS And XHTML Free Templates And Layouts: Part 1
Not Sure If all of these templates are free !!!
http://www.1stwebdesigner.com/resources/101-high-quality-css-and-xhtml-free-templates-and-layouts-part-1-2/