public static DigitalAssetVO create(DigitalAssetVO digitalAssetVO, InputStream is, String entity, Integer entityId) throws ConstraintException, SystemException
{
Database db = CastorDatabaseService.getDatabase();
DigitalAsset digitalAsset = null;
beginTransaction(db);
try
{
if(entity.equalsIgnoreCase("ContentVersion"))
{
ContentVersion contentVersion = ContentVersionController.getContentVersionController().getContentVersionWithId(entityId, db);
Collection contentVersions = new ArrayList();
contentVersions.add(contentVersion);
logger.info("Added contentVersion:" + contentVersion.getId());
digitalAsset = new DigitalAssetImpl();
digitalAsset.setValueObject(digitalAssetVO);
if(CmsPropertyHandler.getEnableDiskAssets().equals("false"))
digitalAsset.setAssetBlob(is);
digitalAsset.setContentVersions(contentVersions);
db.create(digitalAsset);
contentVersion.getDigitalAssets().add(digitalAsset);
}
else if(entity.equalsIgnoreCase(UserProperties.class.getName()))
{
UserProperties userProperties = UserPropertiesController.getController().getUserPropertiesWithId(entityId, db);
Collection userPropertiesList = new ArrayList();
userPropertiesList.add(userProperties);
logger.info("Added userProperties:" + userProperties.getId());
digitalAsset = new DigitalAssetImpl();
digitalAsset.setValueObject(digitalAssetVO);
if(CmsPropertyHandler.getEnableDiskAssets().equals("false"))
digitalAsset.setAssetBlob(is);
digitalAsset.setUserProperties(userPropertiesList);
db.create(digitalAsset);
userProperties.getDigitalAssets().add(digitalAsset);
}
else if(entity.equalsIgnoreCase(RoleProperties.class.getName()))
{
RoleProperties roleProperties = RolePropertiesController.getController().getRolePropertiesWithId(entityId, db);
Collection rolePropertiesList = new ArrayList();
rolePropertiesList.add(roleProperties);
logger.info("Added roleProperties:" + roleProperties.getId());
digitalAsset = new DigitalAssetImpl();
digitalAsset.setValueObject(digitalAssetVO);
if(CmsPropertyHandler.getEnableDiskAssets().equals("false"))
digitalAsset.setAssetBlob(is);
digitalAsset.setRoleProperties(rolePropertiesList);
db.create(digitalAsset);
roleProperties.getDigitalAssets().add(digitalAsset);
}
else if(entity.equalsIgnoreCase(GroupProperties.class.getName()))
{
GroupProperties groupProperties = GroupPropertiesController.getController().getGroupPropertiesWithId(entityId, db);
Collection groupPropertiesList = new ArrayList();
groupPropertiesList.add(groupProperties);
logger.info("Added groupProperties:" + groupProperties.getId());
digitalAsset = new DigitalAssetImpl();
digitalAsset.setValueObject(digitalAssetVO);
if(CmsPropertyHandler.getEnableDiskAssets().equals("false"))
digitalAsset.setAssetBlob(is);
digitalAsset.setGroupProperties(groupPropertiesList);
db.create(digitalAsset);
groupProperties.getDigitalAssets().add(digitalAsset);
}
commitTransaction(db);
}
catch(Exception e)
{
logger.error("An error occurred so we should not complete the transaction:" + e, e);
rollbackTransaction(db);
throw new SystemException(e.getMessage());
}
return digitalAsset.getValueObject();
}