Java Code Examples for org.apache.commons.lang3.StringUtils#trim()

The following examples show how to use org.apache.commons.lang3.StringUtils#trim() . 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: JsonDataProcessHandler.java    From molicode with Apache License 2.0 6 votes vote down vote up
@Override
public void doHandle(MoliCodeContext context) {
    String content = context.getDataString(MoliCodeConstant.CTX_KEY_SRC_CONTENT);
    content = StringUtils.trim(content);
    if (StringUtils.isEmpty(content)) {
        LogHelper.DEFAULT.warn("输入数据为空! 数据处理失败");
        return;
    }

    if (content.startsWith("[")) {
        context.put(MoliCodeConstant.CTX_KEY_DEF_DATA, JSON.parseArray(content));
    } else if (content.startsWith("{")) {
        context.put(MoliCodeConstant.CTX_KEY_DEF_DATA, JSON.parseObject(content));
    } else {
        throw new AutoCodeException("非合法的JSON数据格式,content=" + content, ResultCodeEnum.PARAM_ERROR);
    }
}
 
Example 2
Source File: RssFeed.java    From torrssen2 with MIT License 6 votes vote down vote up
public void setRssTitleByTitle(String title) {
    Pattern pattern = Pattern.compile(".*(e\\d{2,}).*", Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(title);

    String rssTitle = title;

    if (matcher.matches()) {
        rssTitle = rssTitle.substring(0, matcher.start(1)).replaceAll("\\.", "");
    }

    // pattern = Pattern.compile("\\d{1,}-\\d{1,}회 합본");
    pattern = Pattern.compile("E{0,1}\\d{1,}.{0,1}E{0,1}\\d{1,}회.{0,1}합본");
    rssTitle = RegExUtils.removeAll(rssTitle, pattern);

    pattern = Pattern.compile("\\[[^\\]]{1,}\\]");
    rssTitle = RegExUtils.removeAll(rssTitle, pattern);

    this.rssTitle = StringUtils.trim(rssTitle);
}
 
Example 3
Source File: ScopeParser.java    From jerseyoauth2 with MIT License 6 votes vote down vote up
public Set<String> parseScope(String scope)
{
	if (scope == null) {
		return null;
	}
	
	Scanner scanner = new Scanner(StringUtils.trim(scope));
	try {
		scanner.useDelimiter(" ");
		
		Set<String> result = new HashSet<>();
		while (scanner.hasNext(SCOPE_PATTERN))
		{
			String scopeToken = scanner.next(SCOPE_PATTERN);
			result.add(scopeToken);
		}
		return result;
	} finally {
		scanner.close();
	}
}
 
Example 4
Source File: JarResourceLoader.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Called by Velocity to initialize the loader
 * @param configuration
 */
public void init( ExtProperties configuration)
{
    log.trace("JarResourceLoader: initialization starting.");

    List paths = configuration.getList(RuntimeConstants.RESOURCE_LOADER_PATHS);

    if (paths != null)
    {
        log.debug("JarResourceLoader # of paths: {}", paths.size() );

        for (ListIterator<String> it = paths.listIterator(); it.hasNext(); )
        {
            String jar = StringUtils.trim(it.next());
            it.set(jar);
            loadJar(jar);
        }
    }

    log.trace("JarResourceLoader: initialization complete.");
}
 
Example 5
Source File: FormsResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected String makeValidFilterText(String filterText) {
  String validFilter = null;

  if (filterText != null) {
    String trimmed = StringUtils.trim(filterText);
    if (trimmed.length() >= MIN_FILTER_LENGTH) {
      validFilter = "%" + trimmed.toLowerCase() + "%";
    }
  }
  return validFilter;
}
 
Example 6
Source File: ActionListPrevFilter.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String id, Integer count, JsonElement jsonElement)
		throws Exception {
	ActionResult<List<Wo>> result = new ActionResult<>();
	Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
	EqualsTerms equals = new EqualsTerms();
	InTerms ins = new InTerms();
	LikeTerms likes = new LikeTerms();
	equals.put(Read.person_FIELDNAME, effectivePerson.getDistinguishedName());
	if (ListTools.isNotEmpty(wi.getApplicationList())) {
		ins.put(Read.application_FIELDNAME, wi.getApplicationList());
	}
	if (ListTools.isNotEmpty(wi.getProcessList())) {
		ins.put(Read.process_FIELDNAME, wi.getProcessList());
	}
	if (ListTools.isNotEmpty(wi.getCreatorUnitList())) {
		ins.put(Read.creatorUnit_FIELDNAME, wi.getCreatorUnitList());
	}
	if (ListTools.isNotEmpty(wi.getStartTimeMonthList())) {
		ins.put(Read.startTimeMonth_FIELDNAME, wi.getStartTimeMonthList());
	}
	if (ListTools.isNotEmpty(wi.getActivityNameList())) {
		ins.put(Read.activityName_FIELDNAME, wi.getActivityNameList());
	}
	if (StringUtils.isNotEmpty(wi.getKey())) {
		String key = StringUtils.trim(StringUtils.replace(wi.getKey(), "\u3000", " "));
		if (StringUtils.isNotEmpty(key)) {
			likes.put(Read.title_FIELDNAME, key);
			likes.put(Read.opinion_FIELDNAME, key);
			likes.put(Read.serial_FIELDNAME, key);
			likes.put(Read.creatorPerson_FIELDNAME, key);
			likes.put(Read.creatorUnit_FIELDNAME, key);
		}
	}
	result = this.standardListPrev(Wo.copier, id, count, Read.sequence_FIELDNAME, equals, null, likes, ins, null,
			null, null, null, true, DESC);
	return result;
}
 
