com.netmera.mobile
Class NetmeraService

java.lang.Object
  extended by com.netmera.mobile.NetmeraService

public class NetmeraService
extends java.lang.Object

NetmeraService is used to get NetmeraContent object by its search() and get() methods. Many query options defined to help finding exact object.


Nested Class Summary
static class NetmeraService.SortBy
           
static class NetmeraService.SortOrder
          Sort order definitions
 
Constructor Summary
NetmeraService(java.lang.String objectName)
          Default constructor for the NetmeraService that sets objectName and other default parameters.
 
Method Summary
 NetmeraService addSearchText(java.lang.String searchText)
          Adds the searchText into the query.
 java.util.List<NetmeraContent> boxSearch(NetmeraGeoLocation firstPoint, NetmeraGeoLocation secondPoint, java.lang.String locationSearchField)
          Creates box using the given two location (latitude,longitude) data and searches inside that box.
 void boxSearchInBackground(NetmeraGeoLocation firstPoint, NetmeraGeoLocation secondPoint, java.lang.String locationSearchField, NetmeraCallback<java.util.List<NetmeraContent>> callback)
          Creates box using the given two location (latitude,longitude) data and searches inside that box in the background thread.Since it runs on the background thread it does not block program.It is recommended over boxSearch() method.
 java.util.List<NetmeraContent> circleSearch(NetmeraGeoLocation startLocation, double distance, java.lang.String locationSearchField)
          Searches the content by taking given location as a base and retrieves the contents that located given distance far away.
 void circleSearchInBackground(NetmeraGeoLocation startLocation, double distance, java.lang.String locationSearchField, NetmeraCallback<java.util.List<NetmeraContent>> callback)
          Searches the content by taking given location as a base and retrieves the contents that located given distance far away in the background thread.Since it runs on the background thread it does not block program.It is recommended over circleSearch() method.
 long count()
          Gets the total number of results that matches the query.
 void countInBackground(NetmeraCallback<java.lang.Long> callback)
          Gets the total number of results that match the query in the background thread.Since it runs on the background thread it does not block program.It is recommended over count() method.
 void deleteCacheResults()
          Deletes everything from the cache
 NetmeraContent get()
          Gets the single NetmeraContent object with the given path.Path of the content can be setted using the setPath() method.
<T> T
get(java.lang.Class<T> classOfT)
          Gets a single content and maps it to your model object.
 NetmeraCache.CacheType getCacheType()
          Gets the defined cache type.
 java.util.List<NetmeraContent> getContents(java.util.List<java.lang.String> pathList)
          Gets the list of NetmeraContent objects with the given path list.If there is no matched content for the given path list, it returns empty list.
 void getContentsInBackground(java.util.List<java.lang.String> pathList, NetmeraCallback<java.util.List<NetmeraContent>> callback)
          Gets the list of NetmeraContent objects with the given path list in the background thread.If there is no matched content for the given path list, it returns empty list.Since it runs on the background thread it does not block program.It is recommended over getContents() method.
<T> void
getInBackground(java.lang.Class<T> classOfT, NetmeraCallback<T> callback)
          Gets a single content in background and maps it to your model object.
 void getInBackground(NetmeraCallback<NetmeraContent> callback)
          Gets the single NetmeraContent object that matches the query in the background thread.Since it runs on the background thread it does not block program.It is recommended over get() method.
 long getMaxCacheAge()
          Use to get max cache age field.
static NetmeraService getNetmeraUserService()
          It creates the NetmeraUser service object.
 java.lang.String getPath()
          Returns the path of the content.
 java.util.List<NetmeraContent> search()
          Retrieves the list of NetmeraContent objects that matches with the query.
<T> java.util.List<T>
search(java.lang.Class<T> classOfT)
          Gets a list of contents and maps them to your model object.
<T> void
searchInBackground(java.lang.Class<T> classOfT, NetmeraCallback<java.util.List<T>> callback)
          Gets a list of contents in background and maps them to your model object.
 void searchInBackground(NetmeraCallback<java.util.List<NetmeraContent>> callback)
          Retrieves the list of NetmeraContent objects that matches with the query in the background thread.Since it runs on the background thread it does not block program.It is recommended over search() method.
 java.util.List<NetmeraUser> searchUser()
          Retrieves the list of NetmeraUser objects that matches with the query.
 void searchUserInBackground(NetmeraCallback<java.util.List<NetmeraUser>> callback)
          Retrieves the list of NetmeraUser objects that matches with the query in the background thread.Since it runs on the background thread it does not block program.It is recommended over searchUser() method.
 void setCacheType(NetmeraCache.CacheType cacheType)
          Sets the cache type.
 void setMax(int max)
          Sets the total number of results to return.
 void setMaxCacheAge(long maxCacheAge)
          Set max cache age.
 void setPage(int page)
          Sets the index of the page to retrieve data.
 void setPath(java.lang.String path)
          Sets the path of the content.This is used to find the content to delete and update.
 void setSortBy(java.lang.String sortBy)
          Sorts the content with the given key.
 void setSortOrder(NetmeraService.SortOrder sortOrder)
          Sorts the content with the given order.
 NetmeraService whereAllContainedIn(java.lang.String key, java.util.Collection<?> values)
          Adds an options to the query where value that matches with the query contains all of the values in the given collection.
 NetmeraService whereContainedIn(java.lang.String key, java.util.Collection<?> values)
          Adds an options to the query where value that matches with the query contains any of the values in the given collection.
 NetmeraService whereEndsWith(java.lang.String key, java.lang.String suffix)
          Adds an options to the query where value that matches with the query ends with the given suffix.
 NetmeraService whereEndsWith(java.lang.String key, java.lang.String suffix, boolean isCaseInsensitive)
          Adds an options to the query where value that matches with the query ends with the given suffix.
 NetmeraService whereEqual(java.lang.String key, java.lang.Object value)
          Adds an options to the query where value that matches with the query is equal to the given value.
 NetmeraService whereEqual(java.lang.String key, java.lang.Object value, boolean isCaseInsensitive)
          Adds an options to the query where value that matches with the query is equal to the given value.
 NetmeraService whereExists(java.lang.String key, boolean value)
          Adds an options to the query where the given key is exists or not.
 NetmeraService whereGreaterThan(java.lang.String key, java.lang.Object value)
          Adds an options to the query where value that matches with the query is greater than the given value.
 NetmeraService whereGreaterThanOrEqual(java.lang.String key, java.lang.Object value)
          Adds an options to the query where value that matches with the query is greater than or equal to the given value.
 NetmeraService whereLessThan(java.lang.String key, java.lang.Object value)
          Adds an options to the query where value that matches with the query is less than the given value.
 NetmeraService whereLessThanOrEqual(java.lang.String key, java.lang.Object value)
          Adds an options to the query where value that matches with the query is less than or equal to the given value.
 NetmeraService whereMatches(java.lang.String key, java.lang.String regex)
          Adds an options to the query where value that returns from the query matches with the given regex.
 NetmeraService whereMatches(java.lang.String key, java.lang.String regex, boolean isCaseInsensitive)
          Adds an options to the query where value that returns from the query matches with the given regex.
 NetmeraService whereNotEqual(java.lang.String key, java.lang.Object value)
          Adds an options to the query where value that matches with the query is not equal to the given value.
 NetmeraService whereOwnerEqual(NetmeraUser user)
          This is used to get the contents of the logged user.
 NetmeraService whereStartsWith(java.lang.String key, java.lang.String prefix)
          Adds an options to the query where value that matches with the query starts with the given prefix.
 NetmeraService whereStartsWith(java.lang.String key, java.lang.String prefix, boolean isCaseInsensitive)
          Adds an options to the query where value that matches with the query starts with the given prefix.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NetmeraService

public NetmeraService(java.lang.String objectName)
Default constructor for the NetmeraService that sets objectName and other default parameters.

