-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inputs, localstorage, connection bonitabpm
- Loading branch information
1 parent
2ad4fa0
commit 716b741
Showing
13 changed files
with
455 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
testAPI/src/main/java/com/bonitaSoft/business/SystemOpImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.bonitaSoft.business; | ||
|
||
import java.io.IOException; | ||
import java.sql.Date; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import javax.servlet.ServletContext; | ||
|
||
import org.bonitasoft.engine.api.ApiAccessType; | ||
import org.bonitasoft.engine.api.LoginAPI; | ||
import org.bonitasoft.engine.api.TenantAPIAccessor; | ||
import org.bonitasoft.engine.exception.BonitaHomeNotSetException; | ||
import org.bonitasoft.engine.exception.ServerAPIException; | ||
import org.bonitasoft.engine.exception.UnknownAPITypeException; | ||
import org.bonitasoft.engine.platform.LoginException; | ||
import org.bonitasoft.engine.session.APISession; | ||
import org.bonitasoft.engine.util.APITypeManager; | ||
|
||
import com.bonitaSoft.tools.LocalStorage; | ||
import com.bonitaSoft.tools.LoginInfo; | ||
import com.bonitaSoft.tools.ReturnObject; | ||
import com.bonitaSoft.tools.Tools; | ||
|
||
public class SystemOpImpl { | ||
|
||
Tools myTools = new Tools(); | ||
|
||
public void getBusiness(ReturnObject myJSONObject, HashMap<String, Object> inputs, ServletContext context) throws IOException { | ||
String log = (String) inputs.get("log"); | ||
String pass = (String) inputs.get("pass"); | ||
|
||
Map<String, String> map = new HashMap<String, String>(); | ||
map.put("server.url", "http://localhost:8080"); | ||
map.put("application.name", "bonita"); | ||
APITypeManager.setAPITypeAndParams(ApiAccessType.HTTP, map); | ||
// get the LoginAPI using the TenantAPIAccessor | ||
try { | ||
final LoginAPI loginAPI = TenantAPIAccessor.getLoginAPI(); | ||
|
||
final APISession apiSession = loginAPI.login(log, pass); | ||
|
||
String token = myTools.generateToken(); | ||
|
||
Date resultdate = new Date(System.currentTimeMillis()); | ||
|
||
LoginInfo loginInfo = new LoginInfo(log,pass,apiSession,resultdate,token); | ||
|
||
LocalStorage localStorage = (LocalStorage) context.getAttribute("localStorage"); | ||
|
||
localStorage.setStorage(token, loginInfo); | ||
|
||
myJSONObject.addDatas("token", token); | ||
} catch (BonitaHomeNotSetException | ServerAPIException | UnknownAPITypeException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} catch (LoginException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
testAPI/src/main/java/com/bonitaSoft/business/TestImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.bonitaSoft.business; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
|
||
import com.bonitaSoft.tools.ReturnObject; | ||
|
||
public class TestImpl { | ||
|
||
public TestImpl(){ | ||
|
||
} | ||
|
||
public void getBusiness(ReturnObject myJSONObject, HashMap<String, Object> inputs) throws IOException { | ||
myJSONObject.addDatas("truc", 1); | ||
myJSONObject.addDatas("name", inputs.get("name")); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
testAPI/src/main/java/com/bonitaSoft/testAPI/SystemOp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.bonitaSoft.testAPI; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import javax.servlet.ServletContext; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.Context; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.UriInfo; | ||
|
||
import org.json.JSONObject; | ||
|
||
import com.bonitaSoft.business.SystemOpImpl; | ||
import com.bonitaSoft.tools.ReturnObject; | ||
import com.bonitaSoft.tools.Tools; | ||
|
||
/** | ||
* Root resource (exposed at "test" path) | ||
* testAPI/webapi/systemop/login.php?log=walter.bates&pass=bpm | ||
*/ | ||
@Path("/systemop") | ||
public class SystemOp { | ||
Tools myTools = new Tools(); | ||
SystemOpImpl mySystemOpImpl = new SystemOpImpl(); | ||
|
||
@Context ServletContext context; | ||
|
||
Boolean debug = true; | ||
|
||
Boolean publicI = true; | ||
|
||
@GET | ||
@Path("/login.php") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String testGet(@Context UriInfo uriInfo) { | ||
return execTest(uriInfo); | ||
} | ||
|
||
@POST | ||
@Path("/login.php") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String testPost(@Context UriInfo uriInfo) { | ||
return execTest(uriInfo); | ||
} | ||
|
||
public String execTest(UriInfo uriInfo) { | ||
JSONObject returnJSONObject = new JSONObject(); | ||
try{ | ||
//def | ||
List<Object> inputsDef = new ArrayList<Object>(); | ||
ReturnObject myJSONObject = new ReturnObject(); | ||
|
||
//input 'log' | ||
Map<String, Object> log = new HashMap<String, Object>(); | ||
log.put("label", "log"); | ||
log.put("type", String.class); | ||
log.put("default", null); | ||
|
||
inputsDef.add(log); | ||
|
||
//input 'pass' | ||
Map<String, Object> pass = new HashMap<String, Object>(); | ||
pass.put("label", "pass"); | ||
pass.put("type", String.class); | ||
pass.put("default", null); | ||
|
||
inputsDef.add(pass); | ||
|
||
//check input | ||
HashMap<String, Object> inputs = myTools.checkInput(uriInfo, inputsDef, publicI, debug); | ||
|
||
if(inputs.get("crtInputs") == null) { | ||
//------------------------------------------------ | ||
//custom part | ||
mySystemOpImpl.getBusiness(myJSONObject, inputs, context); | ||
//------------------------------------------------ | ||
}else{ | ||
myJSONObject.setStrErreur((String) inputs.get("crtInputs")); | ||
} | ||
|
||
returnJSONObject = myJSONObject.getReturnObjectJson(); | ||
return returnJSONObject.toString(); | ||
}catch (Exception e){ | ||
myTools.traceLog("Error : " + e.getMessage()); | ||
return returnJSONObject.toString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
testAPI/src/main/java/com/bonitaSoft/tools/LocalStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.bonitaSoft.tools; | ||
|
||
import java.util.HashMap; | ||
|
||
public class LocalStorage { | ||
private HashMap<String, Object> storage = new HashMap<String, Object>(); | ||
|
||
public Object getStorage(String key) { | ||
return storage.get(key); | ||
} | ||
|
||
public void setStorage(String key, Object obj) { | ||
this.storage.put(key, obj); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.bonitaSoft.tools; | ||
|
||
import java.util.Date; | ||
|
||
public class LoginInfo { | ||
private String user; | ||
|
||
private String pass; | ||
|
||
private Object session; | ||
|
||
private Date startDateSession; | ||
|
||
private String key; | ||
|
||
private Integer Ttl = 3600; | ||
|
||
public LoginInfo(String user, String pass, Object session, Date startDateSession, String key) { | ||
this.user = user; | ||
this.pass = pass; | ||
this.session = session; | ||
this.startDateSession = startDateSession; | ||
this.key = key; | ||
} | ||
|
||
public String getUser() { | ||
return user; | ||
} | ||
|
||
public void setUser(String user) { | ||
this.user = user; | ||
} | ||
|
||
public String getPass() { | ||
return pass; | ||
} | ||
|
||
public void setPass(String pass) { | ||
this.pass = pass; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public void setKey(String key) { | ||
this.key = key; | ||
} | ||
|
||
public Integer getTtl() { | ||
return Ttl; | ||
} | ||
|
||
public void setTtl(Integer ttl) { | ||
Ttl = ttl; | ||
} | ||
|
||
public Object getSession() { | ||
return session; | ||
} | ||
|
||
public void setSession(Object session) { | ||
this.session = session; | ||
} | ||
|
||
public Date getStartDateSession() { | ||
return startDateSession; | ||
} | ||
|
||
public void setStartDateSession(Date startDateSession) { | ||
this.startDateSession = startDateSession; | ||
} | ||
} |
Oops, something went wrong.