Broadleaf: error in execting custom service - broadleaf-commerce

Hi I Have Created a Custom Service to Save Custom objects and using existing objects but after running the application the following error will be displaying in server console and stops the application to start
Here is my code for custom service :
#Service
public class FilterExtra {
// #Autowired
#Resource(name="org.broadleafcommerce.core.search.domain.FieldImpl")
FieldImpl f;
// #Autowired
#Resource(name="org.broadleafcommerce.core.catalog.domain.Product")
Product p;
public static String nme="";
#PersistenceContext(unitName = "blPU")
public EntityManager em;
ProductAttribute pa;
#SuppressWarnings("unchecked")
public String check1(String name) {
Query q=em.createQuery("SELECT * FROM PRODUCT_ATTRIBUTE WHERE NAME=:name");
q.setParameter("name", name);
List<ProductAttribute> inf0 = q.getResultList();
System.out.println(inf0);
if(inf0!=null)
{
f.setFriendlyName(name);
f.setAbbreviation(name);
f.setEntityType(p.getFieldEntityType());
f.setPropertyName("productAttributes("+name+").value");
em.merge(f);
}
if(name.equals(nme))
{
return name;
}
else {
return null;
}
}
}
here is my XML file:
screen shot of xml file:
http://i.prntscr.com/wkVH2q8MQBmAeJ26BfEvZw.png
here is server log for error:
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-11-23 09:59:43.881 ERROR 3827 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
APPLICATION FAILED TO START
Description:
A component required a bean named 'org.broadleafcommerce.core.search.domain.FieldImpl' that could not be found.
Action:
Consider defining a bean named 'org.broadleafcommerce.core.search.domain.FieldImpl' in your configuration.
Please Help me to Solve the issue
Thanks in Advance

Related

Trying to follow .AddService & .UseService pattern

In my Minimal API, I use and integrate with Kofax TotalAgility WCF endpoints. I wanted to implement this integration properly, so I added a remote assembly and added the WCF contract in it along with the service interface and implementation:
Service Interface:
public interface IKofaxService
{
public Task<string> CreateJob(long letterId);
public Task ActionHandler(PortalActionRequest request);
}
Service implementation:
public class KofaxService : IKofaxService
{
private readonly ILogger<KofaxService> logger;
private readonly KofaxSetup config;
private readonly KtaJob.IJobService jobService;
private readonly KtaActivity.IActivityService activityService;
public KofaxService(ILogger<KofaxService> inLogger, KofaxSetup inConfig)
{
logger = inLogger;
// Here is the problem: THe constructor's parameter should be IOptions<Kofaxsetup> instead of just KofaxSetup and this below line will become:
// config = inConfig.Value;
config = inConfig;
//WCF Generated Stuff within this remote assembly
jobService = new KtaJob.JobServiceClient(GetBinding(), GetEndpointAddress(config.KtaUrlApiJob));
activityService = new KtaActivity.ActivityServiceClient(GetBinding(), GetEndpointAddress(config.KtaUrlApiActivity));
}
public async Task<string> CreateJob(long letterId)
{
...
}
public async Task ActionHandler(PortalActionRequest request)
{
...
}
}
In order to have a Servces.AddKofaxTotalAgility() like fluent API, I added the extension method like so (in the remote assembly):
Service extension method:
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddKofaxTotalAgility(this IServiceCollection services)
{
services.AddScoped<IKofaxService, KofaxService>();
return services;
}
}
Also in the remote assembly, I have a class representing the setting object from appSetting's section:
Config class:
public class KofaxSetup
{
public string KtaUrlApiActivity { get; set; } = string.Empty;
public string KtaUrlApiJob { get; set; } = string.Empty;
public string SessionId { get; set; } = string.Empty;
public string ProcessId { get; set; } = string.Empty;
}
Back in the Minimal API project, I added a reference to the remote assembly and also have the settings in appSettings.json file:
appSettings.json:
{
...
"KofaxSetup": {
"KtaUrlApiActivity": "https://kofax.somewhere.com/TotalAgility/Services/SDK/ActivityService.svc",
"KtaUrlApiJob": "https://kofax.somewhere.com/TotalAgility/Services/SDK/JobService.svc",
"SessionId": "7DB87F70018D4770BF6114B1C9BA6041",
"ProcessId": "66EC6EED5D024E7AB0013D60F7A04A1A"
},
...
}
Lastly, modifications to Program.cs are as follows:
Minimal API Program.cs
var builder = WebApplication.CreateBuilder(args);
...
// Trigger KofaxSetting object from AppSetting's section
builder.Services.Configure<KofaxSetup>(builder.Configuration.GetSection(nameof(KofaxSetup)));
...
// Add the service to the DI
builder.Services.AddKofaxTotalAgility();
...
All of this just results in this exception at startup:
Exception # var app = builder.Build();
System.AggregateException: 'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: DACRL.Integrations.Kofax.IKofaxService Lifetime: Scoped ImplementationType: DACRL.Integrations.Kofax.KofaxService': Unable to resolve service for type 'DACRL.Integrations.Kofax.Configs.KofaxSetup' while attempting to activate 'DACRL.Integrations.Kofax.KofaxService'.) (Error while validating the service descriptor 'ServiceType: DACRL.Application.Core.Services.ILetterService Lifetime: Transient ImplementationType: DACRL.Api.Services.LetterService': Unable to resolve service for type 'DACRL.Integrations.Kofax.Configs.KofaxSetup' while attempting to activate 'DACRL.Integrations.Kofax.KofaxService'.) (Error while validating the service descriptor 'ServiceType: DACRL.Application.Core.Services.ILetterService Lifetime: Transient ImplementationType: DACRL.Api.Services.LetterService': Unable to resolve service for type 'DACRL.Integrations.Kofax.Configs.KofaxSetup' while attempting to activate 'DACRL.Integrations.Kofax.KofaxService'.)'
1/2:
InvalidOperationException: Error while validating the service descriptor 'ServiceType: DACRL.Integrations.Kofax.IKofaxService Lifetime: Scoped ImplementationType: DACRL.Integrations.Kofax.KofaxService': Unable to resolve service for type 'DACRL.Integrations.Kofax.Configs.KofaxSetup' while attempting to activate 'DACRL.Integrations.Kofax.KofaxService'.
2/2:
InvalidOperationException: Unable to resolve service for type 'DACRL.Integrations.Kofax.Configs.KofaxSetup' while attempting to activate 'DACRL.Integrations.Kofax.KofaxService'.
Note that the ILetterService is working properly, and this is the service that internally attempts to receive the IKofaxService from DI in its parameter. I'm thinking the error has something to do with the object KofaxSetup
Is there a best practice that I'm missing here? Am I supposed to have a parameter-less constructor somewhere? Is the Logger<KofaxService> injection within the service's implementation not valid?
I actually sorted the issue out but didn't want to waste a well-written question.
The problem was fact, the KofaxSetup class. I was receiving it as its type directly in the Service's constructor. I had to use IOptions<KofaxSetup> instead to solve the issue.

