protected String getDepKey(String groupId, String artifactId) { return StringUtils.concat(groupId, "/", artifactId); }
@SuppressWarnings("unchecked") public AbstractService() { primaryKeyType = (Class<PK>) ClassUtils.getGenericType(this.getClass(), 1); entityType = (Class<E>) ClassUtils.getGenericType(this.getClass(), 0); }
protected String[] decodeBase64EncodedCredentials(String encodedCredentials) { String decodedCredentials = new String(Base64.getDecoder().decode(encodedCredentials)); String[] credentials = decodedCredentials.split(":", 2); return credentials.length != 2 ? null : (!StringUtils.isNullOrEmpty(credentials[0]) && !StringUtils.isNullOrEmpty(credentials[1]) ? credentials : null); } }
protected boolean genericTypeInstanceOf(Class type, AuthorizingContext context) { Class entity = ClassUtils.getGenericType(context.getParamContext().getTarget().getClass()); return null != entity && ClassUtils.instanceOf(entity, type); } }
@Override public Object getValue(Object data) { if (multi) { if (dataToMask) { Long mask = null; if (org.hswebframework.utils.StringUtils.isNumber(data)) { mask = org.hswebframework.utils.StringUtils.toLong(data); } if (mask != null) { return multiValueConvert .apply(EnumDict.getByMask(allOptionSupplier, mask) .stream() .map(EnumDict::getValue) .map(String::valueOf)); } } List<Object> lst = splitter.apply(String.valueOf(data)); return multiValueConvert .apply(allOptionSupplier.get() .stream() .filter(e -> e.eq(lst)) .map(EnumDict::getValue) .map(String::valueOf)); } return data; }
protected void applyPath(E entity) { if (StringUtils.isEmpty(entity.getParentId())) { if (entity.getSortIndex() == null) { entity.setSortIndex(0L); } entity.setParentId(createParentIdOnExists()); entity.setLevel(0); entity.setPath(RandomUtil.randomChar(4)); return; } if (!StringUtils.isEmpty(entity.getPath())) { return; } TreeSortSupportEntity<PK> parent = selectByPk(entity.getParentId()); if (null == parent) { if (entity.getSortIndex() == null) { entity.setSortIndex(0L); } entity.setParentId(createParentIdOnExists()); entity.setPath(RandomUtil.randomChar(4)); entity.setLevel(0); } else { if (entity.getSortIndex() == null && parent.getSortIndex() != null) { entity.setSortIndex(parent.getSortIndex() * 10); } entity.setPath(parent.getPath() + "-" + RandomUtil.randomChar(4)); entity.setLevel(entity.getPath().split("[-]").length); } }
private String createGetPropertyCode(TableMetaData tableMetaData) { StringBuilder builder = new StringBuilder(); int index = 0; builder.append("public Object getProperty(String property){\n"); for (ColumnMetaData column : tableMetaData.getColumns()) { String propertyName = column.getAlias(); if (index++ > 0) { builder.append("\nelse "); } builder.append("if(property.intern()==\"") .append(propertyName) .append("\"||property.intern()==\"") .append(column.getName()) .append("\"){\n") .append("return this.get") .append(StringUtils.toUpperCaseFirstOne(propertyName)) .append("();") .append("\n}"); } builder.append("\nreturn null;\n}"); return builder.toString(); }
public void setVersion(String version) { if (null == version) { return; } boolean snapshot = version.toLowerCase().contains("snapshot"); version = version.toLowerCase() .replace(".snapshot", "") .replace("-snapshot", "") .replace("-rc", "") .replace("-release", ""); String[] ver = version.split("[.]"); Integer[] numberVer = ListUtils.stringArr2intArr(ver); if (numberVer.length < 1 || Arrays.stream(numberVer).anyMatch(Objects::isNull)) { numberVer = new Integer[]{1, 0, 0}; log.warn("解析版本号失败:{},将使用默认版本号:1.0.0,请检查hsweb-starter.js配置内容!", version); } setVersion(numberVer[0], numberVer.length <= 1 ? 0 : numberVer[1], numberVer.length <= 2 ? 0 : numberVer[2], snapshot); }
protected Class<Entity> getClass(String basePackage, String name) { if (!StringUtils.isNullOrEmpty(basePackage)) { name = basePackage.concat(".").concat(name); } return classForName(name); }
public AbstractOAuth2CrudService() { entityType = (Class) ClassUtils.getGenericType(this.getClass(), 0); primaryKeyType = (Class) ClassUtils.getGenericType(this.getClass(), 1); }
private String createSetPropertyCode(TableMetaData tableMetaData) { StringBuilder builder = new StringBuilder(); builder.append("public void setProperty(String property,Object value){\n"); int index = 0; for (ColumnMetaData column : tableMetaData.getColumns()) { String propertyName = column.getAlias(); Class type = column.getJavaType(); if (index++ > 0) { builder.append("\nelse "); } builder.append("if(property.intern()==\"") .append(propertyName) .append("\"||property.intern()==\"") .append(column.getName()).append("\"){\n") .append("this.set") .append(StringUtils.toUpperCaseFirstOne(propertyName)) .append("((").append(type.getName()).append(")") .append("org.hswebframework.web.bean.FastBeanCopier.DEFAULT_CONVERT.convert(value,") .append(type.getName()) .append(".class,null));") .append("\n}"); } builder.append("}"); return builder.toString(); }
protected String[] decodeClientAuthenticationHeader(String authenticationHeader) { if (StringUtils.isNullOrEmpty(authenticationHeader)) { return null; } else { String[] tokens = authenticationHeader.split(" "); if (tokens.length != 2) { return null; } else { String authType = tokens[0]; if (!"basic".equalsIgnoreCase(authType)) { return ErrorType.OTHER.throwThis(GrantTokenException::new, "authentication " + authType + " not support!"); } else { String encodedCreds = tokens[1]; return decodeBase64EncodedCredentials(encodedCreds); } } } }
public MapperEntityFactory addCopier(PropertyCopier copier) { Class source = ClassUtils.getGenericType(copier.getClass(), 0); Class target = ClassUtils.getGenericType(copier.getClass(), 1); if (source == null || source == Object.class) { throw new UnsupportedOperationException("generic type " + source + " not support"); } if (target == null || target == Object.class) { throw new UnsupportedOperationException("generic type " + target + " not support"); } addCopier(source, target, copier); return this; }
public String converter(Object obj) { if (obj instanceof String) { return (String) obj; } String text; String callback = ThreadLocalUtils.getAndRemove("jsonp-callback"); if (obj instanceof ResponseMessage) { ResponseMessage message = (ResponseMessage) obj; // if (dictSupportApi != null) { // message.setResult(dictSupportApi.wrap(message.getResult())); // } text = JSON.toJSONString(obj, FastJsonHttpMessageConverter.parseFilter(message), features); } else { // if (dictSupportApi != null) { // obj = dictSupportApi.wrap(obj); // } text = JSON.toJSONString(obj, features); } if (!StringUtils.isNullOrEmpty(callback)) { text = new StringBuilder() .append(callback) .append("(").append(text).append(")") .toString(); } return text; }
@Override @SuppressWarnings("unchecked") public void registerListener(String serverId, OAuth2Listener<? extends OAuth2Event> listener) { Class type = ClassUtils.getGenericType(listener.getClass()); listenerStore.computeIfAbsent(serverId, k -> new HashMap<>()) .computeIfAbsent(type, k -> new ArrayList<>()) .add(listener); }
public String converter(Object obj) { if (obj instanceof String) { return (String) obj; } String text; String callback = ThreadLocalUtils.getAndRemove("jsonp-callback"); if (obj instanceof ResponseMessage) { ResponseMessage message = (ResponseMessage) obj; // if (dictSupportApi != null) { // message.setResult(dictSupportApi.wrap(message.getResult())); // } text = JSON.toJSONString(obj, parseFilter(message), features); } else { // if (dictSupportApi != null) { // obj = dictSupportApi.wrap(obj); // } text = JSON.toJSONString(obj, features); } if (!StringUtils.isNullOrEmpty(callback)) { text = new StringBuilder() .append(callback) .append("(").append(text).append(")") .toString(); } return text; }
public HttpTokenRequest(HttpServletRequest request) { this.parameters = WebUtil.getParameters(request); this.headers = WebUtil.getHeaders(request); String clientId = parameters.get(OAuth2Constants.client_id); String clientSecret = parameters.get(OAuth2Constants.client_secret); String authorization = headers.get(OAuth2Constants.authorization); clientCredentials = getClientCredentials(clientId, clientSecret, authorization); this.scope = getParameter(OAuth2Constants.scope) .filter(scopeStr -> !StringUtils.isNullOrEmpty(scopeStr)) .map(scopeStr -> new HashSet<>(Arrays.asList(scopeStr.split("[, \n]")))) .orElseGet(HashSet::new); }
@Override public List<DictionaryItemEntity> selectByDictId(String dictId) { if (StringUtils.isNullOrEmpty(dictId)) { return new java.util.ArrayList<>(); } return createQuery() .where(DictionaryItemEntity.dictId, dictId) .orderByAsc(DictionaryItemEntity.sortIndex) .listNoPaging(); }
@Override public Map<String, Object> getVariablesByProcInstId(String procInstId) { List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(procInstId).list(); String executionId = ""; for (Execution execution : executions) { if (StringUtils.isNullOrEmpty(execution.getParentId())) { executionId = execution.getId(); } } return runtimeService.getVariables(executionId); }
@Override public void claim(String taskId, String userId) { Task task = taskService.createTaskQuery(). taskId(taskId) .taskCandidateUser(userId) .active() .singleResult(); if (task == null) { throw new NotFoundException("无法签收此任务"); } if (!StringUtils.isNullOrEmpty(task.getAssignee())) { throw new BusinessException("任务已签售"); } else { taskService.claim(taskId, userId); } }