Java Code Examples for com.google.protobuf.ProtocolStringList

The following examples show how to use com.google.protobuf.ProtocolStringList. These examples are extracted from open source projects. 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 Project: dubbo-samples   Source File: UserProviderImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void getUserList(UserIdList request, StreamObserver<UserList> responseObserver){
    ProtocolStringList protocolStringList = request.getIdList();
    UserList.Builder userListBuilder = UserList.newBuilder();
    for (String id : protocolStringList) {
        User user = User.newBuilder().setId(id)
                .setTime(Timestamp.getDefaultInstance())
                .setAge(11)
                .setName("Hello")
                .setId(id)
                .build();
        userListBuilder.addUser(user);
    }
    responseObserver.onNext(userListBuilder.build());
    responseObserver.onCompleted();
}
 
Example 2
Source Project: saluki   Source File: CommonProto2Java.java    License: Apache License 2.0 6 votes vote down vote up
public void generateFile(String protoPath) {
  try {
    if (pojoTypes == null) {
      pojoTypes = Maps.newHashMap();
    }
  } finally {
    if (!new File(protoPath).exists()) {
      logger.warn("protoPath:" + protoPath
          + " not exist, it may be in the third party jars, so it can't be generate");
      return;
    }
    FileDescriptorSet fileDescriptorSet = commondProtoc.invoke(protoPath);
    for (FileDescriptorProto fdp : fileDescriptorSet.getFileList()) {
      Pair<String, String> packageClassName = this.packageClassName(fdp.getOptions());
      if (packageClassName == null) {
        continue;
      }
      ProtocolStringList dependencyList = fdp.getDependencyList();
      for (Iterator<String> it = dependencyList.iterator(); it.hasNext();) {
        String dependencyPath = discoveryRoot + "/" + it.next();
        generateFile(dependencyPath);
      }
      doPrint(fdp, packageClassName.getLeft(), packageClassName.getRight());
    }
  }
}
 
Example 3
Source Project: modeldb   Source File: CommitDAORdbImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param session session
 * @param parentShaList : a list of sha for which the function returns commits
 * @return {@link Map<String, CommitEntity>}
 */
private Map<String, CommitEntity> getCommits(
    Session session, Long repoId, ProtocolStringList parentShaList) {
  StringBuilder commitQueryBuilder =
      new StringBuilder(
          "SELECT cm FROM "
              + CommitEntity.class.getSimpleName()
              + " cm LEFT JOIN cm.repository repo WHERE repo.id = :repoId AND cm.commit_hash IN (:commitHashes)");

  Query<CommitEntity> commitEntityQuery =
      session.createQuery(commitQueryBuilder.append(" ORDER BY cm.date_created DESC").toString());
  commitEntityQuery.setParameter("repoId", repoId);
  commitEntityQuery.setParameter("commitHashes", parentShaList);
  return commitEntityQuery.list().stream()
      .collect(Collectors.toMap(CommitEntity::getCommit_hash, commitEntity -> commitEntity));
}
 
Example 4
@Override
public Messages.Message process(Messages.Message message) {
    ProtocolStringList stubs = message.getStubImplementationCodeRequest().getCodesList();
    String filePath = message.getStubImplementationCodeRequest().getImplementationFilePath();


    File file = new File(filePath);
    Messages.FileDiff fileDiff;

    if (file.exists()) {
        fileDiff = implementInExistingFile(stubs, file);
    } else {
        File fileName = FileHelper.getDefaultImplFileName("", 0);
        fileDiff = implementInNewClass(stubs, fileName);
    }

    return Messages.Message.newBuilder()
            .setMessageId(message.getMessageId())
            .setFileDiff(fileDiff)
            .setMessageType(Messages.Message.MessageType.StubImplementationCodeRequest)
            .build();
}
 
Example 5
Source Project: wind-im   Source File: ApiGroupService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 群主以及管理员删除群成员<br>
 * 群主/管理员权限限制
 *
 * @param command
 * @return
 */
public CommandResponse deleteMember(Command command) {
	CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
	IErrorCode errCode = ErrorCode2.ERROR;
	try {
		ApiGroupRemoveMemberProto.ApiGroupRemoveMemberRequest request = ApiGroupRemoveMemberProto.ApiGroupRemoveMemberRequest
				.parseFrom(command.getParams());
		String siteUserId = command.getSiteUserId();
		String groupId = request.getGroupId();
		ProtocolStringList deleteMemberIds = request.getSiteUserIdList();
		LogUtils.requestDebugLog(logger, command, request.toString());

		if (StringUtils.isAnyBlank(siteUserId, groupId) || deleteMemberIds == null) {
			throw new ZalyException(ErrorCode2.ERROR_PARAMETER);
		}

		if (!checkGroupStatus(groupId)) {
			throw new ZalyException(ErrorCode2.ERROR_GROUP_DELETED);
		}

		String groupMasterId = UserGroupDao.getInstance().getGroupMaster(groupId);
		if (siteUserId.equals(groupMasterId)) {
			if (UserGroupDao.getInstance().deleteGroupMember(groupId, deleteMemberIds)) {
				errCode = ErrorCode2.SUCCESS;
			}
		} else {
			errCode = ErrorCode2.ERROR_NOPERMISSION;
		}

	} 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 6
Source Project: wind-im   Source File: HttpGroupService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * /hai/group/removeMember : 删除群成员
 * 
 * @param command
 * @return
 */
public CommandResponse removeMember(Command command) {
	CommandResponse commandResponse = new CommandResponse();
	ErrorCode2 errCode = ErrorCode2.ERROR;
	try {
		HaiGroupRemoveMemberProto.HaiGroupRemoveMemberRequest request = HaiGroupRemoveMemberProto.HaiGroupRemoveMemberRequest
				.parseFrom(command.getParams());
		String groupId = request.getGroupId();
		if (!checkGroupIdLegal(groupId)) {
			throw new ZalyException2(ErrorCode2.ERROR_PARAMETER);
		}

		ProtocolStringList deleteMemberIds = request.getGroupMemberList();
		LogUtils.requestDebugLog(logger, command, request.toString());
		//无法删除群主
		String groupMaster = UserGroupDao.getInstance().getGroupMaster(groupId);
		for (String deleteMemberId : deleteMemberIds) {
			if (!checkUserIdLegal(deleteMemberId)) {
				throw new ZalyException2(ErrorCode2.ERROR_PARAMETER);
			}
			if (groupMaster.equals(deleteMemberId)) {
				throw new ZalyException2(ErrorCode2.ERROR_NOPERMISSION);
			}
		}
		if (UserGroupDao.getInstance().deleteGroupMember(groupId, deleteMemberIds)) {
			errCode = ErrorCode2.SUCCESS;
		}

	} catch (Exception e) {
		errCode = ErrorCode2.ERROR_SYSTEMERROR;
		LogUtils.requestErrorLog(logger, command, e);
	} catch (ZalyException2 zalyException2) {
		errCode = (ErrorCode2) zalyException2.getErrCode();
		LogUtils.requestErrorLog(logger, command, zalyException2);
	}
	return commandResponse.setErrCode2(errCode);
}
 
Example 7
Source Project: wind-im   Source File: HttpGroupService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * /hai/group/checkMember : 检测用户是否在群聊中
 * 
 * @param command
 * @return
 */
public CommandResponse checkMember(Command command) {
	CommandResponse commandResponse = new CommandResponse();
	ErrorCode2 errCode = ErrorCode2.ERROR;
	try {
		HaiGroupCheckMemberProto.HaiGroupCheckMemberRequest request = HaiGroupCheckMemberProto.HaiGroupCheckMemberRequest
				.parseFrom(command.getParams());
		String groupId = request.getGroupId();
		ProtocolStringList checkUserIds = request.getSiteUserIdList();
		LogUtils.requestDebugLog(logger, command, request.toString());

		if (StringUtils.isNotBlank(groupId) || checkUserIds == null) {
			errCode = ErrorCode2.ERROR_PARAMETER;
		}

		List<String> checkedUserList = UserGroupDao.getInstance().checkGroupMember(groupId, checkUserIds);
		if (checkedUserList != null) {
			HaiGroupCheckMemberProto.HaiGroupCheckMemberResponse response = HaiGroupCheckMemberProto.HaiGroupCheckMemberResponse
					.newBuilder().addAllMembersSiteUserId(checkedUserList).build();
			commandResponse.setParams(response.toByteArray());
		}

		errCode = ErrorCode2.SUCCESS;
	} catch (Exception e) {
		errCode = ErrorCode2.ERROR_SYSTEMERROR;
		LogUtils.requestErrorLog(logger, command, e);
	}
	return commandResponse.setErrCode2(errCode);
}
 
Example 8
Source Project: openzaly   Source File: ApiGroupService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 群主以及管理员删除群成员<br>
 * 群主/管理员权限限制
 *
 * @param command
 * @return
 */
public CommandResponse deleteMember(Command command) {
	CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
	IErrorCode errCode = ErrorCode2.ERROR;
	try {
		ApiGroupRemoveMemberProto.ApiGroupRemoveMemberRequest request = ApiGroupRemoveMemberProto.ApiGroupRemoveMemberRequest
				.parseFrom(command.getParams());
		String siteUserId = command.getSiteUserId();
		String groupId = request.getGroupId();
		ProtocolStringList deleteMemberIds = request.getSiteUserIdList();
		LogUtils.requestDebugLog(logger, command, request.toString());

		if (StringUtils.isAnyBlank(siteUserId, groupId) || deleteMemberIds == null) {
			throw new ZalyException(ErrorCode2.ERROR_PARAMETER);
		}

		if (!checkGroupStatus(groupId)) {
			throw new ZalyException(ErrorCode2.ERROR_GROUP_DELETED);
		}

		String groupMasterId = UserGroupDao.getInstance().getGroupMaster(groupId);
		if (siteUserId.equals(groupMasterId)) {
			if (UserGroupDao.getInstance().deleteGroupMember(groupId, deleteMemberIds)) {
				errCode = ErrorCode2.SUCCESS;
			}
		} else {
			errCode = ErrorCode2.ERROR_NOPERMISSION;
		}

	} 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 9
Source Project: openzaly   Source File: HttpGroupService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * /hai/group/removeMember : 删除群成员
 * 
 * @param command
 * @return
 */
public CommandResponse removeMember(Command command) {
	CommandResponse commandResponse = new CommandResponse();
	ErrorCode2 errCode = ErrorCode2.ERROR;
	try {
		HaiGroupRemoveMemberProto.HaiGroupRemoveMemberRequest request = HaiGroupRemoveMemberProto.HaiGroupRemoveMemberRequest
				.parseFrom(command.getParams());
		String groupId = request.getGroupId();
		if (!checkGroupIdLegal(groupId)) {
			throw new ZalyException2(ErrorCode2.ERROR_PARAMETER);
		}

		ProtocolStringList deleteMemberIds = request.getGroupMemberList();
		LogUtils.requestDebugLog(logger, command, request.toString());
		//无法删除群主
		String groupMaster = UserGroupDao.getInstance().getGroupMaster(groupId);
		for (String deleteMemberId : deleteMemberIds) {
			if (!checkUserIdLegal(deleteMemberId)) {
				throw new ZalyException2(ErrorCode2.ERROR_PARAMETER);
			}
			if (groupMaster.equals(deleteMemberId)) {
				throw new ZalyException2(ErrorCode2.ERROR_NOPERMISSION);
			}
		}
		if (UserGroupDao.getInstance().deleteGroupMember(groupId, deleteMemberIds)) {
			errCode = ErrorCode2.SUCCESS;
		}

	} catch (Exception e) {
		errCode = ErrorCode2.ERROR_SYSTEMERROR;
		LogUtils.requestErrorLog(logger, command, e);
	} catch (ZalyException2 zalyException2) {
		errCode = (ErrorCode2) zalyException2.getErrCode();
		LogUtils.requestErrorLog(logger, command, zalyException2);
	}
	return commandResponse.setErrCode2(errCode);
}
 
Example 10
Source Project: openzaly   Source File: HttpGroupService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * /hai/group/checkMember : 检测用户是否在群聊中
 * 
 * @param command
 * @return
 */
public CommandResponse checkMember(Command command) {
	CommandResponse commandResponse = new CommandResponse();
	ErrorCode2 errCode = ErrorCode2.ERROR;
	try {
		HaiGroupCheckMemberProto.HaiGroupCheckMemberRequest request = HaiGroupCheckMemberProto.HaiGroupCheckMemberRequest
				.parseFrom(command.getParams());
		String groupId = request.getGroupId();
		ProtocolStringList checkUserIds = request.getSiteUserIdList();
		LogUtils.requestDebugLog(logger, command, request.toString());

		if (StringUtils.isNotBlank(groupId) || checkUserIds == null) {
			errCode = ErrorCode2.ERROR_PARAMETER;
		}

		List<String> checkedUserList = UserGroupDao.getInstance().checkGroupMember(groupId, checkUserIds);
		if (checkedUserList != null) {
			HaiGroupCheckMemberProto.HaiGroupCheckMemberResponse response = HaiGroupCheckMemberProto.HaiGroupCheckMemberResponse
					.newBuilder().addAllMembersSiteUserId(checkedUserList).build();
			commandResponse.setParams(response.toByteArray());
		}

		errCode = ErrorCode2.SUCCESS;
	} catch (Exception e) {
		errCode = ErrorCode2.ERROR_SYSTEMERROR;
		LogUtils.requestErrorLog(logger, command, e);
	}
	return commandResponse.setErrCode2(errCode);
}
 
Example 11
Source Project: bidder   Source File: GoogleBidRequest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Take the internal protobuf and convert to JSON.
 * 
 * @throws Exception on JSON or protobuf errors.
 */
private void doInternal() throws Exception {
	impressions = new ArrayList<>();
	root = BidRequest.factory.objectNode();

	// Add this to the log
	byte[] bytes = internal.toByteArray();
	String str = new String(Base64.encodeBase64(bytes));
	root.put("protobuf", str);

	root.put("at", internal.getAt().getNumber());
	ProtocolStringList list = internal.getBadvList();
	root.set("badv", getAsStringList(BidRequest.factory.arrayNode(), list));
	if (internal.hasTmax())
		root.put("tmax", internal.getTmax());

	// Google id's can have / in them. That really makes it hard to pass them in
	// pixels and such.
	String id = internal.getId();

	root.put("id", id);
	makeSiteOrApp();
	makeDevice();
	makeImpressions();
	makeUser();

	rootNode = root;
	setup();

}
 
Example 12
Source Project: karate-grpc   Source File: ServiceResolver.java    License: MIT License 5 votes vote down vote up
/**
 * Recursively constructs file descriptors for all dependencies of the supplied proto and
 * returns a FileDescriptor for the supplied proto itself.
 * For maximal efficientcy, reuse the descriptorCache argument across calls.
 */
private static Descriptors.FileDescriptor descriptorFromProto(
        DescriptorProtos.FileDescriptorProto descriptorProto,
        ImmutableMap<String, DescriptorProtos.FileDescriptorProto> descriptorProtoIndex,
        Map<String, Descriptors.FileDescriptor> descriptorCache) throws Descriptors.DescriptorValidationException {
    // First, check the cache.
    String descriptorName = descriptorProto.getName();
    if (descriptorCache.containsKey(descriptorName)) {
        return descriptorCache.get(descriptorName);
    }

    // Then, fetch all the required dependencies recursively.
    ImmutableList.Builder<Descriptors.FileDescriptor> dependencies = ImmutableList.builder();
    ProtocolStringList protocolStringList = descriptorProto.getDependencyList();
    protocolStringList.forEach(dependencyName -> {
        if (!descriptorProtoIndex.containsKey(dependencyName)) {
            throw new IllegalArgumentException("Can't find dependency: " + dependencyName);
        }
        DescriptorProtos.FileDescriptorProto dependencyProto = descriptorProtoIndex.get(dependencyName);
        try {
            dependencies.add(descriptorFromProto(dependencyProto, descriptorProtoIndex, descriptorCache));
        } catch (Descriptors.DescriptorValidationException e) {
            logger.warning(e.getMessage());
        }
    });

    // Finally, construct the actual descriptor.
    Descriptors.FileDescriptor[] empty = new Descriptors.FileDescriptor[0];

    return Descriptors.FileDescriptor.buildFrom(descriptorProto, dependencies.build().toArray(empty));
}
 
Example 13
Source Project: openzaly   Source File: ApiGroupService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 群主以及管理员删除群成员<br>
 * 群主/管理员权限限制
 *
 * @param command
 * @return
 */
public CommandResponse deleteMember(Command command) {
	CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
	IErrorCode errCode = ErrorCode2.ERROR;
	try {
		ApiGroupRemoveMemberProto.ApiGroupRemoveMemberRequest request = ApiGroupRemoveMemberProto.ApiGroupRemoveMemberRequest
				.parseFrom(command.getParams());
		String siteUserId = command.getSiteUserId();
		String groupId = request.getGroupId();
		ProtocolStringList deleteMemberIds = request.getSiteUserIdList();
		LogUtils.requestDebugLog(logger, command, request.toString());

		if (StringUtils.isAnyBlank(siteUserId, groupId) || deleteMemberIds == null) {
			throw new ZalyException(ErrorCode2.ERROR_PARAMETER);
		}

		if (!checkGroupStatus(groupId)) {
			throw new ZalyException(ErrorCode2.ERROR_GROUP_DELETED);
		}

		String groupMasterId = UserGroupDao.getInstance().getGroupMaster(groupId);
		if (siteUserId.equals(groupMasterId)) {
			if (UserGroupDao.getInstance().deleteGroupMember(groupId, deleteMemberIds)) {
				errCode = ErrorCode2.SUCCESS;
			}
		} else {
			errCode = ErrorCode2.ERROR_NOPERMISSION;
		}

	} 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 14
Source Project: openzaly   Source File: HttpGroupService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * /hai/group/removeMember : 删除群成员
 * 
 * @param command
 * @return
 */
public CommandResponse removeMember(Command command) {
	CommandResponse commandResponse = new CommandResponse();
	ErrorCode2 errCode = ErrorCode2.ERROR;
	try {
		HaiGroupRemoveMemberProto.HaiGroupRemoveMemberRequest request = HaiGroupRemoveMemberProto.HaiGroupRemoveMemberRequest
				.parseFrom(command.getParams());
		String groupId = request.getGroupId();
		if (!checkGroupIdLegal(groupId)) {
			throw new ZalyException2(ErrorCode2.ERROR_PARAMETER);
		}

		ProtocolStringList deleteMemberIds = request.getGroupMemberList();
		LogUtils.requestDebugLog(logger, command, request.toString());
		//无法删除群主
		String groupMaster = UserGroupDao.getInstance().getGroupMaster(groupId);
		for (String deleteMemberId : deleteMemberIds) {
			if (!checkUserIdLegal(deleteMemberId)) {
				throw new ZalyException2(ErrorCode2.ERROR_PARAMETER);
			}
			if (groupMaster.equals(deleteMemberId)) {
				throw new ZalyException2(ErrorCode2.ERROR_NOPERMISSION);
			}
		}
		if (UserGroupDao.getInstance().deleteGroupMember(groupId, deleteMemberIds)) {
			errCode = ErrorCode2.SUCCESS;
		}

	} catch (Exception e) {
		errCode = ErrorCode2.ERROR_SYSTEMERROR;
		LogUtils.requestErrorLog(logger, command, e);
	} catch (ZalyException2 zalyException2) {
		errCode = (ErrorCode2) zalyException2.getErrCode();
		LogUtils.requestErrorLog(logger, command, zalyException2);
	}
	return commandResponse.setErrCode2(errCode);
}
 
Example 15
Source Project: openzaly   Source File: HttpGroupService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * /hai/group/checkMember : 检测用户是否在群聊中
 * 
 * @param command
 * @return
 */
public CommandResponse checkMember(Command command) {
	CommandResponse commandResponse = new CommandResponse();
	ErrorCode2 errCode = ErrorCode2.ERROR;
	try {
		HaiGroupCheckMemberProto.HaiGroupCheckMemberRequest request = HaiGroupCheckMemberProto.HaiGroupCheckMemberRequest
				.parseFrom(command.getParams());
		String groupId = request.getGroupId();
		ProtocolStringList checkUserIds = request.getSiteUserIdList();
		LogUtils.requestDebugLog(logger, command, request.toString());

		if (StringUtils.isNotBlank(groupId) || checkUserIds == null) {
			errCode = ErrorCode2.ERROR_PARAMETER;
		}

		List<String> checkedUserList = UserGroupDao.getInstance().checkGroupMember(groupId, checkUserIds);
		if (checkedUserList != null) {
			HaiGroupCheckMemberProto.HaiGroupCheckMemberResponse response = HaiGroupCheckMemberProto.HaiGroupCheckMemberResponse
					.newBuilder().addAllMembersSiteUserId(checkedUserList).build();
			commandResponse.setParams(response.toByteArray());
		}

		errCode = ErrorCode2.SUCCESS;
	} catch (Exception e) {
		errCode = ErrorCode2.ERROR_SYSTEMERROR;
		LogUtils.requestErrorLog(logger, command, e);
	}
	return commandResponse.setErrCode2(errCode);
}
 
Example 16
Source Project: sofa-rpc   Source File: GenericServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
private Class[] getArgTypes(Request request) {
    ProtocolStringList argTypesList = request.getArgTypesList();
    int size = argTypesList.size();
    Class[] argTypes = new Class[size];
    for (int i = 0; i < size; i++) {
        String typeName = argTypesList.get(i);
        argTypes[i] = ClassUtils.forName(typeName);
    }
    return argTypes;
}
 
Example 17
Source Project: heroic   Source File: HeroicInteractiveShell.java    License: Apache License 2.0 5 votes vote down vote up
void printTasksHelp(PrintWriter out) {
    out.println("Available commands:");

    for (final CommandDefinition cmd : commands) {
        out.println(String.format("%s - %s", cmd.getName(), cmd.getUsage()));

        final ProtocolStringList aliases = cmd.getAliasesList();
        if (!aliases.isEmpty()) {
            out.println(String.format("  aliases: %s", StringUtils.join(", ", aliases)));
        }
    }
}
 
Example 18
private Messages.FileDiff implementInExistingFile(ProtocolStringList stubs, File file) {
    try {
        if (new FileReader(file).read() != -1) {
            return implementInExistingClass(stubs, file);
        }
        return implementInNewClass(stubs, file);
    } catch (IOException e) {
        Logger.error("Unable to implement method", e);
    }
    return null;
}
 
Example 19
private Messages.FileDiff implementInNewClass(ProtocolStringList stubs, File file) {
    String className = FileHelper.getClassName(file);
    String contents = getNewClassContents(className, stubs);
    Spec.Span.Builder span = Spec.Span.newBuilder()
            .setStart(0)
            .setStartChar(0)
            .setEnd(0)
            .setEndChar(0);
    Messages.TextDiff textDiff = Messages.TextDiff.newBuilder().setSpan(span).setContent(contents).build();
    return Messages.FileDiff.newBuilder().setFilePath(file.toString()).addTextDiffs(textDiff).build();
}
 
Example 20
private String getNewClassContents(String className, ProtocolStringList stubs) {
    return "import com.thoughtworks.gauge.Step;"
            + NEW_LINE
            + NEW_LINE
            + "public class " + className + " {"
            + NEW_LINE
            + String.join(NEW_LINE, stubs)
            + NEW_LINE
            + "}"
            + NEW_LINE;
}
 
Example 21
private Messages.FileDiff implementInExistingClass(ProtocolStringList stubs, File file) {
    try {

        JavaParser javaParser = new JavaParser();
        ParseResult<CompilationUnit> compilationUnit = javaParser.parse(file);
        String contents = String.join(NEW_LINE, stubs);
        int lastLine;
        int column;
        MethodVisitor methodVisitor = new MethodVisitor();
        methodVisitor.visit(compilationUnit.getResult().get(), null);
        if (!methodDeclarations.isEmpty()) {
            MethodDeclaration methodDeclaration = methodDeclarations.get(methodDeclarations.size() - 1);
            lastLine = methodDeclaration.getRange().get().end.line - 1;
            column = methodDeclaration.getRange().get().end.column + 1;
            contents = NEW_LINE + contents;
        } else {
            new ClassVisitor().visit(compilationUnit.getResult().get(), null);
            lastLine = classRange.end.line - 1;
            column = 0;
            contents = contents + NEW_LINE;
        }
        Spec.Span.Builder span = Spec.Span.newBuilder()
                .setStart(lastLine)
                .setStartChar(column)
                .setEnd(lastLine)
                .setEndChar(column);
        Messages.TextDiff textDiff = Messages.TextDiff.newBuilder().setSpan(span).setContent(contents).build();
        return Messages.FileDiff.newBuilder().setFilePath(file.toString()).addTextDiffs(textDiff).build();

    } catch (IOException e) {
        Logger.error("Unable to implement method", e);
    }
    return null;
}
 
Example 22
Source Project: gauge-java   Source File: MessageCollectorTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testAddingMessagesToProtoResult() {
    Spec.ProtoExecutionResult executionResult = emptyExecResult();
    String[] messages = {"first message", "second message"};
    Spec.ProtoExecutionResult protoExecutionResult = new MessageCollector().addPendingMessages(executionResult, Arrays.asList(messages));
    ProtocolStringList actualMessageList = protoExecutionResult.getMessageList();
    for (String message : messages) {
        assertTrue(actualMessageList.contains(message));
    }
}
 
Example 23
Source Project: gauge-java   Source File: MessageCollectorTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testAddingNullMessagesToProtoResult() {
    Spec.ProtoExecutionResult executionResult = emptyExecResult();
    String[] messages = {"first message", "second message", null};
    Spec.ProtoExecutionResult protoExecutionResult = new MessageCollector().addPendingMessages(executionResult, Arrays.asList(messages));
    ProtocolStringList actualMessageList = protoExecutionResult.getMessageList();
    assertEquals(2, actualMessageList.size());
    assertFalse(actualMessageList.contains(null));
}
 
Example 24
Source Project: XRTB   Source File: GoogleBidRequest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Take the internal protobuf and convert to JSON.
 * @throws Exception on JSON or protobuf errors.
 */
void doInternal() throws Exception {
	impressions = new ArrayList<Impression>();
	root = BidRequest.factory.objectNode();
	
	// Add this to the log
	byte[] bytes = internal.toByteArray();
	String str = new String(Base64.encodeBase64(bytes));
	root.put("protobuf", str);
	
	root.put("at",internal.getAt().getNumber());
	ProtocolStringList list = internal.getBadvList();
	root.put("badv", getAsStringList(BidRequest.factory.arrayNode(), list));
	if (internal.hasTmax()) root.put("tmax", internal.getTmax());
	
	// Google id's can have / in them. That really makes it hard to pass them in pixels and such.
	String id = internal.getId();
	id = URLEncoder.encode(id, "UTF-8");
	
	root.put("id", id);
	makeSiteOrApp();
	makeDevice();
	makeImpressions();
	makeUser();
	
	
	rootNode = (JsonNode)root;
	setup();
	
}
 
Example 25
Source Project: XRTB   Source File: GoogleBidRequest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Return a list of protocol strings in JSON form
 * @param node ArrayNode. The node we will add to.
 * @param list List. A list of protocol strings.
 * @return ArrayNode. The node we passed in.
 */
protected static ArrayNode getAsStringList(ArrayNode node, ProtocolStringList list) {
	for (int i=0; i<list.size();i++) {
		node.add(list.get(i));
	}
	return node;
}
 
Example 26
Source Project: bazel   Source File: CrashFailureDetailsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void deepStack() {
  ProtocolStringList stackTraceList =
      CrashFailureDetails.forThrowable(functionForDeepStackTrace(1001))
          .getCrash()
          .getCauses(0)
          .getStackTraceList();
  assertThat(stackTraceList).hasSize(1000);

  // Check that the deepest 1000 frames were recorded:
  for (String stackFrame : stackTraceList) {
    assertThat(stackFrame).contains("CrashFailureDetailsTest.functionForDeepStackTrace");
  }
}
 
Example 27
Source Project: grpc-java   Source File: TestSdsServer.java    License: Apache License 2.0 5 votes vote down vote up
private DiscoveryResponse buildResponse(DiscoveryRequest discoveryRequest) {
  checkNotNull(discoveryRequest, "discoveryRequest");
  String requestVersion = discoveryRequest.getVersionInfo();
  String requestNonce = discoveryRequest.getResponseNonce();
  ProtocolStringList resourceNames = discoveryRequest.getResourceNamesList();
  return buildResponse(requestVersion, requestNonce, resourceNames, false, discoveryRequest);
}
 
Example 28
Source Project: wind-im   Source File: ApiGroupService.java    License: 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 29
Source Project: openzaly   Source File: ApiGroupService.java    License: 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 30
Source Project: openzaly   Source File: ApiGroupService.java    License: 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);
}