当前位置: 首页>>代码示例>>Java>>正文


Java Membership类代码示例

本文整理汇总了Java中org.ndexbio.model.object.Membership的典型用法代码示例。如果您正苦于以下问题:Java Membership类的具体用法?Java Membership怎么用?Java Membership使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Membership类属于org.ndexbio.model.object包,在下文中一共展示了Membership类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getGroupNetworkMemberships

import org.ndexbio.model.object.Membership; //导入依赖的package包/类
/**************************************************************************
 * Retrieves array of network membership objects
 * 
 * @param groupId
 *            The group ID.
 * @throws IllegalArgumentException
 *             Bad input.
 * @throws ObjectNotFoundException
 *             The group doesn't exist.
 * @throws NdexException
 *             Failed to query the database.
 * @throws SQLException 
 * @throws IOException 
 * @throws JsonMappingException 
 * @throws JsonParseException 
 **************************************************************************/

@GET
@PermitAll
@Path("/{groupid}/network/{permission}/{start}/{size}")
@Produces("application/json")
@ApiDoc("Return a list of network membership objects which the given group have direct permission to. ")
public List<Membership> getGroupNetworkMemberships(@PathParam("groupid") final String groupIdStr,
		@PathParam("permission") final String permissions ,
		@PathParam("start") int skipBlocks,
		@PathParam("size") int blockSize,
		@DefaultValue("false") @QueryParam("inclusive") boolean inclusive) throws NdexException, SQLException, JsonParseException, JsonMappingException, IllegalArgumentException, IOException {
	
	Permissions permission = Permissions.valueOf(permissions.toUpperCase());
	UUID groupId = UUID.fromString(groupIdStr);
	
	try (GroupDAO dao = new GroupDAO()){
//		if ( !dao.isInGroup(groupId, getLoggedInUserId()))
//			throw new NdexException("User is not a member of this group.");
		List<Membership> l = dao.getGroupNetworkMemberships(groupId, permission, skipBlocks, blockSize, getLoggedInUserId(), inclusive);
		return l;
	}
}
 
开发者ID:ndexbio,项目名称:ndex-rest,代码行数:39,代码来源:GroupService.java

示例2: getGroupUserMemberships

import org.ndexbio.model.object.Membership; //导入依赖的package包/类
/**************************************************************************
 * Retrieves array of user membership objects
 * 
 * @param groupId
 *            The group ID.
 * @throws IllegalArgumentException
 *             Bad input.
 * @throws ObjectNotFoundException
 *             The group doesn't exist.
 * @throws NdexException
 *             Failed to query the database.
 * @throws SQLException 
 * @throws IOException 
 * @throws JsonMappingException 
 * @throws JsonParseException 
 **************************************************************************/

@GET
@Path("/{groupId}/user/{permission}/{skipBlocks}/{blockSize}")
@Produces("application/json")
@ApiDoc("")
public List<Membership> getGroupUserMemberships(@PathParam("groupId") final String groupIdStr,
		@PathParam("permission") final String permissions ,
		@PathParam("skipBlocks") int skipBlocks,
		@PathParam("blockSize") int blockSize,
		@DefaultValue("false") @QueryParam("inclusive") boolean inclusive) throws NdexException, SQLException, JsonParseException, JsonMappingException, IllegalArgumentException, IOException {

	Permissions permission = Permissions.valueOf(permissions.toUpperCase());
	UUID groupId = UUID.fromString(groupIdStr);
	
	try (GroupDAO dao = new GroupDAO()){
	/*	if ( ! dao.isInGroup(groupId, getLoggedInUserId())) {
			throw new NdexException("User has to be a member of this group.");
		} */
		List<Membership> l = dao.getGroupUserMemberships(groupId, permission, skipBlocks, blockSize, inclusive);
		return l;
	} 
}
 
开发者ID:ndexbio,项目名称:ndex-rest,代码行数:39,代码来源:GroupService.java

示例3: getUserNetworkMemberships

import org.ndexbio.model.object.Membership; //导入依赖的package包/类
/**************************************************************************
 * Retrieves array of network membership objects
 * 
 * @param userId
 *            The user ID.
 * @throws IllegalArgumentException
 *             Bad input.
 * @throws ObjectNotFoundException
 *             The group doesn't exist.
 * @throws NdexException
 *             Failed to query the database.
 * @throws SQLException 
 * @throws IOException 
 * @throws JsonMappingException 
 * @throws JsonParseException 
 **************************************************************************/

@GET
@Path("/network/{permission}/{start}/{size}")
@Produces("application/json")
@ApiDoc("Get a list of memberships which contains networks that this this user has explicit permissions on. The result includes permissions directly"
		+ " and in-directly ( through groups) granted to this user. ")
//TODO: need to review the spec. Should we remove userID from URL or remove this function and replace with a getNetworksByOwner function?

