Skip to content

Commit

Permalink
Add aliasses to create datastore
Browse files Browse the repository at this point in the history
  • Loading branch information
anmunoz committed Sep 5, 2022
1 parent 8fa328b commit a4662f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private String resourceLookupOrCreateDynamicFields(String orgName, String pkgNam
cache.addRes(orgName, pkgName, resName);
cache.setResId(orgName, pkgName, resName, resId);
if(createDataStore){
createDataStoreWithFields(resId,records);
createDataStoreWithFields(resId,resName,records);
createView(resId);
}
return resId;
Expand All @@ -123,7 +123,7 @@ private String resourceLookupOrCreateDynamicFields(String orgName, String pkgNam
cache.addRes(orgName, pkgName, resName);
cache.setResId(orgName, pkgName, resName, resId);
if(createDataStore){
createDataStoreWithFields(resId,records);
createDataStoreWithFields(resId,resName,records);
createView(resId);
}
return resId;
Expand All @@ -140,7 +140,7 @@ private String resourceLookupOrCreateDynamicFields(String orgName, String pkgNam
cache.addRes(orgName, pkgName, resName);
cache.setResId(orgName, pkgName, resName, resId);
if(createDataStore){
createDataStoreWithFields(resId,records);
createDataStoreWithFields(resId, resName, records);
createView(resId);
}
return resId;
Expand Down Expand Up @@ -169,7 +169,7 @@ private String resourceLookupOrCreate(String orgName, String pkgName, String res
cache.addRes(orgName, pkgName, resName);
cache.setResId(orgName, pkgName, resName, resId);
if(createDataStore){
createDataStore(resId);
createDataStore(resId, resName);
createView(resId);
}
return resId;
Expand All @@ -192,7 +192,7 @@ private String resourceLookupOrCreate(String orgName, String pkgName, String res
cache.addRes(orgName, pkgName, resName);
cache.setResId(orgName, pkgName, resName, resId);
if(createDataStore){
createDataStore(resId);
createDataStore(resId, resName);
createView(resId);
}
return resId;
Expand All @@ -212,7 +212,7 @@ private String resourceLookupOrCreate(String orgName, String pkgName, String res
cache.addRes(orgName, pkgName, resName);
cache.setResId(orgName, pkgName, resName, resId);
if(createDataStore){
createDataStore(resId);
createDataStore(resId, resName);
createView(resId);
}
return resId;
Expand Down Expand Up @@ -460,10 +460,11 @@ private String createResource(String resName, String pkgId, DCATMetadata dcatMet
* @param resId Identifies the resource whose datastore is going to be created.
* @throws Exception
*/
private void createDataStore(String resId) throws Exception {
private void createDataStore(String resId, String resName) throws Exception {
// create the CKAN request JSON
// CKAN types reference: http://docs.ckan.org/en/ckan-2.2/datastore.html#valid-types
String jsonString = "{ \"resource_id\": \"" + resId
+ "\", \"aliases\": [\""+resName+"\"+ ],"
+ "\", \"fields\": [ "
+ "{ \"id\": \"" + NGSIConstants.RECV_TIME_TS + "\", \"type\": \"int\"},"
+ "{ \"id\": \"" + NGSIConstants.RECV_TIME + "\", \"type\": \"timestamp\"},"
Expand Down Expand Up @@ -498,7 +499,7 @@ private void createDataStore(String resId) throws Exception {
* @param records Array list with the attributes names for being used as fields with column mode
* @throws Exception
*/
private void createDataStoreWithFields(String resId, String records) throws Exception {
private void createDataStoreWithFields(String resId, String resName, String records) throws Exception {
// create the CKAN request JSON
// CKAN types reference: http://docs.ckan.org/en/ckan-2.2/datastore.html#valid-types
org.json.JSONObject jsonContent = new org.json.JSONObject(records);
Expand All @@ -521,6 +522,7 @@ private void createDataStoreWithFields(String resId, String records) throws Exce
}

dataStore.setResource_id(resId);
dataStore.setAliases(resName);
dataStore.setFields(jsonArray);
dataStore.setForce("true");
String jsonString = gson.toJson(dataStore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class DataStore {
private String resource_id;
private ArrayList<JsonElement> fields;
private String force;
private String aliases;

public DataStore(){}

Expand All @@ -35,4 +36,6 @@ public String getForce() {
public void setForce(String force) {
this.force = force;
}

public void setAliases(String aliases) { this.aliases = aliases; }
}

0 comments on commit a4662f4

Please sign in to comment.