Created pie chart using DynamicJasper API - java

I am trying to generate a report dynamically with JasperReports and DynamicJasper APIs.
I added pie chart to reports but after drb.addChart(djChart) chat added as null. Here is my code:
private static DynamicReport createPieChart() {
DynamicReportBuilder drb = new DynamicReportBuilder();
DynamicReport dr = new DynamicReport();
try {
AbstractColumn columnName = ColumnBuilder.getNew().setColumnProperty("name", String.class.getName()).setTitle("Name").build();
AbstractColumn columnaId = ColumnBuilder.getNew().setColumnProperty("id", Integer.class.getName()).setTitle("Id").build();
AbstractColumn columnaTotal = ColumnBuilder.getNew().setColumnProperty("total", Long.class.getName()).setTitle("Total").build();
drb.addColumn(columnName);
drb.addColumn(columnaId);
drb.addColumn(columnaTotal);
DJChart djChart = new DJPieChartBuilder().setX(20)
.setY(10)
.setWidth(500)
.setHeight(250)
.setKey((PropertyColumn) columnaId)
.addSerie(columnaTotal).build();
drb.setUseFullPageWidth(true);
drb.addChart(djChart);
dr = drb.build();
} catch (Exception e) {
}
return dr;
}
Please help!

My problem was building report before set its query. Thanks

Please find the sample code here
DJChart djChart = new DJLineChartBuilder()
//chart
.setX(20)
.setY(10)
.setWidth(500)
.setHeight(250)
.setCentered(false)
.setBackColor(Color.LIGHT_GRAY)
.setShowLegend(true)
.setPosition(DJChartOptions.POSITION_FOOTER)
.setTitle(new StringExpression() {
public Object evaluate(Map fields, Map variables, Map parameters) {
return variables.get("group_state_name");
}
})
.setTitleColor(Color.DARK_GRAY)
.setTitleFont(Font.ARIAL_BIG_BOLD)
.setSubtitle("subtitle")
.setSubtitleColor(Color.DARK_GRAY)
.setSubtitleFont(Font.COURIER_NEW_BIG_BOLD)
.setLegendColor(Color.DARK_GRAY)
.setLegendFont(Font.COURIER_NEW_MEDIUM_BOLD)
.setLegendBackgroundColor(Color.WHITE)
.setLegendPosition(DJChartOptions.EDGE_BOTTOM)
.setTitlePosition(DJChartOptions.EDGE_TOP)
.setLineStyle(DJChartOptions.LINE_STYLE_DOTTED)
.setLineWidth(1)
.setLineColor(Color.DARK_GRAY)
.setPadding(5)
//dataset
.setCategory((PropertyColumn) columnBranch)
.addSerie(columnaQuantity, "quant.")
.addSerie(columnAmount)
//plot
.setShowShapes(true)
.setShowLines(true)
.setCategoryAxisFormat(categoryAxisFormat)
.setValueAxisFormat(valueAxisFormat)
.build();
drb.addChart(djChart);
DJHyperLink djlink = new DJHyperLink();
djlink.setExpression(new StringExpression() {
public Object evaluate(Map fields, Map variables, Map parameters) {
return "http://thisIsAURL?count=" + variables.get("REPORT_COUNT");
}
});
djlink.setTooltip(new LiteralExpression("I'm a literal tootltip"));
djChart.setLink(djlink);

Related

How do I build a custom CheckBoxGroup field in Magnolia 6.2 CMS?

When I create the CustomCheckBoxGroup field, all options of the field are displayed. But if I select one or more options and then save them, they are not saved in Magnolia. I suspect that wrong dataProvider is initialized (JcrDatasource instead of OptionListProvider).
form:
properties:
checkboxGroup:
$type: customCheckBoxGroupField
What is wrong here?
public class CustomCheckBoxGroupFieldFactory<T> extends AbstractOptionGroupFieldFactory<CustomCheckBoxGroupFieldDefinition<T>, Set<T>> {
private final static String STORES = "stores";
public CustomCheckBoxGroupFieldFactory(
CustomCheckBoxGroupFieldDefinition<T> definition,
ComponentProvider componentProvider,
SelectFieldSupport<Set<T>> selectFieldSupport) {
super(definition, componentProvider, selectFieldSupport);
}
#Override
public CheckBoxGroup<T> createFieldComponent() {
CheckBoxGroup<T> items = new CheckBoxGroup<T>("Test");
items.setItems((Collection)(this.selectStores()));
items.setItemCaptionGenerator(
item -> ((Option) item).getName() //((Option) item).getLabel()
);
return items;
}
public HasValue<Set<T>> createField() {
return this.createFieldComponent();
}
private Collection<Option> selectStores() {
List<Option> options = new ArrayList<>();
try {
Session session = MgnlContext.getJCRSession(STORES);
Node parent = session.getNode("/");
for (Node storeNode : NodeUtil.getNodes(parent, NodeTypes.Content.NAME)) {
if (storeNode.hasProperty(PROPERTY_NAME_DISPLAY_NAME)) {
Option option = new Option();
option.setValue(storeNode.getIdentifier());
option.setLabel(storeNode.getProperty(PROPERTY_NAME_DISPLAY_NAME).getString());
option.setName(storeNode.getProperty(PROPERTY_NAME_DISPLAY_NAME).getString());
options.add(option);
}
}
} catch (RepositoryException e) {
log.error("Cannot preselect already configured workspaces.", e);
}
return options;
}
}

OpenSubtitles API Response

I can communicate but I expect to get a list of subtitles in the Object. Here is my code:
public static void makerequest(){
Thread thread = new Thread() {
#Override
public void run() {
try {
XMLRPCClient client = new XMLRPCClient(new URL("https://api.opensubtitles.org/xml-rpc"));
HashMap ed = (HashMap<Object,String>) client.call("LogIn",username,password,"en",useragent);
String Token = (String) ed.get("token");
Map<String, String> videoProperties = new HashMap<>();
videoProperties.put("sublanguageid", "en");
videoProperties.put("imdbid", "528809");
Object[] videoParams = {videoProperties};
Object[] params = {Token, videoParams};
HashMap test2 = (HashMap<Object,String>) client.call("SearchSubtitles",params);
Object[] d = (Object[]) test2.get("data");
Log.d("diditworkstring", String.valueOf(d));
} catch (Exception ex) {
// Any other exception
Log.d("diditworkexception", String.valueOf(ex));
}
}
};
thread.start();
}
In my log I get the following:
Log: {seconds=0.188, data=[Ljava.lang.Object;#2ec1b40, status=200 OK}
I thought I would see a list of subtitle information. I see that in this response (data=Ljava.Object;#23c1b40). is there something in that Object??
Below is the code that ultimately worked. I don't know the proper terminology but here is my best shot at explaining what I was doing wrong. I was trying to directly look at the Object as a string. After viewing it with Arrays.asList() I was able to see the data. Then each item in the list I cast as Map. After that I was able to get/change anything my heart desired.
Hope this Helps someone some day :)
Thread thread = new Thread() {
#Override
public void run() {
try {
// Setup XMLRPC Client
XMLRPCClient client = new XMLRPCClient(new URL("https://api.opensubtitles.org/xml-rpc"));
HashMap ed = (HashMap<Object,String>) client.call("LogIn",username,password,"en",useragent);
// separate my Token from the reply
String Token = (String) ed.get("token");
// setup Parameters for next call to search for subs
Map<String, String> videoProperties = new HashMap<>();
videoProperties.put("sublanguageid", "en");
videoProperties.put("query", "blade 2");
Object[] videoParams = {videoProperties};
Object[] params = {Token, videoParams};
// Make next call include method and Parameters
java.util.HashMap test2 = (HashMap<String,Array>) client.call("SearchSubtitles",params);
// select data key from test2
Object[] d = (Object[]) test2.get("data");
// change d Object to List
List ee = Arrays.asList(d);
// Grab Map from list
Map xx = (Map) ee.get(1);
Log.d("diditworkstring", String.valueOf(xx.get("ZipDownloadLink")));
} catch (Exception ex) {
// Any other exception
Log.d("diditworkexception", String.valueOf(ex));
}
}
};

Create an issue to JIRA by Java Code

I am able to connect to JIRA by JIRARestClient API and also able to get the information about issue but whenever I am trying to create issue by below code, getting this error "RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors={issuetype=valid issue type is required}, errorMessages=[]}]}"
IssueRestClient issueClient = new AsynchronousJiraRestClientFactory()
.createWithBasicHttpAuthentication(baseUri, username, password).getIssueClient();
IssueType issueType = new IssueType(null, 0L, "bug", false, "my issue", null);
BasicProject basicProject = new BasicProject(null, "CPQ", 1L, null);
IssueInput newIssue = new IssueInputBuilder(basicProject,issueType,"Mopendra").build();
String issueCreated = issueClient.createIssue(newIssue).claim().getKey();
can anyone please help me on this?
the cause is that you should use valid issue type that exists in your Jira and fill parameters correctly. You can fetch existing issue types and choose one you need. See
Jira issue type values for Rest api
Please refer the below-working code. This should solve your problem.
//call method createIssue
final String issueKey = myJiraClient.createIssue("YOUR_PRAJECT_NAME", 1L, "Issue created from Standalone App");
// method declaration
private String createIssue(String projectKey, Long iType, String issueSummary) {
IssueRestClient issueClient = restClient.getIssueClient();
BasicProject cpqProject = null;
IssueType issueType = null;
try {
final Iterable<BasicProject> projects = restClient.getProjectClient().getAllProjects().claim();
System.out.println("======================getting all projoects======================");
for (BasicProject project : projects) {
if(project.getKey().equalsIgnoreCase("cpq")) {
cpqProject = project;
}
}
Promise<Project> project = restClient.getProjectClient().getProject(projectKey);
for(IssueType type : (project.get()).getIssueTypes()) {
if(type.getName().equalsIgnoreCase("Bug")){
issueType = type;
}
}
} catch (Exception e) {
e.printStackTrace();
}
IssueInput newIssue = new IssueInputBuilder(cpqProject, issueType, issueSummary).build();
return issueClient.createIssue(newIssue).claim().getKey();
}

How can I call an arraylist that I already have loaded with my database inside the XML

I'm using ZK and I have this code that works me statically
<zscript>
<![CDATA[
List tipo_servicios = new ArrayList();
List tipo_servicios_enc = new ArrayList();
DTO.Tiposervicio tipo_servicios_select;
DTO.Tiposervicio tiposervicio = new DTO.Tiposervicio();
tiposervicio.setId(1);
tiposervicio.setName("Mustang");
tiposervicio.setDescripcion("New Mustang 2018");
tiposervicio.setEstatus('A');
tipo_servicios.add(tiposervicio);
void buscarTipoServicios()
{
if (keywordBox.getValue() != null && !keywordBox.getValue().trim().equals(""))
{
tipo_servicios_enc.clear();
for (DTO.Tiposervicio tipo_serv : tipo_servicios)
{
if (tipo_serv.getName().toLowerCase().contains(keywordBox.getValue().trim().toLowerCase()) || tipo_serv.getName().toLowerCase().contains(keywordBox.getValue().trim().toLowerCase()))
{
tipo_servicios_enc.add(tipo_serv);
}
}
binder.loadAll();
}
}
]]>
</zscript>
It's a search engine
void buscarTipoServicios()
And I have in my service package my next code that is used to load my array from the database
public class ConsultarTipoServicio extends SelectorComposer
{
private List<Tiposervicio> listaTipoServicio;
private TiposervicioJpaController tipoServicioJpaController;
public ConsultarTipoServicio() throws Exception
{
EntityManagerFactory emf =Persistence.createEntityManagerFactory("ProyectoLabIIPU");
tipoServicioJpaController=new TiposervicioJpaController(emf);
listaTipoServicio= tipoServicioJpaController.findTiposervicioEntities();
}
public List<Tiposervicio> getlistaTipoServicio()
{
return listaTipoServicio;
}
}
I want somehow to assign to my
List tipo_servicios = new ArrayList();
The array already loaded from
getlistaTypeServicio ()
I'm trying something like this but it gives me error
List tipo_servicios = Servicios.ConsultarTipoServicios.getlistaTipoServicio();
I solved it this way
consultar = new Servicios.ConsultarTipoServicio();
List tipo_servicios = consultar.getlistaTipoServicio();
List tipo_servicios_enc = new ArrayList();
DTO.Tiposervicio tipo_servicios_select;

How to filter a Spark RDD based on particular field value in Java?

I am creating a Spark job in Java. Here is my code.
I am trying to filter records from a CSV file. Header contains fields OID, COUNTRY_NAME, ......
Instead of just filtering based on s.contains("CANADA"), I would like to be more specific, like I want to filter based on COUNTRY_NAME.equals("CANADA").
Any thoughts on how I can do this?
public static void main(String[] args) {
String gaimFile = "hdfs://xx.yy.zz.com/sandbox/data/acc/mydata";
SparkConf conf = new SparkConf().setAppName("Filter App");
JavaSparkContext sc = new JavaSparkContext(conf);
try{
JavaRDD<String> gaimData = sc.textFile(gaimFile);
JavaRDD<String> canadaOnly = gaimData.filter(new Function<String, Boolean>() {
private static final long serialVersionUID = -4438640257249553509L;
public Boolean call(String s) {
// My file id csv with header OID, COUNTRY_NAME, .....
// here instead of just saying s.contains
// i would like to be more specific and say
// if COUNTRY_NAME.eqauls("CANADA)
return s.contains("CANADA");
}
});
}
catch(Exception e){
System.out.println("ERROR: G9 MatchUp Failed");
}
finally{
sc.close();
}
}
You will have to map your values into a custom class first:
rdd.map(lines=>ConvertToCountry(line))
.filter(country=>country == "CANADA")
class Country{
...ctor that takes an array and fills properties...
...properties for each field from the csv...
}
ConvertToCountry(line: String){
return new Country(line.split(','))
}
The above is a combination of Scala and pseudocode, but you should get the point.

Categories

Resources