Android Open Source - meets-android Mage Meets Model






From Project

Back to project page meets-android.

License

The source code is released under:

MIT License

If you think the Android project meets-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.theagilemonkeys.meets.magento.models.base;
/*from ww  w. j  av a2s. co m*/
import com.theagilemonkeys.meets.ApiMethod;
import com.theagilemonkeys.meets.ApiMethodModelHelper;
import com.theagilemonkeys.meets.models.base.MeetsListener;
import com.theagilemonkeys.meets.models.base.MeetsModel;
import com.theagilemonkeys.meets.utils.soap.Serializable;
import com.theagilemonkeys.meets.utils.Copier;

import org.jdeferred.AlwaysCallback;
import org.jdeferred.Deferred;
import org.jdeferred.DonePipe;
import org.jdeferred.FailPipe;
import org.jdeferred.Promise;

import java.util.Map;

/**
 * Android Meets SDK
 * Original work Copyright (c) 2014 [TheAgileMonkeys]
 *
 * @author ??lvaro Lpez Espinosa
 */
public abstract class MageMeetsModel<MODEL extends MeetsModel> extends Serializable.Object implements MeetsModel<MODEL> {
    private transient ApiMethodModelHelper<MODEL> apiMethodCtrl = new ApiMethodModelHelper<MODEL>((MODEL) this);

    @Override
    public boolean isNew() {
        return getId() <= 0;
    }

    @Override
    public MODEL fetch(int id) {
        return (MODEL) setId(id).fetch();
    }

    /**
     * Update this from the object returned after fetch() is called. Copy all properties from fecthedResult
     * to this, using the Copier instance returned by getCopier()
     * @param fetchedResult
     */
    protected void updateFromFetchedResult(Object fetchedResult){
        getCopier().copyProperties(this, fetchedResult);
    }

    protected transient AlwaysCallback updateAndTrigger = new AlwaysCallback() {
        @Override
        public void onAlways(Promise.State state, Object resolved, Object rejected) {
            if (state == Promise.State.RESOLVED) updateFromFetchedResult(resolved);
            triggerListeners((Exception) rejected);
        }
    };

    protected transient AlwaysCallback onlyTrigger = new AlwaysCallback() {
        @Override
        public void onAlways(Promise.State state, Object resolved, Object rejected) {
            triggerListeners((Exception) rejected);
        }
    };

    /**
     * Return the Copier instance used to copy properties from fetched object to this.
     * Child classes can override this method to configure the copier to, for example,
     * avoid cloning certain properties. In this case, child classes must call super and work
     * with the copier returned.
     * @return Copier
     */
    protected Copier getCopier(){
        return new Copier().setIgnoreNulls(true);
    }

    @Override
    public MODEL shallowCopyFrom(MODEL model) {
        getCopier().copyProperties(this, model);
        return (MODEL) this;
    }

    @Override
    public MODEL include(String... weakAttributes) {
        throw new UnsupportedOperationException("TODO");
    }

    /////////////////////////////////////////////////////////////////////////
    //////////////////// ApiMethodModelHelper delegation /////////////////////
    /////////////////////////////////////////////////////////////////////////


    public Promise pushMethod(ApiMethod method) {
        return apiMethodCtrl.pushMethod(method);
    }

    public MODEL forceNextCacheToBe(boolean enable) {
        return apiMethodCtrl.forceNextCacheToBe(enable);
    }

    public Promise pushPipe(DonePipe donePipe, FailPipe failPipe) {
        return apiMethodCtrl.pushPipe(donePipe, failPipe);
    }

    public Map<MeetsListener<MODEL>,Boolean> getListenersWithKeepInfo() {
        return apiMethodCtrl.getListenersWithKeepInfo();
    }

    public void triggerListeners(Exception e) {
        apiMethodCtrl.triggerListeners(e);
    }

    public Promise pushMethod(ApiMethod method, ApiMethodModelHelper.DelayedParams params) {
        return apiMethodCtrl.pushMethod(method, params);
    }

    public Promise pushDeferred(Deferred deferred) {
        return apiMethodCtrl.pushDeferred(deferred);
    }

    public MODEL setModelCache(boolean enable) {
        return apiMethodCtrl.setModelCache(enable);
    }

    public void triggerListeners() {
        apiMethodCtrl.triggerListeners();
    }

    @Override
    public MODEL await(MeetsListener<MODEL> listener) {
        return apiMethodCtrl.await(listener);
    }

    @Override
    public MODEL await(MeetsListener<MODEL> listener, boolean keepListening) {
        return apiMethodCtrl.await(listener, keepListening);
    }

    @Override
    public MODEL noLongerWait(MeetsListener<MODEL> listener) {
        return apiMethodCtrl.noLongerWait(listener);
    }

    @Override
    public MODEL allNoLongerWait() {
        return apiMethodCtrl.allNoLongerWait();
    }

    @Override
    public MODEL nextWaitForPrevious() {
        return apiMethodCtrl.nextWaitForPrevious();
    }
}




