Liferay 7.2 Finder unsatisfied references - liferay-7

I have Liferay 7.2
I created a module service " blogentriesfinderservice".
I used service builder to create entity.
Now i want a custom query.
I created FooFinderImpl but i have this error in liferay:
Bundle {id: 4459, name: blogentriesfinderservice.service, version: 1.0.0}
Declarative Service {id: 4932, name: blogentriesfinderservice.service.impl.FooLocalServiceImpl, unsatisfied references:
{name: fooFinder, target: null}
}
Declarative Service {id: 4933, name: blogentriesfinderservice.service.impl.FooServiceImpl, unsatisfied references:
{name: fooFinder, target: null}
{name: fooLocalService, target: null}
}
This is the code of FooFinderImpl
package blogentriesfinderservice.service.persistence.impl;
import java.util.List;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl;
import blogentriesfinderservice.model.Foo;
import blogentriesfinderservice.model.impl.FooImpl;
import blogentriesfinderservice.service.persistence.FooFinder;
import com.liferay.portal.dao.orm.custom.sql.CustomSQLUtil;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.SQLQuery;
public class FooFinderImpl extends FooFinderBaseImpl implements FooFinder {
public String findByDentroFinder() {
return "test";
}
}

I found the solution.
I need to add this code before class declaration:
#Component(
service = FooFinder.class
)

Related

Use process.env inside imported const in jest

I have a config file that exports some info for my app.
export const config: Config = {
isProd: process.env.NODE_ENV == 'production',
connection: {
port: parseInt(process.env.APP_PORT) || 2000,
},
};
And I want to import it and use inside my e2e jest test.
import {Test, TestingModule} from "#nestjs/testing";
import {INestApplication} from "#nestjs/common";
import * as request from "supertest";
import {AppModule} from "./../src/app.module";
import * as dotenv from "dotenv";
dotenv.config({path: ".env"});
import {config} from "../src/infrastructure/config/config"
console.log(process.env); // available here
console.log(config); // will return default values, not from .env
// ...
How can i make jest use env inside imported module?
Nestjs has great configuration modules that support .env:
https://docs.nestjs.com/techniques/configuration#custom-env-file-path
Makes it really easy to ref your configuration in all of your services as opposed to having to import.

Face Verification based Attendance system

import attendence_sys.models
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('attendence_sys', '0004_auto_20200626_2227'),
]
operations = [
migrations.AlterField(
model_name='faculty',
name='profile_pic',
field=models.ImageField(blank=True, null=True, upload_to=attendence_sys.models.user_directory_path),
),
]
File "c:\Users\hasif\OneDrive\Documents\Face_Verification_based_Attendance_system-master\attendence_sys\migrations\0005_auto_20200626_2245.py",
line 3, in
import attendence_sys.models
ModuleNotFoundError: No module named 'attendence_sys'

Connect to Mongo (hosted on VM) from local machine using SpringBoot

I have setup MongoDB on a VM. Now I need connect to Mongo (hosted on VM) from local machine using SpringBoot. What do I change in application.propeties file given that I have that VMs' username, password and IP address.
How do I set up Mongo in VM for the below InitDatabase class
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.stereotype.Component;
#Component
public class InitDatabase {
#Bean
CommandLineRunner init(MongoOperations operations) {
return args -> {
operations.dropCollection(Image.class);
operations.insert(new Image("1",
"learning-spring-boot-cover.jpg"));
operations.insert(new Image("2",
"learning-spring-boot-2nd-edition-cover.jpg"));
operations.insert(new Image("3",
"bazinga.png"));
operations.findAll(Image.class).forEach(image -> {
System.out.println(image.toString());
});
};
}
}
You should override spring.mongodb configuration properties :
MongoDB config
spring.data.mongodb.authentication-database= *which_authentication_database_you_want_to_connect*
spring.data.mongodb.username=*database_username*
spring.data.mongodb.password=*database_password*
spring.data.mongodb.database=*which_database_you_want_to_connect*
spring.data.mongodb.port=*running_mongo_instance_port*
spring.data.mongodb.host=*running_mongo_instance_host -- you should write your own VM's ip address*