Default value for the max = 10 and page = 0. It returns 10 result in each page. It skips page * max in each iteration.

Parameters:
objectName - - Name of the content
Method Detail

getCacheType

public NetmeraCache.CacheType getCacheType()
Gets the defined cache type.

Returns:
Returns the NetmeraCache.CacheType

setCacheType

public void setCacheType(NetmeraCache.CacheType cacheType)
Sets the cache type.

Parameters:
cacheType - - type of the cache policy

deleteCacheResults

public void deleteCacheResults()
Deletes everything from the cache


getMaxCacheAge

public long getMaxCacheAge()
Use to get max cache age field.

Returns:
max cache age.

setMaxCacheAge

public void setMaxCacheAge(long maxCacheAge)
Set max cache age. This value is used to control if the data in the cache is expired or not.

Parameters:
maxCacheAge - max cache age

setMax

public void setMax(int max)
Sets the total number of results to return. If it is less than or equal to 0 then it is setted to 10.

Parameters:
max -

setPage

public void setPage(int page)
Sets the index of the page to retrieve data. If it is less than 0 then it is setted to 0.

For example : setPage(3); means that skip 3*max page and retrieve the next max page.

Parameters:
page -

getPath

public java.lang.String getPath()
Returns the path of the content.

Returns:
Returns the path of the content

setPath

public void setPath(java.lang.String path)
Sets the path of the content.This is used to find the content to delete and update.

Parameters:
path - - path of the content

setSortBy

public void setSortBy(java.lang.String sortBy)
Sorts the content with the given key.

Parameters:
sortBy - key to sort content

setSortOrder

public void setSortOrder(NetmeraService.SortOrder sortOrder)
Sorts the content with the given order. If not setted then by default it is sorted by ascending order.

Parameters:
sortOrder - order of the sort

count

public long count()
           throws NetmeraException
Gets the total number of results that matches the query.

Returns:
Returns the total number of results
Throws:
NetmeraException - Throws exception if it cannot access server.

countInBackground

public void countInBackground(NetmeraCallback<java.lang.Long> callback)
Gets the total number of results that match the query in the background thread.Since it runs on the background thread it does not block program.It is recommended over count() method.

Parameters:
callback - - NetmeraCallback.onFail(NetmeraException) or NetmeraCallback.onSuccess(Object) methods called when count operation finishes.

addSearchText

public NetmeraService addSearchText(java.lang.String searchText)
Adds the searchText into the query.

Parameters:
searchText - - Text to search

whereEqual

public NetmeraService whereEqual(java.lang.String key,
                                 java.lang.Object value)
Adds an options to the query where value that matches with the query is equal to the given value.

Parameters:
key - - key to identify specified value
value - - value associates with the specified key

whereEqual

public NetmeraService whereEqual(java.lang.String key,
                                 java.lang.Object value,
                                 boolean isCaseInsensitive)
Adds an options to the query where value that matches with the query is equal to the given value.

Parameters:
key - - key to identify specified value
value - - value associates with the specified key
isCaseInsensitive - - If true, search is done case insensitive

whereGreaterThan

public NetmeraService whereGreaterThan(java.lang.String key,
                                       java.lang.Object value)
Adds an options to the query where value that matches with the query is greater than the given value.

Parameters:
key - - key to identify specified value
value - - value associates with the specified key

whereLessThan

public NetmeraService whereLessThan(java.lang.String key,
                                    java.lang.Object value)
Adds an options to the query where value that matches with the query is less than the given value.

Parameters:
key - - key to identify specified value
value - - value associates with the specified key

whereNotEqual

public NetmeraService whereNotEqual(java.lang.String key,
                                    java.lang.Object value)
Adds an options to the query where value that matches with the query is not equal to the given value.

Parameters:
key - - key to identify specified value
value - - value associates with the specified key

whereGreaterThanOrEqual

public NetmeraService whereGreaterThanOrEqual(java.lang.String key,
                                              java.lang.Object value)
Adds an options to the query where value that matches with the query is greater than or equal to the given value.

