public ContentCategory createWithDatabase(ContentCategoryVO c, Database db) throws SystemException, PersistenceException
{
// Need this crappy hack to forge the relationship (castor completely sucks like this)
// TODO: When hibernate comes, just save the VOs and if it has a child VO with an id set
// TODO: it is used to make the relationship...ask me for clarification -frank
Category category = (Category)getObjectWithId(CategoryImpl.class, c.getCategory().getId(), db);
//ContentVersion contentVersion = (ContentVersion)getObjectWithId(ContentVersionImpl.class, c.getContentVersionId(), db);
ContentVersion contentVersion = ContentVersionController.getContentVersionController().getMediumContentVersionWithId(c.getContentVersionId(), db);
ContentCategory contentCategory = null;
List existingContentCategories = ContentCategoryController.getController().findByContentVersionAttribute(c.getAttributeName(), contentVersion.getContentVersionId(), db);
boolean exists = false;
Iterator existingContentCategoriesIterator = existingContentCategories.iterator();
while(existingContentCategoriesIterator.hasNext())
{
ContentCategory contentCategoryCandidate = (ContentCategory)existingContentCategoriesIterator.next();
if(contentCategoryCandidate.getCategoryId().equals(category.getId()))
{
exists = true;
contentCategory = contentCategoryCandidate;
logger.info("The category " + category.getName() + " was allready set on this version");
break;
}
}
if(!exists)
{
logger.info("Creating the category " + category.getName() + " as it was not set on this version");
contentCategory = new MediumContentCategoryImpl();
contentCategory.setValueObject(c);
contentCategory.setCategory((CategoryImpl)category);
contentCategory.setContentVersion((MediumContentVersionImpl)contentVersion);
db.create(contentCategory);
contentVersion.getContentCategories().add(contentCategory);
}
else
{
logger.info("Skipping the category " + category.getName() + " as it was allready set on this version");
}
return contentCategory;
}