Worklight 5.0.6 JSONStore with Sync error - ibm-mobilefirst

I try to init JSONStore Sync with Adapter in Worklight 5.0.6 like below:
var usersSearchFields = {"age":"integer","name.demo":"string"},
usersAdapterOptions = {
name: 'user',
replace: 'updateUser',
remove: 'deleteUser',
add: 'addUser',
load: {
procedure: 'getUsers',
params: [],
key: 'users'
},
accept: function (data) {
return (data.status === 200);
}
};
var collections = {
users : {
searchFields : usersSearchFields,
adapter : usersAdapterOptions
}
};
var options = {
username: 'carlos',
password: '123'
};
var usersCollection=WL.JSONStore.init(collections, options)
.then(function (res) {
logMessage('Collection has been initialized');
})
.fail(function (errobject) {
WL.Logger.debug(errobject.toString());
});
It runs successfully in the first time but after i exit app then return, it gets error:
*"PROVISION_TABLE_SEARCH_FIELDS_MISMATCH"*
Anyone can help me please? Thank you very much.

It looks like the following known issue:
PM85364: JSONSTORE ERROR AFTER FIRST LAUNCH ON ANDROID WITH '.' IN SEARCH FIELDS.. To fix it upgrade to the 5.0.6.1 Fix Pack (Source).
Typically:
-2 PROVISION_TABLE_SEARCH_FIELDS_MISMATCH
You cannot change search fields without calling destroy or removeCollection and init or initCollection with the new search fields. This error can happen if you change the name or type of the search field. For example: {key: 'string'} to {key: 'number'} or {myKey: 'string'} to {theKey: 'string'}.
The documentation is here. I also recommend this StackOverflow answer on JSONStore debugging.
This fixes issues like the one you're facing:
Reset the Simulator or Emulator and/or call WL.JSONStore.destroy().

Related

cannot use the find functions using sequelize-typescript

I have setup passport and sequelize-typescript for my project. In the passport setup, I use a strategy for example google like this:
passport.use(
new GoogleStrategy(
{
clientID: process.env.GOOGLE_AUTH_CLIENT_ID,
clientSecret: process.env.GOOGLE_AUTH_CLIENT_SECRET,
callbackURL: process.env.GOOGLE_AUTH_CALLBACK_URL,
profileFields: ['id', 'displayName', 'photos', 'email'],
enableProof: true
},
function(accessToken, refreshToken, profile, done) {
console.log(profile)
const { name, email, picture } = profile._json;
User.findOne({where: {id: profile.id}})
.then(user => {
console.log(user)
if(user === null) {
const { name, email, picture } = profile._json;
// new User({
// id: profile.id,
// name: name,
// email: email,
// pictureUrl: picture,
// })
}
})
done(null, profile)
}
)
)
When I try to use functions such as findOrCreate() or findOne(), I receive a typescript error that says:
[ERROR] 23:29:01 ⨯ Unable to compile TypeScript:
src/passport_strategies.ts:45:18 - error TS2339: Property 'findOne' does not exist on type 'typeof User'.
45 User.findOne({where: {id: profile.id}})
I also get the same error for the part commented out in the first code snippet. The model user I have created is declared like this:
export class User extends Model<User> {} (It has the columns set in the file) Model being imported from sequelize-typescript
Here is where sequelize is created:
export const sequelize = new Sequelize({
"username": c.username,
"password": c.password,
"database": c.database,
"host": c.host,
dialect: 'postgres',
storage: ':memory:',
models: [__dirname + '/models']
});
I tried checking other examples that are on the internet but they all have the same setup and I couldn't figure out why I'm getting this error. Not sure if this helps at all but I'm using postgres dialect.
I suspect that it is a version mismatch.
sequelize-typescript#2 is for sequelize#6.2>= and sequelize-typescript#1 is for sequelize#5>=.
I also suggest for educational purposes to implement typescript with sequelize without the use of the sequelize-typescript package just for understanding the need of the package itself. https://sequelize.org/master/manual/typescript.html
Also just in case with all the respect, i point that #Table is needed if you are using the latest version.

Rally API for User story creation in a particular Project?

i have tried the following code with no luck
var rally = require('rally'),
restApi = rally({
user: 'userName', //required if no api key, defaults to process.env.RALLY_USERNAME
pass: 'password', //required if no api key, defaults to process.env.RALLY_PASSWORD
apiKey: 'XXXXX', //preferred, required if no user/pass, defaults to process.env.RALLY_API_KEY
apiVersion: 'v2.0', //this is the default and may be omitted
server: 'https://rally1.rallydev.com', //this is the default and may be omitted
requestOptions: {
headers: {
'X-RallyIntegrationName': 'My cool node.js program', //while optional, it is good practice to
'X-RallyIntegrationVendor': 'My company', //provide this header information
'X-RallyIntegrationVersion': '1.0'
}
//any additional request options (proxy options, timeouts, etc.)
}
});
restApi.create({
type: 'hierarchicalrequirement', //the type to create
data: {
Name: 'RallYUS',
//the data with which to populate the new object
},
fetch: ['FormattedID'], //the fields to be returned on the created object
scope: {
//optional, only required if creating in non-default workspace
project: 'rally',
workspace: 'abcd'
},
requestOptions: {} //optional additional options to pass through to request
}, function(error, result) {
if(error) {
console.log(error);
} else {
console.log(result.Object);
}
});
I was able to create a US but in a different project . I have been trying to fix the project issue and event entered ObjectID and Object UUID as well but still keeps creating in default project attached to user profile . Any help to force Userstory using hierarchialrelation with creation of US would definitely help
All object relationships are specified using refs in the Web Services API. This should work:
scope: {
project: '/project/12345' //where 12345 is the object id
}

