Commit 122fd8c4 authored by Michel Dirix's avatar Michel Dirix

- BasicService template

- Beginning of ProxyWsLog template
- CatalogServices based on FrascatiStudio facebook page
parent db184f3c
......@@ -66,12 +66,6 @@
<hibernate.connection.url>jdbc:mysql://localhost:3306/easysoasimplified</hibernate.connection.url>
<hibernate.connection.username>root</hibernate.connection.username>
<hibernate.connection.password></hibernate.connection.password>
<!-- <hibernate.connection.url>jdbc:mysql://mysql-studio-frascati.jelastic.com/easysoa?autoReconnect=true</hibernate.connection.url> -->
<!-- <hibernate.connection.username>root</hibernate.connection.username> -->
<!-- <hibernate.connection.password></hibernate.connection.password> -->
<!-- <hibernate.connection.url>jdbc:mysql://mysql-stutio-frascati-dev.jelastic.dogado.eu/studio?autoReconnect=true</hibernate.connection.url> -->
<!-- <hibernate.connection.username>root</hibernate.connection.username> -->
<!-- <hibernate.connection.password></hibernate.connection.password> -->
</properties>
......@@ -248,6 +242,11 @@
<!-- Dependencies -->
<!-- ============ -->
<dependencies>
<dependency>
<groupId>org.ow2.frascati.tinfi</groupId>
<artifactId>frascati-tinfi-runtime-api</artifactId>
<version>1.4.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
......@@ -356,8 +355,9 @@
<artifactId>frascati-binding-ws</artifactId>
<version>${frascati.version}</version>
</dependency>
</dependencies>
<!-- ======== -->
......
/**
* EasySOA
*
* Copyright (C) 2011-2012 Inria, University of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* Contact: frascati@ow2.org
*
* Author: Michel Dirix
*
* Contributor(s):
*
*/
package org.easysoa.api;
import java.util.List;
import org.easysoa.model.Publication;
import org.osoa.sca.annotations.Service;
@Service
public interface CatalogServicesProcessorItf {
/**
* Get all the publications on a social network
* @param networkId
* @return list of publication
*/
List<Publication> getPublications(String networkId);
void publish(String message, String networkId);
}
/**
* EasySOA
*
* Copyright (C) 2011-2012 Inria, University of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* Contact: frascati@ow2.org
*
* Author: Michel Dirix
*
* Contributor(s):
*
*/
package org.easysoa.api;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.osoa.sca.annotations.Service;
@Service
public interface CatalogServicesRest {
/**
* Gives all messages posted on the socialNetwork (Publication object)
* @param socialNetwork
* @return json which reprensents a list of Publication
*/
@GET
@Path("/catalogServices")
@Produces("text/plain")
String getCatalogServices(@FormParam("socialNetwork") String socialNetwork);
/**
* Gives all the elements of the composite where a binding can be added
* @return json which reprensents the bindable elements
*/
@GET
@Path("/bindableElements")
@Produces("text/plain")
String getBindableElements(@FormParam("userId")String userId);
/**
* Share the application manipulated by the user in the services catalog identified by networkId
* @param userId
* @param socialNetwork
*/
@POST
@Path("/share")
@Produces("text/plain")
void share(@FormParam("userId")String userId, @FormParam("socialNetwork") String socialNetwork, @FormParam("urls") String urls);
}
......@@ -32,10 +32,6 @@ import java.util.Map;
import org.osoa.sca.annotations.Service;
/**
*
* @author Michel Dirix
*/
@Service
public interface CompositeTemplateItf {
......
......@@ -76,4 +76,12 @@ public interface EMFModelUtils {
* @return true if an interface exists, false otherwise
*/
boolean hasAnInterface(String userId, String elementId);
/**
* Add an intent on the element identified by the id
* @param userId the userId to get the model he's manipulating
* @param elementId the id of the element where the addition is done
* @param intentName the intent's name
*/
EObject addIntent(String userId, String elementId, String intentName);
}
/**
* EasySOA
*
* Copyright (C) 2011-2012 Inria, University of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* Contact: frascati@ow2.org
*
* Author: Michel Dirix
*
* Contributor(s): Antonio Souza Neto
*
*/
package org.easysoa.api;
import org.easysoa.model.Application;
public interface IntentManager {
/**
* initialize files for the intent (composite and implementation)
* @param application concerned application
* @param intentName intent name
*/
void initIntent(Application application, String intentName);
}
/**
* EasySOA
*
* Copyright (C) 2011-2012 Inria, University of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* Contact: frascati@ow2.org
*
* Author: Michel Dirix
*
* Contributor(s):
*
*/
package org.easysoa.api;
import org.osoa.sca.annotations.Service;
@Service
public interface IntentTemplateItf {
String getIntentComposite();
String getIntentImpl();
String getIntentLoggingItf();
}
......@@ -34,6 +34,7 @@ import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.easysoa.model.Application;
import org.osoa.sca.annotations.Service;
......@@ -99,7 +100,7 @@ public interface RESTCall {
@POST
@Path("/createNewBinding")
@Produces("text/plain")
void createNewBinding(@FormParam("userId")String userId, @FormParam("elementId")String elementId, @FormParam("bindingType")String bindingType);
void createNewBinding(@FormParam("userId")String userId, @FormParam("elementId")String elementId, @FormParam("bindingType")String bindingType, @FormParam("uri")String bindingUri);
@GET
@Path("/isExistingTown")
......@@ -115,4 +116,9 @@ public interface RESTCall {
@Path("/hasExistingInterface")
@Produces("text/plain")
boolean hasAnExistingInterface(@FormParam("userId")String userId,@FormParam("elementId")String elementId);
@POST
@Path("/addIntent")
@Produces("text/plain")
void addIntent(@FormParam("application")Application application,@FormParam("userId")String userId, @FormParam("elementId")String elementId, @FormParam("intentName")String intentName);
}
......@@ -36,10 +36,7 @@ import org.easysoa.model.User;
import org.eclipse.stp.sca.Composite;
import org.osoa.sca.annotations.Service;
/**
*
* @author dirix
*/
@Service
public interface ServiceManager {
......
/**
* EasySOA
*
* Copyright (C) 2011-2012 Inria, University of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* Contact: frascati@ow2.org
*
* Author: Michel Dirix
*
* Contributor(s):
*
*/
package org.easysoa.catalog;
import java.util.List;
import java.util.Properties;
import org.easysoa.model.Publication;
import org.osoa.sca.annotations.Service;
@Service
public interface CatalogServicesItf {
String getId();
/**
* Get all the publications
* @return list of publication
*/
List<Publication> getPublications(Properties properties);
/**
* Publish a message on a network
* @param message
*/
void publish(String message, Properties properties);
}
/**
* EasySOA
*
* Copyright (C) 2011-2012 Inria, University of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* Contact: frascati@ow2.org
*
* Author: Michel Dirix
*
* Contributor(s):
*
*/
package org.easysoa.catalog;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.easysoa.api.CatalogServicesProcessorItf;
import org.easysoa.deploy.DeployProcessor;
import org.easysoa.model.Publication;
import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Reference;
import org.osoa.sca.annotations.Scope;
@Scope("Composite")
public class CatalogServicesProcessor implements CatalogServicesProcessorItf {
@Reference
protected List<CatalogServicesItf> catalog;
protected Map<String, CatalogServicesItf> catalogMap;
protected Properties properties;
@Init
public final void initializeProcessorsByID() {
this.catalogMap = new HashMap<String, CatalogServicesItf>();
for (CatalogServicesItf catalogService : this.catalog) {
this.catalogMap.put(catalogService.getId(), catalogService);
}
this.properties = new Properties();
InputStream inputStream = DeployProcessor.class
.getResourceAsStream("/properties/social.properties");
try {
this.properties.load(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public List<Publication> getPublications(String networkId) {
return this.catalogMap.get(networkId).getPublications(properties);
}
@Override
public void publish(String message, String networkId) {
this.catalogMap.get(networkId).publish(message, properties);
}
}
/**
* EasySOA
*
* Copyright (C) 2011-2012 Inria, University of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* Contact: frascati@ow2.org
*
* Author: Michel Dirix
*
* Contributor(s):
*
*/
package org.easysoa.catalog;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.Scanner;
import org.easysoa.deploy.DeployProcessor;
import org.easysoa.model.Publication;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.scribe.builder.ServiceBuilder;
import org.scribe.builder.api.FacebookApi;
import org.scribe.model.OAuthRequest;
import org.scribe.model.Response;
import org.scribe.model.Token;
import org.scribe.model.Verb;
import org.scribe.oauth.OAuthService;
public class FacebookCatalogServices implements CatalogServicesItf {
private final static String SCOPE = "publish_actions,publish_stream,status_update";
@Override
public String getId() {
return "Facebook";
}
@Override
public List<Publication> getPublications(Properties properties) {
try {
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"));
OAuthRequest request = new OAuthRequest(Verb.GET,
"https://graph.facebook.com/"
+ properties.getProperty("idPageFBK") + "/feed");
service.signRequest(accessToken, request);
Response response = request.send();
return this.parse(response.getBody());
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private ArrayList<Publication> parse(String json) throws JSONException {
System.out.println("parsing : " + json);
ArrayList<Publication> publications = new ArrayList<Publication>();
JSONObject jsonObjet = new JSONObject(json);
System.out.println(jsonObjet.getString("data").length());
if (jsonObjet.has("data")) {
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) {
String date = j.getString("created_time");
String message = j.getString("message");
Publication p = getPublication(date, message);
publications.add(p);
}
}
}
return publications;
}
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 = "";
boolean getHttp = false;
while (in.hasNext()) {
if (txt.startsWith("-")) {
http.add(txt.substring(1));
getHttp = true;
} else if (getHttp == true) {
description += txt;
if (in.hasNextLine()) {
description += in.nextLine();
}
}
if(in.hasNext()){
txt = in.next();
}
}
return new Publication(date, name, description, http);
}
@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){
e.printStackTrace();
}
}
public static void main(String[] args) {
Properties properties = new Properties();
InputStream inputStream = DeployProcessor.class
.getResourceAsStream("/properties/social.properties");
try {
properties.load(inputStream);
FacebookCatalogServices fb = new FacebookCatalogServices();
//fb.publish("test has published\n-http://localhost:8095/ipLocalization\nlocalize you by your ip", properties);
List<Publication> publis = fb.getPublications(properties);
System.out.println("url####");
for(Publication pub : publis){
for(String url : pub.getUrls()){
System.out.println(url);
}
}
System.out.println(publis.size());
} catch (IOException e) {
e.printStackTrace();
}
}
}
......@@ -86,8 +86,9 @@ public class TemplateActionBasicService implements TemplateActionItf {
this.rest.addElement(userId, "", "addComponent");
this.rest.addElement(userId, "component+name", "addComponentService");
this.rest.addElement(userId, "", "addService");
this.rest.createNewBinding(userId, "service+name", bindingType);
this.rest.createNewBinding(userId, "service+name", bindingType,"");
this.rest.createNewInterface(userId, "component+name+service+name", interfaceName, interfaceType, true, "New");
this.rest.createNewInterface(userId, "service+name", "org.ow2.frascati.api."+interfaceName.substring(0, interfaceName.indexOf(".")), interfaceType, false, "Use");
this.rest.createNewImplementation(userId, "component+name", className, implemType, true);
File interfaceFile = new File(preferences.getWorkspacePath()+ File.separator + application.getSources() + File.separator + "api" + File.separator + interfaceName);
File implementationFile = new File(preferences.getWorkspacePath()+ File.separator + application.getSources() + File.separator + "impl" + File.separator + className);
......
/**
* EasySOA
*
* Copyright (C) 2011-2012 Inria, University of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* Contact: frascati@ow2.org
*
* Author: Michel Dirix
*
* Contributor(s): Antonio Souza Neto
*
*/
package org.easysoa.compositeTemplates;
import java.util.Map;
import org.easysoa.api.CodeGenerator;
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.Reference;
public class TemplateActionProxyWSLog implements TemplateActionItf {
@Reference
protected CodeGenerator wsdlGenerator;
@Reference
protected RESTCall rest;