public List<Membership> getUserNetworkMemberships(
		@PathParam("permission") final String permissions ,
		@PathParam("start") int skipBlocks,
		@PathParam("size") int blockSize,
		@DefaultValue("false") @QueryParam("inclusive") boolean inclusive) throws NdexException, SQLException, JsonParseException, JsonMappingException, IllegalArgumentException, IOException {
	
	logger.info("[start: Getting {} networks ]", permissions);
	
	Permissions permission = Permissions.valueOf(permissions.toUpperCase());
	try (UserDAO dao = new UserDAO ()) {
		
		List<Membership> members= dao.getUserNetworkMemberships(getLoggedInUserId(), permission, skipBlocks, blockSize, inclusive );
		logger.info("[end: Returned {} members ]", members.size());			
		return members;
	} 
}
 
开发者ID:ndexbio,项目名称:ndex-rest,代码行数:41,代码来源:UserService.java

示例4: getUserGroupMemberships

import org.ndexbio.model.object.Membership; //导入依赖的package包/类
/**************************************************************************
 * Retrieves array of group membership objects
 * 
 * @param userId
 *            The user ID.
 * @throws IllegalArgumentException
 *             Bad input.
 * @throws ObjectNotFoundException
 *             The group doesn't exist.
 * @throws NdexException
 *             Failed to query the database.
 * @throws SQLException 
 * @throws IOException 
 * @throws JsonMappingException 
 * @throws JsonParseException 
 **************************************************************************/

@GET
@Path("/{userid}/group/{permission}/{start}/{size}")
@Produces("application/json")
@ApiDoc("Returns a list of membership of groups that the current user has the given permission on. skipBlocks <0 or blockSize <=0 means return all results in one list.")
public List<Membership> getUserGroupMemberships(
		@PathParam("userid")	final String userIdStr,
		@PathParam("permission") final String permissions ,
		@PathParam("start") int skipBlocks,
		@PathParam("size") int blockSize,
		@DefaultValue("false") @QueryParam("inclusive") boolean inclusive) 
				throws NdexException, SQLException, JsonParseException, JsonMappingException, IllegalArgumentException, IOException {

	logger.info("[start: Getting {} groups for user {}]", permissions, getLoggedInUser().getUserName());

	Permissions permission = Permissions.valueOf(permissions.toUpperCase());
	UUID userId = UUID.fromString(userIdStr);
	try (UserDAO dao = new UserDAO ()) {
		List<Membership> result =
				dao.getUserGroupMemberships(userId, permission, skipBlocks, blockSize, inclusive);
		logger.info("[end: Got {} group membership for user {}]", result.size(), getLoggedInUser().getUserName());
		return result;
	} 
}
 
开发者ID:ndexbio,项目名称:ndex-rest,代码行数:41,代码来源:UserService.java

示例5: getGroupUserMemberships

import org.ndexbio.model.object.Membership; //导入依赖的package包/类
/**************************************************************************
	 * Retrieves array of user membership objects
	 * 
	 * @param groupId
	 *            The group ID.
	 * @throws IllegalArgumentException
	 *             Bad input.
	 * @throws ObjectNotFoundException
	 *             The group doesn't exist.
	 * @throws NdexException
	 *             Failed to query the database.
	 * @throws SQLException 
	 * @throws IOException 
	 * @throws JsonMappingException 
	 * @throws JsonParseException 
	 **************************************************************************/
	
	@GET
	@Path("/{groupid}/membership")
	@Produces("application/json")
	@PermitAll
	@ApiDoc("")
	public List<Membership> getGroupUserMemberships(@PathParam("groupid") final String groupIdStr,
			  @QueryParam("type") String permissions,
				@DefaultValue("0") @QueryParam("start") int skipBlocks,
				@DefaultValue("100") @QueryParam("size") int blockSize
			) throws NdexException, SQLException, JsonParseException, JsonMappingException, IllegalArgumentException, IOException {

//		logger.info("[start: Getting {} users in group {}]", permissions, groupIdStr);

		boolean inclusive = false;
		Permissions permission = null; //Permissions.MEMBER;
		if ( permissions != null) {
			permission = Permissions.valueOf(permissions.toUpperCase());
		}
		UUID groupId = UUID.fromString(groupIdStr);
		
		try (GroupDAO dao = new GroupDAO()){
	/*		if ( ! dao.isInGroup(groupId, getLoggedInUserId())) {
				throw new NdexException("User has to be a member of this group.");
			} */
			List<Membership> l = dao.getGroupUserMemberships(groupId, permission, skipBlocks, blockSize, inclusive);
	//		logger.info("[end:]");
			return l;
		} 
	}
 
开发者ID:ndexbio,项目名称:ndex-rest,代码行数:47,代码来源:GroupServiceV2.java

示例6: getNetworkUserMemberships

import org.ndexbio.model.object.Membership; //导入依赖的package包/类
/**************************************************************************
 * Retrieves array of user membership objects
 *
 * @param networkId
 *            The network ID.
 * @throws IllegalArgumentException
 *             Bad input.
 * @throws ObjectNotFoundException
 *             The group doesn't exist.
 * @throws NdexException
 *             Failed to query the database.
 * @throws SQLException 
 **************************************************************************/