NestJS: Resolving dependencies in NestMiddleware?

I'm trying to combine express-session with a typeorm storage within NestJS framework. Therefore I wrote a NestMiddleware as wrapper for express-session (see below). When I start node, NestJS logs the following
Error message:
UnhandledPromiseRejectionWarning: Unhandled promise rejection
(rejection id: 1): Error: Nest can't resolve dependencies of the
SessionMiddleware (?). Please verify whether [0] argument is available
in the current context.
Express is not started (connection refused), but the Sqlite DB (where the sessions should be stored) is created (also a session table, but not the columns).
To me it looks like there is a special problem in resolving dependencies with #InjectRepository from nestjs/typorm-Module. Does anyone have a hint?
Code:
import { Middleware, NestMiddleware, ExpressMiddleware } from '#nestjs/common';
import * as expressSession from 'express-session';
import { InjectRepository } from '#nestjs/typeorm';
import { Repository } from 'typeorm';
import { TypeormStore } from 'connect-typeorm';
import { Session } from './session.entity';
#Middleware()
export class SessionMiddleware implements NestMiddleware {
constructor(
#InjectRepository(Session)
private readonly sessionRepository: Repository<Session>
) {}
resolve(): ExpressMiddleware {
return expressSession({
store: new TypeormStore({ ttl: 86400 }).connect(this.sessionRepository),
secret: 'secret'
});
}
}
It was my fault. Had the middleware in a module, but was configuring the session middleware at the app module level. On that level the following import statement was missing:
TypeOrmModule.forFeature([Session])
Moved now everything to non-app module including middleware configuration. That solved the problem.

elastic4s NoNodeAvailableException when connecting through TcpClient.transport

Am trying to get my hands on elastic4s by one of the samples as given
here
But I keep getting the below exception when am trying to connect through TcpClient.transport :
Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{IFyYWnE_S4aHRVxT9v60LQ}{dockerhost}{192.168.99.100:9300}]]
Am trying to connect to an elastic instance on docker, elastic version is 2.3.4
Here is my code below dependencies.
import com.sksamuel.elastic4s.{ElasticClient, ElasticsearchClientUri, TcpClient}
import org.elasticsearch.action.support.WriteRequest.RefreshPolicy
import org.elasticsearch.common.settings.Settings
import com.sksamuel.elastic4s.ElasticDsl._
object Main extends App {
//val settings = Settings.builder().put("cluster.name", "elasticsearch").build()
val client = TcpClient.transport(ElasticsearchClientUri("elasticsearch://dockerhost:9300"))
client.execute {
bulk(
indexInto("myindex" / "mytype").fields("country" -> "Mongolia", "capital" -> "Ulaanbaatar"),
indexInto("myindex" / "mytype").fields("country" -> "Namibia", "capital" -> "Windhoek")
).refresh(RefreshPolicy.WAIT_UNTIL)
}.await
val result = client.execute {
search("myindex").matchQuery("capital", "ulaanbaatar")
}.await
println(result.hits.head.sourceAsString)
client.close()
}
build.gradle:
compile group: 'com.sksamuel.elastic4s', name: 'elastic4s-core_2.11', version: '5.4.9'
compile group: 'com.sksamuel.elastic4s', name: 'elastic4s-tcp_2.11', version: '5.4.9'
compile group: 'com.sksamuel.elastic4s', name: 'elastic4s-http_2.11', version: '5.4.9'
compile group: 'com.sksamuel.elastic4s', name: 'elastic4s-streams_2.11', version: '5.4.9'
Any help regarding this issue would be helpful.
I am asked this question a lot, and 99% of the time, the answer to this question is
The cluster name is not the default (elasticsearch) and therefore it must be specified in the connection string.
The server is not setup to listen outside of localhost. https://www.elastic.co/blog/elasticsearch-unplugged