com.adaptrex.core.ext.RestProxy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of adaptrex-core Show documentation
Show all versions of adaptrex-core Show documentation
The Core Adaptrex Framework
/*
* Copyright 2012 Adaptrex, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.adaptrex.core.ext;
import java.util.HashMap;
import java.util.Map;
import com.adaptrex.core.utilities.StringUtilities;
import com.fasterxml.jackson.annotation.JsonInclude;
public class RestProxy {
private String url;
private Map reader = new HashMap();
private Map writer = new HashMap();
private Map extraParams = new HashMap();
public RestProxy(String url, ExtConfig config) {
this.url = url;
reader.put("type","json");
if (config.isTouch()) {
reader.put("rootProperty","data"); // Sencha touch uses rootProperty instead of root
} else {
reader.put("root","data");
}
writer.put("writeAllFields", false);
if (!config.getIncludes().isEmpty()) {
String include = StringUtilities.join(config.getIncludes(), ",");
extraParams.put("include", include);
}
if (!config.getExcludes().isEmpty()) {
extraParams.put("exclude", StringUtilities.join(config.getExcludes(), ","));
}
if (!config.getAssociations().isEmpty()) {
extraParams.put("associations", StringUtilities.join(config.getAssociations(), ","));
}
if (!config.getModelName().isEmpty()) {
extraParams.put("modelname", config.getModelName());
}
}
@JsonInclude
public String getUrl() {
return this.url;
}
@JsonInclude
public String getType() {
return "rest";
}
@JsonInclude
public Map getReader() {
return this.reader;
}
@JsonInclude
public Map getWriter() {
return this.writer;
}
@JsonInclude
public Map getExtraParams() {
return this.extraParams;
}
}