Magento 2 : Add custom notification in admin - notifications

I see some module has a custom notification, my question is how to add it in my module
hope someone helps me. Thank.

To get your module's custom notification class to run, you need to create the file VendorName/ModuleName/etc/adminhtml/di.xml with the following code:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Framework\Notification\MessageList">
<arguments>
<argument name="messages" xsi:type="array">
<item name="yourClassName" xsi:type="string">VendorName\ModuleName\Model\System\Message\YourClassName</item>
</argument>
</arguments>
</type>
</config>
Then you have to create the VendorName\ModuleName\Model\System\Message\YourClassName.php class file with the following code:
<?php
namespace VendorName\ModuleName\Model\System\Message;
class YourClassName implements \Magento\Framework\Notification\MessageInterface
{
public function getIdentity()
{
// Retrieve unique message identity
return 'identity';
}
public function isDisplayed()
{
// Return true to show your message, false to hide it
return true;
}
public function getText()
{
// Retrieve message text
return 'Notification message text goes here';
}
public function getSeverity()
{
// Possible values: SEVERITY_CRITICAL, SEVERITY_MAJOR, SEVERITY_MINOR, SEVERITY_NOTICE
return self::SEVERITY_MAJOR;
}
}

Related

Springfox API docu with xml response- Workaround for #XmlAttribute

I have some issues setting up Springfox for usage in Swagger UI.
I got it working in general, but the XML examples which are created are partly wrong because some xml annoations are not considered by springfox.
I have these models:
#XmlRootElement(name = "ApplicatorUnits")
#XmlAccessorType(XmlAccessType.FIELD)
public class EHDTOApplicatorUnits
{
#XmlElement(name = "UnitGroup")
private List<EHDTOUnitGroup> ehdtoUnitGroups;
public List<EHDTOUnitGroup> getEhdtoUnitGroups()
{
return ehdtoUnitGroups;
}
public void setEhdtoUnitGroups(List<EHDTOUnitGroup> ehdtoUnitGroups)
{
this.ehdtoUnitGroups = ehdtoUnitGroups;
}
}
#XmlRootElement(name = "UnitGroup")
#XmlAccessorType(XmlAccessType.FIELD)
public class EHDTOUnitGroup
{
#XmlAttribute(name = "name")
private String name;
#XmlElement(name = "unit")
private List<EHDTOUnit> ehdtoUnits;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public List<EHDTOUnit> getEhdtoUnits()
{
return ehdtoUnits;
}
public void setEhdtoUnits(List<EHDTOUnit> ehdtoUnits)
{
this.ehdtoUnits = ehdtoUnits;
}
}
You see some usages of #XmlAttribute, #XmlRootElement and #XmlElement.
After adding jackson jaxb annotation introspectors (I tried different ways) the XML was partly correct, as the #XmlAttribute annotations have been considered after this step:
JaxbAnnotationModule jaxbAnnotationModule = new JaxbAnnotationModule();
jaxbAnnotationModule.setPriority(Priority.PRIMARY);
mapper.registerModule(jaxbAnnotationModule);
/*AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
AnnotationIntrospector secondary = new XmlJaxbAnnotationIntrospector(mapper.getTypeFactory()); //new JaxbAnnotationIntrospector(mapper.getTypeFactory());
AnnotationIntrospector pair = new AnnotationIntrospectorPair(primary,secondary);
mapper.setAnnotationIntrospector(pair);*/
However, the other 2 are still ignored, resulting in this example xml:
<?xml version="1.0"?>
<EHDTOApplicatorUnits>
<UnitGroup>
<name>string</name>
<unit>
<id>1</id>
<name>string</name>
<unitSystem>string</unitSystem>
</unit>
</UnitGroup>
</EHDTOApplicatorUnits>
While the real output of the API is:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ApplicatorUnits>
<UnitGroup name="coefTempErrorSpan">
<unit>
<id>1</id>
<name>% span /10K</name>
<unitSystem>SI</unitSystem>
</unit>
<unit>
<id>2</id>
<name>% span /50F</name>
<unitSystem>SI</unitSystem>
</unit>
</UnitGroup>
...
</ApplicatorUnits>
You see the different naming of the root element, and also the "name" of the UnitGroup which is not an attribute in the example xml but an own child-node.
I found I can use #ApiModel(value = "ApplicatorUnits") as workaround for #XmlRootElement but what about #XmlAttribute, is there also a workaround? #ApiModelProperty does not seem to work for this case. Does somebody have an idea how to workaround this issue?

jsf variable lost value [duplicate]

