configure the order of constraint execution on a field in hibernate with xml file - hibernate-validator

`this is my sample.xml files
<field name="userName">
<constraint annotation="org.hibernate.validator.constraints.NotBlank"/>
<constraint annotation="javax.validation.constraints.Size">
<element name ="min">1</element>
<element name ="max">20</element>
</constraint>
</field>`
if there is a way to configure the hibernate validator so that "Size" validations runs only if the NotBlank valditons falis and show validations messages only for the Size not correct.
here is the modifed xml
<bean class="User">
<field name="systemCode">
<constraint annotation="org.hibernate.validator.constraints.NotBlank">
<groups>
<value>UserNameNotBlank</value>
</groups>
</constraint>
<constraint annotation="javax.validation.constraints.Size">
<groups>
<value>UserNameSize</value>
</groups>
<element name="min">1</element>
<element name="max">4</element>
</constraint>
</field>
</bean>
what are the next steps the interfaces had been created is it possible to performing ordering on the field level or is it possible only on method level.
Note : please give the reference link where xml based configurations are there.

There is no order for constraint validation unless a group sequence is used. The spec says:
By default, constraints are evaluated in no particular order
regardless of which groups they belong to...
And a little further on
To implement such ordering, a group can be defined as a sequence of
other groups...
See also http://beanvalidation.org/1.1/spec/#constraintdeclarationvalidationprocess-groupsequence-groupsequence

Related

Custom record identifier using alfresco record management

Presently in alfresco records management Unique identifier is numeric number.
Need to customize the unique identifier to support alpha numeric.
I does support alpha numeric:
<property name="rma:identifier">
<title>Record Component Identifier</title>
<type>d:text</type>
<mandatory>true</mandatory>
<index enabled="true">
<atomic>true</atomic>
<stored>false</stored>
<tokenised>false</tokenised>
</index>
</property>
So you can update this property, create your own behaviour or extend the java class org.alfresco.module.org_alfresco_module_rm.identifier.BasicIdentifierGenerator
to define your own identifier.

is it possible to change a entity property doctrine type dynamically?

I have an entity property which is mapped to doctrine type text, its underling database column type is longtext in which different data will be saved into, such as int, text, custom doctrine type, I want to change its doctrine type dynamically , so that doctrine can handle data type automatically. for example,
<field name="value" column="value" type="text" />
this field will be feeding data form the text form field type, also a custom form type MoneyType, this form type will construct currency,amount into a Money object, I also customize a doctrine type called money , this will convert money to string vise versa, so I need to change this value field doctrine type depending on the data that is coming. is it possible to do this?
Just to be certain there is no misconfusion : to answer the question in your title, no you can not (to my knowledge) change dynamically a Doctrine entity type.
However, for your example, the solution may be to use data transformers. It will enable to change the data once it has been input by the user, and do whatever you want with it. In the absence of code, I can only encourage you to read this.
Hope this helps.

Solr index directory of files add file permissions from database

I'm using Solr to index a directory of pdf and word files. I want Solr to search these files but only return results based off a logged in user's permissions. Is it possible to index a directory of files as well as query a database containing the file permissions and add the data to the index as a xml entity and perform a filtered query on those results?
I am using WordPress as the CMS system with a file management plugin called Filebase. Filebase syncs with a directory to upload documents to the site. I have Solr configured to index the filebase directory containing the documents. Filebase has permissions that I set on each file.
My thought is if I can store the file's minimum user level position integer in the index I can then perform a filtered query to only display results with a user level of 'x'.
I hope this makes sense.
Yes, if you are on Solr 4+, you can push a Partial Update to Solr index.
SCHEMA
For partial update, all fields in your schema.xml need to be stored.
This is how your fields section should look like in schema.xml:
<fields>
<field name="id" type="string" indexed="true" stored="true" required="true" />
<field name="title" type="text_general" indexed="true" stored="true"/>
<field name="description" type="text_general" indexed="true" stored="true" />
<field name="body" type="text_general" indexed="true" stored="true"/>
<field name="permission" type="integer" indexed="true" stored="true" />
</fields>
INDEXING:
You can first index all documents(directory of pdf and word) to your index.
Then you can send a partial update to the permission field for a particular id.
When you send partial update, what actually happens in background is:
Solr will go and fetch values for all other fields for that document, such as title, description, body
Delete old document
Push new updated document to Solr index, with all existing fields as well as new permission field
Suppose you want to set permission=5 for document with id=document_1, your query should look like:
localhost:8080/solr/update?commit=true' -H 'Content-type:application/json' -d '[{"id":"document_1","permission":{"set":5}}]
Here is a good documentation on partial updates: http://solr.pl/en/2012/07/09/solr-4-0-partial-documents-update/

ASP.NET Memberships. Is it extensible?

