Java Code Examples for org.restlet.data.Form#getNames()

The following examples show how to use org.restlet.data.Form#getNames() . 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: TicketResource.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
/**
 * Log the form request.
 *
 * @param form the form
 */
private void logFormRequest(final Form form) {
    if (LOGGER.isDebugEnabled()) {
        final Set<String> pairs = new HashSet<>();
        for (final String name : form.getNames()) {
            final StringBuilder builder = new StringBuilder();
            builder.append(name);
            builder.append(": ");
            if (!"password".equalsIgnoreCase(name)) {
                builder.append(form.getValues(name));
            } else {
                builder.append("*****");
            }
            pairs.add(builder.toString());
        }
        LOGGER.debug(StringUtils.join(pairs, ", "));
    }
}
 
Example 2
Source File: TicketResource.java    From cas4.0.x-server-wechat with Apache License 2.0 6 votes vote down vote up
private void logFormRequest(final Form form) {
    if (LOGGER.isDebugEnabled()) {
        final Set<String> pairs = new HashSet<String>();
        for (final String name : form.getNames()) {
            final StringBuilder builder = new StringBuilder();
            builder.append(name);
            builder.append(": ");
            if (!"password".equalsIgnoreCase(name)) {
                builder.append(form.getValues(name));
            } else {
                builder.append("*****");
            }
            pairs.add(builder.toString());
        }
        LOGGER.debug(StringUtils.join(pairs, ", "));
    }
}
 
Example 3
Source File: AbstractRestResource.java    From FoxBPM with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化分页处理
 */
protected void initPage() {
	Form queryForm = getQuery();
	Set<String> queryNames = queryForm.getNames();
	if (queryNames.contains(RestConstants.PAGE_START)) {
		if (queryNames.contains(RestConstants.PAGE_LENGTH)) {
			pageSize = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_LENGTH, queryForm));
		}
		pageIndex = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_START, queryForm)) / pageSize + 1;
	}
	
	if (queryNames.contains(RestConstants.PAGE_INDEX)) {
		pageIndex = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_INDEX, queryForm));
	}
	if (queryNames.contains(RestConstants.PAGE_SIZE)) {
		pageSize = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_SIZE, queryForm));
	}
}
 
Example 4
Source File: AbstractRestResource.java    From FoxBPM with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化分页处理
 */
protected void initPage() {
	Form queryForm = getQuery();
	Set<String> queryNames = queryForm.getNames();
	if (queryNames.contains(RestConstants.PAGE_START)) {
		if (queryNames.contains(RestConstants.PAGE_LENGTH)) {
			pageSize = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_LENGTH, queryForm));
		}
		pageIndex = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_START, queryForm)) / pageSize + 1;
	}
	
	if (queryNames.contains(RestConstants.PAGE_INDEX)) {
		pageIndex = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_INDEX, queryForm));
	}
	if (queryNames.contains(RestConstants.PAGE_SIZE)) {
		pageSize = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_SIZE, queryForm));
	}
}
 
Example 5
Source File: ProcessDefinitionCollectionResouce.java    From FoxBPM with Apache License 2.0 5 votes vote down vote up
@Get
public DataResult getDefinitions() {
	ProcessEngine engine = ProcessEngineManagement.getDefaultProcessEngine();
	ProcessDefinitionQuery processDefinitionQuery = engine.getModelService().createProcessDefinitionQuery();
	Form query = getQuery();
	Set<String> names = query.getNames();
	if (names.contains(RestConstants.CATEGORY)) {
		processDefinitionQuery.processDefinitionCategory(getQueryParameter(RestConstants.CATEGORY, query));
	}
	if (names.contains(RestConstants.PROCESS_KEY)) {
		processDefinitionQuery.processDefinitionKey(getQueryParameter(RestConstants.PROCESS_KEY, query));
	}
	if (names.contains(RestConstants.NAME)) {
		processDefinitionQuery.processDefinitionName(getQueryParameter(RestConstants.NAME, query));
	}
	if (names.contains(RestConstants.NAME_LIKE)) {
		processDefinitionQuery.processDefinitionNameLike(parseLikeValue(getQueryParameter(RestConstants.NAME_LIKE, query)));
	}

	List<ProcessDefinition> processDefinitions = processDefinitionQuery.list();
	List<Map<String,Object>> results = new ArrayList<Map<String,Object>>();
	for (ProcessDefinition process : processDefinitions) {
		Map<String,Object> processAttrMap = process.getPersistentState();
		processAttrMap.put("description", process.getDescription());
		results.add(processAttrMap);
	}
	DataResult result = new DataResult();
	result.setData(results);
	result.setTotal(processDefinitions.size());
	return result;
}
 
