Search in sources :

Example 36 with ErrorCode2

use of com.akaxin.common.constant.ErrorCode2 in project openzaly by akaxincom.

the class ImSiteAuthHandler method authResponse.

private CommandResponse authResponse(Channel channel, Command command, boolean result) {
    CommandResponse commandResponse = new CommandResponse().setVersion(CommandConst.PROTOCOL_VERSION).setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR2_IMAUTH_FAIL;
    if (result) {
        String siteServer = ServerAddressUtils.getAddressPort();
        ImSiteAuthProto.ImSiteAuthResponse authResponse = ImSiteAuthProto.ImSiteAuthResponse.newBuilder().setSiteServer(siteServer).build();
        commandResponse.setParams(authResponse.toByteArray());
        errCode = ErrorCode2.SUCCESS;
        ChannelWriter.write(channel, commandResponse.setErrCode2(errCode));
    } else {
        ChannelWriter.writeAndClose(channel, commandResponse.setErrCode2(errCode));
    }
    logger.debug("{} client={} siteUserId={} action={} auth response result={}", AkxProject.PLN, command.getClientIp(), command.getSiteUserId(), RequestAction.IM_SITE_AUTH, errCode.toString());
    return commandResponse;
}
Also used : ImSiteAuthProto(com.akaxin.proto.site.ImSiteAuthProto) ErrorCode2(com.akaxin.common.constant.ErrorCode2) CommandResponse(com.akaxin.common.command.CommandResponse)

Example 37 with ErrorCode2

use of com.akaxin.common.constant.ErrorCode2 in project openzaly by akaxincom.

the class ApiDeviceService method list.

public CommandResponse list(Command command) {
    CommandResponse commandResponse = new CommandResponse();
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiDeviceListProto.DeviceListInfoRequest request = ApiDeviceListProto.DeviceListInfoRequest.parseFrom(command.getParams());
        String siteFriendId = request.getSiteUserId();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNotBlank(siteFriendId)) {
            ApiDeviceListProto.DeviceListInfoResponse.Builder responseBuilder = ApiDeviceListProto.DeviceListInfoResponse.newBuilder();
            List<UserDeviceBean> deviceList = UserDeviceDao.getInstance().getActiveDeviceList(siteFriendId);
            for (UserDeviceBean device : deviceList) {
                DeviceProto.SimpleDeviceProfile deviceProfile = DeviceProto.SimpleDeviceProfile.newBuilder().setDeviceId(String.valueOf(device.getDeviceId())).setDeviceName(String.valueOf(device.getDeviceName())).setUserDevicePubk(String.valueOf(device.getUserDevicePubk())).setLastLoginTime(device.getActiveTime()).build();
                responseBuilder.addList(deviceProfile);
            }
            commandResponse.setParams(responseBuilder.build().toByteArray());
            errCode = ErrorCode2.SUCCESS;
        } else {
            errCode = ErrorCode2.ERROR_PARAMETER;
        }
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : ErrorCode2(com.akaxin.common.constant.ErrorCode2) ApiDeviceListProto(com.akaxin.proto.site.ApiDeviceListProto) UserDeviceBean(com.akaxin.site.storage.bean.UserDeviceBean) CommandResponse(com.akaxin.common.command.CommandResponse) DeviceProto(com.akaxin.proto.core.DeviceProto)

Example 38 with ErrorCode2

use of com.akaxin.common.constant.ErrorCode2 in project openzaly by akaxincom.

the class ApiFileService method upload.

