Skip to content

Commit

Permalink
Merge pull request #70 from contentstack/master
Browse files Browse the repository at this point in the history
Back Merge
  • Loading branch information
cs-raj authored Sep 12, 2024
2 parents 58a18e9 + 5fe94a8 commit e01b28e
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 13 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG

## Version 3.16.1

### Date: 21-August-2024

- Fetch Asset by query

---

## Version 3.16.0

### Date: 31-July-2024
Expand Down
23 changes: 16 additions & 7 deletions contentstack/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android.buildFeatures.buildConfig true
mavenPublishing {
publishToMavenCentral(SonatypeHost.DEFAULT)
signAllPublications()
coordinates("com.contentstack.sdk", "android", "3.16.0")
coordinates("com.contentstack.sdk", "android", "4.0.0")

pom {
name = "contentstack-android"
Expand Down Expand Up @@ -112,18 +112,27 @@ android {

def localProperties = new Properties()
localProperties.load(new FileInputStream(rootProject.file("local.properties")))
def getPropertyOrEmpty = { key ->
def value = localProperties.getProperty(key)
return value != null ? "$value" : "\"\""
}
def variantsArray = localProperties.getProperty('variantsUID')?.split(",")?.collect { it.trim() }
def variantsAsArrayString = variantsArray ? 'new String[] {' + variantsArray.collect { "\"$it\"" }.join(", ") + '}' : "new String[0]"
buildTypes {
debug {
debuggable true
testCoverageEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

buildConfigField "String", "host", localProperties['host']
buildConfigField "String", "APIKey", localProperties['APIKey']
buildConfigField "String", "deliveryToken", localProperties['deliveryToken']
buildConfigField "String", "environment", localProperties['environment']
buildConfigField "String", "contentTypeUID", localProperties['contentType']
buildConfigField "String", "assetUID", localProperties['assetUid']
buildConfigField "String", "host", getPropertyOrEmpty('host')
buildConfigField "String", "APIKey", getPropertyOrEmpty('APIKey')
buildConfigField "String", "deliveryToken", getPropertyOrEmpty('deliveryToken')
buildConfigField "String", "environment", getPropertyOrEmpty('environment')
buildConfigField "String", "contentTypeUID", getPropertyOrEmpty('contentType')
buildConfigField "String", "assetUID", getPropertyOrEmpty('assetUid')
buildConfigField "String", "variantUID", getPropertyOrEmpty('variantUID')
buildConfigField "String", "variantEntryUID", getPropertyOrEmpty('variantEntryUID')
buildConfigField "String[]", "variantsUID", variantsAsArrayString
}
release {
minifyEnabled false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import org.junit.runners.MethodSorters;

import java.util.List;
import java.util.concurrent.CountDownLatch;

import static junit.framework.Assert.assertTrue;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;

import androidx.test.InstrumentationRegistry;
import androidx.test.core.app.ApplicationProvider;
Expand All @@ -22,6 +24,8 @@ public class AssetTestCase {
private final String TAG = AssetTestCase.class.getSimpleName();
private static String assetUid = BuildConfig.assetUID;
private static Stack stack;
private static CountDownLatch latch;


@BeforeClass
public static void oneTimeSetUp() throws Exception {
Expand Down Expand Up @@ -191,4 +195,75 @@ public void test_GCP_NA() throws Exception {
stack = Contentstack.stack(appContext, DEFAULT_API_KEY, DEFAULT_DELIVERY_TOKEN, DEFAULT_ENV, config);
}

@Test
public void test_I_fetch_asset_by_title() {
final AssetLibrary assetLibrary = stack.assetLibrary().where("title", "iot-icon.png");
assetLibrary.fetchAll(new FetchAssetsCallback() {
@Override
public void onCompletion(ResponseType responseType, List<Asset> assets, Error error) {
if (error == null) {
for (Asset asset : assets) {
Log.d("RESULT:", "resp" + asset.json);
}
}
}
});
}

@Test
public void test_J_fetch_asset_by_tags() {
final AssetLibrary assetLibrary = stack.assetLibrary().where("tags","tag1");
assetLibrary.fetchAll(new FetchAssetsCallback() {
@Override
public void onCompletion(ResponseType responseType, List<Asset> assets, Error error) {
if (error == null) {
for( Asset asset : assets){
Log.d("RESULT:", "resp" + asset.json);
}
assertTrue(assets.size()>0);
}
}
});
}

@Test
public void test_K_fetch_asset_by_description() {
final AssetLibrary assetLibrary= stack.assetLibrary().where("description","Page1");
assetLibrary.fetchAll(new FetchAssetsCallback() {
@Override
public void onCompletion(ResponseType responseType, List<Asset> assets, Error error) {
for(Asset asset : assets){
Log.d("RESULT:", "resp" + asset.toJSON());
}
assertTrue(assets.size()>0);
}
});
}

@Test
public void test_L_fetch_asset_invalid() {
final AssetLibrary assetLibrary = stack.assetLibrary().where("title",null);
assetLibrary.fetchAll(new FetchAssetsCallback() {
@Override
public void onCompletion(ResponseType responseType, List<Asset> assets, Error error) {
Log.e("RESULT:", "ERROR:"+ error.errorMessage);
}
});

}

@Test
public void test_M_fetch_asset_empty_title() {
final AssetLibrary assetLibrary = stack.assetLibrary().where("title","");
assetLibrary.fetchAll(new FetchAssetsCallback() {
@Override
public void onCompletion(ResponseType responseType, List<Asset> assets, Error error) {
for(Asset asset : assets){
Log.d("RESULT:", "resp: " + asset.toJSON());
}
assertEquals(0, assets.size());
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class EntryTestCase {
private static final String CONTENT_TYPE_UID = BuildConfig.contentTypeUID;
private static CountDownLatch latch;
private static Stack stack;
private static String variantUID = BuildConfig.variantUID;
private static String variantEntryUID = BuildConfig.variantEntryUID;
private static String[] variantsUID = BuildConfig.variantsUID;


@BeforeClass
Expand Down Expand Up @@ -319,4 +322,26 @@ public void onCompletion(ResponseType responseType, Error error) {
latch.await();
}

@Test
public void VariantsTestSingleUid(){
final Entry entry = stack.contentType("product").entry(variantEntryUID).variants(variantUID);
entry.fetch(new EntryResultCallBack() {
@Override
public void onCompletion(ResponseType responseType, Error error) {
assertEquals(variantUID, entry.getHeaders().get("x-cs-variant-uid"));
System.out.println(entry.toJSON());
}
});
}
@Test
public void VariantsTestArray(){
final Entry entry = stack.contentType("product").entry(variantEntryUID).variants(variantsUID);
entry.fetch(new EntryResultCallBack() {
@Override
public void onCompletion(ResponseType responseType, Error error) {
System.out.println(entry.toJSON());
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import android.content.Context;
import android.util.Log;
Expand Down Expand Up @@ -98,4 +99,30 @@ public void onCompletion(SyncStack syncStack, Error error) {
});
assertNotNull(stack.syncParams);
}

@Test
public void testEarlyAccess() throws Exception {
Context ctx = ApplicationProvider.getApplicationContext();
Config config = new Config();
String[] earlyAccess = {"Taxonomy"};
config.earlyAccess(earlyAccess);
stack = Contentstack.stack(ctx, apiKey, deliveryToken, environment, config);
assertEquals(earlyAccess[0], config.earlyAccess[0]);
assertNotNull(stack.localHeader.containsKey("x-header-ea"));
assertEquals("Taxonomy", stack.localHeader.get("x-header-ea"));
}

@Test
public void testConfigEarlyAccessMultipleFeature() throws Exception {
Context ctx = ApplicationProvider.getApplicationContext();
Config config = new Config();
String[] earlyAccess = {"Taxonomy", "Teams", "Terms", "LivePreview"};
config.earlyAccess(earlyAccess);
stack = Contentstack.stack(ctx, apiKey, deliveryToken, environment, config);
assertEquals(4, stack.localHeader.keySet().size());
assertEquals(earlyAccess[1], config.earlyAccess[1]);
assertTrue(stack.localHeader.containsKey("x-header-ea"));
assertEquals("Taxonomy,Teams,Terms,LivePreview", stack.localHeader.get("x-header-ea"));
}

}
15 changes: 15 additions & 0 deletions contentstack/src/main/java/com/contentstack/sdk/AssetLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,5 +452,20 @@ public AssetLibrary includeMetadata() {
}
return this;
}
public AssetLibrary where(String key, String value) {
if (value != null) {
try {
JSONObject queryParams = new JSONObject();
queryParams.put(key, value);
urlQueries.put("query", queryParams);
} catch (JSONException e) {
Log.e(TAG, "JSON error: " + e.getLocalizedMessage());
}
} else {
Log.e(TAG, "Value for key '" + key + "' is null. Skipping addition to query.");
}
return this;
}


}
36 changes: 36 additions & 0 deletions contentstack/src/main/java/com/contentstack/sdk/Entry.java
Original file line number Diff line number Diff line change
Expand Up @@ -1494,4 +1494,40 @@ public Entry includeMetadata() {
}
return this;
}
/**
* method variants
* memberof Entry
* description The variant header will be added to client
* returns {Entry}
* example
* import contentstack from '@contentstack/delivery-sdk'
*
* Stack stack = contentstack.Stack("apiKey", "deliveryToken",
* "environment");
* Entry entry =
* stack.contentType("user").entry("entry_uid").variant("variant_uid").fetch();
*/
public Entry variants(String variants){
if (variants != null && variants.length() > 0) {
this.localHeader.put("x-cs-variant-uid", variants.trim());
}
return this;

}
public Entry variants(String[] variants){
if (variants != null && variants.length > 0) {
List<String> variantList = new ArrayList<>();
for (String variant : variants) {
if(variant != null && !variant.trim().isEmpty())
variantList.add(variant.trim());
}
if(!variantList.isEmpty()){
this.localHeader.put("x-cs-variant-uid", String.join(", ", variantList));
}
}
return this;
}
public ArrayMap<String, Object> getHeaders() {
return localHeader;
}
}
9 changes: 3 additions & 6 deletions contentstack/src/main/java/com/contentstack/sdk/SDKUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,9 @@ public String getSHAFromString(String value) {
// Create Hex String
// deepcode ignore ApiMigration: <please specify a reason of ignoring this>
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < messageDigest.length; i++) {
String hex = Integer.toHexString(0xFF & messageDigest[i]);
if (hex.length() == 1) {
hexString.append('0');
}
hexString.append(hex);
for (byte b : messageDigest) {
// Format each byte as two-digit hexadecimal
hexString.append(String.format("%02X", b));
}

return hexString.toString();
Expand Down

0 comments on commit e01b28e

Please sign in to comment.