コード例 #1
0
 private boolean isIdInvalid(ProcessorContext context) {
   if (context.resourceId() == null || context.resourceId().isEmpty()) {
     LOGGER.error("Invalid request, resource id not available. Aborting");
     return true;
   }
   return !validateUuid(context.resourceId());
 }
コード例 #2
0
 private MessageResponse processListOfCoursesBySubject() {
   ProcessorContext context = createContext();
   if (context.subjectId() == null || context.subjectId().isEmpty()) {
     LOGGER.error("invalid Subject Id. ");
     return MessageResponseFactory.createInvalidRequestResponse("Invalid subject id");
   }
   return new RepoBuilder().buildTaxonomyRepo(context).getListOfCoursesBySubject();
 }
コード例 #3
0
 private MessageResponse processResourceUpdate() {
   ProcessorContext context = createContext();
   if (isIdInvalid(context)) {
     return MessageResponseFactory.createInvalidRequestResponse("Invalid request id");
   }
   if (context.request() == null || context.request().isEmpty()) {
     LOGGER.error("Invalid request, json not available. Aborting");
     return MessageResponseFactory.createInvalidRequestResponse("Invalid Json");
   }
   return new RepoBuilder().buildResourceRepo(context).updateResource();
 }
コード例 #4
0
 private void processCommandSave(ProcessorContext context, DataInputStream dis)
     throws IOException {
   GameRecord record = extractGameRecord(context, dis);
   try {
     recordServ.saveOrUpdate(record, context.getProductId());
   } catch (ServiceException e) {
     context.setErrorCode(ErrorCode.EC_SERVICE_FAILED);
     context.setMessage(ErrorCode.getErrorMessage(ErrorCode.EC_SERVICE_FAILED));
     throw new RequestProcessException(e);
   }
 }
コード例 #5
0
 private void processCommandQueryDescList(ProcessorContext context, DataInputStream dis)
     throws IOException {
   int accountId = dis.readInt();
   int productId = dis.readInt();
   try {
     List<GameRecordDesc> descList = recordServ.queryRecordDescList(accountId, productId);
     context.setResult(descList);
   } catch (ServiceException e) {
     context.setErrorCode(ErrorCode.EC_SERVICE_FAILED);
     context.setMessage(ErrorCode.getErrorMessage(ErrorCode.EC_SERVICE_FAILED));
     throw new RequestProcessException(e);
   }
 }
コード例 #6
0
 private void processCommandRead(ProcessorContext context, DataInputStream dis)
     throws IOException {
   int accountId = dis.readInt();
   int productId = dis.readInt();
   int recordId = dis.readInt();
   try {
     GameRecord record = recordServ.read(accountId, productId, recordId);
     context.setResult(record);
   } catch (ServiceException e) {
     context.setErrorCode(ErrorCode.EC_SERVICE_FAILED);
     context.setMessage(ErrorCode.getErrorMessage(ErrorCode.EC_SERVICE_FAILED));
     throw new RequestProcessException(e);
   }
 }
コード例 #7
0
  private GameRecord extractGameRecord(ProcessorContext context, DataInputStream dis)
      throws IOException {
    int accountId = dis.readInt();
    int productId = dis.readInt();
    context.setProductId(productId);
    int recordId = dis.readInt();
    int playDuration = dis.readInt();
    int scores = dis.readInt();
    String remark = dis.readUTF();
    int dataLen = dis.readInt();
    byte[] data = null;
    if (dataLen > 0) {
      data = new byte[dataLen];
      int readLen = 0;
      int curReadLen = 0;
      while (readLen < data.length) {
        curReadLen = dis.read(data, readLen, data.length - readLen);
        if (curReadLen > 0) {
          readLen += curReadLen;
        }
      }
    }

    GameRecord record = new GameRecord();
    record.setAccountId(accountId);
    record.setRecordId(recordId);
    record.setPlayDuration(playDuration);
    record.setScores(scores);
    record.setRemark(remark);
    record.setTime(new java.util.Date());
    record.setData(data);

    return record;
  }
