All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jk.services.client.JKMatureServiceClient Maven / Gradle / Ivy

There is a newer version: 7.0.0-M7
Show newest version
/*
 * Copyright 2002-2022 Dr. Jalal Kiswani. 
 * Email: [email protected]
 * Check out https://smart-api.com for more details
 * 
 * All the opensource projects of Dr. Jalal Kiswani are free for personal and academic use only, 
 * for commercial usage and support, please contact the author.
 *
 * 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.jk.services.client;

import java.util.List;

import com.jk.core.config.JKConfig;
import com.jk.core.jpa.BaseModel;
import com.jk.core.util.JK;
import com.jk.core.util.JKObjectUtil;

// TODO: Auto-generated Javadoc
/**
 * The Class MatureServiceClient.
 *
 * @param  the generic type
 */
public abstract class JKMatureServiceClient extends JKServiceClient {

	private String base;

	/**
	 * Gets the service url property name.
	 *
	 * @return the service url property name
	 */
	public String getServiceUrlPropertyName() {
		JK.implementMe();
		return null;
	}

	/**
	 * Gets the base.
	 *
	 * @return the base
	 */
	@Override
	public String getBase() {
		if (base == null) {
			return JKConfig.getDefaultInstance().getString(getServiceUrlPropertyName());
		}
		return base;
	}

	/**
	 * 
	 */
	public void setBase(String base) {
		this.base = base;
	}

	/**
	 * Gets the all.
	 *
	 * @return the all
	 */
	public List getAll() {
		return callJsonAsListOfObjects();
	}

	/**
	 * Find.
	 *
	 * @param id the id
	 * @return the t
	 */
	public T find(String id) {
		return callSingleJson(id);
	}

	/**
	 * Insert.
	 *
	 * @param model the model
	 * @return the string
	 */
	public T insert(T model) {
		String json = callJsonWithPost(model);
		return (T) JKObjectUtil.jsonToObject(json, model.getClass());
	}

	/**
	 * Update.
	 *
	 * @param model the model
	 * @return the string
	 */
	public String update(T model) {
		return callJsonWithPut("/" + getId(model), model);
	}

	/**
	 * Delete.
	 *
	 * @param id the id
	 * @return the string
	 */
	public String delete(Object id) {
		return callJsonWithDelete("/" + id.toString());
	}

	/**
	 * Gets the id.
	 *
	 * @param model the model
	 * @return the id
	 */
	protected String getId(T model) {
		if (model instanceof BaseModel) {
			return ((BaseModel) model).getUid();
		}
		return JKObjectUtil.getPropertyValue(model, "id").toString();
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy