- Create preferences site to be configured in each environment

- Create table and models related to preferences
- Change all the sources using the "Documents" directory, to use information from the preferences component
- Parameterize compile/deployment to use lib  classpath defined in preferences
parent aecbdcd0
......@@ -39,7 +39,7 @@
<groupId>org.easysoa</groupId>
<artifactId>frascati-studio</artifactId>
<name>EasySOASimplified</name>
<name>FraSCAti Studio</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
......
......@@ -161,6 +161,20 @@ CREATE TABLE IF NOT EXISTS `FriendRequest` (
-- --------------------------------------------------------
--
-- Structure de la table `Preference`
--
CREATE TABLE IF NOT EXISTS `Preference` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`value` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Structure de la table `Town`
--
......
......@@ -38,10 +38,11 @@ public interface CompilerItf {
/**
* Compile a SCA application
*
* @param root
* @param applicationName
* @param root - The complete application path
* @param applicationName - The application name
* @param libPath - Lib path used in application class path
* @return The contribution File (.zip) ready to deploy
*/
File compile(String root, String applicationName);
File compile(String root, String applicationName, String libPath);
}
......@@ -35,10 +35,29 @@ import org.easysoa.model.DeploymentLocation;
public interface DeployProcessorItf {
/**
* Retrieve the list of available deployments defined in src/main/resources/deploy.properties
*
* @return
*/
List<DeploymentLocation> getAvailableDeployments();
/**
* Deploy an <b>application</b> in all chosen servers
*
* @param ids - Array of Server URLs
* @param application - Application to be deployed
* @return Success (true) or Fail (false)
*/
boolean deploy(String ids[], Application application);
/**
* Undeploy an <b>application</b> in all chosen servers
*
* @param ids - Array of Server URLs
* @param application - Application to be undeployed
* @return Success (true) or Fail (false)
*/
boolean undeploy(String[] ids, Application application);
}
......@@ -37,13 +37,40 @@ import org.osoa.sca.annotations.Service;
@Service
public interface FileManager {
/**
* Save Composite file.
*
* @param compositeObject
* @param path
* @return success (true) or fail (false)
*/
boolean saveComposite(EObject compositeObject , String path);
/**
* Copy recursively all files in <b>sourceFile</b> from <b>sourcePath</b> to <b>targetPath</b>
* that respects the filter <b>fileFilter</b> (optional)
*
* @param sourceFile
* @param sourcePath
* @param targetPath
* @param fileFilter
*/
void copyFilesRecursively(File sourceFile, File sourcePath, File targetPath, FileFilter fileFilter);
/**
* Delete recursively all files in <b>src</b>
*
* @param src
*/
void deleteRecursively(File src);
/**
* Copy recursively all files in <b>sourceFile</b> from <b>sourcePath</b> to <b>targetPath</b>
*
* @param sourceFile
* @param sourcePath
* @param targetPath
*/
void copyFilesRecursively(File sourceFile, File sourcePath, File targetPath);
String getWorkspacePath();
}
/**
* 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: Antonio Souza Neto
*
* Contributor(s):
*
*/
package org.easysoa.api;
/**
* Initialize, manage and retrieve system preferences
*
*/
public interface PreferencesManagerItf {
/**
* Return workspacePath preference
*
* @return workspacePath
*/
String getWorkspacePath();
/**
* Return libPath preference
*
* @return libPath
*/
String getLibPath();
}
......@@ -38,10 +38,46 @@ import org.osoa.sca.annotations.Service;
@Service
public interface Users {
/**
* Connect to FraSCAti Studio
*
* @param username
* @param password
* @return Current user, or null if connection fails
*/
User connect(String username,String password);
/**
* Create new account with the given parameters
*
* @param login
* @param password
* @param confirmPassword
* @param mail
* @param name
* @param surname
* @param civility
* @param town
* @param country
* @param birthday
* @return
*/
User createAccount(String login, String password, String confirmPassword,
String mail, String name, String surname, String civility, String town, String country, String birthday);
User modifyInformations(User user);
/**
* Search User with the corresponding <b>id</b>
*
* @param id
* @return
*/
User searchUser(Long id);
/**
* Search User with the corresponding <b>idString</b>
*
* @param idString
* @return
*/
User searchUser(String idString);
}
......@@ -50,7 +50,7 @@ public class MavenCompilerImpl implements CompilerItf {
};
@Override
public File compile(String root, String applicationName) {
public File compile(String root, String applicationName, String libPath) {
try{
InvocationRequest request = new DefaultInvocationRequest();
request.setPomFile( new File( root+File.separator+"pom.xml" ) );
......
......@@ -69,7 +69,7 @@ public class SCAJavaCompilerImpl implements CompilerItf {
public void setFileManager(FileManager fileManager) {
this.fileManager = fileManager;
}
/*
* Properties
*
......@@ -122,13 +122,12 @@ public class SCAJavaCompilerImpl implements CompilerItf {
*/
@Override
public File compile(String root, String applicationName) {
public File compile(String root, String applicationName, String libPath) {
String srcPath = root+File.separator+ sourceDirectory;
String binPath = root+File.separator+ binDirectory;
fileManager.deleteRecursively(new File( binPath));
String libPath = fileManager.getWorkspacePath() + File.separator + "lib";
List<File> classPath = getClassPath( libPath);
if(compileAll(srcPath, binPath, classPath) == false){
......@@ -233,13 +232,6 @@ public class SCAJavaCompilerImpl implements CompilerItf {
System.out.println("Fail!");
for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics.getDiagnostics()) {
//It's Useful just for detailed tests
/*System.out.println(diagnostic.getCode());
System.out.println(diagnostic.getKind());
System.out.println(diagnostic.getPosition());
System.out.println(diagnostic.getStartPosition());
System.out.println(diagnostic.getEndPosition());
System.out.println(diagnostic.getSource());*/
System.out.println(diagnostic.getMessage(null));
}
} else {
......
......@@ -128,7 +128,7 @@ public class DeployProcessor implements DeployProcessorItf {
public boolean deploy(String[] ids, Application application) {
boolean deploymentResult = true;
File contribFile = scaCompiler.compile(application.getRoot(), application.getName());
File contribFile = scaCompiler.compile(application.getRoot(), application.getName(), application.getLibPath());
if (contribFile == null) {
Logger.getLogger("EasySOALogger").severe("No contribution file generated.");
......
......@@ -53,6 +53,7 @@ import org.easysoa.api.FileManager;
import org.easysoa.api.ImplementationsProcessorItf;
import org.easysoa.api.InterfaceProcessorItf;
import org.easysoa.api.ModelAccess;
import org.easysoa.api.PreferencesManagerItf;
import org.easysoa.api.Provider;
import org.easysoa.api.RESTCall;
import org.easysoa.api.ServiceManager;
......@@ -124,6 +125,8 @@ public class RESTCallImpl implements RESTCall {
protected DeploymentAccess deploymentAccess;
@Reference
protected ModelAccess modelAccess;
@Reference
protected PreferencesManagerItf preferences;
@Override
public String getCompositeTree(String userId) {
......@@ -1124,6 +1127,7 @@ public class RESTCallImpl implements RESTCall {
String[] idsTab = ids.split("<>");
Application application = serviceManager.getCurrentApplication(userId);
application.setLibPath(preferences.getLibPath());
boolean resultDeployment = this.deploy.deploy(idsTab, application);
......
......@@ -33,9 +33,9 @@ import java.util.logging.Logger;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import org.easysoa.api.FileManager;
import org.easysoa.api.Friends;
import org.easysoa.api.MailService;
import org.easysoa.api.PreferencesManagerItf;
import org.easysoa.api.Provider;
import org.easysoa.api.Users;
import org.easysoa.model.Civility;
......@@ -53,7 +53,7 @@ import org.osoa.sca.annotations.Scope;
public class UserImpl implements Users {
@Reference
public FileManager fileManager;
public PreferencesManagerItf preferences;
@Reference
public Provider<EntityManager> db;
@Reference
......@@ -110,25 +110,14 @@ public class UserImpl implements Users {
return null;
}
//mailService.sendMailAccountCreation(user);
//TODO - Send mail to user
User userx = em.find(User.class, user.getId());
return userx;
}
@Override
public User modifyInformations(User user) {
//TODO Doing nothing here...
//EntityManager em = db.get();
//em.getTransaction().begin();
//em.getTransaction().commit();
return user;
}
private void createWorkspace(User user) {
try{
String path = fileManager.getWorkspacePath();
String path = preferences.getWorkspacePath();
File space = new File(path);
if(!space.exists()){
space.mkdirs();
......
......@@ -32,7 +32,9 @@ import javax.persistence.EntityManager;
import org.easysoa.api.DeployProcessorItf;
import org.easysoa.api.DeploymentAccess;
import org.easysoa.api.PreferencesManagerItf;
import org.easysoa.api.Provider;
import org.easysoa.model.Application;
import org.easysoa.model.DeployedApplication;
import org.easysoa.model.DeploymentServer;
import org.json.simple.JSONArray;
......@@ -47,6 +49,8 @@ public class DeploymentAccessImpl implements DeploymentAccess{
protected Provider<EntityManager> db;
@Reference
protected DeployProcessorItf deploy;
@Reference
protected PreferencesManagerItf preferences;
@SuppressWarnings("unchecked")
@Override
......@@ -122,7 +126,8 @@ public class DeploymentAccessImpl implements DeploymentAccess{
DeploymentServer deploymentServer = this.getDeploymentServer(server);
for(DeployedApplication deployedApplication : deploymentServer.getDeployedApplications(em, deploymentServer)){
System.out.println("appName : "+deployedApplication.getApplication().getName());
Application application = new Application();
application.setLibPath(preferences.getLibPath());
deploy.deploy(new String[]{server}, deployedApplication.getApplication());
}
}
......
......@@ -76,7 +76,21 @@ public class Application
@XmlAttribute(name = "root", required = true)
protected String root;
/**
* This attribute is not saved in database.
* It's used only to inform where is the lib path used by this application
*/
protected String libPath;
public String getLibPath() {
return libPath;
}
public void setLibPath(String libPath) {
this.libPath = libPath;
}
public String getRoot() {
return root;
}
......
/**
* 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: Antonio Souza Neto
*
* Contributor(s):
*
*/
package org.easysoa.model;
import java.io.Serializable;
import java.util.logging.Logger;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NoResultException;
import javax.persistence.Query;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Preference")
@XmlRootElement(name = "Preference")
@Entity(name = "Preference")
public class Preference implements Serializable {
private static final long serialVersionUID = 1L;
@XmlAttribute(name = "id", required = true)
protected Integer id;
@XmlAttribute(name = "name", required = true)
protected String name;
@XmlAttribute(name = "value" , required = true)
protected String value;
/**
* Preference's Constructor
*
* @param name - The name identifying the preference
* @param value - Preference's value
*/
public Preference(String name, String value){
this.name = name;
this.value = value;
}
@Id @GeneratedValue(strategy=GenerationType.AUTO)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(unique = true, nullable = false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(nullable = false)
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
/**
* Retrieves the value of a preference
*
* @param em - The entity manager used to connect the database
* @param preferenceName - The name of the preference
* @return The preference value
*/
public static String searchPreference(EntityManager em, String preferenceName){
Query query = em
.createQuery("SELECT p.value FROM Preference p WHERE p.name = :name");
query.setParameter("name", preferenceName);
try{
String preferenceValue = (String)query.getSingleResult();
return preferenceValue;
}catch(NoResultException nre){
Logger.getLogger("EasySOALogger").severe("No preference found for " + preferenceName + "!" );
return null;
}catch(Exception e){
Logger.getLogger("EasySOALogger").severe("Error trying to retrive preference for " + preferenceName + "!" );
e.printStackTrace();
return null;
}
}
/**
* Update a preference with a new value
*
* @param em - The entity manager used to connect the database
* @param preferenceName - The name of the preference to be updated
* @param preferenceValue - The new preference value
*/
public static void updatePreferenceValue(EntityManager em, String preferenceName, String preferenceValue){
Query query = em
.createQuery("UPDATE Preference SET value = :value WHERE name = :name");
query.setParameter("name", preferenceName);
query.setParameter("value", preferenceValue);
try{
int updatedCount = query.executeUpdate();
Logger.getLogger("EasySOALogger").info(updatedCount + " records updated in Preference table." );
}catch(Exception e){
Logger.getLogger("EasySOALogger").severe("Error trying to update preference for " + preferenceName + "!" );
e.printStackTrace();
}
}
}
......@@ -49,24 +49,11 @@ import org.eclipse.stp.sca.Composite;
import org.eclipse.stp.sca.DocumentRoot;
import org.eclipse.stp.sca.ScaFactory;
import org.eclipse.stp.sca.util.ScaResourceFactoryImpl;
import org.osoa.sca.annotations.Property;
import org.osoa.sca.annotations.Scope;
@Scope("COMPOSITE")
public class FileManagerImpl implements FileManager {
@Property
private String workspacePath = System.getProperty("user.home")+File.separator+"Documents"+File.separator+"easysoawebsitesimplified";
@Override
public String getWorkspacePath() {
return workspacePath;
}
public void setWorkspacePath(String workspacePath) {
this.workspacePath = workspacePath;
}
@Override
public boolean saveComposite(EObject compositeObject, String path) {
......
/**
* 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: Antonio Souza Neto
*
* Contributor(s):
*
*/
package org.easysoa.utils;
import java.io.File;
import java.util.logging.Logger;
import javax.persistence.EntityManager;
import org.easysoa.api.PreferencesManagerItf;
import org.easysoa.api.Provider;
import org.easysoa.model.Preference;
import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Property;
import org.osoa.sca.annotations.Reference;
import org.osoa.sca.annotations.Scope;
@Scope("COMPOSITE")
public class PreferencesManager implements PreferencesManagerItf {
/* *********************************
*
* Properties and preferences names
*
* Each preference in database must to have a corresponding property
*
* *********************************/
private static final String WORKSPACE_PATH_NAME = "workspacePath";
private static final String LIB_PATH_NAME = "libPath";
@Property(required = true)
private String workspacePath = "";
@Property(required = true)
private String libPath = "";
@Override
public String getWorkspacePath() {
return workspacePath;
}
public void setWorkspacePath(String workspacePath) {
this.workspacePath = workspacePath;
}
@Override
public String getLibPath() {
return libPath;
}
public void setLibPath(String libPath) {
this.libPath = libPath;
}
/* ********************
* References
* ********************/
@Reference
protected Provider<EntityManager> db;
/* *********************
* Methods
* *********************/
/**
* Initialize the preferences retrieving from the database if exist. <br>
* If preferences don't exist, records in database will be created
* with default values
*
*/
@Init
public void initPreferences(){
EntityManager em = db.get();
String defaultWorkspacePath = System.getProperty("user.home")+File.separator+"Documents"+File.separator+"frascati-studio";
workspacePath = verifyPreference(em, WORKSPACE_PATH_NAME, defaultWorkspacePath);
String defaultLibPath = defaultWorkspacePath + File.separator+"lib";
libPath = verifyPreference(em, LIB_PATH_NAME, defaultLibPath);
}