public void deleteImage(int articleId) throws IOException { Article article = em.find(Article.class, articleId); if (article == null) { throw new RuntimeException("No such article"); } if (!article.getOwner().equals(plAccess.getUser().getLoginName())) { throw new RuntimeException("The user has no such article."); } String oldImageId = article.getImageId(); if (oldImageId != null) { store.delete(store.createUrl(oldImageId)); } article.setImageId(null); }
private void markAsUnpublished(ZdoModel model, ZdoModel kdrModel) throws IOException { if (ZdoGroup.ZDO.name().equals(model.get(ZdoTerms.group))) { model.replaceValueOfProperty(ZdoTerms.group, ZdoGroup.UNPUBLISHED.name()); // Unlock kdr object kdrModel.decreaseLockCount(); String pdfUrl = kdrModel.get(ZdoTerms.pdfUrl); String epubUrl = kdrModel.get(ZdoTerms.epubUrl); if (pdfUrl != null) { store.delete(pdfUrl); kdrModel.removeAllValuesOfProperty(ZdoTerms.pdfUrl); } if (epubUrl != null) { store.delete(epubUrl); kdrModel.removeAllValuesOfProperty(ZdoTerms.epubUrl); } // And unindex original published doc if (ZdoType.isRootCategory(model.get(ZdoTerms.zdoType))) { rootsToDelete.add(store.getOnlyIdFromUrl(model.getUrl())); } } }
public void uploadImage(int articleId, MultipartFormDataInput input) throws IOException { Article article = em.find(Article.class, articleId); if (article == null) { throw new RuntimeException("No such article"); } if (!article.getOwner().equals(plAccess.getUser().getLoginName())) { throw new RuntimeException("The user has no such article."); } String oldImageId = article.getImageId(); if (oldImageId != null) { store.delete(store.createUrl(oldImageId)); } String uuid = imgUploadTools.uploadedFileToFedora(input, ZdoFileType.articleImage); article.setImageId(uuid); }