Java Source Code List

com.theagilemonkeys.meets.ApiMethodModelHelperInterface.java
com.theagilemonkeys.meets.ApiMethodModelHelper.java
com.theagilemonkeys.meets.ApiMethod.java
com.theagilemonkeys.meets.MeetsSpiceService.java
com.theagilemonkeys.meets.Meets.java
com.theagilemonkeys.meets.magento.RestApiMethod.java
com.theagilemonkeys.meets.magento.SoapApiMethod.java
com.theagilemonkeys.meets.magento.methods.CatalogCategoryInfo.java
com.theagilemonkeys.meets.magento.methods.CatalogCategoryLevel.java
com.theagilemonkeys.meets.magento.methods.CatalogCategoryTree.java
com.theagilemonkeys.meets.magento.methods.CatalogInventoryStockItemList.java
com.theagilemonkeys.meets.magento.methods.CatalogProductAttributeOptions.java
com.theagilemonkeys.meets.magento.methods.CatalogProductInfo.java
com.theagilemonkeys.meets.magento.methods.CatalogProductList.java
com.theagilemonkeys.meets.magento.methods.CustomerAddressCreate.java
com.theagilemonkeys.meets.magento.methods.CustomerAddressDelete.java
com.theagilemonkeys.meets.magento.methods.CustomerAddressInfo.java
com.theagilemonkeys.meets.magento.methods.CustomerAddressList.java
com.theagilemonkeys.meets.magento.methods.CustomerAddressUpdate.java
com.theagilemonkeys.meets.magento.methods.CustomerCustomerCreate.java
com.theagilemonkeys.meets.magento.methods.CustomerCustomerInfo.java
com.theagilemonkeys.meets.magento.methods.CustomerCustomerList.java
com.theagilemonkeys.meets.magento.methods.CustomerCustomerUpdate.java
com.theagilemonkeys.meets.magento.methods.Products.java
com.theagilemonkeys.meets.magento.methods.ShoppingCartCreate.java
com.theagilemonkeys.meets.magento.methods.ShoppingCartCustomerAddresses.java
com.theagilemonkeys.meets.magento.methods.ShoppingCartCustomerSet.java
com.theagilemonkeys.meets.magento.methods.ShoppingCartInfo.java
com.theagilemonkeys.meets.magento.methods.ShoppingCartOrder.java
com.theagilemonkeys.meets.magento.methods.ShoppingCartPaymentList.java
com.theagilemonkeys.meets.magento.methods.ShoppingCartPaymentMethod.java
com.theagilemonkeys.meets.magento.methods.ShoppingCartProductAdd.java
com.theagilemonkeys.meets.magento.methods.ShoppingCartProductRemove.java
com.theagilemonkeys.meets.magento.methods.ShoppingCartShippingList.java
com.theagilemonkeys.meets.magento.methods.ShoppingCartShippingMethod.java
com.theagilemonkeys.meets.magento.models.MageMeetsAddress.java
com.theagilemonkeys.meets.magento.models.MageMeetsCartItem.java
com.theagilemonkeys.meets.magento.models.MageMeetsCartPayment.java
com.theagilemonkeys.meets.magento.models.MageMeetsCartShipping.java
com.theagilemonkeys.meets.magento.models.MageMeetsCart.java
com.theagilemonkeys.meets.magento.models.MageMeetsCategory.java
com.theagilemonkeys.meets.magento.models.MageMeetsCustomer.java
com.theagilemonkeys.meets.magento.models.MageMeetsProduct.java
com.theagilemonkeys.meets.magento.models.MageStockInfoList.java
com.theagilemonkeys.meets.magento.models.MageStockItem.java
com.theagilemonkeys.meets.magento.models.base.MageMeetsCollectionPojos.java
com.theagilemonkeys.meets.magento.models.base.MageMeetsCollection.java
com.theagilemonkeys.meets.magento.models.base.MageMeetsFactory.java
com.theagilemonkeys.meets.magento.models.base.MageMeetsModel.java
com.theagilemonkeys.meets.models.MeetsAddress.java
com.theagilemonkeys.meets.models.MeetsCart.java
com.theagilemonkeys.meets.models.MeetsCategory.java
com.theagilemonkeys.meets.models.MeetsCustomer.java
com.theagilemonkeys.meets.models.MeetsProduct.java
com.theagilemonkeys.meets.models.MeetsStock.java
com.theagilemonkeys.meets.models.base.MeetsCollectionPojos.java
com.theagilemonkeys.meets.models.base.MeetsCollection.java
com.theagilemonkeys.meets.models.base.MeetsFactory.java
com.theagilemonkeys.meets.models.base.MeetsListener.java
com.theagilemonkeys.meets.models.base.MeetsModel.java
com.theagilemonkeys.meets.utils.Copier.java
com.theagilemonkeys.meets.utils.StringUtils.java
com.theagilemonkeys.meets.utils.soap.Serializable.java
com.theagilemonkeys.meets.utils.soap.SoapParser.java