Xamarin ios: loaded the nib but the view outlet was not set

I’m new in xamarin ios and I need to add view in existing project. Project use mvvmcross framework.
I’ve done:
Created PerevozkiViewModelClass :MvxViewModel in Core project
Add UI View controller with storydoard (P.S. BaseView extends MvxViewController)
public partial class PerevozkiView : BaseView
{
public PerevozkiView() : base("PerevozkiView", null)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
var set = this.CreateBindingSet<PerevozkiView, PerevozkiViewModel>();
set.Apply();
}
}
Delete PerevozkiView.Storyboard
4.Add PerevozkiView.xib and in file owner specify PerevozkiView (I cant choose it from list, so I just hardcode “PerevozkiView as file owner)
After deploy in IOS simulator I’ve got exception:
Foundation.MonoTouchException
Сообщение = Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: -[UIViewController _loadViewFromNibNamed:bundle:] loaded the "PerevozkiView" nib but the view outlet was not set here in Main:
public class Application
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, "AppDelegate");
}
}
I have no idea what is wrong. Pls help

How to migrate Log4j Filter to Log4j 2

I got a Java Webapplication that starts an asynchron server side "job".
The application creates a directory for each job and logs in a file in this directory.
My implementation with log4j is:
import org.apache.log4j.*;
public class ThreadLogger {
String sThreadName;
String sLogfilePath;
RollingFileAppender rfaJob;
PatternLayout plJobLog;
public ThreadLogger(){}
public void start(String sThreadId, String sLogfilePath){
this.sThreadName = sThreadId;
this.sLogfilePath = sLogfilePath;
// Create Logfilter and LogAppender for thread based logging
ThreadLoggingFilter ThreadLogFilter = new ThreadLoggingFilter(this.sThreadName);
plJobLog = new PatternLayout("[%x - %t][%d / %p / %c] - %m%n");
this.rfaJob = new RollingFileAppender();
this.rfaJob.setLayout(plJobLog);
this.rfaJob.setFile(sLogfilePath);
this.rfaJob.setEncoding("UTF-8");
this.rfaJob.activateOptions();
this.rfaJob.setMaxBackupIndex(9);
this.rfaJob.setMaxFileSize("10MB");
this.rfaJob.setThreshold(Level.ALL);
this.rfaJob.addFilter(ThreadLogFilter);
Logger.getRootLogger().addAppender(this.rfaJob);
}
public void stop(){
Logger.getRootLogger().removeAppender(this.rfaJob);
this.rfaJob.close();
}
}
and the ThreadLogginFilter is:
import org.apache.log4j.spi.*;
public class ThreadLoggingFilter extends Filter {
String threadName;
public ThreadLoggingFilter(String _threadName){
this.threadName = _threadName;
}
#Override
public int decide(final LoggingEvent event) {
if (event.getNDC() != null && event.getNDC().equals(this.threadName)) {
return ACCEPT;
}
return DENY;
}
}
No I want to implement this with log4j2 and don´t know how to do the filter.
I know the documentation on https://logging.apache.org/log4j/2.0/manual/filters.html but I cant find a way to do this.
Is it possible to do this without a configuration?
Update: The goal...
My webapplication starts threads. Every thread produces several files to a folder that will be send to the user at the end. Within the folder there has to be the log file. So every thread need his own appender with a foldername.

Disable spring boot auditing in a jhipster generated application

I would like to disable/limit auditing (CustomAuditEventRepository) in an application generated using jhipster.
How can I do this?
Modify CustomAuditEventRepository so that it does nothing in add(), this is generated code, it's yours so you can do whatever you want with it.
Options 1: Disable audit event of spring actuator. Adding config properties to application.yml file:
management:
auditevents:
enabled: false
Refer: AuditAutoConfiguration
#Configuration(proxyBeanMethods = false)
#ConditionalOnBean(AuditEventRepository.class)
#ConditionalOnProperty(prefix = "management.auditevents", name = "enabled", matchIfMissing = true)
public class AuditAutoConfiguration {
...
}
Options 2: Add custom AuditListener bean
#Bean
public MyAuditListener auditListener() {
return new MyAuditListener();
}
public class MyAuditListener extends AbstractAuditListener {
private static final Log logger = LogFactory.getLog(MyAuditListener.class);
public MyAuditListener() {
...
}
#Override
protected void onAuditEvent(AuditEvent event) {
...
}
}

After creating a timer job i can't see it in the SharePoint administration panel

I've developed a timer job for one of my SharePoint web applications.
I have written my job from SPJobdefinition class:
public class EraseUsersJob : SPJobDefinition
{
#region constants
public struct Constantes
{
public const string JOB_NAME = "EraseUsers";
public const string JOB_TITLE = "Erase Users";
}
#endregion
#region constructors
public EraseUsersJob() : base() { }
public EraseUsersJob(string jobName,
SPService service,
SPServer server,
SPJobLockType targetType)
: base(jobName, service, server, targetType) { }
public EraseUsersJob(SPWebApplication webApplication)
: this(Constantes.JOB_NAME, webApplication)
{
}
public EraseUsersJob(string jobName, SPWebApplication webApplication)
: base(jobName, webApplication, null, SPJobLockType.Job)
{
this.Title = Constantes.JOB_TITLE;
}
#endregion
#region override
public override void Execute(Guid targetInstanceId)
{
//my code
}
// my private methods used in execute() method
Then within a console program a create a new instance of this job using the constructor with the SPWebApplication argument.
Then i set a schedule for my job and update it.
My problem is that when i check if my Timer Job has been created in the SharePoint administration i find that it has not been created.
Am i missing something?
If you need more details or further information I will provide it to you.
EDIT:
Here's my Program.cs:
class Program
{
static void Main(string[] args)
{
try
{
SPWebApplication webApplication = SPWebApplication.Lookup(new Uri("http://XXXXX:80"));
//Console.WriteLine("Installing EraseUsers job ...");
JobManager jobsManager = new JobManager();
jobsManager.ApplyJobs(webApplication);
}
catch (Exception e)
{
Console.WriteLine("ERROR: "+e.Message);
}
}
Here's my job manager class:
public class JobManager : DeployJobHelper
{
public void ApplyJobs(SPWebApplication webApplication)
{
try
{
Console.WriteLine(" Installing EraseUsersJob");
EraseUsersJob eraseUsersJob= new EraseUsersJob(webApplication);
this.ApplyJob(webApplication, eraseUsersJob);
}
catch (Exception ex)
{
Console.WriteLine(" Error: " + ex.Message + " // " + ex.StackTrace);
}
Console.WriteLine(" Job installation finished.");
}
}
Here's my DeployHelper.cs:
public class DeployJobHelper
{
protected void ApplyJob(SPWebApplication webApplication, SPJobDefinition jobDefinition)
{
string jobName = jobDefinition.Name;
// delete previous Job definition
webApplication.DeleteJobByName(jobName);
//Install Job
jobDefinition.Schedule = new SPMinuteSchedule() { BeginSecond=0, EndSecond=50,Interval=2 }; //GetScheduleValue(jobName);
jobDefinition.Update();
}
}
Moreover i've seen this error in the ULS:
SharePoint cannot deserialize an object of type XyZ.AbC.EraseUsersJob.EraseUsersJob, XyZ.AbC.EraseUsersJob, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null on this machine. This typically occurs because the assembly containing this type is not installed on this machine. In this case, this message can be safely ignored. Otherwise, the assembly needs to be installed on this machine in a location that can be discovered by the .NET Framework.
I've read this error has something to do with either restarting Windows Sharepoint Services Timer or with namespace issues. I've already restarted my Windows SharePoint Services Timer and all my classes are wrapped within XyZ.AbC.EraseUsersJob namespace.

Resources