Please help me to develop a cq 5.4 WorkflowProcess - java

I am trying to create a CQ 5.4 workflow which updates the description of the Digital Asset Image which started this workflow.
My Problem is when I compile and build this code the WorkFlow Process does not appear in the Process Step's drop down in CQ 5.4 author server instance.
Here is the code , Let me know if any other step is required or I am doing wrong somewhere,
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.day.cq.dam.commons.process.AbstractAssetWorkflowProcess;
import com.day.cq.workflow.WorkflowException;
import com.day.cq.workflow.WorkflowSession;
import com.day.cq.workflow.exec.WorkItem;
import com.day.cq.workflow.exec.WorkflowProcess;
import com.day.cq.workflow.metadata.MetaDataMap;
#Component
#Service(WorkflowProcess.class)
#Properties({
#Property(name = "service.description", value = "Update the Image Description"),
#Property(name = "service.vendor", value = "******"),
#Property(name = "process.label", value = "Update the Image Description") })
public class RemoveImgPropBatchWorkFlowProcessStep extends AbstractAssetWorkflowProcess{
private static final Logger log = LoggerFactory.getLogger(RemoveImgPropBatchWorkFlowProcessStep.class);
#Override
public void execute(WorkItem workItem, WorkflowSession workFlowSesion, MetaDataMap meta)
throws WorkflowException {
// TODO Auto-generated method stub
log.info("RemoveImgPropBatchWorkFlowProcessStep Workflow called up");
workItem.getNode().setDescription("Image is updated");
}
}

The Issue is resolved, all the dependent bundles were not active hence the workflow process was not getting displayed. Regards, Yash

Related

Opendaylight - Cannot find symbol getNode()

I am trying to create a basic Hello-World application in Opendaylight. I created the app by following the steps from https://docs.opendaylight.org/en/stable-magnesium/developer-guide/developing-apps-on-the-opendaylight-controller.html.
I was able to run basic Hello-World RPC as in the tutorial, and am trying to extend the app so that it can return Netconf Nodes that are present at the equivalent /restconf/operational/network-topology:network-topology/topology/topology-netconf/. For this, I am referring to the NCMount Example from https://github.com/opendaylight/coretutorials/tree/master/ncmount.
While trying to do maven build, I am getting the following error:
/home/ubuntu/ghost/odlapps/1.3.0-SS/hello/impl/src/main/java/org/opendaylight/hello/impl/HelloWorldImpl.java:[58,21] cannot find symbol
[ERROR] symbol: method getNode()
[ERROR] location: class java.util.Optional<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology>
My HelloWorldImpl.java looks like:
package org.opendaylight.hello.impl;
import com.google.common.util.concurrent.ListenableFuture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hello.rev191127.HelloService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hello.rev191127.HelloWorldInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hello.rev191127.HelloWorldOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hello.rev191127.HelloWorldOutputBuilder;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.binding.api.ReadTransaction;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.common.api.ReadFailedException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.network.topology.topology.topology.types.TopologyNetconf;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
public class HelloWorldImpl implements HelloService {
private static final Logger LOG = LoggerFactory.getLogger(HelloWorldImpl.class);
private final DataBroker dataBroker;
public static final InstanceIdentifier<Topology> NETCONF_TOPO_IID =
InstanceIdentifier
.create(NetworkTopology.class)
.child(Topology.class,
new TopologyKey(new TopologyId(TopologyNetconf.QNAME.getLocalName())));
#Override
public ListenableFuture<RpcResult<HelloWorldOutput>> helloWorld(HelloWorldInput input) {
HelloWorldOutputBuilder helloBuilder = new HelloWorldOutputBuilder();
ReadTransaction tx = dataBroker.newReadOnlyTransaction();
List<Node> nodes;
// Get All nodes from Operational Database
try {
nodes = tx.read(LogicalDatastoreType.OPERATIONAL, NETCONF_TOPO_IID)
// .checkedGet()
.get()
.getNode();
} catch (ReadFailedException e) {
LOG.error("Failed to read node config from datastore", e);
throw new IllegalStateException(e);
}
List<String> results = new ArrayList<>();
for (Node node : nodes) {
LOG.info("Node: {}", node);
NetconfNode nnode = node.augmentation(NetconfNode.class);
if (nnode != null) {
// We have a device
ConnectionStatus csts = nnode.getConnectionStatus();
}
results.add(node.getNodeId().getValue());
}
helloBuilder.setGreeting(results);
return RpcResultBuilder.success(helloBuilder.build()).buildFuture();
}
}
I am not sure what org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology returns because I dont seem to be able to find the apidoc for this package anywhere. I was getting the same error for getChecked(), so I commented it out to see if it helps.
So,
Is there any documentation/javadocs that I can refer to understand the Optional that is returned after performing READ on the operational datastore?
Are there examples based on current archetypes as NCMount is based on pretty old versions of Opendaylight?
Any help is greatly appreciated. Thanks!

Neo4j embedded graph java visualization

I'm beginning in Neo4j java embedded graph.
I have made a first test but I cant visualize my graph in neo4j-community.
Here is my code for creating the graph :
package connection;
import java.io.File;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
public class embededdedGraph {
public static void main(String... args) throws Exception {
GraphDatabaseFactory graphDbFactory = new GraphDatabaseFactory();
File graphDir = new File("/home/nicolas/neo4j-community-3.5.14/data/databases/cars.db");
GraphDatabaseService graphDb = graphDbFactory.newEmbeddedDatabase(graphDir);
Transaction tx = graphDb.beginTx();
createNode(graphDb);
tx.close();
}
public static void createNode(GraphDatabaseService graphDb) {
Node car = graphDb.createNode();
car.addLabel(Label.label("Car"));
car.setProperty("make", "tesla");
car.setProperty("model", "model3");
Node owner = graphDb.createNode(Label.label("Person"));
owner.setProperty("firstName", "Oliver");
owner.setProperty("lastName", "John");
owner.createRelationshipTo(car, RelationshipType.withName("owner"));
}
}
Next I changed the value of "#dbms.active_database" to "dbms.active_database=cars.db in the /neo4j-community-3.5.14/conf/neo4.conf file.
When I restart the neo4j-community, the database name is "cars.db" but it indicated that there are no labels and relationships in it.
What is the problem I cannot figure?
Nicolas
It looks like you need to call tx.success() or tx.fail() before tx.close().
https://neo4j.com/docs/java-reference/3.5/javadocs/org/neo4j/graphdb/Transaction.html
I am also new at this API, I hope it helps

Eclipse Rich Client Application Connect to database

i'm starting a new Eclipse RCP application and it's my first time and i have a problem , i want to display list of my available database(by the way i'm using nosql database(MongoDB)) but my code seems not to work, can anyone help please , can anyone point me to a good tutorial
thanks for your time and help guys.
package test2.parts;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.e4.ui.di.Focus;
import org.eclipse.e4.ui.di.Persist;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoCursor;
import org.eclipse.swt.widgets.Label;
public class SamplePart {
org.eclipse.swt.widgets.List list ;
private TableViewer tableViewer;
#Inject
private MPart part;
#PostConstruct
public void createComposite(Composite parent) {
parent.setLayout(new GridLayout(1, false));
Text txtInput = new Text(parent, SWT.BORDER);
txtInput.setMessage("Enter text to mark part as dirty");
txtInput.addModifyListener(e -> part.setDirty(true));
txtInput.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
list = new org.eclipse.swt.widgets.List(parent, SWT.BORDER);
tableViewer = new TableViewer(parent);
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
tableViewer.setInput(createInitialDataModel());
tableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
}
#Focus
public void setFocus() {
tableViewer.getTable().setFocus();
}
#Persist
public void save() {
part.setDirty(false);
}
private List<String> createInitialDataModel() {
MongoClient mongoClient = new MongoClient("localhost", 27017);
ArrayList<String> dbs = new ArrayList<String>();
MongoCursor<String> dbsCursor = mongoClient.listDatabaseNames().iterator();
while (dbsCursor.hasNext()) {
list.add(dbsCursor.next());
}
return (List<String>) list;
}
}
The stack trace shows that the plug-in can't find the MongoClient class.
Eclipse plug-ins can only access code in other plug-ins or in jars included in the plug-in. They can't use jars which are just on the ordinary Java classpath.
So you will need to add the jar containing the MongoClient class in to your plugin and add it to the Bundle-Classpath in the MANIFEST.MF. You can do that in the MANIFEST.MF editor in the 'Classpath' section of the 'Runtime' tab.
You also need to include the jar in the build.properties file.

/ExampleApplication/IntrusionException] INTRUSION - Mixed encoding (2x) detected in URL

I am retrieving URL from database and it contains special characters like % - = / ? etc. so while I try to populate that in my page JSON is not able to parse that URL and it is giving me some exception when I was debugging I got like this
(Log4JLogger.java:log:449) [SECURITY FAILURE Anonymous:null#unknown -> /ExampleApplication/IntrusionException] INTRUSION - Mixed encoding (2x) detected
I tried from these link here this my offending URL here
but it is not working he mentioned that bug is solved. but for which version version here I am using is 2.1.0 below is my code
package com.ghn.repufact.review.extractor;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import javax.ws.rs.core.UriBuilder;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.log4j.Logger;
import org.owasp.esapi.ESAPI;
import org.owasp.esapi.Encoder;
import org.owasp.esapi.Validator;
import org.owasp.esapi.errors.EncodingException;
import org.owasp.esapi.reference.DefaultValidator;
import org.springframework.stereotype.Component;
#Component
public class ValidateURL {
private static final Logger logger=Logger.getLogger(ValidateResponse.class);
public String parseOrgConsumerLink(String myLink) throws URISyntaxException {
if(myLink==null || "".equalsIgnoreCase(myLink))
return myLink;
Encoder enc=ESAPI.encoder();
URI mixURI=new URI(myLink);
UriBuilder uriBuider=UriBuilder.fromUri(enc.canonicalize(mixURI.getAuthority()+mixURI.getPath()));
uriBuider.path(enc.canonicalize(mixURI.getAuthority() + mixURI.getPath()));
logger.info("Uri after URIbuilder:"+uriBuider.build().toString());
List<NameValuePair> params = URLEncodedUtils.parse(mixURI, "UTF-8");
for (NameValuePair nameValuePair : params)
uriBuider.queryParam(enc.canonicalize(nameValuePair.getName()), enc.canonicalize(nameValuePair.getValue()));
String canonicalizedUrl = uriBuider.build().toString();
logger.info("canonicaliz URI:"+canonicalizedUrl);
return canonicalizedUrl;
}
public boolean isCanonicalizedURI(String myLink) throws EncodingException {
Validator validator=DefaultValidator.getInstance();
//boolean flag=validator.isValidInput("test", myLink, "URI", 200, false);
myLink = ESAPI.encoder().encodeForURL(myLink);
boolean flag = validator.isValidInput("APPNAME", myLink, "URLSTRING", 600, true, false);
logger.info("checking for URI:"+myLink+" isCanonical:"+flag);
return flag;
}
}
please let me know if any work around here. By the way I am using spring MVC

Using a Hibernate datasource with JFreeCharts

I have a Java Web Application which allows a user to select a bunch of fields (with filters, aggregations etc.) which will then be used to create charts/graphs.
The database behind the application is a standard PostGreSQL 9.04 database but we are using the Hibernate ORM to access data.
The code I have right now creates an HQL Query (Hibernate Query Language) based on the users selections from the web interface. What I really need is some way to use that query to create a dataset that JFreeCharts can use to build the chart.
Are there any examples of JFreeChart and Hibernate integration? Having researched it myself I can't really find much other than this post on the Hibernate forum which says it can be done but giving no detail on how:
https://forum.hibernate.org/viewtopic.php?f=6&t=997556
To summarise:
I have an HQL Query, I want to use that to create a data source which JFreeCharts can use to create Pie/Bar/Stacked Bar/Line charts.
Any help would be much appreciated.
Absent an existing implementation, you might be inspired by one of the existing data model variations seen in org.jfree.data.jdbc.
I tried something. Here's the code for my entity class:
package com.gxet4n.jfreechart;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name="mobile_tbl")
public class Mobile_tbl {
#Id
private int id;
#Column(name="mobile_brand")
private String mobile_brand;
#Column(name="unit_sale")
private int unit_sale;
// getters and setters
}
Then here's the code for my main class :
package com.gxet4n.jfreechart;
import java.io.File;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.query.Query;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtils;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
public class PieChart_HQL {
public static void main( String[ ] args )throws Exception {
DefaultPieDataset dataset = new DefaultPieDataset( );
DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
try {
SessionFactory sessionFactory = new Configuration().configure().addAnnotatedClass(Mobile_tbl.class).buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
Query<?> query = session.createQuery("FROM Mobile_tbl");
List<Mobile_tbl> mobiles = (List<Mobile_tbl>)query.list();
session.close();
for (Mobile_tbl m : mobiles) {
dataset.setValue(m.getMobile_brand(), m.getUnit_sale());
}
for (Mobile_tbl m : mobiles) {
dataset2.setValue(m.getUnit_sale(),m.getMobile_brand(),"");
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
JFreeChart chart = ChartFactory.createPieChart(
"Mobile Sales", // chart title
dataset, // data
true, // include legend
true,
false );
JFreeChart barChart = ChartFactory.createBarChart(
"Mobiles Sales",
"Mobile Brand",
"Unit Sale",
dataset2,
PlotOrientation.VERTICAL,
true, true, false);
int width = 560; /* Width of the image */
int height = 370; /* Height of the image */
File pieChart = new File( "Pie_Chart_HQL.png" );
ChartUtils.saveChartAsPNG(pieChart, chart, width, height);
File barchart = new File( "Bar_Chart_HQL.png" );
ChartUtils.saveChartAsPNG(barchart, barChart, width, height);
}
}
Finally there's the results :
I used hibernate core 5.2.12.Final and jfreechart 1.5.0

Categories