com.akaxin.proto.site.ApiGroupCreateProto Java Examples

The following examples show how to use com.akaxin.proto.site.ApiGroupCreateProto. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApiGroupService.java    From wind-im with Apache License 2.0 4 votes vote down vote up
/**
 * 用户创建群,并添加初始群成员 <br>
 * 无权限限制
 *
 * @param command
 * @return
 */
public CommandResponse create(Command command) {
	CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
	IErrorCode errCode = ErrorCode2.ERROR;
	try {
		ApiGroupCreateProto.ApiGroupCreateRequest request = ApiGroupCreateProto.ApiGroupCreateRequest
				.parseFrom(command.getParams());
		String siteUserId = command.getSiteUserId();// group owner
		String groupName = request.getGroupName();
		ProtocolStringList groupMembers = request.getSiteUserIdsList();
		List<String> groupMemberIds = Lists.newArrayList(groupMembers);// copy a new list
		LogUtils.requestDebugLog(logger, command, request.toString());

		if (StringUtils.isAnyEmpty(siteUserId, groupName) || groupMemberIds == null) {
			throw new ZalyException(ErrorCode2.ERROR_PARAMETER);
		}

		if (!SiteConfig.allowCreateGroups(siteUserId)) {
			throw new ZalyException(ErrorCode2.ERROR2_GROUP_NOTALLOW);
		}
		// 检查用户是否被封禁,或者不存在
		for (String groupMemberId : groupMemberIds) {
			SimpleUserBean bean = UserProfileDao.getInstance().getSimpleProfileById(groupMemberId);
			if (bean == null || bean.getUserStatus() == 1) {
				groupMemberIds.remove(groupMemberId);
			}
		}

		if (!groupMemberIds.contains(siteUserId)) {
			groupMemberIds.add(siteUserId);
		}

		if (groupMemberIds.size() < 3) {
			throw new ZalyException(ErrorCode2.ERROR_GROUP_MEMBERLESS3);
		}

		GroupProfileBean groupBean = UserGroupDao.getInstance().createGroup(siteUserId, groupName, groupMemberIds);
		if (groupBean != null && StringUtils.isNotEmpty(groupBean.getGroupId())) {
			GroupProto.GroupProfile.Builder groupProfileBuilder = GroupProto.GroupProfile.newBuilder();
			groupProfileBuilder.setId(groupBean.getGroupId());
			if (StringUtils.isNotEmpty(groupBean.getGroupName())) {
				groupProfileBuilder.setName(groupBean.getGroupName());
			}
			if (StringUtils.isNotEmpty(groupBean.getGroupPhoto())) {
				groupProfileBuilder.setIcon(String.valueOf(groupBean.getGroupPhoto()));
			}

			ApiGroupCreateProto.ApiGroupCreateResponse response = ApiGroupCreateProto.ApiGroupCreateResponse
					.newBuilder().setProfile(groupProfileBuilder.build()).build();
			commandResponse.setParams(response.toByteArray());
			errCode = ErrorCode2.SUCCESS;
		} else {
			errCode = ErrorCode2.ERROR_GROUP_WHEN_CREATE;
		}

	} catch (Exception e) {
		if (e instanceof ZalyException) {
			errCode = ((ZalyException) e).getErrCode();
		} else {
			errCode = ErrorCode2.ERROR_SYSTEMERROR;
		}
		LogUtils.requestErrorLog(logger, command, e);
	}
	return commandResponse.setErrCode(errCode);
}
 
Example #2
Source File: ApiGroupService.java    From openzaly with Apache License 2.0 4 votes vote down vote up
/**
 * 用户创建群,并添加初始群成员 <br>
 * 无权限限制
 *
 * @param command
 * @return
 */