public CommandResponse upload(Command command) {
    CommandResponse commandResponse = new CommandResponse();
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiFileUploadProto.ApiFileUploadRequest request = ApiFileUploadProto.ApiFileUploadRequest.parseFrom(command.getParams());
        FileProto.File file = request.getFile();
        int type = file.getFileTypeValue();
        byte[] content = file.getFileContent().toByteArray();
        LogUtils.requestDebugLog(logger, command, "type=" + type + ",size=" + content.length);
        String fileId = FileServerUtils.saveFile(content, FilePathUtils.getPicPath(), type);
        ApiFileUploadProto.ApiFileUploadResponse response = ApiFileUploadProto.ApiFileUploadResponse.newBuilder().setFileId(fileId).build();
        commandResponse.setParams(response.toByteArray());
        errCode = ErrorCode2.SUCCESS;
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : ApiFileUploadProto(com.akaxin.proto.site.ApiFileUploadProto) FileProto(com.akaxin.proto.core.FileProto) ErrorCode2(com.akaxin.common.constant.ErrorCode2) CommandResponse(com.akaxin.common.command.CommandResponse) ByteString(com.google.protobuf.ByteString)

Example 39 with ErrorCode2

use of com.akaxin.common.constant.ErrorCode2 in project openzaly by akaxincom.

the class ApiFriendService method delete.

/**
 * 用户删除好友列表中的其他用户
 *
 * @param command
 * @return
 */
public CommandResponse delete(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiFriendDeleteProto.ApiFriendDeleteRequest request = ApiFriendDeleteProto.ApiFriendDeleteRequest.parseFrom(command.getParams());
        String siteUserId = command.getSiteUserId();
        String siteFriendId = request.getSiteFriendId();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNotBlank(siteUserId) && StringUtils.isNotBlank(siteFriendId) && !siteUserId.equals(siteFriendId)) {
            if (UserFriendDao.getInstance().deleteFriend(siteUserId, siteFriendId)) {
                errCode = ErrorCode2.SUCCESS;
            }
        } else {
            errCode = ErrorCode2.ERROR_PARAMETER;
        }
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : ApiFriendDeleteProto(com.akaxin.proto.site.ApiFriendDeleteProto) ErrorCode2(com.akaxin.common.constant.ErrorCode2) CommandResponse(com.akaxin.common.command.CommandResponse)

Example 40 with ErrorCode2

use of com.akaxin.common.constant.ErrorCode2 in project openzaly by akaxincom.

the class ApiFriendService method updateSetting.

/**
 * 对用户设置消息免打扰功能
 *
 * @param command
 * @return
 */
public CommandResponse updateSetting(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiFriendUpdateSettingProto.ApiFriendUpdateSettingRequest request = ApiFriendUpdateSettingProto.ApiFriendUpdateSettingRequest.parseFrom(command.getParams());
        String siteUserId = command.getSiteUserId();
        String siteFriendId = request.getSiteFriendId();
        boolean messageMute = request.getMessageMute();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNoneBlank(siteUserId, siteFriendId)) {
            UserFriendBean friendBean = new UserFriendBean();
            friendBean.setSiteUserId(siteFriendId);
            friendBean.setMute(messageMute);
            if (UserFriendDao.getInstance().updateFriendSetting(siteUserId, friendBean)) {
                errCode = ErrorCode2.SUCCESS;
            } else {
                errCode = ErrorCode2.ERROR_DATABASE_EXECUTE;
            }
        } else {
            errCode = ErrorCode2.ERROR_PARAMETER;
        }
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : ApiFriendUpdateSettingProto(com.akaxin.proto.site.ApiFriendUpdateSettingProto) ErrorCode2(com.akaxin.common.constant.ErrorCode2) CommandResponse(com.akaxin.common.command.CommandResponse) UserFriendBean(com.akaxin.site.storage.bean.UserFriendBean)

Aggregations

CommandResponse (com.akaxin.common.command.CommandResponse)68 ErrorCode2 (com.akaxin.common.constant.ErrorCode2)68 UserProto (com.akaxin.proto.core.UserProto)12 PluginBean (com.akaxin.site.storage.bean.PluginBean)7 GroupProto (com.akaxin.proto.core.GroupProto)6 GroupProfileBean (com.akaxin.site.storage.bean.GroupProfileBean)6 SimpleUserBean (com.akaxin.site.storage.bean.SimpleUserBean)6 UserProfileBean (com.akaxin.site.storage.bean.UserProfileBean)6 UserDeviceBean (com.akaxin.site.storage.bean.UserDeviceBean)5 ByteString (com.google.protobuf.ByteString)5 DeviceProto (com.akaxin.proto.core.DeviceProto)4 ProtocolStringList (com.google.protobuf.ProtocolStringList)4 ConfigProto (com.akaxin.proto.core.ConfigProto)3 GroupMemberBean (com.akaxin.site.storage.bean.GroupMemberBean)3 UserGroupBean (com.akaxin.site.storage.bean.UserGroupBean)3 FileProto (com.akaxin.proto.core.FileProto)2 HaiSiteUpdateConfigProto (com.akaxin.proto.plugin.HaiSiteUpdateConfigProto)2 ApiFriendSettingProto (com.akaxin.proto.site.ApiFriendSettingProto)2 ApiGroupUpdateSettingProto (com.akaxin.proto.site.ApiGroupUpdateSettingProto)2 User2Notice (com.akaxin.site.business.impl.notice.User2Notice)2