Parameters:
key - - key to identify specified value
value - - value associates with the specified key

whereLessThanOrEqual

public NetmeraService whereLessThanOrEqual(java.lang.String key,
                                           java.lang.Object value)
Adds an options to the query where value that matches with the query is less than or equal to the given value.

Parameters:
key - - key to identify specified value
value - - value associates with the specified key

whereExists

public NetmeraService whereExists(java.lang.String key,
                                  boolean value)
Adds an options to the query where the given key is exists or not. If value is true then it checks whether key exists, if value is false then it checks whether key not exists.

Parameters:
key - - key to identify specified value
value - - boolean value to check whether key exists or not

whereMatches

public NetmeraService whereMatches(java.lang.String key,
                                   java.lang.String regex)
Adds an options to the query where value that returns from the query matches with the given regex.

Parameters:
key - - key to identify specified value
regex - - value associates with the specified key

whereMatches

public NetmeraService whereMatches(java.lang.String key,
                                   java.lang.String regex,
                                   boolean isCaseInsensitive)
Adds an options to the query where value that returns from the query matches with the given regex.

Parameters:
key - - key to identify specified value
regex - - value associates with the specified key
isCaseInsensitive - - If true, search is done case insensitive

whereStartsWith

public NetmeraService whereStartsWith(java.lang.String key,
                                      java.lang.String prefix)
Adds an options to the query where value that matches with the query starts with the given prefix.

Parameters:
key - - key to identify specified value
prefix - - value associates with the specified key

whereStartsWith

public NetmeraService whereStartsWith(java.lang.String key,
                                      java.lang.String prefix,
                                      boolean isCaseInsensitive)
Adds an options to the query where value that matches with the query starts with the given prefix.

Parameters:
key - - key to identify specified value
prefix - - value associates with the specified key
isCaseInsensitive - - If true, search is done case insensitive

whereEndsWith

public NetmeraService whereEndsWith(java.lang.String key,
                                    java.lang.String suffix)
Adds an options to the query where value that matches with the query ends with the given suffix.

Parameters:
key - - key to identify specified value
suffix - - value associates with the specified key

whereEndsWith

public NetmeraService whereEndsWith(java.lang.String key,
                                    java.lang.String suffix,
                                    boolean isCaseInsensitive)
Adds an options to the query where value that matches with the query ends with the given suffix.

Parameters:
key - - key to identify specified value
suffix - - value associates with the specified key
isCaseInsensitive - - If true, search is done case insensitive

whereContainedIn

public NetmeraService whereContainedIn(java.lang.String key,
                                       java.util.Collection<?> values)
Adds an options to the query where value that matches with the query contains any of the values in the given collection.

Parameters:
key - - key to identify specified value
values - - value associates with the specified key

whereAllContainedIn

public NetmeraService whereAllContainedIn(java.lang.String key,
                                          java.util.Collection<?> values)
Adds an options to the query where value that matches with the query contains all of the values in the given collection.

Parameters:
key - - key to identify specified value
values - - value associates with the specified key

whereOwnerEqual

public NetmeraService whereOwnerEqual(NetmeraUser user)
                               throws NetmeraException
This is used to get the contents of the logged user.

Parameters:
user - current user
Throws:
NetmeraException - Throws exception if it cannot access server.

circleSearch

public java.util.List<NetmeraContent> circleSearch(NetmeraGeoLocation startLocation,
                                                   double distance,
                                                   java.lang.String locationSearchField)
                                            throws NetmeraException
Searches the content by taking given location as a base and retrieves the contents that located given distance far away.

Parameters:
startLocation - base location to search near it.
distance - is used to create circle by taking the startLocation as a center.
locationSearchField - name of the field that holds location data.
Returns:
the list of NetmeraContent object.
Throws:
NetmeraException - Throws exception if it cannot access server.

circleSearchInBackground

public void circleSearchInBackground(NetmeraGeoLocation startLocation,
                                     double distance,
                                     java.lang.String locationSearchField,
                                     NetmeraCallback<java.util.List<NetmeraContent>> callback)
