Smack shows online/offline status incorrectly - openfire

This is my code to show online of line of friends of the current user.
final String me = "hieugioi#xxx.xxx.x.xx";
connection.connect();
connection.login(me, "123456");
final Roster roster = connection.getRoster();
final Collection<RosterEntry> entries = roster.getEntries();
for(final RosterEntry entry : entries) {
System.out.println("User: " + entry.getUser());
System.out.println("Name: " + entry.getName());
//System.out.println("Status: " + entry.getStatus());
final Presence p = roster.getPresence(entry.getUser());
System.out.println("====== Mode: " + p.getMode());
System.out.println("====== Status: " + p.getStatus());
}
The log shows
12-24 09:37:18.029: I/System.out(2831): User: hieungoan#xxx.xxx.x.xx
12-24 09:37:18.029: I/System.out(2831): Name: hieungoan
12-24 09:37:18.029: I/System.out(2831): ====== Mode: null
12-24 09:37:18.029: I/System.out(2831): ====== Status: null
12-24 09:37:18.029: I/System.out(2831): User: hieutot#xxx.xxx.x.xx
12-24 09:37:18.029: I/System.out(2831): Name: hieutot
12-24 09:37:18.029: I/System.out(2831): ====== Mode: null
12-24 09:37:18.029: I/System.out(2831): ====== Status: null
12-24 09:37:18.029: I/System.out(2831): User: hieuhay#xxx.xxx.x.xx
12-24 09:37:18.029: I/System.out(2831): Name: hieuhay
12-24 09:37:18.029: I/System.out(2831): ====== Mode: null
12-24 09:37:18.029: I/System.out(2831): ====== Status: null
12-24 09:37:18.029: I/System.out(2831): User: hieukhoe#xxx.xxx.x.xx
12-24 09:37:18.029: I/System.out(2831): Name: hieukhoe
12-24 09:37:18.029: I/System.out(2831): ====== Mode: null
12-24 09:37:18.029: I/System.out(2831): ====== Status: null
In fact the users hieutot and hieungoan is online in Openfire but it always show NULL as above! What's wrong with my code?

Please check out the section on Listening for Roster and Presence Changes.

Related

How do I search in redis json

