*/
-public class EntityContent extends AbstractEntity implements Entity
+public class EntityContent extends Entity
{
private static int instances;
* set is_produced flag for the article
*/
- public void setProduced(boolean yesno)
+ public void setProduced(boolean yesno) throws StorageObjectException
{
Connection con=null;Statement stmt=null;
String value = (yesno) ? "1":"0";
String sql = "update content set is_produced='" + value + "' where id='" + getId()+"'";
try {
- con = theStorageObject.getPooledCon();
- /** @todo should be preparedStatement: faster!! */
- stmt = con.createStatement();
- theStorageObject.executeUpdate(stmt,sql);
+ con = theStorageObject.getPooledCon();
+ /** @todo should be preparedStatement: faster!! */
+ stmt = con.createStatement();
+ theStorageObject.executeUpdate(stmt,sql);
} catch (StorageObjectException e) {
- theLog.printDebugInfo(e.toString() + "\n -- set produced failed");
+ throwStorageObjectException(e, "\n -- set produced failed");
} catch (SQLException e) {
- theLog.printDebugInfo(e.toString() + "\n -- set produced failed");
+ throwStorageObjectException(e, "\n -- set produced failed");
} finally {
theStorageObject.freeConnection(con,stmt);
}
* make openposting to newswire
*/
- public void newswire()
+ public void newswire() throws StorageObjectException
{
String sql = "update content set to_article_type='1', is_produced='0' where id='" + getId()+"'";
try {
theStorageObject.executeUpdate(sql);
} catch (StorageObjectException e) {
- theLog.printError(e.toString() + "newswire failed");
+ throwStorageObjectException(e, "\n -- newswire failed");
} catch (SQLException e) {
- theLog.printError(e.toString() + "newswire failed");
+ throwStorageObjectException(e, "\n -- newswire failed");
}
}
/**
* dettach from media
*/
-
- public void dettach()
+ public void dettach(String cid,String mid) throws StorageObjectException
{
- String sql = "update content set to_media=null, is_produced='0' where id='" + getId()+"'";
- try {
- theStorageObject.executeUpdate(sql);
- } catch (StorageObjectException e) {
- theLog.printError(e.toString() + "dettach failed");
- } catch (SQLException e) {
- theLog.printError(e.toString() + "dettach failed");
+ if (mid!=null){
+ try{
+ DatabaseContentToMedia.getInstance().delete(cid,mid);
+ } catch (Exception e){
+ throwStorageObjectException(e, "\n -- failed to get instance");
+ }
+ //set Content to unproduced
+ setProduced(false);
}
}
* attach to media
*/
- public void attach(String mid)
+ public void attach(String mid) throws StorageObjectException
{
if (mid!=null) {
- String sql = "update content set to_media='" + mid + "', is_produced='0' where id='" + getId()+"'";
- try {
- theStorageObject.executeUpdate(sql);
- } catch (StorageObjectException e) {
- theLog.printError(e.toString() + "attach failed");
- } catch (SQLException e) {
- theLog.printError(e.toString() + "attach failed");
+ //write media-id mid and content-id in table content_x_media
+ try{
+ DatabaseContentToMedia.getInstance().addMedia(getId(),mid);
+ } catch(StorageObjectException e){
+ throwStorageObjectException(e, "attach: could not get the instance");
}
- }
- else
+ //set Content to unproduced
+ setProduced(false);
+ } else {
theLog.printError("EntityContent: attach without mid");
+ }
}
/**
- * overridden method getValues to include formatted date into every
+ * overridden method getValue to include formatted date into every
* entityContent
*/
- public HashMap getValues() {
- HashMap returnHash = super.getValues();
- String date=null;
-
- if ((date=(String)returnHash.get("date"))!=null)
- returnHash.put("date_formatted", StringUtil.webdbDate2readableDate(date));
- if ((date=(String)returnHash.get("webdb_create"))!=null)
- returnHash.put("webdb_create_formatted", StringUtil.dateToReadableDate(date));
- if ((date=(String)returnHash.get("webdb_lastchange"))!=null)
- returnHash.put("webdb_lastchange_formatted", StringUtil.dateToReadableDate(date));
- return returnHash;
+ public String getValue(String field)
+ {
+ if (field!=null && field.equals("date_formatted"))
+ {
+ if (hasValueForField("date"))
+ return StringUtil.webdbDate2readableDate(getValue("date"));
+ else return null;
+ }
+ else
+ return super.getValue(field);
}
/**
*
* @return freemarker.template.SimpleList
*/
- public SimpleList getComments() {
+ public SimpleList getComments() throws StorageObjectException {
return ((DatabaseContent)theStorageObject).getComments(this);
}