Commit a99b1b14 authored by Michel Dirix's avatar Michel Dirix

- Display exceptions for user which use basicService template

- Remove sysout 
- Add java generation for ProxyLogWS template
parent fbcff3e0
......@@ -68,6 +68,8 @@
<hibernate.connection.password></hibernate.connection.password>
<slf4j.version>1.5.5</slf4j.version>
<juliac.version>2.4.3</juliac.version>
</properties>
......
......@@ -81,7 +81,6 @@ public class FacebookCatalogServices implements CatalogServicesItf {
+ properties.getProperty("idPageFBK") + "/feed");
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("response body : "+response.getBody());
return this.parse(response.getBody());
} catch (Exception e) {
e.printStackTrace();
......@@ -93,12 +92,10 @@ public class FacebookCatalogServices implements CatalogServicesItf {
ArrayList<Publication> publications = new ArrayList<Publication>();
JSONObject jsonObjet = new JSONObject(json);
if (jsonObjet.has("data")) {
System.out.println("hasData");
JSONArray jsonArray = new JSONArray(jsonObjet.getString("data"));
for (int i = 0; i < jsonArray.length(); ++i) {
JSONObject j = jsonArray.getJSONObject(i);
if (j.has("message") && j.getString("message").length() > 10) {
System.out.println("concerned message");
String date = j.getString("created_time");
String message = j.getString("message");
Publication p = getPublication(date, message);
......@@ -110,12 +107,9 @@ public class FacebookCatalogServices implements CatalogServicesItf {
}
private Publication getPublication(String date, String message) {
System.out.println(message);
System.out.println(date);
Scanner in = new Scanner(message);
String name = null;
name = in.next();
System.out.println("name : "+name);
ArrayList<String> http = new ArrayList<String>();
String txt = in.next();
String description = "";
......@@ -130,40 +124,39 @@ public class FacebookCatalogServices implements CatalogServicesItf {
description += in.nextLine();
}
}
if(in.hasNext()){
if (in.hasNext()) {
txt = in.next();
}
}
return new Publication(date, name, description, http);
}
/**
* @see CatalogServicesItf#publish(String, Properties)
*/
@Override
public void publish(String message, Properties properties) {
try{
String postfb = URLEncoder.encode(message, "UTF-8");
OAuthService service = new ServiceBuilder().provider(FacebookApi.class)
.apiKey(properties.getProperty("apiKeyFBK"))
.apiSecret(properties.getProperty("apiSecretFBK")).scope(SCOPE)
.build();
Token accessToken = new Token(properties.getProperty("tokenAccessFBK"),
properties.getProperty("apiSecretFBK"));
String urlPost = "https://api.facebook.com/method/stream.publish?format=json&message="
+ postfb
+ "&uid=100003869660631"
+ "&target_id=" + properties.getProperty("idPageFBK");
OAuthRequest request = new OAuthRequest(Verb.GET, urlPost);
service.signRequest(accessToken, request);
Response response = request.send();
String adrFBK = response.getBody();
System.out.println(adrFBK);
}
catch(Exception e){
try {
String postfb = URLEncoder.encode(message, "UTF-8");
OAuthService service = new ServiceBuilder()
.provider(FacebookApi.class)
.apiKey(properties.getProperty("apiKeyFBK"))
.apiSecret(properties.getProperty("apiSecretFBK"))
.scope(SCOPE).build();
Token accessToken = new Token(
properties.getProperty("tokenAccessFBK"),
properties.getProperty("apiSecretFBK"));
String urlPost = "https://api.facebook.com/method/stream.publish?format=json&message="
+ postfb
+ "&uid=100003869660631"
+ "&target_id="
+ properties.getProperty("idPageFBK");
OAuthRequest request = new OAuthRequest(Verb.GET, urlPost);
service.signRequest(accessToken, request);
request.send();
} catch (Exception e) {
e.printStackTrace();
}
}
}
......@@ -254,7 +254,6 @@ public class CodeGeneratorWsdlToJSImpl implements CodeGenerator {
@Override
public String getCompositeLineImplementation(String service) {
System.out.println("getCompositeLineImplementation java");
return "<frascati:implementation.script script=\"scripts/"+service+".js\"/>";
}
}
......@@ -224,12 +224,6 @@ public class CodeGeneratorWsdlToJavaImpl implements CodeGenerator {
.getAbsolutePath());
String[] params = new String[] { "-d", outputDirectory, wsdl };
ToolContext toolContext = new ToolContext();
// if(application.getPackageName() != null && !application.getPackageName().equals("")){
// toolContext.setPackageName(application.getPackageName()+".impl.generated");
// }
// else{
// toolContext.setPackageName("impl.generated");
// }
new WSDLToJava(params).run(toolContext);
} catch(ToolException te){
throw new ToolException();
......@@ -281,7 +275,6 @@ public class CodeGeneratorWsdlToJavaImpl implements CodeGenerator {
@Override
public String getCompositeLineImplementation(String service) {
System.out.println("getCompositeLineImplementation java");
return "<implementation.java class=\"org.ow2.frascati.impl."+service+"\"/>";
}
......
......@@ -73,7 +73,6 @@ public class CodeTransformerProcessor implements CodeTransformerProcessorItf {
return this.transformersMap.get(generatorType).transform(file, application);
}
catch(Exception e){
System.out.println("CodeTransformerProcessor throws an Exception");
throw e;
}
}
......
......@@ -28,7 +28,9 @@
package org.easysoa.codegenerator;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Arrays;
import org.easysoa.api.CompilerItf;
import org.easysoa.model.Application;
......@@ -46,10 +48,10 @@ import org.ow2.frascati.util.FrascatiClassLoader;
public class JavaCodeTransformer implements CodeTransformerItf {
@Reference
protected MembraneGeneration membraneGeneration;
protected MembraneGeneration membraneGeneration;
@Reference
protected CompilerItf scaCompiler;
/**
* @see CodeTransformerItf#getId()
*/
......@@ -63,89 +65,85 @@ public class JavaCodeTransformer implements CodeTransformerItf {
*/
@SuppressWarnings("unchecked")
@Override
public String transform(File generatedFile, Application application) throws CompilationException{
public String transform(File generatedFile, Application application)
throws CompilationException {
String json = null;
//TODO add my FrascatiClassLoader and close
FrascatiClassLoader cl = new FrascatiClassLoader();
try {
membraneGeneration.open(cl);
} catch (FactoryException e1) {
e1.printStackTrace();
}
membraneGeneration.addJavaSource(application.retrieveAbsoluteRoot() + File.separator + "src"
+ File.separator + "main" + File.separator + "java");
membraneGeneration.addJavaSource(application.retrieveAbsoluteRoot() + File.separator + "src"
+ File.separator + "main" + File.separator + "resources");
ClassLoader classLoader;
try {
classLoader = membraneGeneration.compileJavaSource();
} catch (Exception e) {
//e.printStackTrace();
try {
membraneGeneration.close();
} catch (FactoryException e1) {
e1.printStackTrace();
}
System.out.println("JavaCodeTransformer throws an Exception");
System.out.println("message : "+e.getMessage());
throw new CompilationException("A problem occured during the compilation. Please verify your interface code.");
}
String fileName = generatedFile.getName().substring(0, generatedFile.getName().indexOf("."));
String className = "org.ow2.frascati.api"+"."+ fileName;
Class<?> interfaceClass;
try {
interfaceClass = classLoader.loadClass(className);
} catch (ClassNotFoundException e) {
e.printStackTrace();
try {
membraneGeneration.close();
} catch (FactoryException e1) {
e1.printStackTrace();
}
return null;
membraneGeneration.addJavaSource(application.retrieveAbsoluteRoot()
+ File.separator + "src" + File.separator + "main"
+ File.separator + "java");
membraneGeneration.addJavaSource(application.retrieveAbsoluteRoot()
+ File.separator + "src" + File.separator + "main"
+ File.separator + "resources");
ClassLoader classLoader;
try {
classLoader = membraneGeneration.compileJavaSource();
membraneGeneration.close();
} catch (Exception e) {
Throwable throwable;
throwable = (Throwable) e.getCause().getCause().getCause();
if (throwable instanceof IOException) {
throw new CompilationException(
throwable.getMessage());
}
JSONObject interfaceJson = new JSONObject();
interfaceJson.put("name", className);
JSONArray methodsJSon = new JSONArray();
interfaceJson.put("methods", methodsJSon);
for(Method method : interfaceClass.getMethods()){
JSONObject methodJson = new JSONObject();
methodJson.put("name", method.getName());
methodJson.put("return", convertType(method.getReturnType().getName()));
JSONArray params = new JSONArray();
methodJson.put("params", params);
for (int paramIndex = 0; paramIndex < method.getParameterTypes().length; paramIndex++) {
JSONObject param = new JSONObject();
param.put("param", convertType(method.getParameterTypes()[paramIndex].getCanonicalName()));
params.add(param);
}
JSONArray exceptions = new JSONArray();
methodJson.put("exceptions", exceptions);
for (int paramIndex = 0; paramIndex < method.getExceptionTypes().length; paramIndex++) {
JSONObject exception = new JSONObject();
exception.put("exception", method.getExceptionTypes()[paramIndex].getCanonicalName());
exceptions.add(exception);
}
methodsJSon.add(methodJson);
throw new CompilationException("Undeclared throwable exception");
}
String fileName = generatedFile.getName().substring(0,
generatedFile.getName().indexOf("."));
String className = "org.ow2.frascati.api" + "." + fileName;
Class<?> interfaceClass;
try {
interfaceClass = classLoader.loadClass(className);
} catch (ClassNotFoundException e) {
return null;
}
JSONObject interfaceJson = new JSONObject();
interfaceJson.put("name", className);
JSONArray methodsJSon = new JSONArray();
interfaceJson.put("methods", methodsJSon);
for (Method method : interfaceClass.getMethods()) {
JSONObject methodJson = new JSONObject();
methodJson.put("name", method.getName());
methodJson.put("return", convertType(method.getReturnType()
.getName()));
JSONArray params = new JSONArray();
methodJson.put("params", params);
for (int paramIndex = 0; paramIndex < method.getParameterTypes().length; paramIndex++) {
JSONObject param = new JSONObject();
param.put("param",
convertType(method.getParameterTypes()[paramIndex]
.getCanonicalName()));
params.add(param);
}
json = interfaceJson.toJSONString();
try {
membraneGeneration.close();
} catch (FactoryException e) {
e.printStackTrace();
JSONArray exceptions = new JSONArray();
methodJson.put("exceptions", exceptions);
for (int paramIndex = 0; paramIndex < method.getExceptionTypes().length; paramIndex++) {
JSONObject exception = new JSONObject();
exception.put("exception",
method.getExceptionTypes()[paramIndex]
.getCanonicalName());
exceptions.add(exception);
}
return json;
methodsJSon.add(methodJson);
}
json = interfaceJson.toJSONString();
}
return json;
}
private String convertType(String type){
if(type.contains(".")){
return type.substring(type.lastIndexOf(".")+1, type.length());
}
else{
private String convertType(String type) {
if (type.contains(".")) {
return type.substring(type.lastIndexOf(".") + 1, type.length());
} else {
return type;
}
}
}
......@@ -119,8 +119,6 @@ public class TemplateActionBasicService implements TemplateActionItf {
implementationFile, className);
return "";
} catch (Exception e) {
System.out
.println("TemplateActionBasicService throws an Exception");
throw e;
}
}
......
......@@ -70,8 +70,6 @@ public class TemplateActionProxyWS implements TemplateActionItf {
@Override
public String doActionAfterCreation(Map<String, Object> params, Composite composite, Application application) {
String generatorId = (String)params.get("generator-id");
System.out.println("generatorId : "+generatorId);
System.out.println("implementation : "+ generatorsMap.get(generatorId).getCompositeLineImplementation((String)params.get("service")));
params.put("implementation", generatorsMap.get(generatorId).getCompositeLineImplementation((String)params.get("service")));
generatorsMap.get(generatorId).generate((String)params.get("userId"),(String)params.get("service"),(String)params.get("port"),(String)params.get("url"));
if("Java".equals(generatorId)){
......
......@@ -27,6 +27,8 @@
*/
package org.easysoa.compositeTemplates;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.easysoa.api.CodeGenerator;
......@@ -34,15 +36,27 @@ import org.easysoa.api.RESTCall;
import org.easysoa.api.TemplateActionItf;
import org.easysoa.model.Application;
import org.eclipse.stp.sca.Composite;
import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Reference;
public class TemplateActionProxyWSLog implements TemplateActionItf {
@Reference
protected CodeGenerator wsdlGenerator;
@Reference
protected RESTCall rest;
@Reference
protected List<CodeGenerator> generators;
private Map<String, CodeGenerator> generatorsMap;
@Init
public void initializeMapId(){
this.generatorsMap = new HashMap<String, CodeGenerator>();
for(CodeGenerator generator : generators){
generatorsMap.put(generator.getId(), generator);
}
}
@Override
public String getId() {
return "ProxyWSLog";
......@@ -50,11 +64,20 @@ public class TemplateActionProxyWSLog implements TemplateActionItf {
@Override
public String doActionBeforeCreation(Map<String, Object> params) {
return wsdlGenerator.generate((String)params.get("userId"),(String)params.get("service"),(String)params.get("port"),(String)params.get("url"));
return "";
}
@Override
public String doActionAfterCreation(Map<String, Object> params, Composite composite, Application application) {
String generatorId = (String)params.get("generator-id");
params.put("implementation", generatorsMap.get(generatorId).getCompositeLineImplementation((String)params.get("service")));
generatorsMap.get(generatorId).generate((String)params.get("userId"),(String)params.get("service"),(String)params.get("port"),(String)params.get("url"));
if("Java".equals(generatorId)){
this.rest.createNewImplementation((String)params.get("userId"), "component+proxy-"+application.getName(), (String)params.get("service")+".java", "Java", false);
}
else if("JavaScript".equals(generatorId)){
this.rest.createNewImplementation((String)params.get("userId"), "component+proxy-"+application.getName(), (String)params.get("service")+".js", "Script", false);
}
rest.addIntent(application, (String)params.get("userId"), "service+serviceProxy", "logging");
return "";
}
......
......@@ -77,7 +77,6 @@ public class CatalogServicesRestImpl implements CatalogServicesRest {
public String getCatalogServices(String socialNetwork) {
List<Publication> publications = this.catalogServices
.getPublications(socialNetwork);
System.out.println("nb publications : "+publications.size());
JSONObject publicationsJson = new JSONObject();
JSONArray publicationsTab = new JSONArray();
publicationsJson.put("publications", publicationsTab);
......@@ -95,7 +94,6 @@ public class CatalogServicesRestImpl implements CatalogServicesRest {
}
publicationsTab.add(publi);
}
System.out.println("parsing : " + publicationsJson.toJSONString());
return publicationsJson.toJSONString();
}
......@@ -151,7 +149,6 @@ public class CatalogServicesRestImpl implements CatalogServicesRest {
bindable.add(object);
}
}
System.out.println("bindable elements : "+bindable.toJSONString());
return bindable.toJSONString();
}
......
......@@ -594,9 +594,6 @@ public class RESTCallImpl implements RESTCall {
public void createNewImplementation(String userId, String elementId,
String className, String implemType, boolean createFile) {
try {
System.out.println("createNewImplementation# id : " + elementId
+ " className : " + className + " implemType : "
+ implemType);
LOG.info("createNewImplementation# id : " + elementId
+ " className : " + className + " implemType : "
+ implemType);
......@@ -718,20 +715,15 @@ public class RESTCallImpl implements RESTCall {
String choice) {
try {
elementId = URLDecoder.decode(elementId, "UTF-8");
System.out.println("createNewInterface# id : " + elementId
+ " className : " + className + " interfaceType : "
+ interfaceType);
LOG.info("createNewInterface# id : " + elementId + " className : "
+ className + " interfaceType : " + interfaceType);
EObject object = emfModelUtils.getComponent(userId, elementId);
System.out.println(object.eClass().toString());
boolean hasAPackage = false;
elementId = URLDecoder.decode(elementId, "UTF-8");
String classNameOrigin = className;
Interface interf = this.interfaces.createInterface(interfaceType);
String packageName = null;
if (interf instanceof JavaInterface) {
System.out.println("java interface created");
if (!"Use".equals(choice)) {
hasAPackage = true;
Application application = this.serviceManager
......@@ -764,8 +756,6 @@ public class RESTCallImpl implements RESTCall {
}
if (object instanceof ComponentService) {
System.out
.println("Addition of the interface on componentService");
ComponentService component = (ComponentService) object;
component.setInterface(interf);
}
......@@ -841,7 +831,6 @@ public class RESTCallImpl implements RESTCall {
javaImplem.getClass_()
.lastIndexOf(".") + 1)
+ ".java";
System.out.println("getIntentImplementation : " + url);
File intent = new File(url);
Scanner scanner = new Scanner(intent);
......@@ -860,9 +849,7 @@ public class RESTCallImpl implements RESTCall {
}
}
}
} else {
System.out.println("found application null");
}
}
return null;
}
......@@ -889,7 +876,6 @@ public class RESTCallImpl implements RESTCall {
javaImplem.getClass_()
.lastIndexOf(".") + 1)
+ ".java";
System.out.println("saveIntent : " + url);
File intent = new File(url);
FileWriter fw = new FileWriter(intent, false);
......@@ -901,8 +887,6 @@ public class RESTCallImpl implements RESTCall {
}
}
}
} else {
System.out.println("found application null");
}
}
}
......@@ -138,7 +138,6 @@ public class ServiceManagerImpl implements ServiceManager {
+ (String) params.get("compositeName")+ ".composite");
System.out.println("#Create application package name : "+packageName);
if(packageName != null && !packageName.equals("")){
packageName = packageName.replace(".", File.separator);
}
......@@ -164,7 +163,6 @@ public class ServiceManagerImpl implements ServiceManager {
File libDirectory = new File(application.retrieveAbsoluteRoot() + File.separator + "lib");
libDirectory.mkdir();
System.out.println("libDirectory========================================"+libDirectory.getPath());
membraneGeneration.addJavaSource(application.retrieveAbsoluteRoot() + File.separator + "src"
+ File.separator + "main" + File.separator + "java");
......@@ -314,7 +312,6 @@ public class ServiceManagerImpl implements ServiceManager {
String result = "";
try {
result = this.templates.doActionBeforeCreation(templateName, params);
System.out.println("doActionBeforeCreation result : "+result);
if(!result.isEmpty()){
return result;
}
......@@ -335,7 +332,6 @@ public class ServiceManagerImpl implements ServiceManager {
return result;
}
} catch (Exception e) {
System.out.println("ServiceManager throws an Exception");
throw e;
}
return result;
......@@ -381,7 +377,6 @@ public class ServiceManagerImpl implements ServiceManager {
File file = new File(preferences.getWorkspacePath() + File.separator + user.getWorkspaceUrl() + File.separator
+ name);
System.out.println("deleteApplication : "+file.getPath());
this.deleteDirectory(file);
entityManager.getTransaction().commit();
......@@ -581,7 +576,6 @@ public class ServiceManagerImpl implements ServiceManager {
}
private String searchInResources(String file, String resources) {
System.out.println(file);
File dir = new File(resources);
String[] packageItems = file.split("/");
if (packageItems.length > 0) {
......
......@@ -75,8 +75,6 @@ public class TemplateRestImpl implements TemplateRest {
map);
} catch (Exception e) {
e.printStackTrace();
System.out.println("TemplateRestImpl throws an Exception");
System.out.println("message : "+e.getMessage());
return e.getMessage();
}
}
......
......@@ -90,17 +90,13 @@ public class EMFModelUtilsImpl implements EMFModelUtils{
*/
public EObject getComponent(String userId, String elementId) {
System.out.println("\n\n\n elementID: "+ elementId + "\n\n\n");
try {
elementId = URLDecoder.decode(elementId, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
String[] ids = elementId.split(" ");
System.out.println("getComponent : idslength : "+ ids.length);
for(String idS : ids){
System.out.println(idS);
}
if (ids[ids.length - 1].contains("_")) {
ids[ids.length - 1] = ids[ids.length - 1].substring(0,
......@@ -163,7 +159,6 @@ public class EMFModelUtilsImpl implements EMFModelUtils{
if (componentService.getName().equals(ids[3])) {
// component name service name
if (ids.length == 4) {
System.out.println("return componentService");
return componentService;
}
// component name service name interface
......@@ -597,10 +592,8 @@ public class EMFModelUtilsImpl implements EMFModelUtils{
public Composite getIntentComposite(Application application, String compositeName){
try{
String location = this.preferences.getWorkspacePath()+File.separator+application.getResources()+File.separator+compositeName+".composite";
System.out.println("intent location : "+location);
location = location
.replaceAll(File.separator + File.separator, "/");
System.out.println("intent location 2 : "+location);
FrascatiClassLoader classLoader = new FrascatiClassLoader(this.classloaderManager.getClassLoader());
String sourceFile = null;
......
......@@ -108,11 +108,19 @@ function getActionMenu() {
}
function getGlobalId() {
console.log("getGlobalId");
var selectId = tree.getSelectedItemId();
var globalId = "";
while (selectId != "composite+") {
globalId = selectId + globalId;
selectId = tree.getParentId(selectId);
console.log("selectId : "+ selectId);
if(selectId != "composite+"){
while (selectId != "composite+") {
//console.log(selectId);
globalId = selectId + globalId;
selectId = tree.getParentId(selectId);
}
}
else{
globalId="composite+";
}
return globalId;
}
......
......@@ -42,9 +42,15 @@
var id = tree.getSelectedItemId();
var selectId = tree.getSelectedItemId();
var globalId = "";
while (selectId != "composite+") {
globalId = selectId + globalId;
selectId = tree.getParentId(selectId);
console.log(selectId);
if(selectId != "composite+"){
while (selectId != "composite+") {
globalId = selectId + globalId;
selectId = tree.getParentId(selectId);
}
}
else{
globalId="composite+";
}
if ((globalId.split("+").length == 3)
&& (globalId.split("+")[2].startsWith("implementation"))) {
......
......@@ -71,6 +71,7 @@
<reference name="preferences" target="Preferences/preferences" />
</component>
<wire source="ProxyWSTemplateAction/generators" target="CodeGeneratorWsdlToJS/codeGeneratorWsdlToJS" />
<wire source="ProxyWSLogTemplateAction/generators" target="CodeGeneratorWsdlToJS/codeGeneratorWsdlToJS" />
<component name="CodeGeneratorWsdlToJava">
<implementation.java class="org.easysoa.codegenerator.CodeGeneratorWsdlToJavaImpl" />
......@@ -89,6 +90,7 @@
<reference name="preferences" target="Preferences/preferences" />
</component>
<wire source="ProxyWSTemplateAction/generators" target="CodeGeneratorWsdlToJava/codeGeneratorWsdlToJava" />
<wire source="ProxyWSLogTemplateAction/generators" target="CodeGeneratorWsdlToJava/codeGeneratorWsdlToJava" />
<component name="Friends">
<implementation.java class="org.easysoa.impl.FriendsImpl" />
......@@ -559,7 +561,9 @@
<service name="template">
<interface.java interface="org.easysoa.api.TemplateActionItf" />