File file = new File(path);
String categoryPath=file.getParent();
List<Category> categoryFromPath = categoryDao.getCategoryFromPath(categoryPath);
if (categoryFromPath.size()==0) {
throw new GenericErrorException("There is no category for the path " + categoryPath);
}
else if (categoryFromPath.size()!=1) {
throw new IllegalStateException("Two category with the samepath! "+categoryPath);
} else {
uniqueCategoryId=categoryFromPath.get(0).getId();
}
List<Content> articleInCategoryFromPathID = getArticleInCategoryFromCatiDAndTitle(title, categoryFromPath.get(0).getId());
if (articleInCategoryFromPathID.size()!=0) {
throw new GenericErrorException("There is already an article "+title+" in the category for the path " + categoryPath);
}
Content article = aContent(title, alias, content, link, path, uniqueCategoryId,description,keywords);
System.out.println(article);
try {
LOGGER.info("Creating article {} in {}",title,categoryPath);
getHibernateTemplate().save(JoomlaDslUtils.sanytize(article));
} catch (NoSuchMethodException e) {
throw new GenericErrorException("GRAVE" + categoryPath+"/"+title,e);
} catch (InvocationTargetException e) {
throw new GenericErrorException("GRAVE" + categoryPath+"/"+title,e);
} catch (IllegalAccessException e) {
throw new GenericErrorException("GRAVE" + categoryPath+"/"+title,e);
}
}