How to use $this->release() method in laravel Notification ShouldQueue - laravel-9

I use laravel notification class for sending emails. Normaly for retring failed jobs in Job Class I can use $this->release() method. Do you have any idea how I can use this method in my notification class as well?
class OrderConfirmationNotification extends Notification implements ShouldQueue
{
use Queueable;
public $pdfAttachment;
public $determineSenderEmail;
public $mailData;
public $tries = 3;
public function __construct(array $mailData)
{
$this->mailData = $mailData;
$this->determineSenderEmail = $this->mailData['sender_email'];
}
/** #return string[] */
public function via(): array
{
return ['mail'];
}
/** #return MailMessage */
public function toMail(): MailMessage
{
return (new MailMessage)
->markdown($this->mailData['mail_template'], ['logoImage' => $this->mailData['company_logo']])
->from($this->determineSenderEmail['email'], $this->determineSenderEmail['name'])
->replyTo($this->determineSenderEmail['reply_to'], $this->determineSenderEmail['reply_name'])
->bcc($this->mailData['bcc_email']);
}
public function failed(Exception $exception)
{
Log::channel('xml_parse')->warning(sprintf('Order Confirmation notification failed'));
}
}

Related

Why this constructor is not intercepted by my code?

I want to write a javaagent using byte-buddy. I wan to intercept constructor of any class that is a sub class of java.sql.Connection.
my setup code:
log.info("{} profile activated", profile);
if (profile.equals("hikari")) {
startMatcher = nameStartsWith("com.zaxxer.hikari");
JDBCAPIInterceptor.profile = new HikariProfile();
} else if (profile.equals("dbcp1")) {
startMatcher = nameStartsWith("org.apache.commons.dbcp");
JDBCAPIInterceptor.profile = new DBCP1Profile();
} else if (profile.equals("dbcp2")) {
startMatcher = nameStartsWith("org.apache.commons.dbcp2");
JDBCAPIInterceptor.profile = new DBCP2Profile();
} else if (profile.equals("druid")) {
startMatcher = nameStartsWith("com.alibaba.druid.pool");
} else {
startMatcher = any();
}
new AgentBuilder.Default().type(startMatcher.and(isSubTypeOf(java.sql.Connection.class).or(isSubTypeOf(java.sql.Statement.class))))
.transform(constructorTransformer).transform(methodsTransformer).with(listener).installOn(inst);
but why constructor of org.apache.commons.dbcp2.PoolingDataSource$PoolGuardConnectionWrapper can't be intercepted while it's definitely a sub class of java.sql.Connection as it extends org.apache.commons.dbcp2.DelegatingConnection which implements java.sql.Connection?
also, my intercepting code is executed while constructor of org.apache.commons.dbcp2.DelegatingConnection being called.
public class PoolingDataSource<C extends Connection> implements DataSource, AutoCloseable {
/**
* PoolGuardConnectionWrapper is a Connection wrapper that makes sure a closed connection cannot be used anymore.
*
* #since 2.0
*/
private class PoolGuardConnectionWrapper<D extends Connection> extends DelegatingConnection<D> {
PoolGuardConnectionWrapper(final D delegate) {
super(delegate);
}
#Override
public void close() throws SQLException {
if (getDelegateInternal() != null) {
super.close();
super.setDelegate(null);
}
}
/**
* #see org.apache.commons.dbcp2.DelegatingConnection#getDelegate()
*/
#Override
public D getDelegate() {
return isAccessToUnderlyingConnectionAllowed() ? super.getDelegate() : null;
}
/**
* #see org.apache.commons.dbcp2.DelegatingConnection#getInnermostDelegate()
*/
#Override
public Connection getInnermostDelegate() {
return isAccessToUnderlyingConnectionAllowed() ? super.getInnermostDelegate() : null;
}
#Override
public boolean isClosed() throws SQLException {
return getDelegateInternal() == null || super.isClosed();
}
}
}

kotlin, what is #param used for before the annotation type

In java class with annotation:
public final class Info {
private Info() {
}
public static class InfoAction {
public static final String OPEN = "open";
public static final String VIEW_ALL = "view_all";
#Retention(RetentionPolicy.SOURCE)
#StringDef({OPEN, VIEW_ALL})
public #interface Action {
}
public String mAction;
public InfoAction(#Action String action) {
this.mAction = action;
}
}
IDE convert to kotlin:
class Info private constructor() {
class InfoAction(#param:Action var infoAction: String) {
#kotlin.annotation.Retention(AnnotationRetention.SOURCE)
#StringDef(OPEN, VIEW_ALL)
annotation class Action
companion object {
const val OPEN = "open"
const val VIEW_ALL = "view_all"
}
}
}
it has #param:Action, but replace with #Action it works as well.
what is this #param here for, and can the #Action be used?
#param is for constructor parameter
detail:
https://kotlinlang.org/docs/annotations.html#annotation-use-site-targets

Opening different URLs in one Serenity task class?

In Serenity BDD I have a Task which opens the login page of an application. I'd like to use this class to not only open the login page but other pages as well.
public class StartWith implements Task {
LoginPage loginPage;
#Override
public <T extends Actor> void performAs(T actor) {
actor.attemptsTo(
Open.browserOn(loginPage)
);
}
public static Task theLoginPage() {
return instrumented(StartWith.class);
}
// Is this possible???
public static Task theContactPage() {
return instrumented(StartWith.class);
}
}
Is it possible to add another static method e.g. theContactPage so that my actor could call one of these:
StartWith.theLoginPage()
StartWith.theContactPage()
You can use url as string param.
public class StartWith implements Task {
private final String url;
public StartWith(String url) {
this.url = url;
}
#Override
#Step("{0} start portal at \\{#url\\}")
public <T extends Actor> void performAs(T actor) {
actor.attemptsTo(
Open.url(url)
);
}
public static Task theLoginPage() {
String url = "http://example.com/login";
return instrumented(StartWith.class, url);
}
public static Task theContactPage() {
String url = "http://example.com/contact";
return instrumented(StartWith.class);
}
}

How does the following test pass?

I have a simple test for the following controller action method
Admin controller
namespace TestingDemo {
public class AdminController : Controller {
private IUserRepository repository;
public AdminController(IUserRepository repo) {
repository = repo;
}
public ActionResult ChangeLoginName(string oldName, string newName) {
User user = repository.FetchByLoginName(oldName);
user.LoginName = newName;
repository.SubmitChanges();
// render some view to show the result
return View();
}
}
}
The test I have is this
namespace TestingDemo.Tests {
[TestClass]
public class AdminControllerTests {
[TestMethod]
public void CanChangeLoginName() {
// Arrange (set up a scenario)
User user = new User() { LoginName = "Bob" };
FakeRepository repositoryParam = new FakeRepository();
repositoryParam.Add(user);
AdminController target = new AdminController(repositoryParam);
string oldLoginParam = user.LoginName;
string newLoginParam = "Joe";
// Act (attempt the operation)
target.ChangeLoginName(oldLoginParam, newLoginParam);
// Assert (verify the result)
Assert.AreEqual(newLoginParam, user.LoginName);
Assert.IsTrue(repositoryParam.DidSubmitChanges);
}
}
class FakeRepository : IUserRepository {
public List<User> Users = new List<User>();
public bool DidSubmitChanges = false;
public void Add(User user) {
Users.Add(user);
}
public User FetchByLoginName(string loginName) {
return Users.First(m => m.LoginName == loginName);
}
public void SubmitChanges() {
DidSubmitChanges = true;
}
}
}
my question is how does user.LoginName get changed? the only change that happens to user is in the action method, and that is a local user variable. How is the user variable in the test getting updated?
The controller test first adds a user to List<User> Users in the fake repository, using the Users.Add method.
The repository this is added to is passed into the constructor of the controller in the test:
AdminController target = new AdminController(repositoryParam);

Problem getting same class instance passed from one activity to another

I am trying to pass SampleParcelable class object say sampleObj from my ClassA (current) activity to ClassB (a new one), but when i log the objects value, the object's value which i am creating in ClassA is totally different from what i get in ClassB.
ClassA :-
public class ClassA extends Activity
{
private SampleParcelable sampleObj;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
sampleObj = new SampleParcelable();
Log.d("Actual Reference Value", "\t" + sampleObj);
Intent terminateActivity = new Intent( ClassA.this, ClassB.class );
terminateActivity.putExtra("SampleValue", sampleObj);
SampleParcelable readbackCi = terminateActivity.getParcelableExtra("SampleValue");
Log.d("Retrieved Value", "\n\n\t" + readbackCi);
}
}
ClassB :-
public class ClassB extends Activity
{
private SampleParcelable newSampleObj;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
try {
Intent intentObj = getIntent();
Log.d("Intent Value", "intent: " + intentObj.toString());
Log.d("Extra Values", "extras: " + intentObj.getExtras());
newSampleObj = (SampleParcelable) intentObj.getParcelableExtra("SampleValue");
Log.d("New Value", " " + newSampleObj.toString());
} catch (Exception e) {
Log.d("Exception in main", e.toString());
}
}
}
SampleParcelable :-
public class SampleParcelable implements Parcelable
{
public SampleParcelable(Parcel in) {
in.readParcelable(SampleParcelable.class.getClassLoader());
}
public SampleParcelable() {
}
#Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
}
public static final Parcelable.Creator<SampleParcelable> CREATOR = new Parcelable.Creator<SampleParcelable>() {
public SampleParcelable createFromParcel(Parcel in) {
return new SampleParcelable(in);
}
public SampleParcelable[] newArray(int size) {
return new SampleParcelable[size];
}
};
}
After debugging I guess, I know 1 reason why my object values are different, because when retrieving object in ClassB using getParcelableExtra() at that time my SampleParcelable class createFromParcel method is called which internally creates a new object. May be i m wrong.
I am not getting any solution for this, i just want same object in my new class so that i can access some values using that object which were set in my ClassA activity.
Thanks in advance
Here how you can achieve what you intend for::
package com.unundoinc.FaceBook.Activity;
import android.os.Parcel;
import android.os.Parcelable;
public class CheckParcelable implements Parcelable
{
private Facebook facebook;
public CheckParcelable() { ; }
/**
*
* Constructor to use when re-constructing object
* from a parcel
*
* #param in a parcel from which to read this object
*/
public CheckParcelable(Parcel in) {
readFromParcel(in);
}
#Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags)
{
// TODO Auto-generated method stub
dest.writeValue(getFacebook());
}
private void readFromParcel(Parcel in) {
// readParcelable needs the ClassLoader
// but that can be picked up from the class
// This will solve the BadParcelableException
// because of ClassNotFoundException
facebook = (Facebook) in.readValue(Facebook.class.getClassLoader());
}
public void setFacebook(Facebook facebook) {
this.facebook = facebook;
}
public Facebook getFacebook() {
return facebook;
}
public static final Parcelable.Creator<CheckParcelable> CREATOR =
new Parcelable.Creator<CheckParcelable>()
{
public CheckParcelable createFromParcel(Parcel in)
{
return new CheckParcelable(in);
}
public CheckParcelable[] newArray(int size) {
return new CheckParcelable[size];
}
};
}
For Using the Parceable You Need to do something like this in the class from where you require pass the object to the other Activity::
Facebook facebook = new Facebook();
facebook.setAccessToken("TIMEPASS");
CheckParcelable parcelable = new CheckParcelable();
parcelable.setFacebook(facebook);
Intent newIntent = new Intent(ActivityA.this, ActivityB.class);
newIntent.putExtra("CheckParcelable", parcelable);
And for getting the Object from Other Activity you require to perform this thing ::
CheckParcelable parcelable = getIntent().getExtras().getParcelable("CheckParcelable");
Facebook facebook = parcelable.getFacebook();
Log.v(TAG, "PARCELABLE IS ::" +facebook.getAccessToken());
I hope this would solve you problem ;D