ODocument attrObj = new ODocument(dao.USER_ATTRIBUTES_CLASS);
try{
if (nonAppUserAttributes!=null) attrObj.fromJSON(nonAppUserAttributes.toString());
else attrObj.fromJSON("{}");
}catch (OSerializationException e){
throw new InvalidJsonException (dao.ATTRIBUTES_VISIBLE_BY_ANONYMOUS_USER + " is not a valid JSON object",e);
}
PermissionsHelper.grantRead(attrObj, RoleDao.getRole(DefaultRoles.REGISTERED_USER.toString()));
PermissionsHelper.grantRead(attrObj, RoleDao.getRole(DefaultRoles.ANONYMOUS_USER.toString()));
PermissionsHelper.grantRead(attrObj, friendRole);
PermissionsHelper.changeOwner(attrObj,userRid );
profile.field(dao.ATTRIBUTES_VISIBLE_BY_ANONYMOUS_USER,attrObj);
attrObj.save();
}
/* these attributes are visible by:
* User
*/
{
ODocument attrObj = new ODocument(dao.USER_ATTRIBUTES_CLASS);
try{
if (privateAttributes!=null) attrObj.fromJSON(privateAttributes.toString());
else attrObj.fromJSON("{}");
}catch (OSerializationException e){
throw new InvalidJsonException (dao.ATTRIBUTES_VISIBLE_ONLY_BY_THE_USER + " is not a valid JSON object",e);
}
profile.field(dao.ATTRIBUTES_VISIBLE_ONLY_BY_THE_USER, attrObj);
PermissionsHelper.changeOwner(attrObj, userRid);
attrObj.save();
}
/* these attributes are visible by:
* Friends
* User
*/
{
ODocument attrObj = new ODocument(dao.USER_ATTRIBUTES_CLASS);
try{
if (friendsAttributes!=null) attrObj.fromJSON(friendsAttributes.toString());
else attrObj.fromJSON("{}");
}catch (OSerializationException e){
throw new InvalidJsonException (dao.ATTRIBUTES_VISIBLE_BY_FRIENDS_USER + " is not a valid JSON object",e);
}
PermissionsHelper.grantRead(attrObj, friendRole);
PermissionsHelper.changeOwner(attrObj, userRid);
profile.field(dao.ATTRIBUTES_VISIBLE_BY_FRIENDS_USER, attrObj);
attrObj.save();
}
/* these attributes are visible by:
* Registered user
* Friends
* User
*/
{
ODocument attrObj = new ODocument(dao.USER_ATTRIBUTES_CLASS);
try{
if (appUsersAttributes!=null) attrObj.fromJSON(appUsersAttributes.toString());
else attrObj.fromJSON("{}");
}catch (OSerializationException e){
throw new InvalidJsonException (dao.ATTRIBUTES_VISIBLE_BY_REGISTERED_USER + " is not a valid JSON object",e);
}
attrObj.field("_social",new HashMap());
PermissionsHelper.grantRead(attrObj, RoleDao.getRole(DefaultRoles.REGISTERED_USER.toString()));
PermissionsHelper.changeOwner(attrObj, userRid);
profile.field(dao.ATTRIBUTES_VISIBLE_BY_REGISTERED_USER, attrObj);
attrObj.save();
}
//system info
{
ODocument attrObj = new ODocument(dao.USER_ATTRIBUTES_CLASS);
attrObj.field(dao.USER_LOGIN_INFO, new ArrayList() );
attrObj.field(dao.USER_SIGNUP_DATE, signupDate==null?new Date():signupDate);
PermissionsHelper.changeOwner(attrObj, userRid);
profile.field(dao.ATTRIBUTES_SYSTEM, attrObj);
}
profile.field(dao.USER_SIGNUP_DATE, signupDate==null?new Date():signupDate);
//this is useful when you want to know if the username was automatically generated
profile.field(UserDao.GENERATED_USERNAME,generated);
PermissionsHelper.grantRead(profile, RoleDao.getRole(DefaultRoles.REGISTERED_USER.toString()));
PermissionsHelper.grantRead(profile, RoleDao.getRole(DefaultRoles.ANONYMOUS_USER.toString()));
PermissionsHelper.changeOwner(profile, userRid);
profile.save();
DbHelper.commitTransaction();
}catch( OSerializationException e ){
DbHelper.rollbackTransaction();
throw new InvalidJsonException(e);
}catch( InvalidJsonException e ){
DbHelper.rollbackTransaction();
throw e;
}catch( UserAlreadyExistsException e ){
DbHelper.rollbackTransaction();