Example 7
Source File: DynaCode.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public static String getClassName(String code) {
    String className = StringUtils.substringBefore(code, "{");
    if (StringUtils.isBlank(className)) {
        return className;
    }
    if (StringUtils.contains(code, " class ")) {
        className = StringUtils.substringAfter(className, " class ");
        if (StringUtils.contains(className, " extends ")) {
            className = StringUtils.substringBefore(className, " extends ").trim();
        } else if (StringUtils.contains(className, " implements ")) {
            className = StringUtils.trim(StringUtils.substringBefore(className, " implements "));
        } else {
            className = StringUtils.trim(className);
        }
    } else if (StringUtils.contains(code, " interface ")) {
        className = StringUtils.substringAfter(className, " interface ");
        if (StringUtils.contains(className, " extends ")) {
            className = StringUtils.substringBefore(className, " extends ").trim();
        } else {
            className = StringUtils.trim(className);
        }
    } else if (StringUtils.contains(code, " enum ")) {
        className = StringUtils.trim(StringUtils.substringAfter(className, " enum "));
    } else {
        return StringUtils.EMPTY;
    }
    return className;
}
 
Example 8
Source File: DynaCode.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
public static String getClassName(String code) {
    String className = StringUtils.substringBefore(code, "{");
    if (StringUtils.isBlank(className)) {
        return className;
    }
    if (StringUtils.contains(code, " class ")) {
        className = StringUtils.substringAfter(className, " class ");
        if (StringUtils.contains(className, " extends ")) {
            className = StringUtils.substringBefore(className, " extends ").trim();
        } else if (StringUtils.contains(className, " implements ")) {
            className = StringUtils.trim(StringUtils.substringBefore(className, " implements "));
        } else {
            className = StringUtils.trim(className);
        }
    } else if (StringUtils.contains(code, " interface ")) {
        className = StringUtils.substringAfter(className, " interface ");
        if (StringUtils.contains(className, " extends ")) {
            className = StringUtils.substringBefore(className, " extends ").trim();
        } else {
            className = StringUtils.trim(className);
        }
    } else if (StringUtils.contains(code, " enum ")) {
        className = StringUtils.trim(StringUtils.substringAfter(className, " enum "));
    } else {
        return StringUtils.EMPTY;
    }
    return className;
}
 
