formEntryVO.setUserAgent(userAgent);
formEntryVO.setUserIP(userIP);
formEntryVO.setUserName(userName);
formEntryVO.setRegistrationDateTime(registrationDate);
FormEntry newFormEntry = null;
Database db = CastorDatabaseService.getDatabase();
ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer();
beginTransaction(db);
try
{
newFormEntry = formEntryController.create(formEntryVO, formEntryValueVOList, db);
commitTransaction(db);
}
catch(Exception e)
{
logger.error("An error occurred so we should not completes the transaction:" + e, e);
rollbackTransaction(db);
throw new SystemException(e.getMessage());
}
Database db2 = CastorDatabaseService.getDatabase();
beginTransaction(db2);
try
{
newFormEntry = formEntryController.getFormEntryWithId(newFormEntry.getFormEntryId(), db2);
List digitalAssets = (List)formEntry.get("digitalAssets");
logger.info("digitalAssets:" + digitalAssets);
if(digitalAssets != null)
{
Iterator digitalAssetIterator = digitalAssets.iterator();
while(digitalAssetIterator.hasNext())
{
RemoteAttachment remoteAttachment = (RemoteAttachment)digitalAssetIterator.next();
logger.info("digitalAssets in ws:" + remoteAttachment);
FormEntryAssetVO newAsset = new FormEntryAssetVO();
newAsset.setContentType(remoteAttachment.getContentType());
newAsset.setAssetKey(remoteAttachment.getName());
newAsset.setFileName(remoteAttachment.getFileName());
newAsset.setFileSize(new Integer(new Long(remoteAttachment.getBytes().length).intValue()));
byte[] bytes = remoteAttachment.getBytes();
InputStream is = new ByteArrayInputStream(bytes);
formEntryController.createAsset(newAsset, newFormEntry, is, newFormEntry.getId(), principal, db2);
}
}
commitTransaction(db2);
}