本文整理汇总了Java中org.ndexbio.model.object.Membership.setMemberUUID方法的典型用法代码示例。如果您正苦于以下问题:Java Membership.setMemberUUID方法的具体用法?Java Membership.setMemberUUID怎么用?Java Membership.setMemberUUID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ndexbio.model.object.Membership
的用法示例。
在下文中一共展示了Membership.setMemberUUID方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateMembershipAddMember
import org.ndexbio.model.object.Membership; //导入方法依赖的package包/类
@Test
public void updateMembershipAddMember() throws ObjectNotFoundException, NdexException {
User member = null;
try {
//localConnection.begin();
final NewUser newUser = new NewUser();
newUser.setEmailAddress("member");
newUser.setPassword("member");
newUser.setAccountName("member");
newUser.setFirstName("member");
newUser.setLastName("member");
member = userDAO.createNewUser(newUser,null);
//localConnection.commit();
Membership membership = new Membership();
membership.setMemberAccountName(member.getAccountName());
membership.setMemberUUID(member.getExternalId());
membership.setPermissions(Permissions.WRITE);
membership.setMembershipType(MembershipType.GROUP);
dao.updateMember(membership, testGroup.getExternalId(), testUser.getExternalId());
//localConnection.commit();
} catch(Exception e) {
fail(e.getMessage());
} finally {
userDAO.deleteUserById(member.getExternalId());
//localConnection.commit();
}
}
示例2: updateMembershipInvalidAdminChange
import org.ndexbio.model.object.Membership; //导入方法依赖的package包/类
@Test(expected = NdexException.class)
public void updateMembershipInvalidAdminChange() throws ObjectNotFoundException, NdexException {
Membership membership = new Membership();
membership.setMemberAccountName(testUser.getAccountName());
membership.setMemberUUID(testUser.getExternalId());
membership.setPermissions(Permissions.READ);
membership.setMembershipType(MembershipType.GROUP);
dao.updateMember(membership, testGroup.getExternalId(), testUser.getExternalId());
}
示例3: getUserGroupMemberships
import org.ndexbio.model.object.Membership; //导入方法依赖的package包/类
/**************************************************************************
* getUsergroupMemberships
*
* @param userId
* UUID for associated user
* @param permission
* Type of memberships to retrieve, ADMIN, WRITE, or READ
* @param skipBlocks
* amount of blocks to skip
* @param blockSize
* The size of blocks to be skipped and retrieved
* @throws NdexException
* Invalid parameters or an error occurred while accessing the
* database
* @throws ObjectNotFoundException
* Invalid userId
* @throws IOException
* @throws SQLException
* @throws IllegalArgumentException
* @throws JsonMappingException
* @throws JsonParseException
**************************************************************************/
public List<Membership> getUserGroupMemberships(UUID userId,
Permissions permission, int skipBlocks, int blockSize, boolean inclusive)
throws ObjectNotFoundException, NdexException, JsonParseException, JsonMappingException, IllegalArgumentException, SQLException, IOException {
String queryStr = "select gu.group_id, g.group_name, gu.is_admin from ndex_group_user gu, ndex_group g " +
" where gu.group_id = g.\"UUID\" and gu.user_id = ? ";
if ( permission == Permissions.GROUPADMIN) {
queryStr += " and gu.is_admin";
} else if ( permission == null || permission != Permissions.MEMBER)
throw new NdexException ("Valid permissions required in getUserGroupMembership function.");
else {
if ( !inclusive)
queryStr += " and gu.is_admin = false";
}
if ( skipBlocks>=0 && blockSize>0) {
queryStr += " limit " + blockSize + " offset " + skipBlocks * blockSize;
}
User user = getUserById(userId, true,false);
List<Membership> memberships = new ArrayList<>();
try (PreparedStatement st = db.prepareStatement(queryStr)) {
st.setObject(1, userId);
try (ResultSet rs = st.executeQuery() ) {
while (rs.next()) {
Membership membership = new Membership();
membership.setMembershipType(MembershipType.GROUP);
membership.setMemberAccountName( user.getUserName());
membership.setMemberUUID(userId);
membership.setPermissions(rs.getBoolean(3)? Permissions.GROUPADMIN : Permissions.MEMBER);
membership.setResourceName(rs.getString(2));
membership.setResourceUUID((java.util.UUID)rs.getObject(1));
memberships.add(membership);
}
}
}
return memberships;
}
示例4: getGroupNetworkMemberships
import org.ndexbio.model.object.Membership; //导入方法依赖的package包/类
/**************************************************************************
* getGroupNetworkMemberships
*
* @param groupId
* UUID for associated group
* @param permission
* Type of memberships to retrieve, GROUPADMIN or MEMBER
* @param skipBlocks
* amount of blocks to skip
* @param blockSize
* The size of blocks to be skipped and retrieved
**************************************************************************/
public List<Membership> getGroupNetworkMemberships(UUID groupId, Permissions permission, int skipBlocks, int blockSize, UUID userId, boolean inclusive)
throws ObjectNotFoundException, NdexException, JsonParseException, JsonMappingException, IllegalArgumentException, SQLException, IOException {
Preconditions.checkArgument(!Strings.isNullOrEmpty(groupId.toString()),
"A group UUID is required");
Preconditions.checkArgument( (permission.equals( Permissions.READ ))
|| (permission.equals( Permissions.WRITE )),
"Valid permissions required");
String permissionStr = "";
if ((permission.equals( Permissions.WRITE ) )) {
permissionStr = " and permission_type=\'" + Permissions.WRITE.toString() + "\'";
} else if ( permission != Permissions.READ ) {
throw new IllegalArgumentException("Valid permissions required.");
} else if ( !inclusive)
permissionStr = " and permission_type=\'" + Permissions.READ.toString() + "\'";
String sqlStr = "SELECT n.\"UUID\", n.name, gn.permission_type FROM group_network_membership gn, network n where gn.group_id = ? "+ permissionStr +
" and gn.network_id = n.\"UUID\" and " + NetworkDAO.createIsReadableConditionStr(userId) + " order by n.modification_time desc";
if ( skipBlocks>=0 && blockSize>0) {
sqlStr += " limit " + blockSize + " offset " + skipBlocks * blockSize;
}
Group group = getGroupById(groupId);
List<Membership> memberships = new ArrayList<>();
try (PreparedStatement st = db.prepareStatement(sqlStr)) {
st.setObject(1, groupId);
try (ResultSet rs = st.executeQuery() ) {
while (rs.next()) {
Membership membership = new Membership();
membership.setMembershipType( MembershipType.NETWORK );
membership.setMemberAccountName( group.getGroupName() );
membership.setMemberUUID( groupId );
membership.setPermissions( Permissions.valueOf(rs.getString(3)) );
membership.setResourceName( rs.getString(2) );
membership.setResourceUUID( (UUID) rs.getObject(1) );
memberships.add(membership);
}
}
}
return memberships;
}
示例5: getGroupUserMemberships
import org.ndexbio.model.object.Membership; //导入方法依赖的package包/类
/**************************************************************************
* getGroupUserMemberships
*
* @param groupId
* UUID for associated group
* @param permission
* Type of memberships to retrieve, ADMIN, WRITE, or READ
* @param skipBlocks
* amount of blocks to skip
* @param blockSize
* The size of blocks to be skipped and retrieved
* @throws NdexException
* Invalid parameters or an error occurred while accessing the database
* @throws ObjectNotFoundException
* Invalid groupId
* @throws IOException
* @throws SQLException
* @throws IllegalArgumentException
* @throws JsonMappingException
* @throws JsonParseException
**************************************************************************/
public List<Membership> getGroupUserMemberships(UUID groupId, Permissions permission, int skipBlocks, int blockSize, boolean inclusive)
throws ObjectNotFoundException, NdexException, JsonParseException, JsonMappingException, IllegalArgumentException, SQLException, IOException {
/* Preconditions.checkArgument( (permission.equals( Permissions.GROUPADMIN) )
|| (permission.equals( Permissions.MEMBER )),
"Valid permissions required"); */
String queryStr = "select user_id, is_admin, u.user_name from ndex_group_user gu, ndex_user u where u.\"UUID\" = gu.user_id and group_id = ?";
if ( permission != null) {
if ( permission == Permissions.GROUPADMIN)
queryStr += " and is_admin";
else {
if ( !inclusive) {
queryStr += " and is_admin = false";
}
}
}
if ( skipBlocks>=0 && blockSize>0) {
queryStr += " limit " + blockSize + " offset " + skipBlocks * blockSize;
}
Group group = getGroupById(groupId);
List<Membership> memberships = new ArrayList<>();
try (PreparedStatement st = db.prepareStatement(queryStr)) {
st.setObject(1, groupId);
try (ResultSet rs = st.executeQuery() ) {
while (rs.next()) {
Membership membership = new Membership();
membership.setMembershipType( MembershipType.GROUP );
membership.setMemberAccountName( rs.getString(3) );
membership.setMemberUUID( (UUID)rs.getObject(1) );
if (rs.getBoolean(2))
membership.setPermissions( Permissions.GROUPADMIN );
else
membership.setPermissions( Permissions.MEMBER );
membership.setResourceName( group.getGroupName() );
membership.setResourceUUID( groupId );
memberships.add(membership);
}
}
}
return memberships;
}
示例6: getNetworkUserMemberships
import org.ndexbio.model.object.Membership; //导入方法依赖的package包/类
/**************************************************************************
* getNetworkUserMemberships
*
* @param networkId
* UUID for network
* @param permission
* Type of memberships to retrieve, ADMIN, WRITE, or READ
* @param skipBlocks
* amount of blocks to skip
* @param blockSize
* The size of blocks to be skipped and retrieved
* @throws NdexException
* Invalid parameters or an error occurred while accessing the database
* @throws ObjectNotFoundException
* Invalid groupId
* @throws SQLException
**************************************************************************/
public List<Membership> getNetworkUserMemberships(UUID networkId, Permissions permission, int skipBlocks, int blockSize)
throws ObjectNotFoundException, NdexException, SQLException {
Preconditions.checkArgument(!Strings.isNullOrEmpty(networkId.toString()),
"A network UUID is required");
if ( permission !=null )
Preconditions.checkArgument(
(permission.equals( Permissions.ADMIN) )
|| (permission.equals( Permissions.WRITE ))
|| (permission.equals( Permissions.READ )),
"Valid permission required");
List<Membership> memberships = new ArrayList<>();
String sql = "select owneruuid as user_id, owner as user_name,name, 'ADMIN' from network where \"UUID\"=? and is_deleted=false";
if ( permission == null ) {
sql += " union select un.user_id, u.user_name, n.name, un.permission_type from user_network_membership un, network n, ndex_user u where u.\"UUID\" = un.user_id and "
+ "n.\"UUID\" = un.network_id and network_id = '" + networkId.toString() + "'";
}else if ( permission != Permissions.ADMIN)
sql = "select user_id, u.user_name, n.name, un.permission_type from user_network_membership un, network n, ndex_user u where u.\"UUID\" = un.user_id and n.\"UUID\" = un.network_id "
+ "and network_id = ? and un.permission_type = '" + permission.toString() + "'";
if ( skipBlocks>=0 && blockSize>0) {
sql += " limit " + blockSize + " offset " + skipBlocks * blockSize;
}
try ( PreparedStatement p = db.prepareStatement(sql)) {
p.setObject(1, networkId);
try ( ResultSet rs = p.executeQuery()) {
while ( rs.next()) {
Membership membership = new Membership();
membership.setMembershipType( MembershipType.NETWORK );
membership.setMemberAccountName( rs.getString(2) );
membership.setMemberUUID((UUID) rs.getObject(1) );
membership.setPermissions( Permissions.valueOf(rs.getString(4)));
membership.setResourceName(rs.getString(3) );
membership.setResourceUUID( networkId );
memberships.add(membership);
}
}
}
logger.info("Successfuly retrieved network-user memberships");
return memberships;
}
示例7: getGroupNetworkMemberships
import org.ndexbio.model.object.Membership; //导入方法依赖的package包/类
/**************************************************************************
* getGroupNetworkMemberships
*
* @param groupId
* UUID for associated group
* @param permission
* Type of memberships to retrieve, GROUPADMIN or MEMBER
* @param skipBlocks
* amount of blocks to skip
* @param blockSize
* The size of blocks to be skipped and retrieved
* @throws NdexException
* Invalid parameters or an error occurred while accessing the database
* @throws ObjectNotFoundException
* Invalid groupId
**************************************************************************/
public List<Membership> getGroupNetworkMemberships(UUID groupId, Permissions permission, int skipBlocks, int blockSize)
throws ObjectNotFoundException, NdexException {
Preconditions.checkArgument(!Strings.isNullOrEmpty(groupId.toString()),
"A group UUID is required");
Preconditions.checkArgument( (permission.equals( Permissions.ADMIN ))
|| (permission.equals( Permissions.READ ))
|| (permission.equals( Permissions.WRITE )),
"Valid permissions required");
ODocument group = this.getRecordByUUID(groupId, NdexClasses.Group);
final int startIndex = skipBlocks
* blockSize;
try {
List<Membership> memberships = new ArrayList<>();
String groupRID = group.getIdentity().toString();
OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<>(
"SELECT FROM"
+ " (TRAVERSE "+ NdexClasses.Group +".out_"+ permission.name().toString().toLowerCase() +" FROM"
+ " " + groupRID
+ " WHILE $depth <=1)"
+ " WHERE @class = '" + NdexClasses.Network + "' and ( " + NdexClasses.ExternalObj_isDeleted + " = false) "
+ " ORDER BY " + NdexClasses.ExternalObj_cTime + " DESC " + " SKIP " + startIndex
+ " LIMIT " + blockSize);
List<ODocument> records = this.db.command(query).execute();
for(ODocument member: records) {
Membership membership = new Membership();
membership.setMembershipType( MembershipType.NETWORK );
membership.setMemberAccountName( (String) group.field(NdexClasses.account_P_accountName) );
membership.setMemberUUID( groupId );
membership.setPermissions( permission );
membership.setResourceName( (String) member.field("name") );
membership.setResourceUUID( UUID.fromString( (String) member.field(NdexClasses.ExternalObj_ID) ) );
memberships.add(membership);
}
logger.info("Successfuly retrieved group-network memberships");
return memberships;
} catch(Exception e) {
logger.severe("An unexpected error occured while retrieving group-network memberships " + e.getMessage());
throw new NdexException("Unable to get network memberships for group with UUID "+groupId);
}
}
示例8: getGroupUserMemberships
import org.ndexbio.model.object.Membership; //导入方法依赖的package包/类
/**************************************************************************
* getGroupUserMemberships
*
* @param groupId
* UUID for associated group
* @param permission
* Type of memberships to retrieve, ADMIN, WRITE, or READ
* @param skipBlocks
* amount of blocks to skip
* @param blockSize
* The size of blocks to be skipped and retrieved
* @throws NdexException
* Invalid parameters or an error occurred while accessing the database
* @throws ObjectNotFoundException
* Invalid groupId
**************************************************************************/
public List<Membership> getGroupUserMemberships(UUID groupId, Permissions permission, int skipBlocks, int blockSize)
throws ObjectNotFoundException, NdexException {
Preconditions.checkArgument(!Strings.isNullOrEmpty(groupId.toString()),
"A group UUID is required");
Preconditions.checkArgument( (permission.equals( Permissions.GROUPADMIN) )
|| (permission.equals( Permissions.MEMBER )),
"Valid permissions required");
ODocument group = this.getRecordByUUID(groupId, NdexClasses.Group);
final int startIndex = skipBlocks
* blockSize;
try {
List<Membership> memberships = new ArrayList<>();
String groupRID = group.getIdentity().toString();
OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<>(
"SELECT FROM"
+ " (TRAVERSE "+ NdexClasses.Group +".in_"+ permission.name().toString().toLowerCase() +" FROM"
+ " " + groupRID
+ " WHILE $depth <=1)"
+ " WHERE @class = '" + NdexClasses.User + "' AND ( " + NdexClasses.ExternalObj_isDeleted + " = false) "
+ " ORDER BY " + NdexClasses.ExternalObj_cTime + " DESC " + " SKIP " + startIndex
+ " LIMIT " + blockSize);
List<ODocument> records = this.db.command(query).execute();
for(ODocument member: records) {
Membership membership = new Membership();
membership.setMembershipType( MembershipType.GROUP );
membership.setMemberAccountName( (String) member.field(NdexClasses.account_P_accountName) );
membership.setMemberUUID( UUID.fromString( (String) member.field(NdexClasses.ExternalObj_ID) ) );
membership.setPermissions( permission );
membership.setResourceName( (String) group.field(NdexClasses.GRP_P_NAME) );
membership.setResourceUUID( groupId );
memberships.add(membership);
}
logger.info("Successfuly retrieved group-user memberships");
return memberships;
} catch(Exception e) {
logger.severe("An unexpected error occured while retrieving group-user memberships "+e.getMessage());
throw new NdexException("Unable to get user memberships for group with UUID "+groupId);
}
}
示例9: getMembershipToNetwork
import org.ndexbio.model.object.Membership; //导入方法依赖的package包/类
public Membership getMembershipToNetwork(UUID groupId, UUID networkId)
throws IllegalArgumentException, ObjectNotFoundException, NdexException {
Preconditions.checkArgument(groupId != null, "UUID for group required");
Preconditions.checkArgument(networkId != null, "UUID for network required");
Permissions permission = null;
Membership membership = new Membership();
ODocument OGroup = this.getRecordByUUID(groupId, NdexClasses.Group);
ODocument ONetwork = this.getRecordByUUID(networkId, NdexClasses.Network);
// order allows us to return most permissive permission
if (checkPermission(OGroup.getIdentity(),
ONetwork.getIdentity(),
Direction.OUT,
1,
Permissions.READ))
permission = Permissions.READ;
if (checkPermission(OGroup.getIdentity(),
ONetwork.getIdentity(),
Direction.OUT,
1,
Permissions.WRITE))
permission = Permissions.WRITE;
if (checkPermission(OGroup.getIdentity(),
ONetwork.getIdentity(),
Direction.OUT,
1,
Permissions.ADMIN))
permission = Permissions.ADMIN;
membership.setMemberAccountName((String) OGroup.field("accountName"));
membership.setMemberUUID(groupId);
membership.setResourceName((String) ONetwork.field("name"));
membership.setResourceUUID(networkId);
membership.setPermissions(permission);
membership.setMembershipType(MembershipType.NETWORK);
return membership;
}
示例10: getUserNetworkMemberships
import org.ndexbio.model.object.Membership; //导入方法依赖的package包/类
/**************************************************************************
* getUserNetworkMemberships
*
* @param userId
* UUID for associated user
* @param permission
* Type of memberships to retrieve, ADMIN, WRITE, or READ
* @param skipBlocks
* amount of blocks to skip
* @param blockSize
* The size of blocks to be skipped and retrieved
* @throws NdexException
* Invalid parameters or an error occurred while accessing the
* database
* @throws ObjectNotFoundException
* Invalid userId
**************************************************************************/
public List<Membership> getUserNetworkMemberships(UUID userId,
Permissions permission, int skipBlocks, int blockSize)
throws ObjectNotFoundException, NdexException {
Preconditions.checkArgument(!Strings.isNullOrEmpty(userId.toString()),
"A user UUID is required");
Preconditions.checkArgument((permission == Permissions.ADMIN)
|| (permission == Permissions.READ)
|| (permission == Permissions.WRITE),
"Valid permissions required");
ODocument user = this.getRecordByUUID(userId, NdexClasses.User);
final int startIndex = skipBlocks * blockSize;
try {
List<Membership> memberships = new ArrayList<>();
String userRID = user.getIdentity().toString();
OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<>(
"SELECT FROM" + " (TRAVERSE out_"
+ Permissions.GROUPADMIN.name().toLowerCase()
+ ", out_"
+ permission.name().toString().toLowerCase()
+ " FROM" + " " + userRID + " WHILE $depth <=2)"
+ " WHERE @class = '" + NdexClasses.Network + "' and ( " + NdexClasses.ExternalObj_isDeleted +" = false) "
+ " ORDER BY " + NdexClasses.ExternalObj_cTime + " DESC " + " SKIP "
+ startIndex + " LIMIT " + blockSize);
List<ODocument> records = this.db.command(query).execute();
for (ODocument network : records) {
Membership membership = new Membership();
membership.setMembershipType(MembershipType.NETWORK);
membership.setMemberAccountName((String) user
.field("accountName"));
membership.setMemberUUID(userId);
membership.setPermissions(permission);
membership.setResourceName((String) network.field("name"));
membership.setResourceUUID(UUID.fromString((String) network
.field("UUID")));
memberships.add(membership);
}
logger.info("Successfuly retrieved user-network memberships");
return memberships;
} catch (Exception e) {
logger.severe("An unexpected error occured while retrieving user-network memberships");
throw new NdexException(e.getMessage());
}
}
示例11: getUserGroupMemberships
import org.ndexbio.model.object.Membership; //导入方法依赖的package包/类
/**************************************************************************
* getUsergroupMemberships
*
* @param userId
* UUID for associated user
* @param permission
* Type of memberships to retrieve, ADMIN, WRITE, or READ
* @param skipBlocks
* amount of blocks to skip
* @param blockSize
* The size of blocks to be skipped and retrieved
* @throws NdexException
* Invalid parameters or an error occurred while accessing the
* database
* @throws ObjectNotFoundException
* Invalid userId
**************************************************************************/
public List<Membership> getUserGroupMemberships(UUID userId,
Permissions permission, int skipBlocks, int blockSize)
throws ObjectNotFoundException, NdexException {
Preconditions.checkArgument(!Strings.isNullOrEmpty(userId.toString()),
"A user UUID is required");
Preconditions.checkArgument((permission.equals(Permissions.GROUPADMIN))
|| (permission.equals(Permissions.MEMBER)),
"Valid permissions required");
ODocument user = this.getRecordByUUID(userId, NdexClasses.User);
final int startIndex = skipBlocks * blockSize;
try {
List<Membership> memberships = new ArrayList<>();
String userRID = user.getIdentity().toString();
OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<>(
"SELECT FROM" + " (TRAVERSE " + NdexClasses.User + ".out_"
+ permission.name().toString().toLowerCase()
+ " FROM" + " " + userRID + " WHILE $depth <=1)"
+ " WHERE @class = '" + NdexClasses.Group + "' and ( " + NdexClasses.ExternalObj_isDeleted +" = false) "
+ " ORDER BY " + NdexClasses.ExternalObj_cTime + " DESC " + " SKIP "
+ startIndex + " LIMIT " + blockSize);
List<ODocument> records = this.db.command(query).execute();
for (ODocument group : records) {
Membership membership = new Membership();
membership.setMembershipType(MembershipType.GROUP);
membership.setMemberAccountName((String) user
.field("accountName"));
membership.setMemberUUID(userId);
membership.setPermissions(permission);
membership.setResourceName((String) group
.field(NdexClasses.GRP_P_NAME));
membership.setResourceUUID(UUID.fromString((String) group
.field("UUID")));
memberships.add(membership);
}
logger.info("Successfuly retrieved user-group memberships");
return memberships;
} catch (Exception e) {
logger.severe("An unexpected error occured while retrieving user-group memberships");
throw new NdexException(e.getMessage());
}
}
示例12: getMembership
import org.ndexbio.model.object.Membership; //导入方法依赖的package包/类
/**************************************************************************
* getMembership
*
* @param account
* UUID for user or group
* @param resource
* UUID for resource
* @throws NdexException
* Invalid parameters or an error occurred while accessing the
* database
* @throws ObjectNotFoundException
* Invalid userId
**************************************************************************/
public Membership getMembership(UUID account, UUID resource, int depth)
throws IllegalArgumentException, ObjectNotFoundException,
NdexException {
Preconditions.checkArgument(account != null, "Account UUID required");
Preconditions.checkArgument(resource != null, "Resource UUID required");
Preconditions.checkArgument(depth > 0 && depth < 3, "Depth range: [1,2]");
ODocument OAccount = this.getRecordByUUID(account, null);
ODocument OResource = this.getRecordByUUID(resource, null);
Permissions permission = null;
Membership membership = new Membership();
if (OResource.getClassName().equals(NdexClasses.Group)) {
if (checkPermission(OAccount.getIdentity(),
OResource.getIdentity(), Direction.OUT, depth,
Permissions.GROUPADMIN))
permission = Permissions.GROUPADMIN;
if (checkPermission(OAccount.getIdentity(),
OResource.getIdentity(), Direction.OUT, depth,
Permissions.MEMBER))
permission = Permissions.MEMBER;
membership.setMemberAccountName((String) OAccount
.field(NdexClasses.account_P_accountName));
membership.setMemberUUID(account);
membership.setResourceName((String) OResource
.field(NdexClasses.GRP_P_NAME));
membership.setResourceUUID(resource);
membership.setPermissions(permission);
membership.setMembershipType(MembershipType.GROUP);
} else {
// order allows us to return most permissive permission
if (checkPermission(OAccount.getIdentity(),
OResource.getIdentity(), Direction.OUT, depth,
Permissions.READ, Permissions.GROUPADMIN, Permissions.MEMBER))
permission = Permissions.READ;
if (checkPermission(OAccount.getIdentity(),
OResource.getIdentity(), Direction.OUT, depth,
Permissions.WRITE, Permissions.GROUPADMIN, Permissions.MEMBER))
permission = Permissions.WRITE;
if (checkPermission(OAccount.getIdentity(),
OResource.getIdentity(), Direction.OUT, depth,
Permissions.ADMIN, Permissions.GROUPADMIN, Permissions.MEMBER))
permission = Permissions.ADMIN;
membership.setMemberAccountName((String) OAccount
.field(NdexClasses.account_P_accountName));
membership.setMemberUUID(account);
membership.setResourceName((String) OResource.field("name"));
membership.setResourceUUID(resource);
membership.setPermissions(permission);
membership.setMembershipType(MembershipType.NETWORK);
}
if (permission != null)
return membership;
return null;
}
示例13: getNetworkUserMemberships
import org.ndexbio.model.object.Membership; //导入方法依赖的package包/类
/**************************************************************************
* getNetworkUserMemberships
*
* @param networkId
* UUID for network
* @param permission
* Type of memberships to retrieve, ADMIN, WRITE, or READ
* @param skipBlocks
* amount of blocks to skip
* @param blockSize
* The size of blocks to be skipped and retrieved
* @throws NdexException
* Invalid parameters or an error occurred while accessing the database
* @throws ObjectNotFoundException
* Invalid groupId
**************************************************************************/
public List<Membership> getNetworkUserMemberships(UUID networkId, Permissions permission, int skipBlocks, int blockSize)
throws ObjectNotFoundException, NdexException {
Preconditions.checkArgument(!Strings.isNullOrEmpty(networkId.toString()),
"A network UUID is required");
if ( permission !=null )
Preconditions.checkArgument(
(permission.equals( Permissions.ADMIN) )
|| (permission.equals( Permissions.WRITE ))
|| (permission.equals( Permissions.READ )),
"Valid permission required");
ODocument network = this.getRecordByUUID(networkId, NdexClasses.Network);
final int startIndex = skipBlocks
* blockSize;
List<Membership> memberships = new ArrayList<>();
String networkRID = network.getIdentity().toString();
String traverseCondition = null;
if ( permission != null)
traverseCondition = NdexClasses.Network +".in_"+ permission.name().toString();
else
traverseCondition = "in_" + Permissions.ADMIN + ",in_" + Permissions.READ + ",in_" + Permissions.WRITE;
OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<>(
"SELECT " + NdexClasses.account_P_accountName + "," +
NdexClasses.ExternalObj_ID + ", $path" +
" FROM"
+ " (TRAVERSE "+ traverseCondition.toLowerCase() +" FROM"
+ " " + networkRID
+ " WHILE $depth <=1)"
+ " WHERE (@class = '" + NdexClasses.User + "'"
+ " OR @class='" + NdexClasses.Group + "') " +" AND ( " + NdexClasses.ExternalObj_isDeleted + " = false) "
+ " ORDER BY " + NdexClasses.ExternalObj_cTime + " DESC " + " SKIP " + startIndex
+ " LIMIT " + blockSize);
List<ODocument> records = this.db.command(query).execute();
for(ODocument member: records) {
Membership membership = new Membership();
membership.setMembershipType( MembershipType.NETWORK );
membership.setMemberAccountName( (String) member.field(NdexClasses.account_P_accountName) );
membership.setMemberUUID( UUID.fromString( (String) member.field(NdexClasses.ExternalObj_ID) ) );
membership.setPermissions( Helper.getNetworkPermissionFromInPath ((String)member.field("$path") ));
membership.setResourceName( (String) network.field("name") );
membership.setResourceUUID( networkId );
memberships.add(membership);
}
logger.info("Successfuly retrieved network-user memberships");
return memberships;
}