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());
}
}
}
/*
* IMPORTANT!!!! XSL Autogenerated class, DO NOT EDIT!!!!!
* Template: Infrastructure8.2 rev3 [oneit.objstore.BusinessObjectTemplate.xsl]
*
* Version: 1.0
* Vendor: Apache Software Foundation (Xalan XSLTC)
* Vendor URL: http://xml.apache.org/xalan-j
*/
package performa.orm;
import java.io.*;
import java.util.*;
import oneit.appservices.config.*;
import oneit.logging.*;
import oneit.objstore.*;
import oneit.objstore.assocs.*;
import oneit.objstore.attributes.*;
import oneit.objstore.rdbms.filters.*;
import oneit.objstore.parser.*;
import oneit.objstore.validator.*;
import oneit.objstore.utils.*;
import oneit.utils.*;
import oneit.utils.filter.Filter;
import oneit.utils.transform.*;
import oneit.utils.parsers.FieldException;
import oneit.servlets.orm.*;
public abstract class BaseTestAnalysis extends NonPersistentBO
{
// Reference instance for the object
public static final TestAnalysis REFERENCE_TestAnalysis = new TestAnalysis ();
// Reference instance for the object
public static final TestAnalysis DUMMY_TestAnalysis = new DummyTestAnalysis ();
// Static constants corresponding to field names
public static final String FIELD_CSV = "CSV";
// Static constants corresponding to searches
// Static constants corresponding to attribute helpers
private static final BLOBAttributeHelper HELPER_CSV = BLOBAttributeHelper.INSTANCE;
// Private attributes corresponding to business object data
private BinaryContent _CSV;
// Private attributes corresponding to single references
// Private attributes corresponding to multiple references
// Map of maps of metadata
private static final Map ATTRIBUTES_METADATA_TestAnalysis = new HashMap ();
// Arrays of validators for each attribute
private static final AttributeValidator[] FIELD_CSV_Validators;
// Arrays of behaviour decorators
private static final TestAnalysisBehaviourDecorator[] TestAnalysis_BehaviourDecorators;
static
{
try
{
Map validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));
FIELD_CSV_Validators = (AttributeValidator[])setupAttribMetaData_CSV(validatorMapping).toArray (new AttributeValidator[0]);
REFERENCE_TestAnalysis.initialiseReference ();
DUMMY_TestAnalysis.initialiseReference ();
TestAnalysis_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(TestAnalysis.class).toArray(new TestAnalysisBehaviourDecorator[0]);
}
catch (RuntimeException e)
{
LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
throw e;
}
}
// Meta Info setup
private static List setupAttribMetaData_CSV(Map validatorMapping)
{
Map metaInfo = new HashMap ();
metaInfo.put ("attribHelper", "BLOBAttributeHelper");
metaInfo.put ("attribHelperInstance", "BLOBAttributeHelper.INSTANCE");
metaInfo.put ("binaryHandler", "loggedin");
metaInfo.put ("dbcol", "xxxx");
metaInfo.put ("mandatory", "true");
metaInfo.put ("name", "CSV");
metaInfo.put ("type", "BinaryContent");
LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for TestAnalysis.CSV:", metaInfo);
ATTRIBUTES_METADATA_TestAnalysis.put (FIELD_CSV, Collections.unmodifiableMap (metaInfo));
List validators = BaseBusinessClass.getAttribValidators(TestAnalysis.class, "CSV", metaInfo, validatorMapping);
LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Validators for TestAnalysis.CSV:", validators);
return validators;
}
// END OF STATIC METADATA DEFINITION
// This constructor should not be called
protected BaseTestAnalysis ()
{
}
protected BBCBehaviourDecorator[] getBehaviours()
{
return TestAnalysis_BehaviourDecorators;
}
// Initialise the attributes
protected void _initialiseNewObjAttributes (ObjectTransaction transaction) throws StorageException
{
super._initialiseNewObjAttributes (transaction);
_CSV = (BinaryContent)(HELPER_CSV.initialise (_CSV));
}
// Initialise the associations
protected void _initialiseAssociations ()
{
super._initialiseAssociations ();
}
// Initialise the associations
protected BaseBusinessClass initialiseReference ()
{
super.initialiseReference ();
return this;
}
/**
* Get the attribute CSV
*/
public BinaryContent getCSV ()
{
assertValid();
BinaryContent valToReturn = _CSV;
for (TestAnalysisBehaviourDecorator bhd : TestAnalysis_BehaviourDecorators)
{
valToReturn = bhd.getCSV ((TestAnalysis)this, valToReturn);
}
return valToReturn;
}
/**
* Called prior to the attribute changing. Subclasses need not call super. If a field exception
* is thrown, the attribute change will fail. The new value is different to the old value.
*/
protected void preCSVChange (BinaryContent newCSV) throws FieldException
{
}
/**
* Called after the attribute changes.
* If a field exception is thrown, the value is still changed, however it
* may lead to the TX being rolled back
*/
protected void postCSVChange () throws FieldException
{
}
public FieldWriteability getWriteability_CSV ()
{
return getFieldWritabilityUtil (FieldWriteability.TRUE);
}
/**
* Set the attribute CSV. Checks to ensure a new value
* has been supplied. If so, marks the field as altered and sets the attribute.
*/
public void setCSV (BinaryContent newCSV) throws FieldException
{
boolean oldAndNewIdentical = HELPER_CSV.compare (_CSV, newCSV);
try
{
for (TestAnalysisBehaviourDecorator bhd : TestAnalysis_BehaviourDecorators)
{
newCSV = bhd.setCSV ((TestAnalysis)this, newCSV);
oldAndNewIdentical = HELPER_CSV.compare (_CSV, newCSV);
}
BusinessObjectParser.assertFieldCondition (newCSV != null, this, FIELD_CSV, "mandatory");
if (FIELD_CSV_Validators.length > 0)
{
Object newCSVObj = HELPER_CSV.toObject (newCSV);
if (newCSVObj != null)
{
int loopMax = FIELD_CSV_Validators.length;
Map metadata = (Map)ATTRIBUTES_METADATA_TestAnalysis.get (FIELD_CSV);
for (int v = 0 ; v < loopMax ; ++v)
{
FIELD_CSV_Validators[v].checkAttribute (this, FIELD_CSV, metadata, newCSVObj);
}
}
}
}
catch (FieldException e)
{
if (!oldAndNewIdentical)
{
e.setWouldModify ();
}
throw e;
}
if (!oldAndNewIdentical)
{
assertValid();
Debug.assertion (getWriteability_CSV () != FieldWriteability.FALSE, "Field CSV is not writeable");
preCSVChange (newCSV);
markFieldChange (FIELD_CSV);
_CSV = newCSV;
postFieldChange (FIELD_CSV);
postCSVChange ();
}
}
/**
* A list of multi assoc names e.g. list of strings.
*/
public List<String> getSingleAssocs()
{
List result = super.getSingleAssocs ();
return result;
}
public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
{
if (assocName == null)
{
throw new RuntimeException ("Game over == null!");
}
else
{
return super.getSingleAssocReferenceInstance (assocName);
}
}
public String getSingleAssocBackReference(String assocName)
{
if (assocName == null)
{
throw new RuntimeException ("Game over == null!");
}
else
{
return super.getSingleAssocBackReference (assocName);
}
}
public BaseBusinessClass getSingleAssoc (String assocName) throws StorageException
{
if (assocName == null)
{
throw new RuntimeException ("Game over == null!");
}
else
{
return super.getSingleAssoc (assocName);
}
}
public BaseBusinessClass getSingleAssoc (String assocName, Get getType) throws StorageException
{
if (assocName == null)
{
throw new RuntimeException ("Game over == null!");
}
else
{
return super.getSingleAssoc (assocName, getType);
}
}
public Long getSingleAssocID (String assocName) throws StorageException
{
if (assocName == null)
{
throw new RuntimeException ("Game over == null!");
}
else
{
return super.getSingleAssocID (assocName);
}
}
public void setSingleAssoc (String assocName, BaseBusinessClass newValue) throws StorageException, FieldException
{
if (assocName == null)
{
throw new RuntimeException ("Game over == null!");
}
else
{
super.setSingleAssoc (assocName, newValue);
}
}
/**
* A list of multi assoc names e.g. list of strings.
*/
public List<String> getMultiAssocs()
{
List result = super.getMultiAssocs ();
return result;
}
/**
* Get the reference instance for the multi assoc name.
*/
public BaseBusinessClass getMultiAssocReferenceInstance(String attribName)
{
return super.getMultiAssocReferenceInstance(attribName);
}
public String getMultiAssocBackReference(String attribName)
{
return super.getMultiAssocBackReference(attribName);
}
/**
* Get the assoc count for the multi assoc name.
*/
public int getMultiAssocCount(String attribName) throws StorageException
{
return super.getMultiAssocCount(attribName);
}
/**
* Get the assoc at a particular index
*/
public BaseBusinessClass getMultiAssocAt(String attribName, int index) throws StorageException
{
return super.getMultiAssocAt(attribName, index);
}
/**
* Add to a multi assoc by attribute name
*/
public void addToMultiAssoc(String attribName, BaseBusinessClass newElement) throws StorageException
{
super.addToMultiAssoc(attribName, newElement);
}
/**
* Remove from a multi assoc by attribute name
*/
public void removeFromMultiAssoc(String attribName, BaseBusinessClass oldElement) throws StorageException
{
super.removeFromMultiAssoc(attribName, oldElement);
}
protected void __loadMultiAssoc (String attribName, BaseBusinessClass[] elements)
{
super.__loadMultiAssoc(attribName, elements);
}
protected boolean __isMultiAssocLoaded (String attribName)
{
return super.__isMultiAssocLoaded(attribName);
}
public void onDelete ()
{
try
{
}
catch (Exception e)
{
throw NestedException.wrap(e);
}
super.onDelete ();
}
public TestAnalysis newInstance ()
{
return new TestAnalysis ();
}
public TestAnalysis referenceInstance ()
{
return REFERENCE_TestAnalysis;
}
public TestAnalysis getInTransaction (ObjectTransaction t) throws StorageException
{
return getTestAnalysisByID (t, getObjectID());
}
public BaseBusinessClass dummyInstance ()
{
return DUMMY_TestAnalysis;
}
public String getBaseSetName ()
{
return "it_does_not_matter";
}
/**
* This is where an object returns the Persistent sets that will
* store it into the database.
* The should be entered into allSets
*/
public void getPersistentSets (PersistentSetCollection allSets)
{
ObjectStatus myStatus = getStatus ();
PersistentSetStatus myPSetStatus = myStatus.getPSetStatus();
ObjectID myID = getID();
super.getPersistentSets (allSets);
PersistentSet it_does_not_matterPSet = allSets.getPersistentSet (myID, "it_does_not_matter", myPSetStatus);
it_does_not_matterPSet.setAttrib (FIELD_ObjectID, myID);
it_does_not_matterPSet.setAttrib (FIELD_CSV, HELPER_CSV.toObject (_CSV)); //
}
/**
* Sets the objects state based on Persistent sets.
*/
public void setFromPersistentSets (ObjectID objectID, PersistentSetCollection allSets)
{
super.setFromPersistentSets (objectID, allSets);
PersistentSet it_does_not_matterPSet = allSets.getPersistentSet (objectID, "it_does_not_matter");
_CSV = (BinaryContent)(HELPER_CSV.fromObject (_CSV, it_does_not_matterPSet.getAttrib (FIELD_CSV))); //
}
public void setAttributesFrom (BaseBusinessClass other, MultiException e)
{
super.setAttributesFrom (other, e);
if (other instanceof TestAnalysis)
{
TestAnalysis otherTestAnalysis = (TestAnalysis)other;
try
{
setCSV (otherTestAnalysis.getCSV ());
}
catch (FieldException ex)
{
e.addException (ex);
}
}
}
/**
* Set the attributes in this to copies of the attributes in source.
*/
public void copyAttributesFrom (BaseBusinessClass source)
{
super.copyAttributesFrom (source);
if (source instanceof BaseTestAnalysis)
{
BaseTestAnalysis sourceTestAnalysis = (BaseTestAnalysis)(source);
_CSV = sourceTestAnalysis._CSV;
}
}
/**
* Set the associations in this to copies of the attributes in source.
*/
public void copySingleAssociationsFrom (BaseBusinessClass source, boolean linkToGhosts)
{
super.copySingleAssociationsFrom (source, linkToGhosts);
if (source instanceof BaseTestAnalysis)
{
BaseTestAnalysis sourceTestAnalysis = (BaseTestAnalysis)(source);
}
}
/**
* Set the associations in this to copies of the attributes in source.
*/
public void copyAssociationsFrom (BaseBusinessClass source, boolean linkToGhosts)
{
super.copyAssociationsFrom (source, linkToGhosts);
if (source instanceof BaseTestAnalysis)
{
BaseTestAnalysis sourceTestAnalysis = (BaseTestAnalysis)(source);
}
}
public void validate (ValidationContext context)
{
super.validate (context);
}
/**
* Subclasses must override this to read in their attributes
*/
protected void readExternalData(Map<String, Object> vals) throws IOException, ClassNotFoundException
{
super.readExternalData(vals);
_CSV = (BinaryContent)(HELPER_CSV.readExternal (_CSV, vals.get(FIELD_CSV))); //
}
/**
* Subclasses must override this to write out their attributes
*/
protected void writeExternalData(Map<String, Object> vals) throws IOException
{
super.writeExternalData(vals);
vals.put (FIELD_CSV, HELPER_CSV.writeExternal (_CSV));
}
public void compare (BaseBusinessClass other, AttributeChangeListener listener) throws StorageException
{
super.compare (other, listener);
if (other instanceof BaseTestAnalysis)
{
BaseTestAnalysis otherTestAnalysis = (BaseTestAnalysis)(other);
if (!HELPER_CSV.compare(this._CSV, otherTestAnalysis._CSV))
{
listener.notifyFieldChange(this, other, FIELD_CSV, HELPER_CSV.toObject(this._CSV), HELPER_CSV.toObject(otherTestAnalysis._CSV));
}
// Compare single assocs
// Compare multiple assocs
}
}
public void visitTransients (AttributeVisitor visitor) throws StorageException
{
super.visitAttributes (visitor);
}
public void visitAttributes (AttributeVisitor visitor) throws StorageException
{
super.visitAttributes (visitor);
visitor.visitField(this, FIELD_CSV, HELPER_CSV.toObject(getCSV()));
}
public void visitAssociations (AssociationVisitor visitor, AssociatedScope scope) throws StorageException
{
super.visitAssociations (visitor, scope);
}
public static TestAnalysis createTestAnalysis (ObjectTransaction transaction) throws StorageException
{
TestAnalysis result = new TestAnalysis ();
result.initialiseNewObject (transaction);
return result;
}
public static TestAnalysis getTestAnalysisByID (ObjectTransaction transaction, Long objectID) throws StorageException
{
return (TestAnalysis)(transaction.getObjectByID (REFERENCE_TestAnalysis, objectID));
}
public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
{
if (false)
{
throw new RuntimeException ("Game over man!!");
}
else if (attribName.equals (FIELD_CSV))
{
return filter.matches (getCSV ());
}
else
{
return super.testFilter (attribName, filter);
}
}
public Object getAttribute (String attribName)
{
if (false)
{
throw new RuntimeException ("Game over man!!");
}
else if (attribName.equals (FIELD_CSV))
{
return HELPER_CSV.toObject (getCSV ());
}
else
{
return super.getAttribute (attribName);
}
}
public AttributeHelper getAttributeHelper (String attribName)
{
if (false)
{
throw new RuntimeException ("Game over man!!");
}
else if (attribName.equals (FIELD_CSV))
{
return HELPER_CSV;
}
else
{
return super.getAttributeHelper (attribName);
}
}
public void setAttribute (String attribName, Object attribValue) throws FieldException
{
if (false)
{
throw new RuntimeException ("Game over man!!");
}
else if (attribName.equals (FIELD_CSV))
{
setCSV ((BinaryContent)(HELPER_CSV.fromObject (_CSV, attribValue)));
}
else
{
super.setAttribute (attribName, attribValue);
}
}
public boolean isWriteable (String fieldName)
{
return getWriteable (fieldName) == FieldWriteability.TRUE;
}
public FieldWriteability getWriteable (String fieldName)
{
if (false)
{
throw new RuntimeException ("Game over man!!");
}
else if (fieldName.equals (FIELD_CSV))
{
return getWriteability_CSV ();
}
else
{
return super.getWriteable (fieldName);
}
}
public void putUnwriteable (Set<String> fields)
{
if (getWriteability_CSV () != FieldWriteability.TRUE)
{
fields.add (FIELD_CSV);
}
super.putUnwriteable (fields);
}
public List<AbstractAttribute> getAttributes ()
{
List result = super.getAttributes ();
result.add(HELPER_CSV.getAttribObject (getClass (), _CSV, true, FIELD_CSV));
return result;
}
public Map getAttributeMetadata (String attribute)
{
if (ATTRIBUTES_METADATA_TestAnalysis.containsKey (attribute))
{
return (Map)ATTRIBUTES_METADATA_TestAnalysis.get (attribute);
}
else
{
return super.getAttributeMetadata (attribute);
}
}
public Object getAttributeMetadata (String attribute, String metadata)
{
if (ATTRIBUTES_METADATA_TestAnalysis.containsKey (attribute))
{
return ((Map)ATTRIBUTES_METADATA_TestAnalysis.get (attribute)).get(metadata);
}
else
{
return super.getAttributeMetadata (attribute, metadata);
}
}
public void preCommit (boolean willBeStored) throws Exception
{
super.preCommit(willBeStored);
if(willBeStored)
{
{
oneit.servlets.objstore.binary.BinaryContentHandler bchandler = oneit.servlets.objstore.binary.BinaryContentServlet.getHandler("loggedin");
if(bchandler != null)
{
bchandler.preCommit(willBeStored, this, "CSV");
}
else
{
LogMgr.log(BUSINESS_OBJECTS, LogLevel.SYSTEMWARNING, "Unknown BinaryContentHandler loggedin on attribute CSV");
}
}
}
}
public oneit.servlets.objstore.binary.BinaryContentHandler getBinaryContentHandler(String attribName)
{
if(CollectionUtils.equals(attribName, "CSV"))
{
return oneit.servlets.objstore.binary.BinaryContentServlet.getHandler("loggedin");
}
return super.getBinaryContentHandler(attribName);
}
public static class TestAnalysisBehaviourDecorator extends BaseBusinessClass.BBCBehaviourDecorator<TestAnalysis>
{
/**
* Get the attribute CSV
*/
public BinaryContent getCSV (TestAnalysis obj, BinaryContent original)
{
return original;
}
/**
* Change the value set for attribute CSV.
* May modify the field beforehand
* Occurs before validation.
*/
public BinaryContent setCSV (TestAnalysis obj, BinaryContent newCSV) throws FieldException
{
return newCSV;
}
}
public ORMPipeLine pipes()
{
return new TestAnalysisPipeLineFactory<TestAnalysis, TestAnalysis> ((TestAnalysis)this);
}
/**
* Use this instead of pipes() to get rid of type casting.
*/
public TestAnalysisPipeLineFactory<TestAnalysis, TestAnalysis> pipelineTestAnalysis()
{
return (TestAnalysisPipeLineFactory<TestAnalysis, TestAnalysis>) pipes();
}
public static TestAnalysisPipeLineFactory<TestAnalysis, TestAnalysis> pipesTestAnalysis(Collection<TestAnalysis> items)
{
return REFERENCE_TestAnalysis.new TestAnalysisPipeLineFactory<TestAnalysis, TestAnalysis> (items);
}
public static TestAnalysisPipeLineFactory<TestAnalysis, TestAnalysis> pipesTestAnalysis(TestAnalysis[] _items)
{
return pipesTestAnalysis(Arrays.asList (_items));
}
public static TestAnalysisPipeLineFactory<TestAnalysis, TestAnalysis> pipesTestAnalysis()
{
return pipesTestAnalysis((Collection)null);
}
public class TestAnalysisPipeLineFactory<From extends BaseBusinessClass, Me extends TestAnalysis> extends NonPersistentBOPipeLineFactory<From, Me>
{
public <Prev> TestAnalysisPipeLineFactory (PipeLine<From, Prev> pipeLine, Pipe<Prev, Me> nextPipe)
{
super (pipeLine, nextPipe);
}
public TestAnalysisPipeLineFactory (From seed)
{
super(seed);
}
public TestAnalysisPipeLineFactory (Collection<From> seed)
{
super(seed);
}
public PipeLine<From, ? extends Object> to(String name)
{
if (name.equals ("CSV"))
{
return toCSV ();
}
return super.to(name);
}
public PipeLine<From, BinaryContent> toCSV () { return pipe(new ORMAttributePipe<Me, BinaryContent>(FIELD_CSV)); }
}
public boolean isTransientAttrib(String attribName)
{
return super.isTransientAttrib(attribName);
}
public boolean isTransientSingleReference(String assocName)
{
return super.isTransientSingleReference(assocName);
}
}
class DummyTestAnalysis extends TestAnalysis
{
// Default constructor primarily to support Externalisable
public DummyTestAnalysis()
{
super();
}
public void assertValid ()
{
}
}
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
package performa.orm;
import java.io.*;
import java.util.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import oneit.logging.*;
import oneit.objstore.*;
import oneit.objstore.assocs.*;
import oneit.objstore.rdbms.*;
import oneit.objstore.utils.*;
import oneit.sql.*;
import oneit.utils.resource.*;
import oneit.utils.*;
import oneit.utils.threading.*;
import oneit.servlets.orm.*;
/**
* IMPORTANT!!!! Autogenerated class, DO NOT EDIT!!!!!
* Template: Infrastructure8.2[oneit.objstore.PersistenceMgrTemplate.xsl]
*/
public class TestAnalysisPersistenceMgr extends NonPersistentBOPersistenceMgr
{
private static final LoggingArea TestAnalysisPersistence = LoggingArea.createLoggingArea(ObjectPersistenceMgr.OBJECT_PERSISTENCE, "TestAnalysis");
// Private attributes corresponding to business object data
private BinaryContent dummyCSV;
// Static constants corresponding to attribute helpers
private static final BLOBAttributeHelper HELPER_CSV = BLOBAttributeHelper.INSTANCE;
public TestAnalysisPersistenceMgr ()
{
dummyCSV = (BinaryContent)(HELPER_CSV.initialise (dummyCSV));
}
private String SELECT_COLUMNS = "{PREFIX}it_does_not_matter.OBJECT_id as id, {PREFIX}it_does_not_matter.OBJECT_LAST_UPDATED_DATE as LAST_UPDATED_DATE, {PREFIX}it_does_not_matter.OBJECT_CREATED_DATE as CREATED_DATE, {PREFIX}it_does_not_matter.xxxx, 1 AS commasafe ";
private String SELECT_JOINS = "";
public BaseBusinessClass fetchByID(ObjectID id, PersistentSetCollection allPSets, RDBMSPersistenceContext context, SQLManager sqlMgr) throws SQLException, StorageException
{
Set<BaseBusinessClass> resultByIDs = fetchByIDs(Collections.singleton (id), allPSets, context, sqlMgr);
if (resultByIDs.isEmpty ())
{
return null;
}
else if (resultByIDs.size () > 1)
{
throw new StorageException ("Multiple results for id:" + id);
}
else
{
return resultByIDs.iterator ().next ();
}
}
public Set<BaseBusinessClass> fetchByIDs(Set<ObjectID> ids, PersistentSetCollection allPSets, RDBMSPersistenceContext context, SQLManager sqlMgr) throws SQLException, StorageException
{
Set<BaseBusinessClass> results = new HashSet ();
Set<Long> idsToFetch = new HashSet ();
for (ObjectID id : ids)
{
if (context.containsObject(id)) // Check for cached version
{
BaseBusinessClass objectToReturn = context.getObjectToReplace(id, TestAnalysis.REFERENCE_TestAnalysis);
if (objectToReturn instanceof TestAnalysis)
{
LogMgr.log (TestAnalysisPersistence, LogLevel.TRACE, "Cache hit for id:", id);
results.add (objectToReturn);
}
else
{
throw new StorageException ("Cache collision for id:" + id + " with object " + objectToReturn + "while fetching a TestAnalysis");
}
}
PersistentSet it_does_not_matterPSet = allPSets.getPersistentSet(id, "it_does_not_matter", PersistentSetStatus.FETCHED);
// Check for persistent sets already prefetched
if (false || !it_does_not_matterPSet.containsAttrib(BaseBusinessClass.FIELD_ObjectLastModified) ||
!it_does_not_matterPSet.containsAttrib(TestAnalysis.FIELD_CSV))
{
// We will need to retrieve it
idsToFetch.add (id.longValue());
}
else
{
LogMgr.log (TestAnalysisPersistence, LogLevel.DEBUG2, "Persistent set preloaded id:", id);
/* Non Polymorphic */
TestAnalysis result = new TestAnalysis ();
result.setFromPersistentSets(id, allPSets);
context.addRetrievedObject(result);
results.add (result);
}
}
if (idsToFetch.size () > 0)
{
String query = "SELECT " + SELECT_COLUMNS +
"FROM {PREFIX}it_does_not_matter " +
"WHERE " + SELECT_JOINS + "{PREFIX}it_does_not_matter.OBJECT_id IN ?";
BaseBusinessClass[] resultsFetched = loadQuery (allPSets, sqlMgr, context, query, new Object[] { idsToFetch }, null, false);
for (BaseBusinessClass objFetched : resultsFetched)
{
results.add (objFetched);
}
}
return results;
}
public BaseBusinessClass[] getReferencedObjects(ObjectID _objectID, String refName, PersistentSetCollection allPSets, RDBMSPersistenceContext context, SQLManager sqlMgr) throws SQLException, StorageException
{
if (false)
{
throw new RuntimeException ();
}
else
{
throw new IllegalArgumentException ("Illegal reference type:" + refName);
}
}
public void update(BaseBusinessClass obj, PersistentSetCollection allPSets, RDBMSPersistenceContext context, SQLManager sqlMgr) throws SQLException, ConcurrentUpdateConflictException, StorageException
{
EqualityResult test = EqualityResult.compare (obj, obj.getBackup ());
ObjectID objectID = obj.getID ();
if (!test.areAttributesEqual () || !test.areSingleAssocsEqual () || obj.getForcedSave())
{
PersistentSet it_does_not_matterPSet = allPSets.getPersistentSet(objectID, "it_does_not_matter");
if (it_does_not_matterPSet.getStatus () != PersistentSetStatus.PROCESSED &&
it_does_not_matterPSet.getStatus () != PersistentSetStatus.DEFERRED)
{
int rowsUpdated = executeStatement (sqlMgr,
"UPDATE {PREFIX}it_does_not_matter " +
"SET xxxx = ? , OBJECT_LAST_UPDATED_DATE = " + sqlMgr.getPortabilityServices ().getTimestampExpression () + " " +
"WHERE it_does_not_matter.OBJECT_id = ? AND " + getConcurrencyCheck (sqlMgr, "OBJECT_LAST_UPDATED_DATE", obj.getObjectLastModified ()) + " ",
CollectionUtils.listEntry (HELPER_CSV.getForSQL(dummyCSV, it_does_not_matterPSet.getAttrib (TestAnalysis.FIELD_CSV))).listEntry (objectID.longID ()).listEntry (obj.getObjectLastModified ()).toList().toArray());
if (rowsUpdated != 1)
{
// Error, either a concurrency error or a not-exists error
ResultSet r = executeQuery (sqlMgr,
"SELECT OBJECT_id, OBJECT_LAST_UPDATED_DATE FROM {PREFIX}it_does_not_matter WHERE OBJECT_id = ?",
new Object[] { objectID.longID () });
if (r.next ())
{
Date d = new java.util.Date (r.getTimestamp (2).getTime());
String errorMsg = QueryBuilder.buildQueryString ("Concurrent update error:[?] for row:[?] objDate:[?] dbDate:[?]",
new Object[] { "it_does_not_matter", objectID.longID (), obj.getObjectLastModified (), d },
sqlMgr.getPortabilityServices ());
LogMgr.log (TestAnalysisPersistence, LogLevel.BUSINESS1, errorMsg);
throw new ConcurrentUpdateConflictException (obj, "it_does_not_matter");
}
else
{
String errorMsg = "Attempt to update nonexistent row in table:it_does_not_matter for row:" + objectID + " objDate:" + obj.getObjectLastModified ();
LogMgr.log (TestAnalysisPersistence, LogLevel.BUSINESS1, errorMsg);
throw new RuntimeException (errorMsg);
}
}
it_does_not_matterPSet.setStatus (PersistentSetStatus.PROCESSED);
}
}
else
{
LogMgr.log (TestAnalysisPersistence, LogLevel.DEBUG1, "Skipping update since no attribs or simple assocs changed on ", objectID);
}
}
public void delete(BaseBusinessClass obj, PersistentSetCollection allPSets, RDBMSPersistenceContext context, SQLManager sqlMgr) throws SQLException, ConcurrentUpdateConflictException, StorageException
{
ObjectID objectID = obj.getID ();
PersistentSet it_does_not_matterPSet = allPSets.getPersistentSet(objectID, "it_does_not_matter");
LogMgr.log (TestAnalysisPersistence, LogLevel.DEBUG2, "Deleting:", objectID);
if (it_does_not_matterPSet.getStatus () != PersistentSetStatus.PROCESSED &&
it_does_not_matterPSet.getStatus () != PersistentSetStatus.DEFERRED)
{
int rowsDeleted = executeStatement (sqlMgr,
"DELETE " +
"FROM {PREFIX}it_does_not_matter " +
"WHERE it_does_not_matter.OBJECT_id = ? AND " + sqlMgr.getPortabilityServices ().getTruncatedTimestampColumn ("OBJECT_LAST_UPDATED_DATE") + " = " + sqlMgr.getPortabilityServices ().getTruncatedTimestampParam("?") + " ",
new Object[] { objectID.longID(), obj.getObjectLastModified () });
if (rowsDeleted != 1)
{
// Error, either a concurrency error or a not-exists error
ResultSet r = executeQuery (sqlMgr,
"SELECT OBJECT_id FROM {PREFIX}it_does_not_matter WHERE OBJECT_id = ?",
new Object[] { objectID.longID() });
if (r.next ())
{
throw new ConcurrentUpdateConflictException (obj, "it_does_not_matter");
}
else
{
String errorMsg = "Attempt to delete nonexistent row in table:it_does_not_matter for row:" + objectID;
LogMgr.log (TestAnalysisPersistence, LogLevel.SYSTEMERROR1, errorMsg);
throw new RuntimeException (errorMsg);
}
}
it_does_not_matterPSet.setStatus (PersistentSetStatus.PROCESSED);
}
}
public BaseBusinessClass[] loadQuery (PersistentSetCollection allPSets, SQLManager sqlMgr, RDBMSPersistenceContext context, String query, Object[] params, Integer maxRows, boolean truncateExtra) throws SQLException, StorageException
{
LinkedHashMap<ObjectID, TestAnalysis> results = new LinkedHashMap ();
ResultSet r = executeQuery (sqlMgr, query, params);
while (r.next())
{
ThreadUtils.checkInterrupted ();
ObjectID objectID = new ObjectID (TestAnalysis.REFERENCE_TestAnalysis.getObjectIDSpace (), r.getLong ("id"));
TestAnalysis resultElement;
if (maxRows != null && !results.containsKey (objectID) && results.size () >= maxRows)
{
if (truncateExtra)
{
break;
}
else
{
throw new SearchRowsExceededException ("Maximum rows exceeded:" + maxRows);
}
}
if (context.containsObject(objectID))
{
BaseBusinessClass cachedElement = context.getObjectToReplace(objectID, TestAnalysis.REFERENCE_TestAnalysis);
if (cachedElement instanceof TestAnalysis)
{
LogMgr.log (TestAnalysisPersistence, LogLevel.TRACE, "Cache hit for id:", objectID);
resultElement = (TestAnalysis)cachedElement;
}
else
{
throw new StorageException ("Cache collision for id:" + objectID + " with object " + cachedElement + "while fetching a TestAnalysis");
}
}
else
{
PersistentSet it_does_not_matterPSet = allPSets.getPersistentSet(objectID, "it_does_not_matter", PersistentSetStatus.FETCHED);
createPersistentSetFromRS(allPSets, r, objectID);
resultElement = new TestAnalysis ();
resultElement.setFromPersistentSets(objectID, allPSets);
context.addRetrievedObject(resultElement);
}
results.put (objectID, resultElement);
}
BaseBusinessClass[] resultsArr = new BaseBusinessClass[results.size ()];
return results.values ().toArray (resultsArr);
}
public BaseBusinessClass[] find(String searchType, PersistentSetCollection allPSets, Hashtable criteria, RDBMSPersistenceContext context, SQLManager sqlMgr) throws SQLException, StorageException
{
LogMgr.log (TestAnalysisPersistence, LogLevel.DEBUG2, "Search executing:", searchType, " criteria:", criteria);
String customParamFilter = (String)criteria.get (SEARCH_CustomFilter);
String customOrderBy = (String)criteria.get (SEARCH_OrderBy);
String customTables = (String)criteria.get (SEARCH_CustomExtraTables);
Boolean noCommaBeforeCustomExtraTables = (Boolean)criteria.get (SEARCH_CustomExtraTablesNoComma);
if (searchType.equals (SEARCH_CustomSQL))
{
Set<ObjectID> processedIDs = new HashSet();
SearchParamTransform tx = new SearchParamTransform (criteria);
Object[] searchParams;
customParamFilter = StringUtils.replaceParams (customParamFilter, tx);
searchParams = tx.getParamsArray();
if (customOrderBy != null)
{
customOrderBy = " ORDER BY " + customOrderBy;
}
else
{
customOrderBy = "";
}
ResultSet r;
String concatCustomTableWith = CollectionUtils.equals(noCommaBeforeCustomExtraTables, true) ? " " : ", ";
String tables = StringUtils.subBlanks(customTables) == null ? " " : concatCustomTableWith + customTables + " ";
String query = "SELECT " + SELECT_COLUMNS +
"FROM {PREFIX}it_does_not_matter " + tables +
"WHERE " + SELECT_JOINS + " " + customParamFilter + customOrderBy;
BaseBusinessClass[] results = loadQuery (allPSets, sqlMgr, context, query, searchParams, null, false);
return results;
}
else
{
BaseBusinessClass[] resultsArray = super.find(searchType, allPSets, criteria, context, sqlMgr);
Vector results = new Vector ();
for (int x = 0 ; x < resultsArray.length ; ++x)
{
if (resultsArray[x] instanceof TestAnalysis)
{
results.add (resultsArray[x]);
}
else
{
// Ignore
}
}
resultsArray = new BaseBusinessClass[results.size ()];
results.copyInto (resultsArray);
return resultsArray;
}
}
private void createPersistentSetFromRS(PersistentSetCollection allPSets, ResultSet r, ObjectID objectID) throws SQLException
{
PersistentSet it_does_not_matterPSet = allPSets.getPersistentSet(objectID, "it_does_not_matter", PersistentSetStatus.FETCHED);
// Object Modified
it_does_not_matterPSet.setAttrib(BaseBusinessClass.FIELD_ObjectLastModified, r.getTimestamp ("LAST_UPDATED_DATE"));
// Object Created
it_does_not_matterPSet.setAttrib(BaseBusinessClass.FIELD_ObjectCreated, r.getTimestamp ("CREATED_DATE"));
it_does_not_matterPSet.setAttrib(TestAnalysis.FIELD_CSV, HELPER_CSV.getFromRS(dummyCSV, r, "xxxx"));
}
public void create(BaseBusinessClass obj, PersistentSetCollection allPSets, RDBMSPersistenceContext context, SQLManager sqlMgr) throws SQLException, StorageException
{
ObjectID objectID = obj.getID ();
PersistentSet it_does_not_matterPSet = allPSets.getPersistentSet(objectID, "it_does_not_matter");
if (it_does_not_matterPSet.getStatus () != PersistentSetStatus.PROCESSED &&
it_does_not_matterPSet.getStatus () != PersistentSetStatus.DEFERRED)
{
executeStatement (sqlMgr,
"INSERT INTO {PREFIX}it_does_not_matter " +
" (xxxx, OBJECT_id, OBJECT_LAST_UPDATED_DATE, OBJECT_CREATED_DATE) " +
"VALUES " +
" (?, ?, " + sqlMgr.getPortabilityServices ().getTimestampExpression () + ", " + sqlMgr.getPortabilityServices ().getTimestampExpression () + ")",
CollectionUtils.listEntry (HELPER_CSV.getForSQL(dummyCSV, it_does_not_matterPSet.getAttrib (TestAnalysis.FIELD_CSV))) .listEntry (objectID.longID ()).toList().toArray());
it_does_not_matterPSet.setStatus (PersistentSetStatus.PROCESSED);
}
}
}
<?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