Search in sources :

Example 76 with CommandResponse

use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.

the class HttpUserService method profile.

/**
 * 查看用户的个人profile
 *
 * @param command
 * @return
 */
public CommandResponse profile(Command command) {
    CommandResponse commandResponse = new CommandResponse();
    ErrorCode2 errorCode = ErrorCode2.ERROR;
    try {
        HaiUserProfileProto.HaiUserProfileRequest request = HaiUserProfileProto.HaiUserProfileRequest.parseFrom(command.getParams());
        String siteUserId = request.getSiteUserId();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNotBlank(siteUserId)) {
            UserProfileBean bean = UserProfileDao.getInstance().getUserProfileById(siteUserId);
            if (bean != null && StringUtils.isNotBlank(bean.getSiteUserId())) {
                UserProto.UserProfile profile = UserProto.UserProfile.newBuilder().setSiteUserId(bean.getSiteUserId()).setUserName(String.valueOf(bean.getUserName())).setUserPhoto(String.valueOf(bean.getUserPhoto())).setUserStatusValue(bean.getUserStatus()).build();
                HaiUserProfileProto.HaiUserProfileResponse response = HaiUserProfileProto.HaiUserProfileResponse.newBuilder().setUserProfile(profile).build();
                commandResponse.setParams(response.toByteArray());
                errorCode = ErrorCode2.SUCCESS;
            }
        } else {
            errorCode = ErrorCode2.ERROR_PARAMETER;
        }
    } catch (Exception e) {
        errorCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errorCode);
}
Also used : ErrorCode2(com.akaxin.common.constant.ErrorCode2) UserProto(com.akaxin.proto.core.UserProto) CommandResponse(com.akaxin.common.command.CommandResponse) HaiUserProfileProto(com.akaxin.proto.plugin.HaiUserProfileProto) UserProfileBean(com.akaxin.site.storage.bean.UserProfileBean)

Example 77 with CommandResponse

use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.

the class HttpRequestService method process.

public CommandResponse process(Command command) {
    HttpUriAction huaEnum = HttpUriAction.getUriActionEnum(command.getUri());
    command.setMethod(huaEnum.getMethod());
    CommandResponse response = null;
    try {
        switch(huaEnum) {
            case HAI_USER_UPDATE:
            case HAI_USER_SEALUP:
                if (!checkPermissions(command.getSiteUserId())) {
                    break;
                }
            case HAI_USER_LIST:
            case HAI_USER_SEARCH:
            case HAI_USER_PROFILE:
            case HAI_USER_RELATIONLIST:
                return new HttpUserService().execute(command);
            case HAI_GROUP_LIST:
            case HAI_GROUP_PROFILE:
            case HAI_GROUP_MEMBERS:
            case HAI_GROUP_ADDMEMBER:
            case HAI_GROUP_DELETE:
            case HAI_GROUP_REMOVEMEMBER:
            case HAI_GROUP_SETADMIN:
            case HAI_GROUP_UPDATEPROFILE:
            case HAI_GROUP_NONMEMBERS:
                if (checkPermissions(command.getSiteUserId())) {
                    response = new HttpGroupService().execute(command);
                }
                break;
            case HAI_FRIEND_APPLY:
                response = new HttpFriendService().execute(command);
                break;
            case HAI_SITE_GETCONFIG:
            case HAI_SITE_UPDATECONFIG:
                if (checkPermissions(command.getSiteUserId())) {
                    response = new HttpSiteConfigService().execute(command);
                }
                break;
            case HAI_PLUGIN_ADD:
            case HAI_PLUGIN_DELETE:
            case HAI_PLUGIN_DISABLE:
            case HAI_PLUGIN_LIST:
            case HAI_PLUGIN_PROFILE:
            case HAI_PLUGIN_UPDATE:
            case HAI_PLUGIN_UPDATESTATUS:
                if (checkPermissions(command.getSiteUserId())) {
                    response = new HttpPluginService().execute(command);
                }
                break;
            case HAI_UIC_CREATE:
            case HAI_UIC_INFO:
            case HAI_UIC_LIST:
                if (checkPermissions(command.getSiteUserId())) {
                    response = new HttpUICService().execute(command);
                }
                break;
            default:
                logger.error("error http request command={}", command.toString());
                break;
        }
    } catch (Exception e) {
        logger.error("http request service error.", e);
    }
    if (response == null) {
        response = new CommandResponse();
    }
    return response.setVersion(CommandConst.PROTOCOL_VERSION).setAction(CommandConst.ACTION_RES);
}
Also used : HttpUICService(com.akaxin.site.business.impl.hai.HttpUICService) HttpGroupService(com.akaxin.site.business.impl.hai.HttpGroupService) HttpSiteConfigService(com.akaxin.site.business.impl.hai.HttpSiteConfigService) HttpPluginService(com.akaxin.site.business.impl.hai.HttpPluginService) HttpUriAction(com.akaxin.common.constant.HttpUriAction) HttpUserService(com.akaxin.site.business.impl.hai.HttpUserService) CommandResponse(com.akaxin.common.command.CommandResponse) HttpFriendService(com.akaxin.site.business.impl.hai.HttpFriendService)

