com.google.protobuf.ProtocolStringList Java Examples

The following examples show how to use com.google.protobuf.ProtocolStringList. 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: StubImplementationCodeProcessor.java    From gauge-java with Apache License 2.0 6 votes vote down vote up
@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 #2
Source File: CommitDAORdbImpl.java    From modeldb with 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 #3
Source File: CommonProto2Java.java    From saluki with 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 #4
Source File: UserProviderImpl.java    From dubbo-samples with 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 #5
Source File: TestSdsServer.java    From grpc-java with 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 #6
Source File: CrashFailureDetailsTest.java    From bazel with 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 #7
Source File: GoogleBidRequest.java    From XRTB with 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 #8
Source File: GoogleBidRequest.java    From XRTB with 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 #9
Source File: MessageCollectorTest.java    From gauge-java with 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 #10
Source File: MessageCollectorTest.java    From gauge-java with 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 #11
Source File: StubImplementationCodeProcessor.java    From gauge-java with Apache License 2.0 5 votes vote down vote up
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 #12
Source File: StubImplementationCodeProcessor.java    From gauge-java with Apache License 2.0 5 votes vote down vote up
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 #13
Source File: StubImplementationCodeProcessor.java    From gauge-java with Apache License 2.0 5 votes vote down vote up
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 #14
Source File: StubImplementationCodeProcessor.java    From gauge-java with Apache License 2.0 5 votes vote down vote up
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 #15
Source File: HeroicInteractiveShell.java    From heroic with 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 #16
Source File: HttpGroupService.java    From openzaly with 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 #17
Source File: ApiGroupService.java    From wind-im with 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 #18
Source File: HttpGroupService.java    From wind-im with 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 #19
Source File: HttpGroupService.java    From wind-im with 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 #20
Source File: ApiGroupService.java    From openzaly with 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 #21
Source File: HttpGroupService.java    From openzaly with 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 #22
Source File: HttpGroupService.java    From openzaly with 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 #23
Source File: GoogleBidRequest.java    From bidder with 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 #24
Source File: ServiceResolver.java    From karate-grpc with 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 #25
Source File: ApiGroupService.java    From openzaly with 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 #26
Source File: HttpGroupService.java    From openzaly with 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 #27
Source File: GenericServiceImpl.java    From sofa-rpc with 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 #28
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);
}
 
Example #29
Source File: BlobDAO.java    From modeldb with Apache License 2.0 4 votes vote down vote up
GetCommitComponentRequest.Response getCommitComponent(
RepositoryFunction repositoryFunction, String commitHash, ProtocolStringList locationList)
throws NoSuchAlgorithmException, ModelDBException;
 
Example #30
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);
}