* entity.
* @throws UserNotFoundException
*/
public Profile getProfile(String requestorJID, String targetJID) throws UserNotFoundException {
final EntityManager em = OswPlugin.getEmFactory().createEntityManager();
PersistentProfile profile = em.find(PersistentProfile.class, targetJID);
em.close();
if (profile != null) {
if (requestorJID.equals(targetJID)) {
return profile;
} else {
// We should filter all fields that the requestor is not
// supposed to see and strip all data related to ACLs.
final AclAction viewAction = aclFactory.aclAction(AclAction.ACTION_VIEW, AclAction.PERMISSION_GRANT);
List<Field> fields =profile.getFields();
List<Field> canSeefields= new ArrayList<Field>();
for (Field field: fields)
{
boolean canSee=false;
List<AclRule> rules= field.getAclRules();
//this is a patch, so that the profile and its fields can be retrieved even when the acl rules where not set...
// currently the vodafonernd.com DB has many profiles without any ACL rules, which retrieves empty profiles...
if (rules.isEmpty())
canSee=true;
for (AclRule rule: rules)
{
if ((rule.hasAction(viewAction)) && (AclManager.canSee(targetJID, rule, requestorJID)))
canSee=true;
}
if (canSee)
canSeefields.add(field);
}
profile.removeAll();
try{
for (Field f: canSeefields){
f.setAclRules(new ArrayList<AclRule>());
profile.addField(f);
}
}catch (CardinalityException ce){
}catch (UnsupportedFieldException ufe){
}
return profile;