I add the Property "WebSite" as a property of a registered user.
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="membershipSampleApp" type="System.Web.Profile.SqlProfileProvider"/>
</providers>
<properties>
<add name="Website"/>
</properties>
</profile>
Where is that custom property stored in the ASPNETDB database and can I query it to, for example, find all of the users that share the same value of a custom property?
If I want this sort of capability, would I be better off to augment the USERS table with my own parallel table and join the two on UserName as the key?
Yes, you can extend Membership. Here's a long article that explains how to do it. In a nutshell,
The idea behind extending the
Membership API is as follows:
I’ll create a new ExtendedMembershipUser class that inherits all the default properties from the MembershipUser,
and then I’ll add my own custom
properties...
For storing the values in the database, it describes a:
table I added to hold the values of
the custom properties and the
accompanying stored procedures that
the new ExtendedMembershipProvider
uses.
I'm not sure how you're using the "Website" property of the profile but if you have multiple websites using the same Membership store you'd be better off specifying different application names for each site, this was how multiple webs could use the same membership store.
If "Website" is just a property for the user by all means store it in the profile. It doesn't really warrant a rewrite of the membership provider.
Also, the "Website" property would be stored in the aspnet_Profiles table (as binary and XML), this can be difficult to query though. It might make more sense to have a custom profile provider that stores the properties in plain SQL format.
The default profiles implementation sacrifices discoverability for ease of use and flexibility.
If you would like to add indexable and queryable meta data to a user, I would recommend against extending the membership provider as that is not what they are for.
An excellent and easily implemented solution is to use a table based profile provider.
see http://weblogs.asp.net/scottgu/archive/2006/01/10/435038.aspx

Using ASP.NET SQL Membership Provider, how do I store my own per-user data?

I'm using the ASP.NET SQL Membership Provider. So, there's an aspnet_Users table that has details of each of my users. (Actually, the aspnet_Membership table seems to contain most of the actual data).
I now want to store some per-user information in my database, so I thought I'd just create a new table with a UserId (GUID) column and an FK relationship to aspnet_Users. However, I then discovered that I can't easily get access to the UserId since it's not exposed via the membership API. (I know I can access it via the ProviderUserKey, but it seems like the API is abstracting away the internal UserID in favor of the UserName, and I don't want to go too far against the grain).
So, I thought I should instead put a LoweredUserName column in my table, and create an FK relationship to aspnet_Users using that. Bzzzt. Wrong again, because while there is a unique index in aspnet_Users that includes the LoweredUserName, it also includes the ApplicationId - so in order to create my FK relationship, I'd need to have an ApplicationId column in my table too.
At first I thought: fine, I'm only dealing with a single application, so I'll just add such a column and give it a default value. Then I realised that the ApplicationId is a GUID, so it'd be a pain to do this. Not hard exactly, but until I roll out my DB I can't predict what the GUID is going to be.
I feel like I'm missing something, or going about things the wrong way. What am I supposed to do?
I think you are looking for the ProfileProvider which let's you associate any arbitrary information you wish with the user.
ASP.NET Profile Properties Overview
ADDITION If the built-in ProfileProvider will not suit your needs, then you might consider implementing your own ProfileProvider by writing a class that derives from System.Web.Profile.ProfileProvider. This would enable you to write something that avoids the serialization issues you mentioned in your comment.
Implementing a Profile Provider
ADDITION Note about the SqlMembershipProvider. You are indeed correct that the Membership classes are really keyed on username even though the schema is keyed on UserId. This is frankly one of my pet peeves about the SqlMembershipProvider classes. This actually creates problem in a multi-application environment where you want a single user store but independent application role lists.
My recommendation would be to key on UserId since it is, as you mentioned, the primary key of the aspnet_Users table and is used in all the foreign key relationships and it is a single value. If you key on LowerUsername (and ApplicationId), and the username changes, you'll need to have cascade update enabled so that the change ripples to your custom tables.
To do this, you can implement a profile provider. Its not very difficult. You will basically set up your user specific settings like this:
(web.config):
<profile enabled="true" defaultProvider="MyProvider">
<providers>
<add name="MyProvider" connectionStringName="MembershipCnnStr" applicationName="MyApp" type="System.Web.Profile.SqlProfileProvider"/>
</providers>
<properties>
<add name="EmployeeId" type="String" />
<group name="UserSettings">
<add name="IsSandboxMode" type="Boolean" defaultValue="false" />
<add name="Shortcuts" type="System.Collections.Generic.List`1[System.string]" />
</group>
</properties>
</profile>
If you're looking at adding simple data tied to your users, such as added profile properties, you should look into Personalization.
Example, if you want to store a person's mother's maiden name as a part of their profile information you can do so using this feature.
It probably isn't the right choice for complex data, but it's a start.
Write .cs file like
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
FirstNameTextBox.Text = Server.HtmlDecode(Profile.FirstName);
LastNameTextBox.Text = Server.HtmlDecode(Profile.LastName);
}
}
and web.config
<profile>
<providers>
<add name="FirstName" type="System.String"/>
<add name="LastName" type="System.String"/>
<add name="MemberId" defaultValue="0" type="System.Int32"/>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
</providers>
</profile>

Resources