RSS

Monthly Archives: February 2013

Cannot Define Keys on Type Deriving From. Only Root Type in Entity Inheritance Hierarchy Can Contain Keys

This applies to ASP.NET Web API under MVC 4 and .Net 4.5

This error message is from ASP.NET Web API when I implemented using ODataConventionModelBuilder.

cannot-define-keys-on-type-deriving-from-only-root-type-in-entity-inheritance-hierarchy-can-contain-keys

GetEdmModel() is my ODdataConventionModelBuilder and what causing this is that I didn’t specify .DerivesFrom() on the type that inherit from others. In my case, Driver inherits from User.

To get around this, I have to include .DerivesFrom() in ODataConventionModelBuilder.

ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();

// Derived class must be specified.
modelBuilder.Entity<Driver>().DerivesFrom<User>();
modelBuilder.Entity<Customer>().DerivesFrom<User>();

// Exposed enitites to Odata
modelBuilder.EntitySet<User>("Users");

More on OData in Web API alpha release, “ODataConventionModelBuilder and inheritance”

Advertisements
 
1 Comment

Posted by on February 28, 2013 in General

 

Tags: , ,

FluentValidation: Implicit Required Attribute

In my ASP.NET MVC’s Add Implicit Required post, I encountered duplicate validations on same field that causing errors. Well, there’s another strange behavior after that issue was tackled.

This time, no error. But same problem.

Fluent Validation, a free validation framework that I use, also have implicit required attribute and it’s set to true by default. So, to configure it to false:


FluentValidationModelValidatorProvider.Configure(x =>
{
    x.ValidatorFactory =
        UnityConfig.UnityValidatorFactory();
    x.AddImplicitRequiredValidator = false;
});

ValidatorFactory is just dependency injection for FluentValidation. What set the implicit required to false is AddImplicitRequiredValidator.

 
Leave a comment

Posted by on February 28, 2013 in General

 

Tags: ,

AntiForgeryToken: A Claim of Type NameIdentifier or IdentityProvider Was Not Present on Provided ClaimsIdentity

This applies to ASP.Net MVC 4 and .Net 4.5

When converting ASP.NET MVC to Claims-aware app, I would get the following error:

A claim of type ‘http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier’ or ‘http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider’ was not present on the provided ClaimsIdentity. To enable anti-forgery token support with claims-based authentication, please verify that the configured claims provider is providing both of these claims on the ClaimsIdentity instances it generates. If the configured claims provider instead uses a different claim type as a unique identifier, it can be configured by setting the static property AntiForgeryConfig.UniqueClaimTypeIdentifier.

At default, ASP.NET MVC uses User.Identity.Name as anti-forgery token to validate form submitted. Worth to note that by default, ASP.NET MVC is not Claims-aware app.

When converting to Claims-aware app, ASP.NET MVC doesn’t use User.Identity.Name as the anti-forgery token anymore. Instead, it attempts to use the NameIdentifier and IdentityProvider ClaimType.

AntiForgeryConfig

One way to solve it is to set AntiForgeryConfig to use other ClaimType.

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();

    WebApiConfig.Register(GlobalConfiguration.Configuration);
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
    AuthConfig.RegisterAuth();

    AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.Email;
}

Add NameIdentifier and IdentityProvider ClaimTypes

Alternatively, you can add NameIdentifier and IdentityProvider ClaimTypes to your claims.

List<Claim> _claims = new List<Claim>();
_claims.AddRange(new List<Claim>
{
    new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", _user.Email)),
    new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", _user.Email)
});
 
7 Comments

Posted by on February 22, 2013 in General

 

Tags: , , ,

LINQ Select Distinct in Flat Data

Have a flat data schema, such as

</pre>
public class Account {
    public int ID {get;set;}
    public string Name {get;set;}
    public int UserID {get;set;}
}

If I have a list of this flat data, sometime it’s necessary to get unique data. This is how I go about doing it

var nonUnique = new List<Account>{
    new Account {
        ID = 1,
        Name = "A",
        UserID = 1
    },
    new Account {
        ID = 1,
        Name = "A",
        UserID = 2
    },
    new Account {
        ID = 2,
        Name = "B",
        UserID = 4
    }
};

var unique = (from m in nonUnique select new { Id = m.ID, Name = m.Name }).Distinct();

Console.Write(nonUnique);
Console.Write(unique);

unique variable contains distinct data of non-unique.

The output is following:

linq-select-distinct-in-flat-data

 
Leave a comment

Posted by on February 20, 2013 in General

 

Tags: ,

Validation Was Seen More Than Once: Implicit Required Attribute

I recently encountered a duplicate validation error in ASP.Net MVC. At first, this error is mystery to me because it still gave me exception error after I disabled ALL my validations.

validation-was-seen-more-than-once-implicit-required-attribute

Turns out, this is an easy fix. Root cause is by default MVC set AddImplicitRequiredAttributeForValueTypes property to true. This basically means validation is automatically performed on value type. In my case, I have CountryId as follow:

public class Country {
    public int CountryId { get; set; }
}

Since CountryId is not nullable, MVC add require validation for the property.

To fix this, you can either set your value type to nullable or set AddImplicitRequiredAttributeForValueTypes to false.

Nullable Value Type

Notice the int is now int?

public class Country {
    public int? CountryId { get; set; }
}

DataAnnotationsModelValidatorProvider

Set AddImplicitRequiredAttributeForValueTypes to false in your Global.asax.cs.

DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;

Resource: MSDN

 
1 Comment

Posted by on February 20, 2013 in General

 

Tags: ,

Bonita Windows Server Installation on Tomcat

Requirements

Installation Steps

  • Install JRE by clicking on the downloaded file.
  • Install JDK by clicking on the downloaded file.
  • Unzip Apache Tomcat file to a folder, use this path as <TOMCAT_HOME>.
  • Unzip Bonita Open Solution Deployment file to a folder. This folder is referenced as <BOS-5.9-DEPLOY> in the installation guides.
  • Follow this instruction:
    http://www.bonitasoft.com/resources/documentation/bos-59/system-administration/installation/install-bos-%E2%80%9C-scratch%E2%80%9D/install-bos-tomcat
    Notes:

    1. Skip “Download Tomcat” section.
    2. Skip “Download server files” section.
    3. Configure JAAS authentication and communication” section is not necessary if you are not using custom authentication. Follow this step if changes to JAAS authentication is required, for example, use LDAP for authentication.
    4. Configure BOS Tomcat for other databases” section is not necessary if you are not planning to use different database.
  • Add environment variable:
    1. Follow this instruction to add environment variables:
      http://technet.microsoft.com/en-us/library/cc736637(v=ws.10).aspx
    2. Value for “JRE_HOME” and “JAVA_HOME” depend on version of JRE and JDK you downloaded. Make sure the value reflect to folder where the installation is.
    3. Add JRE_HOME
      1. key: JRE_HOME
        value: C:\Program Files (x86)\Java\jre7
    4. Add JAVA_HOME
      1. key: JAVA_HOME
        value: C:\Program Files (x86)\Java\jdk1.7.0_13

Startup / Shutdown Tomcat

It’s necessary to startup / shutdown Tomcat in proper way before replacing / modify any file in <TOMCAT_HOME> folder.

To startup Tomcat

  • On command prompt, browse to <TOMCAT_HOME>\bin folder.
  • Run “startup.bat” file.

To shutdown Tomcat

  • On command prompt, browse to <TOMCAT_HOME>\bin folder.
  • Run “shutdown.bat” file.

Running Bonita User Experience

Bonita REST API

You can install Bonita REST API with the following step:

  • Copy <BOS-5.9-deploy>\bonita_execution_engine\interfaces\REST\with_execution_engine_without_client\bonita-server-rest.war
  • Paste the file into <TOMCAT_HOME>\webapps

Running Bonita REST API

If you need to use an REST client, you must have acknowledgement of the Bonita HTTP API. All HTTP requests will be done using the POST method.

All requests, except checkUserCredentials, checkUserCredentialsWithPasswordHash and getIdentityKeyFromTemporaryToken, will require authentication using HTTP Basic.

To generate your first REST API call, follow this step under “REST client“:

http://www.bonitasoft.org/blog/tutorial/how-to-use-the-bonita-http-api/

 
1 Comment

Posted by on February 14, 2013 in General

 

Tags: , , ,

Bonita (Pretty) Basic

Bonita is pretty! (pun intended)

Pretty Little Background

BonitaSoft is a company behind Bonita Open Solution, a powerful and scalable open source BPM software.

Bonita Open Solution is free and open source. You can even download the source code if you care.

If you ever wonder, they make money by providing training, consulting and subscription pack (SP) which is paid version of Bonita Open Solution (includes many other features not available in free version).

Download

Bonita Open Solution (contains Bonita Studio, Bonita Execution Engine and Bonita User Experience)
http://www.bonitasoft.com/products/BPM_downloads

Source Code
http://www.bonitasoft.org/websvn/

Requirements

Java Runtime Environment (JRE).
http://www.java.com/en/download/chrome.jsp?locale=en

Documentation

Official documentation
http://www.bonitasoft.com/resources/documentation/index.php

Community Support
This is another resource for support. You can find forums, blog, and various way to improve products (issue tracker, contribute to open source), etc.
http://www.bonitasoft.org/

Tutorials

For all Intro Tutorials (PDFs), you will need to login to download.
http://www.bonitasoft.com/resources/documentation/introduction-tutorials

Installation

Bonita Open Solution (contains Bonita Studio, Bonita Execution Engine and Bonita User Experience)
http://www.bonitasoft.com/products/BPM_downloads

 
Leave a comment

Posted by on February 14, 2013 in General

 

Tags: , ,

 
%d bloggers like this: