Search in sources :

Example 56 with BackendlessFault

use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.

the class Persistence method loadRelations.

public <T> void loadRelations(String parentType, String objectId, LoadRelationsQueryBuilder queryBuilder, Class<T> relatedType, final AsyncCallback<List<T>> responder) {
    StringUtils.checkEmpty(objectId, ExceptionMessage.NULL_ENTITY);
    if (queryBuilder == null)
        throw new IllegalArgumentException(ExceptionMessage.NULL_FIELD("queryBuilder"));
    BackendlessDataQuery dataQuery = queryBuilder.build();
    String relationName = dataQuery.getQueryOptions().getRelated().iterator().next();
    int pageSize = dataQuery.getPageSize();
    int offset = dataQuery.getOffset();
    try {
        Object[] args = new Object[] { parentType, objectId, relationName, pageSize, offset };
        Invoker.invokeAsync(PERSISTENCE_MANAGER_SERVER_ALIAS, "loadRelations", args, responder, ResponderHelper.getCollectionAdaptingResponder(relatedType));
    } catch (Throwable e) {
        if (responder != null)
            responder.handleFault(new BackendlessFault(e));
    }
}
Also used : BackendlessDataQuery(com.backendless.persistence.BackendlessDataQuery) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Example 57 with BackendlessFault

use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.

the class Persistence method getObjectCount.

<E> void getObjectCount(final Class<E> entity, DataQueryBuilder queryBuilder, AsyncCallback<Integer> responder) {
    if (queryBuilder == null)
        throw new IllegalArgumentException(ExceptionMessage.NULL_FIELD("queryBuilder"));
    BackendlessDataQuery dataQuery = queryBuilder.build();
    try {
        Object[] args = new Object[] { BackendlessSerializer.getSimpleName(entity), dataQuery };
        Invoker.invokeAsync(PERSISTENCE_MANAGER_SERVER_ALIAS, "count", args, responder);
    } catch (Throwable e) {
        if (responder != null)
            responder.handleFault(new BackendlessFault(e));
    }
}
Also used : BackendlessDataQuery(com.backendless.persistence.BackendlessDataQuery) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Example 58 with BackendlessFault

use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.

the class Persistence method findById.

protected <E> void findById(final E entity, final DataQueryBuilder queryBuilder, AsyncCallback<E> responder) {
    try {
        if (entity == null)
            throw new IllegalArgumentException(ExceptionMessage.NULL_ENTITY);
        if (queryBuilder == null)
            throw new IllegalArgumentException(ExceptionMessage.NULL_FIELD("queryBuilder"));
        Object entityArg = ReflectionUtil.hasField(entity.getClass(), Persistence.DEFAULT_OBJECT_ID_FIELD) ? entity : FootprintsManager.getInstance().getObjectId(entity);
        Object[] args = new Object[] { BackendlessSerializer.getSimpleName(entity.getClass()), entityArg, queryBuilder.build() };
        Invoker.invokeAsync(PERSISTENCE_MANAGER_SERVER_ALIAS, "findById", args, responder, ResponderHelper.getPOJOAdaptingResponder(entity.getClass()));
    } catch (Throwable e) {
        if (responder != null)
            responder.handleFault(new BackendlessFault(e));
    }
}
Also used : BackendlessFault(com.backendless.exceptions.BackendlessFault)

Example 59 with BackendlessFault

use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.

the class UserService method update.

public void update(final BackendlessUser user, final AsyncCallback<BackendlessUser> responder) {
    try {
        checkUserToBeProperForUpdate(user);
        BackendlessSerializer.serializeUserProperties(user);
        if (user.getUserId() != null && user.getUserId().equals(""))
            throw new IllegalArgumentException(ExceptionMessage.WRONG_USER_ID);
        Invoker.invokeAsync(USER_MANAGER_SERVER_ALIAS, "update", new Object[] { user.getProperties() }, new AsyncCallback<BackendlessUser>() {

            @Override
            public void handleResponse(BackendlessUser response) {
                user.clearProperties();
                user.putProperties(response.getProperties());
                if (responder != null)
                    responder.handleResponse(response);
            }

            @Override
            public void handleFault(BackendlessFault fault) {
                if (responder != null)
                    responder.handleFault(fault);
            }
        }, new AdaptingResponder(BackendlessUser.class, new BackendlessUserAdaptingPolicy()));
    } catch (Throwable e) {
        if (responder != null)
            responder.handleFault(new BackendlessFault(e));
    }
}
Also used : AdaptingResponder(com.backendless.core.responder.AdaptingResponder) BackendlessUserAdaptingPolicy(com.backendless.core.responder.policy.BackendlessUserAdaptingPolicy) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Example 60 with BackendlessFault

use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.

the class AdaptingResponder method adaptFault.

public static BackendlessFault adaptFault(AnonymousObject bodyHolder) {
    final StringType faultMessage = (StringType) bodyHolder.getProperties().get("faultString");
    final StringType faultDetail = (StringType) bodyHolder.getProperties().get("faultDetail");
    final StringType faultCode = (StringType) bodyHolder.getProperties().get("faultCode");
    final AnonymousObject extendedData = (AnonymousObject) bodyHolder.getProperties().get("extendedData");
    return new BackendlessFault(new Fault((String) faultMessage.defaultAdapt(), (String) faultDetail.defaultAdapt(), (String) faultCode.defaultAdapt()), (Map<String, Object>) extendedData.defaultAdapt());
}
Also used : AnonymousObject(weborb.reader.AnonymousObject) StringType(weborb.reader.StringType) BackendlessFault(com.backendless.exceptions.BackendlessFault) Fault(weborb.client.Fault) NamedObject(weborb.reader.NamedObject) AnonymousObject(weborb.reader.AnonymousObject) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Aggregations

BackendlessFault (com.backendless.exceptions.BackendlessFault)65 AnonymousObject (weborb.reader.AnonymousObject)15 NamedObject (weborb.reader.NamedObject)15 AsyncCallback (com.backendless.async.callback.AsyncCallback)11 Intent (android.content.Intent)10 View (android.view.View)10 TextView (android.widget.TextView)6 BackendlessCollection (com.backendless.BackendlessCollection)6 List (java.util.List)6 Typeface (android.graphics.Typeface)5 BackendlessDataQuery (com.backendless.persistence.BackendlessDataQuery)5 EditText (android.widget.EditText)4 CollectionAdaptingPolicy (com.backendless.core.responder.policy.CollectionAdaptingPolicy)4 BackendlessFile (com.backendless.files.BackendlessFile)4 ArrayList (java.util.ArrayList)4 Button (android.widget.Button)3 GeoPoint (com.backendless.geo.GeoPoint)3 ProgressDialog (android.app.ProgressDialog)2 DialogInterface (android.content.DialogInterface)2 Bitmap (android.graphics.Bitmap)2