Example 9
Source File: RuntimeInstance.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 *  Allows an external caller to get a property.  The calling
 *  routine is required to know the type, as this routine
 *  will return an Object, as that is what properties can be.
 *
 *  @param key property to return
 *  @return Value of the property or null if it does not exist.
 */
public Object getProperty(String key)
{
    Object o = null;

    /**
     * Before initialization, check the user-entered properties first.
     */
    if (!initialized && overridingProperties != null)
    {
        o = overridingProperties.get(key);
    }

    /**
     * After initialization, configuration will hold all properties.
     */
    if (o == null)
    {
        o = configuration.getProperty(key);
    }
    if (o instanceof String)
    {
        return StringUtils.trim((String) o);
    }
    else
    {
        return o;
    }
}
 
Example 10
Source File: FileUtils.java    From DBus with Apache License 2.0 5 votes vote down vote up
public static String getValueFromFile(String path, String key) throws Exception {
    try (BufferedReader br = new BufferedReader(new FileReader(path))) {
        String line;
        while ((line = br.readLine()) != null) {
            if (line.matches(key + "\\s*=.*")) {
                return StringUtils.trim(StringUtils.split(line, "=")[1]);
            }
        }
        return null;
    } catch (Exception e) {
        throw e;
    }
}
 
Example 11
Source File: BaseTools.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public static String readCfg(String path, String defaultValue) throws Exception {
	String str = readCfg(path);
	if (StringUtils.isEmpty(str)) {
		str = defaultValue;
	}
	return (StringUtils.trim(str));
}
 
Example 12
Source File: JobClientResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * GET /rest/activiti/jobs/{jobId}/exception-stracktrace -> return job stacktrace
 */
@RequestMapping(value = "/rest/activiti/jobs/{jobId}/stacktrace", method = RequestMethod.GET, produces = "text/plain")
public String getJobStacktrace(@PathVariable String jobId) throws BadRequestException {

	ServerConfig serverConfig = retrieveServerConfig();
	try {
		String trace =  clientService.getJobStacktrace(serverConfig, jobId);
		if(trace != null) {
			trace = StringUtils.trim(trace);
		}
		return trace;
	} catch (ActivitiServiceException e) {
		throw new BadRequestException(e.getMessage());
	}
}
 
Example 13
Source File: ActionListNextFilter.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String id, Integer count, JsonElement jsonElement)
		throws Exception {
	ActionResult<List<Wo>> result = new ActionResult<>();
	Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
	EqualsTerms equals = new EqualsTerms();
	InTerms ins = new InTerms();
	LikeTerms likes = new LikeTerms();
	equals.put(Task.person_FIELDNAME, effectivePerson.getDistinguishedName());
	if (ListTools.isNotEmpty(wi.getApplicationList())) {
		ins.put(Task.application_FIELDNAME, wi.getApplicationList());
	}
	if (ListTools.isNotEmpty(wi.getProcessList())) {
		ins.put(Task.process_FIELDNAME, wi.getProcessList());
	}
	if (ListTools.isNotEmpty(wi.getCreatorUnitList())) {
		ins.put(Task.creatorUnit_FIELDNAME, wi.getCreatorUnitList());
	}
	if (ListTools.isNotEmpty(wi.getStartTimeMonthList())) {
		ins.put(Task.startTimeMonth_FIELDNAME, wi.getStartTimeMonthList());
	}
	if (ListTools.isNotEmpty(wi.getActivityNameList())) {
		ins.put(Task.activityName_FIELDNAME, wi.getActivityNameList());
	}
	if (StringUtils.isNotEmpty(wi.getKey())) {
		String key = StringUtils.trim(StringUtils.replace(wi.getKey(), "\u3000", " "));
		if (StringUtils.isNotEmpty(key)) {
			likes.put(Task.title_FIELDNAME, key);
			likes.put(Task.opinion_FIELDNAME, key);
			likes.put(Task.serial_FIELDNAME, key);
			likes.put(Task.creatorPerson_FIELDNAME, key);
			likes.put(Task.creatorUnit_FIELDNAME, key);
		}
	}
	result = this.standardListNext(Wo.copier, id, count, Task.sequence_FIELDNAME, equals, null, likes, ins, null,
			null, null, null, true, DESC);
	return result;
}
 