Searches the content by taking given location as a base and retrieves the contents that located given distance far away in the background thread.Since it runs on the background thread it does not block program.It is recommended over circleSearch() method.

Parameters:
startLocation - base location to search near it.
distance - is used to create circle by taking the startLocation as a center.
locationSearchField - name of the field that holds location data.
callback - NetmeraCallback.onFail(NetmeraException) or NetmeraCallback.onSuccess(Object) methods called when search operation finishes.

boxSearch

public java.util.List<NetmeraContent> boxSearch(NetmeraGeoLocation firstPoint,
                                                NetmeraGeoLocation secondPoint,
                                                java.lang.String locationSearchField)
                                         throws NetmeraException
Creates box using the given two location (latitude,longitude) data and searches inside that box.

Parameters:
firstPoint - NetmeraGeoLocation object
secondPoint - NetmeraGeoLocation object
locationSearchField - name of the field that holds location data.
Returns:
the list of NetmeraContent object.
Throws:
NetmeraException - Throws exception if it cannot access server.

boxSearchInBackground

public void boxSearchInBackground(NetmeraGeoLocation firstPoint,
                                  NetmeraGeoLocation secondPoint,
                                  java.lang.String locationSearchField,
                                  NetmeraCallback<java.util.List<NetmeraContent>> callback)
Creates box using the given two location (latitude,longitude) data and searches inside that box in the background thread.Since it runs on the background thread it does not block program.It is recommended over boxSearch() method.

Parameters:
firstPoint - NetmeraGeoLocation object
secondPoint - NetmeraGeoLocation object
locationSearchField - name of the field that holds location data.
callback - NetmeraCallback.onFail(NetmeraException) or NetmeraCallback.onSuccess(Object) methods called when search operation finishes.

search

public java.util.List<NetmeraContent> search()
                                      throws NetmeraException
Retrieves the list of NetmeraContent objects that matches with the query.

It also checks NetmeraCache.CacheType and finds data using cache policy.

Returns:
List of the NetmeraContent object
Throws:
NetmeraException - Throws exception if it cannot access server.

searchInBackground

public void searchInBackground(NetmeraCallback<java.util.List<NetmeraContent>> callback)
Retrieves the list of NetmeraContent objects that matches with the query in the background thread.Since it runs on the background thread it does not block program.It is recommended over search() method.

Parameters:
callback - - NetmeraCallback.onFail(NetmeraException) or NetmeraCallback.onSuccess(Object) methods called when search operation finishes.

get

public NetmeraContent get()
                   throws NetmeraException
Gets the single NetmeraContent object with the given path.Path of the content can be setted using the setPath() method.

It also checks NetmeraCache.CacheType and finds data using cache policy.

Returns:
NetmeraContent object
Throws:
NetmeraException - Throws exception if it cannot access server.

getContentsInBackground

public void getContentsInBackground(java.util.List<java.lang.String> pathList,
                                    NetmeraCallback<java.util.List<NetmeraContent>> callback)
Gets the list of NetmeraContent objects with the given path list in the background thread.If there is no matched content for the given path list, it returns empty list.Since it runs on the background thread it does not block program.It is recommended over getContents() method.

Parameters:
callback - - NetmeraCallback.onFail(NetmeraException) or NetmeraCallback.onSuccess(Object) methods called when get operation finishes.

getContents

public java.util.List<NetmeraContent> getContents(java.util.List<java.lang.String> pathList)
                                           throws NetmeraException
Gets the list of NetmeraContent objects with the given path list.If there is no matched content for the given path list, it returns empty list.

Parameters:
pathList - Path List of NetmeraContent objects
Returns:
List of the NetmeraContent object
Throws:
NetmeraException - Throws exception if it cannot access server.

get

public <T> T get(java.lang.Class<T> classOfT)
      throws NetmeraException
