public void updateXmlForm(AttachmentPK pk, String language, String xmlFormName) throws AttachmentException { Connection con = getConnection(); try { if (!I18NHelper.isI18N || !StringUtil.isDefined(language)) { dao.updateXmlForm(con, pk, xmlFormName); } else { AttachmentDetail attachment = dao.findByPrimaryKey(con, pk); if (!StringUtil.isDefined(attachment.getLanguage()) || attachment.getLanguage().equals(language)) { dao.updateXmlForm(con, pk, xmlFormName); } else { AttachmentI18NDAO.updateXmlForm(con, pk, language, xmlFormName); } } } catch (SQLException se) { throw new AttachmentException( "AttachmentBmImpl.updateXmlForm()", SilverpeasException.ERROR, "EX_RECORD_NOT_UPDATE_ATTACHMENT", se); } finally { closeConnection(con); } }
public void deleteAttachment(AttachmentPK primaryKey) throws AttachmentException { Connection con = getConnection(); try { AttachmentI18NDAO.removeTranslations(con, primaryKey); dao.deleteAttachment(con, primaryKey); } catch (SQLException se) { throw new AttachmentException( "AttachmentBmImpl.createAttachment()", SilverpeasException.ERROR, "attachment_MSG_NOT_DELETE_FILE", se); } finally { closeConnection(con); } }
@Override public void updateAttachment(AttachmentDetail attachDetail) throws AttachmentException { Connection con = getConnection(); try { boolean updateDefault = false; AttachmentDetail oldAttachment = dao.findByPrimaryKey(con, attachDetail.getPK()); String oldLang = oldAttachment.getLanguage(); if (attachDetail.isRemoveTranslation()) { if ("-1".equals(attachDetail.getTranslationId())) { List<AttachmentDetailI18N> translations = AttachmentI18NDAO.getTranslations(con, attachDetail.getPK()); if (translations != null && translations.size() > 0) { AttachmentDetailI18N translation = translations.get(0); attachDetail.setPhysicalName(translation.getPhysicalName()); attachDetail.setLogicalName(translation.getLogicalName()); attachDetail.setType(translation.getType()); attachDetail.setCreationDate(translation.getCreationDate()); attachDetail.setSize(translation.getSize()); attachDetail.setAuthor(translation.getAuthor()); attachDetail.setTitle(translation.getTitle()); attachDetail.setInfo(translation.getInfo()); attachDetail.setLanguage(translation.getLanguage()); AttachmentI18NDAO.removeTranslation(con, translation.getId()); updateDefault = true; } } else { AttachmentI18NDAO.removeTranslation(con, attachDetail.getTranslationId()); } } else { // Add or update a translation if (attachDetail.getLanguage() != null) { if (oldLang == null) { // translation for the first time oldLang = I18NHelper.defaultLanguage; } if (!oldLang.equalsIgnoreCase(attachDetail.getLanguage())) { AttachmentDetailI18N translation = new AttachmentDetailI18N(attachDetail); String translationId = attachDetail.getTranslationId(); if (translationId != null && !"-1".equals(translationId)) { AttachmentI18NDAO.updateTranslation(con, translation); } else { AttachmentI18NDAO.addTranslation(con, translation); } attachDetail.setPhysicalName(oldAttachment.getPhysicalName()); attachDetail.setLogicalName(oldAttachment.getLogicalName()); attachDetail.setType(oldAttachment.getType()); attachDetail.setCreationDate(oldAttachment.getCreationDate()); attachDetail.setSize(oldAttachment.getSize()); attachDetail.setAuthor(oldAttachment.getAuthor()); attachDetail.setTitle(oldAttachment.getTitle()); attachDetail.setInfo(oldAttachment.getInfo()); attachDetail.setLanguage(oldLang); } else { updateDefault = true; } } else { updateDefault = true; } } if (updateDefault) { dao.updateRow(con, attachDetail); } } catch (SQLException se) { throw new AttachmentException( "AttachmentBmImpl.updateAttachment()", SilverpeasException.ERROR, "attachment.EX_RECORD_NOT_UPDATE_ATTACHMENT", se); } finally { closeConnection(con); } }