public CommandResponse create(Command command) {
	CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
	IErrorCode errCode = ErrorCode2.ERROR;
	try {
		ApiGroupCreateProto.ApiGroupCreateRequest request = ApiGroupCreateProto.ApiGroupCreateRequest
				.parseFrom(command.getParams());
		String siteUserId = command.getSiteUserId();// group owner
		String groupName = request.getGroupName();
		ProtocolStringList groupMembers = request.getSiteUserIdsList();
		List<String> groupMemberIds = Lists.newArrayList(groupMembers);// copy a new list
		LogUtils.requestDebugLog(logger, command, request.toString());

		if (StringUtils.isAnyEmpty(siteUserId, groupName) || groupMemberIds == null) {
			throw new ZalyException(ErrorCode2.ERROR_PARAMETER);
		}

		if (!SiteConfig.allowCreateGroups(siteUserId)) {
			throw new ZalyException(ErrorCode2.ERROR2_GROUP_NOTALLOW);
		}
		// 检查用户是否被封禁,或者不存在
		for (String groupMemberId : groupMemberIds) {
			SimpleUserBean bean = UserProfileDao.getInstance().getSimpleProfileById(groupMemberId);
			if (bean == null || bean.getUserStatus() == 1) {
				groupMemberIds.remove(groupMemberId);
			}
		}

		if (!groupMemberIds.contains(siteUserId)) {
			groupMemberIds.add(siteUserId);
		}

		if (groupMemberIds.size() < 3) {
			throw new ZalyException(ErrorCode2.ERROR_GROUP_MEMBERLESS3);
		}

		GroupProfileBean groupBean = UserGroupDao.getInstance().createGroup(siteUserId, groupName, groupMemberIds);
		if (groupBean != null && StringUtils.isNotEmpty(groupBean.getGroupId())) {
			GroupProto.GroupProfile.Builder groupProfileBuilder = GroupProto.GroupProfile.newBuilder();
			groupProfileBuilder.setId(groupBean.getGroupId());
			if (StringUtils.isNotEmpty(groupBean.getGroupName())) {
				groupProfileBuilder.setName(groupBean.getGroupName());
			}
			if (StringUtils.isNotEmpty(groupBean.getGroupPhoto())) {
				groupProfileBuilder.setIcon(String.valueOf(groupBean.getGroupPhoto()));
			}

			ApiGroupCreateProto.ApiGroupCreateResponse response = ApiGroupCreateProto.ApiGroupCreateResponse
					.newBuilder().setProfile(groupProfileBuilder.build()).build();
			commandResponse.setParams(response.toByteArray());
			errCode = ErrorCode2.SUCCESS;
		} else {
			errCode = ErrorCode2.ERROR_GROUP_WHEN_CREATE;
		}

	} catch (Exception e) {
		if (e instanceof ZalyException) {
			errCode = ((ZalyException) e).getErrCode();
		} else {
			errCode = ErrorCode2.ERROR_SYSTEMERROR;
		}
		LogUtils.requestErrorLog(logger, command, e);
	}
	return commandResponse.setErrCode(errCode);
}
 
Example #3
Source File: ApiGroupService.java    From openzaly with Apache License 2.0 4 votes vote down vote up
/**
 * 用户创建群,并添加初始群成员 <br>
 * 无权限限制
 *
 * @param command
 * @return
 */
public CommandResponse create(Command command) {
	CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
	IErrorCode errCode = ErrorCode2.ERROR;
	try {
		ApiGroupCreateProto.ApiGroupCreateRequest request = ApiGroupCreateProto.ApiGroupCreateRequest
				.parseFrom(command.getParams());
		String siteUserId = command.getSiteUserId();// group owner
		String groupName = request.getGroupName();
		ProtocolStringList groupMembers = request.getSiteUserIdsList();
		List<String> groupMemberIds = Lists.newArrayList(groupMembers);// copy a new list
		LogUtils.requestDebugLog(logger, command, request.toString());

		if (StringUtils.isAnyEmpty(siteUserId, groupName) || groupMemberIds == null) {
			throw new ZalyException(ErrorCode2.ERROR_PARAMETER);
		}

		// 检查用户是否被封禁,或者不存在
		for (String groupMemberId : groupMemberIds) {
			SimpleUserBean bean = UserProfileDao.getInstance().getSimpleProfileById(groupMemberId);
			if (bean == null || bean.getUserStatus() == 1) {
				groupMemberIds.remove(groupMemberId);
			}
		}

		if (!groupMemberIds.contains(siteUserId)) {
			groupMemberIds.add(siteUserId);
		}

		if (groupMemberIds.size() < 3) {
			throw new ZalyException(ErrorCode2.ERROR_GROUP_MEMBERLESS3);
		}

		GroupProfileBean groupBean = UserGroupDao.getInstance().createGroup(siteUserId, groupName, groupMemberIds);
		if (groupBean != null && StringUtils.isNotEmpty(groupBean.getGroupId())) {
			GroupProto.GroupProfile.Builder groupProfileBuilder = GroupProto.GroupProfile.newBuilder();
			groupProfileBuilder.setId(groupBean.getGroupId());
			if (StringUtils.isNotEmpty(groupBean.getGroupName())) {
				groupProfileBuilder.setName(groupBean.getGroupName());
			}
			if (StringUtils.isNotEmpty(groupBean.getGroupPhoto())) {
				groupProfileBuilder.setIcon(String.valueOf(groupBean.getGroupPhoto()));
			}

			ApiGroupCreateProto.ApiGroupCreateResponse response = ApiGroupCreateProto.ApiGroupCreateResponse
					.newBuilder().setProfile(groupProfileBuilder.build()).build();
			commandResponse.setParams(response.toByteArray());
			errCode = ErrorCode2.SUCCESS;
		} else {
			errCode = ErrorCode2.ERROR_GROUP_WHEN_CREATE;
		}

	} catch (Exception e) {
		if (e instanceof ZalyException) {
			errCode = ((ZalyException) e).getErrCode();
		} else {
			errCode = ErrorCode2.ERROR_SYSTEMERROR;
		}
		LogUtils.requestErrorLog(logger, command, e);
	}
	return commandResponse.setErrCode(errCode);
}