Example 6
Source File: UserCollectionResouce.java    From FoxBPM with Apache License 2.0 5 votes vote down vote up
@Get
public DataResult getAllUsers() {
	Form query = getQuery();
	Set<String> names = query.getNames();
	String userName = null;
	String userId = null;
	if (names.contains("userName")) {
		String tmpUserName = getQueryParameter("userName", query);
		if(StringUtil.isNotEmpty(tmpUserName))
			userName = "%"+tmpUserName+"%";
	}
	if (names.contains("userId")) {
		String tmpUserId = getQueryParameter("userId", query);
		if(StringUtil.isNotEmpty(tmpUserId))
			userId = "%"+tmpUserId+"%";
	}
	List<UserEntity> users = FoxBpmUtil.getProcessEngine().getIdentityService().getUsers(userId, userName);
	// 数据转换
	List<Map<String, Object>> resultDatas = new ArrayList<Map<String, Object>>();
	for (UserEntity user : users) {
		resultDatas.add(user.getPersistentState());
	}
	// 数据响应体构造
	DataResult result = new DataResult();
	result.setData(resultDatas);
	result.setTotal(users.size());
	return result;
}
 
Example 7
Source File: CalendarPartCollectionResource.java    From FoxBPM with Apache License 2.0 5 votes vote down vote up
@Get
public DataResult getCalendarParts(){
	
	Form queryForm = getQuery();
	Set<String> queryNames = queryForm.getNames();
	
	String id = StringUtil.getString(getQueryParameter("id", queryForm));
	
	String idLike = null;
	if (StringUtil.isNotEmpty(id)) {
		idLike = "%" + id + "%";
	}
	
	if (queryNames.contains(RestConstants.PAGE_START)) {
		if (queryNames.contains(RestConstants.PAGE_LENGTH)) {
			pageSize = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_LENGTH, queryForm));
		}
		pageIndex = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_START, queryForm)) / pageSize + 1;
	}
	
	if (queryNames.contains(RestConstants.PAGE_INDEX)) {
		pageIndex = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_INDEX, queryForm));
	}
	if (queryNames.contains(RestConstants.PAGE_SIZE)) {
		pageSize = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_SIZE, queryForm));
	}
	
	WorkCalendarService workCalendarService = ProcessEngineManagement.getDefaultProcessEngine().getService(WorkCalendarService.class);
	
	DataResult result = new DataResult();
	result.setData(workCalendarService.getCalendarPart(pageIndex, pageSize, idLike));
	result.setPageIndex(pageIndex);
	result.setPageSize(pageSize);
	result.setRecordsTotal(workCalendarService.getCalendarPartCount(idLike));
	result.setRecordsFiltered(workCalendarService.getCalendarPartCount(idLike));
	return result;
}
 