コード例 #8
0
 @SuppressWarnings("unchecked")
 private void processCommandQueryDescList(ProcessorContext context, DataOutputStream dos)
     throws IOException {
   dos.writeInt(context.getHeadWrapper().getHead());
   dos.writeInt(0); /*result*/
   List<GameRecordDesc> descList = (List<GameRecordDesc>) context.getResult();
   if (descList != null && descList.size() > 0) {
     dos.writeShort(descList.size());
     for (GameRecordDesc desc : descList) {
       dos.writeInt(desc.getRecordId());
       dos.writeInt(desc.getPlayDuration());
       dos.writeInt(desc.getScores());
       dos.writeUTF(desc.getRemark());
       dos.writeUTF(DateFormatUtils.format(desc.getTime(), "yyyy/MM/dd HH:mm:ss"));
     }
   } else {
     dos.writeShort(0);
   }
 }
コード例 #9
0
  @Override
  public Mapper process(
      ProcessorContext context, TypeElement mapperTypeElement, List<SourceMethod> sourceModel) {
    this.elementUtils = context.getElementUtils();
    this.typeUtils = context.getTypeUtils();
    this.messager = context.getMessager();
    this.options = context.getOptions();
    this.versionInformation = context.getVersionInformation();
    this.typeFactory = context.getTypeFactory();

    MapperConfiguration mapperConfig = MapperConfiguration.getInstanceOn(mapperTypeElement);
    List<MapperReference> mapperReferences = initReferencedMappers(mapperTypeElement, mapperConfig);

    MappingBuilderContext ctx =
        new MappingBuilderContext(
            typeFactory,
            elementUtils,
            typeUtils,
            messager,
            options,
            new MappingResolverImpl(
                messager, elementUtils, typeUtils, typeFactory, sourceModel, mapperReferences),
            mapperTypeElement,
            sourceModel,
            mapperReferences);
    this.mappingContext = ctx;
    return getMapper(mapperTypeElement, mapperConfig, sourceModel);
  }
コード例 #10
0
 @Override
 public void processRequest(ProcessorContext context, DataInputStream dis) throws IOException {
   switch (context.getHeadWrapper().getCommand()) {
     case Constant.RECORD_CMD_SAVE:
       processCommandSave(context, dis);
       break;
     case Constant.RECORD_CMD_READ:
       processCommandRead(context, dis);
       break;
     case Constant.RECORD_CMD_QUERY_DESC_LIST:
       processCommandQueryDescList(context, dis);
       break;
     case Constant.RECORD_CMD_UPDATE:
       processCommandUpdate(context, dis);
       break;
     default:
       String msg = "无效的协议命令, cmd=" + context.getHeadWrapper().getCommand();
       context.setErrorCode(Constant.EC_INVALID_CMD);
       context.setMessage(msg);
       throw new RequestProcessException(msg);
   }
 }
コード例 #11
0
 private void processCommandRead(ProcessorContext context, DataOutputStream dos)
     throws IOException {
   dos.writeInt(context.getHeadWrapper().getHead());
   GameRecord record = (GameRecord) context.getResult();
   if (record != null) {
     dos.writeInt(0);
     dos.writeInt(record.getRecordId());
     dos.writeInt(record.getPlayDuration());
     dos.writeInt(record.getScores());
     dos.writeUTF(record.getRemark());
     dos.writeUTF(DateFormatUtils.format(record.getTime(), "yyyy/MM/dd HH:mm:ss"));
     byte[] data = record.getData();
     if (data != null && data.length > 0) {
       dos.writeInt(data.length);
       dos.write(data, 0, data.length);
     } else {
       dos.writeInt(0);
     }
   } else {
     dos.writeInt(Constant.EC_RECORD_NOT_EXIST);
     dos.writeUTF("游戏记录不存在");
   }
 }
コード例 #12
0
 @Override
 public void processResponse(ProcessorContext context, DataOutputStream dos)
     throws ServiceException, IOException {
   switch (context.getHeadWrapper().getCommand()) {
     case Constant.RECORD_CMD_SAVE:
       processCommandSave(context, dos);
       break;
     case Constant.RECORD_CMD_READ:
       processCommandRead(context, dos);
       break;
     case Constant.RECORD_CMD_QUERY_DESC_LIST:
       processCommandQueryDescList(context, dos);
       break;
     case Constant.RECORD_CMD_UPDATE:
       processCommandUpdate(context, dos);
       break;
     default:
       break;
   }
 }
コード例 #13
0
 private void processCommandSave(ProcessorContext context, DataOutputStream dos)
     throws IOException {
   dos.writeInt(context.getHeadWrapper().getHead());
   dos.writeInt(0); /*result*/
 }