Example 14
Source File: ConfigUtils.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public static GroupConfig findGroupByName(String groupName, ConfigManager configManager) {
    groupName = StringUtils.trim(groupName);
    if (configManager == null) {
        return null;
    }
    Map<String, GroupConfig> groups = configManager.getCurGroupConfigMap();
    return groups == null ? null : groups.get(groupName);
}
 
Example 15
Source File: ActionManageListFilterPaging.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
private List<Read> list(EffectivePerson effectivePerson, Business business, Integer adjustPage,
		Integer adjustPageSize, Wi wi) throws Exception {
	EntityManager em = business.entityManagerContainer().get(Read.class);
	List<String> person_ids = business.organization().person().list(wi.getCredentialList());
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Read> cq = cb.createQuery(Read.class);
	Root<Read> root = cq.from(Read.class);
	Predicate p = cb.conjunction();
	if (ListTools.isNotEmpty(wi.getApplicationList())) {
		p = cb.and(p, root.get(Read_.application).in(wi.getApplicationList()));
	}
	if (ListTools.isNotEmpty(wi.getProcessList())) {
		p = cb.and(p, root.get(Read_.process).in(wi.getProcessList()));
	}
	if(DateTools.isDateTimeOrDate(wi.getStartTime())){
		p = cb.and(p, cb.greaterThan(root.get(Read_.startTime), DateTools.parse(wi.getStartTime())));
	}
	if(DateTools.isDateTimeOrDate(wi.getEndTime())){
		p = cb.and(p, cb.lessThan(root.get(Read_.startTime), DateTools.parse(wi.getEndTime())));
	}
	if (ListTools.isNotEmpty(person_ids)) {
		p = cb.and(p, root.get(Read_.person).in(person_ids));
	}
	if (ListTools.isNotEmpty(wi.getCreatorUnitList())) {
		p = cb.and(p, root.get(Read_.creatorUnit).in(wi.getCreatorUnitList()));
	}
	if (ListTools.isNotEmpty(wi.getWorkList())) {
		p = cb.and(p, root.get(Read_.work).in(wi.getWorkList()));
	}
	if (ListTools.isNotEmpty(wi.getJobList())) {
		p = cb.and(p, root.get(Read_.job).in(wi.getJobList()));
	}
	if (ListTools.isNotEmpty(wi.getStartTimeMonthList())) {
		p = cb.and(p, root.get(Read_.startTimeMonth).in(wi.getStartTimeMonthList()));
	}
	if (ListTools.isNotEmpty(wi.getActivityNameList())) {
		p = cb.and(p, root.get(Read_.activityName).in(wi.getActivityNameList()));
	}
	if (StringUtils.isNotEmpty(wi.getKey())) {
		String key = StringUtils.trim(StringUtils.replace(wi.getKey(), "\u3000", " "));
		if (StringUtils.isNotEmpty(key)) {
			key = StringUtils.replaceEach(key, new String[] { "?", "%" }, new String[] { "", "" });
			p = cb.and(p,
					cb.or(cb.like(root.get(Read_.title), "%" + key + "%"),
							cb.like(root.get(Read_.opinion), "%" + key + "%"),
							cb.like(root.get(Read_.serial), "%" + key + "%"),
							cb.like(root.get(Read_.creatorPerson), "%" + key + "%"),
							cb.like(root.get(Read_.creatorUnit), "%" + key + "%")));
		}
	}
	cq.select(root).where(p).orderBy(cb.desc(root.get(Read_.startTime)));
	return em.createQuery(cq).setFirstResult((adjustPage - 1) * adjustPageSize).setMaxResults(adjustPageSize)
			.getResultList();
}
 
