Upload Resources:

- Creation of a table and component to manage file types and their locations
- Script to initialize this table
- Upload of resource files interface and component
- Compilation and contribution generation using user libraries
parent 6f80be58
......@@ -23,7 +23,7 @@
*
* Author: Michel Dirix
*
* Contributor(s): Antonio Souza Neto
* Contributor(s): Antonio de Almeida Souza Neto
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
......
INSERT INTO `FileType` (`id`, `name`, `location`) VALUES
(1, 'Library', '/lib');
......@@ -143,6 +143,20 @@ CREATE TABLE IF NOT EXISTS `DeploymentServer` (
-- --------------------------------------------------------
--
-- Structure de la table `FileType`
--
CREATE TABLE IF NOT EXISTS `FileType` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`location` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
-- --------------------------------------------------------
--
-- Structure de la table `FriendRequest`
......
......@@ -40,10 +40,11 @@ public interface CompilerItf {
*
* @param root - The complete application path
* @param applicationName - The application name
* @param libPath - Lib path used in application class path
* @param globalLibPath - Global Lib path used in application class path
* @param localLibPath - Local Lib path used in application class path
* @return The contribution File (.zip) ready to deploy
* @throws Exception
*/
File compile(String root, String applicationName, String libPath) throws Exception;
File compile(String root, String applicationName, String globalLibPath, String localLibPath) throws Exception;
}
......@@ -20,19 +20,31 @@
*
* Contact: frascati@ow2.org
*
* Author: Michel Dirix
* Author: Antonio de Almeida Souza Neto
*
* Contributor(s):
* Contributor(s):
*
*/
package org.easysoa.api;
import org.osoa.sca.annotations.Service;
import java.util.List;
@Service
public interface Uploader {
public interface FileTypesManagerItf {
void upload(String fileName);
/**
* Return all available File Types (Ex. library, css, js, executable etc.)
*
* @return List of File Types
*/
List<String> getAllFileTypes();
/**
* Return the file type location corresponding to fileTypeName
*
* @param fileTypeName
* @return the file type location
*/
String getLocationFileType(String fileTypeName);
}
......@@ -52,7 +52,7 @@ public class MavenCompilerImpl implements CompilerItf {
};
@Override
public File compile(String root, String applicationName, String libPath) {
public File compile(String root, String applicationName, String libPath, String localLibPath) {
try{
InvocationRequest request = new DefaultInvocationRequest();
request.setPomFile( new File( root+File.separator+"pom.xml" ) );
......
......@@ -20,7 +20,7 @@
*
* Contact: frascati@ow2.org
*
* Author: Antonio Souza Neto
* Author: Antonio de Almeida Souza Neto
*
* Contributor(s):
*
......@@ -78,6 +78,7 @@ public class SCAJavaCompilerImpl implements CompilerItf {
@Reference
protected FileManager fileManager;
/*
* Properties
......@@ -128,13 +129,26 @@ public class SCAJavaCompilerImpl implements CompilerItf {
*/
@Override
public File compile(String root, String applicationName, String libPath) throws Exception {
public File compile(String root, String applicationName, String globalLibPath, String localLibPath) throws Exception {
String srcPath = root+File.separator+ sourceDirectory;
String binPath = root+File.separator+ binDirectory;
fileManager.deleteRecursively(new File( binPath));
List<File> classPath = getClassPath( libPath);
List<File> classPath = new ArrayList<File>();
List<File> jarLocalLib = new ArrayList<File>();
//add jars from the global class path
if (globalLibPath != null && !"".equals(globalLibPath)) {
classPath.addAll(getClassPath(globalLibPath));
}
if (localLibPath != null && !"".equals(localLibPath)) {
jarLocalLib = getClassPath(localLibPath);
//add jars from the local class path
classPath.addAll(jarLocalLib);
}
if(compileAll(srcPath, binPath, classPath) == false){
return null;
......@@ -151,7 +165,7 @@ public class SCAJavaCompilerImpl implements CompilerItf {
jarGenerated = JarGenerator.generateJarFromAll(binPath, binPath + File.separator + ".." + File.separator + applicationName + ".jar");
return generateContribution(applicationName, binPath, jarGenerated);
return generateContribution(applicationName, binPath, jarGenerated, jarLocalLib);
}
......@@ -295,9 +309,10 @@ public class SCAJavaCompilerImpl implements CompilerItf {
private File generateContribution(String applicationName, String binPath, File jarGenerated) {
private File generateContribution(String applicationName, String binPath, File jarGenerated, List<File> localJarLib) {
Collection<File> jars = new ArrayList<File>();
jars.add(jarGenerated);
jars.addAll(localJarLib);
Collection<String> deployables = new ArrayList<String>();
deployables.add(applicationName + ".composite");
......
......@@ -22,7 +22,7 @@
*
* Author: Michel Dirix
*
* Contributor(s): Antonio Souza Neto
* Contributor(s): Antonio de Almeida Souza Neto
*
*/
......@@ -133,7 +133,7 @@ public class DeployProcessor implements DeployProcessorItf {
public boolean deploy(String[] ids, Application application) throws Exception {
boolean deploymentResult = true;
File contribFile = scaCompiler.compile(application.retrieveAbsoluteRoot(), application.getName(), application.getLibPath());
File contribFile = scaCompiler.compile(application.retrieveAbsoluteRoot(), application.getName(), application.getGlobalLibPath(), application.getLocalLibPath());
if (contribFile == null) {
throw new Exception("No contribution file generated.");
......
......@@ -22,7 +22,7 @@
*
* Author: Michel Dirix
*
* Contributor(s): Antonio Souza Neto
* Contributor(s): Antonio de Almeida Souza Neto
*
*/
package org.easysoa.impl;
......@@ -36,6 +36,7 @@ import javax.persistence.EntityManager;
import org.easysoa.api.DeployProcessorItf;
import org.easysoa.api.DeploymentAccess;
import org.easysoa.api.DeploymentRest;
import org.easysoa.api.FileTypesManagerItf;
import org.easysoa.api.PreferencesManagerItf;
import org.easysoa.api.Provider;
import org.easysoa.api.ServiceManager;
......@@ -57,6 +58,8 @@ public class DeploymentRestImpl implements DeploymentRest {
protected Provider<EntityManager> database;
@Reference
protected PreferencesManagerItf preferences;
@Reference
protected FileTypesManagerItf fileTypesManager;
/** Logger */
public final static Logger LOG = Logger.getLogger(DeploymentRestImpl.class.getCanonicalName());
......@@ -70,7 +73,8 @@ public class DeploymentRestImpl implements DeploymentRest {
if(application != null){
System.out.println();
}
application.setLibPath(preferences.getLibPath());
application.setGlobalLibPath(preferences.getLibPath());
application.setLocalLibPath(application.retrieveAbsoluteRoot() + fileTypesManager.getLocationFileType("Library"));
application.setCurrentWorskpacePath(preferences.getWorkspacePath());
boolean resultDeployment;
......
......@@ -58,9 +58,6 @@ public class StudioGUIRestImpl implements StudioGUIRest {
@Override
public synchronized String getComponentMenu(String userId, String elementId) {
System.out.println("getComponentMenu ElementId: " + elementId);
return this.processor.getActionMenu(emfModelUtils.getComponent(userId, elementId));
}
}
......@@ -19,9 +19,9 @@
*
* Contact: frascati@ow2.org
*
* Author: Philippe Merle
* Author: Michel Dirix
*
* Contributor(s): Antonio Souza Neto
* Contributor(s): Antonio de Almeida Souza Neto
*
*/
......@@ -41,6 +41,7 @@ import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.easysoa.api.FileTypesManagerItf;
import org.easysoa.api.PreferencesManagerItf;
import org.easysoa.api.ServiceManager;
import org.easysoa.model.Application;
......@@ -48,12 +49,7 @@ import org.oasisopen.sca.annotation.Reference;
import org.oasisopen.sca.annotation.Scope;
import org.osoa.sca.annotations.Service;
/**
* OW2 FraSCAti Web Explorer Uploader component implementation.
*
* @author <a href="mailto:philippe.merle@inria.fr">Philippe Merle</a>
* @version 1.5
*/
@Scope("COMPOSITE")
@Service(Servlet.class)
public class UploaderImpl extends HttpServlet {
......@@ -72,6 +68,8 @@ public class UploaderImpl extends HttpServlet {
protected ServiceManager serviceManager;
@Reference
protected PreferencesManagerItf preferences;
@Reference
protected FileTypesManagerItf fileTypesManager;
// ---------------------------------------------------------------------------
// Internal methods.
......@@ -80,55 +78,83 @@ public class UploaderImpl extends HttpServlet {
/**
* @see HttpServlet#service(HttpServletRequest, HttpServletResponse)
*/
@SuppressWarnings("unchecked")
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
if (ServletFileUpload.isMultipartContent(request)) {
ServletFileUpload servletFileUpload = new ServletFileUpload(
new DiskFileItemFactory());
List<FileItem> fileItemList = null;
try {
throws ServletException, IOException {
if(ServletFileUpload.isMultipartContent(request)) {
ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
List<FileItem> fileItemList = null;
try {
fileItemList = servletFileUpload.parseRequest(request);
} catch(FileUploadException fue) {
} catch(FileUploadException fue) {
throw new ServletException(fue);
}
String userId = null;
String componentType = null;
for(FileItem fileItem : fileItemList) {
if("componentType".equals(fileItem.getFieldName())) {
componentType = fileItem.getString();
}
if("userIdForm".equals(fileItem.getFieldName())){
userId = fileItem.getString();
}
}
String locationComponentType = null;
if("implementation".equals(componentType)){
locationComponentType = "impl";
}
else if("interface".equals(componentType)){
locationComponentType = "api";
}
}
String userId = null;
String componentType = null;
String fileType = null;
for(FileItem fileItem : fileItemList) {
if("componentType".equals(fileItem.getFieldName())) {
componentType = fileItem.getString();
}
if("userIdForm".equals(fileItem.getFieldName())){
userId = fileItem.getString();
}
if ("file-type".equals(fileItem.getFieldName())){
fileType = fileItem.getString();
}
}
boolean resource = false;
//TODO Refactoring - Change name from componentType to UploadType
String locationComponentType = null;
if("implementation".equals(componentType)){
locationComponentType = "impl";
}
else if("interface".equals(componentType)){
locationComponentType = "api";
}else if ("resource".equals(componentType)) {
resource = true;
if("Library".equals(fileType)){
locationComponentType = fileTypesManager.getLocationFileType("Library");
}
}
File saveTo = null;
for(FileItem fileItem : fileItemList) {
File saveTo = null;
for(FileItem fileItem : fileItemList) {
if((fileItem.getFieldName().equals("filename") || fileItem.getFieldName().equals("filenameUploadInterface"))
&& fileItem.getSize() > 0) {
Application application = serviceManager.getCurrentApplication(userId);
application.setCurrentWorskpacePath(preferences.getWorkspacePath());
saveTo = new File(application.retrieveAbsoluteSources()+File.separator+locationComponentType+File.separator+fileItem.getName());
String dirPath;
if (resource) {
dirPath = application.retrieveAbsoluteRoot()+locationComponentType;
}else{
dirPath = application.retrieveAbsoluteSources()+File.separator+locationComponentType;
}
File directory = new File(dirPath);
if ( ! directory.exists()) {
directory.mkdirs();
}
saveTo = new File(dirPath+File.separator+fileItem.getName());
try {
fileItem.write(saveTo);
fileItem.write(saveTo);
} catch(Exception e) {
throw new ServletException(e);
throw new ServletException(e);
}
}
}
}
}
}
}
}
......@@ -20,7 +20,7 @@
*
* Author: Michel Dirix
*
* Contributor(s): Antonio Souza Neto
* Contributor(s): Antonio de Almeida Souza Neto
*
*/
package org.easysoa.jpa;
......@@ -32,6 +32,7 @@ import javax.persistence.EntityManager;
import org.easysoa.api.DeployProcessorItf;
import org.easysoa.api.DeploymentAccess;
import org.easysoa.api.FileTypesManagerItf;
import org.easysoa.api.PreferencesManagerItf;
import org.easysoa.api.Provider;
import org.easysoa.model.Application;
......@@ -51,6 +52,8 @@ public class DeploymentAccessImpl implements DeploymentAccess{
protected DeployProcessorItf deploy;
@Reference
protected PreferencesManagerItf preferences;
@Reference
protected FileTypesManagerItf fileTypesManager;
/** Logger */
public final static Logger LOG = Logger.getLogger(DeploymentAccessImpl.class.getCanonicalName());
......@@ -129,7 +132,8 @@ public class DeploymentAccessImpl implements DeploymentAccess{
DeploymentServer deploymentServer = this.getDeploymentServer(server);
for(DeployedApplication deployedApplication : deploymentServer.getDeployedApplications(entityManager, deploymentServer)){
Application application = new Application();
application.setLibPath(preferences.getLibPath());
application.setGlobalLibPath(preferences.getLibPath());
application.setLocalLibPath(application.retrieveAbsoluteRoot() + fileTypesManager.getLocationFileType("Library"));
application.setCurrentWorskpacePath(preferences.getWorkspacePath());
deploy.deploy(new String[]{server}, deployedApplication.getApplication());
}
......
......@@ -22,7 +22,7 @@
*
* Author: Michel Dirix
*
* Contributor(s): Antonio Souza Neto
* Contributor(s): Antonio de Almeida Souza Neto
*
*/
package org.easysoa.model;
......@@ -84,22 +84,42 @@ public class Application
/**
* This attribute is not saved in database.
* It's used only to inform where is the lib path used by this application
* It's used only to inform where is the global lib path used by this application
*/
protected String libPath = "";
protected String globalLibPath = "";
@Transient
public String getLibPath() {
if (libPath.equals("") ) {
LOG.warning("Lib Path is not defined for the application " + name);
public String getGlobalLibPath() {
if (globalLibPath.equals("") ) {
LOG.warning("Global Lib Path is not defined for the application " + name);
return "";
}else{
return libPath + File.separator;
return globalLibPath + File.separator;
}
}
public void setLibPath(String libPath) {
this.libPath = libPath;
public void setGlobalLibPath(String globalLibPath) {
this.globalLibPath = globalLibPath;
}
/**
* This attribute is not saved in database.
* It's used only to inform where is the local lib path used by this application
*/
protected String localLibPath = "";
@Transient
public String getLocalLibPath() {
if (localLibPath.equals("") ) {
LOG.warning("Local Lib Path is not defined for the application " + name);
return "";
}else{
return localLibPath + File.separator;
}
}
public void setLocalLibPath(String localLibPath) {
this.localLibPath = localLibPath;
}
/**
......
/**
* 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 de Almeida Souza Neto
*
* Contributor(s):
*
*/
package org.easysoa.model;
import java.io.Serializable;
import java.util.List;
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;
/**
* This table contains informations related to filename extensions.<br>
* The location field refers to the relative location where these kind of files
* will be saved or created for example.
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "FileType")
@XmlRootElement(name = "FileType")
@Entity(name = "FileType")
public class FileType 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 = "location" , required = true)
protected String location;
/** Logger */
public final static Logger LOG = Logger.getLogger(FileType.class.getCanonicalName());
/**
* FileType's Constructor
*
* @param name - The name identifying the preference
* @param location - Upload location for this type
*/
public FileType(String name, String location){
this.name = name;
this.location = location;
}
@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 getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
/**
* Retrieve all the file type names available in FileType table
*
* @param entityManager
* @return
*/
@SuppressWarnings("unchecked")
public static List<String> retrieveAllFileTypes(EntityManager entityManager){
Query query = entityManager
.createQuery("SELECT fileType.name FROM FileType fileType");
try{
List<String> fileTypes = query.getResultList();
return fileTypes;
}catch(Exception e){
LOG.severe("Error trying to retrive file types!" );
e.printStackTrace();
return null;
}
}
/**
* Return the file type location corresponding to fileTypeName
*
* @param entityManager
* @param fileTypeName
* @return the corresponding location
*/
public static String retrieveLocationFileType(EntityManager entityManager, String fileTypeName){
Query query = entityManager
.createQuery("SELECT fileType.location FROM FileType fileType WHERE fileType.name = :fileType");
query.setParameter("fileType", fileTypeName);
try{
String location = (String) query.getSingleResult();
return location;
}catch(NoResultException nre){
LOG.severe("No result found for " + fileTypeName + " file type!" );
return null;
}catch(Exception e){
LOG.severe("Error trying to retrive " +fileTypeName + " file type!" );
e.printStackTrace();
return null;
}
}
}
......@@ -20,7 +20,7 @@
*
* Contact: frascati@ow2.org
*
* Author: Antonio Souza Neto
* Author: Antonio de Almeida Souza Neto
*
* Contributor(s):
*
......
......@@ -22,7 +22,7 @@
*
* Author: Michel Dirix
*
* Contributor(s):
* Contributor(s): Antonio de Almeida Souza Neto
*
*/
package org.easysoa.processor;
......@@ -119,6 +119,7 @@ public class CompositeProcessor implements ComplexProcessorItf {
stringBuffer.append("<div id=\"save\" img=\"filesave.png\" text=\"Save\"><hotkey>Ctrl+S</hotkey><hotkey>Cmd+S</hotkey></div>");
stringBuffer.append("<div id=\"deploy\" text=\"Deploy\"></div>");
stringBuffer.append("<div id=\"undeploy\" text=\"Undeploy\"></div>");
stringBuffer.append("<div id=\"upload\" text=\"Upload\"></div>");
return stringBuffer.toString();
}
......
/**
* 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