contentful / vault Goto Github PK
View Code? Open in Web Editor NEWEasy persistence of Contentful data for Android over SQLite.
Home Page: https://contentful.github.io/vault/
License: Apache License 2.0
Easy persistence of Contentful data for Android over SQLite.
Home Page: https://contentful.github.io/vault/
License: Apache License 2.0
What are the Proguard rules to embed vault into own application?
Since links are represented on different tables this currently limits the query abilities when applying a where()
clause, as one cannot add conditions based on linked entries:
vault.fetch(Cat.class)
.where("bestFriend.remote_id = ?", "foo") // won't work
.all();
This forces the caller to filter the results manually. Among many other benefits, supporting queries with RxJava could make this a little bit less tedious, for example:
vault.observe(Cat.class)
.filter((cat) -> "FOO".equals(cat.bestFriend().remoteId())
.subscribe((cat) -> ...);
In seeding section I saw it being mentioned to put file "vault_file_name.db" in assets folder and then refer it while declaring space. But no where I found it mentioned what "vault_file_name.db" is and how to generate or download it ?
Is there a way to have multiple languages persisted on the device? This is quite a big feature of our app and if we cannot have multiple languages persisted we will need to roll our own implementation.
At the moment, there is only one language supported with a single .sqllite file. If it was possible, we would prefer to have the id of the database file linked to the locale as well. That way we can switch the locale and language easily.
There is also evidence that switching to another language will not overwrite the previous language. Do we have to remove the space and start over?
Original issue #98
This issue in not happening in any other device
These are the related dependencies. As you can see i'm using retrofit in the app as well:
apt 'com.contentful.vault:compiler:2.0.0'
compile'com.contentful.vault:core:2.0.0'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
compile('com.squareup.retrofit2:adapter-rxjava:2.0.0') {
exclude module: 'rxjava'
exclude module: 'rxandroid'
}
I'm building the CDAClient in the application class' onCreate().
Fatal Exception: java.lang.NoClassDefFoundError: retrofit.RestAdapter$Builder
at com.contentful.java.cda.CDAClient.createService(CDAClient.java:54)
at com.contentful.java.cda.CDAClient.(CDAClient.java:38)
at com.contentful.java.cda.CDAClient.(CDAClient.java:23)
at com.contentful.java.cda.CDAClient$Builder.build(CDAClient.java:265)
at uk.co.activityhunter.activityhunter.util.ProjectUtils.setCDAClient(ProjectUtils.java:105)
at uk.co.activityhunter.activityhunter.application.AHApp.onCreate(AHApp.java:26)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1009)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4632)
at android.app.ActivityThread.access$1800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1298)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5336)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:873)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:689)
at dalvik.system.NativeStart.main(NativeStart.java)
I've got this exception while upgrading tables (new value in dbVersion). It seems the table name with "-" is not allowed.
Caused by: android.database.sqlite.SQLiteException: near "-": syntax error (code 1): , while compiling: DROP TABLE assets$en-US at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887) at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498) at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58) at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31) at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1674) at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1605) at com.contentful.vault.SqliteHelper.deleteTables(SqliteHelper.java:128) at com.contentful.vault.SqliteHelper.onUpgrade(SqliteHelper.java:70)
Hi.
I was trying to create a new content type to sync and I am currently having some trouble syncing the non localised fields.
I inspected the database output and the identifier
and helpKey
fields are currently set to NULL for all the entry_{id}${locale}
tables
Only the content
field is downloaded and it is because it is localisable.
I have tested it against vault 0.9.14 and 2.0.0 and it has the same problem
Here is the model definition
@ContentType("helpContent")
public class Helpcontent extends Resource {
@Field String identifier;
@Field String content;
@Field String helpKey;
public Helpcontent() {
}
public String identifier() {
return identifier;
}
public String helpKey() {
return helpKey;
}
public String content() {
return content;
}
}
And here is the JSON preview
{
"name": "Help content",
"description": "",
"displayField": "identifier",
"fields": [
{
"id": "identifier",
"name": "Identifier",
"type": "Symbol",
"localized": false,
"required": true,
"validations": [
{
"unique": true
}
],
"disabled": false,
"omitted": false
},
{
"id": "content",
"name": "Content",
"type": "Text",
"localized": true,
"required": true,
"validations": [],
"disabled": false,
"omitted": false
},
{
"name": "helpKey",
"id": "helpKey",
"type": "Symbol"
}
],
"sys": {
"id": "helpContent",
"type": "ContentType",
"createdAt": "2016-11-02T14:28:38.538Z",
"createdBy": {
"sys": {
"type": "Link",
"linkType": "User",
"id": "5u4wmZIO25TuaI2AWA4pJq"
}
},
"space": {
"sys": {
"type": "Link",
"linkType": "Space",
"id": "vo0tsnu0x6xh"
}
},
"firstPublishedAt": "2016-11-02T14:28:53.932Z",
"publishedCounter": 2,
"publishedAt": "2016-11-03T15:27:58.070Z",
"publishedBy": {
"sys": {
"type": "Link",
"linkType": "User",
"id": "5u4wmZIO25TuaI2AWA4pJq"
}
},
"publishedVersion": 3,
"version": 4,
"updatedAt": "2016-11-03T15:27:58.077Z",
"updatedBy": {
"sys": {
"type": "Link",
"linkType": "User",
"id": "5u4wmZIO25TuaI2AWA4pJq"
}
}
}
}
void requestSync(CDAClient client)
@ContentType("foo")
public class Foo extends Resource {
@Field String bar;
@Field String baz;
}
should generate:
public class Foo$Fields {
public static final String BAR "bar-db-column-name";
public static final String BAZ "baz-db-column-name";
}
@ContentType("foo")
public class Foo extends Resource { }
Currently results in a compile-time error:
Error:(X, X) error: Failed writing injection for "com.package.Foo", message: cannot unindent 1 from 0
This exception is raised due to incorrect use of JavaPoet since ModelInjection.java
assumes at least one field was defined. Defining a model with no fields is an error, and a more friendly error message should indicate that.
SyncConfig
should have an optional mode that invalidates existing data and then performs initial sync.
Contentful defines title for each content type. Would be possible to access the content of this field using a single method, something like:
resource.title()
I am working with the blog app https://github.com/contentful/blog-app-android
I want query posts by author and within a date range. I don't see those kinds of examples in sample given here https://github.com/contentful/vault#queries.
Can someone help ?
Would you be able to describe how we would represent Links to other resources in the model itself?
At the moment, we have a content type that references other entry types but do not know how to represent it in the data models.
Edit - to clarify, these links in the data model can refer to many different content types
Hi there,
I was struggling for some days why my stuff wasn't synced. The Problem was I wrote the contenttypes with an capital letter in the beginning, because it's displayed in the web interface of contentful. I think it would be a good idea to examine users of vault to have a look into the json preview and search for the contenttype.
Best
Alex
Making queries right now forces the caller to hardcode strings or concatenate them:
vault.fetch(Foo.class).where("gross = ?", bar)
vault.fetch(Foo.class).where(Foo$Fields.GROSS + " = ?", bar);
An alternative approach should be considered, one that potentially could also infer that JOIN
clauses are required to fulfill the query.
Link resolution for a field pointing at multiple resources is incorrect and will always use the first object.
For:
@Field List<Asset> assets;
order of objects is different than entered in web editor.
When all links points to the same entry:
@Field List<Resource> links;
only:
links.get(0) == $entry
rest is null.
Hi,
I was wondering if it possible to use the Preview API + key with this Vault library?
How do we use the Vault library using the preview api token?
Is it supported?
I am getting an exception even though there is a function in the CDAClient to use the preview API.
java.lang.UnsupportedOperationException: Syncing using a preview token is not supported. Please use a production token.
The example in the README.md needs to be updated in regards to setSpace and setToken
// Client
CDAClient client = new CDAClient.Builder()
.setSpaceKey("cfexampleapi");
.setAccessToken("b4c0n73n7fu1");
.build();
It would be nice to update Vault dependencies.
Hi.
I have come across a bug where if I have a localised Asset field, it will not load the correct Asset file, it will load the asset for the default locale.
The localised text fields are being loaded correctly, just the wrong asset is being loaded.
When all links points to the same entry:
@Field List<Resource> links;
only:
links.get(0) == $entry
rest is null.
I'm wondering whether it would be technically possible to include task for gradle to prepare the database for asset folder during the app build process?
I was able to load up my content object using vault until I started added some links to other content types. It started to crash with the following stacktrace.
java.lang.NullPointerException
at com.contentful.vault.LinkResolver.getCachedResourceOrFetch(LinkResolver.java:103)
at com.contentful.vault.LinkResolver.resolveLinksForField(LinkResolver.java:70)
at com.contentful.vault.LinkResolver.resolveLinks(LinkResolver.java:58)
at com.contentful.vault.QueryResolver.resolveLinks(QueryResolver.java:81)
at com.contentful.vault.QueryResolver.all(QueryResolver.java:65)
at com.contentful.vault.FetchQuery.all(FetchQuery.java:27)
at com.contentful.vault.FetchQuery.first(FetchQuery.java:31)
at com.contentful.vault.FetchQuery.first(FetchQuery.java:43)
What else do you need to know to debug this scenario?
Model fields of type List
should be set to an empty list instance in case there is no data.
Hi.
I am getting a very strange error all of a sudden where the requestSync action fails to complete and we are getting a java.util.ConcurrentModificationException
It looks like it is caused by Retrofit.
OnErrorThrowable$OnNextValue "rx.exceptions.OnErrorThrowable$OnNextValue: OnError while emitting onNext value: retrofit.client.Response.class"
OnError while emitting onNext value: retrofit.client.Response.class"
Is there a way to trace the source of this problem?
It was working fine last week. The only thing that has changed is the volume of localised content. Which is quite large.
It is an error to annotate a static field with @Field
:
@Field static String foo;
Hi,
I'm desperately trying to fetch all items whose Title contains MY_QUERY with vault + RxJava.
I've tried tons of variants, including:
.observe(Guide.class).where("title LIKE '%?%'", "MY_QUERY").all()
.observe(Guide.class).where("query", "MY_QUERY").all()
And many other options... Can you advise, please?
Hi.
We are starting to create some complex queries and was trying to figure out how we can search for content based on linked objects.
What sort of ORM model are you using and does it allow table joins?
Is it possible to query for content using a SQL statement?
Example:
static class Foo { }
Vault vault = Vault.with(context, Foo.class); // passes
vault.requestSync(...); // fails
Exception:
java.lang.RuntimeException: java.lang.ClassNotFoundException:
com.pkg.Whatever$Foo$$SpaceHelper
at com.contentful.vault.Vault.createSpaceHelper(Vault.java:157)
at com.contentful.vault.Vault.getOrCreateSqliteHelper(Vault.java:173)
at com.contentful.vault.Vault.requestSync(Vault.java:107)
at com.contentful.vaultintegration.BaseTest.sync(BaseTest.java:122)
at com.contentful.vaultintegration.BaseTest.sync(BaseTest.java:98)
at com.contentful.vaultintegration.ArrayTest.testArray(ArrayTest.java:40)
This should fail faster, right when Vault.with()
is invoked. The error message should also be more informative.
Hi.
Is there a way to download content for all available locales without knowing those specifically?
Because now, when I add new locale to contentful, I should add it to annotation and release new build to Play Market.
Hi,
After upgrading to Android Studio 3.0 Canary 3 and migrating everything according to the guide, project fails to build and shows
NoClassDefFoundError: com/contentful/vault/ContentType
My build.gradle contains:
buildToolsVersion "26.0.0-rc2"
...
implementation 'com.contentful.vault:core:2.1.0'
annotationProcessor 'com.contentful.vault:compiler:2.1.0'
implementation 'com.squareup.okhttp:okhttp:2.3.0'
implementation 'com.squareup.okhttp:okhttp-urlconnection:2.3.0'
...
// ButterKnife compiles well
implementation 'com.jakewharton:butterknife:8.6.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
Thanks in advance.
How feasible would be to use a different model type in Vault? Instead of using:
@ContentType("cat")
public class Cat extends Resource {
@Field public String name;
@Field public Cat bestFriend;
@Field public Asset image;
}
define model in a different way:
public class Entry extends Resource {
Map<String, Object> fields;
}
What I'm going to achieve is to fetch different content type objects in a single line of code, e.g.:
vault.fetch(Entry.class).where("contentType = ?", "Cat")
Hi,
I'm facing a problem, when i try to synchronize the contentful database, the most part of fields get null value and i don't know why, i'm using the default locale 'tlh'. I show you an example of one object result:
Brand{companyName='null', logo=null, companyDescription='null', website='null', twitter='null', email='null', phone=[+45 35 55 11 22]}
I only get values on list fields like 'phone' in this case.
Greetings
Hi.
This is more of a problem with our content model itself but it would be a good idea to raise this as an issue and safeguard against it because it causes the app to freeze
At the moment, I have Content Type A
that references Content Type B
.
Due to poor design on our part, Content Type B
contains links to Content Type A
which causes the looping problem.
I do understand that the quickest way to solve this is to fix the links between the content types, but is there a strategy to introduce into the vault ORM that prevents such links from being loaded?
Currently only the URL and mime-type of an asset are provided by the Asset
class. title
should also be supported as well as the file
JSON element and description
.
I added a new field into existing content type. Model object was updated to reflect this field. Also I had previously many entries created for this content type. I got then the following exception in ModelHelper of that content type (fromCursor method):
Caused by: java.lang.IllegalStateException: Couldn't read row 0, col 6 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it. at android.database.CursorWindow.nativeGetString(Native Method) at android.database.CursorWindow.getString(CursorWindow.java:438) at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
I think a null check should be added somewhere inside the appendFromCursor method of com.contentful.vault.compiler.ModelInjection class.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.