Example 16
Source File: ActionManageListPrevFilter.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String id, Integer count, JsonElement jsonElement)
		throws Exception {
	ActionResult<List<Wo>> result = new ActionResult<>();
	Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		Business business = new Business(emc);
		List<String> person_ids = business.organization().person().list(wi.getCredentialList());
		EqualsTerms equals = new EqualsTerms();
		InTerms ins = new InTerms();
		LikeTerms likes = new LikeTerms();
		if (ListTools.isNotEmpty(wi.getApplicationList())) {
			ins.put(Task.application_FIELDNAME, wi.getApplicationList());
		}
		if (ListTools.isNotEmpty(wi.getProcessList())) {
			ins.put(Task.process_FIELDNAME, wi.getProcessList());
		}
		if (ListTools.isNotEmpty(person_ids)) {
			ins.put(Task.person_FIELDNAME, person_ids);
		}
		if (ListTools.isNotEmpty(wi.getCreatorUnitList())) {
			ins.put(Task.creatorUnit_FIELDNAME, wi.getCreatorUnitList());
		}
		if (ListTools.isNotEmpty(wi.getStartTimeMonthList())) {
			ins.put(Task.startTimeMonth_FIELDNAME, wi.getStartTimeMonthList());
		}
		if (ListTools.isNotEmpty(wi.getActivityNameList())) {
			ins.put(Task.activityName_FIELDNAME, wi.getActivityNameList());
		}
		if (StringUtils.isNotEmpty(wi.getKey())) {
			String key = StringUtils.trim(StringUtils.replace(wi.getKey(), "\u3000", " "));
			if (StringUtils.isNotEmpty(key)) {
				likes.put(Task.title_FIELDNAME, key);
				likes.put(Task.opinion_FIELDNAME, key);
				likes.put(Task.serial_FIELDNAME, key);
				likes.put(Task.creatorPerson_FIELDNAME, key);
				likes.put(Task.creatorUnit_FIELDNAME, key);
			}
		}
		if (effectivePerson.isManager()) {
			result = this.standardListPrev(Wo.copier, id, count, Task.sequence_FIELDNAME, equals, null, likes, ins, null,
					null, null, null, true, DESC);
		}
		return result;
	}
}
 
Example 17
Source File: ActionManageListPrevWithFilter.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String id, Integer count, String applicationFlag,
		JsonElement jsonElement) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		ActionResult<List<Wo>> result = new ActionResult<>();
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		Business business = new Business(emc);
		EqualsTerms equals = new EqualsTerms();
		InTerms ins = new InTerms();
		LikeTerms likes = new LikeTerms();
		Application application = business.application().pick(applicationFlag);
		if (null == application) {
			throw new ExceptionApplicationNotExist(applicationFlag);
		}
		equals.put("application", application.getId());
		if (ListTools.isNotEmpty(wi.getProcessList())) {
			ins.put("process", wi.getProcessList());
		}
		if (ListTools.isNotEmpty(wi.getCreatorUnitList())) {
			ins.put("creatorUnit", wi.getCreatorUnitList());
		}
		if (ListTools.isNotEmpty(wi.getStartTimeMonthList())) {
			ins.put("startTimeMonth", wi.getStartTimeMonthList());
		}
		if (ListTools.isNotEmpty(wi.getActivityNameList())) {
			ins.put("activityName", wi.getActivityNameList());
		}
		if (ListTools.isNotEmpty(wi.getWorkStatusList())) {
			ins.put("workStatus", wi.getWorkStatusList());
		}
		if (StringUtils.isNotEmpty(wi.getKey())) {
			String key = StringUtils.trim(StringUtils.replace(wi.getKey(), "\u3000", " "));
			if (StringUtils.isNotEmpty(key)) {
				likes.put("title", key);
				likes.put("serial", key);
				likes.put("creatorPerson", key);
				likes.put("creatorUnit", key);
			}
		}
		result = this.standardListPrev(Wo.copier, id, count,  JpaObject.sequence_FIELDNAME, equals, null, likes, ins, null, null, null,
				null, true, DESC);
		/* 添加权限 */
		if (null != result.getData()) {
			for (Wo wo : result.getData()) {
				Work o = emc.find(wo.getId(), Work.class);
				WorkControl control = business.getControl(effectivePerson, o, WoControl.class);
				wo.setControl(control);
			}
		}
		return result;
	}
}
 
