Commit 8dfb62e3 by Pradip J. Sabhadiya

Added csv uplod screen and fp

parent 57f7d349
<?xml version="1.0" encoding="UTF-8"?>
<!-- @AutoRun -->
<OBJECTS name="" xmlns:oneit="http://www.1iT.com.au"><NODE name="Script" factory="Vector">
<NODE name="DDL" factory="Participant" class="oneit.sql.transfer.DefineTableOperation">
<tableName factory="String">it_does_not_matter</tableName>
<column name="object_id" type="Long" nullable="false" length="11"/>
<column name="object_last_updated_date" type="Date" nullable="false" length="22"/>
<column name="object_created_date" type="Date" nullable="false" length="22"/>
<column name="xxxx" type="BLOB" nullable="false"/>
</NODE>
</NODE></OBJECTS>
\ No newline at end of file
-- DROP TABLE it_does_not_matter;
CREATE TABLE it_does_not_matter (
object_id int NOT NULL ,
object_last_updated_date datetime DEFAULT getdate() NOT NULL ,
object_created_date datetime DEFAULT getdate() NOT NULL
,
xxxx image NOT NULL
);
ALTER TABLE it_does_not_matter ADD
CONSTRAINT PK_it_does_not_matter PRIMARY KEY
(
object_id
) ;
\ No newline at end of file
-- DROP TABLE it_does_not_matter;
CREATE TABLE it_does_not_matter (
object_id number(12) NOT NULL ,
object_last_updated_date date DEFAULT SYSDATE NOT NULL ,
object_created_date date DEFAULT SYSDATE NOT NULL
,
xxxx blob NOT NULL
);
ALTER TABLE it_does_not_matter ADD
CONSTRAINT PK_it_does_not_matter PRIMARY KEY
(
object_id
) ;
\ No newline at end of file
-- @AutoRun
-- drop table it_does_not_matter;
CREATE TABLE it_does_not_matter (
object_id numeric(12) NOT NULL ,
object_last_updated_date timestamp DEFAULT NOW() NOT NULL ,
object_created_date timestamp DEFAULT NOW() NOT NULL
,
xxxx bytea NOT NULL
);
ALTER TABLE it_does_not_matter ADD
CONSTRAINT pk_it_does_not_matter PRIMARY KEY
(
object_id
) ;
\ No newline at end of file
package performa.form;
import java.io.*;
import java.util.*;
import javax.servlet.http.*;
import oneit.logging.*;
import oneit.objstore.*;
import oneit.objstore.parser.BusinessObjectParser;
import oneit.servlets.forms.*;
import oneit.servlets.jsp.TableTag;
import oneit.servlets.portability.FileDownloader;
import oneit.servlets.process.*;
import oneit.utils.*;
import oneit.utils.table.*;
import performa.orm.TestAnalysis;
/**
*
* @author Pradip J. Sabhadiya
*/
public class ImportCSVFP extends ORMProcessFormProcessor
{
private static List<String> SUPPORTED_TYPES = new ArrayList<>(Arrays.asList("text/csv", "text/plain"));
@Override
public SuccessfulResult processForm(ORMProcessState process, SubmissionDetails submission, Map params) throws BusinessException, StorageException
{
TestAnalysis testAnalysis = (TestAnalysis) process.getAttribute("TestAnalysis");
ByteArrayOutputStream bos = new ByteArrayOutputStream ();
byte[] bytes ;
//TO-DO -> "filecontent" processing
try
{
ExcelExporter.ExportAppender excelRenderer = getExportAppender(testAnalysis.getCSV());
excelRenderer.export(bos);
bytes = bos.toByteArray();
}
catch(IOException ioe)
{
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, ioe, "Exception occurred while Creating Excel File.");
throw new BusinessException(ioe.getMessage());
}
return (HttpServletRequest request, HttpServletResponse response) ->
{
FileDownloader.writeData(request, response, bytes, TableTag.EXCEL_MIME_TYPE, "Result.xls", false);
};
}
private static ExcelExporter.ExportAppender getExportAppender(BinaryContent file) throws IOException
{
Properties props = new Properties();
props.load(ImportCSVFP.class.getClassLoader().getResourceAsStream("excel-styles.properties"));
props.put("subheader.font-style", "bold");
props.put("header.horizontal-alignment", "center");
props.put("header.font-style", "bold");
props.put("header.cell-background", "black");
ExcelExporter.ExportAppender exportAppender = new ExcelExporter(props).getAppender();
exportAppender.appendTable("New Sheet", 1, getExcelContent(file));
return exportAppender;
}
private static SingleValueTableModel getExcelContent(BinaryContent file)
{
SingleValueTableModel model = new SingleValueTableModel(); // TO-DO Converting To Excel
model.addCell(0, 0, new SingleValueTableModel.CellModel(file.getName(), ""));
return model;
}
@Override
public void validate(ORMProcessState process, SubmissionDetails submission, MultiException exceptions, Map params) throws StorageException
{
super.validate(process, submission, exceptions, params);
TestAnalysis testAnalysis = (TestAnalysis) process.getAttribute("TestAnalysis");
Debug.assertion(testAnalysis != null, "Test Analysis is null while Processing CSV File.");
if(testAnalysis.getCSV() != null)
{
BusinessObjectParser.assertFieldCondition(SUPPORTED_TYPES.contains(testAnalysis.getCSV().getContentType()), testAnalysis, TestAnalysis.FIELD_CSV, "invalid", exceptions, true, submission.getRequest());
}
}
}
package performa.orm;
public class TestAnalysis extends BaseTestAnalysis
{
private static final long serialVersionUID = 0L;
// This constructor should not be called
public TestAnalysis ()
{
// Do not add any code to this, always put it in initialiseNewObject
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
<BUSINESSCLASS name="TestAnalysis" package="performa.orm" superclass="NonPersistentBO">
<IMPORT value="oneit.servlets.orm.*"/>
<TABLE name="it_does_not_matter" tablePrefix="OBJECT" polymorphic="FALSE">
<ATTRIB name="CSV" type="BinaryContent" dbcol="xxxx" binaryHandler="loggedin" mandatory="true" attribHelper="BLOBAttributeHelper" attribHelperInstance="BLOBAttributeHelper.INSTANCE" />
</TABLE>
</BUSINESSCLASS>
</ROOT>
\ No newline at end of file
<?xml version="1.0"?>
<OBJECTS name="FOO">
<NODE name="testAnalysis_jsp" factory="Participant">
<INHERITS factory="Named" nodename="CoreORMAdmin"/>
<FORM name="*.importCSV" factory="Participant" class="performa.form.ImportCSVFP"/>
</NODE>
</OBJECTS>
\ No newline at end of file
<?xml version="1.0"?>
<OBJECTS name="">
<NODE name="UI_Factories::PERFORMA">
<NODE name="PERFORMA" factory="Participant" class="oneit.servlets.jsp.ui.DefaultUICustomiser">
<TOPMENU name="MENU.TEST_ANALYSIS" desc="Test Analysis" sortOrder="100" factory="Participant" class="oneit.servlets.jsp.ui.DefaultUICustomiser$Element" link="/extensions/performa/testAnalysis.jsp"/>
</NODE>
</NODE>
</OBJECTS>
\ No newline at end of file
<%@ page import="performa.orm.*, performa.orm.types.*, performa.form.*, performa.utils.*"%>
\ No newline at end of file
<%@ page extends="oneit.servlets.jsp.FormJSP"%>
<%@ include file="/setuprequest.jsp"%>
<%@ include file="inc/stdimports.jsp"%>
<%@ include file="/editor/stdimports.jsp"%>
<%! protected String getName (ServletConfig config) { return "testAnalysis_jsp"; } %>
<%
ORMProcessState process = (ORMProcessState) ProcessDecorator.getDefaultProcess(request);
ObjectTransaction objTran = process.getTransaction ();
String module = "TestAnalysis";
TestAnalysis testAnalysis = (TestAnalysis) process.getAttribute(module);
if(testAnalysis == null)
{
testAnalysis = TestAnalysis.createTestAnalysis(objTran);
process.setAttribute(module, testAnalysis);
%><%@include file="/saferedirect.jsp"%><%
}
request.setAttribute("oneit.pageFormDetails", CollectionUtils.mapEntry("name", "FormAnalysisEngine").mapEntry("enctype", "multipart/form-data").toMap());
request.setAttribute("oneit.pageHeaderTitle", "Analysis Engine");
%>
<%@include file="/editor/header.jsp"%>
<oneit:layout_total widths="<%= new double[] {1, 4, 7} %>" skin="bootstrap">
<oneit:skin tagName="layout_row">
<oneit:layout_label width="1">
<strong style="line-height: 30px">CSV : </strong>
</oneit:layout_label>
<oneit:layout_field width="1">
<oneit:ormInput obj="<%= testAnalysis %>" attributeName="<%= TestAnalysis.FIELD_CSV %>" type="file" class="form-control" required="required" style="padding:4px;" accept=".csv"/>
</oneit:layout_field>
<oneit:layout_field width="1">
<oneit:button value="Import CSV" name="importCSV" cssClass="btn btn-primary" requestAttribs='<%= CollectionUtils.EMPTY_MAP %>'/>
</oneit:layout_field>
</oneit:skin>
</oneit:layout_total>
<%@include file="/editor/footer.jsp"%>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment