2013-02-06 23:25:43 +01:00
|
|
|
package org.gcube.portlets.user.reportgenerator.server.servlet;
|
|
|
|
|
|
|
|
import java.io.BufferedInputStream;
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.ObjectInputStream;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
2013-11-13 18:56:13 +01:00
|
|
|
import java.util.Random;
|
2013-11-07 19:00:34 +01:00
|
|
|
import java.util.UUID;
|
2013-02-06 23:25:43 +01:00
|
|
|
import java.util.Vector;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpSession;
|
2013-04-29 17:27:29 +02:00
|
|
|
import javax.xml.bind.DatatypeConverter;
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
import net.sf.csv4j.CSVFileProcessor;
|
|
|
|
import net.sf.csv4j.CSVLineProcessor;
|
|
|
|
import net.sf.csv4j.ParseException;
|
|
|
|
import net.sf.csv4j.ProcessingException;
|
|
|
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
import org.gcube.application.framework.accesslogger.library.impl.AccessLogger;
|
|
|
|
import org.gcube.application.framework.core.session.ASLSession;
|
|
|
|
import org.gcube.application.framework.core.session.SessionManager;
|
2013-11-25 17:12:01 +01:00
|
|
|
import org.gcube.application.reporting.Property;
|
2013-11-13 18:56:13 +01:00
|
|
|
import org.gcube.application.reporting.ReportsModeler;
|
2013-11-22 18:28:12 +01:00
|
|
|
import org.gcube.application.reporting.component.Heading;
|
|
|
|
import org.gcube.application.reporting.component.Instruction;
|
|
|
|
import org.gcube.application.reporting.component.ReportSequence;
|
|
|
|
import org.gcube.application.reporting.component.TextInput;
|
|
|
|
import org.gcube.application.reporting.component.Title;
|
2013-11-25 17:12:01 +01:00
|
|
|
import org.gcube.application.reporting.component.interfaces.ReportComponent;
|
2013-11-22 18:28:12 +01:00
|
|
|
import org.gcube.application.reporting.reference.Column;
|
2013-11-14 16:26:26 +01:00
|
|
|
import org.gcube.application.reporting.reference.DBTableRow;
|
2013-11-18 18:25:49 +01:00
|
|
|
import org.gcube.application.reporting.reference.ReferenceReport;
|
2013-11-14 16:26:26 +01:00
|
|
|
import org.gcube.application.reporting.reference.ReferenceReportType;
|
2013-11-22 18:28:12 +01:00
|
|
|
import org.gcube.application.rsg.service.dto.NameValue;
|
2013-11-13 18:56:13 +01:00
|
|
|
import org.gcube.application.rsg.service.dto.ReportEntry;
|
|
|
|
import org.gcube.application.rsg.service.dto.ReportType;
|
2013-02-06 23:25:43 +01:00
|
|
|
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
|
|
|
|
import org.gcube.applicationsupportlayer.social.NotificationsManager;
|
2013-10-09 14:21:50 +02:00
|
|
|
import org.gcube.common.homelibrary.home.HomeLibrary;
|
|
|
|
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
|
|
|
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.WorkspaceItemType;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.folder.FolderItemType;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalImage;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.folder.items.Report;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.folder.items.ReportTemplate;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.folder.items.gcube.ImageDocument;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.folder.items.ts.TimeSeries;
|
2013-03-05 15:26:22 +01:00
|
|
|
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
|
2013-02-06 23:25:43 +01:00
|
|
|
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
|
|
|
import org.gcube.portlets.admin.wfdocslibrary.client.WfDocsLibrary;
|
|
|
|
import org.gcube.portlets.admin.wfdocslibrary.server.db.MyDerbyStore;
|
|
|
|
import org.gcube.portlets.admin.wfdocslibrary.server.db.Store;
|
|
|
|
import org.gcube.portlets.d4sreporting.common.server.ServiceUtil;
|
2013-03-01 19:42:50 +01:00
|
|
|
import org.gcube.portlets.d4sreporting.common.shared.BasicComponent;
|
|
|
|
import org.gcube.portlets.d4sreporting.common.shared.BasicSection;
|
2013-03-05 15:26:22 +01:00
|
|
|
import org.gcube.portlets.d4sreporting.common.shared.ComponentType;
|
|
|
|
import org.gcube.portlets.d4sreporting.common.shared.Model;
|
2013-03-01 19:42:50 +01:00
|
|
|
import org.gcube.portlets.d4sreporting.common.shared.RepTimeSeries;
|
2013-03-08 15:49:26 +01:00
|
|
|
import org.gcube.portlets.d4sreporting.common.shared.RepeatableSequence;
|
2013-03-05 15:26:22 +01:00
|
|
|
import org.gcube.portlets.d4sreporting.common.shared.Table;
|
2013-02-06 23:25:43 +01:00
|
|
|
import org.gcube.portlets.d4sreporting.common.shared.TableCell;
|
|
|
|
import org.gcube.portlets.user.reportgenerator.client.ReportConstants;
|
|
|
|
import org.gcube.portlets.user.reportgenerator.client.ReportService;
|
|
|
|
import org.gcube.portlets.user.reportgenerator.server.servlet.loggers.CreateReportLogEntry;
|
|
|
|
import org.gcube.portlets.user.reportgenerator.server.servlet.loggers.OpenReportLogEntry;
|
|
|
|
import org.gcube.portlets.user.reportgenerator.server.servlet.loggers.OpenWorkflowLogEntry;
|
|
|
|
import org.gcube.portlets.user.reportgenerator.server.servlet.loggers.SaveWorkflowLogEntry;
|
|
|
|
import org.gcube.portlets.user.reportgenerator.shared.SessionInfo;
|
2013-03-05 15:26:22 +01:00
|
|
|
import org.gcube.portlets.user.reportgenerator.shared.UserBean;
|
2013-11-25 17:12:01 +01:00
|
|
|
import org.gcube.portlets.user.reportgenerator.shared.VMEReportBean;
|
2013-11-13 18:56:13 +01:00
|
|
|
import org.gcube.portlets.user.reportgenerator.shared.VMETypeIdentifier;
|
2013-10-09 14:21:50 +02:00
|
|
|
import org.gcube.portlets.widgets.exporter.shared.SaveReportFileException;
|
|
|
|
import org.gcube.portlets.widgets.exporter.shared.SaveReportFileExistException;
|
|
|
|
import org.gcube.portlets.widgets.exporter.shared.TypeExporter;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
2013-03-05 15:26:22 +01:00
|
|
|
import com.liferay.portal.model.UserModel;
|
2013-02-06 23:25:43 +01:00
|
|
|
import com.liferay.portal.service.LockLocalServiceUtil;
|
2013-03-05 15:26:22 +01:00
|
|
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
2013-02-06 23:25:43 +01:00
|
|
|
import com.liferay.portlet.documentlibrary.model.DLFileEntry;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* class implementing services
|
|
|
|
* @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it
|
|
|
|
*/
|
|
|
|
@SuppressWarnings("serial")
|
|
|
|
public class ReportServiceImpl extends RemoteServiceServlet implements ReportService {
|
|
|
|
|
2013-10-09 14:21:50 +02:00
|
|
|
private static final Logger _log = LoggerFactory.getLogger(ReportServiceImpl.class);
|
2013-03-05 19:53:57 +01:00
|
|
|
/**
|
|
|
|
* used for debugging in eclipse
|
|
|
|
*/
|
|
|
|
private boolean withinPortal = true;
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-03-16 02:53:00 +01:00
|
|
|
private static final String TEST_SCOPE = "/gcube/devsec/devVRE";
|
2013-11-13 18:56:13 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static final String CURRENT_REPORT_ID_ATTRIBUTE = "CURRENT_REPORT_ID_ATTRIBUTE";
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static final String CURRENT_REPORT_INSTANCE = "myReport";
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static final String PREVIOUS_REPORT_INSTANCE = "myPreviousReport";
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the WF DB Store
|
|
|
|
*/
|
|
|
|
private Store store;
|
|
|
|
|
|
|
|
|
|
|
|
//set to true if wanna test workflow menu mode
|
|
|
|
boolean testWorkflow = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called then servlet is intialized
|
|
|
|
*/
|
|
|
|
public void init() {
|
2013-11-18 18:25:49 +01:00
|
|
|
_log.info("Initializing Servlet ReportServiceImpl... connecting to WF DB");
|
|
|
|
store = new MyDerbyStore();
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
2013-03-08 15:49:26 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
/**
|
|
|
|
* the current ASLSession
|
|
|
|
* @return .
|
|
|
|
*/
|
|
|
|
private ASLSession getASLSession() {
|
|
|
|
String sessionID = this.getThreadLocalRequest().getSession().getId();
|
2013-03-16 02:53:00 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
|
|
|
|
if (user == null) {
|
|
|
|
user = "massimiliano.assante";
|
|
|
|
this.getThreadLocalRequest().getSession().setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, user);
|
2013-03-15 14:19:27 +01:00
|
|
|
SessionManager.getInstance().getASLSession(sessionID, user).setScope(TEST_SCOPE);
|
2013-03-16 02:53:00 +01:00
|
|
|
String email = user+"@isti.cnr.it";
|
|
|
|
String fullName = "Massimiliano Assante";
|
|
|
|
String thumbnailURL = "images/Avatar_default.png";
|
|
|
|
SessionManager.getInstance().getASLSession(sessionID, user).setUserEmailAddress(email);
|
|
|
|
SessionManager.getInstance().getASLSession(sessionID, user).setUserAvatarId(thumbnailURL);
|
|
|
|
SessionManager.getInstance().getASLSession(sessionID, user).setUserFullName(fullName);
|
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
2013-03-08 15:49:26 +01:00
|
|
|
|
2013-03-05 15:26:22 +01:00
|
|
|
if (!withinPortal)
|
|
|
|
_log.warn("\n\n****** Starting in Development MODE ******\n\n");
|
2013-03-08 15:49:26 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
return SessionManager.getInstance().getASLSession(sessionID, user);
|
2013-03-08 15:49:26 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Retrieve the user saved template names
|
|
|
|
*
|
|
|
|
* @return a String[] containing the template names
|
|
|
|
*/
|
|
|
|
public String[] getUserTemplateNames() {
|
|
|
|
ServiceUtil myUtil = new ServiceUtil(getASLSession());
|
|
|
|
Vector<String> tmp = new Vector<String>();
|
|
|
|
String userDir = myUtil.getTemplateFolder(getVreName(), getUsername());
|
|
|
|
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("userDir: " + userDir);
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
File f = new File(userDir);
|
|
|
|
//checking if dir exists
|
|
|
|
if (! f.exists()) {
|
|
|
|
try {
|
|
|
|
f.mkdirs();
|
|
|
|
return new String[0];
|
|
|
|
} catch (SecurityException ex) {
|
|
|
|
return new String[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
File []f2 = f.listFiles();
|
|
|
|
for(int i = 0; i < f2.length; i++){
|
|
|
|
if(f2[i].isDirectory()) {
|
|
|
|
tmp.add(f2[i].getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tmp.toArray(new String[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return a SerializableModel instance of the imported fimes xml
|
|
|
|
*/
|
2013-03-01 19:42:50 +01:00
|
|
|
public Model readImportedModel(String tempPath) {
|
|
|
|
Model toConvert = null;
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
FileInputStream fis = null;
|
|
|
|
ObjectInputStream in = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
fis = new FileInputStream(tempPath);
|
|
|
|
in = new ObjectInputStream(fis);
|
2013-03-01 19:42:50 +01:00
|
|
|
toConvert = (Model) in.readObject();
|
2013-02-06 23:25:43 +01:00
|
|
|
in.close();
|
|
|
|
} catch (IOException ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
} catch (ClassNotFoundException ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
2013-10-29 17:08:14 +01:00
|
|
|
_log.debug("Converting Imported Fimes to Serializable object, num sections: " + toConvert.getSections().size());
|
2013-02-06 23:25:43 +01:00
|
|
|
return (toConvert);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return a SerializableModel instance of the templatename passed as parameter
|
|
|
|
* @param templateName : the template to read from disk
|
|
|
|
* @param templateObjectID the id in the basket
|
|
|
|
* @param isTemplate says if you're opening a template or a report
|
|
|
|
* @param isImporting says if your importing or youre loading a template in the UI
|
|
|
|
*
|
|
|
|
*/
|
2013-03-01 19:42:50 +01:00
|
|
|
public Model readModel(String templateName, String templateObjectID, boolean isTemplate, boolean isImporting) {
|
2013-02-06 23:25:43 +01:00
|
|
|
ServiceUtil myUtil = new ServiceUtil(getASLSession());
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("Reading " + templateName);
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
Workspace root = null;
|
|
|
|
WorkspaceItem item = null;
|
|
|
|
try {
|
|
|
|
root = getWorkspaceArea();
|
|
|
|
item = root.getItem(templateObjectID);
|
|
|
|
if (! isImporting)
|
|
|
|
storeReportItemIDInSession(templateObjectID);
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
_log.debug("** -> getItem, id: " + templateObjectID + " Name: " + item.getName());
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
String zipToExtract = "";
|
|
|
|
if (item.getType() == WorkspaceItemType.FOLDER_ITEM) {
|
|
|
|
_log.debug("Item is a FolderItem - OK... next step check if is a templet or a report");
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
FolderItem bi = (FolderItem) item;
|
|
|
|
boolean fromBasket = false;
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
if (isTemplate) {
|
|
|
|
if (bi.getFolderItemType() == FolderItemType.REPORT_TEMPLATE) {
|
|
|
|
ReportTemplate zippedTemplate = (ReportTemplate) bi;
|
|
|
|
String zipFilename = "";
|
|
|
|
if (! isTemplate) {//then is a report
|
|
|
|
zipFilename = templateName + "-report.zip"; //gCube report
|
|
|
|
_log.debug("********************** Reading template -----------------");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
zipFilename = templateName + ".zip"; //gCube template
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
String zipPath = myUtil.getTemplatePath(templateName, getVreName(), getUsername());
|
|
|
|
fromBasket = getTemplateFromBasket(zippedTemplate, zipPath, zipFilename);
|
|
|
|
zipToExtract = zipPath + zipFilename;
|
|
|
|
}
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
if (bi.getFolderItemType() == FolderItemType.REPORT) {
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
_log.debug("Item is a REPORT");
|
|
|
|
Report zippedTemplate = (Report) bi;
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
String zipFilename = "";
|
|
|
|
if (! isTemplate) {//then is a report
|
|
|
|
zipFilename = templateName + "-report.zip"; //gCube report
|
|
|
|
_log.debug(" Reading report -----------------");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
zipFilename = templateName + ".zip"; //d4science template
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
File toDelete = new File(zipFilename);
|
|
|
|
toDelete.delete();
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
String zipPath = myUtil.getTemplatePath(templateName, getVreName(), getUsername());
|
|
|
|
fromBasket = getReportFromBasket(zippedTemplate, zipPath, zipFilename);
|
|
|
|
zipToExtract = zipPath + zipFilename;
|
|
|
|
}
|
2013-10-29 19:17:47 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
_log.info("\n\n** zipToExtract: " + zipToExtract);
|
2013-11-13 18:56:13 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
if (bi.getFolderItemType() == FolderItemType.REPORT || bi.getFolderItemType() == FolderItemType.REPORT_TEMPLATE) {
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
if (fromBasket) {
|
|
|
|
File toExtract = new File(zipToExtract);
|
|
|
|
File outputDir = new File( myUtil.getTemplatePath(templateName, getVreName(), getUsername()) );
|
|
|
|
ZipUtil.unzipArchive(toExtract, outputDir);
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
String templatePath = myUtil.getTemplatePath(templateName, getVreName(), getUsername());
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
String modelFilename = "";
|
|
|
|
try {
|
|
|
|
modelFilename = seekModel(templatePath, templateName);
|
|
|
|
} catch (FileNotFoundException e) { e.printStackTrace(); }
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
String fileToRead = templatePath + modelFilename + ".d4st" ;
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
_log.debug("Loading fileToRead from Disk -> " + fileToRead);
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
Model toReturn = null;
|
|
|
|
Model toConvert = null;
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
FileInputStream fis = null;
|
|
|
|
ObjectInputStream in = null;
|
|
|
|
try {
|
|
|
|
fis = new FileInputStream(fileToRead);
|
|
|
|
in = new ObjectInputStream(fis);
|
|
|
|
toConvert = (Model) in.readObject();
|
|
|
|
in.close();
|
|
|
|
} catch (IOException ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
} catch (ClassNotFoundException ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
_log.debug("Converting fileToRead to Serializable object");
|
|
|
|
toReturn = (toConvert);
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
// changes the template name model
|
|
|
|
toReturn.setTemplateName(templateName);
|
2013-10-29 19:17:47 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
File toDelete = new File(fileToRead); //to delete the file extracted from the workspace
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
File toDelete1 = new File( myUtil.getTemplatePath(templateName, getVreName(), getUsername()));
|
|
|
|
boolean deleted1 = toDelete1.delete();
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
File toDelete2 = new File(zipToExtract);
|
|
|
|
boolean deleted2 = toDelete2.delete();
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
boolean deleted = toDelete.delete();
|
|
|
|
_log.debug("deleting extracted file: " + fileToRead + " result: " + deleted);
|
|
|
|
_log.debug("dirToDelete: " + toDelete1 + " result: " + deleted1);
|
|
|
|
_log.debug("dirToDelete: " + toDelete2 + " result: " + deleted2);
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
//**** IMPORTANT ****
|
|
|
|
if (! isImporting) {
|
|
|
|
storeTemplateInSession(toReturn);
|
|
|
|
_log.debug("storeTemplateInSession DONE");
|
|
|
|
}
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 17:08:14 +01:00
|
|
|
AccessLogger log = AccessLogger.getAccessLogger();
|
|
|
|
OpenReportLogEntry logEntry = new OpenReportLogEntry(toReturn.getTemplateName(), templateObjectID);
|
|
|
|
log.logEntry(getASLSession().getUsername(), getASLSession().getScopeName(), logEntry);
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-11-27 14:51:58 +01:00
|
|
|
try {
|
|
|
|
ReportsReader.readReportStructure(toReturn);
|
|
|
|
} catch (Exception e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2013-10-29 17:08:14 +01:00
|
|
|
return toReturn;
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
}
|
2013-10-29 17:08:14 +01:00
|
|
|
_log.error("FAILED TO READ RETURING EMPTY Serializable Template");
|
2013-03-01 19:42:50 +01:00
|
|
|
return new Model();
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
2013-10-29 17:08:14 +01:00
|
|
|
_log.error("FAILED TO READ FROM BASKET RETURING EMPTY Serializable Template");
|
|
|
|
return new Model();
|
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* handles the case that the user has changed the template name in the basket
|
|
|
|
* @param templatePath
|
|
|
|
* @param templateName
|
|
|
|
* @return
|
|
|
|
* @throws FileNotFoundException
|
|
|
|
*/
|
|
|
|
private String seekModel(String templatePath, String templateName) throws FileNotFoundException {
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("seekModel: tPath=" + templatePath);
|
2013-02-06 23:25:43 +01:00
|
|
|
String fileToSeek = templatePath + templateName + ".d4st";
|
|
|
|
|
|
|
|
File toSeek = new File(fileToSeek);
|
|
|
|
if (toSeek.exists()) {
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("seekModel: modelName is the SAME returning");
|
2013-02-06 23:25:43 +01:00
|
|
|
return templateName;
|
|
|
|
}
|
|
|
|
else {
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("seekModel: modelName DIFFERENT upgrading");
|
2013-02-06 23:25:43 +01:00
|
|
|
File dirToLookIn = new File(templatePath);
|
|
|
|
File[] innerFiles = dirToLookIn.listFiles();
|
2013-11-13 18:56:13 +01:00
|
|
|
for (int i = 0; i < innerFiles.length; i++) {
|
|
|
|
_log.debug("scanning files in extracted folder: " + innerFiles[i].getName());
|
2013-02-06 23:25:43 +01:00
|
|
|
if (innerFiles[i].getName().endsWith(".d4st")) {
|
|
|
|
String toReturn = innerFiles[i].getName();
|
|
|
|
toReturn = toReturn.substring(0, toReturn.length()-5);
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("seekModel: returning.. =" + toReturn);
|
2013-02-06 23:25:43 +01:00
|
|
|
return toReturn;
|
|
|
|
}
|
2013-11-13 18:56:13 +01:00
|
|
|
}
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
throw new FileNotFoundException();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the template instance from the Basket
|
|
|
|
* @param repTmp
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
private boolean getTemplateFromBasket(ReportTemplate repTmp, String pathToFile, String filename) {
|
|
|
|
try {
|
|
|
|
File dir = new File(pathToFile);
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("DIR: " + pathToFile);
|
2013-02-06 23:25:43 +01:00
|
|
|
if (! dir.exists() )
|
|
|
|
dir.mkdirs();
|
|
|
|
|
|
|
|
File f = new File(pathToFile+filename);
|
|
|
|
InputStream inputStream = null;
|
|
|
|
try {
|
|
|
|
inputStream = repTmp.getData();
|
|
|
|
} catch (InternalErrorException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
OutputStream out = new FileOutputStream(f);
|
|
|
|
|
|
|
|
byte buf[] = new byte[1024];
|
|
|
|
int len;
|
|
|
|
while((len = inputStream.read(buf))>0)
|
|
|
|
out.write(buf,0,len);
|
|
|
|
out.close();
|
|
|
|
inputStream.close();
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.info("Successfully got ReportTemplate from Basket: " + pathToFile);
|
2013-02-06 23:25:43 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (IOException e){
|
|
|
|
e.printStackTrace();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the report instance from the Basket
|
|
|
|
* @param repTmp .
|
|
|
|
* @param pathToFile the directory where to save the file
|
|
|
|
* @param filename the filename to give to the newly created file
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
private boolean getReportFromBasket(Report repTmp, String pathToFile, String filename) {
|
|
|
|
try {
|
|
|
|
File dir = new File(pathToFile);
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("DIR: " + pathToFile);
|
2013-02-06 23:25:43 +01:00
|
|
|
if (! dir.exists() )
|
|
|
|
dir.mkdirs();
|
|
|
|
|
|
|
|
File f = new File(pathToFile+filename);
|
|
|
|
InputStream inputStream = null;
|
|
|
|
try {
|
|
|
|
inputStream = repTmp.getData();
|
|
|
|
} catch (InternalErrorException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
OutputStream out = new FileOutputStream(f);
|
|
|
|
|
|
|
|
byte buf[] = new byte[1024];
|
|
|
|
int len;
|
|
|
|
while((len = inputStream.read(buf))>0)
|
|
|
|
out.write(buf,0,len);
|
|
|
|
out.close();
|
|
|
|
inputStream.close();
|
2013-03-13 17:15:29 +01:00
|
|
|
_log.info("Successfully got ReportTemplate from HL: " + pathToFile);
|
2013-02-06 23:25:43 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (IOException e){
|
|
|
|
e.printStackTrace();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2013-03-16 02:53:00 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return the shared session
|
|
|
|
*/
|
|
|
|
public String getUsername() {
|
|
|
|
if (! ReportConstants.isDeployed) {
|
|
|
|
return "massimiliano.assante";
|
|
|
|
} else {
|
|
|
|
HttpServletRequest httpServletRequest = this.getThreadLocalRequest();
|
|
|
|
HttpSession session = httpServletRequest.getSession();
|
|
|
|
String user = (String) session.getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
|
|
|
|
if(session.getAttribute(ScopeHelper.USERNAME_ATTRIBUTE)== null)
|
|
|
|
{
|
|
|
|
user = "massimiliano.assante";
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.warn("D4ScienceSession user NULL set to: " + user);
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.warn("ASLSession user: " + user);
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
ASLSession d4session = SessionManager.getInstance().getASLSession(session.getId(), user);
|
|
|
|
d4session.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, user);
|
|
|
|
return user;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return the current scope
|
|
|
|
*/
|
|
|
|
public String getVreName() {
|
|
|
|
if (! ReportConstants.isDeployed) {
|
2013-03-15 14:19:27 +01:00
|
|
|
return TEST_SCOPE;
|
2013-02-06 23:25:43 +01:00
|
|
|
} else {
|
|
|
|
HttpServletRequest httpServletRequest = this.getThreadLocalRequest();
|
|
|
|
HttpSession session = httpServletRequest.getSession();
|
|
|
|
|
|
|
|
ASLSession d4session = SessionManager.getInstance().getASLSession(session.getId(), getUsername());
|
|
|
|
String scope = d4session.getScopeName();
|
|
|
|
|
|
|
|
if(scope == null) {
|
2013-03-15 14:19:27 +01:00
|
|
|
scope = TEST_SCOPE;
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.warn("ASL Session scope NULL set to: " + scope);
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//need to remove the initial / of the scope
|
|
|
|
if (scope.charAt(0) == '/')
|
|
|
|
scope = scope.substring(1, scope.length());
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.info("SCOPE: " + scope);
|
2013-02-06 23:25:43 +01:00
|
|
|
return scope;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
2013-03-16 02:53:00 +01:00
|
|
|
* @return
|
|
|
|
* @throws WorkspaceFolderNotFoundException
|
2013-02-06 23:25:43 +01:00
|
|
|
* @throws InternalErrorException
|
|
|
|
* @throws HomeNotFoundException
|
|
|
|
*/
|
|
|
|
protected Workspace getWorkspaceArea() throws WorkspaceFolderNotFoundException, InternalErrorException, HomeNotFoundException {
|
2013-10-09 14:21:50 +02:00
|
|
|
return HomeLibrary.getUserWorkspace(getASLSession().getUsername());
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* reads from the file system and returns the user workspace as TreeNode object
|
|
|
|
*
|
2013-03-16 02:53:00 +01:00
|
|
|
* @return the Default folder if if there is no basket in session, else the folder in session id
|
2013-02-06 23:25:43 +01:00
|
|
|
*/
|
2013-03-16 02:53:00 +01:00
|
|
|
public String getRootFolder() {
|
2013-02-06 23:25:43 +01:00
|
|
|
try {
|
|
|
|
Workspace workspaceArea = getWorkspaceArea();
|
|
|
|
WorkspaceFolder basket = workspaceArea.getRoot();
|
|
|
|
return basket.getId();
|
2013-03-16 02:53:00 +01:00
|
|
|
} catch (Exception e) { e.printStackTrace();
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
2013-03-16 02:53:00 +01:00
|
|
|
return "Coud not open default folder";
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return the model previously stored in the session
|
|
|
|
*/
|
2013-03-01 19:42:50 +01:00
|
|
|
public Model readTemplateFromSession() {
|
2013-02-06 23:25:43 +01:00
|
|
|
ASLSession d4Session = getASLSession();
|
|
|
|
|
|
|
|
String templateid = (String) d4Session.getAttribute("idreport");
|
|
|
|
|
|
|
|
Object workflowid = getASLSession().getAttribute(WfDocsLibrary.LAST_WORKFLOW_ID);
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug(" (templateid != null && workflowid != null) = " + (templateid != null) + " - " + (workflowid != null));
|
2013-02-06 23:25:43 +01:00
|
|
|
if (workflowid != null) {
|
|
|
|
getASLSession().setAttribute(WfDocsLibrary.LAST_WORKFLOW_ID, null);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
String templateName = "";
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("TEMPLATE ID==NULL " + (templateid == null));
|
2013-02-06 23:25:43 +01:00
|
|
|
if (templateid != null) {
|
|
|
|
if (! templateid.equals("")) {
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("READING SESSION VARIABLE FOR REPORT ID... " + templateid);
|
2013-02-06 23:25:43 +01:00
|
|
|
//reset the value
|
|
|
|
d4Session.setAttribute("idreport", "");
|
|
|
|
Workspace root = null;
|
|
|
|
WorkspaceItem item = null;
|
|
|
|
try {
|
|
|
|
root = getWorkspaceArea();
|
|
|
|
|
|
|
|
item = root.getItem(templateid);
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.info("READ REPORT FROM WP... " + item.getName());
|
2013-02-06 23:25:43 +01:00
|
|
|
templateName = item.getName();
|
|
|
|
} catch (WorkspaceFolderNotFoundException e) {e.printStackTrace();
|
|
|
|
} catch (InternalErrorException e) { e.printStackTrace();
|
|
|
|
} catch (HomeNotFoundException e) { e.printStackTrace();
|
|
|
|
} catch (ItemNotFoundException e) { e.printStackTrace();}
|
|
|
|
|
2013-03-01 19:42:50 +01:00
|
|
|
Model toReturn = readModel(templateName, templateid, false, false);
|
2013-02-06 23:25:43 +01:00
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
if (d4Session.getAttribute(CURRENT_REPORT_INSTANCE) != null)
|
2013-03-01 19:42:50 +01:00
|
|
|
return (Model) d4Session.getAttribute(CURRENT_REPORT_INSTANCE) ;
|
2013-02-06 23:25:43 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (d4Session.getAttribute(CURRENT_REPORT_INSTANCE) != null) {
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("getAttribute(\"CURRENT_REPORT_INSTANCE\")...");
|
2013-03-01 19:42:50 +01:00
|
|
|
Model model = (Model) d4Session.getAttribute(CURRENT_REPORT_INSTANCE) ;
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug(model.getTemplateName());
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ServiceUtil myUtil = new ServiceUtil(getASLSession());
|
|
|
|
String dirToClean = myUtil.getTemplateFolder(getVreName(), getUsername());
|
2013-03-16 02:53:00 +01:00
|
|
|
_log.info("No data on session for Reports, cleaning temp dir: " + dirToClean);
|
|
|
|
delTemplateDir(new File(dirToClean));
|
2013-02-06 23:25:43 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* recurdively delete the templates folder of the dir dir
|
|
|
|
* @param dir the dir to delete
|
|
|
|
*/
|
|
|
|
public void delTemplateDir(File dir) {
|
|
|
|
try {
|
|
|
|
File[] files = dir.listFiles();
|
|
|
|
for (int i = 0; i < files.length; i++) {
|
|
|
|
if (files[i].isDirectory())
|
|
|
|
delTemplateDir(files[i]);
|
|
|
|
files[i].delete();
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
System.out.println("WARNING: Could not cleaning temp dir: reason unknown");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param model to store in the session
|
|
|
|
*/
|
2013-03-01 19:42:50 +01:00
|
|
|
public void storeTemplateInSession(Model model) {
|
2013-02-06 23:25:43 +01:00
|
|
|
ASLSession d4Session = getASLSession();
|
|
|
|
d4Session.setAttribute(CURRENT_REPORT_INSTANCE, model);
|
2013-05-06 17:38:24 +02:00
|
|
|
_log.trace("Saved in Session");
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-29 17:27:29 +02:00
|
|
|
private void convertDynamicImagesFromHL(Model model) {
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("model == NULL " + (model == null));
|
2013-03-01 19:42:50 +01:00
|
|
|
Vector<BasicSection> sections = model.getSections();
|
|
|
|
for (BasicSection section : sections) {
|
|
|
|
for (BasicComponent component : section.getComponents()) {
|
2013-02-06 23:25:43 +01:00
|
|
|
if (component.getType() == ComponentType.DYNA_IMAGE) {
|
2013-03-13 18:44:20 +01:00
|
|
|
_log.debug("Found Simple Image: " + component.getPossibleContent());
|
2013-11-25 17:12:01 +01:00
|
|
|
if (component.getId() != null) { // you need to convert only new images that stay in the HL Workspace, this is the check
|
|
|
|
String imageID = component.getId();
|
2013-04-29 17:27:29 +02:00
|
|
|
component.setPossibleContent(getdDataImagebase64(imageID));
|
|
|
|
_log.trace("Image converted base 64 OK: " + component.getPossibleContent());
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
}
|
2013-03-13 17:03:57 +01:00
|
|
|
if (component.getType() == ComponentType.REPEAT_SEQUENCE || component.getType() == ComponentType.BODY_TABLE_IMAGE) { //there could be images inside
|
2013-03-08 15:49:26 +01:00
|
|
|
RepeatableSequence res = (RepeatableSequence) component.getPossibleContent();
|
|
|
|
for (BasicComponent co : res.getGroupedComponents()) {
|
2013-03-13 17:03:57 +01:00
|
|
|
_log.debug("Found Image IN SEQUENCE, type is: " + component.getType());
|
2013-11-25 17:12:01 +01:00
|
|
|
if (co.getId() != null) { // you need to convert only new images that stay in the HL Workspace, this is the check
|
|
|
|
String imageID = co.getId();
|
2013-04-29 17:27:29 +02:00
|
|
|
co.setPossibleContent(getdDataImagebase64(imageID));
|
|
|
|
_log.trace("Image converted base 64 OK, in SEQUENCE: " + co.getPossibleContent());
|
2013-03-08 15:49:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-29 17:27:29 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* convert the image into a String encoded base 64
|
|
|
|
* @param imageIDinWorkspace the id of the image in workspace
|
|
|
|
* @return the string representing the image converted to be put in the img src attribute e.g. data:image/ong;base64,a...z
|
|
|
|
*/
|
|
|
|
private String getdDataImagebase64(String imageIDinWorkspace) {
|
|
|
|
Workspace root = null;
|
|
|
|
try {
|
|
|
|
root = getWorkspaceArea();
|
|
|
|
|
|
|
|
WorkspaceItem item = null;
|
|
|
|
item = root.getItem(imageIDinWorkspace);
|
|
|
|
if (item.getType() == WorkspaceItemType.FOLDER_ITEM) {
|
|
|
|
_log.debug("Item is a Folder Item");
|
|
|
|
FolderItem imageItem = (FolderItem) item;
|
|
|
|
InputStream data = null;
|
|
|
|
|
|
|
|
if (imageItem.getFolderItemType()==FolderItemType.EXTERNAL_IMAGE){
|
|
|
|
_log.debug("EXTERNAL_IMAGE -|- " + item.getType() + " itemId=" + item.getId());
|
|
|
|
ExternalImage image = (ExternalImage)item;
|
|
|
|
_log.debug("EXTERNAL_IMAGE Name= " + item.getName() + " Asking InputStream ..");
|
|
|
|
data = image.getData();
|
|
|
|
_log.debug("Got inputStream");
|
|
|
|
}
|
|
|
|
else if (imageItem.getFolderItemType()==FolderItemType.IMAGE_DOCUMENT){
|
|
|
|
ImageDocument image = (ImageDocument)item;
|
|
|
|
if (image.getMimeType().equals("image/tiff"))
|
|
|
|
data = image.getThumbnail();
|
|
|
|
else
|
|
|
|
data = image.getData();
|
|
|
|
}
|
|
|
|
if (data != null) {
|
|
|
|
_log.debug("Encoding image in base64");
|
2013-10-29 17:08:14 +01:00
|
|
|
byte[] imageBytes = IOUtils.toByteArray(data);
|
2013-11-07 12:48:50 +01:00
|
|
|
String extension = ImagesUtil.getImageExtension(imageItem);
|
2013-04-29 17:27:29 +02:00
|
|
|
String srcAttrValue = "data:image/"+extension+";base64,"+DatatypeConverter.printBase64Binary(imageBytes);
|
|
|
|
_log.debug("Encoded image=" + srcAttrValue);
|
2013-10-29 17:08:14 +01:00
|
|
|
return srcAttrValue;
|
2013-04-29 17:27:29 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return null;
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2013-10-29 17:08:14 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
/**
|
|
|
|
* @param reportItemid the report itemd id in basket to store in the session
|
|
|
|
*/
|
|
|
|
public void storeReportItemIDInSession(String reportItemid) {
|
|
|
|
ASLSession d4Session = getASLSession();
|
|
|
|
d4Session.setAttribute(CURRENT_REPORT_ID_ATTRIBUTE, reportItemid);
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("WROTE REPORT ID IN SESSION: " + reportItemid);
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the report item id in basket, or "" if doesn't exist
|
|
|
|
*/
|
|
|
|
public String getReportItemIDFromSession() {
|
|
|
|
ASLSession d4Session = getASLSession();
|
|
|
|
if (d4Session.getAttribute(CURRENT_REPORT_ID_ATTRIBUTE) == null)
|
|
|
|
return "";
|
|
|
|
else
|
|
|
|
return d4Session.getAttribute(CURRENT_REPORT_ID_ATTRIBUTE).toString();
|
|
|
|
}
|
|
|
|
/**
|
2013-10-29 19:17:47 +01:00
|
|
|
* used to save the report in the same folder
|
2013-02-06 23:25:43 +01:00
|
|
|
*/
|
2013-05-06 17:38:24 +02:00
|
|
|
public void saveReport(Model toSave) {
|
2013-02-06 23:25:43 +01:00
|
|
|
Workspace root = null;
|
|
|
|
try {
|
|
|
|
root = getWorkspaceArea();
|
2013-03-16 02:53:00 +01:00
|
|
|
} catch (Exception e) { e.printStackTrace();}
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
WorkspaceItem item = null;
|
|
|
|
String folderid = "";
|
|
|
|
String itemName = "";
|
|
|
|
try {
|
|
|
|
if (getReportItemIDFromSession().equals("")) {
|
2013-03-16 02:53:00 +01:00
|
|
|
folderid = getRootFolder();
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
item = root.getItem(getReportItemIDFromSession());
|
|
|
|
folderid = item.getParent().getId();
|
|
|
|
itemName = item.getName();
|
|
|
|
}
|
|
|
|
} catch (ItemNotFoundException e) {
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.error("ITEM NOT FOUND -> " + getReportItemIDFromSession());
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
} catch (InternalErrorException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2013-05-06 17:38:24 +02:00
|
|
|
saveReport(toSave, folderid, itemName);
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-02-15 16:54:13 +01:00
|
|
|
* @param save a report in another folder .
|
2013-02-06 23:25:43 +01:00
|
|
|
*
|
|
|
|
*/
|
2013-05-06 17:38:24 +02:00
|
|
|
public void saveReport(Model toSave, String folderid, String newname) {
|
2013-11-25 17:12:01 +01:00
|
|
|
try {
|
|
|
|
ReportsReader.readReportStructure(toSave);
|
|
|
|
} catch (Exception e1) {
|
|
|
|
e1.printStackTrace();
|
|
|
|
}
|
2013-05-06 17:38:24 +02:00
|
|
|
Model model = toSave;
|
|
|
|
storeTemplateInSession(toSave);
|
2013-03-13 18:44:20 +01:00
|
|
|
_log.info("Serializing Model in folder: " + folderid );
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.info("Trying to convert dynamic images ... ");
|
2013-04-29 17:27:29 +02:00
|
|
|
convertDynamicImagesFromHL(model);
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
ServiceUtil myUtil = new ServiceUtil(getASLSession());
|
|
|
|
boolean result = myUtil.writeModel(model, "CURRENT_OPEN", getVreName(), getUsername());
|
|
|
|
|
|
|
|
if (!result) {
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("Could not save report, serializing failed");
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
String templatePath = myUtil.getTemplateFolder(getVreName(), getUsername()) + "CURRENT_OPEN";
|
|
|
|
try {
|
|
|
|
Thread.sleep(1000);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("Trying to zip folder: " + templatePath);
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
String folderToZip = templatePath;
|
|
|
|
String outZip = templatePath+"-report.zip";
|
|
|
|
|
|
|
|
try {
|
|
|
|
ZipUtil.zipDir(outZip, folderToZip);
|
|
|
|
} catch (IOException e) {
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.error("Could not zip template, serializing failed");
|
2013-02-06 23:25:43 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.info("Folder zipped, result: "+ outZip);
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
InputStream isZip = null;
|
|
|
|
|
|
|
|
WorkspaceFolder toSaveIn = null;
|
|
|
|
try {
|
|
|
|
isZip = new BufferedInputStream(new FileInputStream(outZip));
|
|
|
|
|
2013-03-16 02:53:00 +01:00
|
|
|
toSaveIn = getRootFolder(folderid);
|
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
String templateName = newname;
|
|
|
|
|
2013-10-29 19:17:47 +01:00
|
|
|
boolean isUpdate = false;
|
2013-02-06 23:25:43 +01:00
|
|
|
if (templateName.endsWith("d4sR") ) {
|
|
|
|
if (toSaveIn.exists(templateName)) {
|
2013-10-29 19:17:47 +01:00
|
|
|
_log.warn("Item exists already, updating");
|
|
|
|
//toSaveIn.removeChild(toSaveIn.find(templateName));
|
|
|
|
isUpdate = true;
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (toSaveIn.exists(templateName + ".d4sR")) {
|
2013-10-29 19:17:47 +01:00
|
|
|
_log.warn("Item exists already, updating");
|
|
|
|
//toSaveIn.removeChild(toSaveIn.find(templateName + ".d4sR"));
|
|
|
|
isUpdate = true;
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//remove the template extension
|
|
|
|
String templateToInsert = templateName.replace(".d4sT", "");
|
|
|
|
if (! templateToInsert.endsWith(".d4sR"))
|
|
|
|
templateToInsert+=".d4sR";
|
|
|
|
|
2013-10-29 19:17:47 +01:00
|
|
|
Report rep = null;
|
|
|
|
if (isUpdate) {
|
|
|
|
rep = (Report) toSaveIn.find(templateName);
|
|
|
|
getWorkspaceArea().updateItem(rep.getId(), isZip);
|
|
|
|
} else { //is new
|
|
|
|
Calendar dateCreated = Calendar.getInstance();
|
|
|
|
dateCreated.setTime(model.getDateCreated());
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 19:17:47 +01:00
|
|
|
Calendar lastEdit = Calendar.getInstance();
|
|
|
|
lastEdit.setTime(model.getLastEdit());
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-10-29 19:17:47 +01:00
|
|
|
rep = toSaveIn.createReportItem(templateToInsert, templateToInsert, dateCreated, lastEdit,
|
|
|
|
model.getAuthor(), model.getLastEditBy(), templateToInsert, model.getSections().size(), "no-status", isZip);
|
|
|
|
}
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
storeReportItemIDInSession(rep.getId());
|
|
|
|
|
2013-03-16 02:53:00 +01:00
|
|
|
if (toSaveIn.getType() == WorkspaceItemType.SHARED_FOLDER) {
|
|
|
|
sendReportUpdateNotification(toSaveIn, rep);
|
|
|
|
}
|
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
AccessLogger log = AccessLogger.getAccessLogger();
|
|
|
|
CreateReportLogEntry logEntry = new CreateReportLogEntry(model.getTemplateName(), rep.getId());
|
|
|
|
log.logEntry(getASLSession().getUsername(), getASLSession().getScopeName(), logEntry);
|
|
|
|
|
2013-03-16 02:53:00 +01:00
|
|
|
} catch (Exception e) {
|
2013-02-06 23:25:43 +01:00
|
|
|
e.printStackTrace();
|
2013-03-16 02:53:00 +01:00
|
|
|
}
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-03-16 02:53:00 +01:00
|
|
|
* Return an instance of the root folder
|
|
|
|
* @param folderId
|
2013-02-06 23:25:43 +01:00
|
|
|
* @return
|
|
|
|
* @throws ItemNotFoundException
|
|
|
|
*/
|
2013-03-16 02:53:00 +01:00
|
|
|
private WorkspaceFolder getRootFolder(String folderId) throws ItemNotFoundException {
|
2013-02-06 23:25:43 +01:00
|
|
|
Workspace root = null;
|
|
|
|
try {
|
|
|
|
root = getWorkspaceArea();
|
|
|
|
} catch (WorkspaceFolderNotFoundException e) {e.printStackTrace();
|
|
|
|
} catch (InternalErrorException e) { e.printStackTrace();
|
|
|
|
} catch (HomeNotFoundException e) { e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
WorkspaceItem item = null;
|
|
|
|
try {
|
2013-03-16 02:53:00 +01:00
|
|
|
item = root.getItem(folderId);
|
2013-02-06 23:25:43 +01:00
|
|
|
} catch (ItemNotFoundException e) {
|
2013-03-16 02:53:00 +01:00
|
|
|
_log.info("Folder : " + folderId + " NOT FOUND RETURNING DEFAULT ONE");
|
|
|
|
return(WorkspaceFolder)root.getItem(getRootFolder());
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
}
|
2013-03-16 02:53:00 +01:00
|
|
|
if (item.getType() == WorkspaceItemType.FOLDER || item.getType() == WorkspaceItemType.SHARED_FOLDER) {
|
|
|
|
return (WorkspaceFolder) item;
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
2013-03-16 02:53:00 +01:00
|
|
|
_log.error("The item id does not belong to a valid folder id:" + folderId);
|
|
|
|
return null;
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
|
2013-03-16 02:53:00 +01:00
|
|
|
/**
|
|
|
|
* send an update notification to all the user sharing this folder
|
|
|
|
* @param toSaveIn
|
|
|
|
* @throws InternalErrorException
|
|
|
|
*/
|
|
|
|
private void sendReportUpdateNotification(WorkspaceFolder sharedFolder, WorkspaceItem wsItem) throws InternalErrorException {
|
|
|
|
if (sharedFolder.getType() == WorkspaceItemType.SHARED_FOLDER) {
|
|
|
|
WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) sharedFolder;
|
|
|
|
List<String> usersToNotify = wsFolder.getUsers();
|
|
|
|
Thread thread = new Thread(new NotificationsThread(getASLSession(), usersToNotify, wsItem, sharedFolder));
|
|
|
|
thread.start();
|
|
|
|
}
|
|
|
|
}
|
2013-02-06 23:25:43 +01:00
|
|
|
/**
|
|
|
|
* return a sample of the given TS to the client
|
|
|
|
* @param sTS .
|
|
|
|
* @return .
|
|
|
|
*/
|
2013-03-01 19:42:50 +01:00
|
|
|
public Table getSampleTimeSeries(RepTimeSeries sTS) {
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
File csvTS = getTimeSeriesFromWorkspace(sTS);
|
2013-03-01 19:42:50 +01:00
|
|
|
Table toReturn = null;
|
2013-02-06 23:25:43 +01:00
|
|
|
try {
|
|
|
|
toReturn = parseCSV(csvTS, sTS);
|
|
|
|
} catch (ParseException e) { e.printStackTrace();
|
|
|
|
} catch (IOException e) { e.printStackTrace();
|
|
|
|
} catch (ProcessingException e) { e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* retrieve the given TS csv representation and writes it into /tmp returning the File
|
|
|
|
* @param sTS serializable TS
|
|
|
|
* @return a File csv
|
|
|
|
*/
|
2013-03-01 19:42:50 +01:00
|
|
|
private File getTimeSeriesFromWorkspace(RepTimeSeries sTS) {
|
2013-02-06 23:25:43 +01:00
|
|
|
try {
|
|
|
|
String timeSeriesBasketID = sTS.getTsMetadata().getId();
|
|
|
|
|
|
|
|
Workspace root = null;
|
|
|
|
try {
|
|
|
|
root = getWorkspaceArea();
|
|
|
|
} catch (WorkspaceFolderNotFoundException e) {e.printStackTrace();
|
|
|
|
} catch (InternalErrorException e) { e.printStackTrace();
|
|
|
|
} catch (HomeNotFoundException e) { e.printStackTrace();
|
|
|
|
}
|
|
|
|
WorkspaceItem item = null;
|
|
|
|
try {
|
|
|
|
item = root.getItem(timeSeriesBasketID);
|
|
|
|
} catch (ItemNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("Got Item TS From HL, Item Type: "+item.getType());
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
if (item.getType() != WorkspaceItemType.FOLDER_ITEM) {
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("The item id does not belong to a timeseries, id:" + timeSeriesBasketID);
|
2013-02-06 23:25:43 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
FolderItem bItem = (FolderItem) item;
|
|
|
|
if (bItem.getFolderItemType() != FolderItemType.TIME_SERIES) {
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("The basket item does not belong to a timeseries, id:" + timeSeriesBasketID);
|
2013-02-06 23:25:43 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeSeries ts = (TimeSeries) bItem;
|
|
|
|
return getTSFromBasket(ts);
|
|
|
|
}
|
|
|
|
catch (NullPointerException e) {
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.error("No TS was dragged in the Area returning NULL");
|
2013-02-06 23:25:43 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param toParse the csv to parse
|
|
|
|
* @throws ProcessingException .
|
|
|
|
* @throws IOException .
|
|
|
|
* @throws ParseException .
|
|
|
|
*/
|
2013-03-01 19:42:50 +01:00
|
|
|
private Table parseCSV(File toParse, final RepTimeSeries sTS) throws ParseException , IOException, ProcessingException {
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-03-01 19:42:50 +01:00
|
|
|
final Table toReturn;
|
2013-02-06 23:25:43 +01:00
|
|
|
final boolean isFiltered;
|
|
|
|
final int fromLine;
|
|
|
|
final int toLine;
|
|
|
|
|
|
|
|
//if there is no filter
|
|
|
|
if ( sTS.getFilter() == null) {
|
2013-03-01 19:42:50 +01:00
|
|
|
toReturn = new Table(sTS.getTsMetadata().getHeaderLabels().size());
|
2013-02-06 23:25:43 +01:00
|
|
|
isFiltered = false;
|
|
|
|
fromLine = 1;
|
|
|
|
toLine = 10;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int headers = sTS.getFilter().getColsNumberToShow().size();
|
2013-03-01 19:42:50 +01:00
|
|
|
toReturn = new Table(headers);
|
2013-02-06 23:25:43 +01:00
|
|
|
isFiltered = true;
|
|
|
|
fromLine = sTS.getFilter().getFrom();
|
|
|
|
toLine = fromLine + 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
final CSVFileProcessor fp = new CSVFileProcessor();
|
|
|
|
fp.processFile(toParse.getAbsolutePath() , new CSVLineProcessor() {
|
|
|
|
boolean keepGoing = true;
|
|
|
|
|
|
|
|
public void processHeaderLine( final int linenumber, final List<String> fieldNames ) {
|
|
|
|
ArrayList<TableCell> toInsert = new ArrayList<TableCell>();
|
|
|
|
for (String field : fieldNames) {
|
|
|
|
toInsert.add(new TableCell(field));
|
|
|
|
}
|
|
|
|
if (! isFiltered)
|
|
|
|
toReturn.addRow((ArrayList<TableCell>) toInsert);
|
|
|
|
else {
|
|
|
|
ArrayList<String> filteredHeaders = new ArrayList<String>();
|
|
|
|
for (Integer colNo : sTS.getFilter().getColsNumberToShow()) {
|
|
|
|
String toAdd = sTS.getTsMetadata().getHeaderLabels().get(colNo);
|
|
|
|
filteredHeaders.add(toAdd);
|
|
|
|
toInsert = new ArrayList<TableCell>();
|
|
|
|
for (String field : filteredHeaders) {
|
|
|
|
toInsert.add(new TableCell(field));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
toReturn.addRow(toInsert);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void processDataLine( final int linenumber, final List<String> fieldValues ) {
|
|
|
|
if (linenumber > toLine)
|
|
|
|
keepGoing = false;
|
|
|
|
if (linenumber >= fromLine && linenumber <= toLine) {
|
|
|
|
ArrayList<TableCell> toInsert = new ArrayList<TableCell>();
|
|
|
|
for (String field : fieldValues) {
|
|
|
|
toInsert.add(new TableCell(field));
|
|
|
|
}
|
|
|
|
if (! isFiltered)
|
|
|
|
toReturn.addRow(toInsert);
|
|
|
|
else {
|
|
|
|
ArrayList<String> filteredFields = new ArrayList<String>();
|
|
|
|
for (Integer colNo : sTS.getFilter().getColsNumberToShow()) {
|
|
|
|
String toAdd = fieldValues.get(colNo);
|
|
|
|
filteredFields.add(toAdd);
|
|
|
|
toInsert = new ArrayList<TableCell>();
|
|
|
|
for (String field : filteredFields) {
|
|
|
|
toInsert.add(new TableCell(field));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
toReturn.addRow(toInsert);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public boolean continueProcessing() {
|
|
|
|
return keepGoing;
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the TS from the Basket
|
|
|
|
* @param ts
|
|
|
|
* @return a csv file
|
|
|
|
*/
|
|
|
|
private File getTSFromBasket(TimeSeries ts) {
|
|
|
|
try {
|
|
|
|
File temp = File.createTempFile(ts.getName(), ".csv");
|
|
|
|
|
|
|
|
InputStream inputStream = null;
|
|
|
|
try {
|
|
|
|
inputStream = ts.getData();
|
|
|
|
} catch (InternalErrorException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
OutputStream out = new FileOutputStream(temp);
|
|
|
|
|
|
|
|
byte buf[] = new byte[1024];
|
|
|
|
int len;
|
|
|
|
while((len = inputStream.read(buf))>0)
|
|
|
|
out.write(buf,0,len);
|
|
|
|
out.close();
|
|
|
|
inputStream.close();
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("Successfully got TimeSeries from Basket: \n" + temp.getAbsolutePath());
|
2013-02-06 23:25:43 +01:00
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
catch (IOException e){
|
|
|
|
e.printStackTrace();
|
|
|
|
return null;
|
|
|
|
} catch (InternalErrorException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* each portlet instance runs in a scope
|
|
|
|
* each portlet instance is used by a unique username from within the portal
|
|
|
|
* @param currentHost .
|
|
|
|
* @return a SessionInfo bean containing the username the scope andis opening a workflow document or not
|
|
|
|
*/
|
|
|
|
public SessionInfo getSessionInfo(String currentHost) {
|
|
|
|
if (testWorkflow) {
|
|
|
|
|
|
|
|
getASLSession().setAttribute(WfDocsLibrary.WORKFLOW_ID_ATTRIBUTE, "1");
|
|
|
|
getASLSession().setAttribute(WfDocsLibrary.WORKFLOW_GIVEN_NAME, "TEST REPORT");
|
|
|
|
getASLSession().setAttribute(WfDocsLibrary.WORKFLOW_READONLY_ATTRIBUTE, true);
|
2013-03-05 15:26:22 +01:00
|
|
|
return new SessionInfo(getUserBean(), getVreName(), true, true);
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
if (getASLSession().getAttribute(WfDocsLibrary.WORKFLOW_ID_ATTRIBUTE) == null) {
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("WfDocsLibrary.WORKFLOW_ID_ATTRIBUTE is NULL: ");
|
|
|
|
return new SessionInfo(getUserBean(), getVreName(), false, false);
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
else {
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("FOUND WORKFLOW_ID_ATTRIBUTE ***** ");
|
2013-02-06 23:25:43 +01:00
|
|
|
//String workflowid = getASLSession().getAttribute(WfDocsLibrary.WORKFLOW_ID_ATTRIBUTE).toString();
|
|
|
|
Boolean canEdit = ! (Boolean) getASLSession().getAttribute(WfDocsLibrary.WORKFLOW_READONLY_ATTRIBUTE);
|
2013-03-05 15:26:22 +01:00
|
|
|
return new SessionInfo(getUserBean(), getVreName(), true, canEdit);
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-01 19:42:50 +01:00
|
|
|
public Model getWorkflowDocumentFromDocumentLibrary() {
|
2013-02-06 23:25:43 +01:00
|
|
|
ServiceUtil myUtil = new ServiceUtil(getASLSession());
|
|
|
|
|
|
|
|
if (testWorkflow) {
|
|
|
|
FileInputStream fis = null;
|
|
|
|
ObjectInputStream in = null;
|
2013-03-01 19:42:50 +01:00
|
|
|
Model toConvert = null;
|
2013-02-06 23:25:43 +01:00
|
|
|
try {
|
|
|
|
fis = new FileInputStream("/Users/massi/portal/CURRENT_OPEN.d4st");
|
|
|
|
in = new ObjectInputStream(fis);
|
2013-03-01 19:42:50 +01:00
|
|
|
toConvert = (Model) in.readObject();
|
2013-02-06 23:25:43 +01:00
|
|
|
in.close();
|
|
|
|
} catch (IOException ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
} catch (ClassNotFoundException ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
toConvert.setTemplateName("TEST");
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.info(" Converting TEST REPORT to Serializable object, model name: \n" + toConvert.getTemplateName());
|
2013-02-06 23:25:43 +01:00
|
|
|
return toConvert;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
String workflowid = getASLSession().getAttribute(WfDocsLibrary.WORKFLOW_ID_ATTRIBUTE).toString();
|
|
|
|
Boolean canEdit = ! (Boolean) getASLSession().getAttribute(WfDocsLibrary.WORKFLOW_READONLY_ATTRIBUTE);
|
|
|
|
String documentName = getASLSession().getAttribute(WfDocsLibrary.WORKFLOW_GIVEN_NAME).toString();
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.info("getWorkflowDocumentFromDocumentLibrary() CALLED ***** ID = " + workflowid + " name:\n " + documentName);
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
//TODO: check this
|
|
|
|
//reset the values in session
|
|
|
|
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.info("Reset the values in session ... ");
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
getASLSession().setAttribute(WfDocsLibrary.LAST_WORKFLOW_ID, workflowid);
|
|
|
|
getASLSession().setAttribute(WfDocsLibrary.WORKFLOW_ID_ATTRIBUTE, null);
|
|
|
|
getASLSession().setAttribute(WfDocsLibrary.WORKFLOW_READONLY_ATTRIBUTE, null);
|
|
|
|
getASLSession().setAttribute(WfDocsLibrary.WORKFLOW_GIVEN_NAME, null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
InputStream inputStream = DocLibraryUtil.getFileEntryAsStream(getASLSession(), workflowid);
|
|
|
|
String templatePath = myUtil.getTemplateFolder(getVreName(), getUsername()) + "CURRENT_OPEN/";
|
|
|
|
String pathToFile = templatePath;
|
|
|
|
File toExtract = writeReportToDisk(inputStream, pathToFile, "Workflodoc-report.zip");
|
|
|
|
|
|
|
|
File outputDir = new File( myUtil.getTemplatePath("", getVreName(), getUsername()) );
|
|
|
|
ZipUtil.unzipArchive(toExtract, outputDir);
|
|
|
|
toExtract.delete();
|
|
|
|
|
|
|
|
|
|
|
|
FileInputStream fis = null;
|
|
|
|
ObjectInputStream in = null;
|
2013-03-01 19:42:50 +01:00
|
|
|
Model toConvert = null;
|
2013-02-06 23:25:43 +01:00
|
|
|
try {
|
|
|
|
String path = myUtil.getTemplateFolder(getVreName(), getUsername());
|
2013-11-13 18:56:13 +01:00
|
|
|
|
2013-11-07 19:00:34 +01:00
|
|
|
String reportFileName = seekModel(templatePath, UUID.randomUUID().toString()); //random name just to make sure it look for the name
|
|
|
|
String pathToReport = path + "CURRENT_OPEN/"+reportFileName+".d4st";
|
|
|
|
_log.trace("WF PathToReport = " + pathToReport);
|
|
|
|
fis = new FileInputStream(pathToReport);
|
2013-02-06 23:25:43 +01:00
|
|
|
in = new ObjectInputStream(fis);
|
2013-03-01 19:42:50 +01:00
|
|
|
toConvert = (Model) in.readObject();
|
2013-02-06 23:25:43 +01:00
|
|
|
in.close();
|
|
|
|
} catch (IOException ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
} catch (ClassNotFoundException ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
toConvert.setTemplateName(documentName);
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("Converting fileToRead to Serializable object, model name: \n" + toConvert.getTemplateName());
|
2013-03-01 19:42:50 +01:00
|
|
|
Model toReturn = (toConvert);
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
//saves this model as previous one in session
|
|
|
|
getASLSession().setAttribute(PREVIOUS_REPORT_INSTANCE, toConvert);
|
|
|
|
|
|
|
|
AccessLogger log = AccessLogger.getAccessLogger();
|
|
|
|
OpenWorkflowLogEntry logEntry = new OpenWorkflowLogEntry(toConvert.getTemplateName(), toConvert.getUniqueID(), toConvert.getAuthor());
|
|
|
|
log.logEntry(getASLSession().getUsername(), getASLSession().getScopeName(), logEntry);
|
|
|
|
|
|
|
|
return toReturn;
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the report instance from the Basket
|
|
|
|
* @param repTmp .
|
|
|
|
* @param pathToFile the directory where to save the file
|
|
|
|
* @param filename the filename to give to the newly created file
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
private File writeReportToDisk(InputStream isData, String pathToFile, String filename) {
|
|
|
|
try {
|
|
|
|
File dir = new File(pathToFile);
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("DIR: " + pathToFile);
|
2013-02-06 23:25:43 +01:00
|
|
|
if (! dir.exists() )
|
|
|
|
dir.mkdirs();
|
|
|
|
|
|
|
|
File f = new File(pathToFile+filename);
|
|
|
|
OutputStream out = new FileOutputStream(f);
|
|
|
|
|
|
|
|
IOUtils.copy(isData, out);
|
|
|
|
out.close();
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("Successfully WROTE ReportTemplate from DL: " + pathToFile);
|
2013-02-06 23:25:43 +01:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
catch (IOException e){
|
|
|
|
e.printStackTrace();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* update the Workflow Document in session
|
|
|
|
*/
|
2013-05-06 17:38:24 +02:00
|
|
|
public void updateWorkflowDocument(Model toSave, boolean update) {
|
2013-02-06 23:25:43 +01:00
|
|
|
ASLSession session = getASLSession();
|
|
|
|
ServiceUtil myUtil = new ServiceUtil(session);
|
|
|
|
|
|
|
|
String workflowid = session.getAttribute(WfDocsLibrary.LAST_WORKFLOW_ID).toString();
|
2013-03-01 19:42:50 +01:00
|
|
|
Model model = null;
|
2013-02-06 23:25:43 +01:00
|
|
|
String documentWorkflowOwnerId = store.getWorkflowById(workflowid).getAuthor();
|
|
|
|
String documentWorkflowName = store.getWorkflowById(workflowid).getName();
|
|
|
|
if (update) {
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("SAVING in WorkflowDocument Library ");
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-05-06 17:38:24 +02:00
|
|
|
model = (Model) toSave;
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("Trying to convert dynamic images ... ");
|
2013-04-29 17:27:29 +02:00
|
|
|
convertDynamicImagesFromHL(model);
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
boolean result = myUtil.writeModel(model, "CURRENT_OPEN", getVreName(), getUsername());
|
|
|
|
|
|
|
|
if (!result) {
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.error("Could not save report, serializing failed");
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
String templatePath = myUtil.getTemplateFolder(getVreName(), getUsername()) + "CURRENT_OPEN";
|
|
|
|
try {
|
|
|
|
Thread.sleep(1000);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("Trying to zip folder: " + templatePath);
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
String folderToZip = templatePath;
|
|
|
|
String outZip = templatePath+"-report.zip";
|
|
|
|
|
|
|
|
try {
|
|
|
|
ZipUtil.zipDir(outZip, folderToZip);
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.debug("Folder zipped, result: "+ outZip);
|
2013-02-06 23:25:43 +01:00
|
|
|
InputStream isZip = new BufferedInputStream(new FileInputStream(outZip));
|
|
|
|
|
|
|
|
DocLibraryUtil.updateFileIntoDocLibrary(getASLSession(), workflowid, getBytesFromInputStream(isZip));
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.info("Updated in DOC LIB OK");
|
2013-02-06 23:25:43 +01:00
|
|
|
store.addWorkflowLogAction(workflowid, getASLSession().getUsername(), "Updated");
|
|
|
|
|
|
|
|
//send the notification
|
|
|
|
NotificationsManager nm = new ApplicationNotificationsManager(session, "org.gcube.admin.portlet.wfdocviewer.server.WorkflowDocServiceImpl");
|
|
|
|
nm.notifyDocumentWorkflowUpdate(documentWorkflowOwnerId, workflowid, documentWorkflowName);
|
|
|
|
|
|
|
|
AccessLogger log = AccessLogger.getAccessLogger();
|
|
|
|
SaveWorkflowLogEntry logEntry = new SaveWorkflowLogEntry(model.getTemplateName(), model.getUniqueID(), model.getAuthor());
|
|
|
|
log.logEntry(getASLSession().getUsername(), getASLSession().getScopeName(), logEntry);
|
|
|
|
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.error("Could not zip template, serializing failed");
|
2013-02-06 23:25:43 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
store.addWorkflowLogAction(workflowid, getASLSession().getUsername(), "Viewed");
|
|
|
|
//send the notification
|
|
|
|
NotificationsManager nm = new ApplicationNotificationsManager(session, "org.gcube.admin.portlet.wfdocviewer.server.WorkflowDocServiceImpl");
|
|
|
|
nm.notifyDocumentWorkflowView(documentWorkflowOwnerId, workflowid, documentWorkflowName);
|
|
|
|
}
|
|
|
|
//unlocks
|
|
|
|
unlock(workflowid);
|
|
|
|
getASLSession().setAttribute("idreport", null);
|
|
|
|
}
|
2013-03-05 15:26:22 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return the info about the current user
|
|
|
|
*/
|
|
|
|
private UserBean getUserBean() {
|
|
|
|
try {
|
|
|
|
|
|
|
|
String username = getASLSession().getUsername();
|
|
|
|
String email = username+"@isti.cnr.it";
|
|
|
|
String fullName = username+" FULL";
|
|
|
|
String thumbnailURL = "images/Avatar_default.png";
|
|
|
|
|
|
|
|
if (withinPortal) {
|
|
|
|
|
|
|
|
UserModel user = UserLocalServiceUtil.getUserByScreenName(OrganizationsUtil.getCompany().getCompanyId(), username);
|
|
|
|
thumbnailURL = "/image/user_male_portrait?img_id="+user.getPortraitId();
|
|
|
|
fullName = user.getFirstName() + " " + user.getLastName();
|
|
|
|
email = user.getEmailAddress();
|
|
|
|
UserBean toReturn = new UserBean(username, fullName, thumbnailURL, user.getEmailAddress());
|
|
|
|
_log.info("Returning USER: " + toReturn);
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
UserBean toReturn = new UserBean(getASLSession().getUsername(), fullName, thumbnailURL, email);
|
|
|
|
_log.info("Returning test USER: " + toReturn);
|
|
|
|
return toReturn;
|
|
|
|
}
|
2013-02-06 23:25:43 +01:00
|
|
|
|
2013-03-05 15:26:22 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return new UserBean();
|
|
|
|
}
|
2013-02-06 23:25:43 +01:00
|
|
|
/**
|
|
|
|
*/
|
|
|
|
byte[] getBytesFromInputStream(InputStream is) {
|
|
|
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
|
|
|
try {
|
|
|
|
IOUtils.copy(is, os);
|
|
|
|
} catch (IOException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return os.toByteArray();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param workflowid .
|
|
|
|
*/
|
|
|
|
private void unlock(String workflowid) {
|
|
|
|
DLFileEntry fileEntry;
|
|
|
|
try {
|
|
|
|
fileEntry = DocLibraryUtil.getFileEntry(getASLSession(), workflowid);
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.info("Log action saved, trying ot unlock document ...");
|
2013-02-06 23:25:43 +01:00
|
|
|
LockLocalServiceUtil.unlock(DLFileEntry.class.getName(), fileEntry.getFileEntryId());
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.info("UNLOCK OK!");
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void renewLock() {
|
|
|
|
HttpSession httpSes = this.getThreadLocalRequest().getSession();
|
|
|
|
httpSes.setMaxInactiveInterval(-1); //session won't expire
|
|
|
|
String workflowid = getASLSession().getAttribute(WfDocsLibrary.LAST_WORKFLOW_ID).toString();
|
|
|
|
try {
|
|
|
|
DLFileEntry fileEntry = DocLibraryUtil.getFileEntry(getASLSession(), workflowid);
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.info("Renewing Lock ...");
|
2013-02-06 23:25:43 +01:00
|
|
|
long fifteenMin = 900000;
|
|
|
|
Date currTimePlus15 = new Date(new Date().getTime() + fifteenMin);
|
|
|
|
LockLocalServiceUtil.getLock(DLFileEntry.class.getName(), fileEntry.getFileEntryId()).setExpirationDate(currTimePlus15);
|
2013-03-05 15:26:22 +01:00
|
|
|
_log.info("Lock Renewed, expiring: " + currTimePlus15);
|
2013-02-06 23:25:43 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-03-15 19:06:43 +01:00
|
|
|
@Override
|
|
|
|
public String save(String filePath, String workspaceFolderId, String itemName, TypeExporter type, boolean overwrite) throws SaveReportFileException, SaveReportFileExistException {
|
|
|
|
try {
|
|
|
|
File file = new File(filePath);
|
|
|
|
|
2013-10-09 14:21:50 +02:00
|
|
|
Workspace workspace = HomeLibrary.getUserWorkspace(getASLSession().getUsername());
|
2013-03-15 19:06:43 +01:00
|
|
|
_log.info("Saving in Workspace of " + workspace.getOwner().getPortalLogin());
|
|
|
|
WorkspaceFolder folder = (workspaceFolderId != null)?
|
|
|
|
(WorkspaceFolder)workspace.getItem(workspaceFolderId):workspace.getRoot();
|
2013-03-16 02:53:00 +01:00
|
|
|
|
|
|
|
itemName = itemName + "." + type.toString().toLowerCase();
|
|
|
|
if (workspace.exists(itemName, folder.getId())) {
|
|
|
|
if (overwrite)
|
|
|
|
workspace.remove(itemName, folder.getId());
|
|
|
|
else
|
|
|
|
throw new SaveReportFileException("The item " + itemName + " already exists");
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case PDF:
|
|
|
|
return folder.createExternalPDFFileItem(itemName,
|
|
|
|
"", null, new FileInputStream(file)).getId();
|
|
|
|
|
|
|
|
case HTML:
|
|
|
|
return folder.createExternalFileItem(itemName,
|
|
|
|
"", "text/html", new FileInputStream(file)).getId();
|
|
|
|
case DOCX:
|
|
|
|
return folder.createExternalFileItem(itemName,
|
|
|
|
"", "application/msword", new FileInputStream(file)).getId();
|
|
|
|
|
|
|
|
case XML:
|
|
|
|
return folder.createExternalFileItem(itemName,
|
|
|
|
"", "application/xml", new FileInputStream(file)).getId();
|
|
|
|
}
|
|
|
|
throw new SaveReportFileException("Unknown file type");
|
2013-03-15 19:06:43 +01:00
|
|
|
} catch (ItemAlreadyExistException e) {
|
|
|
|
throw new SaveReportFileExistException(e.getMessage());
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new SaveReportFileException(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-30 16:16:20 +02:00
|
|
|
@Override
|
|
|
|
public void renewHTTPSession() {
|
|
|
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
|
|
|
_log.info("HTTP Session renewed" + new Date(session.getLastAccessedTime()));
|
|
|
|
}
|
2013-11-13 18:56:13 +01:00
|
|
|
|
|
|
|
@Override
|
2013-11-25 17:12:01 +01:00
|
|
|
public ArrayList<VMEReportBean> listVMEReports() {
|
2013-11-13 18:56:13 +01:00
|
|
|
try {
|
|
|
|
Thread.sleep(1000);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
}
|
2013-11-25 17:12:01 +01:00
|
|
|
ArrayList<VMEReportBean> toReturn = new ArrayList<VMEReportBean>();
|
2013-11-13 18:56:13 +01:00
|
|
|
ReportType type = new ReportType();
|
|
|
|
type.setTypeIdentifier("Vme");
|
|
|
|
|
|
|
|
for (ReportEntry re : getFakeReports(type)) {
|
2013-11-25 17:12:01 +01:00
|
|
|
String rfmo = re.getNameValueList().get(0).getValue();
|
|
|
|
String name = re.getNameValueList().get(1).getValue();
|
|
|
|
int year = Integer.parseInt(re.getNameValueList().get(2).getValue());
|
|
|
|
toReturn.add(new VMEReportBean(""+re.getId(), rfmo, name, year));
|
2013-11-13 18:56:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-11-25 19:11:03 +01:00
|
|
|
public ArrayList<VMEReportBean> listVMEReportRefByType(VMETypeIdentifier refType) {
|
2013-11-13 18:56:13 +01:00
|
|
|
if (refType == VMETypeIdentifier.Vme)
|
|
|
|
throw new IllegalArgumentException("VME Type is not a reference");
|
|
|
|
try {
|
|
|
|
Thread.sleep(1000);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
}
|
2013-11-25 19:11:03 +01:00
|
|
|
ArrayList<VMEReportBean> toReturn = new ArrayList<VMEReportBean>();
|
2013-11-13 18:56:13 +01:00
|
|
|
ReportType type = new ReportType();
|
|
|
|
type.setTypeIdentifier(refType.toString());
|
2013-11-26 18:37:13 +01:00
|
|
|
|
2013-11-13 18:56:13 +01:00
|
|
|
for (ReportEntry re : getFakeReports(type)) {
|
2013-11-25 19:11:03 +01:00
|
|
|
String name = re.getNameValueList().get(0).getValue();
|
|
|
|
toReturn.add(new VMEReportBean(""+re.getId(), "", name, -1));
|
2013-11-13 18:56:13 +01:00
|
|
|
}
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
|
2013-11-26 18:37:13 +01:00
|
|
|
|
2013-11-25 17:12:01 +01:00
|
|
|
private List<ReportEntry> getFakeReports(ReportType type, NameValue... filters) {
|
2013-11-13 18:56:13 +01:00
|
|
|
Random generator = new Random();
|
|
|
|
int n = generator.nextInt(15) + 5;
|
|
|
|
ArrayList<ReportEntry> toReturn = new ArrayList<ReportEntry>();
|
2013-11-25 17:12:01 +01:00
|
|
|
if (type.getTypeIdentifier().equals("Vme")) {
|
2013-11-13 18:56:13 +01:00
|
|
|
ReportEntry re = new ReportEntry();
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
re = new ReportEntry();
|
|
|
|
re.setId(i);
|
2013-11-26 18:37:13 +01:00
|
|
|
|
2013-11-25 17:12:01 +01:00
|
|
|
NameValue rfmo = new NameValue();
|
|
|
|
rfmo.setName("Rfmo");
|
|
|
|
rfmo.setValue(i % 2 == 0 ? "NAFO" : "NEAFC");
|
2013-11-22 18:28:12 +01:00
|
|
|
NameValue name = new NameValue();
|
2013-11-25 17:12:01 +01:00
|
|
|
name.setName("Vme");
|
|
|
|
name.setValue("VME " + generateRandomWord());
|
|
|
|
NameValue year = new NameValue();
|
|
|
|
year.setName("Year");
|
|
|
|
year.setValue(""+(2000+generator.nextInt(15)));
|
|
|
|
List<NameValue> namesValues = new ArrayList<NameValue>();
|
|
|
|
namesValues.add(rfmo);
|
2013-11-22 18:28:12 +01:00
|
|
|
namesValues.add(name);
|
2013-11-25 17:12:01 +01:00
|
|
|
namesValues.add(year);
|
2013-11-26 18:37:13 +01:00
|
|
|
|
2013-11-22 18:28:12 +01:00
|
|
|
re.setNameValueList(namesValues);
|
2013-11-13 18:56:13 +01:00
|
|
|
toReturn.add(re);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ReportEntry re = new ReportEntry();
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
re = new ReportEntry();
|
|
|
|
re.setId(i);
|
2013-11-22 18:28:12 +01:00
|
|
|
List<NameValue> namesValues = new ArrayList<NameValue>();
|
|
|
|
NameValue name = new NameValue();
|
|
|
|
name.setName(type.getTypeIdentifier() + "-" + i);
|
2013-11-25 19:11:03 +01:00
|
|
|
name.setValue(type.getTypeIdentifier() + "-" + generateRandomWord());
|
2013-11-22 18:28:12 +01:00
|
|
|
namesValues.add(name);
|
|
|
|
re.setNameValueList(namesValues);
|
2013-11-13 18:56:13 +01:00
|
|
|
toReturn.add(re);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-11-26 18:37:13 +01:00
|
|
|
public Model importVMEReport(String id, VMETypeIdentifier refType) {
|
|
|
|
ReportsModeler rm = null;
|
|
|
|
if (refType == VMETypeIdentifier.Vme) {
|
|
|
|
String reportName = "Sample VME Report imported with id: " + id;
|
|
|
|
rm = new ReportsModeler(
|
|
|
|
UUID.randomUUID().toString(),
|
|
|
|
reportName,
|
|
|
|
getASLSession().getUsername(),
|
|
|
|
new Date(),
|
|
|
|
new Date(),
|
|
|
|
getASLSession().getUsername()
|
|
|
|
);
|
|
|
|
rm.add(new Instruction(null));
|
|
|
|
rm.add(new Title("Name for id " + id, false));
|
|
|
|
rm.add(new Heading(1, "VME Name (Non Editable) "));
|
|
|
|
rm.add(new TextInput("Corner Rise Seamounts"));
|
|
|
|
rm.add(new Heading(2, "This is a Heading of Level 2 that is editable"));
|
|
|
|
rm.add(new TextInput("Corner Rise Seamounts again"));
|
|
|
|
rm.add(new TextInput());
|
|
|
|
rm.nextSection();
|
|
|
|
rm = addSection2(rm);
|
|
|
|
rm.nextSection();
|
|
|
|
ReportComponent rp = new TextInput("With props and id");
|
|
|
|
rp.setId(UUID.randomUUID().toString());
|
|
|
|
rp.setProperties(new Property("theId", "theValue"));
|
|
|
|
rm.add(rp);
|
|
|
|
|
|
|
|
rp = new Heading(1, "Ciao!");
|
|
|
|
rp.setId(UUID.randomUUID().toString());
|
|
|
|
rp.setProperties(new Property("theId", "theValue"));
|
|
|
|
rm.add(rp);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
String reportName = refType.getId() + " VME Reference Report with id: " + id;
|
|
|
|
rm = new ReportsModeler(
|
|
|
|
UUID.randomUUID().toString(),
|
|
|
|
reportName,
|
|
|
|
getASLSession().getUsername(),
|
|
|
|
new Date(),
|
|
|
|
new Date(),
|
|
|
|
getASLSession().getUsername()
|
|
|
|
);
|
|
|
|
rm.add(new Title("Test" + refType.getId()));
|
|
|
|
rm.add(new Heading(2, "Year"));
|
|
|
|
rm.add(new TextInput());
|
|
|
|
rm.add(new Heading(2, "Validity Period - Start"));
|
|
|
|
rm.add(new TextInput());
|
|
|
|
rm.add(new Heading(2, "Validity Period - End"));
|
|
|
|
rm.add(new TextInput());
|
|
|
|
rm.add(getTestReference(ReferenceReportType.InformationSource, false));
|
|
|
|
rm.add(new Heading(1, "Ciao!"));
|
|
|
|
}
|
2013-11-13 18:56:13 +01:00
|
|
|
try {
|
|
|
|
return rm.getReportInstance();
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-11-26 18:37:13 +01:00
|
|
|
@Override
|
|
|
|
public Model getVMEReportRef2Associate(String id, VMETypeIdentifier refType) {
|
2013-11-25 19:11:03 +01:00
|
|
|
String reportName = "Sample Reference Report: " + id;
|
2013-11-14 16:26:26 +01:00
|
|
|
ReportsModeler rm = new ReportsModeler(
|
|
|
|
UUID.randomUUID().toString(),
|
|
|
|
reportName,
|
|
|
|
getASLSession().getUsername(),
|
|
|
|
new Date(),
|
|
|
|
new Date(),
|
|
|
|
getASLSession().getUsername()
|
|
|
|
);
|
|
|
|
//construct the options (the references)
|
|
|
|
ArrayList<DBTableRow> dBTableRows = new ArrayList<DBTableRow>();
|
|
|
|
|
2013-11-22 18:28:12 +01:00
|
|
|
ArrayList<Column> md = new ArrayList<Column>();
|
2013-11-18 18:25:49 +01:00
|
|
|
|
2013-11-14 16:26:26 +01:00
|
|
|
Random generator = new Random();
|
|
|
|
int year = generator.nextInt(15) + 2000;
|
2013-11-18 18:25:49 +01:00
|
|
|
//construct the references
|
2013-11-22 18:28:12 +01:00
|
|
|
md.add(new Column("Meeting Date", ""+year));
|
|
|
|
md.add(new Column("Report Summary", "Aenean vulputate ac dui eu interdum. Nullam tincidunt hendrerit sollicitudin."));
|
|
|
|
md.add(new Column("Committee", "Lorem ipsum dolor sit amet, consectetur adipiscing elit"));
|
|
|
|
md.add(new Column("URL", "http://archive.nafo.int/open/fc/2012/fcdoc12-01.pdf"));
|
|
|
|
md.add(new Column("Citation", "(Rossi et Al) adipiscing elit oekfha lfkahjf lakjfha lkfahjf alkjdfh "));
|
|
|
|
md.add(new Column("Type", "The type"));
|
2013-11-18 18:25:49 +01:00
|
|
|
dBTableRows.add(new DBTableRow("primaryKey", md));
|
2013-11-22 18:28:12 +01:00
|
|
|
rm.add(new ReferenceReport(ReferenceReportType.InformationSource, dBTableRows));
|
2013-11-14 16:26:26 +01:00
|
|
|
try {
|
2013-11-25 19:11:03 +01:00
|
|
|
Model toReturn = rm.getReportInstance();
|
2013-11-26 18:37:13 +01:00
|
|
|
//ReportsReader.readReportStructure(toReturn);
|
2013-11-25 19:11:03 +01:00
|
|
|
return toReturn;
|
2013-11-14 16:26:26 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-11-26 18:37:13 +01:00
|
|
|
|
2013-11-18 18:25:49 +01:00
|
|
|
private ReportsModeler addSection2(ReportsModeler rm) {
|
2013-11-22 18:28:12 +01:00
|
|
|
rm.add(new Heading(1, "Specific Measure"));
|
|
|
|
ReportSequence seq = new ReportSequence(UUID.randomUUID().toString());
|
|
|
|
seq.add(new Heading(2, "Year"));
|
|
|
|
seq.add(new TextInput());
|
|
|
|
seq.add(new Heading(2, "Validity Period - Start"));
|
|
|
|
seq.add(new TextInput());
|
|
|
|
seq.add(new Heading(2, "Validity Period - End"));
|
|
|
|
seq.add(new TextInput());
|
2013-11-26 18:37:13 +01:00
|
|
|
seq.add(getTestReference(ReferenceReportType.InformationSource, true));
|
|
|
|
rm.add(seq);
|
|
|
|
return rm;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* TODO: remove
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
private ReferenceReport getTestReference(ReferenceReportType type, boolean single) {
|
2013-11-18 18:25:49 +01:00
|
|
|
//construct the options (the references)
|
|
|
|
ArrayList<DBTableRow> dBTableRows = new ArrayList<DBTableRow>();
|
|
|
|
|
2013-11-22 18:28:12 +01:00
|
|
|
ArrayList<Column> md = new ArrayList<Column>();
|
2013-11-26 18:37:13 +01:00
|
|
|
|
|
|
|
Random generator = new Random();
|
|
|
|
int year = generator.nextInt(15) + 2000;
|
2013-11-18 18:25:49 +01:00
|
|
|
//construct the references
|
2013-11-26 18:37:13 +01:00
|
|
|
md.add(new Column("Meeting Date", ""+year));
|
2013-11-22 18:28:12 +01:00
|
|
|
md.add(new Column("Report Summary", "Aenean vulputate ac dui eu interdum. Nullam tincidunt hendrerit sollicitudin."));
|
|
|
|
md.add(new Column("Committee", "Lorem ipsum dolor sit amet, consectetur adipiscing elit"));
|
|
|
|
md.add(new Column("URL", "http://archive.nafo.int/open/fc/2012/fcdoc12-01.pdf"));
|
|
|
|
md.add(new Column("Citation", "(Rossi et Al) adipiscing elit oekfha lfkahjf lakjfha lkfahjf alkjdfh "));
|
|
|
|
md.add(new Column("Type", "The type"));
|
2013-11-18 18:25:49 +01:00
|
|
|
dBTableRows.add(new DBTableRow("primaryKey", md));
|
2013-11-26 18:37:13 +01:00
|
|
|
return new ReferenceReport(type, dBTableRows, single);
|
2013-11-18 18:25:49 +01:00
|
|
|
}
|
2013-11-25 17:12:01 +01:00
|
|
|
/**
|
|
|
|
* TODO: remove once you get real names
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
private static String generateRandomWord() {
|
2013-11-26 18:37:13 +01:00
|
|
|
Random random = new Random();
|
|
|
|
char[] word = new char[random.nextInt(7)+5]; // words of length 5 through 12
|
|
|
|
for(int j = 0; j < word.length; j++) {
|
|
|
|
word[j] = (char)('a' + random.nextInt(26));
|
|
|
|
}
|
|
|
|
return new String(word);
|
2013-11-25 17:12:01 +01:00
|
|
|
}
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|