This question already has an answer here:
#ViewScoped calls #PostConstruct on every postback request
(1 answer)
Closed 5 years ago.
I have a managed Bean called bean1.java that has a boolean var called found. The variable says if a client has been found or not.
The bean has a method validate() that goes to the DB and checks if the client exists, and sets the variable to found=true if it exists or 'false' if it doesn't.
Then I keep completing other fields in my form. Now, when I click the button save, it the method saving(). That method has to do an action if the var found is true and another action if it's false.
But the problem is when I validate the variable that has been set to true on the method validate(), now it has the value "false".
#ManagedBean
#ViewScoped //SessionScoped
public class AgregarPoliza implements Serializable{
public boolean found=false;
public void validate(){
// go to data base and validate if the client exist, when exist
// set variable true
found = true; // setFound(true); <--- i already try this way too
}
public void saving(){
//it has two actions to do but need to know the value of found
System.out.println("my var found has" + found); //this system.out shows false
if(found ==true){
//makes an action
}
else{
//makes another action
}
}
//get and set of the value found
}
You should try calling the validate method in the method saving like this.
public void validate()
{
// go to data base and validate if the client exist, when exist
// set variable true
found = true; // setFound(true); <--- i already try this way too
}
public void saving(){
this.validate();
//it has two actions to do but need to know the value of found
System.out.println("my var found has" + found); //this system.out shows false
if(found ==true){
//makes an action
}
else{
//makes another action
}
i hava use this and this is working fine now check it please now it can not lost value...
AgregarPoliza.java
package com.best.uibeansTest;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
#ManagedBean(name = "agregarPoliza")
#SessionScoped
public class AgregarPoliza implements Serializable{
public boolean found=false;
public void validate(){
// go to data base and validate if the client exist, when exist
// set variable true
found = true; // setFound(true); <--- i already try this way too
}
public String saving(){
validate();
//it has two actions to do but need to know the value of found
System.out.println("my var found has" + found); //this system.out shows false
if(found ==true){
//makes an action
}
else{
//makes another action
}
return "test2.xhtml" ;
}
//get and set of the value found
public boolean isFound() {
return found;
}
public void setFound(boolean found) {
this.found = found;
}
//get and set of the value found
}
here i just get agregarPoliza as bean i am showing jsf code below through which i check this..
test2.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
<title>JSF Tutorial!</title>
</head>
<h:body>
<h2>Result</h2>
<hr />
<h:form>
<p:commandButton value="Save" ajax="false" action="#{agregarPoliza.saving}"/>
|
found value:
#{agregarPoliza.found}
</h:form>
</h:body>
</html>
on clicking of save button found value is changed to true. try this..

Have users of activeMQ own a queue which name is the user's name

In my application, a user may create an account freely, and it needs to own a queue (or topic) to communicate 2 backend processes between them. I don't want to have to modify activemq's configuration every time that someone creates an account. I have already created a jaasAuthenticationPlugin and it works fine. Here is the relevant part of my activemq.xml file:
<plugins>
<!-- 'activemq-domain' defined in conf/login.conf -->
<jaasAuthenticationPlugin configuration="activemq-domain" />
<authorizationPlugin>
<map>
<authorizationMap>
<authorizationEntries>
<authorizationEntry queue="foobarQueue"
write="foobarGroup"
read="foobarGroup"
admin="foobarGroup"
/>
</authorizationEntries>
</authorizationMap>
</map>
</authorizationPlugin>
</plugins>
As you may deduct, the authentication plugin is authenticating a user (foobar in this example) and putting the user in the foobarGroup group. The AuthorizationEntry is granting read, write and admin privileges to the foobarQueue to this foobarGroup. This is working well, but now if I create a new user, I must come to this file and add a new AuthorizationEntry. Is it possible with a simple configuration line in the activemq.xml to do something like:
<authorizationEntry
queue="<% Username %>"
write="<% Username %>"
read="<% Username %>"
admin="<% Username %>"
/>
or should I write some JAAS authorization class to do that?
Finally I have written a class to handle the Authorization part. It was a bit difficult because documentation is difficult to find and I couldn't find any good example. Digging in the source code of the default LDAPAuthorizationMap was key. Anyway, the source for anyone interested:
package com.example.activemq;
import org.apache.activemq.advisory.AdvisorySupport;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.jaas.GroupPrincipal;
import org.apache.activemq.security.AuthorizationMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.HashSet;
import java.util.Set;
public class OwnedUserQueueAuthorizator implements AuthorizationMap {
private static final Log log =
LogFactory.getLog(OwnedUserQueueAuthorizator.class);
private boolean debug = false;
// the Destination will be the name of the user, and we should return that
// the group with user name has read,write and admin privileges to the
// topic/queue named like the username
// for temporary destinations, if null is returned, then everybody has
// permission.
public Set<GroupPrincipal> getTempDestinationAdminACLs() {
return null;
}
public Set<GroupPrincipal> getTempDestinationReadACLs() {
return null;
}
public Set<GroupPrincipal> getTempDestinationWriteACLs() {
return null;
}
// for persistent destinations
public Set<GroupPrincipal> getAdminACLs(ActiveMQDestination destination) {
if (debug) {
log.debug("getAdminACLs: " + destination.getPhysicalName());
}
return getACLs(destination);
}
public Set<GroupPrincipal> getReadACLs(ActiveMQDestination destination) {
if (debug) {
log.debug("getReadACLs: " + destination.getPhysicalName());
}
return getACLs(destination);
}
public Set<GroupPrincipal> getWriteACLs(ActiveMQDestination destination) {
if (debug) {
log.debug("getwriteACLs: " + destination.getPhysicalName());
}
return getACLs(destination);
}
private Set<GroupPrincipal> getACLs(ActiveMQDestination destination) {
Set<GroupPrincipal> result;
if (AdvisorySupport.isAdvisoryTopic(destination)) {
result = getACLsForAdvisory();
} else {
result = new HashSet<GroupPrincipal>();
// Destination should be something like UUID or UUID.whatever...,
// so we must add only the first component as the group principal
result.add(new GroupPrincipal(
destination.getDestinationPaths()[0])
);
}
if (debug) {
String s = "";
for (GroupPrincipal gp : result) {
s += ", " + gp.getName();
}
log.debug("groupPrincipals: " + "[" + s.substring(2) + "]");
}
return result;
}
private Set<GroupPrincipal> getACLsForAdvisory() {
Set<GroupPrincipal> result = new HashSet<GroupPrincipal>();
GroupPrincipal g = new GroupPrincipal("advisories");
result.add(g);
return result;
}
// Properties
// -------------------------------------------------------------------------
// if the <bean> definition in the activemq.xml has some
// <property name="foo" value="..." />
// defined, they will call this.setFoo($value), so, even if these get/set
// methods aren't called from here, they are really needed.
public void setDebug(String debug) {
this.debug = "true".equalsIgnoreCase(debug);
}
public String getDebug() {
return String.valueOf(debug);
}
}
The conf/activemq.xml file:
<beans ...>
...
<broker ...>
...
<plugins>
<!-- 'activemq-domain' defined in conf/login.conf -->
<jaasAuthenticationPlugin configuration="activemq-domain" />
<authorizationPlugin>
<map>
<bean id="OwnedUserQueueAuthorizationMap"
class="com.example.activemq.OwnedUserQueueAuthorizator"
xmlns="http://www.springframework.org/schema/beans">
<property name="debug" value="false"/>
</bean>
</map>
</authorizationPlugin>
</plugins>
...
</broker>
...
</beans>

Flex 3: Code-behind problem

I have some VBox with button. I want my button changes the label after clicking on it. I'm trying to use the code-behind practice but the instance of the button is always null. There is code:
package TestPackage
{
import mx.containers.VBox;
import mx.controls.Button;
public class ControlsBox extends VBox
{
[Bindable]
public var btnPlay : Button;
public function ControlsBox()
{
super();
}
override protected function childrenCreated():void
{
super.childrenCreated();
}
public function ChangeImage():void
{
btnPlay.label = "a";
}
}
}
Here is mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:controls="TestPackage.*">
<controls:ControlsBox id="ctrlVBox">
<mx:Button id="btnPlay" click="this.ctrlVBox.ChangeImage();" label="c"></mx:Button>
</controls:ControlsBox>
</mx:Application>
What am I doing wrong? And how to do that properly?
Thanks
I don't do this very often in flex, but I think you want something like this:
<controls:ControlsBox id="ctrlVBox">
<controls:btnPlay>
<mx:Button click="this.ctrlVBox.ChangeImage();" label="c"></mx:Button>
</controls:btnPlay>
</controls:ControlsBox>

Flex : stopPropagation of the event Keyboard.ENTER of a colorpicker

I have a WindowedApplication with a listener on keyboardEvent (on the ENTER key), but when the user choose to use the colorpicker and type an hexadecimal code then hit ENTER the event is propaged to my WindowedApplication too.
I have to stop the propagation.
Any hint or snippet ?
thanks
P.
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
keyDown="appHandler(event)">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
private function appHandler(event:KeyboardEvent):void
{
trace('A key has been pressed inside the app');
}
private function cpHandler(event:KeyboardEvent):void
{
trace('A key has been pressed inside the color picker');
event.stopPropagation();
}
]]>
</fx:Script>
<mx:ColorPicker x="159" y="137" id="cp" keyDown="cpHandler(event)"/>
<s:TextInput x="233" y="137"/>
</s:WindowedApplication>
This is part of the code of the TitleWindow, where cp is the ColorPicker.
...
public function init():void { cp.addEventListener(ColorPickerEvent.ENTER,handler);
}
public function handler(e:ColorPickerEvent):void {
e.stopImmediatePropagation();
}
public function changeColor(e:ColorPickerEvent):void {
Application.application.couleur = cp.selectedColor;
PopUpManager.removePopUp(this);
}
...
And this is from my main mxml :
...
employeeList.addEventListener(KeyboardEvent.KEY_UP, enterListener);
...
private function enterListener(e:KeyboardEvent):void {
if(e.keyCode == Keyboard.ENTER) {
if(employeeList.selectedItem) {
showDetail(employeeList.selectedItem as Employee);
}
}
}