I'm currently new to ioredis and I was wondering how o I can search all the json object that has a key value of something.
Example
rooms:{
roomId1: {
name: "room1",
users: [{userId: 1, name: "bob"}, {userId: 2, name: "joe}]
},
roomId2: {
name: "room2",
users: [{userId: 1, name: "jill"}, {userId: 2, name: "joe}]
},
roomId3: {
name: "room3",
users: [{userId: 6, name: "hoi"}, {userId: 1, name: "bob}]
}
}
and I want find all the rooms that has the user "bob" so I want the output to be
[roomId1: {
name: "room1",
users: [{userId: 1, name: "bob"}, {userId: 2, name: "joe}]
}, roomId3: {
name: "room3",
users: [{userId: 6, name: "hoi"}, {userId: 1, name: "bob}]
}]
How cna i achievee this? I guess I can do something like this
const redis = new Redis();
const roomStates = await redis.get("rooms");
//for loop and inner for loop to find the users name bob
but I was wondeirng if theres a faster way of doing it using the redis built in functions

Compare two result sets if employee Id is matches change status flag to true

Can anyone kindly provide the DataWeave logic for the below output structure based on the two Inputs resultSet1 and resultSet2. if the id is matched change the status to true and by default, the status is false?
resultSet1 = [{
id: "12334",
},
{
id: "13357",
}
]
resultSet2 = [
{
id: "12334",
status: false
},
{
id: "11521",
status: false
},
{
id: "13357",
status: false
}
final output:
[
{
id: "12334",
status: true
},
{
id: "11521",
status: false
},
{
id: "13357",
status: true
}
]
Thanks in advance!
this solution iterates resultSet2 and for each item checks if the ID is in the list of IDs of resultSet1
resultSet2 map {
id: $.id,
status: resultSet1.id contains $.id
}

Swagger Parser error duplicated mapping key

Hi friends, I have an error during yaml API testing in Swagger editor
I have duplicate mapping key error in line no 98
I try to force execute the testing I have :
Failed to fetch.
Possible Reasons:
CORS
Network Failure
URL scheme must be "http" or "https" for CORS request. ----- this error please help me!!..
openapi: 3.0.0
info:
title: 06-jobs-api
contact: {}
version: '1.0'
servers:
- url: https://new-jobs-api.herokuapp.com/api/v1
variables: {}
paths:
/auth/register:
post:
tags:
- Auth
summary: register
operationId: register
parameters: []
requestBody:
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/registerrequest'
example:
name: josh
email: josh#gmail.com
password: joshgmail.com
required: true
responses:
'200':
description: ''
headers: {}
deprecated: false
security: []
/auth/login:
post:
tags:
- Auth
summary: login
operationId: login
parameters: []
requestBody:
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/loginrequest'
example:
email: john#gmail.com
password: john#gmail.com
required: true
responses:
'200':
description: ''
headers: {}
deprecated: false
security: []
/jobs:
post:
tags:
- Jobs
summary: create job
operationId: createjob
parameters: []
requestBody:
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/createjobrequest'
example:
company: mongodb
position: back-end developer
required: true
responses:
'200':
description: ''
headers: {}
deprecated: false
get:
tags:
- Jobs
summary: get all jobs
operationId: getalljobs
parameters: []
responses:
'200':
description: ''
headers: {}
deprecated: false
/jobs/{id}:
parameters:
- in: path
name: id
schema:
type: string
required: true
description: The user ID
get: ----- here I have an error line no 98
tags:
- Jobs
summary: get single job
operationId: getsinglejob
parameters: []
responses:
'200':
description: ''
headers: {}
deprecated: false
patch:
tags:
- Jobs
summary: update job
operationId: updatejob
parameters: []
requestBody:
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/updatejobrequest'
example:
company: prime
position: front-end developer
required: true
responses:
'200':
description: ''
headers: {}
deprecated: false
delete:
tags:
- Jobs
summary: delete job
operationId: deletejob
parameters: []
responses:
'200':
description: ''
headers: {}
deprecated: false
components:
schemas:
registerrequest:
title: registerrequest
required:
- name
- email
- password
type: object
properties:
name:
type: string
email:
type: string
password:
type: string
example:
name: josh
email: josh#gmail.com
password: joshgmail.com
createjobrequest:
title: createjobrequest
required:
- company
- position
type: object
properties:
company:
type: string
position:
type: string
example:
company: mongodb
position: back-end developer
updatejobrequest:
title: updatejobrequest
required:
- company
- position
type: object
properties:
company:
type: string
position:
type: string
example:
company: prime
position: front-end developer
loginrequest:
title: loginrequest
required:
- email
- password
type: object
properties:
email:
type: string
password:
type: string
example:
email: john#gmail.com
password: john#gmail.com
securitySchemes:
httpBearer:
type: http
scheme: bearer
security:
- httpBearer: []
tags:
- name: Misc
description: ''
- name: Auth
description: ''
- name: Jobs
description: ''
You need to unindent /jobs/{id} in line 90 by two spaces.

strongloop loopback find users role using loaded operation hook

I have cloned a https://github.com/beeman/loopback-angular-admin and I have created a couple of new roles using the loopback explorer and I am trying to get all the roles of a particular user when he logs in by loaded operation hook defined here -
https://docs.strongloop.com/display/public/LB/Operation+hooks#Operationhooks-loaded
like this -
user.observe('loaded', function appendRole(ctx, next){
if(ctx.instance){
user.findOne({
where: {
id: ctx.instance.id
},
include: {
"relation":"roles"
}
})
}
next();
})
so how do I return roles of a particular user using operation hooks. I am able to get all the roles of a user using loopback explorer using this api call
http://localhost:80/api/users/567ce48d6503f9404b56bb3e/roles?access_token=gyPzW3rpr3uzve2bUHtZQWv8iV5PfZYW7QLicCs4GwIKTdNA33SeRAlgPIQef7AE
UPDATE :
So, I tried adding the following code to the user.js -
user.observe('loaded', function appendRole(ctx, next){
if(ctx.instance){
console.log(ctx.instance.roles);
}
next();
})
and I am getting the following output in the console -
{ [Function]
_receiver:
{ username: 'harshitladdha93#gmail.com',
password: '$2a$10$Bubhaq1LXFyCUn.W1/pEOewLSqspcP2GQlONwGH98V4HqCOAc9522',
email: 'harshitladdha93#gmail.com',
status: 'created',
created: Mon Jan 04 2016 22:53:53 GMT+0530 (IST),
firstName: 'Harshit',
lastName: 'Laddha',
gender: 'male',
birthday: '1993-07-30T18:30:00.000Z',
qualification: 'sa;',
experience: 'askjdl',
achievements: 'sakldj',
street: 'has',
locality: 'alskjd',
area: 'lkjd',
city: 'bangalore',
id: 568aaaa997ace4670b5d9ac2 },
_scope:
{ where: { principalId: 568aaaa997ace4670b5d9ac2 },
collect: 'role',
include: 'role' },
_targetClass: 'Role',
getAsync: [Function],
build: [Function: build],
create: [Function],
updateAll: [Function: updateAll],
destroyAll: [Function: destroyAll],
findById: [Function],
findOne: [Function: findOne],
count: [Function: count],
destroy: [Function],
updateById: [Function],
exists: [Function],
add: [Function],
remove: [Function] }
so how do I get the roles of user using loaded operation hook
Did you try ctx.instance.roles?
UPDATE: Ah crap, that's right, I guess you'll need to do a lookup, but you can't use a user.find() since it will trigger an infinite loop on the loaded observe. Try something like this:
user.observe('loaded', function getRoleMappings(ctx, next) {
var roleMapFilter = {
where: {principalId: ctx.instance.id},
include: ['role']
};
user.app.models.RoleMapping.find(roleMapFilter, function(err, roleMaps) {
if (err) {
console.log('roleMap', err);
next(err);
}
console.log("roleMaps ", roleMaps);
next();
});
});
console.log("roleMaps ", roleMaps); should output something like:
roleMaps [
{
id: 1,
principalType: 'USER',
principalId: '1',
roleId: 1,
role: {
id: 1,
name: 'admin',
description: null,
created: Thu Jun 25 2015 10:24:40 GMT-0700 (PDT),
modified: Thu Jun 25 2015 10:24:40 GMT-0700 (PDT)
}
},
{
id: 2,
principalType: 'USER',
principalId: '1',
roleId: 6,
role: {
id: 6,
name: 'sales',
description: null,
created: Thu Jun 25 2015 10:24:40 GMT-0700 (PDT),
modified: Thu Jun 25 2015 10:24:40 GMT-0700 (PDT)
}
}
]

LokiJS: insert existing value for index doesn't error - how to make unique indices?

if I try to override an existing indexed field, I do not get an error.
It should error, because it is not update()!
var loki = require('lokijs');
var db = new loki('test.json');
var users = db.addCollection('users', { indices: ['userID']});
users.insert(
{
'name': 'Anna',
'userID': 1
},
{
'name': 'Bernd',
'userID': 2
},
{
'name': 'Christa',
'userID': 3
});
db.save();
users.insert({'name': 'Dieter','userID': 2}); // this should error!!
How can I make an unique index to get an error when trying to inset an existing userID ?
the indices option creates an index on the field, which allows for faster retrieval because the index lives in a separate sorted array within the collection (so Loki can use binary-search instead of a full loop to fetch records). However, you're looking for a unique index, which is created with ensureUniqueIndex (check here, scroll down to Finding Documents, there's a section on unique indexes.). With that, you can use the collection method by(field, value) (which can even be curried if you only pass the field value), which uses the unique index to full potential (about 2x the speed of an indexed field). Remember that you need to explicitly call ensureUniqueIndex because unique indexes cannot be serialized and persisted.
update: once the ensureUniqueIndex method is called, the collection will throw an error if you try to insert a duplicate key record. If you have repository checked out you can take a look at spec/generic/unique.spec.js for an example ( here )
var loki = require('lokijs');
var db = new loki('test.json');
var users = db.addCollection('users', { indices: ['userID']});
users.ensureUniqueIndex('userID');
users.on('error',function(obj){
console.log('error ... adding 1 to userID');
obj.userID = obj.userID+1;
return obj;
});
users.insert(
{
'name': 'Anna',
'userID': 1
});
users.insert(
{
'name': 'Bernd',
'userID': 2
});
users.insert(
{
'name': 'Christa',
'userID': 3
});
db.save();
console.log(users.data);
try {
users.insert({'name': 'Dieter','userID': 2}); // this should error!!
} catch(e){
var i = 2+1;
users.insert({'name': 'Dieter','userID': i}); // this should error!!
}
db.save();
db2 = new loki('test.json');
db2.loadDatabase({}, function () {
var users2 = db2.getCollection('users')
console.log(users2.data);
});
Either users.on('error',...) nor try{ users.insert...} catch(e){// id+1} handles the thrown error
That's my console:
[ { name: 'Anna',
userID: 1,
meta: { revision: 0, created: 1436186694342, version: 0 },
'$loki': 1 },
{ name: 'Bernd',
userID: 2,
meta: { revision: 0, created: 1436186694342, version: 0 },
'$loki': 2 },
{ name: 'Christa',
userID: 3,
meta: { revision: 0, created: 1436186694342, version: 0 },
'$loki': 3 } ]
Duplicate key for property userID: 2
[ { name: 'Anna',
userID: 1,
meta: { revision: 0, created: 1436186694342, version: 0 },
'$loki': 1 },
{ name: 'Bernd',
userID: 2,
meta: { revision: 0, created: 1436186694342, version: 0 },
'$loki': 2 },
{ name: 'Christa',
userID: 3,
meta: { revision: 0, created: 1436186694342, version: 0 },
'$loki': 3 },
{ name: 'Dieter',
userID: 2,
meta: { revision: 0, created: 0, version: 0 },
'$loki': 4 } ]