Import project web ui

Implements a page with a browse button to select a file to import.
Modifies CustomMenuControler to show the import option.

FEA: ItEr77S05BasicProjectImport
This commit is contained in:
Alba Carro 2012-08-24 23:54:31 +02:00 committed by Manuel Rego Casasnovas
parent 5ffdfeec20
commit 0d7c88f1cd
5 changed files with 151 additions and 0 deletions

View file

@ -448,5 +448,10 @@
<groupId>br.com.digilabs.jqplot</groupId> <groupId>br.com.digilabs.jqplot</groupId>
<artifactId>jqplot4java</artifactId> <artifactId>jqplot4java</artifactId>
</dependency> </dependency>
<!-- ZK fileupload -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

View file

@ -273,6 +273,9 @@ public class CustomMenuController extends Div implements IMenuItemsRegister {
globalView.goToOrdersList(); globalView.goToOrdersList();
} }
}, "01-introducion.html#id2")); }, "01-introducion.html#id2"));
// In order of see the Import project option in the menu
planningItems.add(subItem(_("Import project"),
"/orders/imports/projectImport.zul", ""));
} }
if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_PLANNING)) { if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_PLANNING)) {
planningItems.add(subItem(_("Resources Load"), new ICapture() { planningItems.add(subItem(_("Resources Load"), new ICapture() {

View file

@ -0,0 +1,95 @@
package org.libreplan.web.orders.imports;
import static org.libreplan.web.I18nHelper._;
import java.io.InputStream;
import org.libreplan.business.orders.imports.OrderImporter;
import org.libreplan.web.common.IMessagesForUser;
import org.libreplan.web.common.Level;
import org.libreplan.web.common.MessagesForUser;
import org.springframework.transaction.annotation.Transactional;
import org.zkoss.util.media.Media;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.GenericForwardComposer;
/**
* Controller for import projects
*
* @author Alba Carro Pérez <alba.carro@gmail.com>
*/
public class ProjectImportController extends GenericForwardComposer {
/**
* OrderImporter service.
*/
private OrderImporter orderImporterMPXJ;
private IMessagesForUser messages;
private Component messagesContainer;
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
comp.setAttribute("projectImportController", this);
messages = new MessagesForUser(messagesContainer);
}
/**
* Method called when the onUpload event happens.
*
* @param Media
* Media to be imported.
*/
public void importProject(Media media) {
String file = media.getName();
if (checkFileFormat(file)) {
importProject(media.getStreamData(), file);
messages.showMessage(Level.INFO, _(file + ": Import successfully!"));
} else {
messages.showMessage(Level.ERROR,
_("The only current suported formats are mpp and planner."));
}
}
/**
* Imports an InputStream.
*
* @param streamData
* InputStream with the data that is going to be imported.
* @param file
* Name of the file that we want to import.
* @return boolean True if the streamData was imported, false if not.
*/
@Transactional
private void importProject(InputStream streamData, String file) {
orderImporterMPXJ.storeOrder(orderImporterMPXJ
.convertImportDataToOrder(orderImporterMPXJ.getImportData(
streamData, file)));
}
/**
* Checks that the file has the correct format (.mpp or .planner).
*
* @param file
* Name of the file.
* @return boolean True if is correct, false if not.
*/
private boolean checkFileFormat(String file) {
if (file.matches("(?i).*mpp") | file.matches("(?i).*planner")) {
return true;
}
return false;
}
}

View file

@ -0,0 +1,42 @@
<!--
This file is part of LibrePlan
Copyright (C) 2010-2011 Wireless Galicia, S.L.
Copyright (C) 2012 Igalia, S.L.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<?page id="projectImport" title="${i18n:_('LibrePlan: Import Project')}"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<?init class="org.zkoss.zk.ui.util.Composition" arg0="/common/layout/template.zul"?>
<?link rel="shortcut icon" href="/common/img/favicon.ico" type="image/x-icon"?>
<?link rel="stylesheet" type="text/css" href="/common/css/libreplan.css"?>
<?link rel="stylesheet" type="text/css" href="/common/css/libreplan_zk.css"?>
<zk>
<window id="importProject" self="@{define(content)}"
apply="org.libreplan.web.orders.imports.ProjectImportController"
title="${i18n:_('Import Project')}">
<vbox id="messagesContainer" />
<hbox>
<button id="btnImportProject" label="${i18n:_('Upload Project')}" upload="true,maxsize=500" onUpload="projectImportController.importProject(event.getMedia())"/>
</hbox>
</window>
</zk>

View file

@ -761,6 +761,12 @@
<artifactId>mpxj</artifactId> <artifactId>mpxj</artifactId>
<version>4.3.0</version> <version>4.3.0</version>
</dependency> </dependency>
<!-- ZK fileupload -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.4</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>