Example 8
Source File: AbstractRestResource.java    From FoxBPM with Apache License 2.0 5 votes vote down vote up
/**
 * foxbpm rest接口的分页机制 接收参数: start:起始行数 lenth:每页条数 pageIndex:当前页
 * pageSize:每页条数 冲突解决:优先处理pageIndex、pageSize
 * 
 * @param query
 * @return
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public DataResult paginateList(Query query) {
	
	Form queryForm = getQuery();
	Set<String> queryNames = queryForm.getNames();
	
	if (queryNames.contains(RestConstants.PAGE_START)) {
		if (queryNames.contains(RestConstants.PAGE_LENGTH)) {
			pageSize = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_LENGTH, queryForm));
		}
		pageIndex = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_START, queryForm)) / pageSize + 1;
	}
	
	if (queryNames.contains(RestConstants.PAGE_INDEX)) {
		pageIndex = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_INDEX, queryForm));
	}
	if (queryNames.contains(RestConstants.PAGE_SIZE)) {
		pageSize = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_SIZE, queryForm));
	}
	
	List<PersistentObject> resultObjects = query.listPagination(pageIndex, pageSize);
	List<Map<String, Object>> dataMap = new ArrayList<Map<String, Object>>();
	if (resultObjects != null) {
		Iterator<PersistentObject> iterator = resultObjects.iterator();
		while (iterator.hasNext()) {
			dataMap.add(iterator.next().getPersistentState());
		}
	}
	
	long resultCount = query.count();
	DataResult result = new DataResult();
	result.setData(dataMap);
	result.setPageIndex(pageIndex);
	result.setPageSize(pageSize);
	result.setRecordsTotal(resultCount);
	result.setRecordsFiltered(resultCount);
	return result;
}
 
Example 9
Source File: RequestParametersForm.java    From geowave with Apache License 2.0 5 votes vote down vote up
public RequestParametersForm(final Form form) {
  super();
  for (final String key : form.getNames()) {
    // For each parameter in the form, add the parameter name and value
    // to the Map<String, Object>.
    keyValuePairs.put(key, form.getFirst(key).getValue());
  }
}
 
Example 10
Source File: ProcessInstanceCollectionResource.java    From FoxBPM with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Get
public DataResult getProcessInstance(){
	if(!validationUser())
		return null;
	Form queryForm = getQuery();
	Set<String> queryNames = queryForm.getNames();
	
	RuntimeService runtimeService = FoxBpmUtil.getProcessEngine().getRuntimeService();
	ProcessInstanceQuery processIntanceQuery = runtimeService.createProcessInstanceQuery();
	if(queryNames.contains(RestConstants.PARTICIPATE)){
		String participate = StringUtil.getString(getQueryParameter(RestConstants.PARTICIPATE, queryForm));
		processIntanceQuery.taskParticipants(participate);
	}
	if(queryNames.contains(RestConstants.INITIATOR)){
		String initotor = StringUtil.getString(getQueryParameter(RestConstants.INITIATOR, queryForm));
		processIntanceQuery.initiator(initotor);
	}
	
	if(queryNames.contains(RestConstants.PROCESS_KEY)){
		processIntanceQuery.processDefinitionKey(getQueryParameter(RestConstants.PROCESS_KEY, queryForm));
	}
	
	if(queryNames.contains(RestConstants.NAME_LIKE)){
		processIntanceQuery.processDefinitionNameLike(parseLikeValue(getQueryParameter(RestConstants.NAME_LIKE, queryForm)));
	}
	
	if(queryNames.contains(RestConstants.PROCESSINSTANCE_ID)){
		processIntanceQuery.processInstanceId(getQueryParameter(RestConstants.PROCESSINSTANCE_ID, queryForm));
	}
	
	if(queryNames.contains(RestConstants.PROCESS_ID)){
		processIntanceQuery.processDefinitionId(getQueryParameter(RestConstants.PROCESS_ID, queryForm));
	}
	
	if(queryNames.contains(RestConstants.BIZKEY_LIKE)){
		processIntanceQuery.processInstanceBusinessKeyLike(parseLikeValue(getQueryParameter(RestConstants.BIZKEY_LIKE, queryForm)));
	}
	
	if(queryNames.contains("subjectLike")){
		processIntanceQuery.subjectLike(parseLikeValue(getQueryParameter("subjectLike", queryForm)));
	}
	
	processIntanceQuery.subjectUnionInitiator();
	if(queryNames.contains("ended")){
		boolean ended = StringUtil.getBoolean(getQueryParameter("ended", queryForm));
		if(ended){
			processIntanceQuery.isEnd();
		}else{
			processIntanceQuery.notEnd();
		}
	}
	
	if(queryNames.contains("status")){
		processIntanceQuery.processInstanceStatus(getQueryParameter("status", queryForm));
	}
	processIntanceQuery.orderByUpdateTime().desc();
	
	DataResult result = paginateList(processIntanceQuery);
	
	List<Map<String,Object>> mapList = (List<Map<String,Object>>)result.getData();
	if(mapList != null && mapList.size()>0){
		for(Map<String,Object> tmp : mapList){
			String initator = StringUtil.getString(tmp.get("initiator"));
			String initatorName = getUserName(initator);
			tmp.put("initatorName", initatorName);
			String processLocation = StringUtil.getString(tmp.get("processLocation"));
			String processLocationString = LocationUtil.parseProcessLocation(processLocation);
			tmp.put("processLocationString", processLocationString);
		}
	}
	return result;
}
 
Example 11
Source File: AbstractRestResource.java    From FoxBPM with Apache License 2.0 4 votes vote down vote up
/**
 * foxbpm rest接口的分页机制 接收参数: start:起始行数 lenth:每页条数 pageIndex:当前页
 * pageSize:每页条数 冲突解决:优先处理pageIndex、pageSize 默认降序排列
 * 
 * @param query
 * @param properties
 *            支持的排序字段
 * @param defaultOrderBy
 *            默认排序字段
 * @return
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public DataResult paginateList(Query query, Map<String, QueryProperty> properties, String defaultOrderBy) {
	
	Form queryForm = getQuery();
	Set<String> queryNames = queryForm.getNames();
	
	if (properties != null) {
		String orderby = StringUtil.getString(getQueryParameter(RestConstants.ORDERBY, queryForm));
		if (StringUtil.isEmpty(orderby)) {
			orderby = defaultOrderBy;
		}
		QueryProperty orderByProPerty = properties.get(orderby);
		if (orderByProPerty == null) {
			throw new FoxbpmPluginException("不支持的排序字段:" + orderby,"Rest服务");
		}
		((AbstractQuery) query).orderBy(orderByProPerty);
		
		String sort = StringUtil.getString(getQueryParameter(RestConstants.SORT, queryForm));
		if (StringUtil.isEmpty(sort)) {
			sort = "desc";
		}
		if ("asc".equals(sort)) {
			((AbstractQuery) query).asc();
		} else {
			((AbstractQuery) query).desc();
		}
	}
	
	if (queryNames.contains(RestConstants.PAGE_START)) {
		if (queryNames.contains(RestConstants.PAGE_LENGTH)) {
			pageSize = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_LENGTH, queryForm));
		}
		pageIndex = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_START, queryForm)) / pageSize + 1;
	}
	
	if (queryNames.contains(RestConstants.PAGE_INDEX)) {
		pageIndex = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_INDEX, queryForm));
	}
	if (queryNames.contains(RestConstants.PAGE_SIZE)) {
		pageSize = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_SIZE, queryForm));
	}
	
	List<PersistentObject> resultObjects = null;
	if (pageIndex == -1) {
		resultObjects = query.list();
	} else {
		resultObjects = query.listPagination(pageIndex, pageSize);
	}
	List<Map<String, Object>> dataMap = new ArrayList<Map<String, Object>>();
	if (resultObjects != null) {
		Iterator<PersistentObject> iterator = resultObjects.iterator();
		while (iterator.hasNext()) {
			dataMap.add(iterator.next().getPersistentState());
		}
	}
	
	long resultCount = query.count();
	DataResult result = new DataResult();
	result.setData(dataMap);
	result.setPageIndex(pageIndex);
	result.setPageSize(pageSize);
	result.setRecordsTotal(resultCount);
	result.setRecordsFiltered(resultCount);
	return result;
}
 
Example 12
Source File: CalendarRuleCollectionResource.java    From FoxBPM with Apache License 2.0 4 votes vote down vote up
@Get
public DataResult getCalendarRules(){
	
	Form queryForm = getQuery();
	Set<String> queryNames = queryForm.getNames();
	
	String id = StringUtil.getString(getQueryParameter("id", queryForm));
	String name = StringUtil.getString(getQueryParameter("name", queryForm));
	
	String idLike = null;
	String nameLike = null;
	if (StringUtil.isNotEmpty(id)) {
		idLike = "%" + id + "%";
	}
	if (StringUtil.isNotEmpty(name)) {
		nameLike = "%" + name + "%";
	}
	
	if (queryNames.contains(RestConstants.PAGE_START)) {
		if (queryNames.contains(RestConstants.PAGE_LENGTH)) {
			pageSize = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_LENGTH, queryForm));
		}
		pageIndex = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_START, queryForm)) / pageSize + 1;
	}
	
	if (queryNames.contains(RestConstants.PAGE_INDEX)) {
		pageIndex = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_INDEX, queryForm));
	}
	if (queryNames.contains(RestConstants.PAGE_SIZE)) {
		pageSize = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_SIZE, queryForm));
	}
	
	WorkCalendarService workCalendarService = ProcessEngineManagement.getDefaultProcessEngine().getService(WorkCalendarService.class);
	
	DataResult result = new DataResult();
	result.setData(workCalendarService.getCalendarRule(pageIndex, pageSize, idLike, nameLike));
	result.setPageIndex(pageIndex);
	result.setPageSize(pageSize);
	result.setRecordsTotal(workCalendarService.getCalendarRuleCount(idLike, nameLike));
	result.setRecordsFiltered(workCalendarService.getCalendarRuleCount(idLike, nameLike));
	return result;
}
 
Example 13
Source File: CalendarTypeCollectionResource.java    From FoxBPM with Apache License 2.0 4 votes vote down vote up
@Get
public DataResult getCalendarTypes(){
	
	Form queryForm = getQuery();
	Set<String> queryNames = queryForm.getNames();
	
	String id = StringUtil.getString(getQueryParameter("id", queryForm));
	String name = StringUtil.getString(getQueryParameter("name", queryForm));
	
	String idLike = null;
	String nameLike = null;
	if (StringUtil.isNotEmpty(id)) {
		idLike = "%" + id + "%";
	}
	if (StringUtil.isNotEmpty(name)) {
		nameLike = "%" + name + "%";
	}
	
	if (queryNames.contains(RestConstants.PAGE_START)) {
		if (queryNames.contains(RestConstants.PAGE_LENGTH)) {
			pageSize = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_LENGTH, queryForm));
		}
		pageIndex = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_START, queryForm)) / pageSize + 1;
	}
	
	if (queryNames.contains(RestConstants.PAGE_INDEX)) {
		pageIndex = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_INDEX, queryForm));
	}
	if (queryNames.contains(RestConstants.PAGE_SIZE)) {
		pageSize = StringUtil.getInt(getQueryParameter(RestConstants.PAGE_SIZE, queryForm));
	}
	
	WorkCalendarService workCalendarService = ProcessEngineManagement.getDefaultProcessEngine().getService(WorkCalendarService.class);
	
	DataResult result = new DataResult();
	result.setData(workCalendarService.getCalendarType(pageIndex, pageSize, idLike, nameLike));
	result.setPageIndex(pageIndex);
	result.setPageSize(pageSize);
	result.setRecordsTotal(workCalendarService.getCalendarTypeCount(idLike, nameLike));
	result.setRecordsFiltered(workCalendarService.getCalendarTypeCount(idLike, nameLike));
	return result;
}
 
Example 14
Source File: OpenTestResource.java    From open-rmbt with Apache License 2.0 4 votes vote down vote up
@Get("json")
    public String request(final String entity)
    {
        int verboseLevel = 0;
        addAllowOrigin();

        //routing should be in a way in which open_test_uuid is always set
        String openUUID = getRequest().getAttributes().get("open_test_uuid").toString();
        
        
        
        final Form getParameters = getRequest().getResourceRef().getQueryAsForm();
        //allow sender + verbose
        for (String name : getParameters.getNames()) {
        	if (name.equals("verbose")) {
        		try {
                    verboseLevel = Integer.parseInt(getParameters.getFirstValue("verbose"));
                }
                catch (NumberFormatException ex) {
                    Logger.getGlobal().info("invalid non-numberic verbosity level");
                }
        	}
        	else if (name.equals("sender") || name.equals("?sender")) { //allow for ?sender; used by some users due to error in old documentation
        		//ignore for now
        		final String sender_id;
        		if (name.equals("sender"))
        			sender_id = "sender " + getParameters.getFirstValue("sender");
        		else 
        			sender_id = "sender " + getParameters.getFirstValue("?sender");
//        		System.out.println(sender_id);
        		//the logging block would require write access to the database
        		/*
        		final String sql = "UPDATE json_sender SET count = count + 1 WHERE sender_id = ?";
        		PreparedStatement ps = null;
                try
                {
                    ps = conn.prepareStatement(sql);
                    ps.setString(1, sender_id);
                    
                    ps.executeUpdate();
                } catch  (final SQLException e)
                {
                    Logger.getLogger(OpenTestResource.class.getName()).log(Level.SEVERE, null, e);
                }
                */
        	}
        }
        
        return getSingleOpenTest(openUUID, verboseLevel);
        
    }