Product SiteDocumentation Site

6.2. Formal attributes

Usually all attributes are formal attributes, in the sense that properties of a type are managed by PicketLink. In order to get them managed by PicketLink you need to annotate each property of your type with Section 3.5.1, “The @AttributeProperty Annotation”
If you take the User type as an example, you'll see that all its properties are defined as follows:
public class User extends Agent {

  @AttributeProperty
  private String firstName;

  @AttributeProperty
  private String lastName;

  @AttributeProperty
  private String email;

}
Formal attributes are strongly-typed as they are directly defined as properties in your type.
Those attributes are also queriable. Which means you can use the Query API to search for types with a specific property and value. If a property is queriable, we recommend to always create a QueryParameter constant as follows:
public class User extends Agent {

  /**
   * A query parameter used to set the firstName value.
   */
  public static final QueryParameter FIRST_NAME = QUERY_ATTRIBUTE.byName("firstName");

  /**
   * A query parameter used to set the lastName value.
   */
  public static final QueryParameter LAST_NAME = QUERY_ATTRIBUTE.byName("lastName");

  /**
   * A query parameter used to set the email value.
   */
  public static final QueryParameter EMAIL = QUERY_ATTRIBUTE.byName("email");

  @AttributeProperty
  private String firstName;

  @AttributeProperty
  private String lastName;

  @AttributeProperty
  private String email;

}
Once the query parameters are defined and mapped to your properties, you can search for types based on its properties as follows:
  IdentityQueryBuilder queryBuilder = identityManager.getQueryBuilder();
  IdentityQuery<User> query = queryBuilder.createIdentityQuery(User.class);

  query.where(queryBuilder.like(User.FIRST_NAME, "John%"));

  // find only by the first name
  List<User> result = query.getResultList();

  for (User user : result) {
    // do something
  }