Example 18
Source File: ActionListPrevWithFilter.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
protected ActionResult<List<Wo>> execute(HttpServletRequest request, EffectivePerson effectivePerson, String id,
		Integer count, String appId, JsonElement jsonElement) throws Exception {
	ActionResult<List<Wo>> result = new ActionResult<>();
	EqualsTerms equals = new EqualsTerms();
	LikeTerms likes = new LikeTerms();
	Wi wrapIn = null;
	Boolean check = true;
	WrapCopier<Form, Wo> copier = WrapCopierFactory.wo(Form.class, Wo.class, null, Wo.Excludes);
	try {
		wrapIn = this.convertToWrapIn(jsonElement, Wi.class);
	} catch (Exception e) {
		check = false;
		Exception exception = new ExceptionWrapInConvert(e, jsonElement);
		result.error(exception);
		logger.error(e, effectivePerson, request, null);
	}
	if (check) {
		try {
			equals.put("appId", appId);
			if ((null != wrapIn.getCategoryIdList()) && (!wrapIn.getCategoryIdList().isEmpty())) {
				equals.put("categoryId", wrapIn.getCategoryIdList().get(0));
			}
			if ((null != wrapIn.getCreatorList()) && (!wrapIn.getCreatorList().isEmpty())) {
				equals.put("creatorUid", wrapIn.getCreatorList().get(0));
			}
			if ((null != wrapIn.getStatusList()) && (!wrapIn.getStatusList().isEmpty())) {
				equals.put("docStatus", wrapIn.getStatusList().get(0));
			}
			if (StringUtils.isNotEmpty(wrapIn.getKey())) {
				String key = StringUtils.trim(StringUtils.replace(wrapIn.getKey(), "\u3000", " "));
				if (StringUtils.isNotEmpty(key)) {
					likes.put("title", key);
				}
			}
			result = this.standardListPrev(copier, id, count, "sequence", equals, null, likes, null, null, null,
					null, null, true, DESC);
		} catch (Throwable th) {
			th.printStackTrace();
			result.error(th);
		}
	}
	return result;
}
 
