private void isClientForFirstMessageInStoreOK(StorableId msgId, Date storedOn) throws KapuaException { KapuaId tmpAccId = ((Account) stepData.get("LastAccount")).getId(); String tmpClId = ((Device) stepData.get("LastDevice")).getClientId(); AndPredicate andPredicate = new AndPredicateImpl(); andPredicate.getPredicates().add(new TermPredicateImpl(ClientInfoField.CLIENT_ID, tmpClId)); ClientInfoQuery clientInfoQuery = DatastoreQueryFactory.createBaseClientInfoQuery(tmpAccId, 100); clientInfoQuery.setPredicate(andPredicate); clientInfoQuery.addFetchAttributes(ClientInfoField.TIMESTAMP.field()); ClientInfoListResult clientInfoList = clientInfoRegistryService.query(clientInfoQuery); assertNotNull("Cannot find the client info registry!", clientInfoList); assertNotEquals("Cannot find the client info registry!", clientInfoList.getSize(), 0); assertNotNull("Cannot find the client info registry!", clientInfoList.getFirstItem()); assertEquals("Wrong client info message id!", clientInfoList.getFirstItem().getFirstMessageId(), msgId); assertEquals("Wrong client info message on!", clientInfoList.getFirstItem().getFirstMessageOn(), storedOn); }
/** * Find client information by identifier * * @param scopeId * @param id * @return * @throws KapuaIllegalArgumentException * @throws ConfigurationException * @throws QueryMappingException * @throws ClientException */ public ClientInfo find(KapuaId scopeId, StorableId id) throws KapuaIllegalArgumentException, ConfigurationException, QueryMappingException, ClientException { ArgumentValidator.notNull(scopeId, "scopeId"); ArgumentValidator.notNull(id, "id"); ClientInfoQueryImpl idsQuery = new ClientInfoQueryImpl(scopeId); idsQuery.setLimit(1); IdsPredicateImpl idsPredicate = new IdsPredicateImpl(ClientInfoSchema.CLIENT_TYPE_NAME); idsPredicate.addValue(id); idsQuery.setPredicate(idsPredicate); ClientInfoListResult result = query(idsQuery); return result.getFirstItem(); }