Skip to content

Commit

Permalink
Version 2.0, with : BonitaEvent, BonitaProperties, Modal page
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Yves Monnet committed Sep 7, 2016
1 parent 4368734 commit f2d9058
Show file tree
Hide file tree
Showing 16 changed files with 1,078 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .lastupdate
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1457543690074
1473209886461
95 changes: 84 additions & 11 deletions Index.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.lang.Runtime;
import java.util.ArrayList;
import java.util.List;

import org.json.simple.JSONObject;
import org.codehaus.groovy.tools.shell.CommandAlias;
Expand Down Expand Up @@ -60,6 +62,12 @@ import org.bonitasoft.engine.command.CommandDescriptor;
import org.bonitasoft.engine.command.CommandCriterion;
import org.bonitasoft.engine.bpm.flownode.ActivityInstance;
import org.bonitasoft.engine.bpm.process.ProcessDeploymentInfo;

import org.bonitasoft.log.event.BEvent;
import org.bonitasoft.log.event.BEvent.Level;
import org.bonitasoft.log.event.BEventFactory;

import org.bonitasoft.ext.properties.BonitaProperties;

import com.bonitasoft.users.UsersOperation;

Expand All @@ -78,10 +86,10 @@ public class Index implements PageController {
PrintWriter out = response.getWriter()

String action=request.getParameter("action");
logger.info("###################################### action is["+action+"] !");
logger.info("###################################### action is["+action+"] 2.0!");
if (action==null || action.length()==0 )
{
logger.severe("###################################### RUN Default !");
// logger.info("RUN Default !");

runTheBonitaIndexDoGet( request, response,pageResourceProvider,pageContext);
return;
Expand All @@ -92,13 +100,15 @@ public class Index implements PageController {
PlatformMonitoringAPI platformMonitoringAPI = TenantAPIAccessor.getPlatformMonitoringAPI(session);
IdentityAPI identityApi = TenantAPIAccessor.getIdentityAPI(session);

HashMap<String,Object> answer = null;
List<BEvent> listEvents = new ArrayList<BEvent>();

if ("ping".equals(action))
{
HashMap<String,Object> pingDetails = new HashMap<String,Object>();
answer = new HashMap<String,Object>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
pingDetails.put("pingcurrentdate", sdf.format( new Date() ) );
pingDetails.put("pingserverinfo", "server is up");
answer.put("pingcurrentdate", sdf.format( new Date() ) );
answer.put("pingserverinfo", "server is up 2.1");

List<ActivityTimeLine> listActivities = new ArrayList<ActivityTimeLine>();
listActivities.add( ActivityTimeLine.getActivityTimeLine("Choose beverage", 9, 11));
Expand All @@ -108,7 +118,7 @@ public class Index implements PageController {
listActivities.add( ActivityTimeLine.getActivityTimeLine("Inject hot water", 13, 14));
listActivities.add( ActivityTimeLine.getActivityTimeLine("Have fun with Bonita", 14, 17));

pingDetails.put("chartObject", getChartTimeLine("Chart Example", listActivities));
answer.put("chartObject", getChartTimeLine("Chart Example", listActivities));


// list of process
Expand All @@ -126,21 +136,84 @@ public class Index implements PageController {
processMap.put("deployeddate", simpleDateFormat.format( processDeployment.getDeploymentDate() ) );
listProcesses.add( processMap);
}
pingDetails.put("listprocesses", listProcesses);
answer.put("listprocesses", listProcesses);

final UsersOperation userOperations = new UsersOperation();
final List<Map<String, Object>> listMapUsers = userOperations.getUsersList(identityApi);
pingDetails.put("listusers", listMapUsers);
answer.put("listusers", listMapUsers);


String jsonDetailsSt = JSONValue.toJSONString( pingDetails );
listEvents.add( new BEvent("com.bonitasoft.ping", 1, Level.INFO, listMapUsers.size()+" Users found", "Number of users found in the system"));
listEvents.add( new BEvent("com.bonitasoft.ping", 1, Level.APPLICATIONERROR, "Fake error", "This is not a real error", "No consequence", "don't call anybody"));



}
if ("saveprops".equals(action)) {
String jsonparam=request.getParameter("jsonparam");
final HashMap<String, Object> jsonHash=null;

if (jsonparam != null && jsonparam.length() > 0 ) {
jsonHash = (HashMap<String, Object>) JSONValue.parse( jsonparam );
}
answer = new HashMap<String,Object>();
if (jsonHash!=null)
{
try
{
BonitaProperties bonitaProperties = new BonitaProperties( pageResourceProvider );

listEvents.addAll( bonitaProperties.load() );
bonitaProperties.setProperty( session.getUserId()+"_firstname", jsonHash.get("firstname") );
listEvents.addAll( bonitaProperties.store());
}
catch( Exception e )
{
logger.severe("Exception "+e.toString());
listEvents.add( new BEvent("com.bonitasoft.ping", 10, Level.APPLICATIONERROR, "Error using BonitaProperties", "Error :"+e.toString(), "Properties is not saved", "Check exception"));
}
}
else
listEvents.add( new BEvent("com.bonitasoft.ping", 11, Level.APPLICATIONERROR, "JsonHash can't be decode", "the parameters in Json can't be decode", "Properties is not saved", "Check page"));

}
if ("loadprops".equals(action)) {
answer = new HashMap<String,Object>();
try
{
logger.info("Load properties");

BonitaProperties bonitaProperties = new BonitaProperties( pageResourceProvider );
listEvents.addAll( bonitaProperties.load() );
logger.info("Load done, events = "+listEvents.size() );

String firstName = bonitaProperties.getProperty( session.getUserId()+"_firstname" );
logger.info("Load done, firstName["+firstName+"]" );
answer.put("firstname", (firstName==null ? "" : firstName) );

}
catch( Exception e )
{
logger.severe("Exception "+e.toString());
listEvents.add( new BEvent("com.bonitasoft.ping", 10, Level.APPLICATIONERROR, "Error using BonitaProperties", "Error :"+e.toString(), "Properties is not saved", "Check exception"));

}

}


// save the result
if (answer!=null)
{
answer.put("listevents", BEventFactory.getHtml(listEvents) );

String jsonDetailsSt = JSONValue.toJSONString( answer );

out.write( jsonDetailsSt );
out.flush();
out.close();
return;
return;
}

out.write( "Unknow command" );
out.flush();
out.close();
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ Demonstrate a Custom page with Html, AngularJS, customRESTAPI embeded

<img src="ScreenShotPing_2.jpg"/>

Demonstrate the BonitaEvent librairy, and the result
<img src="ScreenShotPing_3.jpg"/>

Demonstrate the BonitaProperties librairy, and how to save a value in the Bonita Database
<img src="ScreenShotPing_4.jpg"/>

And a example of Modal in the custom page
<img src="ScreenShotPing_5.jpg"/>
Binary file added ScreenShotPing_3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ScreenShotPing_4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ScreenShotPing_5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 65 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<link rel="stylesheet" href="pageResource?page=custompage_ping&location=style/bootstrap.min.css">
<link rel="stylesheet" href="pageResource?page=custompage_ping&location=style/main.css">
<link rel="stylesheet" href="pageResource?page=custompage_ping&location=style/style.css">
<link rel="stylesheet" href="pageResource?page=custompage_ping&location=style/ng-modal.css">

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="https://www.google.com/uds/?file=visualization&amp;v=1&amp;hl=fr&amp;packages=corechart&amp;async=2"></script>
Expand Down Expand Up @@ -43,7 +44,57 @@ <h1><center>Ping the server</center></h1>

<div id="collectwait" style="background-color:green;color: #FFFFFF;">Please wait, collect in progress</div>
<button id="collectbtn" ng-click="pingctrl.ping()" class="btn btn-info btn-xs">Collect informations</button>

&nbsp;&nbsp;
<button class="btn btn-info btn-xs" ng-click="pingctrl.openDialog()">Dialog</button> <p>


<div class="row">
<div class="col-lg-1">
</div>
<div class="col-lg-5">
<div class="panel panel-info">
<div class="panel-heading">Status of operation (events)</div>
<div>
<p>
<div class="well">
Operations return BonitaEvent. An event give a code, a title, a level (INFO,ERROR,...),an action in case of ERROR and a Consequence in case of ERROR
</div>
<center>
<div ng-bind-html="pingctrl.getListEvents(pingctrl.listevents )"></div>
</center>
<p>
</div>
</div>
</div>

<div class="col-lg-5">
<div class="panel panel-primary">
<div class="panel-heading">Bonita Properties</div>
<div>
<div class="well">
This information is save via the BonitaProperties, in the Bonita Database. So, it's persistent and can be share in a clsuter. It's saved in the backup too.<br>
Give a value, save it.<br>
Click again on the page (or logout) : the value is retrieve from the database and it visible again.
</div>
<center>
<button class="btn btn-success" ng-click="pingctrl.loadProps()">Refresh</button> <p>
</center>
My First name : <input type="input" ng-model="pingctrl.propsFirstName" size="50"><p>
<center>
<button class="btn btn-success " ng-click="pingctrl.saveProps()">Save</button> <p>
</center>



</div>
</div>
</div>
</div>
<p>

<h3>Server state</h3>

<table class="table table-striped table-hover table-condensed">
<tr> <td>Ping date</td><td>{{pingctrl.pingdate}}</td></tr>
<tr> <td>Ping info</td><td>{{pingctrl.pinginfo}}</td></tr>
Expand Down Expand Up @@ -84,10 +135,19 @@ <h3>Chart</h3>

<div google-chart chart="chartObject" style="height: 400px; width: 100%; position: relative; "></div>
</div>
</div>
</div>



<modal-dialog show='pingctrl.isshowDialog' dialog-title='Details' width='75%' height='80%' close="pingctrl.closeDialog()">
<div class="modal-content" width='100%' height='100%'>
<h2>Here a modal</h2>
<p>
<p>
So, here you can set up different information here. To close it, click on the close button on the top left
</div>
</modal-dialog>

</div>
</div>
</div>


Expand All @@ -105,6 +165,8 @@ <h3>Chart</h3>
<script src="pageResource?page=custompage_ping&location=3rd-party/angular-bootstrap-tpls.min.js"></script>
<script src="pageResource?page=custompage_ping&location=3rd-party/angular-file-upload.js"></script>
<script src="pageResource?page=custompage_ping&location=3rd-party/ng-google-chart.js"></script>
<script src="pageResource?page=custompage_ping&location=3rd-party/angular-sanitize.min.js"></script>
<script src="pageResource?page=custompage_ping&location=3rd-party/ng-modal.min.js"></script>


<!-- Application dependencies -->
Expand Down
Binary file added lib/BonitaProperties-1.0.0.jar
Binary file not shown.
Binary file added lib/bonita-event-1.0.0.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions page.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#The name must start with 'custompage_'
#Tue Mar 22 12:45:48 PDT 2016
version=1.2
#Wed Sep 07 11:29:06 PDT 2016
displayName=Ping
version=1.2
name=custompage_ping
description=Show example using Html, Angular, Groovy
Loading

0 comments on commit f2d9058

Please sign in to comment.