Example 78 with CommandResponse

use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.

the class Bootstrap method startHttpServer.

/**
 * 启动Http服务,提供与扩展服务之间的hai(http application interface)接口功能
 *
 * @throws Exception
 */
private static void startHttpServer(String address, int port) throws Exception {
    new HttpServer() {

        @Override
        public void loadExecutor(AbstracteExecutor<Command, CommandResponse> executor) {
            executor.addChain(HttpUriAction.HTTP_ACTION.getUri(), new HttpRequestHandler());
        }
    }.start(address, port);
    logger.info("{} start http server {}:{} ok.", AkxProject.PLN, address, port);
}
Also used : Command(com.akaxin.common.command.Command) HttpRequestHandler(com.akaxin.site.connector.handler.HttpRequestHandler) HttpServer(com.akaxin.site.connector.http.HttpServer) CommandResponse(com.akaxin.common.command.CommandResponse)

Example 79 with CommandResponse

use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.

the class HttpRequestHandler method handle.

@Override
public CommandResponse handle(Command command) {
    try {
        ChannelHandlerContext context = command.getChannelContext();
        if (context == null) {
            logger.error("{} client={} http request error context={}", AkxProject.PLN, command.getClientIp(), context);
            return null;
        }
        CommandResponse comamndResponse = new HttpRequestService().process(command);
        comamndResponse.setVersion(CommandConst.PROTOCOL_VERSION);
        comamndResponse.setAction(CommandConst.ACTION_RES);
        String authKey = command.getField(PluginConst.PLUGIN_AUTH_KEY, String.class);
        fullHttpResponse(context, comamndResponse, authKey);
        return comamndResponse;
    } catch (Exception e) {
        logger.error("api request error.", e);
    }
    return null;
}
Also used : HttpRequestService(com.akaxin.site.business.service.HttpRequestService) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) CommandResponse(com.akaxin.common.command.CommandResponse)

Example 80 with CommandResponse

use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.

the class ImSiteAuthHandler method defaultErrorResponse.

private CommandResponse defaultErrorResponse() {
    CommandResponse commandResponse = new CommandResponse().setVersion(CommandConst.PROTOCOL_VERSION).setAction(CommandConst.ACTION_RES);
    commandResponse.setErrCode2(ErrorCode2.ERROR);
    return commandResponse;
}
Also used : CommandResponse(com.akaxin.common.command.CommandResponse)

Aggregations

CommandResponse (com.akaxin.common.command.CommandResponse)82 ErrorCode2 (com.akaxin.common.constant.ErrorCode2)68 UserProto (com.akaxin.proto.core.UserProto)12 PluginBean (com.akaxin.site.storage.bean.PluginBean)7 ByteString (com.google.protobuf.ByteString)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 Command (com.akaxin.common.command.Command)4 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 RedisCommand (com.akaxin.common.command.RedisCommand)2 ImStcPsnProto (com.akaxin.proto.client.ImStcPsnProto)2 CoreProto (com.akaxin.proto.core.CoreProto)2 FileProto (com.akaxin.proto.core.FileProto)2