Gets a single content and maps it to your model object. Only primitive type instance variables, their wrapper types and String can be mapped. Your model field names must match with your content field names saved on Netmera. Example usage may be like this:
 
 NetmeraService service = new NetmeraService("Your content name on Netmera");
 service.setPath("your content path");
 try {
     MyModel result = service.get(MyModel.class);
 } catch (NetmeraException e) {
     e.printStackTrace();
 }
 
 

Parameters:
classOfT - your model class
Returns:
Your model object instance
Throws:
NetmeraException - if there is invalid field on your content

getInBackground

public <T> void getInBackground(java.lang.Class<T> classOfT,
                                NetmeraCallback<T> callback)
Gets a single content in background and maps it to your model object. Only primitive type instance variables, their wrapper types and String can be mapped. Your model field names must match with your content field names saved on Netmera. Example usage may be like this:
 
 NetmeraService service = new NetmeraService("Your content name on Netmera");
 service.setPath("your content path");
 service.getInBackground(MyModel.class, new NetmeraCallback<MyModel>() {
     @Override
     public void onSuccess(MyModel model) {
        //Success
     }
     @Override
     public void onFail(NetmeraException ex) {
        //Failure
     }
 });
 
 

Parameters:
classOfT - your model class
callback - - NetmeraCallback.onFail(NetmeraException) or NetmeraCallback.onSuccess(Object) methods called when get operation finishes.

search

public <T> java.util.List<T> search(java.lang.Class<T> classOfT)
                         throws NetmeraException
Gets a list of contents and maps them to your model object. Only primitive type instance variables, their wrapper types and String can be mapped. Your model field names must match with your content field names saved on Netmera. Example usage may be like this:
 
 NetmeraService service = new NetmeraService("Your content name on Netmera");
 try {
     List<MyModel> resultList = service.search(MyModel.class);
 } catch (NetmeraException e) {
     e.printStackTrace();
 }
 
 

Parameters:
classOfT - your model class
Returns:
Your model object instance
Throws:
NetmeraException - if there is invalid field on your content

searchInBackground

public <T> void searchInBackground(java.lang.Class<T> classOfT,
                                   NetmeraCallback<java.util.List<T>> callback)
Gets a list of contents in background and maps them to your model object. Only primitive type instance variables, their wrapper types and String can be mapped. Your model field names must match with your content field names saved on Netmera. Example usage may be like this:
 
 NetmeraService service = new NetmeraService("Your content name on Netmera");
 service.searchInBackground(MyModel.class, new NetmeraCallback<List<MyModel>>() {
     @Override
     public void onSuccess(List<MyModel> listOfModel) {
        //Success
     }
     @Override
     public void onFail(NetmeraException ex) {
        //Failure
     }
 });
 
 

Parameters:
classOfT - your model class
callback - - NetmeraCallback.onFail(NetmeraException) or NetmeraCallback.onSuccess(Object) methods called when search operation finishes.

getInBackground

public void getInBackground(NetmeraCallback<NetmeraContent> callback)
Gets the single NetmeraContent object that matches the query in the background thread.Since it runs on the background thread it does not block program.It is recommended over get() method.

Parameters:
callback - - NetmeraCallback.onFail(NetmeraException) or NetmeraCallback.onSuccess(Object) methods called when get operation finishes.

searchUser

public java.util.List<NetmeraUser> searchUser()
                                       throws NetmeraException
Retrieves the list of NetmeraUser objects that matches with the query.

Returns:
List of the NetmeraUser object
Throws:
NetmeraException

searchUserInBackground

public void searchUserInBackground(NetmeraCallback<java.util.List<NetmeraUser>> callback)
Retrieves the list of NetmeraUser objects that matches with the query in the background thread.Since it runs on the background thread it does not block program.It is recommended over searchUser() method.

Parameters:
callback - - NetmeraCallback.onFail(NetmeraException) or NetmeraCallback.onSuccess(Object) methods called when searchUser operation finishes.

getNetmeraUserService

public static NetmeraService getNetmeraUserService()
It creates the NetmeraUser service object. It is used to search users.

Returns:
NetmeraService object