@GET
//@PermitAll
@Path("/{networkid}/user/{permission}/{start}/{size}")
@Produces("application/json")
   @ApiDoc("Retrieves a list of Membership objects which specify user permissions for the network specified by " +
           "'networkId'. The value of the 'permission' parameter constrains the type of the returned Membership " +
           "objects and may take the following set of values: READ, WRITE, and ADMIN.  READ, WRITE, and ADMIN are mutually exclusive. Memberships of all types can " +
           "be retrieved by permission = 'ALL'.   The maximum number of Membership objects to retrieve in the query " +
           "is set by 'blockSize' (which may be any number chosen by the user) while  'skipBlocks' specifies the " +
           "number of blocks that have already been read.")
public List<Membership> getNetworkUserMemberships(@PathParam("networkid") final String networkIdStr,
		@PathParam("permission") final String permissions ,
		@PathParam("start") int skipBlocks,
		@PathParam("size") int blockSize) throws NdexException, SQLException {

	logger.info("[start: Get {} accounts on network {}, skipBlocks {},  blockSize {}]", 
			permissions, networkIdStr, skipBlocks, blockSize);
	
	Permissions permission = null;
	if ( ! permissions.toUpperCase().equals("ALL")) {
		permission = Permissions.valueOf(permissions.toUpperCase());
	} 
	
	UUID networkId = UUID.fromString(networkIdStr);
	
	try (NetworkDAO networkDao = new NetworkDAO()) {
		if ( !networkDao.isAdmin(networkId, getLoggedInUserId())) 
			throw new UnauthorizedOperationException("Authenticated user is not the admin of this network");

		List<Membership> results = networkDao.getNetworkUserMemberships(
				networkId, permission, skipBlocks, blockSize);
		logger.info("[end: Got {} members returned for network {}]", 
				results.size(), networkId);
		return results;
	} 
}
 
开发者ID:ndexbio,项目名称:ndex-rest,代码行数:51,代码来源:NetworkService.java

示例7: getGroupUserAccount

import org.ndexbio.model.object.Membership; //导入依赖的package包/类
public List<String> getGroupUserAccount(String groupAccount) 
		throws ObjectNotFoundException, NdexException {
	
	Preconditions.checkArgument(!Strings.isNullOrEmpty(groupAccount.toString()),
			"A group UUID is required");

	ODocument group = this.getRecordByAccountName(groupAccount, NdexClasses.Group);
	
	List<String> result = new ArrayList<>();
	try {
		List<Membership> memberships = new ArrayList<>();
		
		String groupRID = group.getIdentity().toString();
		OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<>(
	  			"SELECT FROM"
	  			+ " (TRAVERSE "+ NdexClasses.Group +".in_"+ Permissions.GROUPADMIN.name().toString().toLowerCase() +
	  					",in_" + NdexClasses.Group +".in_"+ Permissions.MEMBER.name().toString().toLowerCase() 
	  					+ " FROM " + groupRID + "  WHILE $depth <=1) WHERE @class = '" + NdexClasses.User + 
	  					"' AND ( " + NdexClasses.ExternalObj_isDeleted + " = false) ");
		
		List<ODocument> records = this.db.command(query).execute(); 
		for(ODocument member: records) {
			result.add((String)member.field(NdexClasses.account_P_accountName));		
		}
		
		return result;
		
	} 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 "+groupAccount);
	}
}
 
开发者ID:ndexbio,项目名称:ndex-common,代码行数:33,代码来源:GroupDocDAO.java

示例8: 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();
}

}
 
开发者ID:ndexbio,项目名称:ndex-common,代码行数:36,代码来源:TestGroupDAO.java

示例9: 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());
  
}
 
开发者ID:ndexbio,项目名称:ndex-common,代码行数:13,代码来源:TestGroupDAO.java

示例10: 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;
}
 
开发者ID:ndexbio,项目名称:ndex-rest,代码行数:68,代码来源:UserDAO.java

示例11: 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;
	
}
 
开发者ID:ndexbio,项目名称:ndex-rest,代码行数:64,代码来源:GroupDAO.java

示例12: 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;
	
}
 
开发者ID:ndexbio,项目名称:ndex-rest,代码行数:75,代码来源:GroupDAO.java

示例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
 * @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;
}
 
开发者ID:ndexbio,项目名称:ndex-rest,代码行数:64,代码来源:NetworkDAO.java

示例14: 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);
	}
}
 
开发者ID:ndexbio,项目名称:ndex-common,代码行数:67,代码来源:GroupDocDAO.java

示例15: 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);
	}
}
 
开发者ID:ndexbio,项目名称:ndex-common,代码行数:67,代码来源:GroupDocDAO.java


注:本文中的org.ndexbio.model.object.Membership类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。