Example 19
Source File: TdSpi.java    From redtorch with MIT License 4 votes vote down vote up
public void OnRtnTrade(CThostFtdcTradeField pTrade) {
	try {

		String exchangeAndOrderSysId = pTrade.getExchangeID() + "@" + pTrade.getOrderSysID();

		String orderId = exchangeIdAndOrderSysIdToOrderIdMap.getOrDefault(exchangeAndOrderSysId, "");
		String adapterOrderId = orderIdToAdapterOrderIdMap.getOrDefault(orderId, "");

		String symbol = pTrade.getInstrumentID();
		DirectionEnum direction = CtpConstant.directionMapReverse.getOrDefault(pTrade.getDirection(), DirectionEnum.D_Unknown);
		String adapterTradeId = adapterOrderId + "@" + direction.getValueDescriptor().getName() + "@" + StringUtils.trim(pTrade.getTradeID());
		String tradeId = gatewayId + "@" + adapterTradeId;
		OffsetFlagEnum offsetFlag = CtpConstant.offsetMapReverse.getOrDefault(pTrade.getOffsetFlag(), OffsetFlagEnum.OF_Unkonwn);
		double price = pTrade.getPrice();
		int volume = pTrade.getVolume();
		String tradeDate = pTrade.getTradeDate();
		String tradeTime = pTrade.getTradeTime();

		HedgeFlagEnum hedgeFlag = CtpConstant.hedgeFlagMapReverse.getOrDefault(String.valueOf(pTrade.getHedgeFlag()), HedgeFlagEnum.HF_Unknown);
		TradeTypeEnum tradeType = CtpConstant.tradeTypeMapReverse.getOrDefault(pTrade.getTradeType(), TradeTypeEnum.TT_Unkonwn);
		PriceSourceEnum priceSource = CtpConstant.priceSourceMapReverse.getOrDefault(pTrade.getPriceSource(), PriceSourceEnum.PSRC_Unkonwn);

		String orderLocalId = pTrade.getOrderLocalID();
		String orderSysId = pTrade.getOrderSysID();
		String sequenceNo = pTrade.getSequenceNo() + "";
		String brokerOrderSeq = pTrade.getBrokerOrderSeq() + "";
		String settlementID = pTrade.getSettlementID() + "";

		String originalOrderId = orderIdToOriginalOrderIdMap.getOrDefault(orderId, "");

		// 无法获取账户信息,使用userId作为账户ID
		String accountCode = userId;
		// 无法获取币种信息使用特定值CNY
		String accountId = accountCode + "@CNY@" + gatewayId;

		TradeField.Builder tradeBuilder = TradeField.newBuilder();

		tradeBuilder.setAccountId(accountId);
		tradeBuilder.setAdapterOrderId(adapterOrderId);
		tradeBuilder.setAdapterTradeId(adapterTradeId);
		tradeBuilder.setTradeDate(tradeDate);
		tradeBuilder.setTradeId(tradeId);
		tradeBuilder.setTradeTime(tradeTime);
		tradeBuilder.setTradingDay(tradingDay);
		tradeBuilder.setDirection(direction);
		tradeBuilder.setOffsetFlag(offsetFlag);
		tradeBuilder.setOrderId(orderId);
		tradeBuilder.setOriginOrderId(originalOrderId);
		tradeBuilder.setPrice(price);
		tradeBuilder.setVolume(volume);
		tradeBuilder.setGatewayId(gatewayId);
		tradeBuilder.setOrderLocalId(orderLocalId);
		tradeBuilder.setOrderSysId(orderSysId);
		tradeBuilder.setSequenceNo(sequenceNo);
		tradeBuilder.setBrokerOrderSeq(brokerOrderSeq);
		tradeBuilder.setSettlementId(settlementID);
		tradeBuilder.setHedgeFlag(hedgeFlag);
		tradeBuilder.setTradeType(tradeType);
		tradeBuilder.setPriceSource(priceSource);

		if (instrumentQueried && ctpGatewayImpl.contractMap.containsKey(symbol)) {
			tradeBuilder.setContract(ctpGatewayImpl.contractMap.get(symbol));
			ctpGatewayImpl.emitTrade(tradeBuilder.build());
		} else {
			ContractField.Builder contractBuilder = ContractField.newBuilder();
			contractBuilder.setSymbol(symbol);

			tradeBuilder.setContract(contractBuilder);
			tradeBuilderCacheList.add(tradeBuilder);
		}

	} catch (Throwable t) {
		logger.error("{}OnRtnTrade Exception", logInfo, t);
	}

}
 
Example 20
Source File: IndexController.java    From config-toolkit with Apache License 2.0 3 votes vote down vote up
@PostMapping(value = "/group/{version:.+}")
public ModelAndView createGroup(@PathVariable String version, String newGroup) {
    version = StringUtils.trim(version);
    newGroup = StringUtils.trim(newGroup.trim());

    final String root = getRoot();

    final String groupPath = makePaths(root, version, newGroup);

    nodeService.createProperty(groupPath);

    return new ModelAndView("redirect:/version/" + version);
}