React Native Realm data not persisted

I am using realm.write however my default.realm file is not being updated. I have also added another object to my schema and I can use this whilst developing my React Native app, but the default.realm file is not updated to include this new object.
I can confirm it is not being saved by opening default.realm in Realm Browser. Also, after turning my mac on this morning (after shutting down last night) and running my React Native app then data was not in my Realm when I tried to access it.
Example code:
#queries.js
import Realm from 'realm'
// Define your models and their properties
class Car {}
Car.schema = {
name: 'Car',
primaryKey: 'id',
properties: {
id: 'int',
make: 'string',
model: {type: 'string', optional: true}
}
}
class Person {}
Person.schema = {
name: 'Person',
properties: {
id: 'int',
name: 'string'
}
}
// Get the default Realm with support for our objects
let realm = new Realm({schema: [Car, Person], schemaVersion: 3});
class Queries {
async syncCars()
{
try {
let responsePromise = await fetch(`http://api.localhost.com:3000/v1/cars?auth_token=xxx`).catch(function(error) {
console.log('There has been a problem with your fetch operation: ' + error.message);
});
let responseJson = await responsePromise.json();
realm.write(() => {
responseJson.forEach((values) => {
realm.create('Car', values, true);
});
});
}
catch(error) {
console.log("error " + error);
}
}
}
export default new Queries
and then in my component code I have:
import Queries from './queries'
await Queries.syncCars();
As Kristian Dupont pointed out in the comments above, I was looking at the wrong file.
Following this answer I used realm.path in the Chrome debugger console and found the correct default.realm in a path that included /Library/Developer/CoreSimulator/Devices/. I'm not sure why OSX finder wasn't able to find this file. I'm unsure why a default.realm file was also created in my React Native directory but I have since deleted this file to avoid confusion and have had no further issues.

React Native Post image with hashtag to facebook

I'm trying to post an image with hashtag to facebook using react-native-fbsdk(0.4.0) like this:
ShareDialog.canShow(shareContent)
.then(canShow => {
if (canShow) {
return ShareDialog.show(shareContent);
} else {
return Promise.reject('error sharing');
}
})
.then(result => {
// evaluating result here
});
Share dialog appears normally and content is posted to FB when shareContent has the following content:
shareContent = {
contentType: 'photo',
photos: [{
imageUrl: 'valid uri'
}]
};
When I add a hashtag, share dialog doesn't appear and result is an empty object {}:
shareContent = {
contentType: 'photo',
commonParameters: {
hashtag: '#SomeHashTag'
},
photos: [{
imageUrl: 'the same valid uri'
}]
};
Also if I try to add a hashtag to other types like link share dialog works fine.
What I am doing wrong? :(
I've got the same problem. I wrote printF for displaying what happens inside FBSDKSharePhoto. And I noticed next info:
canOpenURL: failed for URL: "fbauth2:/" - error: "The operation
couldn’t be completed. (OSStatus error -10814.)"
Then I've googled this question and install facebook app on Iphone and loggedIn (you can't install facebook on emulator device you need use real device for this)
And it works for me.

Not able to save permission

I am attempting to create new project permissions for a user/project but the save is failing because "No valid Project provided". Looking at the network logs the RequestPayload in the server call is empty ({"ProjectPermission":{}}). Any ideas?
_addViewPermission: function() {
this.getModel().then({
success: this.createPP,
scope: this
}).then({
success: this.readPP,
scope: this
}).then({
success: function(result) {
console.log('success', result);
},
failure: function(error) {
console.log('oh noes!', error);
}
});
},
getModel: function() {
return Rally.data.ModelFactory.getModel({
type: 'ProjectPermission'
});
},
createPP: function(model) {
var permission = Ext.create(model, {
Project: "/project/51063976712",
Role: 'Viewer',
User: "/user/43049588391"
});
return permission.save();
},
readPP: function(permission){
console.log(permisson);
return permission.self.load(permission.getId(), {
fetch: ['Project', 'User', 'Role']
});
}
This is a longstanding strange defect in the AppSDK- sorry it tripped you up! I tried to find another stackoverflow post on it, but maybe it hasn't been asked here yet.
Anyway, the reason it is failing for you is that the Project field is marked as readonly even though it is required on create. So the proxy never sends along the project field even though you clearly specified it.
The workaround is to simply mark the project field as persistable before creating and saving a new record.
model.getField('Project').persist = true;